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

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

Issue 2339233003: Support Float32 output from SkColorSpaceXform (Closed)
Patch Set: Remove gpu changes 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/SkPngCodec.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 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 numColors - numColorsWithAlpha); 260 numColors - numColorsWithAlpha);
261 } else { 261 } else {
262 SkOpts::RGB_to_BGR1(colorTable + numColorsWithAlpha, palette, 262 SkOpts::RGB_to_BGR1(colorTable + numColorsWithAlpha, palette,
263 numColors - numColorsWithAlpha); 263 numColors - numColorsWithAlpha);
264 } 264 }
265 } 265 }
266 266
267 // If we are not decoding to F16, we can color xform now and store the resul ts 267 // If we are not decoding to F16, we can color xform now and store the resul ts
268 // in the color table. 268 // in the color table.
269 if (fColorXform && kRGBA_F16_SkColorType != dstInfo.colorType()) { 269 if (fColorXform && kRGBA_F16_SkColorType != dstInfo.colorType()) {
270 SkColorType xformColorType = is_rgba(dstInfo.colorType()) ? 270 SkColorSpaceXform::ColorFormat xformColorFormat = is_rgba(dstInfo.colorT ype()) ?
271 kRGBA_8888_SkColorType : kBGRA_8888_SkColorType; 271 SkColorSpaceXform::kRGBA_8888_ColorFormat :
272 SkAlphaType xformAlphaType = select_alpha_xform(dstInfo.alphaType(), 272 SkColorSpaceXform::kBGRA_8888_ColorFormat;
273 SkAlphaType xformAlphaType = select_xform_alpha(dstInfo.alphaType(),
273 this->getInfo().alphaTyp e()); 274 this->getInfo().alphaTyp e());
274 fColorXform->apply(colorTable, colorTable, numColors, xformColorType, xf ormAlphaType); 275 fColorXform->apply(colorTable, colorTable, numColors, xformColorFormat, xformAlphaType);
275 } 276 }
276 277
277 // Pad the color table with the last color in the table (or black) in the ca se that 278 // Pad the color table with the last color in the table (or black) in the ca se that
278 // invalid pixel indices exceed the number of colors in the table. 279 // invalid pixel indices exceed the number of colors in the table.
279 const int maxColors = 1 << fBitDepth; 280 const int maxColors = 1 << fBitDepth;
280 if (numColors < maxColors) { 281 if (numColors < maxColors) {
281 SkPMColor lastColor = numColors > 0 ? colorTable[numColors - 1] : SK_Col orBLACK; 282 SkPMColor lastColor = numColors > 0 ? colorTable[numColors - 1] : SK_Col orBLACK;
282 sk_memset32(colorTable + numColors, lastColor, maxColors - numColors); 283 sk_memset32(colorTable + numColors, lastColor, maxColors - numColors);
283 } 284 }
284 285
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
485 case kSwizzleColor_XformMode: { 486 case kSwizzleColor_XformMode: {
486 const size_t colorXformBytes = dstInfo.width() * sizeof(uint32_t); 487 const size_t colorXformBytes = dstInfo.width() * sizeof(uint32_t);
487 fStorage.reset(colorXformBytes); 488 fStorage.reset(colorXformBytes);
488 fColorXformSrcRow = (uint32_t*) fStorage.get(); 489 fColorXformSrcRow = (uint32_t*) fStorage.get();
489 break; 490 break;
490 } 491 }
491 } 492 }
492 } 493 }
493 494
494 void SkPngCodec::applyXformRow(void* dst, const void* src) { 495 void SkPngCodec::applyXformRow(void* dst, const void* src) {
495 const SkColorType colorType = this->dstInfo().colorType();
496 switch (fXformMode) { 496 switch (fXformMode) {
497 case kSwizzleOnly_XformMode: 497 case kSwizzleOnly_XformMode:
498 fSwizzler->swizzle(dst, (const uint8_t*) src); 498 fSwizzler->swizzle(dst, (const uint8_t*) src);
499 break; 499 break;
500 case kColorOnly_XformMode: 500 case kColorOnly_XformMode:
501 fColorXform->apply(dst, (const uint32_t*) src, fXformWidth, colorTyp e, fXformAlphaType); 501 fColorXform->apply(dst, (const uint32_t*) src, fXformWidth, fXformCo lorFormat,
502 fXformAlphaType);
502 break; 503 break;
503 case kSwizzleColor_XformMode: 504 case kSwizzleColor_XformMode:
504 fSwizzler->swizzle(fColorXformSrcRow, (const uint8_t*) src); 505 fSwizzler->swizzle(fColorXformSrcRow, (const uint8_t*) src);
505 fColorXform->apply(dst, fColorXformSrcRow, fXformWidth, colorType, f XformAlphaType); 506 fColorXform->apply(dst, fColorXformSrcRow, fXformWidth, fXformColorF ormat,
507 fXformAlphaType);
506 break; 508 break;
507 } 509 }
508 } 510 }
509 511
510 class SkPngNormalDecoder : public SkPngCodec { 512 class SkPngNormalDecoder : public SkPngCodec {
511 public: 513 public:
512 SkPngNormalDecoder(const SkEncodedInfo& info, const SkImageInfo& imageInfo, SkStream* stream, 514 SkPngNormalDecoder(const SkEncodedInfo& info, const SkImageInfo& imageInfo, SkStream* stream,
513 SkPngChunkReader* reader, png_structp png_ptr, png_infop info_ptr, i nt bitDepth) 515 SkPngChunkReader* reader, png_structp png_ptr, png_infop info_ptr, i nt bitDepth)
514 : INHERITED(info, imageInfo, stream, reader, png_ptr, info_ptr, bitDepth ) 516 : INHERITED(info, imageInfo, stream, reader, png_ptr, info_ptr, bitDepth )
515 , fLinesDecoded(0) 517 , fLinesDecoded(0)
(...skipping 614 matching lines...) Expand 10 before | Expand all | Expand 10 after
1130 } 1132 }
1131 } 1133 }
1132 1134
1133 // Copy the color table to the client if they request kIndex8 mode. 1135 // Copy the color table to the client if they request kIndex8 mode.
1134 copy_color_table(dstInfo, fColorTable, ctable, ctableCount); 1136 copy_color_table(dstInfo, fColorTable, ctable, ctableCount);
1135 1137
1136 this->initializeSwizzler(dstInfo, options); 1138 this->initializeSwizzler(dstInfo, options);
1137 return true; 1139 return true;
1138 } 1140 }
1139 1141
1140 void SkPngCodec::initializeXformAlphaAndWidth() { 1142 void SkPngCodec::initializeXformParams() {
1141 fXformAlphaType = select_alpha_xform(this->dstInfo().alphaType(), this->getI nfo().alphaType()); 1143 switch (fXformMode) {
1142 fXformWidth = this->swizzler() ? this->swizzler()->swizzleWidth() : this->ds tInfo().width(); 1144 case kColorOnly_XformMode:
1145 fXformColorFormat = select_xform_format(this->dstInfo().colorType()) ;
1146 fXformAlphaType = select_xform_alpha(this->dstInfo().alphaType(),
1147 this->getInfo().alphaType());
1148 fXformWidth = this->dstInfo().width();
1149 break;
1150 case kSwizzleColor_XformMode:
1151 fXformColorFormat = select_xform_format(this->dstInfo().colorType()) ;
1152 fXformAlphaType = select_xform_alpha(this->dstInfo().alphaType(),
1153 this->getInfo().alphaType());
1154 fXformWidth = this->swizzler()->swizzleWidth();
1155 break;
1156 default:
1157 break;
1158 }
1143 } 1159 }
1144 1160
1145 static inline bool apply_xform_on_decode(SkColorType dstColorType, SkEncodedInfo ::Color srcColor) { 1161 static inline bool apply_xform_on_decode(SkColorType dstColorType, SkEncodedInfo ::Color srcColor) {
1146 // We will apply the color xform when reading the color table, unless F16 is requested. 1162 // We will apply the color xform when reading the color table, unless F16 is requested.
1147 return SkEncodedInfo::kPalette_Color != srcColor || kRGBA_F16_SkColorType == dstColorType; 1163 return SkEncodedInfo::kPalette_Color != srcColor || kRGBA_F16_SkColorType == dstColorType;
1148 } 1164 }
1149 1165
1150 void SkPngCodec::initializeSwizzler(const SkImageInfo& dstInfo, const Options& o ptions) { 1166 void SkPngCodec::initializeSwizzler(const SkImageInfo& dstInfo, const Options& o ptions) {
1151 SkImageInfo swizzlerInfo = dstInfo; 1167 SkImageInfo swizzlerInfo = dstInfo;
1152 Options swizzlerOptions = options; 1168 Options swizzlerOptions = options;
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
1219 if (!this->rereadHeaderIfNecessary()) { 1235 if (!this->rereadHeaderIfNecessary()) {
1220 return kCouldNotRewind; 1236 return kCouldNotRewind;
1221 } 1237 }
1222 #endif 1238 #endif
1223 1239
1224 if (options.fSubset) { 1240 if (options.fSubset) {
1225 return kUnimplemented; 1241 return kUnimplemented;
1226 } 1242 }
1227 1243
1228 this->allocateStorage(dstInfo); 1244 this->allocateStorage(dstInfo);
1229 this->initializeXformAlphaAndWidth(); 1245 this->initializeXformParams();
1230 return this->decodeAllRows(dst, rowBytes, rowsDecoded); 1246 return this->decodeAllRows(dst, rowBytes, rowsDecoded);
1231 } 1247 }
1232 1248
1233 SkCodec::Result SkPngCodec::onStartIncrementalDecode(const SkImageInfo& dstInfo, 1249 SkCodec::Result SkPngCodec::onStartIncrementalDecode(const SkImageInfo& dstInfo,
1234 void* dst, size_t rowBytes, const SkCodec::Options& options, 1250 void* dst, size_t rowBytes, const SkCodec::Options& options,
1235 SkPMColor* ctable, int* ctableCount) { 1251 SkPMColor* ctable, int* ctableCount) {
1236 if (!conversion_possible(dstInfo, this->getInfo()) || 1252 if (!conversion_possible(dstInfo, this->getInfo()) ||
1237 !this->initializeXforms(dstInfo, options, ctable, ctableCount)) 1253 !this->initializeXforms(dstInfo, options, ctable, ctableCount))
1238 { 1254 {
1239 return kInvalidConversion; 1255 return kInvalidConversion;
(...skipping 14 matching lines...) Expand all
1254 } else { 1270 } else {
1255 firstRow = 0; 1271 firstRow = 0;
1256 lastRow = dstInfo.height() - 1; 1272 lastRow = dstInfo.height() - 1;
1257 } 1273 }
1258 this->setRange(firstRow, lastRow, dst, rowBytes); 1274 this->setRange(firstRow, lastRow, dst, rowBytes);
1259 return kSuccess; 1275 return kSuccess;
1260 } 1276 }
1261 1277
1262 SkCodec::Result SkPngCodec::onIncrementalDecode(int* rowsDecoded) { 1278 SkCodec::Result SkPngCodec::onIncrementalDecode(int* rowsDecoded) {
1263 // FIXME: Only necessary on the first call. 1279 // FIXME: Only necessary on the first call.
1264 this->initializeXformAlphaAndWidth(); 1280 this->initializeXformParams();
1265 1281
1266 return this->decode(rowsDecoded); 1282 return this->decode(rowsDecoded);
1267 } 1283 }
1268 1284
1269 uint64_t SkPngCodec::onGetFillValue(const SkImageInfo& dstInfo) const { 1285 uint64_t SkPngCodec::onGetFillValue(const SkImageInfo& dstInfo) const {
1270 const SkPMColor* colorPtr = get_color_ptr(fColorTable.get()); 1286 const SkPMColor* colorPtr = get_color_ptr(fColorTable.get());
1271 if (colorPtr) { 1287 if (colorPtr) {
1272 SkAlphaType alphaType = select_alpha_xform(dstInfo.alphaType(), 1288 SkAlphaType alphaType = select_xform_alpha(dstInfo.alphaType(),
1273 this->getInfo().alphaType()); 1289 this->getInfo().alphaType());
1274 return get_color_table_fill_value(dstInfo.colorType(), alphaType, colorP tr, 0, 1290 return get_color_table_fill_value(dstInfo.colorType(), alphaType, colorP tr, 0,
1275 fColorXform.get()); 1291 fColorXform.get());
1276 } 1292 }
1277 return INHERITED::onGetFillValue(dstInfo); 1293 return INHERITED::onGetFillValue(dstInfo);
1278 } 1294 }
1279 1295
1280 SkCodec* SkPngCodec::NewFromStream(SkStream* stream, SkPngChunkReader* chunkRead er) { 1296 SkCodec* SkPngCodec::NewFromStream(SkStream* stream, SkPngChunkReader* chunkRead er) {
1281 SkAutoTDelete<SkStream> streamDeleter(stream); 1297 SkAutoTDelete<SkStream> streamDeleter(stream);
1282 1298
1283 SkCodec* outCodec = nullptr; 1299 SkCodec* outCodec = nullptr;
1284 if (read_header(streamDeleter.get(), chunkReader, &outCodec, nullptr, nullpt r)) { 1300 if (read_header(streamDeleter.get(), chunkReader, &outCodec, nullptr, nullpt r)) {
1285 // Codec has taken ownership of the stream. 1301 // Codec has taken ownership of the stream.
1286 SkASSERT(outCodec); 1302 SkASSERT(outCodec);
1287 streamDeleter.release(); 1303 streamDeleter.release();
1288 return outCodec; 1304 return outCodec;
1289 } 1305 }
1290 1306
1291 return nullptr; 1307 return nullptr;
1292 } 1308 }
OLDNEW
« no previous file with comments | « src/codec/SkPngCodec.h ('k') | src/codec/SkWebpCodec.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698