aboutsummaryrefslogtreecommitdiffhomepage
path: root/dm
diff options
context:
space:
mode:
authorGravatar emmaleer <emmaleer@google.com>2015-08-14 07:44:46 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2015-08-14 07:44:46 -0700
commit8f4ba76742c329bc4d5e1b8ca376d27922bd00b1 (patch)
treeee3b69a6972cb3e16e4c0e85723477bea9dd5387 /dm
parent1bef9f59c566cc54c2259cc4d0171c115157cd1c (diff)
SkScaledCodec class
This class does scaling by using a scanlineDecoder. getScanlines and skipScanlines are used for y sampling, the swizzler is used for x sampling this class is currently only working for png and jpeg images I will update other Codec types to work soon For SkJpegCodec to implement width wise swizzling it now uses a swizzler. I ran performance tests on this change. Here are the performance test results: https://docs.google.com/a/google.com/spreadsheets/d/1D7-Q_GXD_dI68LZO005NNvb8Wq2Ee0wEBEPG72671yw/edit?usp=sharing BUG=skia: Committed: https://skia.googlesource.com/skia/+/0944100ac89f797714eeae0cf2875e2335ff52ee Committed: https://skia.googlesource.com/skia/+/d518ea7927f9f4e0ed5b4134d1b4f48243855a47 Committed: https://skia.googlesource.com/skia/+/b157917507d4f7d2651f0aeb566d31603cc02240 Review URL: https://codereview.chromium.org/1260673002
Diffstat (limited to 'dm')
-rw-r--r--dm/DM.cpp7
-rw-r--r--dm/DMSrcSink.cpp24
2 files changed, 22 insertions, 9 deletions
diff --git a/dm/DM.cpp b/dm/DM.cpp
index 9dcdff1a0f..fe096434c6 100644
--- a/dm/DM.cpp
+++ b/dm/DM.cpp
@@ -212,7 +212,12 @@ static void push_codec_srcs(Path path) {
// TODO (msarett): Add more scaling tests as we implement more flexible scaling.
// TODO (msarett): Implement scaling tests for SkImageDecoder in order to compare with these
// tests. SkImageDecoder supports downscales by integer factors.
- const float scales[] = { 0.125f, 0.25f, 0.375f, 0.5f, 0.625f, 0.750f, 0.875f, 1.0f };
+ // SkJpegCodec natively supports scaling to: 0.125, 0.25, 0.375, 0.5, 0.625, 0.75, 0.875
+ // 0.1, 0.16, 0.2 etc allow us to test SkScaledCodec with sampleSize 10, 6, 5, etc
+ // 0.4, 0.7 etc allow to test what happens when the client requests a scale that
+ // does not exactly match a sampleSize or native scaling capability
+ const float scales[] = { 0.1f, 0.125f, 0.166f, 0.2f, 0.25f, 0.333f, 0.375f, 0.4f, 0.5f, 0.6f,
+ 0.625f, 0.750f, 0.8f, 0.875f, 1.0f };
for (float scale : scales) {
if (scale != 1.0f && (path.endsWith(".webp") || path.endsWith(".WEBP"))) {
diff --git a/dm/DMSrcSink.cpp b/dm/DMSrcSink.cpp
index f555b9fcbd..9826f97822 100644
--- a/dm/DMSrcSink.cpp
+++ b/dm/DMSrcSink.cpp
@@ -27,6 +27,7 @@
#include "SkScanlineDecoder.h"
#include "SkStream.h"
#include "SkXMLWriter.h"
+#include "SkScaledCodec.h"
DEFINE_bool(multiPage, false, "For document-type backends, render the source"
" into multiple pages");
@@ -84,9 +85,13 @@ Error CodecSrc::draw(SkCanvas* canvas) const {
if (!encoded) {
return SkStringPrintf("Couldn't read %s.", fPath.c_str());
}
- SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded));
+ SkAutoTDelete<SkCodec> codec(SkScaledCodec::NewFromData(encoded));
if (NULL == codec.get()) {
- return SkStringPrintf("Couldn't create codec for %s.", fPath.c_str());
+ // scaledCodec not supported, try normal codec
+ codec.reset(SkCodec::NewFromData(encoded));
+ if (NULL == codec.get()) {
+ return SkStringPrintf("Couldn't create codec for %s.", fPath.c_str());
+ }
}
// Choose the color type to decode to
@@ -446,13 +451,16 @@ Error CodecSrc::draw(SkCanvas* canvas) const {
SkISize CodecSrc::size() const {
SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str()));
- SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded));
- if (NULL != codec) {
- SkISize size = codec->getScaledDimensions(fScale);
- return size;
- } else {
- return SkISize::Make(0, 0);
+ SkAutoTDelete<SkCodec> codec(SkScaledCodec::NewFromData(encoded));
+ if (NULL == codec) {
+ // scaledCodec not supported, try regular codec
+ codec.reset(SkCodec::NewFromData(encoded));
+ if (NULL == codec) {
+ return SkISize::Make(0, 0);
+ }
}
+ SkISize size = codec->getScaledDimensions(fScale);
+ return size;
}
Name CodecSrc::name() const {