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

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: Scaling for all types of bmps 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 "SkBmpMaskCodec.h" 8 #include "SkBmpMaskCodec.h"
9 #include "SkCodecPriv.h" 9 #include "SkCodecPriv.h"
10 #include "SkColorPriv.h" 10 #include "SkColorPriv.h"
(...skipping 28 matching lines...) Expand all
39 if (dstInfo.dimensions() != this->getInfo().dimensions()) { 39 if (dstInfo.dimensions() != this->getInfo().dimensions()) {
40 SkCodecPrintf("Error: scaling not supported.\n"); 40 SkCodecPrintf("Error: scaling not supported.\n");
41 return kInvalidScale; 41 return kInvalidScale;
42 } 42 }
43 43
44 if (!conversion_possible(dstInfo, this->getInfo())) { 44 if (!conversion_possible(dstInfo, this->getInfo())) {
45 SkCodecPrintf("Error: cannot convert input type to output type.\n"); 45 SkCodecPrintf("Error: cannot convert input type to output type.\n");
46 return kInvalidConversion; 46 return kInvalidConversion;
47 } 47 }
48 48
49 // Initialize a the mask swizzler 49 Result result = this->prepareToDecode(dstInfo, opts, inputColorPtr, inputCol orCount);
50 if (!this->initializeSwizzler(dstInfo)) { 50 if (kSuccess != result) {
51 SkCodecPrintf("Error: cannot initialize swizzler.\n"); 51 return result;
52 return kInvalidConversion;
53 } 52 }
54 53
55 return this->decode(dstInfo, dst, dstRowBytes, opts); 54 return this->decode(dstInfo, dst, dstRowBytes, opts);
56 } 55 }
57 56
58 bool SkBmpMaskCodec::initializeSwizzler(const SkImageInfo& dstInfo) { 57 bool SkBmpMaskCodec::initializeSwizzler(const SkImageInfo& dstInfo) {
59 // Allocate space for a row buffer 58 // Allocate space for a row buffer
60 const size_t rowBytes = SkAlign4(compute_row_bytes(dstInfo.width(), this->bi tsPerPixel())); 59 const size_t rowBytes = SkAlign4(compute_row_bytes(this->getInfo().width(),
60 this->bitsPerPixel()));
61 fSrcBuffer.reset(SkNEW_ARRAY(uint8_t, rowBytes)); 61 fSrcBuffer.reset(SkNEW_ARRAY(uint8_t, rowBytes));
62 62
63 // Create the swizzler 63 // Create the swizzler
64 fMaskSwizzler.reset(SkMaskSwizzler::CreateMaskSwizzler( 64 fMaskSwizzler.reset(SkMaskSwizzler::CreateMaskSwizzler(
65 dstInfo, fMasks, this->bitsPerPixel())); 65 dstInfo, this->getInfo(), fMasks, this->bitsPerPixel()));
66 66
67 if (NULL == fMaskSwizzler.get()) { 67 if (NULL == fMaskSwizzler.get()) {
68 return false; 68 return false;
69 } 69 }
70 70
71 return true; 71 return true;
72 } 72 }
73 73
74 /* 74 /*
75 * Performs the decoding 75 * Performs the decoding
76 */ 76 */
77 SkCodec::Result SkBmpMaskCodec::decode(const SkImageInfo& dstInfo, 77 SkCodec::Result SkBmpMaskCodec::decode(const SkImageInfo& dstInfo,
78 void* dst, size_t dstRowBytes, 78 void* dst, size_t dstRowBytes,
79 const Options& opts) { 79 const Options& opts) {
80 // Set constant values 80 // Set constant values
81 const int width = dstInfo.width(); 81 const int width = this->getInfo().width();
82 const int height = dstInfo.height(); 82 const int height = dstInfo.height();
83 const size_t rowBytes = SkAlign4(compute_row_bytes(width, this->bitsPerPixel ())); 83 const size_t rowBytes = SkAlign4(compute_row_bytes(width, this->bitsPerPixel ()));
84 84
85 // Iterate over rows of the image 85 // Iterate over rows of the image
86 uint8_t* srcRow = fSrcBuffer.get(); 86 uint8_t* srcRow = fSrcBuffer.get();
87 for (int y = 0; y < height; y++) { 87 for (int y = 0; y < height; y++) {
88 // Read a row of the input 88 // Read a row of the input
89 if (this->stream()->read(srcRow, rowBytes) != rowBytes) { 89 if (this->stream()->read(srcRow, rowBytes) != rowBytes) {
90 SkCodecPrintf("Warning: incomplete input stream.\n"); 90 SkCodecPrintf("Warning: incomplete input stream.\n");
91 // Fill the destination image on failure 91 // Fill the destination image on failure
92 SkPMColor fillColor = dstInfo.alphaType() == kOpaque_SkAlphaType ? 92 SkPMColor fillColor = dstInfo.alphaType() == kOpaque_SkAlphaType ?
93 SK_ColorBLACK : SK_ColorTRANSPARENT; 93 SK_ColorBLACK : SK_ColorTRANSPARENT;
94 if (kNo_ZeroInitialized == opts.fZeroInitialized || 0 != fillColor) { 94 if (kNo_ZeroInitialized == opts.fZeroInitialized || 0 != fillColor) {
95 void* dstStart = this->getDstStartRow(dst, dstRowBytes, y); 95 void* dstStart = this->getDstStartRow(dst, dstRowBytes, y);
96 SkSwizzler::Fill(dstStart, dstInfo, dstRowBytes, dstInfo.height( ) - y, fillColor, 96 SkSwizzler::Fill(dstStart, dstInfo, dstRowBytes, dstInfo.height( ) - y, fillColor,
97 NULL); 97 NULL);
98 } 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, dstInfo.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 }
111
112 SkCodec::Result SkBmpMaskCodec::prepareToDecode(const SkImageInfo& dstInfo,
113 const SkCodec::Options& options, SkPMColor inputColorPtr[], int* inputCo lorCount) {
114 // Initialize a the mask swizzler
115 if (!this->initializeSwizzler(dstInfo)) {
116 SkCodecPrintf("Error: cannot initialize swizzler.\n");
117 return SkCodec::kInvalidConversion;
118 }
119
120 return SkCodec::kSuccess;
121 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698