aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/codec/SkWbmpCodec.cpp
diff options
context:
space:
mode:
authorGravatar Leon Scroggins <scroggo@google.com>2017-07-10 19:51:46 +0000
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-07-10 19:51:59 +0000
commit8321f7585b6aded0c35e50e9af8709b25fdce3f6 (patch)
tree9a9e3a1843c8864a9e847d0c7b59b987946f6b24 /src/codec/SkWbmpCodec.cpp
parenta48ae6ec2feb32e3d781ad43353209a90059a01d (diff)
Revert "Remove support for decoding to kIndex_8"
This reverts commit 742a3e298fda669006147e4a305bab8452369b1f. Reason for revert: Breaking Android roll: frameworks/base/core/jni/android/graphics/BitmapFactory.cpp:453:18: error: no member named 'fColorPtr' in 'SkAndroidCodec::AndroidOptions' codecOptions.fColorPtr = colorPtr; ~~~~~~~~~~~~ ^ frameworks/base/core/jni/android/graphics/BitmapFactory.cpp:454:18: error: no member named 'fColorCount' in 'SkAndroidCodec::AndroidOptions' codecOptions.fColorCount = colorCount; ~~~~~~~~~~~~ ^ Original change's description: > Remove support for decoding to kIndex_8 > > Fix up callsites, and remove tests that no longer make sense. > > Bug: skia:6828 > Change-Id: I2548c4b7528b7b1be7412563156f27b52c9d4295 > Reviewed-on: https://skia-review.googlesource.com/21664 > Reviewed-by: Derek Sollenberger <djsollen@google.com> > Commit-Queue: Leon Scroggins <scroggo@google.com> TBR=djsollen@google.com,scroggo@google.com Change-Id: I1bc669441f250690884e75a9a61427fdf75c6907 No-Presubmit: true No-Tree-Checks: true No-Try: true Bug: skia:6828 Reviewed-on: https://skia-review.googlesource.com/22120 Reviewed-by: Leon Scroggins <scroggo@google.com> Commit-Queue: Leon Scroggins <scroggo@google.com>
Diffstat (limited to 'src/codec/SkWbmpCodec.cpp')
-rw-r--r--src/codec/SkWbmpCodec.cpp34
1 files changed, 29 insertions, 5 deletions
diff --git a/src/codec/SkWbmpCodec.cpp b/src/codec/SkWbmpCodec.cpp
index fe9a29133e..780ae5e5d0 100644
--- a/src/codec/SkWbmpCodec.cpp
+++ b/src/codec/SkWbmpCodec.cpp
@@ -21,6 +21,15 @@ static inline size_t get_src_row_bytes(int width) {
return SkAlign8(width) >> 3;
}
+static inline void setup_color_table(SkColorType colorType,
+ SkPMColor* colorPtr, int* colorCount) {
+ if (kIndex_8_SkColorType == colorType) {
+ colorPtr[0] = SK_ColorBLACK;
+ colorPtr[1] = SK_ColorWHITE;
+ *colorCount = 2;
+ }
+}
+
static inline bool valid_color_type(const SkImageInfo& dstInfo) {
switch (dstInfo.colorType()) {
case kRGBA_8888_SkColorType:
@@ -88,8 +97,9 @@ bool SkWbmpCodec::onRewind() {
return read_header(this->stream(), nullptr);
}
-SkSwizzler* SkWbmpCodec::initializeSwizzler(const SkImageInfo& info, const Options& opts) {
- return SkSwizzler::CreateSwizzler(this->getEncodedInfo(), nullptr, info, opts);
+SkSwizzler* SkWbmpCodec::initializeSwizzler(const SkImageInfo& info, const SkPMColor* ctable,
+ const Options& opts) {
+ return SkSwizzler::CreateSwizzler(this->getEncodedInfo(), ctable, info, opts);
}
bool SkWbmpCodec::readRow(uint8_t* row) {
@@ -102,6 +112,7 @@ SkWbmpCodec::SkWbmpCodec(int width, int height, const SkEncodedInfo& info, SkStr
stream, SkColorSpace::MakeSRGB())
, fSrcRowBytes(get_src_row_bytes(this->getInfo().width()))
, fSwizzler(nullptr)
+ , fColorTable(nullptr)
{}
SkEncodedImageFormat SkWbmpCodec::onGetEncodedFormat() const {
@@ -112,6 +123,8 @@ SkCodec::Result SkWbmpCodec::onGetPixels(const SkImageInfo& info,
void* dst,
size_t rowBytes,
const Options& options,
+ SkPMColor ctable[],
+ int* ctableCount,
int* rowsDecoded) {
if (options.fSubset) {
// Subsets are not supported.
@@ -122,8 +135,11 @@ SkCodec::Result SkWbmpCodec::onGetPixels(const SkImageInfo& info,
return kInvalidConversion;
}
+ // Prepare a color table if necessary
+ setup_color_table(info.colorType(), ctable, ctableCount);
+
// Initialize the swizzler
- std::unique_ptr<SkSwizzler> swizzler(this->initializeSwizzler(info, options));
+ std::unique_ptr<SkSwizzler> swizzler(this->initializeSwizzler(info, ctable, options));
SkASSERT(swizzler);
// Perform the decode
@@ -175,7 +191,7 @@ bool SkWbmpCodec::onSkipScanlines(int count) {
}
SkCodec::Result SkWbmpCodec::onStartScanlineDecode(const SkImageInfo& dstInfo,
- const Options& options) {
+ const Options& options, SkPMColor inputColorTable[], int* inputColorCount) {
if (options.fSubset) {
// Subsets are not supported.
return kUnimplemented;
@@ -187,8 +203,16 @@ SkCodec::Result SkWbmpCodec::onStartScanlineDecode(const SkImageInfo& dstInfo,
return kInvalidConversion;
}
+ // Fill in the color table
+ setup_color_table(dstInfo.colorType(), inputColorTable, inputColorCount);
+
+ // Copy the color table to a pointer that can be owned by the scanline decoder
+ if (kIndex_8_SkColorType == dstInfo.colorType()) {
+ fColorTable.reset(new SkColorTable(inputColorTable, 2));
+ }
+
// Initialize the swizzler
- fSwizzler.reset(this->initializeSwizzler(dstInfo, options));
+ fSwizzler.reset(this->initializeSwizzler(dstInfo, get_color_ptr(fColorTable.get()), options));
SkASSERT(fSwizzler);
fSrcBuffer.reset(fSrcRowBytes);