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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright 2013 Google Inc. 2 * Copyright 2013 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 #ifndef SkDecodingImageGenerator_DEFINED 8 #ifndef SkDecodingImageGenerator_DEFINED
9 #define SkDecodingImageGenerator_DEFINED 9 #define SkDecodingImageGenerator_DEFINED
10 10
11 #include "SkDiscardableMemory.h" 11 #include "SkBitmap.h"
12 #include "SkImageGenerator.h"
13 #include "SkImageInfo.h"
14 12
15 class SkBitmap; 13 class SkData;
14 class SkImageGenerator;
16 class SkStreamRewindable; 15 class SkStreamRewindable;
17 16
18 /** 17 /**
19 * Calls into SkImageDecoder::DecodeMemoryToTarget to implement a 18 * These options will be passed on to the image decoder. The
20 * SkImageGenerator 19 * defaults are sensible.
20 *
21 * @param fSampleSize If set to > 1, tells the decoder to return a
22 * smaller than original bitmap, sampling 1 pixel for
23 * every size pixels. e.g. if sample size is set to 3,
24 * then the returned bitmap will be 1/3 as wide and high,
25 * and will contain 1/9 as many pixels as the original.
26 * Note: this is a hint, and the codec may choose to
27 * ignore this, or only approximate the sample size.
28 *
29 * @param fDitherImage Set to true if the the decoder should try
30 * to dither the resulting image. The default is true.
31 *
32 * @param fRequestedConfig If SkBitmap::kNo_Config, then use
33 * whichever config the decoder wants. Else try to use
34 * this one. If this config won't work, calling getInfo()
35 * on the SkDecodingImageGenerator will return false.
21 */ 36 */
22 class SkDecodingImageGenerator : public SkImageGenerator { 37 struct SK_API SkDecoderOptions {
23 public: 38 SkDecoderOptions()
24 /* 39 : fSampleSize(1)
25 * The constructor will take a reference to the SkData. The 40 , fDitherImage(true)
26 * destructor will unref() it. 41 , fRequestedConfig(SkBitmap::kNo_Config) { }
27 */ 42 SkDecoderOptions(int sampleSize, bool dither, SkBitmap::Config config)
28 explicit SkDecodingImageGenerator(SkData* data); 43 : fSampleSize(sampleSize)
44 , fDitherImage(dither)
45 , fRequestedConfig(config) { }
46 SkDecoderOptions(const SkDecoderOptions& opts)
47 : fSampleSize(opts.fSampleSize)
48 , fDitherImage(opts.fDitherImage)
49 , fRequestedConfig(opts.fRequestedConfig) { }
50 const int fSampleSize;
51 const bool fDitherImage;
52 const SkBitmap::Config fRequestedConfig;
53 };
29 54
30 /* 55 /**
31 * The SkData version of this constructor is preferred. If the 56 * These two functions return a SkImageGenerator that calls into
32 * stream has an underlying SkData (such as a SkMemoryStream) 57 * SkImageDecoder. They return NULL on failure.
33 * pass that in. 58 *
34 * 59 * 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.
35 * This object will unref the stream when done. Since streams 60 * underlying SkData (such as a SkMemoryStream) pass that in.
36 * have internal state (position), the caller should not pass a 61 *
37 * shared stream in. Pass either a new duplicated stream in or 62 * 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.
38 * transfer ownership of the stream. In the latter case, be sure 63 * have internal state (position), the caller should not pass a
39 * that there are no other consumers of the stream who will 64 * shared stream in. Pass either a new duplicated stream in or
40 * modify the stream's position. This constructor asserts 65 * transfer ownership of the stream. In the latter case, be sure
41 * stream->unique(). 66 * 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?
42 * 67 * modify the stream's position. This factory asserts
43 * For example: 68 * stream->unique().
44 * SkStreamRewindable* stream; 69 *
45 * ... 70 * For example:
46 * SkImageGenerator* gen 71 * SkStreamRewindable* stream;
47 * = SkNEW_ARGS(SkDecodingImageGenerator, 72 * ...
48 * (stream->duplicate())); 73 * SkImageGenerator* gen
49 * ... 74 * = SkNewDecodingImageGenerator(
50 * SkDELETE(gen); 75 * stream->duplicate(), SkDecoderOptions());
51 */ 76 * ...
52 explicit SkDecodingImageGenerator(SkStreamRewindable* stream); 77 * SkDELETE(gen);
78 *
79 * @param SkDecoderOptions (see above)
80 *
81 * @return NULL on failure, a new SkImageGenerator on success.
82 */
83 SK_API SkImageGenerator* SkNewDecodingImageGenerator(SkData* data,
84 const SkDecoderOptions& opt );
53 85
54 virtual ~SkDecodingImageGenerator(); 86 /**
87 * @param data Contains the encoded image data that will be used by
88 * the SkDecodingImageGenerator. Will be ref()ed by the
89 * SkImageGenerator constructor and and unref()ed on deletion.
90 */
91 SK_API SkImageGenerator* SkNewDecodingImageGenerator(SkStreamRewindable* stream,
92 const SkDecoderOptions& opt );
93 // // Example of most basic use case:
94 //
95 // bool install_data(SkData* data, SkBitmap* dst) {
96 // return SkInstallDiscardablePixelRef(
97 // SkNewDecodingImageGenerator(data, SkDecoderOptions()), dst, NULL);
98 // }
99 // bool install_stream(SkStreamRewindable* stream, SkBitmap* dst) {
100 // return SkInstallDiscardablePixelRef(
101 // SkNewDecodingImageGenerator(stream, SkDecoderOptions()), dst, NULL);
102 // }
55 103
56 virtual SkData* refEncodedData() SK_OVERRIDE;
57
58 virtual bool getInfo(SkImageInfo* info) SK_OVERRIDE;
59
60 virtual bool getPixels(const SkImageInfo& info,
61 void* pixels,
62 size_t rowBytes) SK_OVERRIDE;
63
64 /**
65 * Install the SkData into the destination bitmap, using a new
66 * SkDiscardablePixelRef and a new SkDecodingImageGenerator.
67 *
68 * @param data Contains the encoded image data that will be used
69 * by the SkDecodingImageGenerator. Will be ref()ed.
70 *
71 * @param destination Upon success, this bitmap will be
72 * configured and have a pixelref installed.
73 *
74 * @param factory If not NULL, this object will be used as a
75 * source of discardable memory when decoding. If NULL, then
76 * SkDiscardableMemory::Create() will be called.
77 *
78 * @return true iff successful.
79 */
80 static bool Install(SkData* data, SkBitmap* destination,
81 SkDiscardableMemory::Factory* factory = NULL);
82 /**
83 * Install the stream into the destination bitmap, using a new
84 * SkDiscardablePixelRef and a new SkDecodingImageGenerator.
85 *
86 * The SkData version of this function is preferred. If the
87 * stream has an underlying SkData (such as a SkMemoryStream)
88 * pass that in.
89 *
90 * @param stream The source of encoded data that will be passed
91 * to the decoder. The installed SkDecodingImageGenerator will
92 * unref the stream when done. If false is returned, this
93 * function will perform the unref. Since streams have internal
94 * state (position), the caller should not pass a shared stream
95 * in. Pass either a new duplicated stream in or transfer
96 * ownership of the stream. In the latter case, be sure that
97 * there are no other consumers of the stream who will modify the
98 * stream's position. This function will fail if
99 * (!stream->unique()).
100 *
101 * @param destination Upon success, this bitmap will be
102 * configured and have a pixelref installed.
103 *
104 * @param factory If not NULL, this object will be used as a
105 * source of discardable memory when decoding. If NULL, then
106 * SkDiscardableMemory::Create() will be called.
107 *
108 * @return true iff successful.
109 */
110 static bool Install(SkStreamRewindable* stream, SkBitmap* destination,
111 SkDiscardableMemory::Factory* factory = NULL);
112
113 private:
114 SkData* fData;
115 SkStreamRewindable* fStream;
116 SkImageInfo fInfo;
117 bool fHasInfo;
118 bool fDoCopyTo;
119 };
120 #endif // SkDecodingImageGenerator_DEFINED 104 #endif // SkDecodingImageGenerator_DEFINED
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698