Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "SkBitmap.h" | |
| 11 #include "SkDiscardableMemory.h" | 12 #include "SkDiscardableMemory.h" |
| 12 #include "SkImageGenerator.h" | 13 #include "SkImageGenerator.h" |
| 13 #include "SkImageInfo.h" | 14 #include "SkImageInfo.h" |
| 14 | 15 |
| 15 class SkBitmap; | |
| 16 class SkStreamRewindable; | 16 class SkStreamRewindable; |
| 17 | 17 |
| 18 /** | 18 /** |
| 19 * Calls into SkImageDecoder::DecodeMemoryToTarget to implement a | 19 * Calls into SkImageDecoder::DecodeMemoryToTarget to implement a |
| 20 * SkImageGenerator | 20 * SkImageGenerator |
| 21 */ | 21 */ |
| 22 class SkDecodingImageGenerator : public SkImageGenerator { | 22 class SkDecodingImageGenerator : public SkImageGenerator { |
| 23 public: | 23 public: |
| 24 struct Options; | |
|
scroggo
2013/12/12 22:33:46
Perhaps a note here to look down below?
hal.canary
2013/12/13 15:48:48
Done. Moved Options to the top.
| |
| 24 /* | 25 /* |
| 25 * The constructor will take a reference to the SkData. The | 26 * The constructor will take a reference to the SkData. The |
| 26 * destructor will unref() it. | 27 * destructor will unref() it. |
| 28 * | |
| 29 * @param Options if NULL, use defaults; | |
| 27 */ | 30 */ |
| 28 explicit SkDecodingImageGenerator(SkData* data); | 31 SkDecodingImageGenerator(SkData* data, const Options* opts); |
|
scroggo
2013/12/12 22:33:46
I like your thinking here, to allow opts to be NUL
hal.canary
2013/12/13 15:48:48
Done.
| |
| 29 | 32 |
| 30 /* | 33 /* |
| 31 * The SkData version of this constructor is preferred. If the | 34 * The SkData version of this constructor is preferred. If the |
| 32 * stream has an underlying SkData (such as a SkMemoryStream) | 35 * stream has an underlying SkData (such as a SkMemoryStream) |
| 33 * pass that in. | 36 * pass that in. |
| 34 * | 37 * |
| 35 * This object will unref the stream when done. Since streams | 38 * This object will unref the stream when done. Since streams |
| 36 * have internal state (position), the caller should not pass a | 39 * have internal state (position), the caller should not pass a |
| 37 * shared stream in. Pass either a new duplicated stream in or | 40 * shared stream in. Pass either a new duplicated stream in or |
| 38 * transfer ownership of the stream. In the latter case, be sure | 41 * transfer ownership of the stream. In the latter case, be sure |
| 39 * that there are no other consumers of the stream who will | 42 * that there are no other consumers of the stream who will |
| 40 * modify the stream's position. This constructor asserts | 43 * modify the stream's position. This constructor asserts |
| 41 * stream->unique(). | 44 * stream->unique(). |
| 42 * | 45 * |
| 43 * For example: | 46 * For example: |
| 44 * SkStreamRewindable* stream; | 47 * SkStreamRewindable* stream; |
| 45 * ... | 48 * ... |
| 46 * SkImageGenerator* gen | 49 * SkImageGenerator* gen |
| 47 * = SkNEW_ARGS(SkDecodingImageGenerator, | 50 * = SkNEW_ARGS(SkDecodingImageGenerator, |
| 48 * (stream->duplicate())); | 51 * (stream->duplicate())); |
| 49 * ... | 52 * ... |
| 50 * SkDELETE(gen); | 53 * SkDELETE(gen); |
| 54 * | |
| 55 * @param Options if NULL, use defaults; | |
| 51 */ | 56 */ |
| 52 explicit SkDecodingImageGenerator(SkStreamRewindable* stream); | 57 SkDecodingImageGenerator(SkStreamRewindable* stream, |
|
scroggo
2013/12/12 22:33:46
Do these get called directly? Or do callers call I
hal.canary
2013/12/13 15:48:48
I'm in the process of eliminating that use case.
| |
| 58 const Options* opts); | |
| 53 | 59 |
| 54 virtual ~SkDecodingImageGenerator(); | 60 virtual ~SkDecodingImageGenerator(); |
| 55 | 61 |
| 56 virtual SkData* refEncodedData() SK_OVERRIDE; | 62 virtual SkData* refEncodedData() SK_OVERRIDE; |
| 57 | 63 |
| 58 virtual bool getInfo(SkImageInfo* info) SK_OVERRIDE; | 64 virtual bool getInfo(SkImageInfo* info) SK_OVERRIDE; |
| 59 | 65 |
| 60 virtual bool getPixels(const SkImageInfo& info, | 66 virtual bool getPixels(const SkImageInfo& info, |
| 61 void* pixels, | 67 void* pixels, |
| 62 size_t rowBytes) SK_OVERRIDE; | 68 size_t rowBytes) SK_OVERRIDE; |
| 63 | 69 |
| 64 /** | 70 /** |
| 65 * Install the SkData into the destination bitmap, using a new | 71 * Install the SkData into the destination bitmap, using a new |
| 66 * SkDiscardablePixelRef and a new SkDecodingImageGenerator. | 72 * SkDiscardablePixelRef and a new SkDecodingImageGenerator. |
| 67 * | 73 * |
| 68 * @param data Contains the encoded image data that will be used | 74 * @param data Contains the encoded image data that will be used |
| 69 * by the SkDecodingImageGenerator. Will be ref()ed. | 75 * by the SkDecodingImageGenerator. Will be ref()ed. |
| 70 * | 76 * |
| 71 * @param destination Upon success, this bitmap will be | 77 * @param destination Upon success, this bitmap will be |
| 72 * configured and have a pixelref installed. | 78 * configured and have a pixelref installed. |
| 73 * | 79 * |
| 74 * @param factory If not NULL, this object will be used as a | 80 * @param factory If not NULL, this object will be used as a |
| 75 * source of discardable memory when decoding. If NULL, then | 81 * source of discardable memory when decoding. If NULL, then |
| 76 * SkDiscardableMemory::Create() will be called. | 82 * SkDiscardableMemory::Create() will be called. |
| 77 * | 83 * |
| 78 * @return true iff successful. | 84 * @return true iff successful. |
| 79 */ | 85 */ |
| 80 static bool Install(SkData* data, SkBitmap* destination, | 86 static bool Install(SkData* data, SkBitmap* destination, |
| 87 const Options* opts, | |
| 81 SkDiscardableMemory::Factory* factory = NULL); | 88 SkDiscardableMemory::Factory* factory = NULL); |
| 82 /** | 89 /** |
| 83 * Install the stream into the destination bitmap, using a new | 90 * Install the stream into the destination bitmap, using a new |
| 84 * SkDiscardablePixelRef and a new SkDecodingImageGenerator. | 91 * SkDiscardablePixelRef and a new SkDecodingImageGenerator. |
| 85 * | 92 * |
| 86 * The SkData version of this function is preferred. If the | 93 * The SkData version of this function is preferred. If the |
| 87 * stream has an underlying SkData (such as a SkMemoryStream) | 94 * stream has an underlying SkData (such as a SkMemoryStream) |
| 88 * pass that in. | 95 * pass that in. |
| 89 * | 96 * |
| 90 * @param stream The source of encoded data that will be passed | 97 * @param stream The source of encoded data that will be passed |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 101 * @param destination Upon success, this bitmap will be | 108 * @param destination Upon success, this bitmap will be |
| 102 * configured and have a pixelref installed. | 109 * configured and have a pixelref installed. |
| 103 * | 110 * |
| 104 * @param factory If not NULL, this object will be used as a | 111 * @param factory If not NULL, this object will be used as a |
| 105 * source of discardable memory when decoding. If NULL, then | 112 * source of discardable memory when decoding. If NULL, then |
| 106 * SkDiscardableMemory::Create() will be called. | 113 * SkDiscardableMemory::Create() will be called. |
| 107 * | 114 * |
| 108 * @return true iff successful. | 115 * @return true iff successful. |
| 109 */ | 116 */ |
| 110 static bool Install(SkStreamRewindable* stream, SkBitmap* destination, | 117 static bool Install(SkStreamRewindable* stream, SkBitmap* destination, |
| 118 const Options* opts, | |
| 111 SkDiscardableMemory::Factory* factory = NULL); | 119 SkDiscardableMemory::Factory* factory = NULL); |
| 112 | 120 |
| 121 /** | |
| 122 * These options will be passed on to the image decoder. The | |
| 123 * defaults are sensible. | |
| 124 * | |
| 125 * @param fSampleSize If set to > 1, tells the decoder to return a | |
| 126 * smaller than original bitmap, sampling 1 pixel for | |
| 127 * every size pixels. e.g. if sample size is set to 3, | |
| 128 * then the returned bitmap will be 1/3 as wide and high, | |
| 129 * and will contain 1/9 as many pixels as the original. | |
| 130 * Note: this is a hint, and the codec may choose to | |
| 131 * ignore this, or only approximate the sample size. | |
| 132 * | |
| 133 * @param fDitherImage Set to true if the the decoder should try | |
| 134 * to dither the resulting image. The default is true. | |
| 135 * | |
| 136 * @param fPreferQualityOverSpeed Should the decoder should try to | |
|
scroggo
2013/12/12 22:33:46
Whether*
hal.canary
2013/12/13 15:48:48
removed this param, as per your suggestion.
| |
| 137 * decode the resulting image to a higher quality even at | |
| 138 * the expense of the decoding speed. | |
| 139 * | |
| 140 * @param fRequestedConfig If SkBitmap::kNo_Config, then use | |
| 141 * whichever config the decoder wants. Else try to use | |
| 142 * this one. If this config won't work, getInfo() will | |
|
scroggo
2013/12/12 22:33:46
This comment seems vague. getInfo() on which class
hal.canary
2013/12/13 15:48:48
Done.
| |
| 143 * return false. | |
| 144 */ | |
| 145 struct Options { | |
| 146 int fSampleSize; | |
| 147 bool fDitherImage; | |
| 148 bool fPreferQualityOverSpeed; | |
| 149 SkBitmap::Config fRequestedConfig; | |
| 150 Options() | |
| 151 : fSampleSize(1) | |
| 152 , fDitherImage(true) | |
| 153 , fPreferQualityOverSpeed(false) | |
| 154 , fRequestedConfig(SkBitmap::kNo_Config) { } | |
| 155 Options(int sampleSize, bool dither, bool quality, | |
| 156 SkBitmap::Config config) | |
| 157 : fSampleSize(sampleSize) | |
| 158 , fDitherImage(dither) | |
| 159 , fPreferQualityOverSpeed(quality) | |
| 160 , fRequestedConfig(config) { } | |
| 161 }; | |
| 113 private: | 162 private: |
| 114 SkData* fData; | 163 SkData* fData; |
| 115 SkStreamRewindable* fStream; | 164 SkStreamRewindable* fStream; |
| 116 SkImageInfo fInfo; | 165 SkImageInfo fInfo; |
| 117 bool fHasInfo; | 166 bool fHasInfo; |
| 118 bool fDoCopyTo; | 167 bool fDoCopyTo; |
| 168 Options fOpts; | |
|
scroggo
2013/12/12 22:33:46
Can be const?
hal.canary
2013/12/13 15:48:48
Done.
| |
| 119 }; | 169 }; |
| 120 #endif // SkDecodingImageGenerator_DEFINED | 170 #endif // SkDecodingImageGenerator_DEFINED |
| OLD | NEW |