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

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

Issue 1287423002: Scanline decoding for bmp (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix windows errors Created 5 years, 3 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
« no previous file with comments | « src/codec/SkBmpMaskCodec.h ('k') | src/codec/SkBmpRLECodec.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "SkBmpMaskCodec.h" 8 #include "SkBmpMaskCodec.h"
9 #include "SkCodecPriv.h" 9 #include "SkCodecPriv.h"
10 #include "SkColorPriv.h" 10 #include "SkColorPriv.h"
11 11
12 /* 12 /*
13 * Creates an instance of the decoder 13 * Creates an instance of the decoder
14 */ 14 */
15 SkBmpMaskCodec::SkBmpMaskCodec(const SkImageInfo& info, SkStream* stream, 15 SkBmpMaskCodec::SkBmpMaskCodec(const SkImageInfo& info, SkStream* stream,
16 uint16_t bitsPerPixel, SkMasks* masks, 16 uint16_t bitsPerPixel, SkMasks* masks,
17 SkBmpCodec::RowOrder rowOrder) 17 SkScanlineDecoder::SkScanlineOrder rowOrder)
18 : INHERITED(info, stream, bitsPerPixel, rowOrder) 18 : INHERITED(info, stream, bitsPerPixel, rowOrder)
19 , fMasks(masks) 19 , fMasks(masks)
20 , fMaskSwizzler(nullptr) 20 , fMaskSwizzler(nullptr)
21 , fSrcBuffer(nullptr) 21 , fSrcRowBytes(SkAlign4(compute_row_bytes(this->getInfo().width(), this->bit sPerPixel())))
22 , fSrcBuffer(new uint8_t [fSrcRowBytes])
22 {} 23 {}
23 24
24 /* 25 /*
25 * Initiates the bitmap decode 26 * Initiates the bitmap decode
26 */ 27 */
27 SkCodec::Result SkBmpMaskCodec::onGetPixels(const SkImageInfo& dstInfo, 28 SkCodec::Result SkBmpMaskCodec::onGetPixels(const SkImageInfo& dstInfo,
28 void* dst, size_t dstRowBytes, 29 void* dst, size_t dstRowBytes,
29 const Options& opts, 30 const Options& opts,
30 SkPMColor* inputColorPtr, 31 SkPMColor* inputColorPtr,
31 int* inputColorCount) { 32 int* inputColorCount) {
32 if (!this->rewindIfNeeded()) { 33 if (!this->rewindIfNeeded()) {
33 return kCouldNotRewind; 34 return kCouldNotRewind;
34 } 35 }
35 if (opts.fSubset) { 36 if (opts.fSubset) {
36 // Subsets are not supported. 37 // Subsets are not supported.
37 return kUnimplemented; 38 return kUnimplemented;
38 } 39 }
39 if (dstInfo.dimensions() != this->getInfo().dimensions()) { 40 if (dstInfo.dimensions() != this->getInfo().dimensions()) {
40 SkCodecPrintf("Error: scaling not supported.\n"); 41 SkCodecPrintf("Error: scaling not supported.\n");
41 return kInvalidScale; 42 return kInvalidScale;
42 } 43 }
43 44
44 if (!conversion_possible(dstInfo, this->getInfo())) { 45 if (!conversion_possible(dstInfo, this->getInfo())) {
45 SkCodecPrintf("Error: cannot convert input type to output type.\n"); 46 SkCodecPrintf("Error: cannot convert input type to output type.\n");
46 return kInvalidConversion; 47 return kInvalidConversion;
47 } 48 }
48 49
49 // Initialize a the mask swizzler 50 Result result = this->prepareToDecode(dstInfo, opts, inputColorPtr, inputCol orCount);
50 if (!this->initializeSwizzler(dstInfo)) { 51 if (kSuccess != result) {
51 SkCodecPrintf("Error: cannot initialize swizzler.\n"); 52 return result;
52 return kInvalidConversion;
53 } 53 }
54 54
55 return this->decode(dstInfo, dst, dstRowBytes, opts); 55 return this->decodeRows(dstInfo, dst, dstRowBytes, opts);
56 } 56 }
57 57
58 bool SkBmpMaskCodec::initializeSwizzler(const SkImageInfo& dstInfo) { 58 bool SkBmpMaskCodec::initializeSwizzler(const SkImageInfo& dstInfo) {
59 // Allocate space for a row buffer
60 const size_t rowBytes = SkAlign4(compute_row_bytes(dstInfo.width(), this->bi tsPerPixel()));
61 fSrcBuffer.reset(new uint8_t[rowBytes]);
62
63 // Create the swizzler 59 // Create the swizzler
64 fMaskSwizzler.reset(SkMaskSwizzler::CreateMaskSwizzler( 60 fMaskSwizzler.reset(SkMaskSwizzler::CreateMaskSwizzler(
65 dstInfo, fMasks, this->bitsPerPixel())); 61 dstInfo, this->getInfo(), fMasks, this->bitsPerPixel()));
66 62
67 if (nullptr == fMaskSwizzler.get()) { 63 if (nullptr == fMaskSwizzler.get()) {
68 return false; 64 return false;
69 } 65 }
70 66
71 return true; 67 return true;
72 } 68 }
73 69
70 SkCodec::Result SkBmpMaskCodec::prepareToDecode(const SkImageInfo& dstInfo,
71 const SkCodec::Options& options, SkPMColor inputColorPtr[], int* inputCo lorCount) {
72 // Initialize a the mask swizzler
73 if (!this->initializeSwizzler(dstInfo)) {
74 SkCodecPrintf("Error: cannot initialize swizzler.\n");
75 return SkCodec::kInvalidConversion;
76 }
77
78 return SkCodec::kSuccess;
79 }
80
74 /* 81 /*
75 * Performs the decoding 82 * Performs the decoding
76 */ 83 */
77 SkCodec::Result SkBmpMaskCodec::decode(const SkImageInfo& dstInfo, 84 SkCodec::Result SkBmpMaskCodec::decodeRows(const SkImageInfo& dstInfo,
78 void* dst, size_t dstRowBytes, 85 void* dst, size_t dstRowBytes,
79 const Options& opts) { 86 const Options& opts) {
80 // Set constant values
81 const int width = dstInfo.width();
82 const int height = dstInfo.height();
83 const size_t rowBytes = SkAlign4(compute_row_bytes(width, this->bitsPerPixel ()));
84
85 // Iterate over rows of the image 87 // Iterate over rows of the image
86 uint8_t* srcRow = fSrcBuffer.get(); 88 uint8_t* srcRow = fSrcBuffer.get();
89 const int height = dstInfo.height();
87 for (int y = 0; y < height; y++) { 90 for (int y = 0; y < height; y++) {
88 // Read a row of the input 91 // Read a row of the input
89 if (this->stream()->read(srcRow, rowBytes) != rowBytes) { 92 if (this->stream()->read(srcRow, fSrcRowBytes) != fSrcRowBytes) {
90 SkCodecPrintf("Warning: incomplete input stream.\n"); 93 SkCodecPrintf("Warning: incomplete input stream.\n");
91 // Fill the destination image on failure 94 // Fill the destination image on failure
92 SkPMColor fillColor = dstInfo.alphaType() == kOpaque_SkAlphaType ? 95 void* dstStart = this->getDstStartRow(dst, dstRowBytes, y);
93 SK_ColorBLACK : SK_ColorTRANSPARENT; 96 uint32_t fillColor = get_fill_color_or_index(dstInfo.alphaType());
94 if (kNo_ZeroInitialized == opts.fZeroInitialized || 0 != fillColor) { 97 SkSwizzler::Fill(dstStart, dstInfo, dstRowBytes, height - y,
95 void* dstStart = this->getDstStartRow(dst, dstRowBytes, y); 98 fillColor, nullptr, opts.fZeroInitialized);
96 SkSwizzler::Fill(dstStart, dstInfo, dstRowBytes, dstInfo.height( ) - y, fillColor,
97 nullptr);
98 }
99 return kIncompleteInput; 99 return kIncompleteInput;
100 } 100 }
101 101
102 // Decode the row in destination format 102 // Decode the row in destination format
103 int row = SkBmpCodec::kBottomUp_RowOrder == this->rowOrder() ? height - 1 - y : y; 103 uint32_t row = this->getDstRow(y, height);
104 void* dstRow = SkTAddOffset<void>(dst, row * dstRowBytes); 104 void* dstRow = SkTAddOffset<void>(dst, row * dstRowBytes);
105 fMaskSwizzler->swizzle(dstRow, srcRow); 105 fMaskSwizzler->swizzle(dstRow, srcRow);
106 } 106 }
107 107
108 // Finished decoding the entire image 108 // Finished decoding the entire image
109 return kSuccess; 109 return kSuccess;
110 } 110 }
OLDNEW
« no previous file with comments | « src/codec/SkBmpMaskCodec.h ('k') | src/codec/SkBmpRLECodec.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698