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

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

Issue 1294613002: Revert of SkScaledCodec class (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 4 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/SkCodec_libpng.cpp ('k') | src/codec/SkJpegCodec.h » ('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 "SkCodec.h" 8 #include "SkCodec.h"
9 #include "SkCodecPriv.h" 9 #include "SkCodecPriv.h"
10 #include "SkColorPriv.h" 10 #include "SkColorPriv.h"
11 #include "SkColorTable.h" 11 #include "SkColorTable.h"
12 #include "SkScaledCodec.h"
13 #include "SkStream.h" 12 #include "SkStream.h"
14 #include "SkCodec_wbmp.h" 13 #include "SkCodec_wbmp.h"
15 14
16 // Each bit represents a pixel, so width is actually a number of bits. 15 // Each bit represents a pixel, so width is actually a number of bits.
17 // A row will always be stored in bytes, so we round width up to the 16 // A row will always be stored in bytes, so we round width up to the
18 // nearest multiple of 8 to get the number of bits actually in the row. 17 // nearest multiple of 8 to get the number of bits actually in the row.
19 // We then divide by 8 to convert to bytes. 18 // We then divide by 8 to convert to bytes.
20 static inline size_t get_src_row_bytes(int width) { 19 static inline size_t get_src_row_bytes(int width) {
21 return SkAlign8(width) >> 3; 20 return SkAlign8(width) >> 3;
22 } 21 }
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 SkSwizzler* SkWbmpCodec::initializeSwizzler(const SkImageInfo& info, 73 SkSwizzler* SkWbmpCodec::initializeSwizzler(const SkImageInfo& info,
75 const SkPMColor* ctable, const Options& opts) { 74 const SkPMColor* ctable, const Options& opts) {
76 // TODO (msarett): Reenable support for 565 if it is desired 75 // TODO (msarett): Reenable support for 565 if it is desired
77 // skbug.com/3683 76 // skbug.com/3683
78 77
79 // Create the swizzler based on the desired color type 78 // Create the swizzler based on the desired color type
80 switch (info.colorType()) { 79 switch (info.colorType()) {
81 case kIndex_8_SkColorType: 80 case kIndex_8_SkColorType:
82 case kN32_SkColorType: 81 case kN32_SkColorType:
83 case kGray_8_SkColorType: 82 case kGray_8_SkColorType:
84 return SkSwizzler::CreateSwizzler(SkSwizzler::kBit, ctable, info, op ts.fZeroInitialized, 83 return SkSwizzler::CreateSwizzler(
85 this->getInfo()); 84 SkSwizzler::kBit, ctable, info, opts.fZeroInitialized);
86 default: 85 default:
87 return NULL; 86 return NULL;
88 } 87 }
89 } 88 }
90 89
91 SkCodec::Result SkWbmpCodec::readRow(uint8_t* row) { 90 SkCodec::Result SkWbmpCodec::readRow(uint8_t* row) {
92 if (this->stream()->read(row, fSrcRowBytes) != fSrcRowBytes) { 91 if (this->stream()->read(row, fSrcRowBytes) != fSrcRowBytes) {
93 return kIncompleteInput; 92 return kIncompleteInput;
94 } 93 }
95 return kSuccess; 94 return kSuccess;
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 const SkCodec::Options& options, SkPMColor inputColorTable[], 194 const SkCodec::Options& options, SkPMColor inputColorTable[],
196 int* inputColorCount) { 195 int* inputColorCount) {
197 if (!fCodec->rewindIfNeeded()) { 196 if (!fCodec->rewindIfNeeded()) {
198 return SkCodec::kCouldNotRewind; 197 return SkCodec::kCouldNotRewind;
199 } 198 }
200 if (options.fSubset) { 199 if (options.fSubset) {
201 // Subsets are not supported. 200 // Subsets are not supported.
202 return SkCodec::kUnimplemented; 201 return SkCodec::kUnimplemented;
203 } 202 }
204 if (dstInfo.dimensions() != this->getInfo().dimensions()) { 203 if (dstInfo.dimensions() != this->getInfo().dimensions()) {
205 if (!SkScaledCodec::DimensionsSupportedForSampling(this->getInfo(), dstInfo)) { 204 return SkCodec::kInvalidScale;
206 return SkCodec::kInvalidScale;
207 }
208 } 205 }
209 206
210 if (!valid_alpha(dstInfo.alphaType(), this->getInfo().alphaType())) { 207 if (!valid_alpha(dstInfo.alphaType(), this->getInfo().alphaType())) {
211 return SkCodec::kInvalidConversion; 208 return SkCodec::kInvalidConversion;
212 } 209 }
213 210
214 // Fill in the color table 211 // Fill in the color table
215 setup_color_table(dstInfo.colorType(), inputColorTable, inputColorCount) ; 212 setup_color_table(dstInfo.colorType(), inputColorTable, inputColorCount) ;
216 213
217 // Copy the color table to a pointer that can be owned by the scanline d ecoder 214 // Copy the color table to a pointer that can be owned by the scanline d ecoder
218 if (kIndex_8_SkColorType == dstInfo.colorType()) { 215 if (kIndex_8_SkColorType == dstInfo.colorType()) {
219 fColorTable.reset(SkNEW_ARGS(SkColorTable, (inputColorTable, 2))); 216 fColorTable.reset(SkNEW_ARGS(SkColorTable, (inputColorTable, 2)));
220 } 217 }
221 218
222 // Initialize the swizzler 219 // Initialize the swizzler
223 fSwizzler.reset(fCodec->initializeSwizzler(dstInfo, 220 fSwizzler.reset(fCodec->initializeSwizzler(dstInfo,
224 get_color_ptr(fColorTable.get()), options)); 221 get_color_ptr(fColorTable.get()), options));
225 if (NULL == fSwizzler.get()) { 222 if (NULL == fSwizzler.get()) {
226 return SkCodec::kInvalidConversion; 223 return SkCodec::kInvalidInput;
227 } 224 }
228 225
229 return SkCodec::kSuccess; 226 return SkCodec::kSuccess;
230 } 227 }
231 228
232 SkEncodedFormat onGetEncodedFormat() const {
233 return kWBMP_SkEncodedFormat;
234 }
235
236 private: 229 private:
237 SkAutoTDelete<SkWbmpCodec> fCodec; 230 SkAutoTDelete<SkWbmpCodec> fCodec;
238 SkAutoTUnref<SkColorTable> fColorTable; 231 SkAutoTUnref<SkColorTable> fColorTable;
239 SkAutoTDelete<SkSwizzler> fSwizzler; 232 SkAutoTDelete<SkSwizzler> fSwizzler;
240 SkAutoTMalloc<uint8_t> fSrcBuffer; 233 SkAutoTMalloc<uint8_t> fSrcBuffer;
241 234
242 typedef SkScanlineDecoder INHERITED; 235 typedef SkScanlineDecoder INHERITED;
243 }; 236 };
244 237
245 SkScanlineDecoder* SkWbmpCodec::NewSDFromStream(SkStream* stream) { 238 SkScanlineDecoder* SkWbmpCodec::NewSDFromStream(SkStream* stream) {
246 SkAutoTDelete<SkWbmpCodec> codec(static_cast<SkWbmpCodec*>( 239 SkAutoTDelete<SkWbmpCodec> codec(static_cast<SkWbmpCodec*>(
247 SkWbmpCodec::NewFromStream(stream))); 240 SkWbmpCodec::NewFromStream(stream)));
248 if (!codec) { 241 if (!codec) {
249 return NULL; 242 return NULL;
250 } 243 }
251 244
252 // Return the new scanline decoder 245 // Return the new scanline decoder
253 return SkNEW_ARGS(SkWbmpScanlineDecoder, (codec.detach())); 246 return SkNEW_ARGS(SkWbmpScanlineDecoder, (codec.detach()));
254 } 247 }
OLDNEW
« no previous file with comments | « src/codec/SkCodec_libpng.cpp ('k') | src/codec/SkJpegCodec.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698