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" |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 return bitmap->allocPixels(fAllocator, ctable); | 138 return bitmap->allocPixels(fAllocator, ctable); |
139 } | 139 } |
140 | 140 |
141 /////////////////////////////////////////////////////////////////////////////// | 141 /////////////////////////////////////////////////////////////////////////////// |
142 | 142 |
143 void SkImageDecoder::setPrefConfigTable(const SkBitmap::Config pref[6]) { | 143 void SkImageDecoder::setPrefConfigTable(const SkBitmap::Config pref[6]) { |
144 if (NULL == pref) { | 144 if (NULL == pref) { |
145 fUsePrefTable = false; | 145 fUsePrefTable = false; |
146 } else { | 146 } else { |
147 fUsePrefTable = true; | 147 fUsePrefTable = true; |
148 memcpy(fPrefTable, pref, sizeof(fPrefTable)); | 148 fPrefTable.f8Index_NoAlpha = pref[0]; |
| 149 fPrefTable.f8Index_YesAlpha = pref[1]; |
| 150 fPrefTable.f8Gray = SkBitmap::kNo_Config; |
| 151 fPrefTable.f16bit_NoAlpha = pref[2]; |
| 152 fPrefTable.f16bit_YesAlpha = pref[3]; |
| 153 fPrefTable.f32_24bit_NoAlpha = pref[4]; |
| 154 fPrefTable.f32_24bit_YesAlpha = pref[5]; |
149 } | 155 } |
150 } | 156 } |
151 | 157 |
| 158 void SkImageDecoder::setPrefConfigTable(const PrefConfigTable& prefTable) { |
| 159 fUsePrefTable = true; |
| 160 fPrefTable = prefTable; |
| 161 } |
| 162 |
152 SkBitmap::Config SkImageDecoder::getPrefConfig(SrcDepth srcDepth, | 163 SkBitmap::Config SkImageDecoder::getPrefConfig(SrcDepth srcDepth, |
153 bool srcHasAlpha) const { | 164 bool srcHasAlpha) const { |
154 SkBitmap::Config config; | 165 SkBitmap::Config config; |
155 | 166 |
156 if (fUsePrefTable) { | 167 if (fUsePrefTable) { |
157 int index = 0; | |
158 switch (srcDepth) { | 168 switch (srcDepth) { |
159 case kIndex_SrcDepth: | 169 case kIndex_SrcDepth: |
160 index = 0; | 170 config = srcHasAlpha ? fPrefTable.f8Index_YesAlpha |
| 171 : fPrefTable.f8Index_NoAlpha; |
| 172 break; |
| 173 case k8BitGray_SrcDepth: |
| 174 config = fPrefTable.f8Gray; |
161 break; | 175 break; |
162 case k16Bit_SrcDepth: | 176 case k16Bit_SrcDepth: |
163 index = 2; | 177 config = srcHasAlpha ? fPrefTable.f16bit_YesAlpha |
| 178 : fPrefTable.f16bit_NoAlpha; |
164 break; | 179 break; |
165 case k32Bit_SrcDepth: | 180 case k32Bit_SrcDepth: |
166 index = 4; | 181 config = srcHasAlpha ? fPrefTable.f32_24bit_YesAlpha |
| 182 : fPrefTable.f32_24bit_NoAlpha; |
167 break; | 183 break; |
168 } | 184 } |
169 if (srcHasAlpha) { | |
170 index += 1; | |
171 } | |
172 config = fPrefTable[index]; | |
173 } else { | 185 } else { |
174 config = fDefaultPref; | 186 config = fDefaultPref; |
175 } | 187 } |
176 | 188 |
177 if (SkBitmap::kNo_Config == config) { | 189 if (SkBitmap::kNo_Config == config) { |
178 config = SkImageDecoder::GetDeviceConfig(); | 190 config = SkImageDecoder::GetDeviceConfig(); |
179 } | 191 } |
180 return config; | 192 return config; |
181 } | 193 } |
182 | 194 |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
454 if (kUnknown_Format == *format) { | 466 if (kUnknown_Format == *format) { |
455 if (stream->rewind()) { | 467 if (stream->rewind()) { |
456 *format = GetStreamFormat(stream); | 468 *format = GetStreamFormat(stream); |
457 } | 469 } |
458 } | 470 } |
459 } | 471 } |
460 delete codec; | 472 delete codec; |
461 } | 473 } |
462 return success; | 474 return success; |
463 } | 475 } |
OLD | NEW |