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

Unified Diff: src/codec/SkCodec_libbmp.cpp

Issue 1075243003: Implementing filling for SkBmpCodec (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | src/codec/SkSwizzler.h » ('j') | src/codec/SkSwizzler.h » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/codec/SkCodec_libbmp.cpp
diff --git a/src/codec/SkCodec_libbmp.cpp b/src/codec/SkCodec_libbmp.cpp
index b553deae6f8c0b14f669d19ee76aa4f8536f19d4..0ca15be5b54749cfb82adb0f3eeb20c728bf8cb8 100644
--- a/src/codec/SkCodec_libbmp.cpp
+++ b/src/codec/SkCodec_libbmp.cpp
@@ -701,6 +701,9 @@ SkCodec::Result SkBmpCodec::onGetPixels(const SkImageInfo& dstInfo,
for (; i < maxColors; i++) {
colorTable[i] = SkPackARGB32NoCheck(0xFF, 0, 0, 0);
}
+
+ // Set the color table
+ fColorTable.reset(SkNEW_ARGS(SkColorTable, (colorTable, maxColors)));
}
// Bmp-in-Ico files do not use an offset to indicate where the pixel data
@@ -724,8 +727,7 @@ SkCodec::Result SkBmpCodec::onGetPixels(const SkImageInfo& dstInfo,
}
}
- // Set the color table and return true on success
- fColorTable.reset(SkNEW_ARGS(SkColorTable, (colorTable, maxColors)));
+ // Return true on success
return true;
}
@@ -757,6 +759,12 @@ SkCodec::Result SkBmpCodec::decodeMask(const SkImageInfo& dstInfo,
// Read a row of the input
if (stream()->read(srcRow, rowBytes) != rowBytes) {
SkCodecPrintf("Warning: incomplete input stream.\n");
+ // Fill the destination image on failure
+ // By using zero as the fill value, we will fill with transparent
+ // pixels for non-opaque images and white for opaque images.
+ // These are arbitrary choices but allow for consistent behavior.
+ SkSwizzler::Fill(dst, dstInfo, dstRowBytes, y, 0, NULL,
+ fRowOrder == kBottomUp_RowOrder);
return kIncompleteInput;
}
@@ -1096,9 +1104,12 @@ SkCodec::Result SkBmpCodec::decode(const SkImageInfo& dstInfo,
return kInvalidInput;
}
+ // Get a pointer to the color table if it exists
+ const SkPMColor* colorPtr = NULL != fColorTable.get() ? fColorTable->readColors() : NULL;
+
// Create swizzler
SkAutoTDelete<SkSwizzler> swizzler(SkSwizzler::CreateSwizzler(config,
- fColorTable->readColors(), dstInfo, dst, dstRowBytes,
+ colorPtr, dstInfo, dst, dstRowBytes,
SkImageGenerator::kNo_ZeroInitialized));
// Allocate space for a row buffer and a source for the swizzler
@@ -1110,6 +1121,13 @@ SkCodec::Result SkBmpCodec::decode(const SkImageInfo& dstInfo,
// Read a row of the input
if (stream()->read(srcBuffer.get(), rowBytes) != rowBytes) {
SkCodecPrintf("Warning: incomplete input stream.\n");
+ // Fill the destination image on failure
+ // By using zero as the fill value, we will fill with the first
+ // color in the color table for palette images, transparent
+ // pixels for non-opaque images, and white for opaque images.
+ // These are arbitrary choices but allow for consistent behavior.
+ SkSwizzler::Fill(dst, dstInfo, dstRowBytes, y, 0, colorPtr,
+ fRowOrder == kBottomUp_RowOrder);
return kIncompleteInput;
}
« no previous file with comments | « no previous file | src/codec/SkSwizzler.h » ('j') | src/codec/SkSwizzler.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698