comparison OrthancFramework/UnitTestsSources/FromDcmtkTests.cpp @ 5323:138e9d0c08c1

added DicomMap::GuessPixelDataValueRepresentation()
author Sebastien Jodogne <s.jodogne@gmail.com>
date Sun, 25 Jun 2023 12:29:39 +0200
parents a904a4caf5b7
children 5b2a5cc64cb1
comparison
equal deleted inserted replaced
5322:a904a4caf5b7 5323:138e9d0c08c1
35 #endif 35 #endif
36 36
37 #include <gtest/gtest.h> 37 #include <gtest/gtest.h>
38 38
39 #include "../Sources/Compatibility.h" 39 #include "../Sources/Compatibility.h"
40 #include "../Sources/DicomFormat/DicomImageInformation.h"
40 #include "../Sources/DicomFormat/DicomPath.h" 41 #include "../Sources/DicomFormat/DicomPath.h"
41 #include "../Sources/DicomNetworking/DicomFindAnswers.h" 42 #include "../Sources/DicomNetworking/DicomFindAnswers.h"
42 #include "../Sources/DicomParsing/DicomModification.h" 43 #include "../Sources/DicomParsing/DicomModification.h"
43 #include "../Sources/DicomParsing/DicomWebJsonVisitor.h" 44 #include "../Sources/DicomParsing/DicomWebJsonVisitor.h"
44 #include "../Sources/DicomParsing/FromDcmtkBridge.h" 45 #include "../Sources/DicomParsing/FromDcmtkBridge.h"
3349 } 3350 }
3350 3351
3351 for (Syntaxes::const_iterator it = compressedSyntaxes.begin(); it != compressedSyntaxes.end(); ++it) 3352 for (Syntaxes::const_iterator it = compressedSyntaxes.begin(); it != compressedSyntaxes.end(); ++it)
3352 { 3353 {
3353 // All the compressed transfer syntaxes must have "OB" pixel data 3354 // All the compressed transfer syntaxes must have "OB" pixel data
3354 ParsedDicomFile dicom(true); 3355 ASSERT_EQ(ValueRepresentation_OtherByte, DicomImageInformation::GuessPixelDataValueRepresentation(it->second, bitsAllocated));
3355 ASSERT_TRUE(dicom.GetDcmtkObject().getDataset()->putAndInsertUint16(DCM_BitsAllocated, bitsAllocated).good()); 3356
3356 ASSERT_TRUE(dicom.GetDcmtkObject().chooseRepresentation(it->first, NULL).good()); 3357 {
3357 dicom.GetDcmtkObject().removeAllButCurrentRepresentations(); 3358 DicomMap dicom;
3358 DicomTransferSyntax ts; 3359 dicom.SetValue(DICOM_TAG_BITS_ALLOCATED, boost::lexical_cast<std::string>(bitsAllocated), false);
3359 ASSERT_TRUE(dicom.LookupTransferSyntax(ts)); 3360 ASSERT_EQ(ValueRepresentation_OtherByte, dicom.GuessPixelDataValueRepresentation(it->second));
3360 ASSERT_EQ(ts, it->second); 3361 }
3361 ASSERT_EQ(ValueRepresentation_OtherByte, dicom.GuessPixelDataValueRepresentation()); 3362
3363 {
3364 DicomMap dicom;
3365 ASSERT_EQ(ValueRepresentation_OtherByte, dicom.GuessPixelDataValueRepresentation(it->second));
3366 }
3367
3368 {
3369 ParsedDicomFile dicom(true);
3370 ASSERT_TRUE(dicom.GetDcmtkObject().getDataset()->putAndInsertUint16(DCM_BitsAllocated, bitsAllocated).good());
3371 ASSERT_TRUE(dicom.GetDcmtkObject().chooseRepresentation(it->first, NULL).good());
3372 dicom.GetDcmtkObject().removeAllButCurrentRepresentations();
3373 DicomTransferSyntax ts;
3374 ASSERT_TRUE(dicom.LookupTransferSyntax(ts));
3375 ASSERT_EQ(ts, it->second);
3376 ASSERT_EQ(ValueRepresentation_OtherByte, dicom.GuessPixelDataValueRepresentation());
3377 }
3362 } 3378 }
3363 3379
3364 { 3380 {
3365 // Little endian implicit is always OW 3381 // Little endian implicit is always OW
3366 ParsedDicomFile dicom(true); 3382 ASSERT_EQ(ValueRepresentation_OtherWord, DicomImageInformation::GuessPixelDataValueRepresentation(DicomTransferSyntax_LittleEndianImplicit, bitsAllocated));
3367 ASSERT_TRUE(dicom.GetDcmtkObject().getDataset()->putAndInsertUint16(DCM_BitsAllocated, bitsAllocated).good()); 3383
3368 ASSERT_TRUE(dicom.GetDcmtkObject().chooseRepresentation(EXS_LittleEndianImplicit, NULL).good()); 3384 {
3369 dicom.GetDcmtkObject().removeAllButCurrentRepresentations(); 3385 DicomMap dicom;
3370 ASSERT_EQ(ValueRepresentation_OtherWord, dicom.GuessPixelDataValueRepresentation()); 3386 dicom.SetValue(DICOM_TAG_BITS_ALLOCATED, boost::lexical_cast<std::string>(bitsAllocated), false);
3371 } 3387 ASSERT_EQ(ValueRepresentation_OtherWord, dicom.GuessPixelDataValueRepresentation(DicomTransferSyntax_LittleEndianImplicit));
3388 }
3389
3390 {
3391 DicomMap dicom;
3392 ASSERT_EQ(ValueRepresentation_OtherWord, dicom.GuessPixelDataValueRepresentation(DicomTransferSyntax_LittleEndianImplicit));
3393 }
3394
3395 {
3396 ParsedDicomFile dicom(true);
3397 ASSERT_TRUE(dicom.GetDcmtkObject().getDataset()->putAndInsertUint16(DCM_BitsAllocated, bitsAllocated).good());
3398 ASSERT_TRUE(dicom.GetDcmtkObject().chooseRepresentation(EXS_LittleEndianImplicit, NULL).good());
3399 dicom.GetDcmtkObject().removeAllButCurrentRepresentations();
3400 ASSERT_EQ(ValueRepresentation_OtherWord, dicom.GuessPixelDataValueRepresentation());
3401 }
3402 }
3403
3372 } 3404 }
3373 3405
3374 // Explicit little and big endian with <= 8 bpp is OB 3406 // Explicit little and big endian with <= 8 bpp is OB
3375 3407
3376 for (unsigned int i = 0; i < 2; i++) 3408 for (unsigned int i = 0; i < 2; i++)
3380 { 3412 {
3381 case 0: bitsAllocated = 1; break; 3413 case 0: bitsAllocated = 1; break;
3382 case 1: bitsAllocated = 8; break; 3414 case 1: bitsAllocated = 8; break;
3383 default: 3415 default:
3384 throw OrthancException(ErrorCode_InternalError); 3416 throw OrthancException(ErrorCode_InternalError);
3417 }
3418
3419 ASSERT_EQ(ValueRepresentation_OtherByte, DicomImageInformation::GuessPixelDataValueRepresentation(DicomTransferSyntax_LittleEndianExplicit, bitsAllocated));
3420 ASSERT_EQ(ValueRepresentation_OtherByte, DicomImageInformation::GuessPixelDataValueRepresentation(DicomTransferSyntax_BigEndianExplicit, bitsAllocated));
3421
3422 {
3423 DicomMap dicom;
3424 dicom.SetValue(DICOM_TAG_BITS_ALLOCATED, boost::lexical_cast<std::string>(bitsAllocated), false);
3425 ASSERT_EQ(ValueRepresentation_OtherByte, dicom.GuessPixelDataValueRepresentation(DicomTransferSyntax_LittleEndianExplicit));
3426 ASSERT_EQ(ValueRepresentation_OtherByte, dicom.GuessPixelDataValueRepresentation(DicomTransferSyntax_BigEndianExplicit));
3427 }
3428
3429 {
3430 DicomMap dicom;
3431 ASSERT_EQ(ValueRepresentation_OtherByte, dicom.GuessPixelDataValueRepresentation(DicomTransferSyntax_LittleEndianExplicit));
3432 ASSERT_EQ(ValueRepresentation_OtherByte, dicom.GuessPixelDataValueRepresentation(DicomTransferSyntax_BigEndianExplicit));
3385 } 3433 }
3386 3434
3387 { 3435 {
3388 ParsedDicomFile dicom(true); 3436 ParsedDicomFile dicom(true);
3389 ASSERT_TRUE(dicom.GetDcmtkObject().getDataset()->putAndInsertUint16(DCM_BitsAllocated, bitsAllocated).good()); 3437 ASSERT_TRUE(dicom.GetDcmtkObject().getDataset()->putAndInsertUint16(DCM_BitsAllocated, bitsAllocated).good());
3400 ASSERT_EQ(ValueRepresentation_OtherByte, dicom.GuessPixelDataValueRepresentation()); 3448 ASSERT_EQ(ValueRepresentation_OtherByte, dicom.GuessPixelDataValueRepresentation());
3401 } 3449 }
3402 } 3450 }
3403 3451
3404 // Explicit little and big endian with > 8 bpp is OW 3452 // Explicit little and big endian with > 8 bpp is OW
3453
3454 ASSERT_EQ(ValueRepresentation_OtherWord, DicomImageInformation::GuessPixelDataValueRepresentation(DicomTransferSyntax_LittleEndianExplicit, 16));
3455 ASSERT_EQ(ValueRepresentation_OtherWord, DicomImageInformation::GuessPixelDataValueRepresentation(DicomTransferSyntax_BigEndianExplicit, 16));
3456
3457 {
3458 DicomMap dicom;
3459 dicom.SetValue(DICOM_TAG_BITS_ALLOCATED, "16", false);
3460 ASSERT_EQ(ValueRepresentation_OtherWord, dicom.GuessPixelDataValueRepresentation(DicomTransferSyntax_LittleEndianExplicit));
3461 ASSERT_EQ(ValueRepresentation_OtherWord, dicom.GuessPixelDataValueRepresentation(DicomTransferSyntax_BigEndianExplicit));
3462 }
3405 3463
3406 { 3464 {
3407 ParsedDicomFile dicom(true); 3465 ParsedDicomFile dicom(true);
3408 ASSERT_TRUE(dicom.GetDcmtkObject().getDataset()->putAndInsertUint16(DCM_BitsAllocated, 16).good()); 3466 ASSERT_TRUE(dicom.GetDcmtkObject().getDataset()->putAndInsertUint16(DCM_BitsAllocated, 16).good());
3409 ASSERT_TRUE(dicom.GetDcmtkObject().chooseRepresentation(EXS_LittleEndianExplicit, NULL).good()); 3467 ASSERT_TRUE(dicom.GetDcmtkObject().chooseRepresentation(EXS_LittleEndianExplicit, NULL).good());