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

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: 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 | « no previous file | include/codec/SkScanlineDecoder.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 "DMSrcSink.h" 8 #include "DMSrcSink.h"
9 #include "SamplePipeControllers.h" 9 #include "SamplePipeControllers.h"
10 #include "SkCodec.h" 10 #include "SkCodec.h"
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 {} 72 {}
73 73
74 bool CodecSrc::veto(SinkFlags flags) const { 74 bool CodecSrc::veto(SinkFlags flags) const {
75 // No need to test decoding to non-raster or indirect backend. 75 // No need to test decoding to non-raster or indirect backend.
76 // TODO: Once we implement GPU paths (e.g. JPEG YUV), we should use a deferr ed decode to 76 // TODO: Once we implement GPU paths (e.g. JPEG YUV), we should use a deferr ed decode to
77 // let the GPU handle it. 77 // let the GPU handle it.
78 return flags.type != SinkFlags::kRaster 78 return flags.type != SinkFlags::kRaster
79 || flags.approach != SinkFlags::kDirect; 79 || flags.approach != SinkFlags::kDirect;
80 } 80 }
81 81
82 SkScanlineDecoder* start_scanline_decoder(SkData* encoded, const SkImageInfo& in fo,
83 SkPMColor* colorPtr, int* colorCountPtr) {
84 SkAutoTDelete<SkScanlineDecoder> scanlineDecoder(SkScanlineDecoder::NewFromD ata(encoded));
85 if (nullptr == scanlineDecoder) {
86 return nullptr;
87 }
88 // DM scanline test assume kTopDown scanline ordering. Other orderings are
89 // tested from within SkScaledCodec.
90 // TODO (msarett): Redesign the CodecSrc tests to improve our coverage of Sk Codec and
91 // SkScanlineDecoder functionality. Maybe we should write c ode to explicitly
92 // test kNone, kOutOfOrder, and kBottomUp.
93 if (SkScanlineDecoder::kTopDown_SkScanlineOrder != scanlineDecoder->getScanl ineOrder()) {
94 return nullptr;
95 }
96 if (SkCodec::kSuccess != scanlineDecoder->start(info, NULL, colorPtr, colorC ountPtr)) {
97 return nullptr;
98 }
99 return scanlineDecoder.detach();
100 }
101
82 Error CodecSrc::draw(SkCanvas* canvas) const { 102 Error CodecSrc::draw(SkCanvas* canvas) const {
83 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str())); 103 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str()));
84 if (!encoded) { 104 if (!encoded) {
85 return SkStringPrintf("Couldn't read %s.", fPath.c_str()); 105 return SkStringPrintf("Couldn't read %s.", fPath.c_str());
86 } 106 }
87 SkAutoTDelete<SkCodec> codec(SkScaledCodec::NewFromData(encoded)); 107 SkAutoTDelete<SkCodec> codec(SkScaledCodec::NewFromData(encoded));
88 if (nullptr == codec.get()) { 108 if (nullptr == codec.get()) {
89 // scaledCodec not supported, try normal codec 109 // scaledCodec not supported, try normal codec
90 codec.reset(SkCodec::NewFromData(encoded)); 110 codec.reset(SkCodec::NewFromData(encoded));
91 if (nullptr == codec.get()) { 111 if (nullptr == codec.get()) {
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 return Error::Nonfatal("Incompatible colortype conversion"); 183 return Error::Nonfatal("Incompatible colortype conversion");
164 default: 184 default:
165 // Everything else is considered a failure. 185 // Everything else is considered a failure.
166 return SkStringPrintf("Couldn't getPixels %s.", fPath.c_str( )); 186 return SkStringPrintf("Couldn't getPixels %s.", fPath.c_str( ));
167 } 187 }
168 canvas->drawBitmap(bitmap, 0, 0); 188 canvas->drawBitmap(bitmap, 0, 0);
169 break; 189 break;
170 } 190 }
171 case kScanline_Mode: { 191 case kScanline_Mode: {
172 SkAutoTDelete<SkScanlineDecoder> scanlineDecoder( 192 SkAutoTDelete<SkScanlineDecoder> scanlineDecoder(
173 SkScanlineDecoder::NewFromData(encoded)); 193 start_scanline_decoder(encoded.get(), decodeInfo, colorPtr, colorCountPtr));
174 if (nullptr == scanlineDecoder || SkCodec::kSuccess != 194 if (nullptr == scanlineDecoder) {
175 scanlineDecoder->start(decodeInfo, nullptr, colorPtr, colorC ountPtr)) { 195 return Error::Nonfatal("Could not start top-down scanline decode r");
176 return Error::Nonfatal("Cannot use scanline decoder for all imag es");
177 } 196 }
178 197
179 const SkCodec::Result result = scanlineDecoder->getScanlines( 198 const SkCodec::Result result = scanlineDecoder->getScanlines(
180 bitmap.getAddr(0, 0), decodeInfo.height(), bitmap.rowBytes() ); 199 bitmap.getAddr(0, 0), decodeInfo.height(), bitmap.rowBytes() );
181 switch (result) { 200 switch (result) {
182 case SkCodec::kSuccess: 201 case SkCodec::kSuccess:
183 case SkCodec::kIncompleteInput: 202 case SkCodec::kIncompleteInput:
184 break; 203 break;
185 default: 204 default:
186 return SkStringPrintf("%s failed with error message %d", 205 return SkStringPrintf("%s failed with error message %d",
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 const int currentSubsetWidth = (col + 1 == divisor) ? 246 const int currentSubsetWidth = (col + 1 == divisor) ?
228 subsetWidth + extraX : subsetWidth; 247 subsetWidth + extraX : subsetWidth;
229 const int x = col * subsetWidth; 248 const int x = col * subsetWidth;
230 for (int row = 0; row < divisor; row++) { 249 for (int row = 0; row < divisor; row++) {
231 //currentSubsetHeight may be larger than subsetHeight for bo ttom subsets 250 //currentSubsetHeight may be larger than subsetHeight for bo ttom subsets
232 const int currentSubsetHeight = (row + 1 == divisor) ? 251 const int currentSubsetHeight = (row + 1 == divisor) ?
233 subsetHeight + extraY : subsetHeight; 252 subsetHeight + extraY : subsetHeight;
234 const int y = row * subsetHeight; 253 const int y = row * subsetHeight;
235 //create scanline decoder for each subset 254 //create scanline decoder for each subset
236 SkAutoTDelete<SkScanlineDecoder> subsetScanlineDecoder( 255 SkAutoTDelete<SkScanlineDecoder> subsetScanlineDecoder(
237 SkScanlineDecoder::NewFromData(encoded)); 256 start_scanline_decoder(encoded.get(), decodeInfo,
238 if (nullptr == subsetScanlineDecoder || SkCodec::kSuccess != 257 colorPtr, colorCountPtr));
239 subsetScanlineDecoder->start( 258 if (nullptr == subsetScanlineDecoder) {
240 decodeInfo, nullptr, colorPtr, colorCountPtr))
241 {
242 if (x == 0 && y == 0) { 259 if (x == 0 && y == 0) {
243 //first try, image may not be compatible 260 //first try, image may not be compatible
244 return Error::Nonfatal("Cannot use scanline decoder for all images"); 261 return Error::Nonfatal("Could not start top-down sca nline decoder");
245 } else { 262 } else {
246 return "Error scanline decoder is nullptr"; 263 return "Error scanline decoder is nullptr";
247 } 264 }
248 } 265 }
249 //skip to first line of subset 266 //skip to first line of subset
250 const SkCodec::Result skipResult = 267 const SkCodec::Result skipResult =
251 subsetScanlineDecoder->skipScanlines(y); 268 subsetScanlineDecoder->skipScanlines(y);
252 switch (skipResult) { 269 switch (skipResult) {
253 case SkCodec::kSuccess: 270 case SkCodec::kSuccess:
254 case SkCodec::kIncompleteInput: 271 case SkCodec::kIncompleteInput:
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 break; 314 break;
298 } 315 }
299 case kStripe_Mode: { 316 case kStripe_Mode: {
300 const int height = decodeInfo.height(); 317 const int height = decodeInfo.height();
301 // This value is chosen arbitrarily. We exercise more cases by choo sing a value that 318 // This value is chosen arbitrarily. We exercise more cases by choo sing a value that
302 // does not align with image blocks. 319 // does not align with image blocks.
303 const int stripeHeight = 37; 320 const int stripeHeight = 37;
304 const int numStripes = (height + stripeHeight - 1) / stripeHeight; 321 const int numStripes = (height + stripeHeight - 1) / stripeHeight;
305 322
306 // Decode odd stripes 323 // Decode odd stripes
307 SkAutoTDelete<SkScanlineDecoder> decoder(SkScanlineDecoder::NewFromD ata(encoded)); 324 SkAutoTDelete<SkScanlineDecoder> decoder(
308 if (nullptr == decoder || SkCodec::kSuccess != 325 start_scanline_decoder(encoded.get(), decodeInfo, colorPtr, colorCountPtr));
309 decoder->start(decodeInfo, nullptr, colorPtr, colorCountPtr) ) { 326 if (nullptr == decoder) {
310 return Error::Nonfatal("Cannot use scanline decoder for all imag es"); 327 return Error::Nonfatal("Could not start top-down scanline decode r");
311 } 328 }
312 for (int i = 0; i < numStripes; i += 2) { 329 for (int i = 0; i < numStripes; i += 2) {
313 // Skip a stripe 330 // Skip a stripe
314 const int linesToSkip = SkTMin(stripeHeight, height - i * stripe Height); 331 const int linesToSkip = SkTMin(stripeHeight, height - i * stripe Height);
315 SkCodec::Result result = decoder->skipScanlines(linesToSkip); 332 SkCodec::Result result = decoder->skipScanlines(linesToSkip);
316 switch (result) { 333 switch (result) {
317 case SkCodec::kSuccess: 334 case SkCodec::kSuccess:
318 case SkCodec::kIncompleteInput: 335 case SkCodec::kIncompleteInput:
319 break; 336 break;
320 default: 337 default:
(...skipping 743 matching lines...) Expand 10 before | Expand all | Expand 10 after
1064 skr.visit<void>(i, drawsAsSingletonPictures); 1081 skr.visit<void>(i, drawsAsSingletonPictures);
1065 } 1082 }
1066 SkAutoTUnref<SkPicture> macroPic(macroRec.endRecordingAsPicture()); 1083 SkAutoTUnref<SkPicture> macroPic(macroRec.endRecordingAsPicture());
1067 1084
1068 canvas->drawPicture(macroPic); 1085 canvas->drawPicture(macroPic);
1069 return ""; 1086 return "";
1070 }); 1087 });
1071 } 1088 }
1072 1089
1073 } // namespace DM 1090 } // namespace DM
OLDNEW
« no previous file with comments | « no previous file | include/codec/SkScanlineDecoder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698