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

Unified Diff: src/images/SkDecodingImageGenerator.h

Issue 93703004: Change SkDecodingImageGenerator API (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: 1 Created 7 years 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: src/images/SkDecodingImageGenerator.h
diff --git a/src/images/SkDecodingImageGenerator.h b/src/images/SkDecodingImageGenerator.h
index dba234bcf19c400d5a005c5c5ac4efe057733267..c4c5373678f22a7a3da12a59f78ad0fffac6d442 100644
--- a/src/images/SkDecodingImageGenerator.h
+++ b/src/images/SkDecodingImageGenerator.h
@@ -8,113 +8,97 @@
#ifndef SkDecodingImageGenerator_DEFINED
#define SkDecodingImageGenerator_DEFINED
-#include "SkDiscardableMemory.h"
-#include "SkImageGenerator.h"
-#include "SkImageInfo.h"
+#include "SkBitmap.h"
-class SkBitmap;
+class SkData;
+class SkImageGenerator;
class SkStreamRewindable;
/**
- * Calls into SkImageDecoder::DecodeMemoryToTarget to implement a
- * SkImageGenerator
+ * These options will be passed on to the image decoder. The
+ * defaults are sensible.
+ *
+ * @param fSampleSize If set to > 1, tells the decoder to return a
+ * smaller than original bitmap, sampling 1 pixel for
+ * every size pixels. e.g. if sample size is set to 3,
+ * then the returned bitmap will be 1/3 as wide and high,
+ * and will contain 1/9 as many pixels as the original.
+ * Note: this is a hint, and the codec may choose to
+ * ignore this, or only approximate the sample size.
+ *
+ * @param fDitherImage Set to true if the the decoder should try
+ * to dither the resulting image. The default is true.
+ *
+ * @param fRequestedConfig If SkBitmap::kNo_Config, then use
+ * whichever config the decoder wants. Else try to use
+ * this one. If this config won't work, calling getInfo()
+ * on the SkDecodingImageGenerator will return false.
*/
-class SkDecodingImageGenerator : public SkImageGenerator {
-public:
- /*
- * The constructor will take a reference to the SkData. The
- * destructor will unref() it.
- */
- explicit SkDecodingImageGenerator(SkData* data);
-
- /*
- * The SkData version of this constructor is preferred. If the
- * stream has an underlying SkData (such as a SkMemoryStream)
- * pass that in.
- *
- * This object will unref the stream when done. Since streams
- * have internal state (position), the caller should not pass a
- * shared stream in. Pass either a new duplicated stream in or
- * transfer ownership of the stream. In the latter case, be sure
- * that there are no other consumers of the stream who will
- * modify the stream's position. This constructor asserts
- * stream->unique().
- *
- * For example:
- * SkStreamRewindable* stream;
- * ...
- * SkImageGenerator* gen
- * = SkNEW_ARGS(SkDecodingImageGenerator,
- * (stream->duplicate()));
- * ...
- * SkDELETE(gen);
- */
- explicit SkDecodingImageGenerator(SkStreamRewindable* stream);
-
- virtual ~SkDecodingImageGenerator();
-
- virtual SkData* refEncodedData() SK_OVERRIDE;
-
- virtual bool getInfo(SkImageInfo* info) SK_OVERRIDE;
+struct SK_API SkDecoderOptions {
+ SkDecoderOptions()
+ : fSampleSize(1)
+ , fDitherImage(true)
+ , fRequestedConfig(SkBitmap::kNo_Config) { }
+ SkDecoderOptions(int sampleSize, bool dither, SkBitmap::Config config)
+ : fSampleSize(sampleSize)
+ , fDitherImage(dither)
+ , fRequestedConfig(config) { }
+ SkDecoderOptions(const SkDecoderOptions& opts)
+ : fSampleSize(opts.fSampleSize)
+ , fDitherImage(opts.fDitherImage)
+ , fRequestedConfig(opts.fRequestedConfig) { }
+ const int fSampleSize;
+ const bool fDitherImage;
+ const SkBitmap::Config fRequestedConfig;
+};
- virtual bool getPixels(const SkImageInfo& info,
- void* pixels,
- size_t rowBytes) SK_OVERRIDE;
+/**
+ * These two functions return a SkImageGenerator that calls into
+ * SkImageDecoder. They return NULL on failure.
+ *
+ * The SkData version of is preferred. If the stream has an
scroggo 2013/12/13 17:23:03 of is?
hal.canary 2013/12/16 15:10:27 Done.
+ * underlying SkData (such as a SkMemoryStream) pass that in.
+ *
+ * This object will unref the stream when done. Since streams
scroggo 2013/12/13 17:23:03 Can you be more specific that it will also unref t
hal.canary 2013/12/16 15:10:27 Done.
+ * have internal state (position), the caller should not pass a
+ * shared stream in. Pass either a new duplicated stream in or
+ * transfer ownership of the stream. In the latter case, be sure
+ * that there are no other consumers of the stream who will
scroggo 2013/12/13 17:23:03 Isn't that redundant with passing ownership?
+ * modify the stream's position. This factory asserts
+ * stream->unique().
+ *
+ * For example:
+ * SkStreamRewindable* stream;
+ * ...
+ * SkImageGenerator* gen
+ * = SkNewDecodingImageGenerator(
+ * stream->duplicate(), SkDecoderOptions());
+ * ...
+ * SkDELETE(gen);
+ *
+ * @param SkDecoderOptions (see above)
+ *
+ * @return NULL on failure, a new SkImageGenerator on success.
+ */
+SK_API SkImageGenerator* SkNewDecodingImageGenerator(SkData* data,
+ const SkDecoderOptions& opt);
- /**
- * Install the SkData into the destination bitmap, using a new
- * SkDiscardablePixelRef and a new SkDecodingImageGenerator.
- *
- * @param data Contains the encoded image data that will be used
- * by the SkDecodingImageGenerator. Will be ref()ed.
- *
- * @param destination Upon success, this bitmap will be
- * configured and have a pixelref installed.
- *
- * @param factory If not NULL, this object will be used as a
- * source of discardable memory when decoding. If NULL, then
- * SkDiscardableMemory::Create() will be called.
- *
- * @return true iff successful.
- */
- static bool Install(SkData* data, SkBitmap* destination,
- SkDiscardableMemory::Factory* factory = NULL);
- /**
- * Install the stream into the destination bitmap, using a new
- * SkDiscardablePixelRef and a new SkDecodingImageGenerator.
- *
- * The SkData version of this function is preferred. If the
- * stream has an underlying SkData (such as a SkMemoryStream)
- * pass that in.
- *
- * @param stream The source of encoded data that will be passed
- * to the decoder. The installed SkDecodingImageGenerator will
- * unref the stream when done. If false is returned, this
- * function will perform the unref. Since streams have internal
- * state (position), the caller should not pass a shared stream
- * in. Pass either a new duplicated stream in or transfer
- * ownership of the stream. In the latter case, be sure that
- * there are no other consumers of the stream who will modify the
- * stream's position. This function will fail if
- * (!stream->unique()).
- *
- * @param destination Upon success, this bitmap will be
- * configured and have a pixelref installed.
- *
- * @param factory If not NULL, this object will be used as a
- * source of discardable memory when decoding. If NULL, then
- * SkDiscardableMemory::Create() will be called.
- *
- * @return true iff successful.
- */
- static bool Install(SkStreamRewindable* stream, SkBitmap* destination,
- SkDiscardableMemory::Factory* factory = NULL);
+/**
+ * @param data Contains the encoded image data that will be used by
+ * the SkDecodingImageGenerator. Will be ref()ed by the
+ * SkImageGenerator constructor and and unref()ed on deletion.
+ */
+SK_API SkImageGenerator* SkNewDecodingImageGenerator(SkStreamRewindable* stream,
+ const SkDecoderOptions& opt);
+// // Example of most basic use case:
+//
+// bool install_data(SkData* data, SkBitmap* dst) {
+// return SkInstallDiscardablePixelRef(
+// SkNewDecodingImageGenerator(data, SkDecoderOptions()), dst, NULL);
+// }
+// bool install_stream(SkStreamRewindable* stream, SkBitmap* dst) {
+// return SkInstallDiscardablePixelRef(
+// SkNewDecodingImageGenerator(stream, SkDecoderOptions()), dst, NULL);
+// }
-private:
- SkData* fData;
- SkStreamRewindable* fStream;
- SkImageInfo fInfo;
- bool fHasInfo;
- bool fDoCopyTo;
-};
#endif // SkDecodingImageGenerator_DEFINED

Powered by Google App Engine
This is Rietveld 408576698