| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 "SkCodecImageGenerator.h" | 8 #include "SkCodecImageGenerator.h" |
| 9 #include "SkPM4fPriv.h" | |
| 10 | 9 |
| 11 SkImageGenerator* SkCodecImageGenerator::NewFromEncodedCodec(SkData* data) { | 10 SkImageGenerator* SkCodecImageGenerator::NewFromEncodedCodec(SkData* data) { |
| 12 SkCodec* codec = SkCodec::NewFromData(data); | 11 SkCodec* codec = SkCodec::NewFromData(data); |
| 13 if (nullptr == codec) { | 12 if (nullptr == codec) { |
| 14 return nullptr; | 13 return nullptr; |
| 15 } | 14 } |
| 16 | 15 |
| 17 return new SkCodecImageGenerator(codec, data); | 16 return new SkCodecImageGenerator(codec, data); |
| 18 } | 17 } |
| 19 | 18 |
| 20 // FIXME: We should expose information about the encoded format on the | 19 static SkImageInfo make_premul(const SkImageInfo& info) { |
| 21 // SkImageGenerator, so the client can interpret the encoded | 20 if (kUnpremul_SkAlphaType == info.alphaType()) { |
| 22 // format and request an output format. For now, as a workaround, | 21 return info.makeAlphaType(kPremul_SkAlphaType); |
| 23 // we guess what output format the client wants. | |
| 24 static SkImageInfo fix_info(const SkCodec& codec) { | |
| 25 const SkImageInfo& info = codec.getInfo(); | |
| 26 SkAlphaType alphaType = (kUnpremul_SkAlphaType == info.alphaType()) ? kPremu
l_SkAlphaType : | |
| 27 info.alphaType(); | |
| 28 | |
| 29 SkColorProfileType profileType = kLinear_SkColorProfileType; | |
| 30 // Crudely guess that the presence of a color space means sRGB, or obey the
global sRGB | |
| 31 // selector. | |
| 32 if (gTreatSkColorAsSRGB || codec.getColorSpace()) { | |
| 33 profileType = kSRGB_SkColorProfileType; | |
| 34 } | 22 } |
| 35 | 23 |
| 36 return SkImageInfo::Make(info.width(), info.height(), info.colorType(), alph
aType, profileType); | 24 return info; |
| 37 } | 25 } |
| 38 | 26 |
| 39 SkCodecImageGenerator::SkCodecImageGenerator(SkCodec* codec, SkData* data) | 27 SkCodecImageGenerator::SkCodecImageGenerator(SkCodec* codec, SkData* data) |
| 40 : INHERITED(fix_info(*codec)) | 28 : INHERITED(make_premul(codec->getInfo())) |
| 41 , fCodec(codec) | 29 , fCodec(codec) |
| 42 , fData(SkRef(data)) | 30 , fData(SkRef(data)) |
| 43 {} | 31 {} |
| 44 | 32 |
| 45 SkData* SkCodecImageGenerator::onRefEncodedData(SK_REFENCODEDDATA_CTXPARAM) { | 33 SkData* SkCodecImageGenerator::onRefEncodedData(SK_REFENCODEDDATA_CTXPARAM) { |
| 46 return SkRef(fData.get()); | 34 return SkRef(fData.get()); |
| 47 } | 35 } |
| 48 | 36 |
| 49 bool SkCodecImageGenerator::onGetPixels(const SkImageInfo& info, void* pixels, s
ize_t rowBytes, | 37 bool SkCodecImageGenerator::onGetPixels(const SkImageInfo& info, void* pixels, s
ize_t rowBytes, |
| 50 SkPMColor ctable[], int* ctableCount) { | 38 SkPMColor ctable[], int* ctableCount) { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 69 SkCodec::Result result = fCodec->getYUV8Planes(sizeInfo, planes); | 57 SkCodec::Result result = fCodec->getYUV8Planes(sizeInfo, planes); |
| 70 | 58 |
| 71 switch (result) { | 59 switch (result) { |
| 72 case SkCodec::kSuccess: | 60 case SkCodec::kSuccess: |
| 73 case SkCodec::kIncompleteInput: | 61 case SkCodec::kIncompleteInput: |
| 74 return true; | 62 return true; |
| 75 default: | 63 default: |
| 76 return false; | 64 return false; |
| 77 } | 65 } |
| 78 } | 66 } |
| OLD | NEW |