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" |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 return false; | 116 return false; |
117 } | 117 } |
118 } | 118 } |
119 | 119 |
120 // we don't need this anymore, so free it now (before we try to allocate | 120 // 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 | 121 // the bitmap's pixels) rather than waiting for its destructor |
122 storage.free(); | 122 storage.free(); |
123 | 123 |
124 int width = callback.width(); | 124 int width = callback.width(); |
125 int height = callback.height(); | 125 int height = callback.height(); |
126 SkBitmap::Config config = this->getPrefConfig(k32Bit_SrcDepth, false); | 126 SkColorType colorType = this->getPrefColorType(k32Bit_SrcDepth, false); |
127 | 127 |
128 // only accept prefConfig if it makes sense for us | 128 // only accept prefConfig if it makes sense for us |
129 if (SkBitmap::kARGB_4444_Config != config && | 129 if (kARGB_4444_SkColorType != colorType && kRGB_565_SkColorType != colorType
) { |
130 SkBitmap::kRGB_565_Config != config) { | 130 colorType = kN32_SkColorType; |
131 config = SkBitmap::kARGB_8888_Config; | |
132 } | 131 } |
133 | 132 |
134 SkScaledBitmapSampler sampler(width, height, getSampleSize()); | 133 SkScaledBitmapSampler sampler(width, height, getSampleSize()); |
135 | 134 |
136 bm->setConfig(config, sampler.scaledWidth(), sampler.scaledHeight(), 0, | 135 bm->setInfo(SkImageInfo::Make(sampler.scaledWidth(), sampler.scaledHeight(), |
137 kOpaque_SkAlphaType); | 136 colorType, kOpaque_SkAlphaType)); |
138 | 137 |
139 if (justBounds) { | 138 if (justBounds) { |
140 return true; | 139 return true; |
141 } | 140 } |
142 | 141 |
143 if (!this->allocPixelRef(bm, NULL)) { | 142 if (!this->allocPixelRef(bm, NULL)) { |
144 return false; | 143 return false; |
145 } | 144 } |
146 | 145 |
147 SkAutoLockPixels alp(*bm); | 146 SkAutoLockPixels alp(*bm); |
148 | 147 |
149 if (!sampler.begin(bm, SkScaledBitmapSampler::kRGB, *this)) { | 148 if (!sampler.begin(bm, SkScaledBitmapSampler::kRGB, *this)) { |
150 return false; | 149 return false; |
151 } | 150 } |
152 | 151 |
153 const int srcRowBytes = width * 3; | 152 const int srcRowBytes = width * 3; |
154 const int dstHeight = sampler.scaledHeight(); | 153 const int dstHeight = sampler.scaledHeight(); |
155 const uint8_t* srcRow = callback.rgb(); | 154 const uint8_t* srcRow = callback.rgb(); |
156 | 155 |
157 srcRow += sampler.srcY0() * srcRowBytes; | 156 srcRow += sampler.srcY0() * srcRowBytes; |
158 for (int y = 0; y < dstHeight; y++) { | 157 for (int y = 0; y < dstHeight; y++) { |
159 sampler.next(srcRow); | 158 sampler.next(srcRow); |
160 srcRow += sampler.srcDY() * srcRowBytes; | 159 srcRow += sampler.srcDY() * srcRowBytes; |
161 } | 160 } |
162 return true; | 161 return true; |
163 } | 162 } |
OLD | NEW |