OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2007 The Android Open Source Project | 3 * Copyright 2007 The Android Open Source Project |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 | 9 |
10 #include "bmpdecoderhelper.h" | 10 #include "bmpdecoderhelper.h" |
11 #include "SkColorPriv.h" | 11 #include "SkColorPriv.h" |
| 12 #include "SkData.h" |
12 #include "SkImageDecoder.h" | 13 #include "SkImageDecoder.h" |
13 #include "SkScaledBitmapSampler.h" | 14 #include "SkScaledBitmapSampler.h" |
14 #include "SkStream.h" | 15 #include "SkStream.h" |
15 #include "SkStreamPriv.h" | 16 #include "SkStreamPriv.h" |
16 #include "SkTDArray.h" | 17 #include "SkTDArray.h" |
17 | 18 |
18 class SkBMPImageDecoder : public SkImageDecoder { | 19 class SkBMPImageDecoder : public SkImageDecoder { |
19 public: | 20 public: |
20 SkBMPImageDecoder() {} | 21 SkBMPImageDecoder() {} |
21 | 22 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 SkTDArray<uint8_t> fRGB; | 90 SkTDArray<uint8_t> fRGB; |
90 int fWidth; | 91 int fWidth; |
91 int fHeight; | 92 int fHeight; |
92 bool fJustBounds; | 93 bool fJustBounds; |
93 }; | 94 }; |
94 | 95 |
95 SkImageDecoder::Result SkBMPImageDecoder::onDecode(SkStream* stream, SkBitmap* b
m, Mode mode) { | 96 SkImageDecoder::Result SkBMPImageDecoder::onDecode(SkStream* stream, SkBitmap* b
m, Mode mode) { |
96 // First read the entire stream, so that all of the data can be passed to | 97 // First read the entire stream, so that all of the data can be passed to |
97 // the BmpDecoderHelper. | 98 // the BmpDecoderHelper. |
98 | 99 |
99 // Allocated space used to hold the data. | 100 SkAutoTUnref<SkData> data(SkCopyStreamToData(stream)); |
100 SkAutoMalloc storage; | 101 if (!data) { |
| 102 return kFailure; |
| 103 } |
| 104 |
101 // Byte length of all of the data. | 105 // Byte length of all of the data. |
102 const size_t length = SkCopyStreamToStorage(&storage, stream); | 106 const size_t length = data->size(); |
103 if (0 == length) { | 107 if (0 == length) { |
104 return kFailure; | 108 return kFailure; |
105 } | 109 } |
106 | 110 |
107 const bool justBounds = SkImageDecoder::kDecodeBounds_Mode == mode; | 111 const bool justBounds = SkImageDecoder::kDecodeBounds_Mode == mode; |
108 SkBmpDecoderCallback callback(justBounds); | 112 SkBmpDecoderCallback callback(justBounds); |
109 | 113 |
110 // Now decode the BMP into callback's rgb() array [r,g,b, r,g,b, ...] | 114 // Now decode the BMP into callback's rgb() array [r,g,b, r,g,b, ...] |
111 { | 115 { |
112 image_codec::BmpDecoderHelper helper; | 116 image_codec::BmpDecoderHelper helper; |
113 const int max_pixels = 16383*16383; // max width*height | 117 const int max_pixels = 16383*16383; // max width*height |
114 if (!helper.DecodeImage((const char*)storage.get(), length, | 118 if (!helper.DecodeImage((const char*) data->data(), length, |
115 max_pixels, &callback)) { | 119 max_pixels, &callback)) { |
116 return kFailure; | 120 return kFailure; |
117 } | 121 } |
118 } | 122 } |
119 | 123 |
120 // we don't need this anymore, so free it now (before we try to allocate | 124 // we don't need this anymore, so free it now (before we try to allocate |
121 // the bitmap's pixels) rather than waiting for its destructor | 125 // the bitmap's pixels) rather than waiting for its destructor |
122 storage.free(); | 126 data.reset(nullptr); |
123 | 127 |
124 int width = callback.width(); | 128 int width = callback.width(); |
125 int height = callback.height(); | 129 int height = callback.height(); |
126 SkColorType colorType = this->getPrefColorType(k32Bit_SrcDepth, false); | 130 SkColorType colorType = this->getPrefColorType(k32Bit_SrcDepth, false); |
127 | 131 |
128 // only accept prefConfig if it makes sense for us | 132 // only accept prefConfig if it makes sense for us |
129 if (kARGB_4444_SkColorType != colorType && kRGB_565_SkColorType != colorType
) { | 133 if (kARGB_4444_SkColorType != colorType && kRGB_565_SkColorType != colorType
) { |
130 colorType = kN32_SkColorType; | 134 colorType = kN32_SkColorType; |
131 } | 135 } |
132 | 136 |
(...skipping 20 matching lines...) Expand all Loading... |
153 const int dstHeight = sampler.scaledHeight(); | 157 const int dstHeight = sampler.scaledHeight(); |
154 const uint8_t* srcRow = callback.rgb(); | 158 const uint8_t* srcRow = callback.rgb(); |
155 | 159 |
156 srcRow += sampler.srcY0() * srcRowBytes; | 160 srcRow += sampler.srcY0() * srcRowBytes; |
157 for (int y = 0; y < dstHeight; y++) { | 161 for (int y = 0; y < dstHeight; y++) { |
158 sampler.next(srcRow); | 162 sampler.next(srcRow); |
159 srcRow += sampler.srcDY() * srcRowBytes; | 163 srcRow += sampler.srcDY() * srcRowBytes; |
160 } | 164 } |
161 return kSuccess; | 165 return kSuccess; |
162 } | 166 } |
OLD | NEW |