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())); |
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, |
(...skipping 13 matching lines...) Expand all Loading... | |
434 fSwizzler.reset(nullptr); | 433 fSwizzler.reset(nullptr); |
435 fSrcRow = nullptr; | 434 fSrcRow = nullptr; |
436 fStorage.free(); | 435 fStorage.free(); |
437 | 436 |
438 // Now, given valid output dimensions, we can start the decompress | 437 // Now, given valid output dimensions, we can start the decompress |
439 if (!jpeg_start_decompress(fDecoderMgr->dinfo())) { | 438 if (!jpeg_start_decompress(fDecoderMgr->dinfo())) { |
440 SkCodecPrintf("start decompress failed\n"); | 439 SkCodecPrintf("start decompress failed\n"); |
441 return kInvalidInput; | 440 return kInvalidInput; |
442 } | 441 } |
443 | 442 |
443 // We will need a sampler if we are performing a subset decode | |
444 if (options.fSubset) { | |
445 this->getSampler(true); | |
scroggo
2015/10/08 20:16:08
As mentioned elsewhere, you don't need to have the
msarett
2015/10/09 20:03:44
Yes, there is a better way to do this.
| |
446 } | |
447 | |
444 return kSuccess; | 448 return kSuccess; |
445 } | 449 } |
446 | 450 |
447 int SkJpegCodec::onGetScanlines(void* dst, int count, size_t rowBytes) { | 451 int SkJpegCodec::onGetScanlines(void* dst, int count, size_t rowBytes) { |
448 // Set the jump location for libjpeg errors | 452 // Set the jump location for libjpeg errors |
449 if (setjmp(fDecoderMgr->getJmpBuf())) { | 453 if (setjmp(fDecoderMgr->getJmpBuf())) { |
450 return fDecoderMgr->returnFailure("setjmp", kInvalidInput); | 454 return fDecoderMgr->returnFailure("setjmp", kInvalidInput); |
451 } | 455 } |
452 // Read rows one at a time | 456 // Read rows one at a time |
453 JSAMPLE* dstRow; | 457 JSAMPLE* dstRow; |
454 if (fSwizzler) { | 458 if (fSwizzler) { |
455 // write data to storage row, then sample using swizzler | 459 // write data to storage row, then sample using swizzler |
456 dstRow = fSrcRow; | 460 dstRow = fSrcRow; |
457 } else { | 461 } else { |
458 // write data directly to dst | 462 // write data directly to dst |
459 dstRow = (JSAMPLE*) dst; | 463 dstRow = (JSAMPLE*) dst; |
460 } | 464 } |
461 | 465 |
462 for (int y = 0; y < count; y++) { | 466 for (int y = 0; y < count; y++) { |
463 // Read row of the image | 467 // Read row of the image |
464 uint32_t rowsDecoded = jpeg_read_scanlines(fDecoderMgr->dinfo(), &dstRow , 1); | 468 uint32_t rowsDecoded = jpeg_read_scanlines(fDecoderMgr->dinfo(), &dstRow , 1); |
465 if (rowsDecoded != 1) { | 469 if (rowsDecoded != 1) { |
(...skipping 29 matching lines...) Expand all Loading... | |
495 #endif | 499 #endif |
496 | 500 |
497 bool SkJpegCodec::onSkipScanlines(int count) { | 501 bool SkJpegCodec::onSkipScanlines(int count) { |
498 // Set the jump location for libjpeg errors | 502 // Set the jump location for libjpeg errors |
499 if (setjmp(fDecoderMgr->getJmpBuf())) { | 503 if (setjmp(fDecoderMgr->getJmpBuf())) { |
500 return fDecoderMgr->returnFailure("setjmp", kInvalidInput); | 504 return fDecoderMgr->returnFailure("setjmp", kInvalidInput); |
501 } | 505 } |
502 | 506 |
503 return count == jpeg_skip_scanlines(fDecoderMgr->dinfo(), count); | 507 return count == jpeg_skip_scanlines(fDecoderMgr->dinfo(), count); |
504 } | 508 } |
OLD | NEW |