Mercurial > hg > orthanc
comparison Core/ImageFormats/ImageProcessing.cpp @ 859:610a9a1ed855 jpeg
ImageProcessing::Convert
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 06 Jun 2014 18:12:31 +0200 |
parents | ff530685e46a |
children | 80c7e53a69b5 |
comparison
equal
deleted
inserted
replaced
858:ebc41566f742 | 859:610a9a1ed855 |
---|---|
35 | 35 |
36 #include "../OrthancException.h" | 36 #include "../OrthancException.h" |
37 | 37 |
38 #include <cassert> | 38 #include <cassert> |
39 #include <string.h> | 39 #include <string.h> |
40 #include <limits> | |
41 #include <stdint.h> | |
42 | |
43 #include <stdio.h> | |
40 | 44 |
41 namespace Orthanc | 45 namespace Orthanc |
42 { | 46 { |
47 template <typename TargetType, typename SourceType> | |
48 static void ConvertInternal(ImageAccessor& target, | |
49 const ImageAccessor& source) | |
50 { | |
51 const TargetType minValue = std::numeric_limits<TargetType>::min(); | |
52 const TargetType maxValue = std::numeric_limits<TargetType>::max(); | |
53 | |
54 for (unsigned int y = 0; y < source.GetHeight(); y++) | |
55 { | |
56 TargetType* t = reinterpret_cast<TargetType*>(target.GetRow(y)); | |
57 const SourceType* s = reinterpret_cast<const SourceType*>(source.GetConstRow(y)); | |
58 | |
59 for (unsigned int x = 0; x < source.GetWidth(); x++, t++, s++) | |
60 { | |
61 if (static_cast<int32_t>(*s) < static_cast<int32_t>(minValue)) | |
62 { | |
63 *t = minValue; | |
64 } | |
65 else if (static_cast<int32_t>(*s) > static_cast<int32_t>(maxValue)) | |
66 { | |
67 *t = maxValue; | |
68 } | |
69 else | |
70 { | |
71 *t = static_cast<TargetType>(*s); | |
72 } | |
73 } | |
74 } | |
75 } | |
76 | |
77 | |
78 | |
43 void ImageProcessing::Copy(ImageAccessor& target, | 79 void ImageProcessing::Copy(ImageAccessor& target, |
44 const ImageAccessor& source) | 80 const ImageAccessor& source) |
45 { | 81 { |
46 if (target.GetWidth() != source.GetWidth() || | 82 if (target.GetWidth() != source.GetWidth() || |
47 target.GetHeight() != source.GetHeight()) | 83 target.GetHeight() != source.GetHeight()) |
78 { | 114 { |
79 Copy(target, source); | 115 Copy(target, source); |
80 return; | 116 return; |
81 } | 117 } |
82 | 118 |
119 if (target.GetFormat() == PixelFormat_Grayscale16 && | |
120 source.GetFormat() == PixelFormat_Grayscale8) | |
121 { | |
122 ConvertInternal<uint16_t, uint8_t>(target, source); | |
123 return; | |
124 } | |
125 | |
126 if (target.GetFormat() == PixelFormat_SignedGrayscale16 && | |
127 source.GetFormat() == PixelFormat_Grayscale8) | |
128 { | |
129 ConvertInternal<int16_t, uint8_t>(target, source); | |
130 return; | |
131 } | |
132 | |
133 if (target.GetFormat() == PixelFormat_Grayscale8 && | |
134 source.GetFormat() == PixelFormat_Grayscale16) | |
135 { | |
136 printf("ICI\n"); | |
137 ConvertInternal<uint8_t, uint16_t>(target, source); | |
138 return; | |
139 } | |
140 | |
141 if (target.GetFormat() == PixelFormat_SignedGrayscale16 && | |
142 source.GetFormat() == PixelFormat_Grayscale16) | |
143 { | |
144 ConvertInternal<int16_t, uint16_t>(target, source); | |
145 return; | |
146 } | |
147 | |
148 if (target.GetFormat() == PixelFormat_Grayscale8 && | |
149 source.GetFormat() == PixelFormat_SignedGrayscale16) | |
150 { | |
151 printf("ICI2\n"); | |
152 ConvertInternal<uint8_t, int16_t>(target, source); | |
153 return; | |
154 } | |
155 | |
156 if (target.GetFormat() == PixelFormat_Grayscale16 && | |
157 source.GetFormat() == PixelFormat_SignedGrayscale16) | |
158 { | |
159 ConvertInternal<uint16_t, int16_t>(target, source); | |
160 return; | |
161 } | |
162 | |
83 throw OrthancException(ErrorCode_NotImplemented); | 163 throw OrthancException(ErrorCode_NotImplemented); |
84 } | 164 } |
85 | 165 |
86 | 166 |
87 void ImageProcessing::ShiftRight(ImageAccessor& image, | 167 void ImageProcessing::ShiftRight(ImageAccessor& image, |