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 "SkBitmap.h" | 8 #include "SkBitmap.h" |
| 9 #include "SkCodecPriv.h" | 9 #include "SkCodecPriv.h" |
| 10 #include "SkColorPriv.h" | 10 #include "SkColorPriv.h" |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 142 numColors - numColorsWithAlpha); | 142 numColors - numColorsWithAlpha); |
| 143 } else { | 143 } else { |
| 144 SkOpts::RGB_to_BGR1(colorTable + numColorsWithAlpha, palette, | 144 SkOpts::RGB_to_BGR1(colorTable + numColorsWithAlpha, palette, |
| 145 numColors - numColorsWithAlpha); | 145 numColors - numColorsWithAlpha); |
| 146 } | 146 } |
| 147 } | 147 } |
| 148 | 148 |
| 149 // If we are not decoding to F16, we can color xform now and store the resul ts | 149 // If we are not decoding to F16, we can color xform now and store the resul ts |
| 150 // in the color table. | 150 // in the color table. |
| 151 if (fColorXform && kRGBA_F16_SkColorType != dstInfo.colorType()) { | 151 if (fColorXform && kRGBA_F16_SkColorType != dstInfo.colorType()) { |
| 152 SkColorType xformColorType = is_rgba(dstInfo.colorType()) ? | 152 SkColorSpaceXform::ColorFormat xformColorFormat = is_rgba(dstInfo.colorT ype()) ? |
| 153 kRGBA_8888_SkColorType : kBGRA_8888_SkColorType; | 153 SkColorSpaceXform::kRGBA_8888_ColorFormat : |
| 154 SkAlphaType xformAlphaType = select_alpha_xform(dstInfo.alphaType(), | 154 SkColorSpaceXform::kBGRA_8888_ColorFormat; |
| 155 SkAlphaType xformAlphaType = select_xform_alpha(dstInfo.alphaType(), | |
| 155 this->getInfo().alphaTyp e()); | 156 this->getInfo().alphaTyp e()); |
| 156 fColorXform->apply(colorTable, colorTable, numColors, xformColorType, xf ormAlphaType); | 157 fColorXform->apply(colorTable, colorTable, numColors, xformColorFormat, xformAlphaType); |
| 157 } | 158 } |
| 158 | 159 |
| 159 // Pad the color table with the last color in the table (or black) in the ca se that | 160 // Pad the color table with the last color in the table (or black) in the ca se that |
| 160 // invalid pixel indices exceed the number of colors in the table. | 161 // invalid pixel indices exceed the number of colors in the table. |
| 161 const int maxColors = 1 << fBitDepth; | 162 const int maxColors = 1 << fBitDepth; |
| 162 if (numColors < maxColors) { | 163 if (numColors < maxColors) { |
| 163 SkPMColor lastColor = numColors > 0 ? colorTable[numColors - 1] : SK_Col orBLACK; | 164 SkPMColor lastColor = numColors > 0 ? colorTable[numColors - 1] : SK_Col orBLACK; |
| 164 sk_memset32(colorTable + numColors, lastColor, maxColors - numColors); | 165 sk_memset32(colorTable + numColors, lastColor, maxColors - numColors); |
| 165 } | 166 } |
| 166 | 167 |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 373 fStorage.reset(SkAlign4(fSrcRowBytes) + colorXformBytes); | 374 fStorage.reset(SkAlign4(fSrcRowBytes) + colorXformBytes); |
| 374 fSwizzlerSrcRow = fStorage.get(); | 375 fSwizzlerSrcRow = fStorage.get(); |
| 375 fColorXformSrcRow = SkTAddOffset<uint32_t>(fSwizzlerSrcRow, SkAlign4 (fSrcRowBytes)); | 376 fColorXformSrcRow = SkTAddOffset<uint32_t>(fSwizzlerSrcRow, SkAlign4 (fSrcRowBytes)); |
| 376 break; | 377 break; |
| 377 } | 378 } |
| 378 } | 379 } |
| 379 } | 380 } |
| 380 | 381 |
| 381 void SkPngCodec::applyXformRow(void* dst, const void* src, SkColorType colorType , | 382 void SkPngCodec::applyXformRow(void* dst, const void* src, SkColorType colorType , |
| 382 SkAlphaType alphaType, int width) { | 383 SkAlphaType alphaType, int width) { |
| 384 SkColorSpaceXform::ColorFormat colorFormat = select_xform_format(colorType); | |
|
msarett
2016/09/14 20:20:35
Leon, ideally your PNG change can land first? I t
scroggo
2016/09/14 20:35:01
That depends. How much of a hurry are you to get t
msarett
2016/09/14 21:09:43
I'll probably want to write some stuff based on th
| |
| 383 switch (fXformMode) { | 385 switch (fXformMode) { |
| 384 case kSwizzleOnly_XformMode: | 386 case kSwizzleOnly_XformMode: |
| 385 fSwizzler->swizzle(dst, (const uint8_t*) src); | 387 fSwizzler->swizzle(dst, (const uint8_t*) src); |
| 386 break; | 388 break; |
| 387 case kColorOnly_XformMode: | 389 case kColorOnly_XformMode: |
| 388 fColorXform->apply(dst, (const uint32_t*) src, width, colorType, alp haType); | 390 fColorXform->apply(dst, (const uint32_t*) src, width, colorFormat, a lphaType); |
| 389 break; | 391 break; |
| 390 case kSwizzleColor_XformMode: | 392 case kSwizzleColor_XformMode: |
| 391 fSwizzler->swizzle(fColorXformSrcRow, (const uint8_t*) src); | 393 fSwizzler->swizzle(fColorXformSrcRow, (const uint8_t*) src); |
| 392 fColorXform->apply(dst, fColorXformSrcRow, width, colorType, alphaTy pe); | 394 fColorXform->apply(dst, fColorXformSrcRow, width, colorFormat, alpha Type); |
| 393 break; | 395 break; |
| 394 } | 396 } |
| 395 } | 397 } |
| 396 | 398 |
| 397 class SkPngNormalCodec : public SkPngCodec { | 399 class SkPngNormalCodec : public SkPngCodec { |
| 398 public: | 400 public: |
| 399 SkPngNormalCodec(const SkEncodedInfo& encodedInfo, const SkImageInfo& imageI nfo, | 401 SkPngNormalCodec(const SkEncodedInfo& encodedInfo, const SkImageInfo& imageI nfo, |
| 400 SkStream* stream, SkPngChunkReader* chunkReader, png_structp png_ptr , | 402 SkStream* stream, SkPngChunkReader* chunkReader, png_structp png_ptr , |
| 401 png_infop info_ptr, int bitDepth) | 403 png_infop info_ptr, int bitDepth) |
| 402 : INHERITED(encodedInfo, imageInfo, stream, chunkReader, png_ptr, info_p tr, bitDepth, 1) | 404 : INHERITED(encodedInfo, imageInfo, stream, chunkReader, png_ptr, info_p tr, bitDepth, 1) |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 418 override { | 420 override { |
| 419 SkASSERT(0 == startRow); | 421 SkASSERT(0 == startRow); |
| 420 | 422 |
| 421 // Assume that an error in libpng indicates an incomplete input. | 423 // Assume that an error in libpng indicates an incomplete input. |
| 422 int y = 0; | 424 int y = 0; |
| 423 if (setjmp(png_jmpbuf((png_struct*)fPng_ptr))) { | 425 if (setjmp(png_jmpbuf((png_struct*)fPng_ptr))) { |
| 424 SkCodecPrintf("Failed to read row.\n"); | 426 SkCodecPrintf("Failed to read row.\n"); |
| 425 return y; | 427 return y; |
| 426 } | 428 } |
| 427 | 429 |
| 428 SkAlphaType xformAlphaType = select_alpha_xform(dstInfo.alphaType(), | 430 SkAlphaType xformAlphaType = select_xform_alpha(dstInfo.alphaType(), |
| 429 this->getInfo().alphaTyp e()); | 431 this->getInfo().alphaTyp e()); |
| 430 int width = fSwizzler ? fSwizzler->swizzleWidth() : dstInfo.width(); | 432 int width = fSwizzler ? fSwizzler->swizzleWidth() : dstInfo.width(); |
| 431 | 433 |
| 432 for (; y < count; y++) { | 434 for (; y < count; y++) { |
| 433 png_read_row(fPng_ptr, fSwizzlerSrcRow, nullptr); | 435 png_read_row(fPng_ptr, fSwizzlerSrcRow, nullptr); |
| 434 this->applyXformRow(dst, fSwizzlerSrcRow, dstInfo.colorType(), xform AlphaType, width); | 436 this->applyXformRow(dst, fSwizzlerSrcRow, dstInfo.colorType(), xform AlphaType, width); |
| 435 dst = SkTAddOffset<void>(dst, rowBytes); | 437 dst = SkTAddOffset<void>(dst, rowBytes); |
| 436 } | 438 } |
| 437 | 439 |
| 438 return y; | 440 return y; |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 504 for (int y = 0; y < count; y++) { | 506 for (int y = 0; y < count; y++) { |
| 505 png_read_row(fPng_ptr, srcRow, nullptr); | 507 png_read_row(fPng_ptr, srcRow, nullptr); |
| 506 srcRow += fSrcRowBytes; | 508 srcRow += fSrcRowBytes; |
| 507 } | 509 } |
| 508 // Discard rows that we don't need. | 510 // Discard rows that we don't need. |
| 509 for (int y = 0; y < this->getInfo().height() - startRow - count; y++ ) { | 511 for (int y = 0; y < this->getInfo().height() - startRow - count; y++ ) { |
| 510 png_read_row(fPng_ptr, fSwizzlerSrcRow, nullptr); | 512 png_read_row(fPng_ptr, fSwizzlerSrcRow, nullptr); |
| 511 } | 513 } |
| 512 } | 514 } |
| 513 | 515 |
| 514 SkAlphaType xformAlphaType = select_alpha_xform(dstInfo.alphaType(), | 516 SkAlphaType xformAlphaType = select_xform_alpha(dstInfo.alphaType(), |
| 515 this->getInfo().alphaTyp e()); | 517 this->getInfo().alphaTyp e()); |
| 516 int width = fSwizzler ? fSwizzler->swizzleWidth() : dstInfo.width(); | 518 int width = fSwizzler ? fSwizzler->swizzleWidth() : dstInfo.width(); |
| 517 srcRow = storage.get(); | 519 srcRow = storage.get(); |
| 518 for (int y = 0; y < count; y++) { | 520 for (int y = 0; y < count; y++) { |
| 519 this->applyXformRow(dst, srcRow, dstInfo.colorType(), xformAlphaType , width); | 521 this->applyXformRow(dst, srcRow, dstInfo.colorType(), xformAlphaType , width); |
| 520 srcRow = SkTAddOffset<uint8_t>(srcRow, fSrcRowBytes); | 522 srcRow = SkTAddOffset<uint8_t>(srcRow, fSrcRowBytes); |
| 521 dst = SkTAddOffset<void>(dst, rowBytes); | 523 dst = SkTAddOffset<void>(dst, rowBytes); |
| 522 } | 524 } |
| 523 | 525 |
| 524 return count; | 526 return count; |
| (...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 895 *rowsDecoded = count; | 897 *rowsDecoded = count; |
| 896 return kIncompleteInput; | 898 return kIncompleteInput; |
| 897 } | 899 } |
| 898 | 900 |
| 899 return kSuccess; | 901 return kSuccess; |
| 900 } | 902 } |
| 901 | 903 |
| 902 uint64_t SkPngCodec::onGetFillValue(const SkImageInfo& dstInfo) const { | 904 uint64_t SkPngCodec::onGetFillValue(const SkImageInfo& dstInfo) const { |
| 903 const SkPMColor* colorPtr = get_color_ptr(fColorTable.get()); | 905 const SkPMColor* colorPtr = get_color_ptr(fColorTable.get()); |
| 904 if (colorPtr) { | 906 if (colorPtr) { |
| 905 SkAlphaType alphaType = select_alpha_xform(dstInfo.alphaType(), | 907 SkAlphaType alphaType = select_xform_alpha(dstInfo.alphaType(), |
| 906 this->getInfo().alphaType()); | 908 this->getInfo().alphaType()); |
| 907 return get_color_table_fill_value(dstInfo.colorType(), alphaType, colorP tr, 0, | 909 return get_color_table_fill_value(dstInfo.colorType(), alphaType, colorP tr, 0, |
| 908 fColorXform.get()); | 910 fColorXform.get()); |
| 909 } | 911 } |
| 910 return INHERITED::onGetFillValue(dstInfo); | 912 return INHERITED::onGetFillValue(dstInfo); |
| 911 } | 913 } |
| 912 | 914 |
| 913 SkCodec* SkPngCodec::NewFromStream(SkStream* stream, SkPngChunkReader* chunkRead er) { | 915 SkCodec* SkPngCodec::NewFromStream(SkStream* stream, SkPngChunkReader* chunkRead er) { |
| 914 SkAutoTDelete<SkStream> streamDeleter(stream); | 916 SkAutoTDelete<SkStream> streamDeleter(stream); |
| 915 | 917 |
| 916 SkCodec* outCodec; | 918 SkCodec* outCodec; |
| 917 if (read_header(stream, chunkReader, &outCodec, nullptr, nullptr)) { | 919 if (read_header(stream, chunkReader, &outCodec, nullptr, nullptr)) { |
| 918 // Codec has taken ownership of the stream. | 920 // Codec has taken ownership of the stream. |
| 919 SkASSERT(outCodec); | 921 SkASSERT(outCodec); |
| 920 streamDeleter.release(); | 922 streamDeleter.release(); |
| 921 return outCodec; | 923 return outCodec; |
| 922 } | 924 } |
| 923 | 925 |
| 924 return nullptr; | 926 return nullptr; |
| 925 } | 927 } |
| OLD | NEW |