Mercurial > hg > orthanc
comparison OrthancServer/FromDcmtkBridge.cpp @ 368:80011cd589e6
support of rgb images
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 18 Feb 2013 16:07:28 +0100 |
parents | 760d0f32cb34 |
children | 4632a044746e |
comparison
equal
deleted
inserted
replaced
367:301f2831489c | 368:80011cd589e6 |
---|---|
1018 FromDcmtkBridge::ToJson(target, *dicom.getDataset(), maxStringLength); | 1018 FromDcmtkBridge::ToJson(target, *dicom.getDataset(), maxStringLength); |
1019 } | 1019 } |
1020 } | 1020 } |
1021 | 1021 |
1022 | 1022 |
1023 static void ExtractPngImagePreview(std::string& result, | 1023 static void ExtractPngImageColorPreview(std::string& result, |
1024 DicomIntegerPixelAccessor& accessor) | 1024 DicomIntegerPixelAccessor& accessor) |
1025 { | 1025 { |
1026 assert(accessor.GetChannelCount() == 3); | |
1027 PngWriter w; | |
1028 | |
1029 std::vector<uint8_t> image(accessor.GetWidth() * accessor.GetHeight() * 3, 0); | |
1030 uint8_t* pixel = &image[0]; | |
1031 | |
1032 for (unsigned int y = 0; y < accessor.GetHeight(); y++) | |
1033 { | |
1034 for (unsigned int x = 0; x < accessor.GetWidth(); x++) | |
1035 { | |
1036 for (unsigned int c = 0; c < 3; c++, pixel++) | |
1037 { | |
1038 int32_t v = accessor.GetValue(x, y, c); | |
1039 if (v < 0) | |
1040 *pixel = 0; | |
1041 else if (v > 255) | |
1042 *pixel = 255; | |
1043 else | |
1044 *pixel = v; | |
1045 } | |
1046 } | |
1047 } | |
1048 | |
1049 w.WriteToMemory(result, accessor.GetWidth(), accessor.GetHeight(), | |
1050 accessor.GetWidth() * 3, PixelFormat_RGB24, &image[0]); | |
1051 } | |
1052 | |
1053 | |
1054 static void ExtractPngImageGrayscalePreview(std::string& result, | |
1055 DicomIntegerPixelAccessor& accessor) | |
1056 { | |
1057 assert(accessor.GetChannelCount() == 1); | |
1026 PngWriter w; | 1058 PngWriter w; |
1027 | 1059 |
1028 int32_t min, max; | 1060 int32_t min, max; |
1029 accessor.GetExtremeValues(min, max); | 1061 accessor.GetExtremeValues(min, max); |
1030 | 1062 |
1052 template <typename T> | 1084 template <typename T> |
1053 static void ExtractPngImageTruncate(std::string& result, | 1085 static void ExtractPngImageTruncate(std::string& result, |
1054 DicomIntegerPixelAccessor& accessor, | 1086 DicomIntegerPixelAccessor& accessor, |
1055 PixelFormat format) | 1087 PixelFormat format) |
1056 { | 1088 { |
1089 assert(accessor.GetChannelCount() == 1); | |
1090 | |
1057 PngWriter w; | 1091 PngWriter w; |
1058 | 1092 |
1059 std::vector<T> image(accessor.GetWidth() * accessor.GetHeight(), 0); | 1093 std::vector<T> image(accessor.GetWidth() * accessor.GetHeight(), 0); |
1060 T* pixel = &image[0]; | 1094 T* pixel = &image[0]; |
1061 for (unsigned int y = 0; y < accessor.GetHeight(); y++) | 1095 for (unsigned int y = 0; y < accessor.GetHeight(); y++) |
1206 accessor.reset(new DicomIntegerPixelAccessor(m, pixData, privateContent.size())); | 1240 accessor.reset(new DicomIntegerPixelAccessor(m, pixData, privateContent.size())); |
1207 accessor->SetCurrentFrame(frame); | 1241 accessor->SetCurrentFrame(frame); |
1208 } | 1242 } |
1209 | 1243 |
1210 PixelFormat format; | 1244 PixelFormat format; |
1245 | |
1246 if (accessor->GetChannelCount() != 1 && | |
1247 (mode == ImageExtractionMode_UInt8 || | |
1248 mode == ImageExtractionMode_UInt16)) | |
1249 { | |
1250 throw OrthancException(ErrorCode_NotImplemented); | |
1251 } | |
1252 | |
1211 switch (mode) | 1253 switch (mode) |
1212 { | 1254 { |
1213 case ImageExtractionMode_Preview: | 1255 case ImageExtractionMode_Preview: |
1256 switch (accessor->GetChannelCount()) | |
1257 { | |
1258 case 1: | |
1259 format = PixelFormat_Grayscale8; | |
1260 break; | |
1261 | |
1262 case 3: | |
1263 format = PixelFormat_RGB24; | |
1264 break; | |
1265 | |
1266 default: | |
1267 throw OrthancException(ErrorCode_NotImplemented); | |
1268 } | |
1269 break; | |
1270 | |
1214 case ImageExtractionMode_UInt8: | 1271 case ImageExtractionMode_UInt8: |
1215 format = PixelFormat_Grayscale8; | 1272 format = PixelFormat_Grayscale8; |
1216 break; | 1273 break; |
1217 | 1274 |
1218 case ImageExtractionMode_UInt16: | 1275 case ImageExtractionMode_UInt16: |
1233 else | 1290 else |
1234 { | 1291 { |
1235 switch (mode) | 1292 switch (mode) |
1236 { | 1293 { |
1237 case ImageExtractionMode_Preview: | 1294 case ImageExtractionMode_Preview: |
1238 ExtractPngImagePreview(result, *accessor); | 1295 if (format == PixelFormat_Grayscale8) |
1296 ExtractPngImageGrayscalePreview(result, *accessor); | |
1297 else | |
1298 ExtractPngImageColorPreview(result, *accessor); | |
1239 break; | 1299 break; |
1240 | 1300 |
1241 case ImageExtractionMode_UInt8: | 1301 case ImageExtractionMode_UInt8: |
1242 ExtractPngImageTruncate<uint8_t>(result, *accessor, format); | 1302 ExtractPngImageTruncate<uint8_t>(result, *accessor, format); |
1243 break; | 1303 break; |