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

Side by Side Diff: dm/DMSrcSink.cpp

Issue 1240143002: Add the ability to decode a subset to SkCodec. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Update comment Created 5 years, 5 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
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 337 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 case SkCodec::kIncompleteInput: 348 case SkCodec::kIncompleteInput:
349 break; 349 break;
350 default: 350 default:
351 return SkStringPrintf("Cannot skip scanlines for %s. ", fPath.c_str()); 351 return SkStringPrintf("Cannot skip scanlines for %s. ", fPath.c_str());
352 } 352 }
353 } 353 }
354 } 354 }
355 canvas->drawBitmap(bitmap, 0, 0); 355 canvas->drawBitmap(bitmap, 0, 0);
356 break; 356 break;
357 } 357 }
358 case kSubset_Mode: {
359 // Arbitrarily choose a divisor.
360 int divisor = 2;
361 // Total width/height of the image.
362 const int W = codec->getInfo().width();
363 const int H = codec->getInfo().height();
364 if (divisor > W || divisor > H) {
365 return Error::Nonfatal(SkStringPrintf("Cannot codec subset: divi sor %d is too big "
366 "for %s with dimensions (% d x %d)", divisor,
367 fPath.c_str(), W, H));
368 }
369 // subset dimensions
370 // SkWebpCodec, the only one that supports subsets, requires even to p/left boundaries.
371 const int w = SkAlign2(W / divisor);
372 const int h = SkAlign2(H / divisor);
373 SkCodec::Options opts;
374 SkBitmap subsetBm;
375 // We will reuse pixel memory from bitmap.
376 void* pixels = bitmap.getPixels();
377 // Keep track of left and top (for drawing subsetBm into canvas). We could use
378 // fScale * x and fScale * y, but we want integers such that the nex t subset will start
379 // where the last one ended. So we'll add decodeInfo.width() and hei ght().
380 int left = 0;
381 for (int x = 0; x < W; x += w) {
382 int top = 0;
383 for (int y = 0; y < H; y+= h) {
384 // Do not make the subset go off the edge of the image.
385 const int preScaleW = SkTMin(w, W - x);
386 const int preScaleH = SkTMin(h, H - y);
387 opts.fSubset.setXYWH(x, y, preScaleW, preScaleH);
388 // And scale
389 decodeInfo = decodeInfo.makeWH(preScaleW * fScale, preScaleH * fScale);
390 size_t rowBytes = decodeInfo.minRowBytes();
391 if (!subsetBm.installPixels(decodeInfo, pixels, rowBytes, co lorTable.get(),
392 NULL, NULL)) {
393 return SkStringPrintf("could not install pixels for %s." , fPath.c_str());
394 }
395 const SkCodec::Result result = codec->getPixels(decodeInfo, pixels, rowBytes,
396 &opts, colorPtr, colorCountPtr);
397 switch (result) {
398 case SkCodec::kSuccess:
399 case SkCodec::kIncompleteInput:
400 break;
401 case SkCodec::kUnimplemented:
402 if (0 == (x|y)) {
403 // First subset is okay to return unimplemented.
404 return Error::Nonfatal("subset codec not support ed");
405 }
406 // If the first subset succeeded, why would a later one fail?
407 // fall through to failure
408 default:
409 return SkStringPrintf("subset codec failed to decode (%d, %d, %d, %d) "
410 "from %s with dimensions (%d x %d)\t error %d",
411 x, y, decodeInfo.width(), deco deInfo.height(),
412 fPath.c_str(), W, H, result);
413 }
414 canvas->drawBitmap(subsetBm, left, top);
415 // translate by the scaled height.
416 top += decodeInfo.height();
417 }
418 // translate by the scaled width.
419 left += decodeInfo.width();
420 }
421 return "";
422 }
358 } 423 }
359 return ""; 424 return "";
360 } 425 }
361 426
362 SkISize CodecSrc::size() const { 427 SkISize CodecSrc::size() const {
363 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str())); 428 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str()));
364 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded)); 429 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded));
365 if (NULL != codec) { 430 if (NULL != codec) {
366 SkISize size = codec->getScaledDimensions(fScale); 431 SkISize size = codec->getScaledDimensions(fScale);
367 return size; 432 return size;
(...skipping 621 matching lines...) Expand 10 before | Expand all | Expand 10 after
989 skr.visit<void>(i, drawsAsSingletonPictures); 1054 skr.visit<void>(i, drawsAsSingletonPictures);
990 } 1055 }
991 SkAutoTUnref<SkPicture> macroPic(macroRec.endRecordingAsPicture()); 1056 SkAutoTUnref<SkPicture> macroPic(macroRec.endRecordingAsPicture());
992 1057
993 canvas->drawPicture(macroPic); 1058 canvas->drawPicture(macroPic);
994 return ""; 1059 return "";
995 }); 1060 });
996 } 1061 }
997 1062
998 } // namespace DM 1063 } // namespace DM
OLDNEW
« no previous file with comments | « dm/DMSrcSink.h ('k') | include/codec/SkCodec.h » ('j') | include/codec/SkCodec.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698