133 if (this->width == 0 || this->height == 0)
134 throw std::logic_error{
"Unexpected dimensions (" +
135 imagePropertiesString(*
this) +
')'};
137 decltype(pixels.size()) expected{};
138 switch (colorspace) {
139 case Colorspace::Grayscale:
141 case BitsPerChannel::Sixteen:
143 case BitsPerPixel::Sixteen:
146 case BitsPerPixel::Eight:
148 case BitsPerPixel::TwentyFour:
150 case BitsPerPixel::FortyEight:
151 throw std::logic_error{
"Unexpected "
153 imagePropertiesString(*
this) +
')'};
156 expected = width * height * 2ul;
157 if (pixels.size() != expected)
158 throw std::logic_error{
"Unexpected pixel "
159 "length (expected = " +
160 std::to_string(expected) +
", actual = " +
161 std::to_string(pixels.size()) +
')'};
164 case BitsPerChannel::Eight:
166 case BitsPerPixel::Eight:
169 case BitsPerPixel::Sixteen:
171 case BitsPerPixel::TwentyFour:
173 case BitsPerPixel::FortyEight:
174 throw std::logic_error{
"Unexpected "
176 imagePropertiesString(*
this) +
')'};
179 expected = width * height;
180 if (pixels.size() != expected)
181 throw std::logic_error{
"Unexpected pixel "
182 "length (expected = " +
183 std::to_string(expected) +
", actual = " +
184 std::to_string(this->pixels.size()) +
')'};
190 case Colorspace::RGB:
192 case BitsPerChannel::Sixteen:
194 case BitsPerPixel::FortyEight:
197 case BitsPerPixel::Eight:
199 case BitsPerPixel::Sixteen:
201 case BitsPerPixel::TwentyFour:
202 throw std::logic_error{
"Unexpected "
204 imagePropertiesString(*
this) +
')'};
207 expected = width * height * (3ul * 2ul);
208 if (pixels.size() != expected)
209 throw std::logic_error{
"Unexpected pixel "
210 "length (expected = " +
211 std::to_string(expected) +
", actual = " +
212 std::to_string(this->pixels.size()) +
')'};
215 case BitsPerChannel::Eight:
217 case BitsPerPixel::TwentyFour:
220 case BitsPerPixel::Eight:
222 case BitsPerPixel::Sixteen:
224 case BitsPerPixel::FortyEight:
225 throw std::logic_error{
"Unexpected "
227 imagePropertiesString(*
this) +
')'};
230 expected = width * height * 3ul;
231 if (pixels.size() != expected)
232 throw std::logic_error{
"Unexpected pixel "
233 "length (expected = " +
234 std::to_string(expected) +
", actual = " +
235 std::to_string(this->pixels.size()) +
')'};
242 throw std::logic_error{
"Untested "
243 "combination (" + imagePropertiesString(*
this) +
')'};