Mercurial > hg > orthanc
comparison OrthancFramework/Sources/DicomParsing/ParsedDicomFile.cpp @ 4532:11bfea08341a Orthanc-1.9.1
fix ParsedDicomImage::EmbedImage() on big-endian
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 25 Feb 2021 16:52:32 +0100 |
parents | 8f9090b137f1 |
children | 94147ce2f097 |
comparison
equal
deleted
inserted
replaced
4531:d64e6f401a8a | 4532:11bfea08341a |
---|---|
102 #include <dcmtk/dcmdata/dcdict.h> | 102 #include <dcmtk/dcmdata/dcdict.h> |
103 #include <dcmtk/dcmdata/dcfilefo.h> | 103 #include <dcmtk/dcmdata/dcfilefo.h> |
104 #include <dcmtk/dcmdata/dcuid.h> | 104 #include <dcmtk/dcmdata/dcuid.h> |
105 #include <dcmtk/dcmdata/dcmetinf.h> | 105 #include <dcmtk/dcmdata/dcmetinf.h> |
106 #include <dcmtk/dcmdata/dcdeftag.h> | 106 #include <dcmtk/dcmdata/dcdeftag.h> |
107 #include <dcmtk/dcmdata/dcswap.h> | |
107 | 108 |
108 #include <dcmtk/dcmdata/dcvrae.h> | 109 #include <dcmtk/dcmdata/dcvrae.h> |
109 #include <dcmtk/dcmdata/dcvras.h> | 110 #include <dcmtk/dcmdata/dcvras.h> |
110 #include <dcmtk/dcmdata/dcvrcs.h> | 111 #include <dcmtk/dcmdata/dcvrcs.h> |
111 #include <dcmtk/dcmdata/dcvrda.h> | 112 #include <dcmtk/dcmdata/dcvrda.h> |
1387 pixels->createUint8Array(accessor.GetHeight() * pitch, target); | 1388 pixels->createUint8Array(accessor.GetHeight() * pitch, target); |
1388 | 1389 |
1389 const unsigned int height = accessor.GetHeight(); | 1390 const unsigned int height = accessor.GetHeight(); |
1390 const unsigned int width = accessor.GetWidth(); | 1391 const unsigned int width = accessor.GetWidth(); |
1391 | 1392 |
1392 for (unsigned int y = 0; y < height; y++) | 1393 { |
1393 { | 1394 Uint8* q = target; |
1394 switch (accessor.GetFormat()) | 1395 for (unsigned int y = 0; y < height; y++) |
1395 { | 1396 { |
1396 case PixelFormat_RGB24: | 1397 switch (accessor.GetFormat()) |
1397 case PixelFormat_Grayscale8: | |
1398 case PixelFormat_Grayscale16: | |
1399 case PixelFormat_SignedGrayscale16: | |
1400 { | 1398 { |
1401 memcpy(target, reinterpret_cast<const Uint8*>(accessor.GetConstRow(y)), pitch); | 1399 case PixelFormat_RGB24: |
1402 target += pitch; | 1400 case PixelFormat_Grayscale8: |
1403 break; | 1401 case PixelFormat_Grayscale16: |
1402 case PixelFormat_SignedGrayscale16: | |
1403 { | |
1404 memcpy(q, reinterpret_cast<const Uint8*>(accessor.GetConstRow(y)), pitch); | |
1405 q += pitch; | |
1406 break; | |
1407 } | |
1408 | |
1409 case PixelFormat_RGBA32: | |
1410 { | |
1411 // The alpha channel is not supported by the DICOM standard | |
1412 const Uint8* source = reinterpret_cast<const Uint8*>(accessor.GetConstRow(y)); | |
1413 for (unsigned int x = 0; x < width; x++, q += 3, source += 4) | |
1414 { | |
1415 q[0] = source[0]; | |
1416 q[1] = source[1]; | |
1417 q[2] = source[2]; | |
1418 } | |
1419 | |
1420 break; | |
1421 } | |
1422 | |
1423 default: | |
1424 throw OrthancException(ErrorCode_NotImplemented); | |
1404 } | 1425 } |
1405 | 1426 } |
1406 case PixelFormat_RGBA32: | 1427 } |
1407 { | 1428 |
1408 // The alpha channel is not supported by the DICOM standard | 1429 static const Endianness ENDIANNESS = Toolbox::DetectEndianness(); |
1409 const Uint8* source = reinterpret_cast<const Uint8*>(accessor.GetConstRow(y)); | 1430 if (ENDIANNESS == Endianness_Big && |
1410 for (unsigned int x = 0; x < width; x++, target += 3, source += 4) | 1431 (accessor.GetFormat() == PixelFormat_Grayscale16 || |
1411 { | 1432 accessor.GetFormat() == PixelFormat_SignedGrayscale16)) |
1412 target[0] = source[0]; | 1433 { |
1413 target[1] = source[1]; | 1434 // New in Orthanc 1.9.1 |
1414 target[2] = source[2]; | 1435 assert(pitch % 2 == 0); |
1415 } | 1436 swapBytes(target, accessor.GetHeight() * pitch, sizeof(uint16_t)); |
1416 | |
1417 break; | |
1418 } | |
1419 | |
1420 default: | |
1421 throw OrthancException(ErrorCode_NotImplemented); | |
1422 } | |
1423 } | 1437 } |
1424 | 1438 |
1425 if (!GetDcmtkObject().getDataset()->insert(pixels.release(), false, false).good()) | 1439 if (!GetDcmtkObject().getDataset()->insert(pixels.release(), false, false).good()) |
1426 { | 1440 { |
1427 throw OrthancException(ErrorCode_InternalError); | 1441 throw OrthancException(ErrorCode_InternalError); |