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" |
11 #include "SkJpegUtility_codec.h" | 11 #include "SkJpegUtility_codec.h" |
12 #include "SkCodecPriv.h" | 12 #include "SkCodecPriv.h" |
13 #include "SkColorPriv.h" | 13 #include "SkColorPriv.h" |
14 #include "SkScaledCodec.h" | |
14 #include "SkScanlineDecoder.h" | 15 #include "SkScanlineDecoder.h" |
15 #include "SkStream.h" | 16 #include "SkStream.h" |
16 #include "SkTemplates.h" | 17 #include "SkTemplates.h" |
17 #include "SkTypes.h" | 18 #include "SkTypes.h" |
18 | 19 |
19 // stdio is needed for libjpeg-turbo | 20 // stdio is needed for libjpeg-turbo |
20 #include <stdio.h> | 21 #include <stdio.h> |
21 | 22 |
22 extern "C" { | 23 extern "C" { |
23 #include "jpeglibmangler.h" | 24 #include "jpeglibmangler.h" |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
139 streamDeleter.detach(); | 140 streamDeleter.detach(); |
140 return codec; | 141 return codec; |
141 } | 142 } |
142 return NULL; | 143 return NULL; |
143 } | 144 } |
144 | 145 |
145 SkJpegCodec::SkJpegCodec(const SkImageInfo& srcInfo, SkStream* stream, | 146 SkJpegCodec::SkJpegCodec(const SkImageInfo& srcInfo, SkStream* stream, |
146 JpegDecoderMgr* decoderMgr) | 147 JpegDecoderMgr* decoderMgr) |
147 : INHERITED(srcInfo, stream) | 148 : INHERITED(srcInfo, stream) |
148 , fDecoderMgr(decoderMgr) | 149 , fDecoderMgr(decoderMgr) |
150 , fPartialNum(1) | |
151 , fPartialDenom(1) | |
149 {} | 152 {} |
150 | 153 |
151 /* | 154 /* |
152 * Return a valid set of output dimensions for this decoder, given an input scal e | 155 * Return a valid set of output dimensions for this decoder, given an input scal e |
153 */ | 156 */ |
154 SkISize SkJpegCodec::onGetScaledDimensions(float desiredScale) const { | 157 SkISize SkJpegCodec::onGetScaledDimensions(float desiredScale) const { |
155 // 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 | 158 // 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 |
156 // support these as well | 159 // support these as well |
157 long num; | 160 long num; |
158 long denom = 8; | 161 long denom = 8; |
(...skipping 23 matching lines...) Expand all Loading... | |
182 dinfo.global_state = DSTATE_READY; | 185 dinfo.global_state = DSTATE_READY; |
183 dinfo.num_components = 0; | 186 dinfo.num_components = 0; |
184 dinfo.scale_num = num; | 187 dinfo.scale_num = num; |
185 dinfo.scale_denom = denom; | 188 dinfo.scale_denom = denom; |
186 turbo_jpeg_calc_output_dimensions(&dinfo); | 189 turbo_jpeg_calc_output_dimensions(&dinfo); |
187 | 190 |
188 // Return the calculated output dimensions for the given scale | 191 // Return the calculated output dimensions for the given scale |
189 return SkISize::Make(dinfo.output_width, dinfo.output_height); | 192 return SkISize::Make(dinfo.output_width, dinfo.output_height); |
190 } | 193 } |
191 | 194 |
195 // The swizzler is only used for sampling in the x direction | |
196 // when sampling a scanlineDecoder is used. The swizzler is not used in onGetPix els | |
197 SkCodec::Result SkJpegCodec::initializeSwizzler(const SkImageInfo& requestedInfo , | |
198 void* dst, size_t rowBytes, | |
199 const Options& options, | |
200 SkPMColor ctable[], | |
201 int* ctableCount, | |
202 int srcWidth) { | |
203 | |
204 const SkColorType srcColorType = requestedInfo.colorType(); | |
205 SkSwizzler::SrcConfig srcConfig; | |
206 switch (srcColorType) { | |
207 case kGray_8_SkColorType: | |
208 srcConfig = SkSwizzler::kGray; | |
209 break; | |
210 case kRGBA_8888_SkColorType: | |
211 srcConfig = SkSwizzler::kRGBX; | |
212 break; | |
213 case kBGRA_8888_SkColorType: | |
214 srcConfig = SkSwizzler::kBGRX; | |
215 break; | |
216 case kRGB_565_SkColorType: | |
217 srcConfig = SkSwizzler::kRGB_565; | |
218 break; | |
219 default: | |
220 //would have exited before now if the colorType was supported by jpe g | |
221 SkASSERT(false); | |
222 } | |
223 | |
224 fSwizzler.reset(SkSwizzler::CreateSwizzler(srcConfig, NULL, requestedInfo, | |
225 options.fZeroInitialized, srcWidt h)); | |
226 if (!fSwizzler) { | |
227 // FIXME: CreateSwizzler could fail for another reason. | |
228 return kUnimplemented; | |
229 } | |
230 return kSuccess; | |
231 } | |
232 | |
192 /* | 233 /* |
193 * Handles rewinding the input stream if it is necessary | 234 * Handles rewinding the input stream if it is necessary |
194 */ | 235 */ |
195 bool SkJpegCodec::handleRewind() { | 236 bool SkJpegCodec::handleRewind() { |
196 switch(this->rewindIfNeeded()) { | 237 switch(this->rewindIfNeeded()) { |
197 case kCouldNotRewind_RewindState: | 238 case kCouldNotRewind_RewindState: |
198 return fDecoderMgr->returnFalse("could not rewind"); | 239 return fDecoderMgr->returnFalse("could not rewind"); |
199 case kRewound_RewindState: { | 240 case kRewound_RewindState: { |
200 JpegDecoderMgr* decoderMgr = NULL; | 241 JpegDecoderMgr* decoderMgr = NULL; |
201 if (!ReadHeader(this->stream(), NULL, &decoderMgr)) { | 242 if (!ReadHeader(this->stream(), NULL, &decoderMgr)) { |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
265 // much faster than decoding to color and then converting | 306 // much faster than decoding to color and then converting |
266 fDecoderMgr->dinfo()->out_color_space = JCS_GRAYSCALE; | 307 fDecoderMgr->dinfo()->out_color_space = JCS_GRAYSCALE; |
267 } | 308 } |
268 return true; | 309 return true; |
269 default: | 310 default: |
270 return false; | 311 return false; |
271 } | 312 } |
272 } | 313 } |
273 | 314 |
274 /* | 315 /* |
275 * Checks if we can scale to the requested dimensions and scales the dimensions | 316 * Checks if we can natively scale to the requested dimensions and natively scal es the |
276 * if possible | 317 * dimensions if possible |
277 */ | 318 */ |
278 bool SkJpegCodec::scaleToDimensions(uint32_t dstWidth, uint32_t dstHeight) { | 319 bool SkJpegCodec::nativelyScaleToDimensions(uint32_t dstWidth, uint32_t dstHeigh t) { |
279 // libjpeg-turbo can scale to 1/8, 1/4, 3/8, 1/2, 5/8, 3/4, 7/8, and 1/1 | 320 // libjpeg-turbo can scale to 1/8, 1/4, 3/8, 1/2, 5/8, 3/4, 7/8, and 1/1 |
280 fDecoderMgr->dinfo()->scale_denom = 8; | 321 fDecoderMgr->dinfo()->scale_denom = 8; |
281 fDecoderMgr->dinfo()->scale_num = 8; | 322 fDecoderMgr->dinfo()->scale_num = 8; |
282 turbo_jpeg_calc_output_dimensions(fDecoderMgr->dinfo()); | 323 turbo_jpeg_calc_output_dimensions(fDecoderMgr->dinfo()); |
283 while (fDecoderMgr->dinfo()->output_width != dstWidth || | 324 while (fDecoderMgr->dinfo()->output_width != dstWidth || |
284 fDecoderMgr->dinfo()->output_height != dstHeight) { | 325 fDecoderMgr->dinfo()->output_height != dstHeight) { |
285 | 326 |
286 // Return a failure if we have tried all of the possible scales | 327 // Return a failure if we have tried all of the possible scales |
287 if (1 == fDecoderMgr->dinfo()->scale_num || | 328 if (1 == fDecoderMgr->dinfo()->scale_num || |
288 dstWidth > fDecoderMgr->dinfo()->output_width || | 329 dstWidth > fDecoderMgr->dinfo()->output_width || |
289 dstHeight > fDecoderMgr->dinfo()->output_height) { | 330 dstHeight > fDecoderMgr->dinfo()->output_height) { |
290 return fDecoderMgr->returnFalse("could not scale to requested dimens ions"); | 331 // reset native scale settings on failure because this may be suppor ted by the swizzler |
332 this->fDecoderMgr->dinfo()->scale_num = 8; | |
333 turbo_jpeg_calc_output_dimensions(this->fDecoderMgr->dinfo()); | |
334 return false; | |
291 } | 335 } |
292 | 336 |
293 // Try the next scale | 337 // Try the next scale |
294 fDecoderMgr->dinfo()->scale_num -= 1; | 338 fDecoderMgr->dinfo()->scale_num -= 1; |
295 turbo_jpeg_calc_output_dimensions(fDecoderMgr->dinfo()); | 339 turbo_jpeg_calc_output_dimensions(fDecoderMgr->dinfo()); |
296 } | 340 } |
297 return true; | 341 return true; |
298 } | 342 } |
299 | 343 |
344 int SkJpegCodec::onPartiallyNativelyScale(float desiredScale) { | |
msarett
2015/08/04 20:39:36
I think this function is clever :)
| |
345 float nativeScales[7] = {0.125, 0.25, 0.375, 0.5, 0.625, 0.75, 0.875}; | |
scroggo
2015/08/04 20:05:21
nit: I think these can (should?) be static const (
emmaleer
2015/08/05 14:47:51
Acknowledged.
| |
346 int numerators[7] = {1, 1, 3, 1, 5, 3, 7}; | |
347 int denomonators[7] = {8, 4, 8, 2, 8, 4, 8}; | |
348 | |
349 int index = 0; | |
350 int sampleSize = 1; | |
351 float totalScale = nativeScales[index] / sampleSize; | |
scroggo
2015/08/04 20:05:21
Can this just be "nativeScales[0]"?
Or do you thi
emmaleer
2015/08/05 14:47:51
Yes, it can just be gNativeScales[0]
| |
352 | |
353 while(totalScale != desiredScale) { | |
scroggo
2015/08/04 20:05:21
nit: there should be a space between while and (
emmaleer
2015/08/05 14:47:51
Acknowledged.
| |
354 if (totalScale < desiredScale) { | |
355 // scaling too much, scale less natively | |
356 if (index == 7) { | |
357 // have tried all possible combinations, partial native scaling not supported | |
358 return -1; | |
359 } | |
360 index++; | |
361 } else { | |
362 // not scaling enough, scale more by increasing sampleSize | |
363 sampleSize++; | |
364 } | |
365 totalScale = nativeScales[index] / sampleSize; | |
366 } | |
367 | |
368 // partial native scaling supported | |
369 fPartialDenom = denomonators[index]; | |
370 fPartialNum = numerators[index]; | |
371 | |
372 return sampleSize; | |
373 } | |
374 | |
300 /* | 375 /* |
301 * Performs the jpeg decode | 376 * Performs the jpeg decode |
302 */ | 377 */ |
303 SkCodec::Result SkJpegCodec::onGetPixels(const SkImageInfo& dstInfo, | 378 SkCodec::Result SkJpegCodec::onGetPixels(const SkImageInfo& dstInfo, |
304 void* dst, size_t dstRowBytes, | 379 void* dst, size_t dstRowBytes, |
305 const Options& options, SkPMColor*, int *) { | 380 const Options& options, SkPMColor*, int *) { |
306 // Rewind the stream if needed | 381 // Rewind the stream if needed |
307 if (!this->handleRewind()) { | 382 if (!this->handleRewind()) { |
308 return fDecoderMgr->returnFailure("could not rewind stream", kCouldNotRe wind); | 383 return fDecoderMgr->returnFailure("could not rewind stream", kCouldNotRe wind); |
309 } | 384 } |
(...skipping 10 matching lines...) Expand all Loading... | |
320 if (setjmp(fDecoderMgr->getJmpBuf())) { | 395 if (setjmp(fDecoderMgr->getJmpBuf())) { |
321 return fDecoderMgr->returnFailure("setjmp", kInvalidInput); | 396 return fDecoderMgr->returnFailure("setjmp", kInvalidInput); |
322 } | 397 } |
323 | 398 |
324 // Check if we can decode to the requested destination and set the output co lor space | 399 // Check if we can decode to the requested destination and set the output co lor space |
325 if (!this->setOutputColorSpace(dstInfo)) { | 400 if (!this->setOutputColorSpace(dstInfo)) { |
326 return fDecoderMgr->returnFailure("conversion_possible", kInvalidConvers ion); | 401 return fDecoderMgr->returnFailure("conversion_possible", kInvalidConvers ion); |
327 } | 402 } |
328 | 403 |
329 // Perform the necessary scaling | 404 // Perform the necessary scaling |
330 if (!this->scaleToDimensions(dstInfo.width(), dstInfo.height())) { | 405 if (!this->nativelyScaleToDimensions(dstInfo.width(), dstInfo.height())) { |
331 return fDecoderMgr->returnFailure("cannot scale to requested dims", kInv alidScale); | 406 return fDecoderMgr->returnFailure("cannot scale to requested dims", kInv alidScale); |
332 } | 407 } |
333 | 408 |
334 // Now, given valid output dimensions, we can start the decompress | 409 // Now, given valid output dimensions, we can start the decompress |
335 if (!turbo_jpeg_start_decompress(dinfo)) { | 410 if (!turbo_jpeg_start_decompress(dinfo)) { |
336 return fDecoderMgr->returnFailure("startDecompress", kInvalidInput); | 411 return fDecoderMgr->returnFailure("startDecompress", kInvalidInput); |
337 } | 412 } |
338 | 413 |
339 // The recommended output buffer height should always be 1 in high quality m odes. | 414 // The recommended output buffer height should always be 1 in high quality m odes. |
340 // If it's not, we want to know because it means our strategy is not optimal . | 415 // If it's not, we want to know because it means our strategy is not optimal . |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
387 /* | 462 /* |
388 * Enable scanline decoding for jpegs | 463 * Enable scanline decoding for jpegs |
389 */ | 464 */ |
390 class SkJpegScanlineDecoder : public SkScanlineDecoder { | 465 class SkJpegScanlineDecoder : public SkScanlineDecoder { |
391 public: | 466 public: |
392 SkJpegScanlineDecoder(const SkImageInfo& dstInfo, SkJpegCodec* codec, | 467 SkJpegScanlineDecoder(const SkImageInfo& dstInfo, SkJpegCodec* codec, |
393 const SkCodec::Options& opts) | 468 const SkCodec::Options& opts) |
394 : INHERITED(dstInfo) | 469 : INHERITED(dstInfo) |
395 , fCodec(codec) | 470 , fCodec(codec) |
396 , fOpts(opts) | 471 , fOpts(opts) |
397 {} | 472 { |
473 if(fCodec->fSwizzler) { | |
474 fStorage.reset(codec->fDecoderMgr->dinfo()->output_width * | |
msarett
2015/08/04 20:39:36
This will always be enough, but is overkill in the
emmaleer
2015/08/05 14:47:51
Acknowledged.
| |
475 codec->fDecoderMgr->dinfo()->out_color_components); | |
476 fSrcRow = static_cast<uint8_t*>(fStorage.get()); | |
477 } else { | |
478 fSrcRow = NULL; | |
479 } | |
480 } | |
398 | 481 |
399 virtual ~SkJpegScanlineDecoder() { | 482 virtual ~SkJpegScanlineDecoder() { |
400 if (setjmp(fCodec->fDecoderMgr->getJmpBuf())) { | 483 if (setjmp(fCodec->fDecoderMgr->getJmpBuf())) { |
401 SkCodecPrintf("setjmp: Error in libjpeg finish_decompress\n"); | 484 SkCodecPrintf("setjmp: Error in libjpeg finish_decompress\n"); |
402 return; | 485 return; |
403 } | 486 } |
404 | 487 |
405 // We may not have decoded the entire image. Prevent libjpeg-turbo from failing on a | 488 // We may not have decoded the entire image. Prevent libjpeg-turbo from failing on a |
406 // partial decode. | 489 // partial decode. |
407 fCodec->fDecoderMgr->dinfo()->output_scanline = fCodec->getInfo().height (); | 490 fCodec->fDecoderMgr->dinfo()->output_scanline = fCodec->getInfo().height (); |
408 turbo_jpeg_finish_decompress(fCodec->fDecoderMgr->dinfo()); | 491 turbo_jpeg_finish_decompress(fCodec->fDecoderMgr->dinfo()); |
409 } | 492 } |
410 | 493 |
411 SkCodec::Result onGetScanlines(void* dst, int count, size_t rowBytes) overri de { | 494 SkCodec::Result onGetScanlines(void* dst, int count, size_t rowBytes) overri de { |
412 // Set the jump location for libjpeg errors | 495 // Set the jump location for libjpeg errors |
413 if (setjmp(fCodec->fDecoderMgr->getJmpBuf())) { | 496 if (setjmp(fCodec->fDecoderMgr->getJmpBuf())) { |
414 return fCodec->fDecoderMgr->returnFailure("setjmp", SkCodec::kInvali dInput); | 497 return fCodec->fDecoderMgr->returnFailure("setjmp", SkCodec::kInvali dInput); |
415 } | 498 } |
499 // Read rows one at a time | |
500 JSAMPLE* dstRow; | |
501 if (fCodec->fSwizzler) { | |
502 // write data to storage row, then sample using swizzler | |
503 dstRow = fSrcRow; | |
504 } else { | |
505 // write data directly to dst | |
506 dstRow = (JSAMPLE*) dst; | |
507 } | |
416 | 508 |
417 // Read rows one at a time | |
418 JSAMPLE* dstRow = (JSAMPLE*) dst; | |
419 for (int y = 0; y < count; y++) { | 509 for (int y = 0; y < count; y++) { |
420 // Read row of the image | 510 // Read row of the image |
421 uint32_t rowsDecoded = | 511 uint32_t rowsDecoded = |
422 turbo_jpeg_read_scanlines(fCodec->fDecoderMgr->dinfo(), &dst Row, 1); | 512 turbo_jpeg_read_scanlines(fCodec->fDecoderMgr->dinfo(), &dst Row, 1); |
423 if (rowsDecoded != 1) { | 513 if (rowsDecoded != 1) { |
424 if (SkCodec::kNo_ZeroInitialized == fOpts.fZeroInitialized || | 514 if (SkCodec::kNo_ZeroInitialized == fOpts.fZeroInitialized || |
425 kN32_SkColorType == this->dstInfo().colorType()) { | 515 kN32_SkColorType == this->dstInfo().colorType()) { |
426 SkSwizzler::Fill(dstRow, this->dstInfo(), rowBytes, | 516 SkSwizzler::Fill(dstRow, this->dstInfo(), rowBytes, |
427 count - y, SK_ColorBLACK, NULL); | 517 count - y, SK_ColorBLACK, NULL); |
428 } | 518 } |
429 fCodec->fDecoderMgr->dinfo()->output_scanline = this->dstInfo(). height(); | 519 fCodec->fDecoderMgr->dinfo()->output_scanline = this->dstInfo(). height(); |
430 return SkCodec::kIncompleteInput; | 520 return SkCodec::kIncompleteInput; |
431 } | 521 } |
432 | 522 |
433 // Convert to RGBA if necessary | 523 // Convert to RGBA if necessary |
434 if (JCS_CMYK == fCodec->fDecoderMgr->dinfo()->out_color_space) { | 524 if (JCS_CMYK == fCodec->fDecoderMgr->dinfo()->out_color_space) { |
435 convert_CMYK_to_RGBA(dstRow, this->dstInfo().width()); | 525 convert_CMYK_to_RGBA(dstRow, fCodec->fDecoderMgr->dinfo()->outpu t_width); |
msarett
2015/08/04 20:39:36
Nice!
| |
436 } | 526 } |
437 | 527 |
438 // Move to the next row | 528 if(fCodec->fSwizzler) { |
439 dstRow = SkTAddOffset<JSAMPLE>(dstRow, rowBytes); | 529 // use swizzler to sample row |
530 fCodec->fSwizzler->swizzle(dst, dstRow); | |
531 dst = SkTAddOffset<JSAMPLE>(dst, rowBytes); | |
532 } else { | |
533 dstRow = SkTAddOffset<JSAMPLE>(dstRow, rowBytes); | |
534 } | |
440 } | 535 } |
441 | |
442 return SkCodec::kSuccess; | 536 return SkCodec::kSuccess; |
443 } | 537 } |
444 | 538 |
445 #ifndef TURBO_HAS_SKIP | 539 #ifndef TURBO_HAS_SKIP |
446 #define turbo_jpeg_skip_scanlines(dinfo, count) \ | 540 #define turbo_jpeg_skip_scanlines(dinfo, count) \ |
447 SkAutoMalloc storage(dinfo->output_width * dinfo->out_color_components); \ | 541 SkAutoMalloc storage(dinfo->output_width * dinfo->out_color_components); \ |
448 uint8_t* storagePtr = static_cast<uint8_t*>(storage.get()); \ | 542 uint8_t* storagePtr = static_cast<uint8_t*>(storage.get()); \ |
449 for (int y = 0; y < count; y++) { \ | 543 for (int y = 0; y < count; y++) { \ |
450 turbo_jpeg_read_scanlines(dinfo, &storagePtr, 1); \ | 544 turbo_jpeg_read_scanlines(dinfo, &storagePtr, 1); \ |
451 } | 545 } |
452 #endif | 546 #endif |
453 | 547 |
454 SkCodec::Result onSkipScanlines(int count) override { | 548 SkCodec::Result onSkipScanlines(int count) override { |
455 // Set the jump location for libjpeg errors | 549 // Set the jump location for libjpeg errors |
456 if (setjmp(fCodec->fDecoderMgr->getJmpBuf())) { | 550 if (setjmp(fCodec->fDecoderMgr->getJmpBuf())) { |
457 return fCodec->fDecoderMgr->returnFailure("setjmp", SkCodec::kInvali dInput); | 551 return fCodec->fDecoderMgr->returnFailure("setjmp", SkCodec::kInvali dInput); |
458 } | 552 } |
459 | 553 |
460 turbo_jpeg_skip_scanlines(fCodec->fDecoderMgr->dinfo(), count); | 554 turbo_jpeg_skip_scanlines(fCodec->fDecoderMgr->dinfo(), count); |
461 | 555 |
462 return SkCodec::kSuccess; | 556 return SkCodec::kSuccess; |
463 } | 557 } |
464 | 558 |
465 private: | 559 private: |
466 SkAutoTDelete<SkJpegCodec> fCodec; | 560 SkAutoTDelete<SkJpegCodec> fCodec; |
561 SkAutoMalloc fStorage; // Only used if sampling is needed | |
562 uint8_t* fSrcRow; // Only used if sampling is needed | |
467 const SkCodec::Options& fOpts; | 563 const SkCodec::Options& fOpts; |
468 | 564 |
469 typedef SkScanlineDecoder INHERITED; | 565 typedef SkScanlineDecoder INHERITED; |
470 }; | 566 }; |
471 | 567 |
472 SkScanlineDecoder* SkJpegCodec::onGetScanlineDecoder(const SkImageInfo& dstInfo, | 568 SkScanlineDecoder* SkJpegCodec::onGetScanlineDecoder(const SkImageInfo& dstInfo, |
473 const Options& options, SkPMColor ctable[], int* ctableCount) { | 569 const Options& options, SkPMColor ctable[], int* ctableCount) { |
474 | 570 |
475 // Rewind the stream if needed | 571 // Rewind the stream if needed |
476 if (!this->handleRewind()) { | 572 if (!this->handleRewind()) { |
(...skipping 15 matching lines...) Expand all Loading... | |
492 if (!codec) { | 588 if (!codec) { |
493 return NULL; | 589 return NULL; |
494 } | 590 } |
495 | 591 |
496 // Check if we can decode to the requested destination and set the output co lor space | 592 // Check if we can decode to the requested destination and set the output co lor space |
497 if (!codec->setOutputColorSpace(dstInfo)) { | 593 if (!codec->setOutputColorSpace(dstInfo)) { |
498 SkCodecPrintf("Cannot convert to output type\n"); | 594 SkCodecPrintf("Cannot convert to output type\n"); |
499 return NULL; | 595 return NULL; |
500 } | 596 } |
501 | 597 |
598 SkImageInfo scaledInfo = dstInfo; | |
599 | |
502 // Perform the necessary scaling | 600 // Perform the necessary scaling |
503 if (!codec->scaleToDimensions(dstInfo.width(), dstInfo.height())) { | 601 if (!codec->nativelyScaleToDimensions(dstInfo.width(), dstInfo.height())) { |
504 SkCodecPrintf("Cannot scale to output dimensions\n"); | 602 // full native scaling to dstInfo dimensions not supported |
505 return NULL; | 603 |
604 if (fPartialNum != 1 || fPartialDenom != 1) { | |
605 // update num and denom as partiallyNativelyScale was previously cal led | |
msarett
2015/08/04 20:39:36
Ah this is the part where we are unhappy. We need
| |
606 codec->fDecoderMgr->dinfo()->scale_denom = fPartialDenom; | |
607 codec->fDecoderMgr->dinfo()->scale_num = fPartialNum; | |
608 turbo_jpeg_calc_output_dimensions(codec->fDecoderMgr->dinfo()); | |
609 | |
610 // update scanlineDecoder's info to reflect partial native scaling | |
611 scaledInfo = dstInfo.makeWH(codec->fDecoderMgr->dinfo()->output_widt h, | |
612 codec->fDecoderMgr->dinfo()->output_heig ht); | |
613 } else { | |
614 // no native scaling (full or partial) supported | |
615 if (!SkScaledCodec::DimensionsSupportedForSampling(this->getInfo(), dstInfo)) { | |
616 return NULL; | |
617 } | |
618 } | |
619 // create swizzler for sampling | |
620 if (codec->initializeSwizzler(dstInfo, NULL, dstInfo.minRowBytes(), opti ons, ctable, | |
621 ctableCount, codec->fDecoderMgr->dinfo()-> output_width) | |
622 != kSuccess) { | |
623 SkCodecPrintf("failed to initialize the swizzler.\n"); | |
624 return NULL; | |
625 } | |
506 } | 626 } |
507 | 627 |
508 // Now, given valid output dimensions, we can start the decompress | 628 // Now, given valid output dimensions, we can start the decompress |
509 if (!turbo_jpeg_start_decompress(codec->fDecoderMgr->dinfo())) { | 629 if (!turbo_jpeg_start_decompress(codec->fDecoderMgr->dinfo())) { |
510 SkCodecPrintf("start decompress failed\n"); | 630 SkCodecPrintf("start decompress failed\n"); |
511 return NULL; | 631 return NULL; |
512 } | 632 } |
513 | 633 |
514 // Return the new scanline decoder | 634 // Return the new scanline decoder |
515 return SkNEW_ARGS(SkJpegScanlineDecoder, (dstInfo, codec.detach(), options)) ; | 635 return SkNEW_ARGS(SkJpegScanlineDecoder, (scaledInfo, codec.detach(), option s)); |
516 } | 636 } |
OLD | NEW |