OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
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 "SkBitmap.h" | 8 #include "SkBitmap.h" |
9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
10 #include "SkConfig8888.h" | 10 #include "SkConfig8888.h" |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 for (int x = 0; x < w; ++x) { | 160 for (int x = 0; x < w; ++x) { |
161 uint32_t s = src32[x]; | 161 uint32_t s = src32[x]; |
162 dst8[x] = SkComputeLuminance(s & 0xFF, (s >> 8) & 0xFF, (s >> 16
) & 0xFF); | 162 dst8[x] = SkComputeLuminance(s & 0xFF, (s >> 8) & 0xFF, (s >> 16
) & 0xFF); |
163 } | 163 } |
164 } | 164 } |
165 src32 = (const uint32_t*)((const char*)src32 + srcRB); | 165 src32 = (const uint32_t*)((const char*)src32 + srcRB); |
166 dst8 += dstRB; | 166 dst8 += dstRB; |
167 } | 167 } |
168 } | 168 } |
169 | 169 |
| 170 static bool extract_alpha(void* dst, size_t dstRB, const void* src, size_t srcRB
, |
| 171 const SkImageInfo& srcInfo, SkColorTable* ctable) { |
| 172 uint8_t* SK_RESTRICT dst8 = (uint8_t*)dst; |
| 173 |
| 174 const int w = srcInfo.width(); |
| 175 const int h = srcInfo.height(); |
| 176 if (srcInfo.isOpaque()) { |
| 177 // src is opaque, so just fill alpha with 0xFF |
| 178 for (int y = 0; y < h; ++y) { |
| 179 memset(dst8, 0xFF, w); |
| 180 dst8 += dstRB; |
| 181 } |
| 182 return true; |
| 183 } |
| 184 switch (srcInfo.colorType()) { |
| 185 case kN32_SkColorType: { |
| 186 const SkPMColor* SK_RESTRICT src32 = (const SkPMColor*)src; |
| 187 for (int y = 0; y < h; ++y) { |
| 188 for (int x = 0; x < w; ++x) { |
| 189 dst8[x] = SkGetPackedA32(src32[x]); |
| 190 } |
| 191 dst8 += dstRB; |
| 192 src32 = (const SkPMColor*)((const char*)src32 + srcRB); |
| 193 } |
| 194 break; |
| 195 } |
| 196 case kARGB_4444_SkColorType: { |
| 197 const SkPMColor16* SK_RESTRICT src16 = (const SkPMColor16*)src; |
| 198 for (int y = 0; y < h; ++y) { |
| 199 for (int x = 0; x < w; ++x) { |
| 200 dst8[x] = SkPacked4444ToA32(src16[x]); |
| 201 } |
| 202 dst8 += dstRB; |
| 203 src16 = (const SkPMColor16*)((const char*)src16 + srcRB); |
| 204 } |
| 205 break; |
| 206 } |
| 207 case kIndex_8_SkColorType: { |
| 208 if (nullptr == ctable) { |
| 209 return false; |
| 210 } |
| 211 const SkPMColor* SK_RESTRICT table = ctable->readColors(); |
| 212 const uint8_t* SK_RESTRICT src8 = (const uint8_t*)src; |
| 213 for (int y = 0; y < h; ++y) { |
| 214 for (int x = 0; x < w; ++x) { |
| 215 dst8[x] = SkGetPackedA32(table[src8[x]]); |
| 216 } |
| 217 dst8 += dstRB; |
| 218 src8 += srcRB; |
| 219 } |
| 220 break; |
| 221 } |
| 222 default: |
| 223 return false; |
| 224 } |
| 225 return true; |
| 226 } |
| 227 |
170 bool SkPixelInfo::CopyPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t
dstRB, | 228 bool SkPixelInfo::CopyPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t
dstRB, |
171 const SkImageInfo& srcInfo, const void* srcPixels,
size_t srcRB, | 229 const SkImageInfo& srcInfo, const void* srcPixels,
size_t srcRB, |
172 SkColorTable* ctable) { | 230 SkColorTable* ctable) { |
173 if (srcInfo.dimensions() != dstInfo.dimensions()) { | 231 if (srcInfo.dimensions() != dstInfo.dimensions()) { |
174 return false; | 232 return false; |
175 } | 233 } |
176 | 234 |
177 const int width = srcInfo.width(); | 235 const int width = srcInfo.width(); |
178 const int height = srcInfo.height(); | 236 const int height = srcInfo.height(); |
179 | 237 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 | 292 |
235 if (kGray_8_SkColorType == srcInfo.colorType() && 4 == dstInfo.bytesPerPixel
()) { | 293 if (kGray_8_SkColorType == srcInfo.colorType() && 4 == dstInfo.bytesPerPixel
()) { |
236 copy_g8_to_32(dstPixels, dstRB, srcPixels, srcRB, width, height); | 294 copy_g8_to_32(dstPixels, dstRB, srcPixels, srcRB, width, height); |
237 return true; | 295 return true; |
238 } | 296 } |
239 if (kGray_8_SkColorType == dstInfo.colorType() && 4 == srcInfo.bytesPerPixel
()) { | 297 if (kGray_8_SkColorType == dstInfo.colorType() && 4 == srcInfo.bytesPerPixel
()) { |
240 copy_32_to_g8(dstPixels, dstRB, srcPixels, srcRB, srcInfo); | 298 copy_32_to_g8(dstPixels, dstRB, srcPixels, srcRB, srcInfo); |
241 return true; | 299 return true; |
242 } | 300 } |
243 | 301 |
| 302 if (kAlpha_8_SkColorType == dstInfo.colorType() && |
| 303 extract_alpha(dstPixels, dstRB, srcPixels, srcRB, srcInfo, ctable)) { |
| 304 return true; |
| 305 } |
| 306 |
244 // Can no longer draw directly into 4444, but we can manually whack it for a
few combinations | 307 // Can no longer draw directly into 4444, but we can manually whack it for a
few combinations |
245 if (kARGB_4444_SkColorType == dstInfo.colorType() && | 308 if (kARGB_4444_SkColorType == dstInfo.colorType() && |
246 (kN32_SkColorType == srcInfo.colorType() || kIndex_8_SkColorType == srcI
nfo.colorType())) { | 309 (kN32_SkColorType == srcInfo.colorType() || kIndex_8_SkColorType == srcI
nfo.colorType())) { |
247 if (srcInfo.alphaType() == kUnpremul_SkAlphaType) { | 310 if (srcInfo.alphaType() == kUnpremul_SkAlphaType) { |
248 // Our method for converting to 4444 assumes premultiplied. | 311 // Our method for converting to 4444 assumes premultiplied. |
249 return false; | 312 return false; |
250 } | 313 } |
251 | 314 |
252 const SkPMColor* table = nullptr; | 315 const SkPMColor* table = nullptr; |
253 if (kIndex_8_SkColorType == srcInfo.colorType()) { | 316 if (kIndex_8_SkColorType == srcInfo.colorType()) { |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 } | 360 } |
298 | 361 |
299 SkPaint paint; | 362 SkPaint paint; |
300 paint.setDither(true); | 363 paint.setDither(true); |
301 | 364 |
302 canvas->clear(0); | 365 canvas->clear(0); |
303 canvas->drawBitmap(bm, 0, 0, &paint); | 366 canvas->drawBitmap(bm, 0, 0, &paint); |
304 return true; | 367 return true; |
305 } | 368 } |
306 } | 369 } |
OLD | NEW |