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

Side by Side Diff: dm/DMSrcSink.cpp

Issue 1267583002: Create a scanline decoder without creating a codec (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix interlaced 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 | « bench/subset/SubsetZoomBench.cpp ('k') | gyp/codec.gyp » ('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 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 case SkCodec::kInvalidConversion: 152 case SkCodec::kInvalidConversion:
153 return Error::Nonfatal("Incompatible colortype conversion"); 153 return Error::Nonfatal("Incompatible colortype conversion");
154 default: 154 default:
155 // Everything else is considered a failure. 155 // Everything else is considered a failure.
156 return SkStringPrintf("Couldn't getPixels %s.", fPath.c_str( )); 156 return SkStringPrintf("Couldn't getPixels %s.", fPath.c_str( ));
157 } 157 }
158 canvas->drawBitmap(bitmap, 0, 0); 158 canvas->drawBitmap(bitmap, 0, 0);
159 break; 159 break;
160 } 160 }
161 case kScanline_Mode: { 161 case kScanline_Mode: {
162 SkAutoTDelete<SkScanlineDecoder> scanlineDecoder(codec->getScanlineD ecoder( 162 SkAutoTDelete<SkScanlineDecoder> scanlineDecoder(
163 decodeInfo, NULL, colorPtr, colorCountPtr)); 163 SkScanlineDecoder::NewFromData(encoded));
164 if (NULL == scanlineDecoder) { 164 if (NULL == scanlineDecoder || SkCodec::kSuccess !=
165 scanlineDecoder->start(decodeInfo, NULL, colorPtr, colorCoun tPtr)) {
165 return Error::Nonfatal("Cannot use scanline decoder for all imag es"); 166 return Error::Nonfatal("Cannot use scanline decoder for all imag es");
166 } 167 }
168
167 const SkCodec::Result result = scanlineDecoder->getScanlines( 169 const SkCodec::Result result = scanlineDecoder->getScanlines(
168 bitmap.getAddr(0, 0), decodeInfo.height(), bitmap.rowBytes() ); 170 bitmap.getAddr(0, 0), decodeInfo.height(), bitmap.rowBytes() );
169 switch (result) { 171 switch (result) {
170 case SkCodec::kSuccess: 172 case SkCodec::kSuccess:
171 case SkCodec::kIncompleteInput: 173 case SkCodec::kIncompleteInput:
172 break; 174 break;
173 default: 175 default:
174 return SkStringPrintf("%s failed with error message %d", 176 return SkStringPrintf("%s failed with error message %d",
175 fPath.c_str(), (int) result); 177 fPath.c_str(), (int) result);
176 } 178 }
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 const int currentSubsetWidth = (col + 1 == divisor) ? 217 const int currentSubsetWidth = (col + 1 == divisor) ?
216 subsetWidth + extraX : subsetWidth; 218 subsetWidth + extraX : subsetWidth;
217 const int x = col * subsetWidth; 219 const int x = col * subsetWidth;
218 for (int row = 0; row < divisor; row++) { 220 for (int row = 0; row < divisor; row++) {
219 //currentSubsetHeight may be larger than subsetHeight for bo ttom subsets 221 //currentSubsetHeight may be larger than subsetHeight for bo ttom subsets
220 const int currentSubsetHeight = (row + 1 == divisor) ? 222 const int currentSubsetHeight = (row + 1 == divisor) ?
221 subsetHeight + extraY : subsetHeight; 223 subsetHeight + extraY : subsetHeight;
222 const int y = row * subsetHeight; 224 const int y = row * subsetHeight;
223 //create scanline decoder for each subset 225 //create scanline decoder for each subset
224 SkAutoTDelete<SkScanlineDecoder> subsetScanlineDecoder( 226 SkAutoTDelete<SkScanlineDecoder> subsetScanlineDecoder(
225 codec->getScanlineDecoder(decodeInfo, NULL, colorPtr , colorCountPtr)); 227 SkScanlineDecoder::NewFromData(encoded));
226 if (NULL == subsetScanlineDecoder) { 228 if (NULL == subsetScanlineDecoder || SkCodec::kSuccess !=
229 subsetScanlineDecoder->start(
230 decodeInfo, NULL, colorPtr, colorCountPtr))
231 {
227 if (x == 0 && y == 0) { 232 if (x == 0 && y == 0) {
228 //first try, image may not be compatible 233 //first try, image may not be compatible
229 return Error::Nonfatal("Cannot use scanline decoder for all images"); 234 return Error::Nonfatal("Cannot use scanline decoder for all images");
230 } else { 235 } else {
231 return "Error scanline decoder is NULL"; 236 return "Error scanline decoder is NULL";
232 } 237 }
233 } 238 }
234 //skip to first line of subset 239 //skip to first line of subset
235 const SkCodec::Result skipResult = 240 const SkCodec::Result skipResult =
236 subsetScanlineDecoder->skipScanlines(y); 241 subsetScanlineDecoder->skipScanlines(y);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 break; 287 break;
283 } 288 }
284 case kStripe_Mode: { 289 case kStripe_Mode: {
285 const int height = decodeInfo.height(); 290 const int height = decodeInfo.height();
286 // This value is chosen arbitrarily. We exercise more cases by choo sing a value that 291 // This value is chosen arbitrarily. We exercise more cases by choo sing a value that
287 // does not align with image blocks. 292 // does not align with image blocks.
288 const int stripeHeight = 37; 293 const int stripeHeight = 37;
289 const int numStripes = (height + stripeHeight - 1) / stripeHeight; 294 const int numStripes = (height + stripeHeight - 1) / stripeHeight;
290 295
291 // Decode odd stripes 296 // Decode odd stripes
292 SkAutoTDelete<SkScanlineDecoder> decoder( 297 SkAutoTDelete<SkScanlineDecoder> decoder(SkScanlineDecoder::NewFromD ata(encoded));
293 codec->getScanlineDecoder(decodeInfo, NULL, colorPtr, colorC ountPtr)); 298 if (NULL == decoder || SkCodec::kSuccess !=
294 if (NULL == decoder) { 299 decoder->start(decodeInfo, NULL, colorPtr, colorCountPtr)) {
295 return Error::Nonfatal("Cannot use scanline decoder for all imag es"); 300 return Error::Nonfatal("Cannot use scanline decoder for all imag es");
296 } 301 }
297 for (int i = 0; i < numStripes; i += 2) { 302 for (int i = 0; i < numStripes; i += 2) {
298 // Skip a stripe 303 // Skip a stripe
299 const int linesToSkip = SkTMin(stripeHeight, height - i * stripe Height); 304 const int linesToSkip = SkTMin(stripeHeight, height - i * stripe Height);
300 SkCodec::Result result = decoder->skipScanlines(linesToSkip); 305 SkCodec::Result result = decoder->skipScanlines(linesToSkip);
301 switch (result) { 306 switch (result) {
302 case SkCodec::kSuccess: 307 case SkCodec::kSuccess:
303 case SkCodec::kIncompleteInput: 308 case SkCodec::kIncompleteInput:
304 break; 309 break;
(...skipping 11 matching lines...) Expand all
316 case SkCodec::kSuccess: 321 case SkCodec::kSuccess:
317 case SkCodec::kIncompleteInput: 322 case SkCodec::kIncompleteInput:
318 break; 323 break;
319 default: 324 default:
320 return SkStringPrintf("Cannot get scanlines for %s." , fPath.c_str()); 325 return SkStringPrintf("Cannot get scanlines for %s." , fPath.c_str());
321 } 326 }
322 } 327 }
323 } 328 }
324 329
325 // Decode even stripes 330 // Decode even stripes
326 decoder.reset(codec->getScanlineDecoder(decodeInfo, NULL, colorPtr, colorCountPtr)); 331 const SkCodec::Result startResult = decoder->start(decodeInfo, NULL, colorPtr,
327 if (NULL == decoder) { 332 colorCountPtr);
328 return "Failed to create second scanline decoder."; 333 if (SkCodec::kSuccess != startResult) {
334 return "Failed to restart scanline decoder with same parameters. ";
329 } 335 }
330 for (int i = 0; i < numStripes; i += 2) { 336 for (int i = 0; i < numStripes; i += 2) {
331 // Read a stripe 337 // Read a stripe
332 const int startY = i * stripeHeight; 338 const int startY = i * stripeHeight;
333 const int linesToRead = SkTMin(stripeHeight, height - startY); 339 const int linesToRead = SkTMin(stripeHeight, height - startY);
334 SkCodec::Result result = decoder->getScanlines(bitmap.getAddr(0, startY), 340 SkCodec::Result result = decoder->getScanlines(bitmap.getAddr(0, startY),
335 linesToRead, bitmap.rowBytes()); 341 linesToRead, bitmap.rowBytes());
336 switch (result) { 342 switch (result) {
337 case SkCodec::kSuccess: 343 case SkCodec::kSuccess:
338 case SkCodec::kIncompleteInput: 344 case SkCodec::kIncompleteInput:
(...skipping 730 matching lines...) Expand 10 before | Expand all | Expand 10 after
1069 skr.visit<void>(i, drawsAsSingletonPictures); 1075 skr.visit<void>(i, drawsAsSingletonPictures);
1070 } 1076 }
1071 SkAutoTUnref<SkPicture> macroPic(macroRec.endRecordingAsPicture()); 1077 SkAutoTUnref<SkPicture> macroPic(macroRec.endRecordingAsPicture());
1072 1078
1073 canvas->drawPicture(macroPic); 1079 canvas->drawPicture(macroPic);
1074 return ""; 1080 return "";
1075 }); 1081 });
1076 } 1082 }
1077 1083
1078 } // namespace DM 1084 } // namespace DM
OLDNEW
« no previous file with comments | « bench/subset/SubsetZoomBench.cpp ('k') | gyp/codec.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698