Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(217)

Side by Side Diff: src/codec/SkBmpRLECodec.cpp

Issue 1277213002: Support more swizzles to 565 in SkCodec (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Update new 565 swizzling functions for scaling Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright 2015 Google Inc. 2 * Copyright 2015 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 "SkBmpRLECodec.h" 8 #include "SkBmpRLECodec.h"
9 #include "SkCodecPriv.h" 9 #include "SkCodecPriv.h"
10 #include "SkColorPriv.h" 10 #include "SkColorPriv.h"
11 #include "SkScanlineDecoder.h" 11 #include "SkScanlineDecoder.h"
12 #include "SkStream.h" 12 #include "SkStream.h"
13 13
14 /* 14 /*
15 * Checks if the conversion between the input image and the requested output
16 * image has been implemented
17 */
18 static bool conversion_possible(const SkImageInfo& dst,
19 const SkImageInfo& src) {
20 // Ensure that the profile type is unchanged
21 if (dst.profileType() != src.profileType()) {
22 return false;
23 }
24
25 // Ensure the alpha type is valid
26 if (!valid_alpha(dst.alphaType(), src.alphaType())) {
27 return false;
28 }
29
30 // Check for supported color types
31 switch (dst.colorType()) {
32 // Allow output to kN32 from any type of input
33 case kN32_SkColorType:
34 return true;
35 // Allow output to kIndex_8 from compatible inputs
36 case kIndex_8_SkColorType:
37 return kIndex_8_SkColorType == src.colorType();
38 default:
39 return false;
40 }
41 }
42
43 /*
44 * Creates an instance of the decoder 15 * Creates an instance of the decoder
45 * Called only by NewFromStream 16 * Called only by NewFromStream
46 */ 17 */
47 SkBmpRLECodec::SkBmpRLECodec(const SkImageInfo& info, SkStream* stream, 18 SkBmpRLECodec::SkBmpRLECodec(const SkImageInfo& info, SkStream* stream,
48 uint16_t bitsPerPixel, uint32_t numColors, 19 uint16_t bitsPerPixel, uint32_t numColors,
49 uint32_t bytesPerColor, uint32_t offset, 20 uint32_t bytesPerColor, uint32_t offset,
50 SkBmpCodec::RowOrder rowOrder, size_t RLEBytes) 21 SkBmpCodec::RowOrder rowOrder, size_t RLEBytes)
51 : INHERITED(info, stream, bitsPerPixel, rowOrder) 22 : INHERITED(info, stream, bitsPerPixel, rowOrder)
52 , fColorTable(NULL) 23 , fColorTable(NULL)
53 , fNumColors(this->computeNumColors(numColors)) 24 , fNumColors(this->computeNumColors(numColors))
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 } 204 }
234 205
235 // Set the pixel based on destination color type 206 // Set the pixel based on destination color type
236 switch (dstInfo.colorType()) { 207 switch (dstInfo.colorType()) {
237 case kN32_SkColorType: { 208 case kN32_SkColorType: {
238 SkPMColor* dstRow = SkTAddOffset<SkPMColor>((SkPMColor*) dst, 209 SkPMColor* dstRow = SkTAddOffset<SkPMColor>((SkPMColor*) dst,
239 row * (int) dstRowBytes); 210 row * (int) dstRowBytes);
240 dstRow[x] = fColorTable->operator[](index); 211 dstRow[x] = fColorTable->operator[](index);
241 break; 212 break;
242 } 213 }
214 case kRGB_565_SkColorType: {
215 uint16_t* dstRow = SkTAddOffset<uint16_t>(dst, row * (int) dstRowByt es);
216 dstRow[x] = SkPixel32ToPixel16(fColorTable->operator[](index));
217 break;
218 }
243 default: 219 default:
244 // This case should not be reached. We should catch an invalid 220 // This case should not be reached. We should catch an invalid
245 // color type when we check that the conversion is possible. 221 // color type when we check that the conversion is possible.
246 SkASSERT(false); 222 SkASSERT(false);
247 break; 223 break;
248 } 224 }
249 } 225 }
250 226
251 /* 227 /*
252 * Set an RLE pixel from R, G, B values 228 * Set an RLE pixel from R, G, B values
(...skipping 12 matching lines...) Expand all
265 } 241 }
266 242
267 // Set the pixel based on destination color type 243 // Set the pixel based on destination color type
268 switch (dstInfo.colorType()) { 244 switch (dstInfo.colorType()) {
269 case kN32_SkColorType: { 245 case kN32_SkColorType: {
270 SkPMColor* dstRow = SkTAddOffset<SkPMColor>((SkPMColor*) dst, 246 SkPMColor* dstRow = SkTAddOffset<SkPMColor>((SkPMColor*) dst,
271 row * (int) dstRowBytes); 247 row * (int) dstRowBytes);
272 dstRow[x] = SkPackARGB32NoCheck(0xFF, red, green, blue); 248 dstRow[x] = SkPackARGB32NoCheck(0xFF, red, green, blue);
273 break; 249 break;
274 } 250 }
251 case kRGB_565_SkColorType: {
252 uint16_t* dstRow = SkTAddOffset<uint16_t>(dst, row * (int) dstRowByt es);
253 dstRow[x] = SkPack888ToRGB16(red, green, blue);
254 break;
255 }
275 default: 256 default:
276 // This case should not be reached. We should catch an invalid 257 // This case should not be reached. We should catch an invalid
277 // color type when we check that the conversion is possible. 258 // color type when we check that the conversion is possible.
278 SkASSERT(false); 259 SkASSERT(false);
279 break; 260 break;
280 } 261 }
281 } 262 }
282 263
283 /* 264 /*
284 * Performs the bitmap decoding for RLE input format 265 * Performs the bitmap decoding for RLE input format
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 // Set the indicated number of pixels 449 // Set the indicated number of pixels
469 for (int which = 0; x < endX; x++) { 450 for (int which = 0; x < endX; x++) {
470 setPixel(dst, dstRowBytes, dstInfo, x, y, 451 setPixel(dst, dstRowBytes, dstInfo, x, y,
471 indices[which]); 452 indices[which]);
472 which = !which; 453 which = !which;
473 } 454 }
474 } 455 }
475 } 456 }
476 } 457 }
477 } 458 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698