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 "SkMSAN.h" | 9 #include "SkMSAN.h" |
10 #include "SkJpegCodec.h" | 10 #include "SkJpegCodec.h" |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 } | 256 } |
257 return nullptr; | 257 return nullptr; |
258 } | 258 } |
259 | 259 |
260 SkJpegCodec::SkJpegCodec(int width, int height, const SkEncodedInfo& info, SkStr
eam* stream, | 260 SkJpegCodec::SkJpegCodec(int width, int height, const SkEncodedInfo& info, SkStr
eam* stream, |
261 JpegDecoderMgr* decoderMgr, sk_sp<SkColorSpace> colorSpace, Origin origi
n, | 261 JpegDecoderMgr* decoderMgr, sk_sp<SkColorSpace> colorSpace, Origin origi
n, |
262 sk_sp<SkData> iccData) | 262 sk_sp<SkData> iccData) |
263 : INHERITED(width, height, info, stream, std::move(colorSpace), origin) | 263 : INHERITED(width, height, info, stream, std::move(colorSpace), origin) |
264 , fDecoderMgr(decoderMgr) | 264 , fDecoderMgr(decoderMgr) |
265 , fReadyState(decoderMgr->dinfo()->global_state) | 265 , fReadyState(decoderMgr->dinfo()->global_state) |
| 266 , fSrcRow(nullptr) |
266 , fSwizzlerSubset(SkIRect::MakeEmpty()) | 267 , fSwizzlerSubset(SkIRect::MakeEmpty()) |
267 , fICCData(std::move(iccData)) | 268 , fICCData(std::move(iccData)) |
268 {} | 269 {} |
269 | 270 |
270 /* | 271 /* |
271 * Return the row bytes of a particular image type and width | 272 * Return the row bytes of a particular image type and width |
272 */ | 273 */ |
273 static size_t get_row_bytes(const j_decompress_ptr dinfo) { | 274 static size_t get_row_bytes(const j_decompress_ptr dinfo) { |
274 #ifdef TURBO_HAS_565 | 275 #ifdef TURBO_HAS_565 |
275 const size_t colorBytes = (dinfo->out_color_space == JCS_RGB565) ? 2 : | 276 const size_t colorBytes = (dinfo->out_color_space == JCS_RGB565) ? 2 : |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
332 return SkISize::Make(dinfo.output_width, dinfo.output_height); | 333 return SkISize::Make(dinfo.output_width, dinfo.output_height); |
333 } | 334 } |
334 | 335 |
335 bool SkJpegCodec::onRewind() { | 336 bool SkJpegCodec::onRewind() { |
336 JpegDecoderMgr* decoderMgr = nullptr; | 337 JpegDecoderMgr* decoderMgr = nullptr; |
337 if (!ReadHeader(this->stream(), nullptr, &decoderMgr)) { | 338 if (!ReadHeader(this->stream(), nullptr, &decoderMgr)) { |
338 return fDecoderMgr->returnFalse("could not rewind"); | 339 return fDecoderMgr->returnFalse("could not rewind"); |
339 } | 340 } |
340 SkASSERT(nullptr != decoderMgr); | 341 SkASSERT(nullptr != decoderMgr); |
341 fDecoderMgr.reset(decoderMgr); | 342 fDecoderMgr.reset(decoderMgr); |
| 343 |
| 344 fSwizzler.reset(nullptr); |
| 345 fSrcRow = nullptr; |
| 346 fStorage.reset(); |
| 347 |
342 return true; | 348 return true; |
343 } | 349 } |
344 | 350 |
345 /* | 351 /* |
346 * Checks if the conversion between the input image and the requested output | 352 * Checks if the conversion between the input image and the requested output |
347 * image has been implemented | 353 * image has been implemented |
348 * Sets the output color space | 354 * Sets the output color space |
349 */ | 355 */ |
350 bool SkJpegCodec::setOutputColorSpace(const SkImageInfo& dst) { | 356 bool SkJpegCodec::setOutputColorSpace(const SkImageInfo& dst) { |
351 if (kUnknown_SkAlphaType == dst.alphaType()) { | 357 if (kUnknown_SkAlphaType == dst.alphaType()) { |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
581 if (setjmp(fDecoderMgr->getJmpBuf())) { | 587 if (setjmp(fDecoderMgr->getJmpBuf())) { |
582 SkCodecPrintf("setjmp: Error from libjpeg\n"); | 588 SkCodecPrintf("setjmp: Error from libjpeg\n"); |
583 return kInvalidInput; | 589 return kInvalidInput; |
584 } | 590 } |
585 | 591 |
586 // 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 |
587 if (!this->setOutputColorSpace(dstInfo)) { | 593 if (!this->setOutputColorSpace(dstInfo)) { |
588 return kInvalidConversion; | 594 return kInvalidConversion; |
589 } | 595 } |
590 | 596 |
591 // Remove objects used for sampling. | |
592 fSwizzler.reset(nullptr); | |
593 fSrcRow = nullptr; | |
594 fStorage.reset(); | |
595 | |
596 // Now, given valid output dimensions, we can start the decompress | 597 // Now, given valid output dimensions, we can start the decompress |
597 if (!jpeg_start_decompress(fDecoderMgr->dinfo())) { | 598 if (!jpeg_start_decompress(fDecoderMgr->dinfo())) { |
598 SkCodecPrintf("start decompress failed\n"); | 599 SkCodecPrintf("start decompress failed\n"); |
599 return kInvalidInput; | 600 return kInvalidInput; |
600 } | 601 } |
601 | 602 |
602 if (options.fSubset) { | 603 if (options.fSubset) { |
603 fSwizzlerSubset = *options.fSubset; | 604 fSwizzlerSubset = *options.fSubset; |
604 } | 605 } |
605 | 606 |
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
907 | 908 |
908 JDIMENSION linesRead = jpeg_read_raw_data(dinfo, yuv, numRowsPerBlock); | 909 JDIMENSION linesRead = jpeg_read_raw_data(dinfo, yuv, numRowsPerBlock); |
909 if (linesRead < remainingRows) { | 910 if (linesRead < remainingRows) { |
910 // FIXME: Handle incomplete YUV decodes without signalling an error. | 911 // FIXME: Handle incomplete YUV decodes without signalling an error. |
911 return kInvalidInput; | 912 return kInvalidInput; |
912 } | 913 } |
913 } | 914 } |
914 | 915 |
915 return kSuccess; | 916 return kSuccess; |
916 } | 917 } |
OLD | NEW |