OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkCodec.h" | 8 #include "SkCodec.h" |
9 #include "SkJpegCodec.h" | 9 #include "SkJpegCodec.h" |
10 #include "SkJpegDecoderMgr.h" | 10 #include "SkJpegDecoderMgr.h" |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 } | 170 } |
171 | 171 |
172 /* | 172 /* |
173 * Return a valid set of output dimensions for this decoder, given an input scal
e | 173 * Return a valid set of output dimensions for this decoder, given an input scal
e |
174 */ | 174 */ |
175 SkISize SkJpegCodec::onGetScaledDimensions(float desiredScale) const { | 175 SkISize SkJpegCodec::onGetScaledDimensions(float desiredScale) const { |
176 // libjpeg-turbo supports scaling by 1/8, 1/4, 3/8, 1/2, 5/8, 3/4, 7/8, and
1/1, so we will | 176 // libjpeg-turbo supports scaling by 1/8, 1/4, 3/8, 1/2, 5/8, 3/4, 7/8, and
1/1, so we will |
177 // support these as well | 177 // support these as well |
178 unsigned int num; | 178 unsigned int num; |
179 unsigned int denom = 8; | 179 unsigned int denom = 8; |
180 if (desiredScale > 0.875f) { | 180 if (desiredScale >= 0.9375) { |
181 num = 8; | 181 num = 8; |
182 } else if (desiredScale > 0.75f) { | 182 } else if (desiredScale >= 0.8125) { |
183 num = 7; | 183 num = 7; |
184 } else if (desiredScale > 0.625f) { | 184 } else if (desiredScale >= 0.6875f) { |
185 num = 6; | 185 num = 6; |
186 } else if (desiredScale > 0.5f) { | 186 } else if (desiredScale >= 0.5625f) { |
187 num = 5; | 187 num = 5; |
188 } else if (desiredScale > 0.375f) { | 188 } else if (desiredScale >= 0.4375f) { |
189 num = 4; | 189 num = 4; |
190 } else if (desiredScale > 0.25f) { | 190 } else if (desiredScale >= 0.3125f) { |
191 num = 3; | 191 num = 3; |
192 } else if (desiredScale > 0.125f) { | 192 } else if (desiredScale >= 0.1875f) { |
193 num = 2; | 193 num = 2; |
194 } else { | 194 } else { |
195 num = 1; | 195 num = 1; |
196 } | 196 } |
197 | 197 |
198 // Set up a fake decompress struct in order to use libjpeg to calculate outp
ut dimensions | 198 // Set up a fake decompress struct in order to use libjpeg to calculate outp
ut dimensions |
199 jpeg_decompress_struct dinfo; | 199 jpeg_decompress_struct dinfo; |
200 sk_bzero(&dinfo, sizeof(dinfo)); | 200 sk_bzero(&dinfo, sizeof(dinfo)); |
201 dinfo.image_width = this->getInfo().width(); | 201 dinfo.image_width = this->getInfo().width(); |
202 dinfo.image_height = this->getInfo().height(); | 202 dinfo.image_height = this->getInfo().height(); |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
399 srcConfig = SkSwizzler::kBGRX; | 399 srcConfig = SkSwizzler::kBGRX; |
400 break; | 400 break; |
401 case kRGB_565_SkColorType: | 401 case kRGB_565_SkColorType: |
402 srcConfig = SkSwizzler::kRGB_565; | 402 srcConfig = SkSwizzler::kRGB_565; |
403 break; | 403 break; |
404 default: | 404 default: |
405 // This function should only be called if the colorType is supported
by jpeg | 405 // This function should only be called if the colorType is supported
by jpeg |
406 SkASSERT(false); | 406 SkASSERT(false); |
407 } | 407 } |
408 | 408 |
409 fSwizzler.reset(SkSwizzler::CreateSwizzler(srcConfig, nullptr, info, | 409 fSwizzler.reset(SkSwizzler::CreateSwizzler(srcConfig, nullptr, info, this->o
ptions().fZeroInitialized, 0, 0)); // TODO: get subset info from options object |
410 this->options().fZeroInitialized)
); | |
411 if (!fSwizzler) { | 410 if (!fSwizzler) { |
412 return nullptr; | 411 return nullptr; |
413 } | 412 } |
414 | 413 |
415 fStorage.reset(get_row_bytes(fDecoderMgr->dinfo())); | 414 fStorage.reset(get_row_bytes(fDecoderMgr->dinfo())); |
416 fSrcRow = static_cast<uint8_t*>(fStorage.get()); | 415 fSrcRow = static_cast<uint8_t*>(fStorage.get()); |
417 return fSwizzler; | 416 return fSwizzler; |
418 } | 417 } |
419 | 418 |
420 SkCodec::Result SkJpegCodec::onStartScanlineDecode(const SkImageInfo& dstInfo, | 419 SkCodec::Result SkJpegCodec::onStartScanlineDecode(const SkImageInfo& dstInfo, |
421 const Options& options, SkPMColor ctable[], int* ctableCount) { | 420 const Options& options, SkPMColor ctable[], int* ctableCount, int subset
Left, |
| 421 int subsetWidth) { |
422 // Set the jump location for libjpeg errors | 422 // Set the jump location for libjpeg errors |
423 if (setjmp(fDecoderMgr->getJmpBuf())) { | 423 if (setjmp(fDecoderMgr->getJmpBuf())) { |
424 SkCodecPrintf("setjmp: Error from libjpeg\n"); | 424 SkCodecPrintf("setjmp: Error from libjpeg\n"); |
425 return kInvalidInput; | 425 return kInvalidInput; |
426 } | 426 } |
427 | 427 |
428 // Check if we can decode to the requested destination and set the output co
lor space | 428 // Check if we can decode to the requested destination and set the output co
lor space |
429 if (!this->setOutputColorSpace(dstInfo)) { | 429 if (!this->setOutputColorSpace(dstInfo)) { |
430 return kInvalidConversion; | 430 return kInvalidConversion; |
431 } | 431 } |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
495 #endif | 495 #endif |
496 | 496 |
497 bool SkJpegCodec::onSkipScanlines(int count) { | 497 bool SkJpegCodec::onSkipScanlines(int count) { |
498 // Set the jump location for libjpeg errors | 498 // Set the jump location for libjpeg errors |
499 if (setjmp(fDecoderMgr->getJmpBuf())) { | 499 if (setjmp(fDecoderMgr->getJmpBuf())) { |
500 return fDecoderMgr->returnFailure("setjmp", kInvalidInput); | 500 return fDecoderMgr->returnFailure("setjmp", kInvalidInput); |
501 } | 501 } |
502 | 502 |
503 return count == jpeg_skip_scanlines(fDecoderMgr->dinfo(), count); | 503 return count == jpeg_skip_scanlines(fDecoderMgr->dinfo(), count); |
504 } | 504 } |
OLD | NEW |