| OLD | NEW | 
|---|
| 1 /* | 1 /* | 
| 2  * Copyright 2015 The Android Open Source Project | 2  * Copyright 2015 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 #include "SkData.h" | 8 #include "SkData.h" | 
| 9 #include "SkImageDecoder.h" | 9 #include "SkImageDecoder.h" | 
| 10 #include "SkImageGenerator.h" | 10 #include "SkImageGenerator.h" | 
| (...skipping 28 matching lines...) Expand all  Loading... | 
| 39 | 39 | 
| 40 public: | 40 public: | 
| 41     SkImageDecoderGenerator(const SkImageInfo& info, SkImageDecoder* decoder, Sk
     Data* data) | 41     SkImageDecoderGenerator(const SkImageInfo& info, SkImageDecoder* decoder, Sk
     Data* data) | 
| 42         : INHERITED(info), fInfo(info), fDecoder(decoder), fData(SkRef(data)) | 42         : INHERITED(info), fInfo(info), fDecoder(decoder), fData(SkRef(data)) | 
| 43     {} | 43     {} | 
| 44 | 44 | 
| 45 protected: | 45 protected: | 
| 46     SkData* onRefEncodedData() override { | 46     SkData* onRefEncodedData() override { | 
| 47         return SkRef(fData.get()); | 47         return SkRef(fData.get()); | 
| 48     } | 48     } | 
| 49 | 49 #ifdef SK_LEGACY_IMAGE_GENERATOR_ENUMS_AND_OPTIONS | 
| 50     virtual Result onGetPixels(const SkImageInfo& info, void* pixels, size_t row
     Bytes, | 50     Result onGetPixels(const SkImageInfo& info, void* pixels, size_t rowBytes, | 
| 51                                const Options&, | 51                        const Options&, | 
| 52                                SkPMColor ctableEntries[], int* ctableCount) over
     ride { | 52                        SkPMColor ctableEntries[], int* ctableCount) override { | 
|  | 53 #else | 
|  | 54     bool onGetPixels(const SkImageInfo& info, void* pixels, size_t rowBytes, | 
|  | 55                      SkPMColor ctableEntries[], int* ctableCount) override { | 
|  | 56 #endif | 
| 53         SkMemoryStream stream(fData->data(), fData->size(), false); | 57         SkMemoryStream stream(fData->data(), fData->size(), false); | 
| 54         SkAutoTUnref<BareMemoryAllocator> allocator(SkNEW_ARGS(BareMemoryAllocat
     or, | 58         SkAutoTUnref<BareMemoryAllocator> allocator(SkNEW_ARGS(BareMemoryAllocat
     or, | 
| 55                                                                (info, pixels, ro
     wBytes))); | 59                                                                (info, pixels, ro
     wBytes))); | 
| 56         fDecoder->setAllocator(allocator); | 60         fDecoder->setAllocator(allocator); | 
| 57         fDecoder->setRequireUnpremultipliedColors(kUnpremul_SkAlphaType == info.
     alphaType()); | 61         fDecoder->setRequireUnpremultipliedColors(kUnpremul_SkAlphaType == info.
     alphaType()); | 
| 58 | 62 | 
| 59         SkBitmap bm; | 63         SkBitmap bm; | 
| 60         const SkImageDecoder::Result result = fDecoder->decode(&stream, &bm, inf
     o.colorType(), | 64         const SkImageDecoder::Result result = fDecoder->decode(&stream, &bm, inf
     o.colorType(), | 
| 61                                                                SkImageDecoder::k
     DecodePixels_Mode); | 65                                                                SkImageDecoder::k
     DecodePixels_Mode); | 
| 62         if (SkImageDecoder::kFailure == result) { | 66         if (SkImageDecoder::kFailure == result) { | 
|  | 67 #ifdef SK_LEGACY_IMAGE_GENERATOR_ENUMS_AND_OPTIONS | 
| 63             return kInvalidInput; | 68             return kInvalidInput; | 
|  | 69 #else | 
|  | 70             return false; | 
|  | 71 #endif | 
| 64         } | 72         } | 
| 65 | 73 | 
| 66         SkASSERT(info.colorType() == bm.info().colorType()); | 74         SkASSERT(info.colorType() == bm.info().colorType()); | 
| 67 | 75 | 
| 68         if (kIndex_8_SkColorType == info.colorType()) { | 76         if (kIndex_8_SkColorType == info.colorType()) { | 
| 69             SkASSERT(ctableEntries); | 77             SkASSERT(ctableEntries); | 
| 70 | 78 | 
| 71             SkColorTable* ctable = bm.getColorTable(); | 79             SkColorTable* ctable = bm.getColorTable(); | 
| 72             if (NULL == ctable) { | 80             if (NULL == ctable) { | 
|  | 81 #ifdef SK_LEGACY_IMAGE_GENERATOR_ENUMS_AND_OPTIONS | 
| 73                 return kInvalidConversion; | 82                 return kInvalidConversion; | 
|  | 83 #else | 
|  | 84                 return false; | 
|  | 85 #endif | 
| 74             } | 86             } | 
| 75             const int count = ctable->count(); | 87             const int count = ctable->count(); | 
| 76             memcpy(ctableEntries, ctable->readColors(), count * sizeof(SkPMColor
     )); | 88             memcpy(ctableEntries, ctable->readColors(), count * sizeof(SkPMColor
     )); | 
| 77             *ctableCount = count; | 89             *ctableCount = count; | 
| 78         } | 90         } | 
|  | 91 #ifdef SK_LEGACY_IMAGE_GENERATOR_ENUMS_AND_OPTIONS | 
| 79         if (SkImageDecoder::kPartialSuccess == result) { | 92         if (SkImageDecoder::kPartialSuccess == result) { | 
| 80             return kIncompleteInput; | 93             return kIncompleteInput; | 
| 81         } | 94         } | 
| 82         return kSuccess; | 95         return kSuccess; | 
|  | 96 #else | 
|  | 97         return true; | 
|  | 98 #endif | 
| 83     } | 99     } | 
| 84 | 100 | 
| 85     bool onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBytes[3], | 101     bool onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBytes[3], | 
| 86                          SkYUVColorSpace* colorSpace) override { | 102                          SkYUVColorSpace* colorSpace) override { | 
| 87         SkMemoryStream stream(fData->data(), fData->size(), false); | 103         SkMemoryStream stream(fData->data(), fData->size(), false); | 
| 88         return fDecoder->decodeYUV8Planes(&stream, sizes, planes, rowBytes, colo
     rSpace); | 104         return fDecoder->decodeYUV8Planes(&stream, sizes, planes, rowBytes, colo
     rSpace); | 
| 89     } | 105     } | 
| 90 | 106 | 
| 91 private: | 107 private: | 
| 92     typedef SkImageGenerator INHERITED; | 108     typedef SkImageGenerator INHERITED; | 
| (...skipping 12 matching lines...) Expand all  Loading... | 
| 105 | 121 | 
| 106     SkBitmap bm; | 122     SkBitmap bm; | 
| 107     stream.rewind(); | 123     stream.rewind(); | 
| 108     if (!decoder->decode(&stream, &bm, kUnknown_SkColorType, SkImageDecoder::kDe
     codeBounds_Mode)) { | 124     if (!decoder->decode(&stream, &bm, kUnknown_SkColorType, SkImageDecoder::kDe
     codeBounds_Mode)) { | 
| 109         SkDELETE(decoder); | 125         SkDELETE(decoder); | 
| 110         return NULL; | 126         return NULL; | 
| 111     } | 127     } | 
| 112 | 128 | 
| 113     return SkNEW_ARGS(SkImageDecoderGenerator, (bm.info(), decoder, data)); | 129     return SkNEW_ARGS(SkImageDecoderGenerator, (bm.info(), decoder, data)); | 
| 114 } | 130 } | 
| OLD | NEW | 
|---|