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

Side by Side Diff: src/codec/SkBmpStandardCodec.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 "SkBmpStandardCodec.h" 8 #include "SkBmpStandardCodec.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 SkBmpStandardCodec::SkBmpStandardCodec(const SkImageInfo& info, SkStream* stream , 18 SkBmpStandardCodec::SkBmpStandardCodec(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, bool inIco ) 21 SkBmpCodec::RowOrder rowOrder, bool inIco )
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 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 } else { 287 } else {
317 row = height - 1 - y; 288 row = height - 1 - y;
318 } 289 }
319 290
320 void* dstRow = SkTAddOffset<void>(dst, row * dstRowBytes); 291 void* dstRow = SkTAddOffset<void>(dst, row * dstRowBytes);
321 fSwizzler->swizzle(dstRow, fSrcBuffer.get()); 292 fSwizzler->swizzle(dstRow, fSrcBuffer.get());
322 } 293 }
323 294
324 // Finally, apply the AND mask for bmp-in-ico images 295 // Finally, apply the AND mask for bmp-in-ico images
325 if (fInIco) { 296 if (fInIco) {
297 // BMP in ICO have transparency, so this cannot be 565, and this mask
298 // prevents us from using kIndex8. The below code depends on the output
299 // being an SkPMColor.
300 SkASSERT(dstInfo.colorType() == kN32_SkColorType);
301
326 // The AND mask is always 1 bit per pixel 302 // The AND mask is always 1 bit per pixel
327 const size_t rowBytes = SkAlign4(compute_row_bytes(width, 1)); 303 const size_t rowBytes = SkAlign4(compute_row_bytes(width, 1));
328 304
329 SkPMColor* dstPtr = (SkPMColor*) dst; 305 SkPMColor* dstPtr = (SkPMColor*) dst;
330 for (int y = 0; y < height; y++) { 306 for (int y = 0; y < height; y++) {
331 // The srcBuffer will at least be large enough 307 // The srcBuffer will at least be large enough
332 if (stream()->read(fSrcBuffer.get(), rowBytes) != rowBytes) { 308 if (stream()->read(fSrcBuffer.get(), rowBytes) != rowBytes) {
333 SkCodecPrintf("Warning: incomplete AND mask for bmp-in-ico.\n"); 309 SkCodecPrintf("Warning: incomplete AND mask for bmp-in-ico.\n");
334 return kIncompleteInput; 310 return kIncompleteInput;
335 } 311 }
(...skipping 16 matching lines...) Expand all
352 uint32_t alphaBit = 328 uint32_t alphaBit =
353 (fSrcBuffer.get()[quotient] >> shift) & 0x1; 329 (fSrcBuffer.get()[quotient] >> shift) & 0x1;
354 dstRow[x] &= alphaBit - 1; 330 dstRow[x] &= alphaBit - 1;
355 } 331 }
356 } 332 }
357 } 333 }
358 334
359 // Finished decoding the entire image 335 // Finished decoding the entire image
360 return kSuccess; 336 return kSuccess;
361 } 337 }
OLDNEW
« no previous file with comments | « src/codec/SkBmpRLECodec.cpp ('k') | src/codec/SkCodec.cpp » ('j') | src/codec/SkSwizzler.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698