aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--gyp/codec.gyp2
-rw-r--r--src/codec/SkCodecImageGenerator.cpp46
-rw-r--r--src/codec/SkCodecImageGenerator.h43
-rw-r--r--tests/CodexTest.cpp13
4 files changed, 104 insertions, 0 deletions
diff --git a/gyp/codec.gyp b/gyp/codec.gyp
index 3fa906fdc2..725b57a27b 100644
--- a/gyp/codec.gyp
+++ b/gyp/codec.gyp
@@ -55,6 +55,8 @@
'../src/codec/SkWbmpCodec.cpp',
'../src/codec/SkWebpAdapterCodec.cpp',
'../src/codec/SkWebpCodec.cpp',
+
+ '../src/codec/SkCodecImageGenerator.cpp',
],
'direct_dependent_settings': {
'include_dirs': [
diff --git a/src/codec/SkCodecImageGenerator.cpp b/src/codec/SkCodecImageGenerator.cpp
new file mode 100644
index 0000000000..2fef381ec1
--- /dev/null
+++ b/src/codec/SkCodecImageGenerator.cpp
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2015 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "SkCodecImageGenerator.h"
+
+SkImageGenerator* SkCodecImageGenerator::NewFromEncodedCodec(SkData* data) {
+ SkCodec* codec = SkCodec::NewFromData(data);
+ if (nullptr == codec) {
+ return nullptr;
+ }
+
+ return new SkCodecImageGenerator(codec, data);
+}
+
+SkCodecImageGenerator::SkCodecImageGenerator(SkCodec* codec, SkData* data)
+ : INHERITED(codec->getInfo())
+ , fCodec(codec)
+ , fData(SkRef(data))
+{}
+
+SkData* SkCodecImageGenerator::onRefEncodedData(SK_REFENCODEDDATA_CTXPARAM) {
+ return SkRef(fData.get());
+}
+
+bool SkCodecImageGenerator::onGetPixels(const SkImageInfo& info, void* pixels, size_t rowBytes,
+ SkPMColor ctable[], int* ctableCount) {
+
+ SkCodec::Result result = fCodec->getPixels(info, pixels, rowBytes, nullptr, ctable,
+ ctableCount);
+ switch (result) {
+ case SkCodec::kSuccess:
+ case SkCodec::kIncompleteInput:
+ return true;
+ default:
+ return false;
+ }
+}
+
+bool SkCodecImageGenerator::onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBytes[3],
+ SkYUVColorSpace* colorSpace) {
+ return false;
+}
diff --git a/src/codec/SkCodecImageGenerator.h b/src/codec/SkCodecImageGenerator.h
new file mode 100644
index 0000000000..80eacb19c8
--- /dev/null
+++ b/src/codec/SkCodecImageGenerator.h
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2015 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "SkCodec.h"
+#include "SkData.h"
+#include "SkImageGenerator.h"
+
+class SkCodecImageGenerator : public SkImageGenerator {
+public:
+ /*
+ * If this data represents an encoded image that we know how to decode,
+ * return an SkCodecImageGenerator. Otherwise return nullptr.
+ *
+ * Refs the data if an image generator can be returned. Otherwise does
+ * not affect the data.
+ */
+ static SkImageGenerator* NewFromEncodedCodec(SkData* data);
+
+protected:
+ SkData* onRefEncodedData(SK_REFENCODEDDATA_CTXPARAM) override;
+
+ bool onGetPixels(const SkImageInfo& info, void* pixels, size_t rowBytes, SkPMColor ctable[],
+ int* ctableCount) override;
+
+ bool onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBytes[3],
+ SkYUVColorSpace* colorSpace) override;
+
+private:
+ /*
+ * Takes ownership of codec
+ * Refs the data
+ */
+ SkCodecImageGenerator(SkCodec* codec, SkData* data);
+
+ SkAutoTDelete<SkCodec> fCodec;
+ SkAutoTUnref<SkData> fData;
+
+ typedef SkImageGenerator INHERITED;
+};
diff --git a/tests/CodexTest.cpp b/tests/CodexTest.cpp
index 96d03c1f12..2768d57cfc 100644
--- a/tests/CodexTest.cpp
+++ b/tests/CodexTest.cpp
@@ -9,6 +9,7 @@
#include "SkAndroidCodec.h"
#include "SkBitmap.h"
#include "SkCodec.h"
+#include "SkCodecImageGenerator.h"
#include "SkData.h"
#include "SkImageDecoder.h"
#include "SkMD5.h"
@@ -379,6 +380,18 @@ static void check(skiatest::Reporter* r,
&scaledCodecDigest, &codecDigest);
}
+ // Test SkCodecImageGenerator
+ if (!isIncomplete) {
+ SkAutoTDelete<SkStream> stream(resource(path));
+ SkAutoTUnref<SkData> fullData(SkData::NewFromStream(stream, stream->getLength()));
+ SkAutoTDelete<SkImageGenerator> gen(SkCodecImageGenerator::NewFromEncodedCodec(fullData));
+ SkBitmap bm;
+ bm.allocPixels(info);
+ SkAutoLockPixels autoLockPixels(bm);
+ REPORTER_ASSERT(r, gen->getPixels(info, bm.getPixels(), bm.rowBytes()));
+ compare_to_good_digest(r, codecDigest, bm);
+ }
+
// If we've just tested incomplete decodes, let's run the same test again on full decodes.
if (isIncomplete) {
check(r, path, size, supportsScanlineDecoding, supportsSubsetDecoding, false);