| 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 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 dinfo.global_state = DSTATE_READY; | 182 dinfo.global_state = DSTATE_READY; |
| 183 dinfo.num_components = 0; | 183 dinfo.num_components = 0; |
| 184 dinfo.scale_num = num; | 184 dinfo.scale_num = num; |
| 185 dinfo.scale_denom = denom; | 185 dinfo.scale_denom = denom; |
| 186 turbo_jpeg_calc_output_dimensions(&dinfo); | 186 turbo_jpeg_calc_output_dimensions(&dinfo); |
| 187 | 187 |
| 188 // Return the calculated output dimensions for the given scale | 188 // Return the calculated output dimensions for the given scale |
| 189 return SkISize::Make(dinfo.output_width, dinfo.output_height); | 189 return SkISize::Make(dinfo.output_width, dinfo.output_height); |
| 190 } | 190 } |
| 191 | 191 |
| 192 /* | 192 bool SkJpegCodec::onRewind() { |
| 193 * Handles rewinding the input stream if it is necessary | 193 JpegDecoderMgr* decoderMgr = NULL; |
| 194 */ | 194 if (!ReadHeader(this->stream(), NULL, &decoderMgr)) { |
| 195 bool SkJpegCodec::handleRewind() { | 195 return fDecoderMgr->returnFalse("could not rewind"); |
| 196 switch(this->rewindIfNeeded()) { | |
| 197 case kCouldNotRewind_RewindState: | |
| 198 return fDecoderMgr->returnFalse("could not rewind"); | |
| 199 case kRewound_RewindState: { | |
| 200 JpegDecoderMgr* decoderMgr = NULL; | |
| 201 if (!ReadHeader(this->stream(), NULL, &decoderMgr)) { | |
| 202 return fDecoderMgr->returnFalse("could not rewind"); | |
| 203 } | |
| 204 SkASSERT(NULL != decoderMgr); | |
| 205 fDecoderMgr.reset(decoderMgr); | |
| 206 return true; | |
| 207 } | |
| 208 case kNoRewindNecessary_RewindState: | |
| 209 return true; | |
| 210 default: | |
| 211 SkASSERT(false); | |
| 212 return false; | |
| 213 } | 196 } |
| 197 SkASSERT(NULL != decoderMgr); |
| 198 fDecoderMgr.reset(decoderMgr); |
| 199 return true; |
| 214 } | 200 } |
| 215 | 201 |
| 216 /* | 202 /* |
| 217 * Checks if the conversion between the input image and the requested output | 203 * Checks if the conversion between the input image and the requested output |
| 218 * image has been implemented | 204 * image has been implemented |
| 219 * Sets the output color space | 205 * Sets the output color space |
| 220 */ | 206 */ |
| 221 bool SkJpegCodec::setOutputColorSpace(const SkImageInfo& dst) { | 207 bool SkJpegCodec::setOutputColorSpace(const SkImageInfo& dst) { |
| 222 const SkImageInfo& src = this->getInfo(); | 208 const SkImageInfo& src = this->getInfo(); |
| 223 | 209 |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 return true; | 283 return true; |
| 298 } | 284 } |
| 299 | 285 |
| 300 /* | 286 /* |
| 301 * Performs the jpeg decode | 287 * Performs the jpeg decode |
| 302 */ | 288 */ |
| 303 SkCodec::Result SkJpegCodec::onGetPixels(const SkImageInfo& dstInfo, | 289 SkCodec::Result SkJpegCodec::onGetPixels(const SkImageInfo& dstInfo, |
| 304 void* dst, size_t dstRowBytes, | 290 void* dst, size_t dstRowBytes, |
| 305 const Options& options, SkPMColor*, int
*) { | 291 const Options& options, SkPMColor*, int
*) { |
| 306 // Rewind the stream if needed | 292 // Rewind the stream if needed |
| 307 if (!this->handleRewind()) { | 293 if (!this->rewindIfNeeded()) { |
| 308 return fDecoderMgr->returnFailure("could not rewind stream", kCouldNotRe
wind); | 294 return fDecoderMgr->returnFailure("could not rewind stream", kCouldNotRe
wind); |
| 309 } | 295 } |
| 310 | 296 |
| 311 if (options.fSubset) { | 297 if (options.fSubset) { |
| 312 // Subsets are not supported. | 298 // Subsets are not supported. |
| 313 return kUnimplemented; | 299 return kUnimplemented; |
| 314 } | 300 } |
| 315 | 301 |
| 316 // Get a pointer to the decompress info since we will use it quite frequentl
y | 302 // Get a pointer to the decompress info since we will use it quite frequentl
y |
| 317 jpeg_decompress_struct* dinfo = fDecoderMgr->dinfo(); | 303 jpeg_decompress_struct* dinfo = fDecoderMgr->dinfo(); |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 392 SkJpegScanlineDecoder(const SkImageInfo& srcInfo, SkJpegCodec* codec) | 378 SkJpegScanlineDecoder(const SkImageInfo& srcInfo, SkJpegCodec* codec) |
| 393 : INHERITED(srcInfo) | 379 : INHERITED(srcInfo) |
| 394 , fCodec(codec) | 380 , fCodec(codec) |
| 395 , fOpts() | 381 , fOpts() |
| 396 {} | 382 {} |
| 397 | 383 |
| 398 SkCodec::Result onStart(const SkImageInfo& dstInfo, const SkCodec::Options&
options, | 384 SkCodec::Result onStart(const SkImageInfo& dstInfo, const SkCodec::Options&
options, |
| 399 SkPMColor ctable[], int* ctableCount) override { | 385 SkPMColor ctable[], int* ctableCount) override { |
| 400 | 386 |
| 401 // Rewind the stream if needed | 387 // Rewind the stream if needed |
| 402 if (!fCodec->handleRewind()) { | 388 if (!fCodec->rewindIfNeeded()) { |
| 403 return SkCodec::kCouldNotRewind; | 389 return SkCodec::kCouldNotRewind; |
| 404 } | 390 } |
| 405 | 391 |
| 406 // Set the jump location for libjpeg errors | 392 // Set the jump location for libjpeg errors |
| 407 if (setjmp(fCodec->fDecoderMgr->getJmpBuf())) { | 393 if (setjmp(fCodec->fDecoderMgr->getJmpBuf())) { |
| 408 SkCodecPrintf("setjmp: Error from libjpeg\n"); | 394 SkCodecPrintf("setjmp: Error from libjpeg\n"); |
| 409 return SkCodec::kInvalidInput; | 395 return SkCodec::kInvalidInput; |
| 410 } | 396 } |
| 411 | 397 |
| 412 // Check if we can decode to the requested destination and set the outpu
t color space | 398 // Check if we can decode to the requested destination and set the outpu
t color space |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 506 SkScanlineDecoder* SkJpegCodec::NewSDFromStream(SkStream* stream) { | 492 SkScanlineDecoder* SkJpegCodec::NewSDFromStream(SkStream* stream) { |
| 507 SkAutoTDelete<SkJpegCodec> codec(static_cast<SkJpegCodec*>(SkJpegCodec::NewF
romStream(stream))); | 493 SkAutoTDelete<SkJpegCodec> codec(static_cast<SkJpegCodec*>(SkJpegCodec::NewF
romStream(stream))); |
| 508 if (!codec) { | 494 if (!codec) { |
| 509 return NULL; | 495 return NULL; |
| 510 } | 496 } |
| 511 | 497 |
| 512 const SkImageInfo& srcInfo = codec->getInfo(); | 498 const SkImageInfo& srcInfo = codec->getInfo(); |
| 513 // Return the new scanline decoder | 499 // Return the new scanline decoder |
| 514 return SkNEW_ARGS(SkJpegScanlineDecoder, (srcInfo, codec.detach())); | 500 return SkNEW_ARGS(SkJpegScanlineDecoder, (srcInfo, codec.detach())); |
| 515 } | 501 } |
| OLD | NEW |