Chromium Code Reviews| 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 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 144 JpegDecoderMgr* decoderMgr) | 144 JpegDecoderMgr* decoderMgr) |
| 145 : INHERITED(srcInfo, stream) | 145 : INHERITED(srcInfo, stream) |
| 146 , fDecoderMgr(decoderMgr) | 146 , fDecoderMgr(decoderMgr) |
| 147 , fReadyState(decoderMgr->dinfo()->global_state) | 147 , fReadyState(decoderMgr->dinfo()->global_state) |
| 148 {} | 148 {} |
| 149 | 149 |
| 150 /* | 150 /* |
| 151 * Return the row bytes of a particular image type and width | 151 * Return the row bytes of a particular image type and width |
| 152 */ | 152 */ |
| 153 static int get_row_bytes(const j_decompress_ptr dinfo) { | 153 static int get_row_bytes(const j_decompress_ptr dinfo) { |
| 154 #if defined (GOOGLE3) | |
|
scroggo
2015/10/27 13:51:23
Is this because GOOGLE3 is expected to build again
mtklein
2015/10/27 14:27:59
Why don't we just use libjpeg's own defines as the
msarett
2015/10/27 14:31:36
sgtm
They are actually enums. Will that still wo
dogben
2015/10/27 15:07:22
Sorry, I should have left a comment or TODO. I for
| |
| 155 int colorBytes = dinfo->out_color_components; | |
| 156 #else | |
| 154 int colorBytes = (dinfo->out_color_space == JCS_RGB565) ? 2 : dinfo->out_col or_components; | 157 int colorBytes = (dinfo->out_color_space == JCS_RGB565) ? 2 : dinfo->out_col or_components; |
| 158 #endif | |
| 155 return dinfo->output_width * colorBytes; | 159 return dinfo->output_width * colorBytes; |
| 156 | 160 |
| 157 } | 161 } |
| 158 | 162 |
| 159 /* | 163 /* |
| 160 * Calculate output dimensions based on the provided factors. | 164 * Calculate output dimensions based on the provided factors. |
| 161 * | 165 * |
| 162 * Not to be used on the actual jpeg_decompress_struct used for decoding, since it will | 166 * Not to be used on the actual jpeg_decompress_struct used for decoding, since it will |
| 163 * incorrectly modify num_components. | 167 * incorrectly modify num_components. |
| 164 */ | 168 */ |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 240 bool isCMYK = JCS_CMYK == colorSpace || JCS_YCCK == colorSpace; | 244 bool isCMYK = JCS_CMYK == colorSpace || JCS_YCCK == colorSpace; |
| 241 | 245 |
| 242 // Check for valid color types and set the output color space | 246 // Check for valid color types and set the output color space |
| 243 switch (dst.colorType()) { | 247 switch (dst.colorType()) { |
| 244 case kN32_SkColorType: | 248 case kN32_SkColorType: |
| 245 if (isCMYK) { | 249 if (isCMYK) { |
| 246 fDecoderMgr->dinfo()->out_color_space = JCS_CMYK; | 250 fDecoderMgr->dinfo()->out_color_space = JCS_CMYK; |
| 247 } else { | 251 } else { |
| 248 // Check the byte ordering of the RGBA color space for the | 252 // Check the byte ordering of the RGBA color space for the |
| 249 // current platform | 253 // current platform |
| 250 #if defined(SK_PMCOLOR_IS_RGBA) | 254 #if defined(GOOGLE3) |
| 255 return false; | |
|
scroggo
2015/10/27 13:51:23
It appears that in GOOGLE3, SkJpegCodec will not w
dogben
2015/10/27 15:07:22
I didn't realize that not supporting JCS_EXT_* wou
| |
| 256 #else | |
| 257 #if defined(SK_PMCOLOR_IS_RGBA) | |
| 251 fDecoderMgr->dinfo()->out_color_space = JCS_EXT_RGBA; | 258 fDecoderMgr->dinfo()->out_color_space = JCS_EXT_RGBA; |
| 252 #else | 259 #else |
| 253 fDecoderMgr->dinfo()->out_color_space = JCS_EXT_BGRA; | 260 fDecoderMgr->dinfo()->out_color_space = JCS_EXT_BGRA; |
| 261 #endif | |
| 254 #endif | 262 #endif |
| 255 } | 263 } |
| 256 return true; | 264 return true; |
| 257 case kRGB_565_SkColorType: | 265 case kRGB_565_SkColorType: |
| 258 if (isCMYK) { | 266 if (isCMYK) { |
| 259 // FIXME (msarett): We need to support 565 here. It's not hard to do, considering | 267 // FIXME (msarett): We need to support 565 here. It's not hard to do, considering |
| 260 // we already convert CMYK to RGBA, I just need to do it. I thi nk it might be | 268 // we already convert CMYK to RGBA, I just need to do it. I thi nk it might be |
| 261 // best to do this in SkSwizzler and also move convert_CMYK_to_R GBA into SkSwizzler. | 269 // best to do this in SkSwizzler and also move convert_CMYK_to_R GBA into SkSwizzler. |
| 262 return false; | 270 return false; |
| 263 } else { | 271 } else { |
| 272 #if defined(GOOGLE3) | |
| 273 return false; | |
| 274 #else | |
| 264 fDecoderMgr->dinfo()->dither_mode = JDITHER_NONE; | 275 fDecoderMgr->dinfo()->dither_mode = JDITHER_NONE; |
| 265 fDecoderMgr->dinfo()->out_color_space = JCS_RGB565; | 276 fDecoderMgr->dinfo()->out_color_space = JCS_RGB565; |
| 277 #endif | |
| 266 } | 278 } |
| 267 return true; | 279 return true; |
| 268 case kGray_8_SkColorType: | 280 case kGray_8_SkColorType: |
| 269 if (isCMYK) { | 281 if (isCMYK) { |
| 270 return false; | 282 return false; |
| 271 } else { | 283 } else { |
| 272 // We will enable decodes to gray even if the image is color bec ause this is | 284 // We will enable decodes to gray even if the image is color bec ause this is |
| 273 // much faster than decoding to color and then converting | 285 // much faster than decoding to color and then converting |
| 274 fDecoderMgr->dinfo()->out_color_space = JCS_GRAYSCALE; | 286 fDecoderMgr->dinfo()->out_color_space = JCS_GRAYSCALE; |
| 275 } | 287 } |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 390 srcConfig = SkSwizzler::kRGBX; | 402 srcConfig = SkSwizzler::kRGBX; |
| 391 break; | 403 break; |
| 392 case kBGRA_8888_SkColorType: | 404 case kBGRA_8888_SkColorType: |
| 393 srcConfig = SkSwizzler::kBGRX; | 405 srcConfig = SkSwizzler::kBGRX; |
| 394 break; | 406 break; |
| 395 case kRGB_565_SkColorType: | 407 case kRGB_565_SkColorType: |
| 396 srcConfig = SkSwizzler::kRGB_565; | 408 srcConfig = SkSwizzler::kRGB_565; |
| 397 break; | 409 break; |
| 398 default: | 410 default: |
| 399 // This function should only be called if the colorType is supported by jpeg | 411 // This function should only be called if the colorType is supported by jpeg |
| 412 #if defined(GOOGLE3) | |
| 413 SK_CRASH(); | |
|
scroggo
2015/10/27 13:51:23
Why this difference? I assume that SkASSERT works
dogben
2015/10/27 15:07:22
Sorry, I added this before https://codereview.chro
| |
| 414 #else | |
| 400 SkASSERT(false); | 415 SkASSERT(false); |
| 416 #endif | |
| 401 } | 417 } |
| 402 | 418 |
| 403 fSwizzler.reset(SkSwizzler::CreateSwizzler(srcConfig, nullptr, dstInfo, opti ons)); | 419 fSwizzler.reset(SkSwizzler::CreateSwizzler(srcConfig, nullptr, dstInfo, opti ons)); |
| 404 fStorage.reset(get_row_bytes(fDecoderMgr->dinfo())); | 420 fStorage.reset(get_row_bytes(fDecoderMgr->dinfo())); |
| 405 fSrcRow = static_cast<uint8_t*>(fStorage.get()); | 421 fSrcRow = static_cast<uint8_t*>(fStorage.get()); |
| 406 } | 422 } |
| 407 | 423 |
| 408 SkSampler* SkJpegCodec::getSampler(bool createIfNecessary) { | 424 SkSampler* SkJpegCodec::getSampler(bool createIfNecessary) { |
| 409 if (!createIfNecessary || fSwizzler) { | 425 if (!createIfNecessary || fSwizzler) { |
| 410 SkASSERT(!fSwizzler || (fSrcRow && static_cast<uint8_t*>(fStorage.get()) == fSrcRow)); | 426 SkASSERT(!fSwizzler || (fSrcRow && static_cast<uint8_t*>(fStorage.get()) == fSrcRow)); |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 481 dst = SkTAddOffset<JSAMPLE>(dst, rowBytes); | 497 dst = SkTAddOffset<JSAMPLE>(dst, rowBytes); |
| 482 } else { | 498 } else { |
| 483 dstRow = SkTAddOffset<JSAMPLE>(dstRow, rowBytes); | 499 dstRow = SkTAddOffset<JSAMPLE>(dstRow, rowBytes); |
| 484 } | 500 } |
| 485 } | 501 } |
| 486 return count; | 502 return count; |
| 487 } | 503 } |
| 488 | 504 |
| 489 #ifndef TURBO_HAS_SKIP | 505 #ifndef TURBO_HAS_SKIP |
| 490 // TODO (msarett): Avoid reallocating the memory buffer on each call to skip. | 506 // TODO (msarett): Avoid reallocating the memory buffer on each call to skip. |
| 491 static uint32_t jpeg_skip_scanlines(dinfo, count) { | 507 static uint32_t jpeg_skip_scanlines(jpeg_decompress_struct* dinfo, int count) { |
|
msarett
2015/10/15 15:02:33
+1
| |
| 492 SkAutoMalloc storage(get_row_bytes(dinfo)); | 508 SkAutoMalloc storage(get_row_bytes(dinfo)); |
| 493 uint8_t* storagePtr = static_cast<uint8_t*>(storage.get()); | 509 uint8_t* storagePtr = static_cast<uint8_t*>(storage.get()); |
| 494 for (int y = 0; y < count; y++) { | 510 for (int y = 0; y < count; y++) { |
| 495 if (1 != jpeg_read_scanlines(dinfo, &storagePtr, 1)) { | 511 if (1 != jpeg_read_scanlines(dinfo, &storagePtr, 1)) { |
| 496 return y; | 512 return y; |
| 497 } | 513 } |
| 498 } | 514 } |
| 499 return count; | 515 return count; |
| 500 } | 516 } |
| 501 #endif | 517 #endif |
| 502 | 518 |
| 503 bool SkJpegCodec::onSkipScanlines(int count) { | 519 bool SkJpegCodec::onSkipScanlines(int count) { |
| 504 // Set the jump location for libjpeg errors | 520 // Set the jump location for libjpeg errors |
| 505 if (setjmp(fDecoderMgr->getJmpBuf())) { | 521 if (setjmp(fDecoderMgr->getJmpBuf())) { |
| 506 return fDecoderMgr->returnFalse("setjmp"); | 522 return fDecoderMgr->returnFalse("setjmp"); |
| 507 } | 523 } |
| 508 | 524 |
| 509 return (uint32_t) count == jpeg_skip_scanlines(fDecoderMgr->dinfo(), count); | 525 return (uint32_t) count == jpeg_skip_scanlines(fDecoderMgr->dinfo(), count); |
| 510 } | 526 } |
| OLD | NEW |