comparison Core/Images/ImageProcessing.cpp @ 3234:3ca924140de6

merged ImageProcessing::Invert implementations
author am@osimis.io
date Fri, 15 Feb 2019 10:37:58 +0100
parents 53bb1f4b3844
children 6f652c7bfc85
comparison
equal deleted inserted replaced
3227:53bb1f4b3844 3234:3ca924140de6
1084 1084
1085 switch (image.GetFormat()) 1085 switch (image.GetFormat())
1086 { 1086 {
1087 case PixelFormat_Grayscale16: 1087 case PixelFormat_Grayscale16:
1088 { 1088 {
1089 uint16_t maxValueUint16 = (uint16_t)maxValue; 1089 uint16_t maxValueUint16 = (uint16_t)(std::min(maxValue, static_cast<int64_t>(std::numeric_limits<uint16_t>::max())));
1090 1090
1091 for (unsigned int y = 0; y < height; y++) 1091 for (unsigned int y = 0; y < height; y++)
1092 { 1092 {
1093 uint16_t* p = reinterpret_cast<uint16_t*>(image.GetRow(y)); 1093 uint16_t* p = reinterpret_cast<uint16_t*>(image.GetRow(y));
1094 1094
1095 for (unsigned int x = 0; x < width; x++, p++) 1095 for (unsigned int x = 0; x < width; x++, p++)
1096 { 1096 {
1097 *p = maxValueUint16 - (*p); 1097 *p = maxValueUint16 - (*p);
1098 }
1099 }
1100
1101 return;
1102 }
1103 case PixelFormat_Grayscale8:
1104 {
1105 uint8_t maxValueUint8 = (uint8_t)(std::min(maxValue, static_cast<int64_t>(std::numeric_limits<uint8_t>::max())));
1106
1107 for (unsigned int y = 0; y < height; y++)
1108 {
1109 uint8_t* p = reinterpret_cast<uint8_t*>(image.GetRow(y));
1110
1111 for (unsigned int x = 0; x < width; x++, p++)
1112 {
1113 *p = maxValueUint8 - (*p);
1098 } 1114 }
1099 } 1115 }
1100 1116
1101 return; 1117 return;
1102 } 1118 }
1107 1123
1108 } 1124 }
1109 1125
1110 void ImageProcessing::Invert(ImageAccessor& image) 1126 void ImageProcessing::Invert(ImageAccessor& image)
1111 { 1127 {
1112 const unsigned int width = image.GetWidth();
1113 const unsigned int height = image.GetHeight();
1114
1115 switch (image.GetFormat()) 1128 switch (image.GetFormat())
1116 { 1129 {
1117 case PixelFormat_Grayscale8: 1130 case PixelFormat_Grayscale8:
1118 { 1131 return Invert(image, 255);
1119 for (unsigned int y = 0; y < height; y++)
1120 {
1121 uint8_t* p = reinterpret_cast<uint8_t*>(image.GetRow(y));
1122
1123 for (unsigned int x = 0; x < width; x++, p++)
1124 {
1125 *p = 255 - (*p);
1126 }
1127 }
1128
1129 return;
1130 }
1131
1132 default: 1132 default:
1133 throw OrthancException(ErrorCode_NotImplemented); 1133 throw OrthancException(ErrorCode_NotImplemented); // you should use the Invert(image, maxValue) overload
1134 } 1134 }
1135 } 1135 }
1136 1136
1137 1137
1138 1138