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

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
« include/core/SkImageDecoder.h ('K') | « 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() {
35 SkSafeUnref(fPeeker); 36 SkSafeUnref(fPeeker);
36 #ifdef SK_SUPPORT_LEGACY_IMAGEDECODER_CHOOSER 37 #ifdef SK_SUPPORT_LEGACY_IMAGEDECODER_CHOOSER
37 SkSafeUnref(fChooser); 38 SkSafeUnref(fChooser);
38 #endif 39 #endif
39 SkSafeUnref(fAllocator); 40 SkSafeUnref(fAllocator);
40 } 41 }
41 42
42 void SkImageDecoder::copyFieldsToOther(SkImageDecoder* other) { 43 void SkImageDecoder::copyFieldsToOther(SkImageDecoder* other) {
scroggo 2014/07/08 17:31:07 I think we should copy fPreserveSrcDepth here as w
reed1 2014/07/08 17:41:24 Done.
43 if (NULL == other) { 44 if (NULL == other) {
44 return; 45 return;
45 } 46 }
46 other->setPeeker(fPeeker); 47 other->setPeeker(fPeeker);
47 #ifdef SK_SUPPORT_LEGACY_IMAGEDECODER_CHOOSER 48 #ifdef SK_SUPPORT_LEGACY_IMAGEDECODER_CHOOSER
48 other->setChooser(fChooser); 49 other->setChooser(fChooser);
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
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 fUsePrefTable = true; 150 fUsePrefTable = true;
150 fPrefTable = prefTable; 151 fPrefTable = prefTable;
151 } 152 }
152 #endif 153 #endif
153 154
154 // TODO: use colortype in fPrefTable, fDefaultPref so we can stop using SkBitmap ConfigToColorType() 155 // TODO: use colortype in fPrefTable, fDefaultPref so we can stop using SkBitmap ConfigToColorType()
155 // 156 //
156 SkColorType SkImageDecoder::getPrefColorType(SrcDepth srcDepth, bool srcHasAlpha ) const { 157 SkColorType SkImageDecoder::getPrefColorType(SrcDepth srcDepth, bool srcHasAlpha ) const {
157 SkColorType ct = fDefaultPref; 158 SkColorType ct = fDefaultPref;
158 #ifdef SK_SUPPORT_LEGACY_BITMAP_CONFIG 159 #ifdef SK_SUPPORT_LEGACY_BITMAP_CONFIG
159
160 if (fUsePrefTable) { 160 if (fUsePrefTable) {
161 // Until we kill or change the PrefTable, we have to go into Config land for a moment. 161 // Until we kill or change the PrefTable, we have to go into Config land for a moment.
162 SkBitmap::Config config = SkBitmap::kNo_Config; 162 SkBitmap::Config config = SkBitmap::kNo_Config;
163 switch (srcDepth) { 163 switch (srcDepth) {
164 case kIndex_SrcDepth: 164 case kIndex_SrcDepth:
165 config = srcHasAlpha ? fPrefTable.fPrefFor_8Index_YesAlpha_src 165 config = srcHasAlpha ? fPrefTable.fPrefFor_8Index_YesAlpha_src
166 : fPrefTable.fPrefFor_8Index_NoAlpha_src; 166 : fPrefTable.fPrefFor_8Index_NoAlpha_src;
167 break; 167 break;
168 case k8BitGray_SrcDepth: 168 case k8BitGray_SrcDepth:
169 config = fPrefTable.fPrefFor_8Gray_src; 169 config = fPrefTable.fPrefFor_8Gray_src;
170 break; 170 break;
171 case k32Bit_SrcDepth: 171 case k32Bit_SrcDepth:
172 config = srcHasAlpha ? fPrefTable.fPrefFor_8bpc_YesAlpha_src 172 config = srcHasAlpha ? fPrefTable.fPrefFor_8bpc_YesAlpha_src
173 : fPrefTable.fPrefFor_8bpc_NoAlpha_src; 173 : fPrefTable.fPrefFor_8bpc_NoAlpha_src;
174 break; 174 break;
175 } 175 }
176 // now return to SkColorType land 176 // now return to SkColorType land
177 ct = SkBitmapConfigToColorType(config); 177 ct = SkBitmapConfigToColorType(config);
178 } 178 }
179 #endif 179 #endif
180 if (fPreserveSrcDepth) {
181 switch (srcDepth) {
182 case kIndex_SrcDepth:
183 ct = kIndex_8_SkColorType;
184 break;
185 case k8BitGray_SrcDepth:
186 ct = kN32_SkColorType;
187 break;
188 case k32Bit_SrcDepth:
189 ct = kN32_SkColorType;
190 break;
191 }
192 }
180 return ct; 193 return ct;
181 } 194 }
182 195
183 bool SkImageDecoder::decode(SkStream* stream, SkBitmap* bm, SkColorType pref, Mo de mode) { 196 bool SkImageDecoder::decode(SkStream* stream, SkBitmap* bm, SkColorType pref, Mo de mode) {
184 // we reset this to false before calling onDecode 197 // we reset this to false before calling onDecode
185 fShouldCancelDecode = false; 198 fShouldCancelDecode = false;
186 // assign this, for use by getPrefColorType(), in case fUsePrefTable is fals e 199 // assign this, for use by getPrefColorType(), in case fUsePrefTable is fals e
187 fDefaultPref = pref; 200 fDefaultPref = pref;
188 201
189 // pass a temporary bitmap, so that if we return false, we are assured of 202 // 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) { 315 if (kUnknown_Format == *format) {
303 if (stream->rewind()) { 316 if (stream->rewind()) {
304 *format = GetStreamFormat(stream); 317 *format = GetStreamFormat(stream);
305 } 318 }
306 } 319 }
307 } 320 }
308 delete codec; 321 delete codec;
309 } 322 }
310 return success; 323 return success;
311 } 324 }
OLDNEW
« include/core/SkImageDecoder.h ('K') | « include/core/SkImageDecoder.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698