Mercurial > hg > orthanc
comparison PalanthirServer/DicomIntegerPixelAccessor.cpp @ 53:293038baf8f1
access to multi-frame images
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 10 Sep 2012 15:17:02 +0200 |
parents | a15e90e5d6fc |
children |
comparison
equal
deleted
inserted
replaced
52:e0cac5540668 | 53:293038baf8f1 |
---|---|
55 catch (boost::bad_lexical_cast) | 55 catch (boost::bad_lexical_cast) |
56 { | 56 { |
57 throw PalanthirException(ErrorCode_NotImplemented); | 57 throw PalanthirException(ErrorCode_NotImplemented); |
58 } | 58 } |
59 | 59 |
60 if (bitsAllocated != 8 && bitsAllocated != 16 && | 60 frame_ = 0; |
61 bitsAllocated != 24 && bitsAllocated != 32) | 61 try |
62 { | |
63 numberOfFrames_ = boost::lexical_cast<unsigned int>(FromDcmtkBridge::GetValue(values, "NumberOfFrames").AsString()); | |
64 } | |
65 catch (PalanthirException) | |
66 { | |
67 // If the tag "NumberOfFrames" is absent, assume there is a single frame | |
68 numberOfFrames_ = 1; | |
69 } | |
70 catch (boost::bad_lexical_cast) | |
71 { | |
72 throw PalanthirException(ErrorCode_NotImplemented); | |
73 } | |
74 | |
75 if ((bitsAllocated != 8 && bitsAllocated != 16 && | |
76 bitsAllocated != 24 && bitsAllocated != 32) || | |
77 numberOfFrames_ == 0) | |
62 { | 78 { |
63 throw PalanthirException(ErrorCode_NotImplemented); | 79 throw PalanthirException(ErrorCode_NotImplemented); |
64 } | 80 } |
65 | 81 |
66 if (bitsAllocated > 32 || | 82 if (bitsAllocated > 32 || |
67 bitsStored >= 32) | 83 bitsStored >= 32) |
68 { | 84 { |
69 // Not available, as the accessor internally uses int32_t values | 85 // Not available, as the accessor internally uses int32_t values |
70 throw PalanthirException(ErrorCode_NotImplemented); | 86 throw PalanthirException(ErrorCode_NotImplemented); |
71 } | 87 } |
72 | 88 |
73 if (samplesPerPixel_ != 1) | 89 if (samplesPerPixel_ != 1) |
74 { | 90 { |
75 throw PalanthirException(ErrorCode_NotImplemented); | 91 throw PalanthirException(ErrorCode_NotImplemented); |
76 } | 92 } |
77 | 93 |
78 if (width_ * height_ * bitsAllocated / 8 != size) | 94 if (width_ * height_ * bitsAllocated / 8 * numberOfFrames_ != size) |
79 { | 95 { |
80 throw PalanthirException(ErrorCode_NotImplemented); | 96 throw PalanthirException(ErrorCode_NotImplemented); |
81 } | 97 } |
82 | 98 |
83 /*printf("%d %d %d %d %d %d %d\n", width_, height_, samplesPerPixel_, bitsAllocated, | 99 /*printf("%d %d %d %d %d %d %d %d\n", width_, height_, samplesPerPixel_, bitsAllocated, |
84 bitsStored, highBit, pixelRepresentation);*/ | 100 bitsStored, highBit, pixelRepresentation, numberOfFrames_);*/ |
85 | 101 |
86 bytesPerPixel_ = bitsAllocated / 8; | 102 bytesPerPixel_ = bitsAllocated / 8; |
87 shift_ = highBit + 1 - bitsStored; | 103 shift_ = highBit + 1 - bitsStored; |
88 | 104 |
89 if (pixelRepresentation) | 105 if (pixelRepresentation) |
94 else | 110 else |
95 { | 111 { |
96 mask_ = (1 << bitsStored) - 1; | 112 mask_ = (1 << bitsStored) - 1; |
97 signMask_ = 0; | 113 signMask_ = 0; |
98 } | 114 } |
115 | |
116 rowOffset_ = width_ * bytesPerPixel_; | |
117 frameOffset_ = height_ * width_ * bytesPerPixel_; | |
99 } | 118 } |
100 | 119 |
101 | 120 |
102 void DicomIntegerPixelAccessor::GetExtremeValues(int32_t& min, | 121 void DicomIntegerPixelAccessor::GetExtremeValues(int32_t& min, |
103 int32_t& max) const | 122 int32_t& max) const |
127 | 146 |
128 int32_t DicomIntegerPixelAccessor::GetValue(unsigned int x, unsigned int y) const | 147 int32_t DicomIntegerPixelAccessor::GetValue(unsigned int x, unsigned int y) const |
129 { | 148 { |
130 assert(x < width_ && y < height_); | 149 assert(x < width_ && y < height_); |
131 | 150 |
132 const uint8_t* pixel = reinterpret_cast<const uint8_t*>(pixelData_) + (y * width_ + x) * bytesPerPixel_; | 151 const uint8_t* pixel = reinterpret_cast<const uint8_t*>(pixelData_) + |
152 y * rowOffset_ + x * bytesPerPixel_ + frame_ * frameOffset_; | |
133 | 153 |
134 int32_t v; | 154 int32_t v; |
135 v = pixel[0]; | 155 v = pixel[0]; |
136 if (bytesPerPixel_ >= 2) | 156 if (bytesPerPixel_ >= 2) |
137 v = v + (static_cast<int32_t>(pixel[1]) << 8); | 157 v = v + (static_cast<int32_t>(pixel[1]) << 8); |
149 v = 0; | 169 v = 0; |
150 } | 170 } |
151 | 171 |
152 return v; | 172 return v; |
153 } | 173 } |
174 | |
175 | |
176 void DicomIntegerPixelAccessor::SetCurrentFrame(unsigned int frame) | |
177 { | |
178 if (frame >= numberOfFrames_) | |
179 { | |
180 throw PalanthirException(ErrorCode_ParameterOutOfRange); | |
181 } | |
182 | |
183 frame_ = frame; | |
184 } | |
185 | |
154 } | 186 } |