| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
| 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 #include "SkData.h" | 8 #include "SkData.h" |
| 9 #include "SkDecodingImageGenerator.h" | 9 #include "SkDecodingImageGenerator.h" |
| 10 #include "SkImageDecoder.h" | 10 #include "SkImageDecoder.h" |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 return false; | 168 return false; |
| 169 } | 169 } |
| 170 | 170 |
| 171 SkAssertResult(fStream->rewind()); | 171 SkAssertResult(fStream->rewind()); |
| 172 SkAutoTDelete<SkImageDecoder> decoder(SkImageDecoder::Factory(fStream)); | 172 SkAutoTDelete<SkImageDecoder> decoder(SkImageDecoder::Factory(fStream)); |
| 173 if (NULL == decoder.get()) { | 173 if (NULL == decoder.get()) { |
| 174 return false; | 174 return false; |
| 175 } | 175 } |
| 176 decoder->setDitherImage(fDitherImage); | 176 decoder->setDitherImage(fDitherImage); |
| 177 decoder->setSampleSize(fSampleSize); | 177 decoder->setSampleSize(fSampleSize); |
| 178 decoder->setRequireUnpremultipliedColors( |
| 179 info.fAlphaType == kUnpremul_SkAlphaType); |
| 178 | 180 |
| 179 SkBitmap bitmap; | 181 SkBitmap bitmap; |
| 180 TargetAllocator allocator(fInfo, pixels, rowBytes); | 182 TargetAllocator allocator(fInfo, pixels, rowBytes); |
| 181 decoder->setAllocator(&allocator); | 183 decoder->setAllocator(&allocator); |
| 182 // TODO: need to be able to pass colortype directly to decoder | 184 // TODO: need to be able to pass colortype directly to decoder |
| 183 SkBitmap::Config legacyConfig = SkColorTypeToBitmapConfig(info.colorType()); | 185 SkBitmap::Config legacyConfig = SkColorTypeToBitmapConfig(info.colorType()); |
| 184 bool success = decoder->decode(fStream, &bitmap, legacyConfig, | 186 bool success = decoder->decode(fStream, &bitmap, legacyConfig, |
| 185 SkImageDecoder::kDecodePixels_Mode); | 187 SkImageDecoder::kDecodePixels_Mode); |
| 186 decoder->setAllocator(NULL); | 188 decoder->setAllocator(NULL); |
| 187 if (!success) { | 189 if (!success) { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 217 // We do not support indexed color with SkImageGenerators, | 219 // We do not support indexed color with SkImageGenerators, |
| 218 return NULL; | 220 return NULL; |
| 219 } | 221 } |
| 220 SkAssertResult(autoStream->rewind()); | 222 SkAssertResult(autoStream->rewind()); |
| 221 SkAutoTDelete<SkImageDecoder> decoder(SkImageDecoder::Factory(autoStream)); | 223 SkAutoTDelete<SkImageDecoder> decoder(SkImageDecoder::Factory(autoStream)); |
| 222 if (NULL == decoder.get()) { | 224 if (NULL == decoder.get()) { |
| 223 return NULL; | 225 return NULL; |
| 224 } | 226 } |
| 225 SkBitmap bitmap; | 227 SkBitmap bitmap; |
| 226 decoder->setSampleSize(opts.fSampleSize); | 228 decoder->setSampleSize(opts.fSampleSize); |
| 229 decoder->setRequireUnpremultipliedColors(opts.fRequireUnpremul); |
| 227 if (!decoder->decode(stream, &bitmap, | 230 if (!decoder->decode(stream, &bitmap, |
| 228 SkImageDecoder::kDecodeBounds_Mode)) { | 231 SkImageDecoder::kDecodeBounds_Mode)) { |
| 229 return NULL; | 232 return NULL; |
| 230 } | 233 } |
| 231 if (bitmap.config() == SkBitmap::kNo_Config) { | 234 if (bitmap.config() == SkBitmap::kNo_Config) { |
| 232 return NULL; | 235 return NULL; |
| 233 } | 236 } |
| 234 | 237 |
| 235 SkImageInfo info = bitmap.info(); | 238 SkImageInfo info = bitmap.info(); |
| 236 | 239 |
| 237 if (!opts.fUseRequestedColorType) { | 240 if (!opts.fUseRequestedColorType) { |
| 238 // Use default | 241 // Use default |
| 239 if (kIndex_8_SkColorType == bitmap.colorType()) { | 242 if (kIndex_8_SkColorType == bitmap.colorType()) { |
| 240 // We don't support kIndex8 because we don't support | 243 // We don't support kIndex8 because we don't support |
| 241 // colortables in this workflow. | 244 // colortables in this workflow. |
| 242 info.fColorType = kPMColor_SkColorType; | 245 info.fColorType = kPMColor_SkColorType; |
| 243 } | 246 } |
| 244 } else { | 247 } else { |
| 245 if (!bitmap.canCopyTo(opts.fRequestedColorType)) { | 248 if (!bitmap.canCopyTo(opts.fRequestedColorType)) { |
| 246 SkASSERT(bitmap.colorType() != opts.fRequestedColorType); | 249 SkASSERT(bitmap.colorType() != opts.fRequestedColorType); |
| 247 return NULL; // Can not translate to needed config. | 250 return NULL; // Can not translate to needed config. |
| 248 } | 251 } |
| 249 info.fColorType = opts.fRequestedColorType; | 252 info.fColorType = opts.fRequestedColorType; |
| 250 } | 253 } |
| 254 |
| 255 if (opts.fRequireUnpremul && info.fAlphaType != kOpaque_SkAlphaType) { |
| 256 info.fAlphaType = kUnpremul_SkAlphaType; |
| 257 } |
| 251 return SkNEW_ARGS(DecodingImageGenerator, | 258 return SkNEW_ARGS(DecodingImageGenerator, |
| 252 (data, autoStream.detach(), info, | 259 (data, autoStream.detach(), info, |
| 253 opts.fSampleSize, opts.fDitherImage)); | 260 opts.fSampleSize, opts.fDitherImage)); |
| 254 } | 261 } |
| 255 | 262 |
| 256 } // namespace | 263 } // namespace |
| 257 | 264 |
| 258 //////////////////////////////////////////////////////////////////////////////// | 265 //////////////////////////////////////////////////////////////////////////////// |
| 259 | 266 |
| 260 SkImageGenerator* SkDecodingImageGenerator::Create( | 267 SkImageGenerator* SkDecodingImageGenerator::Create( |
| (...skipping 13 matching lines...) Expand all Loading... |
| 274 SkStreamRewindable* stream, | 281 SkStreamRewindable* stream, |
| 275 const SkDecodingImageGenerator::Options& opts) { | 282 const SkDecodingImageGenerator::Options& opts) { |
| 276 SkASSERT(stream != NULL); | 283 SkASSERT(stream != NULL); |
| 277 SkASSERT(stream->unique()); | 284 SkASSERT(stream->unique()); |
| 278 if ((stream == NULL) || !stream->unique()) { | 285 if ((stream == NULL) || !stream->unique()) { |
| 279 SkSafeUnref(stream); | 286 SkSafeUnref(stream); |
| 280 return NULL; | 287 return NULL; |
| 281 } | 288 } |
| 282 return CreateDecodingImageGenerator(NULL, stream, opts); | 289 return CreateDecodingImageGenerator(NULL, stream, opts); |
| 283 } | 290 } |
| OLD | NEW |