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

Side by Side Diff: src/images/SkImageDecoder.cpp

Issue 334793002: hide Config in SkImageDecoder -- use SkColorType instead (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: fix warning Created 6 years, 6 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/images/SkDecodingImageGenerator.cpp ('k') | src/ports/SkImageDecoder_empty.cpp » ('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 2006 The Android Open Source Project 2 * Copyright 2006 The Android Open Source Project
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 8
9 #include "SkImageDecoder.h" 9 #include "SkImageDecoder.h"
10 #include "SkBitmap.h" 10 #include "SkBitmap.h"
11 #include "SkImagePriv.h" 11 #include "SkImagePriv.h"
12 #include "SkPixelRef.h" 12 #include "SkPixelRef.h"
13 #include "SkStream.h" 13 #include "SkStream.h"
14 #include "SkTemplates.h" 14 #include "SkTemplates.h"
15 #include "SkCanvas.h" 15 #include "SkCanvas.h"
16 16
17 SkImageDecoder::SkImageDecoder() 17 SkImageDecoder::SkImageDecoder()
18 : fPeeker(NULL) 18 : fPeeker(NULL)
19 #ifdef SK_SUPPORT_LEGACY_IMAGEDECODER_CHOOSER 19 #ifdef SK_SUPPORT_LEGACY_IMAGEDECODER_CHOOSER
20 , fChooser(NULL) 20 , fChooser(NULL)
21 #endif 21 #endif
22 , fAllocator(NULL) 22 , fAllocator(NULL)
23 , fSampleSize(1) 23 , fSampleSize(1)
24 , fDefaultPref(SkBitmap::kNo_Config) 24 , fDefaultPref(kUnknown_SkColorType)
25 , fDitherImage(true) 25 , fDitherImage(true)
26 , fUsePrefTable(false) 26 , fUsePrefTable(false)
27 , fSkipWritingZeroes(false) 27 , fSkipWritingZeroes(false)
28 , fPreferQualityOverSpeed(false) 28 , fPreferQualityOverSpeed(false)
29 , fRequireUnpremultipliedColors(false) { 29 , fRequireUnpremultipliedColors(false) {
30 } 30 }
31 31
32 SkImageDecoder::~SkImageDecoder() { 32 SkImageDecoder::~SkImageDecoder() {
33 SkSafeUnref(fPeeker); 33 SkSafeUnref(fPeeker);
34 #ifdef SK_SUPPORT_LEGACY_IMAGEDECODER_CHOOSER 34 #ifdef SK_SUPPORT_LEGACY_IMAGEDECODER_CHOOSER
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 /////////////////////////////////////////////////////////////////////////////// 141 ///////////////////////////////////////////////////////////////////////////////
142 142
143 void SkImageDecoder::setPrefConfigTable(const PrefConfigTable& prefTable) { 143 void SkImageDecoder::setPrefConfigTable(const PrefConfigTable& prefTable) {
144 fUsePrefTable = true; 144 fUsePrefTable = true;
145 fPrefTable = prefTable; 145 fPrefTable = prefTable;
146 } 146 }
147 147
148 // TODO: use colortype in fPrefTable, fDefaultPref so we can stop using SkBitmap ConfigToColorType() 148 // TODO: use colortype in fPrefTable, fDefaultPref so we can stop using SkBitmap ConfigToColorType()
149 // 149 //
150 SkColorType SkImageDecoder::getPrefColorType(SrcDepth srcDepth, bool srcHasAlpha ) const { 150 SkColorType SkImageDecoder::getPrefColorType(SrcDepth srcDepth, bool srcHasAlpha ) const {
151 SkBitmap::Config config = SkBitmap::kNo_Config; 151 SkColorType ct = fDefaultPref;
152 152
153 if (fUsePrefTable) { 153 if (fUsePrefTable) {
154 // Until we kill or change the PrefTable, we have to go into Config land for a moment.
155 SkBitmap::Config config = SkBitmap::kNo_Config;
154 switch (srcDepth) { 156 switch (srcDepth) {
155 case kIndex_SrcDepth: 157 case kIndex_SrcDepth:
156 config = srcHasAlpha ? fPrefTable.fPrefFor_8Index_YesAlpha_src 158 config = srcHasAlpha ? fPrefTable.fPrefFor_8Index_YesAlpha_src
157 : fPrefTable.fPrefFor_8Index_NoAlpha_src; 159 : fPrefTable.fPrefFor_8Index_NoAlpha_src;
158 break; 160 break;
159 case k8BitGray_SrcDepth: 161 case k8BitGray_SrcDepth:
160 config = fPrefTable.fPrefFor_8Gray_src; 162 config = fPrefTable.fPrefFor_8Gray_src;
161 break; 163 break;
162 case k32Bit_SrcDepth: 164 case k32Bit_SrcDepth:
163 config = srcHasAlpha ? fPrefTable.fPrefFor_8bpc_YesAlpha_src 165 config = srcHasAlpha ? fPrefTable.fPrefFor_8bpc_YesAlpha_src
164 : fPrefTable.fPrefFor_8bpc_NoAlpha_src; 166 : fPrefTable.fPrefFor_8bpc_NoAlpha_src;
165 break; 167 break;
166 } 168 }
167 } else { 169 // now return to SkColorType land
168 config = fDefaultPref; 170 ct = SkBitmapConfigToColorType(config);
169 } 171 }
170 172 return ct;
171 return SkBitmapConfigToColorType(config);
172 } 173 }
173 174
174 bool SkImageDecoder::decode(SkStream* stream, SkBitmap* bm, 175 bool SkImageDecoder::decode(SkStream* stream, SkBitmap* bm, SkColorType pref, Mo de mode) {
175 SkBitmap::Config pref, Mode mode) {
176 // we reset this to false before calling onDecode 176 // we reset this to false before calling onDecode
177 fShouldCancelDecode = false; 177 fShouldCancelDecode = false;
178 // assign this, for use by getPrefConfig(), in case fUsePrefTable is false 178 // assign this, for use by getPrefColorType(), in case fUsePrefTable is fals e
179 fDefaultPref = pref; 179 fDefaultPref = pref;
180 180
181 // pass a temporary bitmap, so that if we return false, we are assured of 181 // pass a temporary bitmap, so that if we return false, we are assured of
182 // leaving the caller's bitmap untouched. 182 // leaving the caller's bitmap untouched.
183 SkBitmap tmp; 183 SkBitmap tmp;
184 if (!this->onDecode(stream, &tmp, mode)) { 184 if (!this->onDecode(stream, &tmp, mode)) {
185 return false; 185 return false;
186 } 186 }
187 bm->swap(tmp); 187 bm->swap(tmp);
188 return true; 188 return true;
189 } 189 }
190 190
191 bool SkImageDecoder::decodeSubset(SkBitmap* bm, const SkIRect& rect, 191 bool SkImageDecoder::decodeSubset(SkBitmap* bm, const SkIRect& rect, SkColorType pref) {
192 SkBitmap::Config pref) {
193 // we reset this to false before calling onDecodeSubset 192 // we reset this to false before calling onDecodeSubset
194 fShouldCancelDecode = false; 193 fShouldCancelDecode = false;
195 // assign this, for use by getPrefConfig(), in case fUsePrefTable is false 194 // assign this, for use by getPrefColorType(), in case fUsePrefTable is fals e
196 fDefaultPref = pref; 195 fDefaultPref = pref;
197 196
198 return this->onDecodeSubset(bm, rect); 197 return this->onDecodeSubset(bm, rect);
199 } 198 }
200 199
201 bool SkImageDecoder::buildTileIndex(SkStreamRewindable* stream, 200 bool SkImageDecoder::buildTileIndex(SkStreamRewindable* stream, int *width, int *height) {
202 int *width, int *height) {
203 // we reset this to false before calling onBuildTileIndex 201 // we reset this to false before calling onBuildTileIndex
204 fShouldCancelDecode = false; 202 fShouldCancelDecode = false;
205 203
206 return this->onBuildTileIndex(stream, width, height); 204 return this->onBuildTileIndex(stream, width, height);
207 } 205 }
208 206
209 bool SkImageDecoder::cropBitmap(SkBitmap *dst, SkBitmap *src, int sampleSize, 207 bool SkImageDecoder::cropBitmap(SkBitmap *dst, SkBitmap *src, int sampleSize,
210 int dstX, int dstY, int width, int height, 208 int dstX, int dstY, int width, int height,
211 int srcX, int srcY) { 209 int srcX, int srcY) {
212 int w = width / sampleSize; 210 int w = width / sampleSize;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 246
249 SkCanvas canvas(*dst); 247 SkCanvas canvas(*dst);
250 canvas.drawSprite(*src, (srcX - dstX) / sampleSize, 248 canvas.drawSprite(*src, (srcX - dstX) / sampleSize,
251 (srcY - dstY) / sampleSize, 249 (srcY - dstY) / sampleSize,
252 &paint); 250 &paint);
253 return true; 251 return true;
254 } 252 }
255 253
256 /////////////////////////////////////////////////////////////////////////////// 254 ///////////////////////////////////////////////////////////////////////////////
257 255
258 bool SkImageDecoder::DecodeFile(const char file[], SkBitmap* bm, 256 bool SkImageDecoder::DecodeFile(const char file[], SkBitmap* bm, SkColorType pre f, Mode mode,
259 SkBitmap::Config pref, Mode mode, Format* format) { 257 Format* format) {
260 SkASSERT(file); 258 SkASSERT(file);
261 SkASSERT(bm); 259 SkASSERT(bm);
262 260
263 SkAutoTUnref<SkStreamRewindable> stream(SkStream::NewFromFile(file)); 261 SkAutoTUnref<SkStreamRewindable> stream(SkStream::NewFromFile(file));
264 if (stream.get()) { 262 if (stream.get()) {
265 if (SkImageDecoder::DecodeStream(stream, bm, pref, mode, format)) { 263 if (SkImageDecoder::DecodeStream(stream, bm, pref, mode, format)) {
266 bm->pixelRef()->setURI(file); 264 bm->pixelRef()->setURI(file);
267 return true; 265 return true;
268 } 266 }
269 } 267 }
270 return false; 268 return false;
271 } 269 }
272 270
273 bool SkImageDecoder::DecodeMemory(const void* buffer, size_t size, SkBitmap* bm, 271 bool SkImageDecoder::DecodeMemory(const void* buffer, size_t size, SkBitmap* bm, SkColorType pref,
274 SkBitmap::Config pref, Mode mode, Format* format) { 272 Mode mode, Format* format) {
275 if (0 == size) { 273 if (0 == size) {
276 return false; 274 return false;
277 } 275 }
278 SkASSERT(buffer); 276 SkASSERT(buffer);
279 277
280 SkMemoryStream stream(buffer, size); 278 SkMemoryStream stream(buffer, size);
281 return SkImageDecoder::DecodeStream(&stream, bm, pref, mode, format); 279 return SkImageDecoder::DecodeStream(&stream, bm, pref, mode, format);
282 } 280 }
283 281
284 bool SkImageDecoder::DecodeStream(SkStreamRewindable* stream, SkBitmap* bm, 282 bool SkImageDecoder::DecodeStream(SkStreamRewindable* stream, SkBitmap* bm, SkCo lorType pref,
285 SkBitmap::Config pref, Mode mode, 283 Mode mode, Format* format) {
286 Format* format) {
287 SkASSERT(stream); 284 SkASSERT(stream);
288 SkASSERT(bm); 285 SkASSERT(bm);
289 286
290 bool success = false; 287 bool success = false;
291 SkImageDecoder* codec = SkImageDecoder::Factory(stream); 288 SkImageDecoder* codec = SkImageDecoder::Factory(stream);
292 289
293 if (NULL != codec) { 290 if (NULL != codec) {
294 success = codec->decode(stream, bm, pref, mode); 291 success = codec->decode(stream, bm, pref, mode);
295 if (success && format) { 292 if (success && format) {
296 *format = codec->getFormat(); 293 *format = codec->getFormat();
297 if (kUnknown_Format == *format) { 294 if (kUnknown_Format == *format) {
298 if (stream->rewind()) { 295 if (stream->rewind()) {
299 *format = GetStreamFormat(stream); 296 *format = GetStreamFormat(stream);
300 } 297 }
301 } 298 }
302 } 299 }
303 delete codec; 300 delete codec;
304 } 301 }
305 return success; 302 return success;
306 } 303 }
OLDNEW
« no previous file with comments | « src/images/SkDecodingImageGenerator.cpp ('k') | src/ports/SkImageDecoder_empty.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698