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" |
11 #include "SkStream.h" | 11 #include "SkStream.h" |
12 | 12 |
13 class BareMemoryAllocator : public SkBitmap::Allocator { | 13 class BareMemoryAllocator : public SkBitmap::Allocator { |
14 const SkImageInfo fInfo; | 14 const SkImageInfo fInfo; |
15 void* const fMemory; | 15 void* const fMemory; |
16 const size_t fRowBytes; | 16 const size_t fRowBytes; |
17 | 17 |
18 public: | 18 public: |
19 BareMemoryAllocator(const SkImageInfo& info, void* memory, size_t rowBytes) | 19 BareMemoryAllocator(const SkImageInfo& info, void* memory, size_t rowBytes) |
20 : fInfo(info), fMemory(memory), fRowBytes(rowBytes) | 20 : fInfo(info), fMemory(memory), fRowBytes(rowBytes) |
21 {} | 21 {} |
22 | 22 |
23 protected: | 23 protected: |
24 bool allocPixelRef(SkBitmap* bm, SkColorTable* ctable) SK_OVERRIDE { | 24 bool allocPixelRef(SkBitmap* bm, SkColorTable* ctable) override { |
25 const SkImageInfo bmi = bm->info(); | 25 const SkImageInfo bmi = bm->info(); |
26 if (bmi.width() != fInfo.width() || bmi.height() != fInfo.height() || | 26 if (bmi.width() != fInfo.width() || bmi.height() != fInfo.height() || |
27 bmi.colorType() != fInfo.colorType()) | 27 bmi.colorType() != fInfo.colorType()) |
28 { | 28 { |
29 return false; | 29 return false; |
30 } | 30 } |
31 return bm->installPixels(bmi, fMemory, fRowBytes, ctable, NULL, NULL); | 31 return bm->installPixels(bmi, fMemory, fRowBytes, ctable, NULL, NULL); |
32 } | 32 } |
33 }; | 33 }; |
34 | 34 |
35 class SkImageDecoderGenerator : public SkImageGenerator { | 35 class SkImageDecoderGenerator : public SkImageGenerator { |
36 const SkImageInfo fInfo; | 36 const SkImageInfo fInfo; |
37 SkAutoTDelete<SkImageDecoder> fDecoder; | 37 SkAutoTDelete<SkImageDecoder> fDecoder; |
38 SkAutoTUnref<SkData> fData; | 38 SkAutoTUnref<SkData> fData; |
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() SK_OVERRIDE { | 46 SkData* onRefEncodedData() override { |
47 return SkRef(fData.get()); | 47 return SkRef(fData.get()); |
48 } | 48 } |
49 | 49 |
50 #ifdef SK_SUPPORT_LEGACY_BOOL_ONGETINFO | 50 #ifdef SK_SUPPORT_LEGACY_BOOL_ONGETINFO |
51 virtual bool onGetInfo(SkImageInfo* info) SK_OVERRIDE { | 51 virtual bool onGetInfo(SkImageInfo* info) override { |
52 *info = fInfo; | 52 *info = fInfo; |
53 return true; | 53 return true; |
54 } | 54 } |
55 #endif | 55 #endif |
56 | 56 |
57 virtual Result onGetPixels(const SkImageInfo& info, void* pixels, size_t row
Bytes, | 57 virtual Result onGetPixels(const SkImageInfo& info, void* pixels, size_t row
Bytes, |
58 const Options&, | 58 const Options&, |
59 SkPMColor ctableEntries[], int* ctableCount) SK_O
VERRIDE { | 59 SkPMColor ctableEntries[], int* ctableCount) over
ride { |
60 SkMemoryStream stream(fData->data(), fData->size(), false); | 60 SkMemoryStream stream(fData->data(), fData->size(), false); |
61 SkAutoTUnref<BareMemoryAllocator> allocator(SkNEW_ARGS(BareMemoryAllocat
or, | 61 SkAutoTUnref<BareMemoryAllocator> allocator(SkNEW_ARGS(BareMemoryAllocat
or, |
62 (info, pixels, ro
wBytes))); | 62 (info, pixels, ro
wBytes))); |
63 fDecoder->setAllocator(allocator); | 63 fDecoder->setAllocator(allocator); |
64 fDecoder->setRequireUnpremultipliedColors(kUnpremul_SkAlphaType == info.
alphaType()); | 64 fDecoder->setRequireUnpremultipliedColors(kUnpremul_SkAlphaType == info.
alphaType()); |
65 | 65 |
66 SkBitmap bm; | 66 SkBitmap bm; |
67 const SkImageDecoder::Result result = fDecoder->decode(&stream, &bm, inf
o.colorType(), | 67 const SkImageDecoder::Result result = fDecoder->decode(&stream, &bm, inf
o.colorType(), |
68 SkImageDecoder::k
DecodePixels_Mode); | 68 SkImageDecoder::k
DecodePixels_Mode); |
69 if (SkImageDecoder::kFailure == result) { | 69 if (SkImageDecoder::kFailure == result) { |
(...skipping 13 matching lines...) Expand all Loading... |
83 memcpy(ctableEntries, ctable->readColors(), count * sizeof(SkPMColor
)); | 83 memcpy(ctableEntries, ctable->readColors(), count * sizeof(SkPMColor
)); |
84 *ctableCount = count; | 84 *ctableCount = count; |
85 } | 85 } |
86 if (SkImageDecoder::kPartialSuccess == result) { | 86 if (SkImageDecoder::kPartialSuccess == result) { |
87 return kIncompleteInput; | 87 return kIncompleteInput; |
88 } | 88 } |
89 return kSuccess; | 89 return kSuccess; |
90 } | 90 } |
91 | 91 |
92 bool onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBytes[3], | 92 bool onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBytes[3], |
93 SkYUVColorSpace* colorSpace) SK_OVERRIDE { | 93 SkYUVColorSpace* colorSpace) override { |
94 SkMemoryStream stream(fData->data(), fData->size(), false); | 94 SkMemoryStream stream(fData->data(), fData->size(), false); |
95 return fDecoder->decodeYUV8Planes(&stream, sizes, planes, rowBytes, colo
rSpace); | 95 return fDecoder->decodeYUV8Planes(&stream, sizes, planes, rowBytes, colo
rSpace); |
96 } | 96 } |
97 | 97 |
98 private: | 98 private: |
99 typedef SkImageGenerator INHERITED; | 99 typedef SkImageGenerator INHERITED; |
100 }; | 100 }; |
101 | 101 |
102 SkImageGenerator* SkImageGenerator::NewFromData(SkData* data) { | 102 SkImageGenerator* SkImageGenerator::NewFromData(SkData* data) { |
103 if (NULL == data) { | 103 if (NULL == data) { |
104 return NULL; | 104 return NULL; |
105 } | 105 } |
106 | 106 |
107 SkMemoryStream stream(data->data(), data->size(), false); | 107 SkMemoryStream stream(data->data(), data->size(), false); |
108 SkImageDecoder* decoder = SkImageDecoder::Factory(&stream); | 108 SkImageDecoder* decoder = SkImageDecoder::Factory(&stream); |
109 if (NULL == decoder) { | 109 if (NULL == decoder) { |
110 return NULL; | 110 return NULL; |
111 } | 111 } |
112 | 112 |
113 SkBitmap bm; | 113 SkBitmap bm; |
114 stream.rewind(); | 114 stream.rewind(); |
115 if (!decoder->decode(&stream, &bm, kUnknown_SkColorType, SkImageDecoder::kDe
codeBounds_Mode)) { | 115 if (!decoder->decode(&stream, &bm, kUnknown_SkColorType, SkImageDecoder::kDe
codeBounds_Mode)) { |
116 SkDELETE(decoder); | 116 SkDELETE(decoder); |
117 return NULL; | 117 return NULL; |
118 } | 118 } |
119 | 119 |
120 return SkNEW_ARGS(SkImageDecoderGenerator, (bm.info(), decoder, data)); | 120 return SkNEW_ARGS(SkImageDecoderGenerator, (bm.info(), decoder, data)); |
121 } | 121 } |
OLD | NEW |