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

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

Issue 2318253004: Revert of Add color xform support to SkWebpCodec (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 3 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/SkCodecPriv.h ('k') | src/codec/SkWebpCodec.cpp » ('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 "SkBitmap.h" 8 #include "SkBitmap.h"
9 #include "SkCodecPriv.h" 9 #include "SkCodecPriv.h"
10 #include "SkColorPriv.h" 10 #include "SkColorPriv.h"
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 fPng_ptr = nullptr; 87 fPng_ptr = nullptr;
88 fInfo_ptr = nullptr; 88 fInfo_ptr = nullptr;
89 } 89 }
90 90
91 private: 91 private:
92 png_structp fPng_ptr; 92 png_structp fPng_ptr;
93 png_infop fInfo_ptr; 93 png_infop fInfo_ptr;
94 }; 94 };
95 #define AutoCleanPng(...) SK_REQUIRE_LOCAL_VAR(AutoCleanPng) 95 #define AutoCleanPng(...) SK_REQUIRE_LOCAL_VAR(AutoCleanPng)
96 96
97 static inline SkAlphaType xform_alpha_type(SkAlphaType dstAlphaType, SkAlphaType srcAlphaType) {
98 return (kOpaque_SkAlphaType == srcAlphaType) ? kOpaque_SkAlphaType : dstAlph aType;
99 }
100
97 // Note: SkColorTable claims to store SkPMColors, which is not necessarily the c ase here. 101 // Note: SkColorTable claims to store SkPMColors, which is not necessarily the c ase here.
98 bool SkPngCodec::createColorTable(const SkImageInfo& dstInfo, int* ctableCount) { 102 bool SkPngCodec::createColorTable(const SkImageInfo& dstInfo, int* ctableCount) {
99 103
100 int numColors; 104 int numColors;
101 png_color* palette; 105 png_color* palette;
102 if (!png_get_PLTE(fPng_ptr, fInfo_ptr, &palette, &numColors)) { 106 if (!png_get_PLTE(fPng_ptr, fInfo_ptr, &palette, &numColors)) {
103 return false; 107 return false;
104 } 108 }
105 109
106 // Contents depend on tableColorType and our choice of if/when to premultipl y: 110 // Contents depend on tableColorType and our choice of if/when to premultipl y:
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 SkOpts::RGB_to_BGR1(colorTable + numColorsWithAlpha, palette, 148 SkOpts::RGB_to_BGR1(colorTable + numColorsWithAlpha, palette,
145 numColors - numColorsWithAlpha); 149 numColors - numColorsWithAlpha);
146 } 150 }
147 } 151 }
148 152
149 // If we are not decoding to F16, we can color xform now and store the resul ts 153 // If we are not decoding to F16, we can color xform now and store the resul ts
150 // in the color table. 154 // in the color table.
151 if (fColorXform && kRGBA_F16_SkColorType != dstInfo.colorType()) { 155 if (fColorXform && kRGBA_F16_SkColorType != dstInfo.colorType()) {
152 SkColorType xformColorType = is_rgba(dstInfo.colorType()) ? 156 SkColorType xformColorType = is_rgba(dstInfo.colorType()) ?
153 kRGBA_8888_SkColorType : kBGRA_8888_SkColorType; 157 kRGBA_8888_SkColorType : kBGRA_8888_SkColorType;
154 SkAlphaType xformAlphaType = select_alpha_xform(dstInfo.alphaType(), 158 SkAlphaType xformAlphaType = xform_alpha_type(dstInfo.alphaType(),
155 this->getInfo().alphaTyp e()); 159 this->getInfo().alphaType( ));
156 fColorXform->apply(colorTable, colorTable, numColors, xformColorType, xf ormAlphaType); 160 fColorXform->apply(colorTable, colorTable, numColors, xformColorType, xf ormAlphaType);
157 } 161 }
158 162
159 // Pad the color table with the last color in the table (or black) in the ca se that 163 // 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. 164 // invalid pixel indices exceed the number of colors in the table.
161 const int maxColors = 1 << fBitDepth; 165 const int maxColors = 1 << fBitDepth;
162 if (numColors < maxColors) { 166 if (numColors < maxColors) {
163 SkPMColor lastColor = numColors > 0 ? colorTable[numColors - 1] : SK_Col orBLACK; 167 SkPMColor lastColor = numColors > 0 ? colorTable[numColors - 1] : SK_Col orBLACK;
164 sk_memset32(colorTable + numColors, lastColor, maxColors - numColors); 168 sk_memset32(colorTable + numColors, lastColor, maxColors - numColors);
165 } 169 }
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 override { 440 override {
437 SkASSERT(0 == startRow); 441 SkASSERT(0 == startRow);
438 442
439 // Assume that an error in libpng indicates an incomplete input. 443 // Assume that an error in libpng indicates an incomplete input.
440 int y = 0; 444 int y = 0;
441 if (setjmp(png_jmpbuf((png_struct*)fPng_ptr))) { 445 if (setjmp(png_jmpbuf((png_struct*)fPng_ptr))) {
442 SkCodecPrintf("Failed to read row.\n"); 446 SkCodecPrintf("Failed to read row.\n");
443 return y; 447 return y;
444 } 448 }
445 449
446 SkAlphaType xformAlphaType = select_alpha_xform(dstInfo.alphaType(), 450 SkAlphaType xformAlphaType = xform_alpha_type(dstInfo.alphaType(),
447 this->getInfo().alphaTyp e()); 451 this->getInfo().alphaType( ));
448 int width = fSwizzler ? fSwizzler->swizzleWidth() : dstInfo.width(); 452 int width = fSwizzler ? fSwizzler->swizzleWidth() : dstInfo.width();
449 453
450 for (; y < count; y++) { 454 for (; y < count; y++) {
451 png_read_row(fPng_ptr, fSwizzlerSrcRow, nullptr); 455 png_read_row(fPng_ptr, fSwizzlerSrcRow, nullptr);
452 this->applyXformRow(dst, fSwizzlerSrcRow, dstInfo.colorType(), xform AlphaType, width); 456 this->applyXformRow(dst, fSwizzlerSrcRow, dstInfo.colorType(), xform AlphaType, width);
453 dst = SkTAddOffset<void>(dst, rowBytes); 457 dst = SkTAddOffset<void>(dst, rowBytes);
454 } 458 }
455 459
456 return y; 460 return y;
457 } 461 }
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 for (int y = 0; y < count; y++) { 526 for (int y = 0; y < count; y++) {
523 png_read_row(fPng_ptr, srcRow, nullptr); 527 png_read_row(fPng_ptr, srcRow, nullptr);
524 srcRow += fSrcRowBytes; 528 srcRow += fSrcRowBytes;
525 } 529 }
526 // Discard rows that we don't need. 530 // Discard rows that we don't need.
527 for (int y = 0; y < this->getInfo().height() - startRow - count; y++ ) { 531 for (int y = 0; y < this->getInfo().height() - startRow - count; y++ ) {
528 png_read_row(fPng_ptr, fSwizzlerSrcRow, nullptr); 532 png_read_row(fPng_ptr, fSwizzlerSrcRow, nullptr);
529 } 533 }
530 } 534 }
531 535
532 SkAlphaType xformAlphaType = select_alpha_xform(dstInfo.alphaType(), 536 SkAlphaType xformAlphaType = xform_alpha_type(dstInfo.alphaType(),
533 this->getInfo().alphaTyp e()); 537 this->getInfo().alphaType( ));
534 int width = fSwizzler ? fSwizzler->swizzleWidth() : dstInfo.width(); 538 int width = fSwizzler ? fSwizzler->swizzleWidth() : dstInfo.width();
535 srcRow = storage.get(); 539 srcRow = storage.get();
536 for (int y = 0; y < count; y++) { 540 for (int y = 0; y < count; y++) {
537 this->applyXformRow(dst, srcRow, dstInfo.colorType(), xformAlphaType , width); 541 this->applyXformRow(dst, srcRow, dstInfo.colorType(), xformAlphaType , width);
538 srcRow = SkTAddOffset<uint8_t>(srcRow, fSrcRowBytes); 542 srcRow = SkTAddOffset<uint8_t>(srcRow, fSrcRowBytes);
539 dst = SkTAddOffset<void>(dst, rowBytes); 543 dst = SkTAddOffset<void>(dst, rowBytes);
540 } 544 }
541 545
542 return count; 546 return count;
543 } 547 }
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after
941 SkCodec* outCodec; 945 SkCodec* outCodec;
942 if (read_header(stream, chunkReader, &outCodec, nullptr, nullptr)) { 946 if (read_header(stream, chunkReader, &outCodec, nullptr, nullptr)) {
943 // Codec has taken ownership of the stream. 947 // Codec has taken ownership of the stream.
944 SkASSERT(outCodec); 948 SkASSERT(outCodec);
945 streamDeleter.release(); 949 streamDeleter.release();
946 return outCodec; 950 return outCodec;
947 } 951 }
948 952
949 return nullptr; 953 return nullptr;
950 } 954 }
OLDNEW
« no previous file with comments | « src/codec/SkCodecPriv.h ('k') | src/codec/SkWebpCodec.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698