Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(359)

Side by Side Diff: src/codec/SkJpegCodec.cpp

Issue 1687863003: Make SkJpegCodec compatible with libjpeg (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix gyp Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/codec/SkCodec.cpp ('k') | tools/BUILD.public.expected » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 JpegDecoderMgr* decoderMgr) 79 JpegDecoderMgr* decoderMgr)
80 : INHERITED(srcInfo, stream) 80 : INHERITED(srcInfo, stream)
81 , fDecoderMgr(decoderMgr) 81 , fDecoderMgr(decoderMgr)
82 , fReadyState(decoderMgr->dinfo()->global_state) 82 , fReadyState(decoderMgr->dinfo()->global_state)
83 {} 83 {}
84 84
85 /* 85 /*
86 * Return the row bytes of a particular image type and width 86 * Return the row bytes of a particular image type and width
87 */ 87 */
88 static size_t get_row_bytes(const j_decompress_ptr dinfo) { 88 static size_t get_row_bytes(const j_decompress_ptr dinfo) {
89 size_t colorBytes = (dinfo->out_color_space == JCS_RGB565) ? 2 : dinfo->out_ color_components; 89 #ifdef TURBO_HAS_565
90 const size_t colorBytes = (dinfo->out_color_space == JCS_RGB565) ? 2 :
91 dinfo->out_color_components;
92 #else
93 const size_t colorBytes = dinfo->out_color_components;
94 #endif
90 return dinfo->output_width * colorBytes; 95 return dinfo->output_width * colorBytes;
91 96
92 } 97 }
93 98
94 /* 99 /*
95 * Calculate output dimensions based on the provided factors. 100 * Calculate output dimensions based on the provided factors.
96 * 101 *
97 * Not to be used on the actual jpeg_decompress_struct used for decoding, since it will 102 * Not to be used on the actual jpeg_decompress_struct used for decoding, since it will
98 * incorrectly modify num_components. 103 * incorrectly modify num_components.
99 */ 104 */
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 // Check if we will decode to CMYK because a conversion to RGBA is not suppo rted 182 // Check if we will decode to CMYK because a conversion to RGBA is not suppo rted
178 J_COLOR_SPACE colorSpace = fDecoderMgr->dinfo()->jpeg_color_space; 183 J_COLOR_SPACE colorSpace = fDecoderMgr->dinfo()->jpeg_color_space;
179 bool isCMYK = JCS_CMYK == colorSpace || JCS_YCCK == colorSpace; 184 bool isCMYK = JCS_CMYK == colorSpace || JCS_YCCK == colorSpace;
180 185
181 // Check for valid color types and set the output color space 186 // Check for valid color types and set the output color space
182 switch (dst.colorType()) { 187 switch (dst.colorType()) {
183 case kN32_SkColorType: 188 case kN32_SkColorType:
184 if (isCMYK) { 189 if (isCMYK) {
185 fDecoderMgr->dinfo()->out_color_space = JCS_CMYK; 190 fDecoderMgr->dinfo()->out_color_space = JCS_CMYK;
186 } else { 191 } else {
187 // Check the byte ordering of the RGBA color space for the 192 #ifdef LIBJPEG_TURBO_VERSION
188 // current platform 193 // Check the byte ordering of the RGBA color space for the
189 #if defined(SK_PMCOLOR_IS_RGBA) 194 // current platform
190 fDecoderMgr->dinfo()->out_color_space = JCS_EXT_RGBA; 195 #ifdef SK_PMCOLOR_IS_RGBA
196 fDecoderMgr->dinfo()->out_color_space = JCS_EXT_RGBA;
197 #else
198 fDecoderMgr->dinfo()->out_color_space = JCS_EXT_BGRA;
199 #endif
191 #else 200 #else
192 fDecoderMgr->dinfo()->out_color_space = JCS_EXT_BGRA; 201 fDecoderMgr->dinfo()->out_color_space = JCS_RGB;
193 #endif 202 #endif
194 } 203 }
195 return true; 204 return true;
196 case kRGB_565_SkColorType: 205 case kRGB_565_SkColorType:
197 if (isCMYK) { 206 if (isCMYK) {
198 fDecoderMgr->dinfo()->out_color_space = JCS_CMYK; 207 fDecoderMgr->dinfo()->out_color_space = JCS_CMYK;
199 } else { 208 } else {
209 #ifdef TURBO_HAS_565
200 fDecoderMgr->dinfo()->dither_mode = JDITHER_NONE; 210 fDecoderMgr->dinfo()->dither_mode = JDITHER_NONE;
201 fDecoderMgr->dinfo()->out_color_space = JCS_RGB565; 211 fDecoderMgr->dinfo()->out_color_space = JCS_RGB565;
212 #else
213 fDecoderMgr->dinfo()->out_color_space = JCS_RGB;
214 #endif
202 } 215 }
203 return true; 216 return true;
204 case kGray_8_SkColorType: 217 case kGray_8_SkColorType:
205 if (isCMYK) { 218 if (isCMYK) {
206 return false; 219 return false;
207 } else { 220 } else {
208 // We will enable decodes to gray even if the image is color bec ause this is 221 // We will enable decodes to gray even if the image is color bec ause this is
209 // much faster than decoding to color and then converting 222 // much faster than decoding to color and then converting
210 fDecoderMgr->dinfo()->out_color_space = JCS_GRAYSCALE; 223 fDecoderMgr->dinfo()->out_color_space = JCS_GRAYSCALE;
211 } 224 }
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 296
284 // Now, given valid output dimensions, we can start the decompress 297 // Now, given valid output dimensions, we can start the decompress
285 if (!jpeg_start_decompress(dinfo)) { 298 if (!jpeg_start_decompress(dinfo)) {
286 return fDecoderMgr->returnFailure("startDecompress", kInvalidInput); 299 return fDecoderMgr->returnFailure("startDecompress", kInvalidInput);
287 } 300 }
288 301
289 // The recommended output buffer height should always be 1 in high quality m odes. 302 // The recommended output buffer height should always be 1 in high quality m odes.
290 // If it's not, we want to know because it means our strategy is not optimal . 303 // If it's not, we want to know because it means our strategy is not optimal .
291 SkASSERT(1 == dinfo->rec_outbuf_height); 304 SkASSERT(1 == dinfo->rec_outbuf_height);
292 305
293 if (JCS_CMYK == dinfo->out_color_space) { 306 J_COLOR_SPACE colorSpace = dinfo->out_color_space;
307 if (JCS_CMYK == colorSpace || JCS_RGB == colorSpace) {
294 this->initializeSwizzler(dstInfo, options); 308 this->initializeSwizzler(dstInfo, options);
295 } 309 }
296 310
297 // Perform the decode a single row at a time 311 // Perform the decode a single row at a time
298 uint32_t dstHeight = dstInfo.height(); 312 uint32_t dstHeight = dstInfo.height();
299 313
300 JSAMPLE* dstRow; 314 JSAMPLE* dstRow;
301 if (fSwizzler) { 315 if (fSwizzler) {
302 // write data to storage row, then sample using swizzler 316 // write data to storage row, then sample using swizzler
303 dstRow = fSrcRow; 317 dstRow = fSrcRow;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 break; 360 break;
347 case kRGB_565_SkColorType: 361 case kRGB_565_SkColorType:
348 srcConfig = SkSwizzler::kNoOp16; 362 srcConfig = SkSwizzler::kNoOp16;
349 break; 363 break;
350 default: 364 default:
351 // This function should only be called if the colorType is suppo rted by jpeg 365 // This function should only be called if the colorType is suppo rted by jpeg
352 SkASSERT(false); 366 SkASSERT(false);
353 } 367 }
354 } 368 }
355 369
370 if (JCS_RGB == fDecoderMgr->dinfo()->out_color_space) {
371 srcConfig = SkSwizzler::kRGB;
372 }
373
356 fSwizzler.reset(SkSwizzler::CreateSwizzler(srcConfig, nullptr, dstInfo, opti ons)); 374 fSwizzler.reset(SkSwizzler::CreateSwizzler(srcConfig, nullptr, dstInfo, opti ons));
357 fStorage.reset(get_row_bytes(fDecoderMgr->dinfo())); 375 fStorage.reset(get_row_bytes(fDecoderMgr->dinfo()));
358 fSrcRow = fStorage.get(); 376 fSrcRow = fStorage.get();
359 } 377 }
360 378
361 SkSampler* SkJpegCodec::getSampler(bool createIfNecessary) { 379 SkSampler* SkJpegCodec::getSampler(bool createIfNecessary) {
362 if (!createIfNecessary || fSwizzler) { 380 if (!createIfNecessary || fSwizzler) {
363 SkASSERT(!fSwizzler || (fSrcRow && fStorage.get() == fSrcRow)); 381 SkASSERT(!fSwizzler || (fSrcRow && fStorage.get() == fSrcRow));
364 return fSwizzler; 382 return fSwizzler;
365 } 383 }
(...skipping 21 matching lines...) Expand all
387 fStorage.free(); 405 fStorage.free();
388 406
389 // Now, given valid output dimensions, we can start the decompress 407 // Now, given valid output dimensions, we can start the decompress
390 if (!jpeg_start_decompress(fDecoderMgr->dinfo())) { 408 if (!jpeg_start_decompress(fDecoderMgr->dinfo())) {
391 SkCodecPrintf("start decompress failed\n"); 409 SkCodecPrintf("start decompress failed\n");
392 return kInvalidInput; 410 return kInvalidInput;
393 } 411 }
394 412
395 // We will need a swizzler if we are performing a subset decode or 413 // We will need a swizzler if we are performing a subset decode or
396 // converting from CMYK. 414 // converting from CMYK.
397 if (options.fSubset || JCS_CMYK == fDecoderMgr->dinfo()->out_color_space) { 415 J_COLOR_SPACE colorSpace = fDecoderMgr->dinfo()->out_color_space;
416 if (options.fSubset || JCS_CMYK == colorSpace || JCS_RGB == colorSpace) {
398 this->initializeSwizzler(dstInfo, options); 417 this->initializeSwizzler(dstInfo, options);
399 } 418 }
400 419
401 return kSuccess; 420 return kSuccess;
402 } 421 }
403 422
404 int SkJpegCodec::onGetScanlines(void* dst, int count, size_t dstRowBytes) { 423 int SkJpegCodec::onGetScanlines(void* dst, int count, size_t dstRowBytes) {
405 // Set the jump location for libjpeg errors 424 // Set the jump location for libjpeg errors
406 if (setjmp(fDecoderMgr->getJmpBuf())) { 425 if (setjmp(fDecoderMgr->getJmpBuf())) {
407 return fDecoderMgr->returnFailure("setjmp", kInvalidInput); 426 return fDecoderMgr->returnFailure("setjmp", kInvalidInput);
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
646 665
647 JDIMENSION linesRead = jpeg_read_raw_data(dinfo, yuv, numRowsPerBlock); 666 JDIMENSION linesRead = jpeg_read_raw_data(dinfo, yuv, numRowsPerBlock);
648 if (linesRead < remainingRows) { 667 if (linesRead < remainingRows) {
649 // FIXME: Handle incomplete YUV decodes without signalling an error. 668 // FIXME: Handle incomplete YUV decodes without signalling an error.
650 return kInvalidInput; 669 return kInvalidInput;
651 } 670 }
652 } 671 }
653 672
654 return kSuccess; 673 return kSuccess;
655 } 674 }
OLDNEW
« no previous file with comments | « src/codec/SkCodec.cpp ('k') | tools/BUILD.public.expected » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698