OLD | NEW |
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 "SkBitmapRegionCanvas.h" | 8 #include "SkBitmapRegionCanvas.h" |
9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
10 #include "SkScanlineDecoder.h" | 10 #include "SkScanlineDecoder.h" |
| 11 #include "SkSwizzler.h" |
11 | 12 |
12 SkBitmapRegionCanvas::SkBitmapRegionCanvas(SkScanlineDecoder* decoder) | 13 SkBitmapRegionCanvas::SkBitmapRegionCanvas(SkScanlineDecoder* decoder) |
13 : INHERITED(decoder->getInfo().width(), decoder->getInfo().height()) | 14 : INHERITED(decoder->getInfo().width(), decoder->getInfo().height()) |
14 , fDecoder(decoder) | 15 , fDecoder(decoder) |
15 {} | 16 {} |
16 | 17 |
17 /* | 18 /* |
18 * Chooses the correct image subset offsets and dimensions for the partial decod
e. | 19 * Chooses the correct image subset offsets and dimensions for the partial decod
e. |
19 */ | 20 */ |
20 static inline void set_subset_region(int inputOffset, int inputDimension, | 21 static inline void set_subset_region(int inputOffset, int inputDimension, |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 | 123 |
123 // Allocate a bitmap for the unscaled decode | 124 // Allocate a bitmap for the unscaled decode |
124 SkBitmap tmp; | 125 SkBitmap tmp; |
125 SkImageInfo tmpInfo = decodeInfo.makeWH(this->width(), imageSubsetHeight); | 126 SkImageInfo tmpInfo = decodeInfo.makeWH(this->width(), imageSubsetHeight); |
126 if (!tmp.tryAllocPixels(tmpInfo)) { | 127 if (!tmp.tryAllocPixels(tmpInfo)) { |
127 SkDebugf("Error: Could not allocate pixels.\n"); | 128 SkDebugf("Error: Could not allocate pixels.\n"); |
128 return nullptr; | 129 return nullptr; |
129 } | 130 } |
130 | 131 |
131 // Skip the unneeded rows | 132 // Skip the unneeded rows |
132 if (SkCodec::kSuccess != fDecoder->skipScanlines(imageSubsetY)) { | 133 if ((uint32_t) imageSubsetY != fDecoder->skipScanlines(imageSubsetY)) { |
133 SkDebugf("Error: Failed to skip scanlines.\n"); | 134 SkDebugf("Error: Failed to skip scanlines.\n"); |
134 return nullptr; | 135 return nullptr; |
135 } | 136 } |
136 | 137 |
137 // Decode the necessary rows | 138 // Decode the necessary rows |
138 SkCodec::Result result = fDecoder->getScanlines(tmp.getAddr(0, 0), imageSubs
etHeight, | 139 uint32_t lines = fDecoder->getScanlines(tmp.getAddr(0, 0), imageSubsetHeight
, tmp.rowBytes()); |
139 tmp.rowBytes()); | 140 if (lines != (uint32_t) imageSubsetHeight) { |
140 switch (result) { | 141 const SkImageInfo fillInfo = tmpInfo.makeWH(tmpInfo.width(), imageSubset
Height - lines); |
141 case SkCodec::kSuccess: | 142 const uint32_t fillValue = fDecoder->getFillValue(fillInfo); |
142 case SkCodec::kIncompleteInput: | 143 SkSwizzler::Fill(tmp.getAddr(0, lines), fillInfo, tmp.rowBytes(), fillVa
lue, |
143 break; | 144 SkCodec::kNo_ZeroInitialized); |
144 default: | |
145 SkDebugf("Error: Failed to get scanlines.\n"); | |
146 return nullptr; | |
147 } | 145 } |
148 | 146 |
149 // Calculate the size of the output | 147 // Calculate the size of the output |
150 const int outWidth = get_scaled_dimension(inputWidth, sampleSize); | 148 const int outWidth = get_scaled_dimension(inputWidth, sampleSize); |
151 const int outHeight = get_scaled_dimension(inputHeight, sampleSize); | 149 const int outHeight = get_scaled_dimension(inputHeight, sampleSize); |
152 | 150 |
153 // Initialize the destination bitmap | 151 // Initialize the destination bitmap |
154 SkAutoTDelete<SkBitmap> bitmap(new SkBitmap()); | 152 SkAutoTDelete<SkBitmap> bitmap(new SkBitmap()); |
155 SkImageInfo dstInfo = decodeInfo.makeWH(outWidth, outHeight); | 153 SkImageInfo dstInfo = decodeInfo.makeWH(outWidth, outHeight); |
156 if (!bitmap->tryAllocPixels(dstInfo)) { | 154 if (!bitmap->tryAllocPixels(dstInfo)) { |
(...skipping 23 matching lines...) Expand all Loading... |
180 (SkScalar) get_scaled_dimension(imageSubsetWidth, sampleSize), | 178 (SkScalar) get_scaled_dimension(imageSubsetWidth, sampleSize), |
181 (SkScalar) get_scaled_dimension(imageSubsetHeight, sampleSize)); | 179 (SkScalar) get_scaled_dimension(imageSubsetHeight, sampleSize)); |
182 SkPaint paint; | 180 SkPaint paint; |
183 // Overwrite the dst with the src pixels | 181 // Overwrite the dst with the src pixels |
184 paint.setXfermodeMode(SkXfermode::kSrc_Mode); | 182 paint.setXfermodeMode(SkXfermode::kSrc_Mode); |
185 // TODO (msarett): Test multiple filter qualities. kNone is the default. | 183 // TODO (msarett): Test multiple filter qualities. kNone is the default. |
186 canvas.drawBitmapRect(tmp, src, dst, &paint); | 184 canvas.drawBitmapRect(tmp, src, dst, &paint); |
187 | 185 |
188 return bitmap.detach(); | 186 return bitmap.detach(); |
189 } | 187 } |
OLD | NEW |