OLD | NEW |
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 , fPreserveSrcDepth(false) |
26 , fDitherImage(true) | 26 , fDitherImage(true) |
27 #ifdef SK_SUPPORT_LEGACY_BITMAP_CONFIG | |
28 , fUsePrefTable(false) | |
29 #endif | |
30 , fSkipWritingZeroes(false) | 27 , fSkipWritingZeroes(false) |
31 , fPreferQualityOverSpeed(false) | 28 , fPreferQualityOverSpeed(false) |
32 , fRequireUnpremultipliedColors(false) { | 29 , fRequireUnpremultipliedColors(false) { |
33 } | 30 } |
34 | 31 |
35 SkImageDecoder::~SkImageDecoder() { | 32 SkImageDecoder::~SkImageDecoder() { |
36 SkSafeUnref(fPeeker); | 33 SkSafeUnref(fPeeker); |
37 #ifdef SK_SUPPORT_LEGACY_IMAGEDECODER_CHOOSER | 34 #ifdef SK_SUPPORT_LEGACY_IMAGEDECODER_CHOOSER |
38 SkSafeUnref(fChooser); | 35 SkSafeUnref(fChooser); |
39 #endif | 36 #endif |
40 SkSafeUnref(fAllocator); | 37 SkSafeUnref(fAllocator); |
41 } | 38 } |
42 | 39 |
43 void SkImageDecoder::copyFieldsToOther(SkImageDecoder* other) { | 40 void SkImageDecoder::copyFieldsToOther(SkImageDecoder* other) { |
44 if (NULL == other) { | 41 if (NULL == other) { |
45 return; | 42 return; |
46 } | 43 } |
47 other->setPeeker(fPeeker); | 44 other->setPeeker(fPeeker); |
48 #ifdef SK_SUPPORT_LEGACY_IMAGEDECODER_CHOOSER | 45 #ifdef SK_SUPPORT_LEGACY_IMAGEDECODER_CHOOSER |
49 other->setChooser(fChooser); | 46 other->setChooser(fChooser); |
50 #endif | 47 #endif |
51 other->setAllocator(fAllocator); | 48 other->setAllocator(fAllocator); |
52 other->setSampleSize(fSampleSize); | 49 other->setSampleSize(fSampleSize); |
53 #ifdef SK_SUPPORT_LEGACY_BITMAP_CONFIG | |
54 if (fUsePrefTable) { | |
55 other->setPrefConfigTable(fPrefTable); | |
56 } else { | |
57 other->fDefaultPref = fDefaultPref; | |
58 } | |
59 #endif | |
60 other->setPreserveSrcDepth(fPreserveSrcDepth); | 50 other->setPreserveSrcDepth(fPreserveSrcDepth); |
61 other->setDitherImage(fDitherImage); | 51 other->setDitherImage(fDitherImage); |
62 other->setSkipWritingZeroes(fSkipWritingZeroes); | 52 other->setSkipWritingZeroes(fSkipWritingZeroes); |
63 other->setPreferQualityOverSpeed(fPreferQualityOverSpeed); | 53 other->setPreferQualityOverSpeed(fPreferQualityOverSpeed); |
64 other->setRequireUnpremultipliedColors(fRequireUnpremultipliedColors); | 54 other->setRequireUnpremultipliedColors(fRequireUnpremultipliedColors); |
65 } | 55 } |
66 | 56 |
67 SkImageDecoder::Format SkImageDecoder::getFormat() const { | 57 SkImageDecoder::Format SkImageDecoder::getFormat() const { |
68 return kUnknown_Format; | 58 return kUnknown_Format; |
69 } | 59 } |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 } | 131 } |
142 #endif | 132 #endif |
143 | 133 |
144 bool SkImageDecoder::allocPixelRef(SkBitmap* bitmap, | 134 bool SkImageDecoder::allocPixelRef(SkBitmap* bitmap, |
145 SkColorTable* ctable) const { | 135 SkColorTable* ctable) const { |
146 return bitmap->allocPixels(fAllocator, ctable); | 136 return bitmap->allocPixels(fAllocator, ctable); |
147 } | 137 } |
148 | 138 |
149 /////////////////////////////////////////////////////////////////////////////// | 139 /////////////////////////////////////////////////////////////////////////////// |
150 | 140 |
151 #ifdef SK_SUPPORT_LEGACY_BITMAP_CONFIG | |
152 void SkImageDecoder::setPrefConfigTable(const PrefConfigTable& prefTable) { | |
153 fUsePrefTable = true; | |
154 fPrefTable = prefTable; | |
155 } | |
156 #endif | |
157 | |
158 // TODO: use colortype in fPrefTable, fDefaultPref so we can stop using SkBitmap
ConfigToColorType() | |
159 // | |
160 SkColorType SkImageDecoder::getPrefColorType(SrcDepth srcDepth, bool srcHasAlpha
) const { | 141 SkColorType SkImageDecoder::getPrefColorType(SrcDepth srcDepth, bool srcHasAlpha
) const { |
161 SkColorType ct = fDefaultPref; | 142 SkColorType ct = fDefaultPref; |
162 #ifdef SK_SUPPORT_LEGACY_BITMAP_CONFIG | |
163 if (fUsePrefTable) { | |
164 // Until we kill or change the PrefTable, we have to go into Config land
for a moment. | |
165 SkBitmap::Config config = SkBitmap::kNo_Config; | |
166 switch (srcDepth) { | |
167 case kIndex_SrcDepth: | |
168 config = srcHasAlpha ? fPrefTable.fPrefFor_8Index_YesAlpha_src | |
169 : fPrefTable.fPrefFor_8Index_NoAlpha_src; | |
170 break; | |
171 case k8BitGray_SrcDepth: | |
172 config = fPrefTable.fPrefFor_8Gray_src; | |
173 break; | |
174 case k32Bit_SrcDepth: | |
175 config = srcHasAlpha ? fPrefTable.fPrefFor_8bpc_YesAlpha_src | |
176 : fPrefTable.fPrefFor_8bpc_NoAlpha_src; | |
177 break; | |
178 } | |
179 // now return to SkColorType land | |
180 ct = SkBitmapConfigToColorType(config); | |
181 } | |
182 #endif | |
183 if (fPreserveSrcDepth) { | 143 if (fPreserveSrcDepth) { |
184 switch (srcDepth) { | 144 switch (srcDepth) { |
185 case kIndex_SrcDepth: | 145 case kIndex_SrcDepth: |
186 ct = kIndex_8_SkColorType; | 146 ct = kIndex_8_SkColorType; |
187 break; | 147 break; |
188 case k8BitGray_SrcDepth: | 148 case k8BitGray_SrcDepth: |
189 ct = kN32_SkColorType; | 149 ct = kN32_SkColorType; |
190 break; | 150 break; |
191 case k32Bit_SrcDepth: | 151 case k32Bit_SrcDepth: |
192 ct = kN32_SkColorType; | 152 ct = kN32_SkColorType; |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 if (kUnknown_Format == *format) { | 278 if (kUnknown_Format == *format) { |
319 if (stream->rewind()) { | 279 if (stream->rewind()) { |
320 *format = GetStreamFormat(stream); | 280 *format = GetStreamFormat(stream); |
321 } | 281 } |
322 } | 282 } |
323 } | 283 } |
324 delete codec; | 284 delete codec; |
325 } | 285 } |
326 return success; | 286 return success; |
327 } | 287 } |
OLD | NEW |