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

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

Issue 1694023002: Revert of Fix colorType/alphaType checks in SkCodec (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 10 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/SkJpegCodec.cpp ('k') | no next file » | 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 "SkCodec.h" 8 #include "SkCodec.h"
9 #include "SkCodecPriv.h" 9 #include "SkCodecPriv.h"
10 #include "SkColorPriv.h" 10 #include "SkColorPriv.h"
(...skipping 12 matching lines...) Expand all
23 23
24 static inline void setup_color_table(SkColorType colorType, 24 static inline void setup_color_table(SkColorType colorType,
25 SkPMColor* colorPtr, int* colorCount) { 25 SkPMColor* colorPtr, int* colorCount) {
26 if (kIndex_8_SkColorType == colorType) { 26 if (kIndex_8_SkColorType == colorType) {
27 colorPtr[0] = SK_ColorBLACK; 27 colorPtr[0] = SK_ColorBLACK;
28 colorPtr[1] = SK_ColorWHITE; 28 colorPtr[1] = SK_ColorWHITE;
29 *colorCount = 2; 29 *colorCount = 2;
30 } 30 }
31 } 31 }
32 32
33 static inline bool valid_color_type(SkColorType colorType, SkAlphaType alphaType ) {
34 switch (colorType) {
35 case kN32_SkColorType:
36 case kIndex_8_SkColorType:
37 return true;
38 case kGray_8_SkColorType:
39 case kRGB_565_SkColorType:
40 return kOpaque_SkAlphaType == alphaType;
41 default:
42 return false;
43 }
44 }
45
46 static bool read_byte(SkStream* stream, uint8_t* data) 33 static bool read_byte(SkStream* stream, uint8_t* data)
47 { 34 {
48 return stream->read(data, 1) == 1; 35 return stream->read(data, 1) == 1;
49 } 36 }
50 37
51 // http://en.wikipedia.org/wiki/Variable-length_quantity 38 // http://en.wikipedia.org/wiki/Variable-length_quantity
52 static bool read_mbf(SkStream* stream, uint64_t* value) { 39 static bool read_mbf(SkStream* stream, uint64_t* value) {
53 uint64_t n = 0; 40 uint64_t n = 0;
54 uint8_t data; 41 uint8_t data;
55 const uint64_t kLimit = 0xFE00000000000000; 42 const uint64_t kLimit = 0xFE00000000000000;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 } 77 }
91 return true; 78 return true;
92 } 79 }
93 80
94 bool SkWbmpCodec::onRewind() { 81 bool SkWbmpCodec::onRewind() {
95 return read_header(this->stream(), nullptr); 82 return read_header(this->stream(), nullptr);
96 } 83 }
97 84
98 SkSwizzler* SkWbmpCodec::initializeSwizzler(const SkImageInfo& info, const SkPMC olor* ctable, 85 SkSwizzler* SkWbmpCodec::initializeSwizzler(const SkImageInfo& info, const SkPMC olor* ctable,
99 const Options& opts) { 86 const Options& opts) {
87 // Create the swizzler based on the desired color type
88 switch (info.colorType()) {
89 case kIndex_8_SkColorType:
90 case kN32_SkColorType:
91 case kRGB_565_SkColorType:
92 case kGray_8_SkColorType:
93 break;
94 default:
95 return nullptr;
96 }
100 return SkSwizzler::CreateSwizzler(SkSwizzler::kBit, ctable, info, opts); 97 return SkSwizzler::CreateSwizzler(SkSwizzler::kBit, ctable, info, opts);
101 } 98 }
102 99
103 bool SkWbmpCodec::readRow(uint8_t* row) { 100 bool SkWbmpCodec::readRow(uint8_t* row) {
104 return this->stream()->read(row, fSrcRowBytes) == fSrcRowBytes; 101 return this->stream()->read(row, fSrcRowBytes) == fSrcRowBytes;
105 } 102 }
106 103
107 SkWbmpCodec::SkWbmpCodec(const SkImageInfo& info, SkStream* stream) 104 SkWbmpCodec::SkWbmpCodec(const SkImageInfo& info, SkStream* stream)
108 : INHERITED(info, stream) 105 : INHERITED(info, stream)
109 , fSrcRowBytes(get_src_row_bytes(this->getInfo().width())) 106 , fSrcRowBytes(get_src_row_bytes(this->getInfo().width()))
(...skipping 10 matching lines...) Expand all
120 size_t rowBytes, 117 size_t rowBytes,
121 const Options& options, 118 const Options& options,
122 SkPMColor ctable[], 119 SkPMColor ctable[],
123 int* ctableCount, 120 int* ctableCount,
124 int* rowsDecoded) { 121 int* rowsDecoded) {
125 if (options.fSubset) { 122 if (options.fSubset) {
126 // Subsets are not supported. 123 // Subsets are not supported.
127 return kUnimplemented; 124 return kUnimplemented;
128 } 125 }
129 126
130 if (!valid_color_type(info.colorType(), info.alphaType()) || 127 if (!valid_alpha(info.alphaType(), this->getInfo().alphaType())) {
131 !valid_alpha(info.alphaType(), this->getInfo().alphaType())) {
132 return kInvalidConversion; 128 return kInvalidConversion;
133 } 129 }
134 130
135 // Prepare a color table if necessary 131 // Prepare a color table if necessary
136 setup_color_table(info.colorType(), ctable, ctableCount); 132 setup_color_table(info.colorType(), ctable, ctableCount);
137 133
138 // Initialize the swizzler 134 // Initialize the swizzler
139 SkAutoTDelete<SkSwizzler> swizzler(this->initializeSwizzler(info, ctable, op tions)); 135 SkAutoTDelete<SkSwizzler> swizzler(this->initializeSwizzler(info, ctable, op tions));
140 SkASSERT(swizzler); 136 if (nullptr == swizzler.get()) {
137 return kInvalidConversion;
138 }
141 139
142 // Perform the decode 140 // Perform the decode
143 SkISize size = info.dimensions(); 141 SkISize size = info.dimensions();
144 SkAutoTMalloc<uint8_t> src(fSrcRowBytes); 142 SkAutoTMalloc<uint8_t> src(fSrcRowBytes);
145 void* dstRow = dst; 143 void* dstRow = dst;
146 for (int y = 0; y < size.height(); ++y) { 144 for (int y = 0; y < size.height(); ++y) {
147 if (!this->readRow(src.get())) { 145 if (!this->readRow(src.get())) {
148 *rowsDecoded = y; 146 *rowsDecoded = y;
149 return kIncompleteInput; 147 return kIncompleteInput;
150 } 148 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 return count; 181 return count;
184 } 182 }
185 183
186 SkCodec::Result SkWbmpCodec::onStartScanlineDecode(const SkImageInfo& dstInfo, 184 SkCodec::Result SkWbmpCodec::onStartScanlineDecode(const SkImageInfo& dstInfo,
187 const Options& options, SkPMColor inputColorTable[], int* inputColorCoun t) { 185 const Options& options, SkPMColor inputColorTable[], int* inputColorCoun t) {
188 if (options.fSubset) { 186 if (options.fSubset) {
189 // Subsets are not supported. 187 // Subsets are not supported.
190 return kUnimplemented; 188 return kUnimplemented;
191 } 189 }
192 190
193 if (!valid_color_type(dstInfo.colorType(), dstInfo.alphaType()) || 191 if (!valid_alpha(dstInfo.alphaType(), this->getInfo().alphaType())) {
194 !valid_alpha(dstInfo.alphaType(), this->getInfo().alphaType())) {
195 return kInvalidConversion; 192 return kInvalidConversion;
196 } 193 }
197 194
198 // Fill in the color table 195 // Fill in the color table
199 setup_color_table(dstInfo.colorType(), inputColorTable, inputColorCount); 196 setup_color_table(dstInfo.colorType(), inputColorTable, inputColorCount);
200 197
201 // Copy the color table to a pointer that can be owned by the scanline decod er 198 // Copy the color table to a pointer that can be owned by the scanline decod er
202 if (kIndex_8_SkColorType == dstInfo.colorType()) { 199 if (kIndex_8_SkColorType == dstInfo.colorType()) {
203 fColorTable.reset(new SkColorTable(inputColorTable, 2)); 200 fColorTable.reset(new SkColorTable(inputColorTable, 2));
204 } 201 }
205 202
206 // Initialize the swizzler 203 // Initialize the swizzler
207 fSwizzler.reset(this->initializeSwizzler(dstInfo, get_color_ptr(fColorTable. get()), options)); 204 fSwizzler.reset(this->initializeSwizzler(dstInfo, get_color_ptr(fColorTable. get()), options));
208 SkASSERT(fSwizzler); 205 if (nullptr == fSwizzler.get()) {
206 return kInvalidConversion;
207 }
209 208
210 fSrcBuffer.reset(fSrcRowBytes); 209 fSrcBuffer.reset(fSrcRowBytes);
211 210
212 return kSuccess; 211 return kSuccess;
213 } 212 }
OLDNEW
« no previous file with comments | « src/codec/SkJpegCodec.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698