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

Unified Diff: include/codec/SkScanlineDecoder.h

Issue 1010903003: Add scanline decoding to SkCodec. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Small cleanups. Created 5 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: include/codec/SkScanlineDecoder.h
diff --git a/include/codec/SkScanlineDecoder.h b/include/codec/SkScanlineDecoder.h
new file mode 100644
index 0000000000000000000000000000000000000000..41fce26a8403d895b9fd6933857847b3f472b047
--- /dev/null
+++ b/include/codec/SkScanlineDecoder.h
@@ -0,0 +1,98 @@
+/*
+ * Copyright 2015 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef SkScanlineDecoder_DEFINED
+#define SkScanlineDecoder_DEFINED
+
+#include "SkTypes.h"
+#include "SkTemplates.h"
+#include "SkImageGenerator.h"
+#include "SkImageInfo.h"
+
+class SkScanlineDecoder : public SkNoncopyable {
+public:
+ // Note for implementations: An SkScanlineDecoder will be deleted by (and
+ // therefore *before*) its associated SkCodec, in case the order matters.
+ virtual ~SkScanlineDecoder() {}
+
+ /**
+ * Write the next countLines scanlines into dst.
+ *
+ * @param dst Must be non-null, and large enough to hold countLines
+ * scanlines of size rowBytes.
+ * @param countLines Number of lines to write.
+ * @param rowBytes Number of bytes per row. Must be large enough to hold
+ * a scanline based on the SkImageInfo used to create this object.
+ */
+ SkImageGenerator::Result getScanlines(void* dst, int countLines, size_t rowBytes) {
+ // Should we keep track of how many scanlines have been read, at
+ // least in debug mode? Then we can make an even smarter check
+ // regarding countLines.
+ if ((rowBytes < fDstInfo.minRowBytes() && countLines > 1 ) || countLines <= 0
+ || countLines > fDstInfo.height()) {
+ return SkImageGenerator::kInvalidParameters;
+ }
+ return this->onGetScanlines(dst, countLines, rowBytes);
+ }
+
+ /**
+ * Skip count scanlines.
+ *
+ * The default version just calls onGetScanlines and discards the dst.
+ * NOTE: If skipped lines are the only lines with alpha, this default
+ * will make reallyHasAlpha return true, when it could have returned
+ * false.
+ */
+ SkImageGenerator::Result skipScanlines(int count) {
+ return this->onSkipScanlines(count);
+ }
+
+ /**
+ * Call this function after reading/skipping all scanlines.
+ */
+ SkImageGenerator::Result finish() {
+ return this->onFinish();
+ }
+
+ /**
+ * Some images may initially report that they have alpha due to the format
+ * of the encoded data, but then never use any colors which have alpha
+ * less than 100%. This function can be called *after* decoding to
+ * determine if such an image truly had alpha. Calling it before decoding
+ * is undefined.
+ */
+ bool reallyHasAlpha() const {
+ return this->onReallyHasAlpha();
+ }
+
+protected:
+ SkScanlineDecoder(const SkImageInfo& requested)
+ : fDstInfo(requested) {}
+
+ virtual bool onReallyHasAlpha() const { return false; }
+
+private:
+ const SkImageInfo fDstInfo;
+
+ // Naive default version just calls onGetScanlines on temp memory.
+ virtual SkImageGenerator::Result onSkipScanlines(int count) {
+ SkAutoMalloc storage(fDstInfo.minRowBytes());
+ // Note that we pass 0 to rowBytes so we continue to use the same memory.
+ // Also note that while getScanlines checks that rowBytes is big enough,
+ // onGetScanlines bypasses that check.
+ return this->onGetScanlines(storage.get(), count, 0);
+ }
+
+ virtual SkImageGenerator::Result onGetScanlines(void* dst, int countLines,
+ size_t rowBytes) = 0;
+
+ virtual SkImageGenerator::Result onFinish() {
+ // Return success by default, since this may not be necessary for all codecs.
+ return SkImageGenerator::kSuccess;
+ }
+};
+#endif // SkScanlineDecoder_DEFINED
« include/codec/SkCodec.h ('K') | « include/codec/SkCodec.h ('k') | src/codec/SkCodec.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698