| 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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 JpegDecoderMgr* decoderMgr) | 80 JpegDecoderMgr* decoderMgr) |
| 81 : INHERITED(srcInfo, stream) | 81 : INHERITED(srcInfo, stream) |
| 82 , fDecoderMgr(decoderMgr) | 82 , fDecoderMgr(decoderMgr) |
| 83 , fReadyState(decoderMgr->dinfo()->global_state) | 83 , fReadyState(decoderMgr->dinfo()->global_state) |
| 84 {} | 84 {} |
| 85 | 85 |
| 86 /* | 86 /* |
| 87 * Return the row bytes of a particular image type and width | 87 * Return the row bytes of a particular image type and width |
| 88 */ | 88 */ |
| 89 static int get_row_bytes(const j_decompress_ptr dinfo) { | 89 static int get_row_bytes(const j_decompress_ptr dinfo) { |
| 90 #if defined (GOOGLE3) | |
| 91 int colorBytes = dinfo->out_color_components; | |
| 92 #else | |
| 93 int colorBytes = (dinfo->out_color_space == JCS_RGB565) ? 2 : dinfo->out_col
or_components; | 90 int colorBytes = (dinfo->out_color_space == JCS_RGB565) ? 2 : dinfo->out_col
or_components; |
| 94 #endif | |
| 95 return dinfo->output_width * colorBytes; | 91 return dinfo->output_width * colorBytes; |
| 96 | 92 |
| 97 } | 93 } |
| 98 | 94 |
| 99 /* | 95 /* |
| 100 * Calculate output dimensions based on the provided factors. | 96 * Calculate output dimensions based on the provided factors. |
| 101 * | 97 * |
| 102 * Not to be used on the actual jpeg_decompress_struct used for decoding, since
it will | 98 * Not to be used on the actual jpeg_decompress_struct used for decoding, since
it will |
| 103 * incorrectly modify num_components. | 99 * incorrectly modify num_components. |
| 104 */ | 100 */ |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 bool isCMYK = JCS_CMYK == colorSpace || JCS_YCCK == colorSpace; | 176 bool isCMYK = JCS_CMYK == colorSpace || JCS_YCCK == colorSpace; |
| 181 | 177 |
| 182 // Check for valid color types and set the output color space | 178 // Check for valid color types and set the output color space |
| 183 switch (dst.colorType()) { | 179 switch (dst.colorType()) { |
| 184 case kN32_SkColorType: | 180 case kN32_SkColorType: |
| 185 if (isCMYK) { | 181 if (isCMYK) { |
| 186 fDecoderMgr->dinfo()->out_color_space = JCS_CMYK; | 182 fDecoderMgr->dinfo()->out_color_space = JCS_CMYK; |
| 187 } else { | 183 } else { |
| 188 // Check the byte ordering of the RGBA color space for the | 184 // Check the byte ordering of the RGBA color space for the |
| 189 // current platform | 185 // current platform |
| 190 #if defined(GOOGLE3) | 186 #if defined(SK_PMCOLOR_IS_RGBA) |
| 191 return false; | 187 fDecoderMgr->dinfo()->out_color_space = JCS_EXT_RGBA; |
| 192 #else | 188 #else |
| 193 #if defined(SK_PMCOLOR_IS_RGBA) | |
| 194 fDecoderMgr->dinfo()->out_color_space = JCS_EXT_RGBA; | |
| 195 #else | |
| 196 fDecoderMgr->dinfo()->out_color_space = JCS_EXT_BGRA; | 189 fDecoderMgr->dinfo()->out_color_space = JCS_EXT_BGRA; |
| 197 #endif | |
| 198 #endif | 190 #endif |
| 199 } | 191 } |
| 200 return true; | 192 return true; |
| 201 case kRGB_565_SkColorType: | 193 case kRGB_565_SkColorType: |
| 202 if (isCMYK) { | 194 if (isCMYK) { |
| 203 fDecoderMgr->dinfo()->out_color_space = JCS_CMYK; | 195 fDecoderMgr->dinfo()->out_color_space = JCS_CMYK; |
| 204 } else { | 196 } else { |
| 205 #if defined(GOOGLE3) | |
| 206 return false; | |
| 207 #else | |
| 208 fDecoderMgr->dinfo()->dither_mode = JDITHER_NONE; | 197 fDecoderMgr->dinfo()->dither_mode = JDITHER_NONE; |
| 209 fDecoderMgr->dinfo()->out_color_space = JCS_RGB565; | 198 fDecoderMgr->dinfo()->out_color_space = JCS_RGB565; |
| 210 #endif | |
| 211 } | 199 } |
| 212 return true; | 200 return true; |
| 213 case kGray_8_SkColorType: | 201 case kGray_8_SkColorType: |
| 214 if (isCMYK) { | 202 if (isCMYK) { |
| 215 return false; | 203 return false; |
| 216 } else { | 204 } else { |
| 217 // We will enable decodes to gray even if the image is color bec
ause this is | 205 // We will enable decodes to gray even if the image is color bec
ause this is |
| 218 // much faster than decoding to color and then converting | 206 // much faster than decoding to color and then converting |
| 219 fDecoderMgr->dinfo()->out_color_space = JCS_GRAYSCALE; | 207 fDecoderMgr->dinfo()->out_color_space = JCS_GRAYSCALE; |
| 220 } | 208 } |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 351 srcConfig = SkSwizzler::kRGBX; | 339 srcConfig = SkSwizzler::kRGBX; |
| 352 break; | 340 break; |
| 353 case kBGRA_8888_SkColorType: | 341 case kBGRA_8888_SkColorType: |
| 354 srcConfig = SkSwizzler::kBGRX; | 342 srcConfig = SkSwizzler::kBGRX; |
| 355 break; | 343 break; |
| 356 case kRGB_565_SkColorType: | 344 case kRGB_565_SkColorType: |
| 357 srcConfig = SkSwizzler::kRGB_565; | 345 srcConfig = SkSwizzler::kRGB_565; |
| 358 break; | 346 break; |
| 359 default: | 347 default: |
| 360 // This function should only be called if the colorType is suppo
rted by jpeg | 348 // This function should only be called if the colorType is suppo
rted by jpeg |
| 361 #if defined(GOOGLE3) | |
| 362 SK_CRASH(); | |
| 363 #else | |
| 364 SkASSERT(false); | 349 SkASSERT(false); |
| 365 #endif | |
| 366 } | 350 } |
| 367 } | 351 } |
| 368 | 352 |
| 369 fSwizzler.reset(SkSwizzler::CreateSwizzler(srcConfig, nullptr, dstInfo, opti
ons)); | 353 fSwizzler.reset(SkSwizzler::CreateSwizzler(srcConfig, nullptr, dstInfo, opti
ons)); |
| 370 fStorage.reset(get_row_bytes(fDecoderMgr->dinfo())); | 354 fStorage.reset(get_row_bytes(fDecoderMgr->dinfo())); |
| 371 fSrcRow = static_cast<uint8_t*>(fStorage.get()); | 355 fSrcRow = static_cast<uint8_t*>(fStorage.get()); |
| 372 } | 356 } |
| 373 | 357 |
| 374 SkSampler* SkJpegCodec::getSampler(bool createIfNecessary) { | 358 SkSampler* SkJpegCodec::getSampler(bool createIfNecessary) { |
| 375 if (!createIfNecessary || fSwizzler) { | 359 if (!createIfNecessary || fSwizzler) { |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 463 #endif | 447 #endif |
| 464 | 448 |
| 465 bool SkJpegCodec::onSkipScanlines(int count) { | 449 bool SkJpegCodec::onSkipScanlines(int count) { |
| 466 // Set the jump location for libjpeg errors | 450 // Set the jump location for libjpeg errors |
| 467 if (setjmp(fDecoderMgr->getJmpBuf())) { | 451 if (setjmp(fDecoderMgr->getJmpBuf())) { |
| 468 return fDecoderMgr->returnFalse("setjmp"); | 452 return fDecoderMgr->returnFalse("setjmp"); |
| 469 } | 453 } |
| 470 | 454 |
| 471 return (uint32_t) count == jpeg_skip_scanlines(fDecoderMgr->dinfo(), count); | 455 return (uint32_t) count == jpeg_skip_scanlines(fDecoderMgr->dinfo(), count); |
| 472 } | 456 } |
| OLD | NEW |