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/images/SkImageDecoder.cpp

Issue 371273007: add setPreserveSrcDepth to replace PrefTable API for android (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 5 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 | « include/core/SkImageDecoder.h ('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 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(kUnknown_SkColorType) 24 , fDefaultPref(kUnknown_SkColorType)
25 , fPreserveSrcDepth(false)
25 , fDitherImage(true) 26 , fDitherImage(true)
26 #ifdef SK_SUPPORT_LEGACY_BITMAP_CONFIG 27 #ifdef SK_SUPPORT_LEGACY_BITMAP_CONFIG
27 , fUsePrefTable(false) 28 , fUsePrefTable(false)
28 #endif 29 #endif
29 , fSkipWritingZeroes(false) 30 , fSkipWritingZeroes(false)
30 , fPreferQualityOverSpeed(false) 31 , fPreferQualityOverSpeed(false)
31 , fRequireUnpremultipliedColors(false) { 32 , fRequireUnpremultipliedColors(false) {
32 } 33 }
33 34
34 SkImageDecoder::~SkImageDecoder() { 35 SkImageDecoder::~SkImageDecoder() {
(...skipping 14 matching lines...) Expand all
49 #endif 50 #endif
50 other->setAllocator(fAllocator); 51 other->setAllocator(fAllocator);
51 other->setSampleSize(fSampleSize); 52 other->setSampleSize(fSampleSize);
52 #ifdef SK_SUPPORT_LEGACY_BITMAP_CONFIG 53 #ifdef SK_SUPPORT_LEGACY_BITMAP_CONFIG
53 if (fUsePrefTable) { 54 if (fUsePrefTable) {
54 other->setPrefConfigTable(fPrefTable); 55 other->setPrefConfigTable(fPrefTable);
55 } else { 56 } else {
56 other->fDefaultPref = fDefaultPref; 57 other->fDefaultPref = fDefaultPref;
57 } 58 }
58 #endif 59 #endif
60 other->setPreserveSrcDepth(fPreserveSrcDepth);
59 other->setDitherImage(fDitherImage); 61 other->setDitherImage(fDitherImage);
60 other->setSkipWritingZeroes(fSkipWritingZeroes); 62 other->setSkipWritingZeroes(fSkipWritingZeroes);
61 other->setPreferQualityOverSpeed(fPreferQualityOverSpeed); 63 other->setPreferQualityOverSpeed(fPreferQualityOverSpeed);
62 other->setRequireUnpremultipliedColors(fRequireUnpremultipliedColors); 64 other->setRequireUnpremultipliedColors(fRequireUnpremultipliedColors);
63 } 65 }
64 66
65 SkImageDecoder::Format SkImageDecoder::getFormat() const { 67 SkImageDecoder::Format SkImageDecoder::getFormat() const {
66 return kUnknown_Format; 68 return kUnknown_Format;
67 } 69 }
68 70
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 fUsePrefTable = true; 151 fUsePrefTable = true;
150 fPrefTable = prefTable; 152 fPrefTable = prefTable;
151 } 153 }
152 #endif 154 #endif
153 155
154 // TODO: use colortype in fPrefTable, fDefaultPref so we can stop using SkBitmap ConfigToColorType() 156 // TODO: use colortype in fPrefTable, fDefaultPref so we can stop using SkBitmap ConfigToColorType()
155 // 157 //
156 SkColorType SkImageDecoder::getPrefColorType(SrcDepth srcDepth, bool srcHasAlpha ) const { 158 SkColorType SkImageDecoder::getPrefColorType(SrcDepth srcDepth, bool srcHasAlpha ) const {
157 SkColorType ct = fDefaultPref; 159 SkColorType ct = fDefaultPref;
158 #ifdef SK_SUPPORT_LEGACY_BITMAP_CONFIG 160 #ifdef SK_SUPPORT_LEGACY_BITMAP_CONFIG
159
160 if (fUsePrefTable) { 161 if (fUsePrefTable) {
161 // Until we kill or change the PrefTable, we have to go into Config land for a moment. 162 // Until we kill or change the PrefTable, we have to go into Config land for a moment.
162 SkBitmap::Config config = SkBitmap::kNo_Config; 163 SkBitmap::Config config = SkBitmap::kNo_Config;
163 switch (srcDepth) { 164 switch (srcDepth) {
164 case kIndex_SrcDepth: 165 case kIndex_SrcDepth:
165 config = srcHasAlpha ? fPrefTable.fPrefFor_8Index_YesAlpha_src 166 config = srcHasAlpha ? fPrefTable.fPrefFor_8Index_YesAlpha_src
166 : fPrefTable.fPrefFor_8Index_NoAlpha_src; 167 : fPrefTable.fPrefFor_8Index_NoAlpha_src;
167 break; 168 break;
168 case k8BitGray_SrcDepth: 169 case k8BitGray_SrcDepth:
169 config = fPrefTable.fPrefFor_8Gray_src; 170 config = fPrefTable.fPrefFor_8Gray_src;
170 break; 171 break;
171 case k32Bit_SrcDepth: 172 case k32Bit_SrcDepth:
172 config = srcHasAlpha ? fPrefTable.fPrefFor_8bpc_YesAlpha_src 173 config = srcHasAlpha ? fPrefTable.fPrefFor_8bpc_YesAlpha_src
173 : fPrefTable.fPrefFor_8bpc_NoAlpha_src; 174 : fPrefTable.fPrefFor_8bpc_NoAlpha_src;
174 break; 175 break;
175 } 176 }
176 // now return to SkColorType land 177 // now return to SkColorType land
177 ct = SkBitmapConfigToColorType(config); 178 ct = SkBitmapConfigToColorType(config);
178 } 179 }
179 #endif 180 #endif
181 if (fPreserveSrcDepth) {
182 switch (srcDepth) {
183 case kIndex_SrcDepth:
184 ct = kIndex_8_SkColorType;
185 break;
186 case k8BitGray_SrcDepth:
187 ct = kN32_SkColorType;
188 break;
189 case k32Bit_SrcDepth:
190 ct = kN32_SkColorType;
191 break;
192 }
193 }
180 return ct; 194 return ct;
181 } 195 }
182 196
183 bool SkImageDecoder::decode(SkStream* stream, SkBitmap* bm, SkColorType pref, Mo de mode) { 197 bool SkImageDecoder::decode(SkStream* stream, SkBitmap* bm, SkColorType pref, Mo de mode) {
184 // we reset this to false before calling onDecode 198 // we reset this to false before calling onDecode
185 fShouldCancelDecode = false; 199 fShouldCancelDecode = false;
186 // assign this, for use by getPrefColorType(), in case fUsePrefTable is fals e 200 // assign this, for use by getPrefColorType(), in case fUsePrefTable is fals e
187 fDefaultPref = pref; 201 fDefaultPref = pref;
188 202
189 // pass a temporary bitmap, so that if we return false, we are assured of 203 // pass a temporary bitmap, so that if we return false, we are assured of
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 if (kUnknown_Format == *format) { 316 if (kUnknown_Format == *format) {
303 if (stream->rewind()) { 317 if (stream->rewind()) {
304 *format = GetStreamFormat(stream); 318 *format = GetStreamFormat(stream);
305 } 319 }
306 } 320 }
307 } 321 }
308 delete codec; 322 delete codec;
309 } 323 }
310 return success; 324 return success;
311 } 325 }
OLDNEW
« no previous file with comments | « include/core/SkImageDecoder.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698