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" | |
11 | 10 |
12 SkBitmapRegionCanvas::SkBitmapRegionCanvas(SkScanlineDecoder* decoder) | 11 SkBitmapRegionCanvas::SkBitmapRegionCanvas(SkCodec* decoder) |
13 : INHERITED(decoder->getInfo().width(), decoder->getInfo().height()) | 12 : INHERITED(decoder->getInfo().width(), decoder->getInfo().height()) |
14 , fDecoder(decoder) | 13 , fDecoder(decoder) |
15 {} | 14 {} |
16 | 15 |
17 /* | 16 /* |
18 * Chooses the correct image subset offsets and dimensions for the partial decod
e. | 17 * Chooses the correct image subset offsets and dimensions for the partial decod
e. |
19 */ | 18 */ |
20 static inline void set_subset_region(int inputOffset, int inputDimension, | 19 static inline void set_subset_region(int inputOffset, int inputDimension, |
21 int imageOriginalDimension, int* imageSubsetOffset, int* outOffset, | 20 int imageOriginalDimension, int* imageSubsetOffset, int* outOffset, |
22 int* imageSubsetDimension) { | 21 int* imageSubsetDimension) { |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 | 106 |
108 // Create the image info for the decode | 107 // Create the image info for the decode |
109 SkAlphaType dstAlphaType = fDecoder->getInfo().alphaType(); | 108 SkAlphaType dstAlphaType = fDecoder->getInfo().alphaType(); |
110 if (kUnpremul_SkAlphaType == dstAlphaType) { | 109 if (kUnpremul_SkAlphaType == dstAlphaType) { |
111 dstAlphaType = kPremul_SkAlphaType; | 110 dstAlphaType = kPremul_SkAlphaType; |
112 } | 111 } |
113 SkImageInfo decodeInfo = SkImageInfo::Make(this->width(), this->height(), | 112 SkImageInfo decodeInfo = SkImageInfo::Make(this->width(), this->height(), |
114 dstColorType, dstAlphaType); | 113 dstColorType, dstAlphaType); |
115 | 114 |
116 // Start the scanline decoder | 115 // Start the scanline decoder |
117 SkCodec::Result r = fDecoder->start(decodeInfo); | 116 SkCodec::Result r = fDecoder->startScanlineDecode(decodeInfo); |
118 if (SkCodec::kSuccess != r) { | 117 if (SkCodec::kSuccess != r) { |
119 SkDebugf("Error: Could not start scanline decoder.\n"); | 118 SkDebugf("Error: Could not start scanline decoder.\n"); |
120 return nullptr; | 119 return nullptr; |
121 } | 120 } |
122 | 121 |
123 // Allocate a bitmap for the unscaled decode | 122 // Allocate a bitmap for the unscaled decode |
124 SkBitmap tmp; | 123 SkBitmap tmp; |
125 SkImageInfo tmpInfo = decodeInfo.makeWH(this->width(), imageSubsetHeight); | 124 SkImageInfo tmpInfo = decodeInfo.makeWH(this->width(), imageSubsetHeight); |
126 if (!tmp.tryAllocPixels(tmpInfo)) { | 125 if (!tmp.tryAllocPixels(tmpInfo)) { |
127 SkDebugf("Error: Could not allocate pixels.\n"); | 126 SkDebugf("Error: Could not allocate pixels.\n"); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 (SkScalar) get_scaled_dimension(imageSubsetWidth, sampleSize), | 179 (SkScalar) get_scaled_dimension(imageSubsetWidth, sampleSize), |
181 (SkScalar) get_scaled_dimension(imageSubsetHeight, sampleSize)); | 180 (SkScalar) get_scaled_dimension(imageSubsetHeight, sampleSize)); |
182 SkPaint paint; | 181 SkPaint paint; |
183 // Overwrite the dst with the src pixels | 182 // Overwrite the dst with the src pixels |
184 paint.setXfermodeMode(SkXfermode::kSrc_Mode); | 183 paint.setXfermodeMode(SkXfermode::kSrc_Mode); |
185 // TODO (msarett): Test multiple filter qualities. kNone is the default. | 184 // TODO (msarett): Test multiple filter qualities. kNone is the default. |
186 canvas.drawBitmapRect(tmp, src, dst, &paint); | 185 canvas.drawBitmapRect(tmp, src, dst, &paint); |
187 | 186 |
188 return bitmap.detach(); | 187 return bitmap.detach(); |
189 } | 188 } |
OLD | NEW |