| 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 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 return false; | 160 return false; |
| 161 } | 161 } |
| 162 | 162 |
| 163 SkAssertResult(fStream->rewind()); | 163 SkAssertResult(fStream->rewind()); |
| 164 SkAutoTDelete<SkImageDecoder> decoder(SkImageDecoder::Factory(fStream)); | 164 SkAutoTDelete<SkImageDecoder> decoder(SkImageDecoder::Factory(fStream)); |
| 165 if (NULL == decoder.get()) { | 165 if (NULL == decoder.get()) { |
| 166 return false; | 166 return false; |
| 167 } | 167 } |
| 168 decoder->setDitherImage(fDitherImage); | 168 decoder->setDitherImage(fDitherImage); |
| 169 decoder->setSampleSize(fSampleSize); | 169 decoder->setSampleSize(fSampleSize); |
| 170 decoder->setRequireUnpremultipliedColors( | 170 decoder->setRequireUnpremultipliedColors(info.alphaType() == kUnpremul_SkAlp
haType); |
| 171 info.fAlphaType == kUnpremul_SkAlphaType); | |
| 172 | 171 |
| 173 SkBitmap bitmap; | 172 SkBitmap bitmap; |
| 174 TargetAllocator allocator(fInfo, pixels, rowBytes); | 173 TargetAllocator allocator(fInfo, pixels, rowBytes); |
| 175 decoder->setAllocator(&allocator); | 174 decoder->setAllocator(&allocator); |
| 176 bool success = decoder->decode(fStream, &bitmap, info.colorType(), | 175 bool success = decoder->decode(fStream, &bitmap, info.colorType(), |
| 177 SkImageDecoder::kDecodePixels_Mode); | 176 SkImageDecoder::kDecodePixels_Mode); |
| 178 decoder->setAllocator(NULL); | 177 decoder->setAllocator(NULL); |
| 179 if (!success) { | 178 if (!success) { |
| 180 return false; | 179 return false; |
| 181 } | 180 } |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 return NULL; | 232 return NULL; |
| 234 } | 233 } |
| 235 | 234 |
| 236 SkImageInfo info = bitmap.info(); | 235 SkImageInfo info = bitmap.info(); |
| 237 | 236 |
| 238 if (opts.fUseRequestedColorType && (opts.fRequestedColorType != info.colorTy
pe())) { | 237 if (opts.fUseRequestedColorType && (opts.fRequestedColorType != info.colorTy
pe())) { |
| 239 if (!bitmap.canCopyTo(opts.fRequestedColorType)) { | 238 if (!bitmap.canCopyTo(opts.fRequestedColorType)) { |
| 240 SkASSERT(bitmap.colorType() != opts.fRequestedColorType); | 239 SkASSERT(bitmap.colorType() != opts.fRequestedColorType); |
| 241 return NULL; // Can not translate to needed config. | 240 return NULL; // Can not translate to needed config. |
| 242 } | 241 } |
| 243 info.fColorType = opts.fRequestedColorType; | 242 info = info.makeColorType(opts.fRequestedColorType); |
| 244 } | 243 } |
| 245 | 244 |
| 246 if (opts.fRequireUnpremul && info.fAlphaType != kOpaque_SkAlphaType) { | 245 if (opts.fRequireUnpremul && info.alphaType() != kOpaque_SkAlphaType) { |
| 247 info.fAlphaType = kUnpremul_SkAlphaType; | 246 info = info.makeAlphaType(kUnpremul_SkAlphaType); |
| 248 } | 247 } |
| 249 | 248 |
| 250 if (!SkColorTypeValidateAlphaType(info.fColorType, info.fAlphaType, &info.fA
lphaType)) { | 249 SkAlphaType newAlphaType = info.alphaType(); |
| 250 if (!SkColorTypeValidateAlphaType(info.colorType(), info.alphaType(), &newAl
phaType)) { |
| 251 return NULL; | 251 return NULL; |
| 252 } | 252 } |
| 253 | 253 |
| 254 return SkNEW_ARGS(DecodingImageGenerator, | 254 return SkNEW_ARGS(DecodingImageGenerator, |
| 255 (data, autoStream.detach(), info, | 255 (data, autoStream.detach(), info.makeAlphaType(newAlphaTyp
e), |
| 256 opts.fSampleSize, opts.fDitherImage)); | 256 opts.fSampleSize, opts.fDitherImage)); |
| 257 } | 257 } |
| 258 | 258 |
| 259 } // namespace | 259 } // namespace |
| 260 | 260 |
| 261 //////////////////////////////////////////////////////////////////////////////// | 261 //////////////////////////////////////////////////////////////////////////////// |
| 262 | 262 |
| 263 SkImageGenerator* SkDecodingImageGenerator::Create( | 263 SkImageGenerator* SkDecodingImageGenerator::Create( |
| 264 SkData* data, | 264 SkData* data, |
| 265 const SkDecodingImageGenerator::Options& opts) { | 265 const SkDecodingImageGenerator::Options& opts) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 277 SkStreamRewindable* stream, | 277 SkStreamRewindable* stream, |
| 278 const SkDecodingImageGenerator::Options& opts) { | 278 const SkDecodingImageGenerator::Options& opts) { |
| 279 SkASSERT(stream != NULL); | 279 SkASSERT(stream != NULL); |
| 280 SkASSERT(stream->unique()); | 280 SkASSERT(stream->unique()); |
| 281 if ((stream == NULL) || !stream->unique()) { | 281 if ((stream == NULL) || !stream->unique()) { |
| 282 SkSafeUnref(stream); | 282 SkSafeUnref(stream); |
| 283 return NULL; | 283 return NULL; |
| 284 } | 284 } |
| 285 return CreateDecodingImageGenerator(NULL, stream, opts); | 285 return CreateDecodingImageGenerator(NULL, stream, opts); |
| 286 } | 286 } |
| OLD | NEW |