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

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: Support more 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 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 } 169 }
199 170
200 // Set the pixel based on destination color type 171 // Set the pixel based on destination color type
201 switch (dstInfo.colorType()) { 172 switch (dstInfo.colorType()) {
202 case kN32_SkColorType: { 173 case kN32_SkColorType: {
203 SkPMColor* dstRow = SkTAddOffset<SkPMColor>((SkPMColor*) dst, 174 SkPMColor* dstRow = SkTAddOffset<SkPMColor>((SkPMColor*) dst,
204 row * (int) dstRowBytes); 175 row * (int) dstRowBytes);
205 dstRow[x] = fColorTable->operator[](index); 176 dstRow[x] = fColorTable->operator[](index);
206 break; 177 break;
207 } 178 }
179 case kRGB_565_SkColorType: {
180 uint16_t* dstRow = SkTAddOffset<uint16_t>(dst, row * (int) dstRowByt es);
181 dstRow[x] = SkPixel32ToPixel16(fColorTable->operator[](index));
182 break;
183 }
208 default: 184 default:
209 // This case should not be reached. We should catch an invalid 185 // This case should not be reached. We should catch an invalid
210 // color type when we check that the conversion is possible. 186 // color type when we check that the conversion is possible.
211 SkASSERT(false); 187 SkASSERT(false);
212 break; 188 break;
213 } 189 }
214 } 190 }
215 191
216 /* 192 /*
217 * Set an RLE pixel from R, G, B values 193 * Set an RLE pixel from R, G, B values
(...skipping 12 matching lines...) Expand all
230 } 206 }
231 207
232 // Set the pixel based on destination color type 208 // Set the pixel based on destination color type
233 switch (dstInfo.colorType()) { 209 switch (dstInfo.colorType()) {
234 case kN32_SkColorType: { 210 case kN32_SkColorType: {
235 SkPMColor* dstRow = SkTAddOffset<SkPMColor>((SkPMColor*) dst, 211 SkPMColor* dstRow = SkTAddOffset<SkPMColor>((SkPMColor*) dst,
236 row * (int) dstRowBytes); 212 row * (int) dstRowBytes);
237 dstRow[x] = SkPackARGB32NoCheck(0xFF, red, green, blue); 213 dstRow[x] = SkPackARGB32NoCheck(0xFF, red, green, blue);
238 break; 214 break;
239 } 215 }
216 case kRGB_565_SkColorType: {
217 uint16_t* dstRow = SkTAddOffset<uint16_t>(dst, row * (int) dstRowByt es);
218 dstRow[x] = SkPack888ToRGB16(red, green, blue);
219 break;
220 }
240 default: 221 default:
241 // This case should not be reached. We should catch an invalid 222 // This case should not be reached. We should catch an invalid
242 // color type when we check that the conversion is possible. 223 // color type when we check that the conversion is possible.
243 SkASSERT(false); 224 SkASSERT(false);
244 break; 225 break;
245 } 226 }
246 } 227 }
247 228
248 /* 229 /*
249 * Performs the bitmap decoding for RLE input format 230 * Performs the bitmap decoding for RLE input format
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 // Set the indicated number of pixels 402 // Set the indicated number of pixels
422 for (int which = 0; x < endX; x++) { 403 for (int which = 0; x < endX; x++) {
423 setPixel(dst, dstRowBytes, dstInfo, x, y, 404 setPixel(dst, dstRowBytes, dstInfo, x, y,
424 indices[which]); 405 indices[which]);
425 which = !which; 406 which = !which;
426 } 407 }
427 } 408 }
428 } 409 }
429 } 410 }
430 } 411 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698