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

Side by Side Diff: dm/DMSrcSink.cpp

Issue 1287423002: Scanline decoding for bmp (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fixes 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
« no previous file with comments | « no previous file | include/codec/SkScaledCodec.h » ('j') | src/codec/SkBmpRLECodec.cpp » ('J')
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 "DMSrcSink.h" 8 #include "DMSrcSink.h"
9 #include "SamplePipeControllers.h" 9 #include "SamplePipeControllers.h"
10 #include "SkCodec.h" 10 #include "SkCodec.h"
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 {} 73 {}
74 74
75 bool CodecSrc::veto(SinkFlags flags) const { 75 bool CodecSrc::veto(SinkFlags flags) const {
76 // No need to test decoding to non-raster or indirect backend. 76 // No need to test decoding to non-raster or indirect backend.
77 // TODO: Once we implement GPU paths (e.g. JPEG YUV), we should use a deferr ed decode to 77 // TODO: Once we implement GPU paths (e.g. JPEG YUV), we should use a deferr ed decode to
78 // let the GPU handle it. 78 // let the GPU handle it.
79 return flags.type != SinkFlags::kRaster 79 return flags.type != SinkFlags::kRaster
80 || flags.approach != SinkFlags::kDirect; 80 || flags.approach != SinkFlags::kDirect;
81 } 81 }
82 82
83 SkScanlineDecoder* start_scanline_decoder(SkData* encoded, const SkImageInfo& in fo,
84 SkPMColor* colorPtr, int* colorCountPtr) {
85 SkAutoTDelete<SkScanlineDecoder> scanlineDecoder(SkScanlineDecoder::NewFromD ata(encoded));
86 if (NULL == scanlineDecoder) {
87 return NULL;
88 }
89 // DM scanline test assume kTopDown scanline ordering. Other orderings are
90 // tested from within SkScaledCodec.
91 if (SkScanlineDecoder::kTopDown_SkScanlineOrder != scanlineDecoder->getScanl ineOrder()) {
92 return NULL;
93 }
94 if (SkCodec::kSuccess != scanlineDecoder->start(info, NULL, colorPtr, colorC ountPtr)) {
95 return NULL;
96 }
97 return scanlineDecoder.detach();
98 }
99
83 Error CodecSrc::draw(SkCanvas* canvas) const { 100 Error CodecSrc::draw(SkCanvas* canvas) const {
84 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str())); 101 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str()));
85 if (!encoded) { 102 if (!encoded) {
86 return SkStringPrintf("Couldn't read %s.", fPath.c_str()); 103 return SkStringPrintf("Couldn't read %s.", fPath.c_str());
87 } 104 }
88 SkAutoTDelete<SkCodec> codec(SkScaledCodec::NewFromData(encoded)); 105 SkAutoTDelete<SkCodec> codec(SkScaledCodec::NewFromData(encoded));
89 if (NULL == codec.get()) { 106 if (NULL == codec.get()) {
90 // scaledCodec not supported, try normal codec 107 // scaledCodec not supported, try normal codec
91 codec.reset(SkCodec::NewFromData(encoded)); 108 codec.reset(SkCodec::NewFromData(encoded));
92 if (NULL == codec.get()) { 109 if (NULL == codec.get()) {
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 return Error::Nonfatal("Incompatible colortype conversion"); 175 return Error::Nonfatal("Incompatible colortype conversion");
159 default: 176 default:
160 // Everything else is considered a failure. 177 // Everything else is considered a failure.
161 return SkStringPrintf("Couldn't getPixels %s.", fPath.c_str( )); 178 return SkStringPrintf("Couldn't getPixels %s.", fPath.c_str( ));
162 } 179 }
163 canvas->drawBitmap(bitmap, 0, 0); 180 canvas->drawBitmap(bitmap, 0, 0);
164 break; 181 break;
165 } 182 }
166 case kScanline_Mode: { 183 case kScanline_Mode: {
167 SkAutoTDelete<SkScanlineDecoder> scanlineDecoder( 184 SkAutoTDelete<SkScanlineDecoder> scanlineDecoder(
168 SkScanlineDecoder::NewFromData(encoded)); 185 start_scanline_decoder(encoded.get(), decodeInfo, colorPtr, colorCountPtr));
169 if (NULL == scanlineDecoder || SkCodec::kSuccess != 186 if (NULL == scanlineDecoder) {
170 scanlineDecoder->start(decodeInfo, NULL, colorPtr, colorCoun tPtr)) { 187 return Error::Nonfatal("Could not start top-down scanline decode r");
171 return Error::Nonfatal("Cannot use scanline decoder for all imag es");
172 } 188 }
173 189
174 const SkCodec::Result result = scanlineDecoder->getScanlines( 190 const SkCodec::Result result = scanlineDecoder->getScanlines(
175 bitmap.getAddr(0, 0), decodeInfo.height(), bitmap.rowBytes() ); 191 bitmap.getAddr(0, 0), decodeInfo.height(), bitmap.rowBytes() );
176 switch (result) { 192 switch (result) {
177 case SkCodec::kSuccess: 193 case SkCodec::kSuccess:
178 case SkCodec::kIncompleteInput: 194 case SkCodec::kIncompleteInput:
179 break; 195 break;
180 default: 196 default:
181 return SkStringPrintf("%s failed with error message %d", 197 return SkStringPrintf("%s failed with error message %d",
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 const int currentSubsetWidth = (col + 1 == divisor) ? 238 const int currentSubsetWidth = (col + 1 == divisor) ?
223 subsetWidth + extraX : subsetWidth; 239 subsetWidth + extraX : subsetWidth;
224 const int x = col * subsetWidth; 240 const int x = col * subsetWidth;
225 for (int row = 0; row < divisor; row++) { 241 for (int row = 0; row < divisor; row++) {
226 //currentSubsetHeight may be larger than subsetHeight for bo ttom subsets 242 //currentSubsetHeight may be larger than subsetHeight for bo ttom subsets
227 const int currentSubsetHeight = (row + 1 == divisor) ? 243 const int currentSubsetHeight = (row + 1 == divisor) ?
228 subsetHeight + extraY : subsetHeight; 244 subsetHeight + extraY : subsetHeight;
229 const int y = row * subsetHeight; 245 const int y = row * subsetHeight;
230 //create scanline decoder for each subset 246 //create scanline decoder for each subset
231 SkAutoTDelete<SkScanlineDecoder> subsetScanlineDecoder( 247 SkAutoTDelete<SkScanlineDecoder> subsetScanlineDecoder(
232 SkScanlineDecoder::NewFromData(encoded)); 248 start_scanline_decoder(encoded.get(), decodeInfo,
233 if (NULL == subsetScanlineDecoder || SkCodec::kSuccess != 249 colorPtr, colorCountPtr));
234 subsetScanlineDecoder->start( 250 if (NULL == subsetScanlineDecoder) {
235 decodeInfo, NULL, colorPtr, colorCountPtr))
236 {
237 if (x == 0 && y == 0) { 251 if (x == 0 && y == 0) {
238 //first try, image may not be compatible 252 //first try, image may not be compatible
239 return Error::Nonfatal("Cannot use scanline decoder for all images"); 253 return Error::Nonfatal("Could not start top-down sca nline decoder");
240 } else { 254 } else {
241 return "Error scanline decoder is NULL"; 255 return "Error scanline decoder is NULL";
242 } 256 }
243 } 257 }
258 if (SkScanlineDecoder::kTopDown_SkScanlineOrder !=
259 subsetScanlineDecoder->getScanlineOrder()) {
260 return Error::Nonfatal("Test mode not supported");
261 }
244 //skip to first line of subset 262 //skip to first line of subset
245 const SkCodec::Result skipResult = 263 const SkCodec::Result skipResult =
246 subsetScanlineDecoder->skipScanlines(y); 264 subsetScanlineDecoder->skipScanlines(y);
247 switch (skipResult) { 265 switch (skipResult) {
248 case SkCodec::kSuccess: 266 case SkCodec::kSuccess:
249 case SkCodec::kIncompleteInput: 267 case SkCodec::kIncompleteInput:
250 break; 268 break;
251 default: 269 default:
252 return SkStringPrintf("%s failed after attempting to skip %d scanlines" 270 return SkStringPrintf("%s failed after attempting to skip %d scanlines"
253 "with error message %d", fPath.c_str(), y, ( int) skipResult); 271 "with error message %d", fPath.c_str(), y, ( int) skipResult);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 break; 310 break;
293 } 311 }
294 case kStripe_Mode: { 312 case kStripe_Mode: {
295 const int height = decodeInfo.height(); 313 const int height = decodeInfo.height();
296 // This value is chosen arbitrarily. We exercise more cases by choo sing a value that 314 // This value is chosen arbitrarily. We exercise more cases by choo sing a value that
297 // does not align with image blocks. 315 // does not align with image blocks.
298 const int stripeHeight = 37; 316 const int stripeHeight = 37;
299 const int numStripes = (height + stripeHeight - 1) / stripeHeight; 317 const int numStripes = (height + stripeHeight - 1) / stripeHeight;
300 318
301 // Decode odd stripes 319 // Decode odd stripes
302 SkAutoTDelete<SkScanlineDecoder> decoder(SkScanlineDecoder::NewFromD ata(encoded)); 320 SkAutoTDelete<SkScanlineDecoder> decoder(
303 if (NULL == decoder || SkCodec::kSuccess != 321 start_scanline_decoder(encoded.get(), decodeInfo, colorPtr, colorCountPtr));
304 decoder->start(decodeInfo, NULL, colorPtr, colorCountPtr)) { 322 if (NULL == decoder) {
305 return Error::Nonfatal("Cannot use scanline decoder for all imag es"); 323 return Error::Nonfatal("Could not start top-down scanline decode r");
306 } 324 }
307 for (int i = 0; i < numStripes; i += 2) { 325 for (int i = 0; i < numStripes; i += 2) {
308 // Skip a stripe 326 // Skip a stripe
309 const int linesToSkip = SkTMin(stripeHeight, height - i * stripe Height); 327 const int linesToSkip = SkTMin(stripeHeight, height - i * stripe Height);
310 SkCodec::Result result = decoder->skipScanlines(linesToSkip); 328 SkCodec::Result result = decoder->skipScanlines(linesToSkip);
311 switch (result) { 329 switch (result) {
312 case SkCodec::kSuccess: 330 case SkCodec::kSuccess:
313 case SkCodec::kIncompleteInput: 331 case SkCodec::kIncompleteInput:
314 break; 332 break;
315 default: 333 default:
(...skipping 767 matching lines...) Expand 10 before | Expand all | Expand 10 after
1083 skr.visit<void>(i, drawsAsSingletonPictures); 1101 skr.visit<void>(i, drawsAsSingletonPictures);
1084 } 1102 }
1085 SkAutoTUnref<SkPicture> macroPic(macroRec.endRecordingAsPicture()); 1103 SkAutoTUnref<SkPicture> macroPic(macroRec.endRecordingAsPicture());
1086 1104
1087 canvas->drawPicture(macroPic); 1105 canvas->drawPicture(macroPic);
1088 return ""; 1106 return "";
1089 }); 1107 });
1090 } 1108 }
1091 1109
1092 } // namespace DM 1110 } // namespace DM
OLDNEW
« no previous file with comments | « no previous file | include/codec/SkScaledCodec.h » ('j') | src/codec/SkBmpRLECodec.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698