blob: ec58710a1c9e8bd5f84e57d6abc69c96f07efdec [file] [log] [blame]
msarette16b04a2015-04-15 07:32:19 -07001/*
2 * Copyright 2015 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#include "SkCodec.h"
9#include "SkJpegCodec.h"
10#include "SkJpegDecoderMgr.h"
mtklein525e90a2015-06-18 09:58:57 -070011#include "SkJpegUtility_codec.h"
msarette16b04a2015-04-15 07:32:19 -070012#include "SkCodecPriv.h"
13#include "SkColorPriv.h"
14#include "SkStream.h"
15#include "SkTemplates.h"
16#include "SkTypes.h"
17
msarettb60c3f82015-06-24 15:10:25 -070018// stdio is needed for libjpeg-turbo
msarette16b04a2015-04-15 07:32:19 -070019#include <stdio.h>
20
21extern "C" {
msarettb60c3f82015-06-24 15:10:25 -070022 #include "jpeglibmangler.h"
msarette16b04a2015-04-15 07:32:19 -070023 #include "jerror.h"
msarette16b04a2015-04-15 07:32:19 -070024 #include "jpegint.h"
25 #include "jpeglib.h"
26}
27
msarette16b04a2015-04-15 07:32:19 -070028/*
msarettb60c3f82015-06-24 15:10:25 -070029 * Convert a row of CMYK samples to RGBA in place.
msarette16b04a2015-04-15 07:32:19 -070030 * Note that this method moves the row pointer.
31 * @param width the number of pixels in the row that is being converted
32 * CMYK is stored as four bytes per pixel
33 */
msarettb60c3f82015-06-24 15:10:25 -070034static void convert_CMYK_to_RGBA(uint8_t* row, uint32_t width) {
msarette16b04a2015-04-15 07:32:19 -070035 // We will implement a crude conversion from CMYK -> RGB using formulas
36 // from easyrgb.com.
37 //
38 // CMYK -> CMY
39 // C = C * (1 - K) + K
40 // M = M * (1 - K) + K
41 // Y = Y * (1 - K) + K
42 //
43 // libjpeg actually gives us inverted CMYK, so we must subtract the
44 // original terms from 1.
45 // CMYK -> CMY
46 // C = (1 - C) * (1 - (1 - K)) + (1 - K)
47 // M = (1 - M) * (1 - (1 - K)) + (1 - K)
48 // Y = (1 - Y) * (1 - (1 - K)) + (1 - K)
49 //
50 // Simplifying the above expression.
51 // CMYK -> CMY
52 // C = 1 - CK
53 // M = 1 - MK
54 // Y = 1 - YK
55 //
56 // CMY -> RGB
57 // R = (1 - C) * 255
58 // G = (1 - M) * 255
59 // B = (1 - Y) * 255
60 //
61 // Therefore the full conversion is below. This can be verified at
62 // www.rapidtables.com (assuming inverted CMYK).
63 // CMYK -> RGB
64 // R = C * K * 255
65 // G = M * K * 255
66 // B = Y * K * 255
67 //
68 // As a final note, we have treated the CMYK values as if they were on
69 // a scale from 0-1, when in fact they are 8-bit ints scaling from 0-255.
70 // We must divide each CMYK component by 255 to obtain the true conversion
71 // we should perform.
72 // CMYK -> RGB
73 // R = C * K / 255
74 // G = M * K / 255
75 // B = Y * K / 255
76 for (uint32_t x = 0; x < width; x++, row += 4) {
msarettb60c3f82015-06-24 15:10:25 -070077#if defined(SK_PMCOLOR_IS_RGBA)
msarette16b04a2015-04-15 07:32:19 -070078 row[0] = SkMulDiv255Round(row[0], row[3]);
79 row[1] = SkMulDiv255Round(row[1], row[3]);
80 row[2] = SkMulDiv255Round(row[2], row[3]);
msarettb60c3f82015-06-24 15:10:25 -070081#else
82 uint8_t tmp = row[0];
83 row[0] = SkMulDiv255Round(row[2], row[3]);
84 row[1] = SkMulDiv255Round(row[1], row[3]);
85 row[2] = SkMulDiv255Round(tmp, row[3]);
86#endif
msarette16b04a2015-04-15 07:32:19 -070087 row[3] = 0xFF;
88 }
89}
90
91bool SkJpegCodec::IsJpeg(SkStream* stream) {
92 static const uint8_t jpegSig[] = { 0xFF, 0xD8, 0xFF };
93 char buffer[sizeof(jpegSig)];
94 return stream->read(buffer, sizeof(jpegSig)) == sizeof(jpegSig) &&
95 !memcmp(buffer, jpegSig, sizeof(jpegSig));
96}
97
98bool SkJpegCodec::ReadHeader(SkStream* stream, SkCodec** codecOut,
99 JpegDecoderMgr** decoderMgrOut) {
100
101 // Create a JpegDecoderMgr to own all of the decompress information
102 SkAutoTDelete<JpegDecoderMgr> decoderMgr(SkNEW_ARGS(JpegDecoderMgr, (stream)));
103
104 // libjpeg errors will be caught and reported here
105 if (setjmp(decoderMgr->getJmpBuf())) {
106 return decoderMgr->returnFalse("setjmp");
107 }
108
109 // Initialize the decompress info and the source manager
110 decoderMgr->init();
111
112 // Read the jpeg header
msarettb60c3f82015-06-24 15:10:25 -0700113 if (JPEG_HEADER_OK != turbo_jpeg_read_header(decoderMgr->dinfo(), true)) {
msarette16b04a2015-04-15 07:32:19 -0700114 return decoderMgr->returnFalse("read_header");
115 }
116
117 if (NULL != codecOut) {
118 // Recommend the color type to decode to
119 const SkColorType colorType = decoderMgr->getColorType();
120
121 // Create image info object and the codec
122 const SkImageInfo& imageInfo = SkImageInfo::Make(decoderMgr->dinfo()->image_width,
123 decoderMgr->dinfo()->image_height, colorType, kOpaque_SkAlphaType);
124 *codecOut = SkNEW_ARGS(SkJpegCodec, (imageInfo, stream, decoderMgr.detach()));
125 } else {
126 SkASSERT(NULL != decoderMgrOut);
127 *decoderMgrOut = decoderMgr.detach();
128 }
129 return true;
130}
131
132SkCodec* SkJpegCodec::NewFromStream(SkStream* stream) {
133 SkAutoTDelete<SkStream> streamDeleter(stream);
134 SkCodec* codec = NULL;
135 if (ReadHeader(stream, &codec, NULL)) {
136 // Codec has taken ownership of the stream, we do not need to delete it
137 SkASSERT(codec);
138 streamDeleter.detach();
139 return codec;
140 }
141 return NULL;
142}
143
144SkJpegCodec::SkJpegCodec(const SkImageInfo& srcInfo, SkStream* stream,
145 JpegDecoderMgr* decoderMgr)
146 : INHERITED(srcInfo, stream)
147 , fDecoderMgr(decoderMgr)
148{}
149
150/*
151 * Return a valid set of output dimensions for this decoder, given an input scale
152 */
153SkISize SkJpegCodec::onGetScaledDimensions(float desiredScale) const {
msarettb60c3f82015-06-24 15:10:25 -0700154 // 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
155 // support these as well
156 long num;
157 long denom = 8;
158 if (desiredScale > 0.875f) {
159 num = 8;
160 } else if (desiredScale > 0.75f) {
161 num = 7;
162 } else if (desiredScale > 0.625f) {
163 num = 6;
164 } else if (desiredScale > 0.5f) {
165 num = 5;
msarette16b04a2015-04-15 07:32:19 -0700166 } else if (desiredScale > 0.375f) {
msarettb60c3f82015-06-24 15:10:25 -0700167 num = 4;
168 } else if (desiredScale > 0.25f) {
169 num = 3;
170 } else if (desiredScale > 0.125f) {
171 num = 2;
msarette16b04a2015-04-15 07:32:19 -0700172 } else {
msarettb60c3f82015-06-24 15:10:25 -0700173 num = 1;
msarette16b04a2015-04-15 07:32:19 -0700174 }
175
176 // Set up a fake decompress struct in order to use libjpeg to calculate output dimensions
177 jpeg_decompress_struct dinfo;
mtkleinf7aaadb2015-04-16 06:09:27 -0700178 sk_bzero(&dinfo, sizeof(dinfo));
msarette16b04a2015-04-15 07:32:19 -0700179 dinfo.image_width = this->getInfo().width();
180 dinfo.image_height = this->getInfo().height();
181 dinfo.global_state = DSTATE_READY;
182 dinfo.num_components = 0;
msarettb60c3f82015-06-24 15:10:25 -0700183 dinfo.scale_num = num;
184 dinfo.scale_denom = denom;
185 turbo_jpeg_calc_output_dimensions(&dinfo);
msarette16b04a2015-04-15 07:32:19 -0700186
187 // Return the calculated output dimensions for the given scale
188 return SkISize::Make(dinfo.output_width, dinfo.output_height);
189}
190
191/*
msarett97fdea62015-04-29 08:17:15 -0700192 * Handles rewinding the input stream if it is necessary
193 */
194bool SkJpegCodec::handleRewind() {
195 switch(this->rewindIfNeeded()) {
196 case kCouldNotRewind_RewindState:
197 return fDecoderMgr->returnFalse("could not rewind");
198 case kRewound_RewindState: {
199 JpegDecoderMgr* decoderMgr = NULL;
200 if (!ReadHeader(this->stream(), NULL, &decoderMgr)) {
201 return fDecoderMgr->returnFalse("could not rewind");
202 }
203 SkASSERT(NULL != decoderMgr);
204 fDecoderMgr.reset(decoderMgr);
205 return true;
206 }
207 case kNoRewindNecessary_RewindState:
208 return true;
209 default:
210 SkASSERT(false);
211 return false;
212 }
213}
214
215/*
msarettb60c3f82015-06-24 15:10:25 -0700216 * Checks if the conversion between the input image and the requested output
217 * image has been implemented
218 * Sets the output color space
219 */
220bool SkJpegCodec::setOutputColorSpace(const SkImageInfo& dst) {
221 const SkImageInfo& src = this->getInfo();
222
223 // Ensure that the profile type is unchanged
224 if (dst.profileType() != src.profileType()) {
225 return false;
226 }
227
228 // Ensure that the alpha type is opaque
229 if (kOpaque_SkAlphaType != dst.alphaType()) {
230 return false;
231 }
232
233 // Check if we will decode to CMYK because a conversion to RGBA is not supported
234 J_COLOR_SPACE colorSpace = fDecoderMgr->dinfo()->jpeg_color_space;
235 bool isCMYK = JCS_CMYK == colorSpace || JCS_YCCK == colorSpace;
236
237 // Check the byte ordering of the RGBA color space for the current platform
238#if defined(SK_PMCOLOR_IS_RGBA)
239 J_COLOR_SPACE outRGBA = JCS_EXT_RGBA;
240#else
241 J_COLOR_SPACE outRGBA = JCS_EXT_BGRA;
242#endif
243
244 // Check for valid color types and set the output color space
245 switch (dst.colorType()) {
246 case kN32_SkColorType:
247 if (isCMYK) {
248 fDecoderMgr->dinfo()->out_color_space = JCS_CMYK;
249 } else {
250 fDecoderMgr->dinfo()->out_color_space = outRGBA;
251 }
252 return true;
253 case kRGB_565_SkColorType:
254 if (isCMYK) {
255 return false;
256 } else {
257 fDecoderMgr->dinfo()->out_color_space = JCS_RGB565;
258 }
259 return true;
260 case kGray_8_SkColorType:
261 if (isCMYK) {
262 return false;
263 } else {
264 // We will enable decodes to gray even if the image is color because this is
265 // much faster than decoding to color and then converting
266 fDecoderMgr->dinfo()->out_color_space = JCS_GRAYSCALE;
267 }
268 return true;
269 default:
270 return false;
271 }
272}
273
274/*
msarett97fdea62015-04-29 08:17:15 -0700275 * Checks if we can scale to the requested dimensions and scales the dimensions
276 * if possible
277 */
278bool SkJpegCodec::scaleToDimensions(uint32_t dstWidth, uint32_t dstHeight) {
msarettb60c3f82015-06-24 15:10:25 -0700279 // 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;
281 fDecoderMgr->dinfo()->scale_num = 8;
282 turbo_jpeg_calc_output_dimensions(fDecoderMgr->dinfo());
msarett97fdea62015-04-29 08:17:15 -0700283 while (fDecoderMgr->dinfo()->output_width != dstWidth ||
284 fDecoderMgr->dinfo()->output_height != dstHeight) {
285
286 // Return a failure if we have tried all of the possible scales
msarettb60c3f82015-06-24 15:10:25 -0700287 if (1 == fDecoderMgr->dinfo()->scale_num ||
msarett97fdea62015-04-29 08:17:15 -0700288 dstWidth > fDecoderMgr->dinfo()->output_width ||
289 dstHeight > fDecoderMgr->dinfo()->output_height) {
290 return fDecoderMgr->returnFalse("could not scale to requested dimensions");
291 }
292
293 // Try the next scale
msarettb60c3f82015-06-24 15:10:25 -0700294 fDecoderMgr->dinfo()->scale_num -= 1;
295 turbo_jpeg_calc_output_dimensions(fDecoderMgr->dinfo());
msarett97fdea62015-04-29 08:17:15 -0700296 }
297 return true;
298}
299
300/*
msarette16b04a2015-04-15 07:32:19 -0700301 * Performs the jpeg decode
302 */
303SkCodec::Result SkJpegCodec::onGetPixels(const SkImageInfo& dstInfo,
304 void* dst, size_t dstRowBytes,
305 const Options& options, SkPMColor*, int*) {
msarett97fdea62015-04-29 08:17:15 -0700306
msarette16b04a2015-04-15 07:32:19 -0700307 // Rewind the stream if needed
msarett97fdea62015-04-29 08:17:15 -0700308 if (!this->handleRewind()) {
309 fDecoderMgr->returnFailure("could not rewind stream", kCouldNotRewind);
msarette16b04a2015-04-15 07:32:19 -0700310 }
311
312 // Get a pointer to the decompress info since we will use it quite frequently
313 jpeg_decompress_struct* dinfo = fDecoderMgr->dinfo();
314
315 // Set the jump location for libjpeg errors
316 if (setjmp(fDecoderMgr->getJmpBuf())) {
317 return fDecoderMgr->returnFailure("setjmp", kInvalidInput);
318 }
319
msarettb60c3f82015-06-24 15:10:25 -0700320 // Check if we can decode to the requested destination and set the output color space
321 if (!this->setOutputColorSpace(dstInfo)) {
msarette16b04a2015-04-15 07:32:19 -0700322 return fDecoderMgr->returnFailure("conversion_possible", kInvalidConversion);
323 }
msarette16b04a2015-04-15 07:32:19 -0700324
msarett97fdea62015-04-29 08:17:15 -0700325 // Perform the necessary scaling
326 if (!this->scaleToDimensions(dstInfo.width(), dstInfo.height())) {
msarettb60c3f82015-06-24 15:10:25 -0700327 return fDecoderMgr->returnFailure("cannot scale to requested dims", kInvalidScale);
msarette16b04a2015-04-15 07:32:19 -0700328 }
329
330 // Now, given valid output dimensions, we can start the decompress
msarettb60c3f82015-06-24 15:10:25 -0700331 if (!turbo_jpeg_start_decompress(dinfo)) {
msarette16b04a2015-04-15 07:32:19 -0700332 return fDecoderMgr->returnFailure("startDecompress", kInvalidInput);
333 }
334
msarettb60c3f82015-06-24 15:10:25 -0700335 // The recommended output buffer height should always be 1 in high quality modes.
336 // If it's not, we want to know because it means our strategy is not optimal.
337 SkASSERT(1 == dinfo->rec_outbuf_height);
msarette16b04a2015-04-15 07:32:19 -0700338
msarettb60c3f82015-06-24 15:10:25 -0700339 // Perform the decode a single row at a time
msarett97fdea62015-04-29 08:17:15 -0700340 uint32_t dstHeight = dstInfo.height();
msarettb60c3f82015-06-24 15:10:25 -0700341 JSAMPLE* dstRow = (JSAMPLE*) dst;
342 for (uint32_t y = 0; y < dstHeight; y++) {
msarette16b04a2015-04-15 07:32:19 -0700343 // Read rows of the image
msarettb60c3f82015-06-24 15:10:25 -0700344 uint32_t rowsDecoded = turbo_jpeg_read_scanlines(dinfo, &dstRow, 1);
msarette16b04a2015-04-15 07:32:19 -0700345
346 // If we cannot read enough rows, assume the input is incomplete
msarettb60c3f82015-06-24 15:10:25 -0700347 if (rowsDecoded != 1) {
msarette16b04a2015-04-15 07:32:19 -0700348 // Fill the remainder of the image with black. This error handling
349 // behavior is unspecified but SkCodec consistently uses black as
350 // the fill color for opaque images. If the destination is kGray,
351 // the low 8 bits of SK_ColorBLACK will be used. Conveniently,
352 // these are zeros, which is the representation for black in kGray.
msarettb60c3f82015-06-24 15:10:25 -0700353 SkSwizzler::Fill(dstRow, dstInfo, dstRowBytes, dstHeight - y, SK_ColorBLACK, NULL);
msarette16b04a2015-04-15 07:32:19 -0700354
355 // Prevent libjpeg from failing on incomplete decode
356 dinfo->output_scanline = dstHeight;
357
358 // Finish the decode and indicate that the input was incomplete.
msarettb60c3f82015-06-24 15:10:25 -0700359 turbo_jpeg_finish_decompress(dinfo);
msarette16b04a2015-04-15 07:32:19 -0700360 return fDecoderMgr->returnFailure("Incomplete image data", kIncompleteInput);
361 }
msarettb60c3f82015-06-24 15:10:25 -0700362
363 // Convert to RGBA if necessary
364 if (JCS_CMYK == dinfo->out_color_space) {
365 convert_CMYK_to_RGBA(dstRow, dstInfo.width());
366 }
367
368 // Move to the next row
369 dstRow = SkTAddOffset<JSAMPLE>(dstRow, dstRowBytes);
msarette16b04a2015-04-15 07:32:19 -0700370 }
msarettb60c3f82015-06-24 15:10:25 -0700371 turbo_jpeg_finish_decompress(dinfo);
msarette16b04a2015-04-15 07:32:19 -0700372
373 return kSuccess;
374}
msarett97fdea62015-04-29 08:17:15 -0700375
376/*
377 * Enable scanline decoding for jpegs
378 */
379class SkJpegScanlineDecoder : public SkScanlineDecoder {
380public:
381 SkJpegScanlineDecoder(const SkImageInfo& dstInfo, SkJpegCodec* codec)
382 : INHERITED(dstInfo)
383 , fCodec(codec)
msarettb60c3f82015-06-24 15:10:25 -0700384 {}
msarett97fdea62015-04-29 08:17:15 -0700385
386 SkImageGenerator::Result onGetScanlines(void* dst, int count, size_t rowBytes) override {
387 // Set the jump location for libjpeg errors
388 if (setjmp(fCodec->fDecoderMgr->getJmpBuf())) {
389 return fCodec->fDecoderMgr->returnFailure("setjmp", SkImageGenerator::kInvalidInput);
390 }
391
392 // Read rows one at a time
msarettb60c3f82015-06-24 15:10:25 -0700393 JSAMPLE* dstRow = (JSAMPLE*) dst;
msarett97fdea62015-04-29 08:17:15 -0700394 for (int y = 0; y < count; y++) {
395 // Read row of the image
msarettb60c3f82015-06-24 15:10:25 -0700396 uint32_t rowsDecoded =
397 turbo_jpeg_read_scanlines(fCodec->fDecoderMgr->dinfo(), &dstRow, 1);
msarett97fdea62015-04-29 08:17:15 -0700398 if (rowsDecoded != 1) {
msarettb60c3f82015-06-24 15:10:25 -0700399 SkSwizzler::Fill(
400 dstRow, this->dstInfo(), rowBytes, count - y, SK_ColorBLACK, NULL);
401 fCodec->fDecoderMgr->dinfo()->output_scanline = this->dstInfo().height();
402 turbo_jpeg_finish_decompress(fCodec->fDecoderMgr->dinfo());
msarett97fdea62015-04-29 08:17:15 -0700403 return SkImageGenerator::kIncompleteInput;
404 }
405
msarettb60c3f82015-06-24 15:10:25 -0700406 // Convert to RGBA if necessary
msarett97fdea62015-04-29 08:17:15 -0700407 if (JCS_CMYK == fCodec->fDecoderMgr->dinfo()->out_color_space) {
msarettb60c3f82015-06-24 15:10:25 -0700408 convert_CMYK_to_RGBA(dstRow, this->dstInfo().width());
msarett97fdea62015-04-29 08:17:15 -0700409 }
410
msarettb60c3f82015-06-24 15:10:25 -0700411 // Move to the next row
412 dstRow = SkTAddOffset<JSAMPLE>(dstRow, rowBytes);
msarett97fdea62015-04-29 08:17:15 -0700413 }
414
415 return SkImageGenerator::kSuccess;
416 }
417
msarettb60c3f82015-06-24 15:10:25 -0700418 // This is a temporary macro that will be removed after we upstream jpeg_skip_scanlines()
419 // to libjpeg-turbo.
420 // skbug.com/3972
421 // TODO (msarett): Remove this function when it is no longer necessary.
422#ifndef turbo_jpeg_skip_scanlines
423#define turbo_jpeg_skip_scanlines(dinfo, count) \
424 SkAutoMalloc storage(dinfo->output_width * dinfo->out_color_components); \
425 uint8_t* storagePtr = static_cast<uint8_t*>(storage.get()); \
426 for (int y = 0; y < count; y++) { \
427 turbo_jpeg_read_scanlines(dinfo, &storagePtr, 1); \
428 }
429#endif
430
msarett97fdea62015-04-29 08:17:15 -0700431 SkImageGenerator::Result onSkipScanlines(int count) override {
432 // Set the jump location for libjpeg errors
433 if (setjmp(fCodec->fDecoderMgr->getJmpBuf())) {
434 return fCodec->fDecoderMgr->returnFailure("setjmp", SkImageGenerator::kInvalidInput);
435 }
436
msarettb60c3f82015-06-24 15:10:25 -0700437 turbo_jpeg_skip_scanlines(fCodec->fDecoderMgr->dinfo(), count);
msarett97fdea62015-04-29 08:17:15 -0700438
439 return SkImageGenerator::kSuccess;
440 }
441
442 void onFinish() override {
443 if (setjmp(fCodec->fDecoderMgr->getJmpBuf())) {
444 SkCodecPrintf("setjmp: Error in libjpeg finish_decompress\n");
445 return;
446 }
447
msarettb60c3f82015-06-24 15:10:25 -0700448 turbo_jpeg_finish_decompress(fCodec->fDecoderMgr->dinfo());
msarett97fdea62015-04-29 08:17:15 -0700449 }
450
451private:
msarettb60c3f82015-06-24 15:10:25 -0700452 SkJpegCodec* fCodec; // unowned
msarett97fdea62015-04-29 08:17:15 -0700453
454 typedef SkScanlineDecoder INHERITED;
455};
456
457SkScanlineDecoder* SkJpegCodec::onGetScanlineDecoder(const SkImageInfo& dstInfo,
458 const Options& options, SkPMColor ctable[], int* ctableCount) {
459
460 // Rewind the stream if needed
461 if (!this->handleRewind()) {
462 SkCodecPrintf("Could not rewind\n");
463 return NULL;
464 }
465
466 // Set the jump location for libjpeg errors
467 if (setjmp(fDecoderMgr->getJmpBuf())) {
468 SkCodecPrintf("setjmp: Error from libjpeg\n");
469 return NULL;
470 }
471
msarettb60c3f82015-06-24 15:10:25 -0700472 // Check if we can decode to the requested destination and set the output color space
473 if (!this->setOutputColorSpace(dstInfo)) {
msarett97fdea62015-04-29 08:17:15 -0700474 SkCodecPrintf("Cannot convert to output type\n");
475 return NULL;
476 }
477
478 // Perform the necessary scaling
479 if (!this->scaleToDimensions(dstInfo.width(), dstInfo.height())) {
msarettb60c3f82015-06-24 15:10:25 -0700480 SkCodecPrintf("Cannot scale to output dimensions\n");
msarett97fdea62015-04-29 08:17:15 -0700481 return NULL;
482 }
483
484 // Now, given valid output dimensions, we can start the decompress
msarettb60c3f82015-06-24 15:10:25 -0700485 if (!turbo_jpeg_start_decompress(fDecoderMgr->dinfo())) {
msarett97fdea62015-04-29 08:17:15 -0700486 SkCodecPrintf("start decompress failed\n");
487 return NULL;
488 }
489
msarett97fdea62015-04-29 08:17:15 -0700490 // Return the new scanline decoder
491 return SkNEW_ARGS(SkJpegScanlineDecoder, (dstInfo, this));
492}