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 10 matching lines...) Expand all Loading... |
21 {} | 21 {} |
22 | 22 |
23 protected: | 23 protected: |
24 bool allocPixelRef(SkBitmap* bm, SkColorTable* ctable) 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, nullptr, nullp
tr); |
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) |
(...skipping 18 matching lines...) Expand all Loading... |
60 if (SkImageDecoder::kFailure == result) { | 60 if (SkImageDecoder::kFailure == result) { |
61 return false; | 61 return false; |
62 } | 62 } |
63 | 63 |
64 SkASSERT(info.colorType() == bm.info().colorType()); | 64 SkASSERT(info.colorType() == bm.info().colorType()); |
65 | 65 |
66 if (kIndex_8_SkColorType == info.colorType()) { | 66 if (kIndex_8_SkColorType == info.colorType()) { |
67 SkASSERT(ctableEntries); | 67 SkASSERT(ctableEntries); |
68 | 68 |
69 SkColorTable* ctable = bm.getColorTable(); | 69 SkColorTable* ctable = bm.getColorTable(); |
70 if (NULL == ctable) { | 70 if (nullptr == ctable) { |
71 return false; | 71 return false; |
72 } | 72 } |
73 const int count = ctable->count(); | 73 const int count = ctable->count(); |
74 memcpy(ctableEntries, ctable->readColors(), count * sizeof(SkPMColor
)); | 74 memcpy(ctableEntries, ctable->readColors(), count * sizeof(SkPMColor
)); |
75 *ctableCount = count; | 75 *ctableCount = count; |
76 } | 76 } |
77 return true; | 77 return true; |
78 } | 78 } |
79 | 79 |
80 bool onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBytes[3], | 80 bool onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBytes[3], |
81 SkYUVColorSpace* colorSpace) override { | 81 SkYUVColorSpace* colorSpace) override { |
82 SkMemoryStream stream(fData->data(), fData->size(), false); | 82 SkMemoryStream stream(fData->data(), fData->size(), false); |
83 return fDecoder->decodeYUV8Planes(&stream, sizes, planes, rowBytes, colo
rSpace); | 83 return fDecoder->decodeYUV8Planes(&stream, sizes, planes, rowBytes, colo
rSpace); |
84 } | 84 } |
85 | 85 |
86 private: | 86 private: |
87 typedef SkImageGenerator INHERITED; | 87 typedef SkImageGenerator INHERITED; |
88 }; | 88 }; |
89 | 89 |
90 SkImageGenerator* SkImageGenerator::NewFromEncodedImpl(SkData* data) { | 90 SkImageGenerator* SkImageGenerator::NewFromEncodedImpl(SkData* data) { |
91 SkMemoryStream stream(data->data(), data->size(), false); | 91 SkMemoryStream stream(data->data(), data->size(), false); |
92 SkImageDecoder* decoder = SkImageDecoder::Factory(&stream); | 92 SkImageDecoder* decoder = SkImageDecoder::Factory(&stream); |
93 if (NULL == decoder) { | 93 if (nullptr == decoder) { |
94 return NULL; | 94 return nullptr; |
95 } | 95 } |
96 | 96 |
97 SkBitmap bm; | 97 SkBitmap bm; |
98 stream.rewind(); | 98 stream.rewind(); |
99 if (!decoder->decode(&stream, &bm, kUnknown_SkColorType, SkImageDecoder::kDe
codeBounds_Mode)) { | 99 if (!decoder->decode(&stream, &bm, kUnknown_SkColorType, SkImageDecoder::kDe
codeBounds_Mode)) { |
100 delete decoder; | 100 delete decoder; |
101 return NULL; | 101 return nullptr; |
102 } | 102 } |
103 | 103 |
104 return new SkImageDecoderGenerator(bm.info(), decoder, data); | 104 return new SkImageDecoderGenerator(bm.info(), decoder, data); |
105 } | 105 } |
OLD | NEW |