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

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

Issue 1372973002: Move all knowledge of X sampling into SkScaledCodec (Closed) Base URL: https://skia.googlesource.com/skia.git@codecSDmerge
Patch Set: Attempt to fix RLE overflow Created 5 years, 2 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_wbmp.h ('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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 } 71 }
73 72
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 // Create the swizzler based on the desired color type 75 // Create the swizzler based on the desired color type
77 switch (info.colorType()) { 76 switch (info.colorType()) {
78 case kIndex_8_SkColorType: 77 case kIndex_8_SkColorType:
79 case kN32_SkColorType: 78 case kN32_SkColorType:
80 case kRGB_565_SkColorType: 79 case kRGB_565_SkColorType:
81 case kGray_8_SkColorType: 80 case kGray_8_SkColorType:
82 return SkSwizzler::CreateSwizzler(SkSwizzler::kBit, ctable, info, op ts.fZeroInitialized, 81 break;
83 this->getInfo());
84 default: 82 default:
85 return nullptr; 83 return nullptr;
86 } 84 }
85 return SkSwizzler::CreateSwizzler(SkSwizzler::kBit, ctable, info,
86 opts.fZeroInitialized);
87 } 87 }
88 88
89 SkCodec::Result SkWbmpCodec::readRow(uint8_t* row) { 89 SkCodec::Result SkWbmpCodec::readRow(uint8_t* row) {
90 if (this->stream()->read(row, fSrcRowBytes) != fSrcRowBytes) { 90 if (this->stream()->read(row, fSrcRowBytes) != fSrcRowBytes) {
91 return kIncompleteInput; 91 return kIncompleteInput;
92 } 92 }
93 return kSuccess; 93 return kSuccess;
94 } 94 }
95 95
96 SkWbmpCodec::SkWbmpCodec(const SkImageInfo& info, SkStream* stream) 96 SkWbmpCodec::SkWbmpCodec(const SkImageInfo& info, SkStream* stream)
(...skipping 10 matching lines...) Expand all
107 SkCodec::Result SkWbmpCodec::onGetPixels(const SkImageInfo& info, 107 SkCodec::Result SkWbmpCodec::onGetPixels(const SkImageInfo& info,
108 void* dst, 108 void* dst,
109 size_t rowBytes, 109 size_t rowBytes,
110 const Options& options, 110 const Options& options,
111 SkPMColor ctable[], 111 SkPMColor ctable[],
112 int* ctableCount) { 112 int* ctableCount) {
113 if (options.fSubset) { 113 if (options.fSubset) {
114 // Subsets are not supported. 114 // Subsets are not supported.
115 return kUnimplemented; 115 return kUnimplemented;
116 } 116 }
117 if (info.dimensions() != this->getInfo().dimensions()) {
118 return kInvalidScale;
119 }
120 117
121 if (!valid_alpha(info.alphaType(), this->getInfo().alphaType())) { 118 if (!valid_alpha(info.alphaType(), this->getInfo().alphaType())) {
122 return kInvalidConversion; 119 return kInvalidConversion;
123 } 120 }
124 121
125 // Prepare a color table if necessary 122 // Prepare a color table if necessary
126 setup_color_table(info.colorType(), ctable, ctableCount); 123 setup_color_table(info.colorType(), ctable, ctableCount);
127 124
128
129 // Initialize the swizzler 125 // Initialize the swizzler
130 SkAutoTDelete<SkSwizzler> swizzler(this->initializeSwizzler(info, ctable, op tions)); 126 SkAutoTDelete<SkSwizzler> swizzler(this->initializeSwizzler(info, ctable, op tions));
131 if (nullptr == swizzler.get()) { 127 if (nullptr == swizzler.get()) {
132 return kInvalidConversion; 128 return kInvalidConversion;
133 } 129 }
134 130
135 // Perform the decode 131 // Perform the decode
136 SkISize size = info.dimensions(); 132 SkISize size = info.dimensions();
137 SkAutoTMalloc<uint8_t> src(fSrcRowBytes); 133 SkAutoTMalloc<uint8_t> src(fSrcRowBytes);
138 void* dstRow = dst; 134 void* dstRow = dst;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 } 170 }
175 return kSuccess; 171 return kSuccess;
176 } 172 }
177 173
178 SkCodec::Result SkWbmpCodec::onStartScanlineDecode(const SkImageInfo& dstInfo, 174 SkCodec::Result SkWbmpCodec::onStartScanlineDecode(const SkImageInfo& dstInfo,
179 const Options& options, SkPMColor inputColorTable[], int* inputColorCoun t) { 175 const Options& options, SkPMColor inputColorTable[], int* inputColorCoun t) {
180 if (options.fSubset) { 176 if (options.fSubset) {
181 // Subsets are not supported. 177 // Subsets are not supported.
182 return kUnimplemented; 178 return kUnimplemented;
183 } 179 }
184 if (dstInfo.dimensions() != this->getInfo().dimensions()) {
185 if (!SkScaledCodec::DimensionsSupportedForSampling(this->getInfo(), dstI nfo)) {
186 return kInvalidScale;
187 }
188 }
189 180
190 if (!valid_alpha(dstInfo.alphaType(), this->getInfo().alphaType())) { 181 if (!valid_alpha(dstInfo.alphaType(), this->getInfo().alphaType())) {
191 return kInvalidConversion; 182 return kInvalidConversion;
192 } 183 }
193 184
194 // Fill in the color table 185 // Fill in the color table
195 setup_color_table(dstInfo.colorType(), inputColorTable, inputColorCount); 186 setup_color_table(dstInfo.colorType(), inputColorTable, inputColorCount);
196 187
197 // Copy the color table to a pointer that can be owned by the scanline decod er 188 // Copy the color table to a pointer that can be owned by the scanline decod er
198 if (kIndex_8_SkColorType == dstInfo.colorType()) { 189 if (kIndex_8_SkColorType == dstInfo.colorType()) {
199 fColorTable.reset(new SkColorTable(inputColorTable, 2)); 190 fColorTable.reset(new SkColorTable(inputColorTable, 2));
200 } 191 }
201 192
202 // Initialize the swizzler 193 // Initialize the swizzler
203 fSwizzler.reset(this->initializeSwizzler(dstInfo, 194 fSwizzler.reset(this->initializeSwizzler(dstInfo,
204 get_color_ptr(fColorTable.get()), options)); 195 get_color_ptr(fColorTable.get()), options));
205 if (nullptr == fSwizzler.get()) { 196 if (nullptr == fSwizzler.get()) {
206 return kInvalidConversion; 197 return kInvalidConversion;
207 } 198 }
208 199
209 fSrcBuffer.reset(fSrcRowBytes); 200 fSrcBuffer.reset(fSrcRowBytes);
210 201
211 return kSuccess; 202 return kSuccess;
212 } 203 }
213 204
OLDNEW
« no previous file with comments | « src/codec/SkCodec_wbmp.h ('k') | src/codec/SkJpegCodec.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698