Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * Copyright 2015 Google Inc. | |
| 3 * | |
| 4 * Use of this source code is governed by a BSD-style license that can be | |
| 5 * found in the LICENSE file. | |
| 6 */ | |
| 7 | |
| 8 #ifndef SkAndroidCodec_DEFINED | |
| 9 #define SkAndroidCodec_DEFINED | |
| 10 | |
| 11 #include "SkCodec.h" | |
| 12 #include "SkEncodedFormat.h" | |
| 13 #include "SkStream.h" | |
| 14 #include "SkTypes.h" | |
| 15 | |
| 16 /** | |
| 17 * Abstract interface defining image codec functionality that is necessary for | |
| 18 * Android. | |
| 19 */ | |
| 20 class SkAndroidCodec : SkNoncopyable { | |
| 21 public: | |
| 22 /** | |
| 23 * If this stream represents an encoded image that we know how to decode, | |
| 24 * return an SkAndroidCodec that can decode it. Otherwise return NULL. | |
| 25 * | |
| 26 * If NULL is returned, the stream is deleted immediately. Otherwise, the | |
| 27 * SkCodec takes ownership of it, and will delete it when done with it. | |
| 28 */ | |
| 29 static SkAndroidCodec* NewFromStream(SkStream*); | |
| 30 | |
| 31 /** | |
| 32 * If this data represents an encoded image that we know how to decode, | |
| 33 * return an SkAndroidCodec that can decode it. Otherwise return NULL. | |
| 34 * | |
| 35 * Will take a ref if it returns a codec, else will not affect the data. | |
| 36 */ | |
| 37 static SkAndroidCodec* NewFromData(SkData*); | |
| 38 | |
| 39 virtual ~SkAndroidCodec() {} | |
| 40 | |
| 41 | |
| 42 const SkImageInfo& getInfo() const { return fInfo; } | |
| 43 | |
| 44 /** | |
| 45 * Format of the encoded data. | |
| 46 */ | |
| 47 SkEncodedFormat getEncodedFormat() const { return this->onGetEncodedFormat() ; } | |
| 48 | |
| 49 /** | |
| 50 * Returns the dimensions of the scaled output image, for an input | |
| 51 * sampleSize. | |
| 52 * | |
| 53 * When the sample size divides evenly into the original dimensions, the | |
| 54 * scaled output dimensions will simply be equal to the original | |
| 55 * dimensions divided by the sample size. | |
| 56 * | |
| 57 * When the sample size does not divide even into the original | |
| 58 * dimensions, the codec may round up or down, depending on what is most | |
| 59 * efficient to decode. | |
| 60 * | |
| 61 * Finally, the codec will always recommend a non-zero output, so the outpu t | |
| 62 * dimension will always be one if the sampleSize is greater than the | |
| 63 * original dimension. | |
| 64 */ | |
| 65 SkISize getSampledDimensions(int sampleSize) const; | |
| 66 | |
| 67 /** | |
| 68 * Return (via desiredSubset) a subset which can decoded from this codec, | |
| 69 * or false if the input subset is invalid. | |
| 70 * | |
| 71 * @param desiredSubset in/out parameter | |
| 72 * As input, a desired subset of the original bounds | |
| 73 * (as specified by getInfo). | |
| 74 * As output, if true is returned, desiredSubset may | |
| 75 * have been modified to a subset which is | |
| 76 * supported. Although a particular change may have | |
| 77 * been made to desiredSubset to create something | |
| 78 * supported, it is possible other changes could | |
| 79 * result in a valid subset. If false is returned, | |
| 80 * desiredSubset's value is undefined. | |
| 81 * @return true If the input desiredSubset is valid. | |
| 82 * desiredSubset may be modified to a subset | |
| 83 * supported by the codec. | |
| 84 * false If desiredSubset is invalid (NULL or not fully | |
| 85 * contained within the image). | |
| 86 */ | |
| 87 bool getSubset(SkIRect* desiredSubset) const; | |
|
msarett
2015/10/16 18:42:16
I could have (and maybe should have) called this g
scroggo
2015/10/16 21:13:55
I think it's odd that this one is different from t
msarett
2015/10/19 16:06:10
Yes they are the same.
I like getSupportedSubset(
| |
| 88 | |
| 89 /** | |
| 90 * Returns the dimensions of the scaled, partial output image, for an | |
| 91 * input sampleSize and subset. | |
| 92 * | |
| 93 * @param sampleSize Factor to scale down by. | |
| 94 * @param subset Must be a valid subset of the original image | |
| 95 * dimensions and a subset supported by SkAndroidCodec. | |
| 96 * getSubset() can be used to obtain a subset supported | |
| 97 * by SkAndroidCodec. | |
| 98 * @return Size of the scaled partial image. Or zero size | |
|
scroggo
2015/10/16 21:13:55
Alternatively, we could return a boolean, and modi
msarett
2015/10/19 16:06:10
Agreed.
I went for this approach for consistency
| |
| 99 * if either of the inputs is invalid. | |
| 100 */ | |
| 101 SkISize getSampledSubsetDimensions(int sampleSize, const SkIRect& subset) co nst; | |
| 102 | |
| 103 /** | |
| 104 * Additional options to pass to getAndroidPixels(). | |
| 105 */ | |
| 106 struct AndroidOptions { | |
| 107 AndroidOptions() | |
| 108 : fZeroInitialized(SkCodec::kNo_ZeroInitialized) | |
| 109 , fSubset(nullptr) | |
| 110 , fColorPtr(nullptr) | |
|
msarett
2015/10/16 18:42:16
At one point, you mentioned that we might want to
| |
| 111 , fColorCount(nullptr) | |
| 112 , fSampleSize(1) | |
| 113 {} | |
| 114 | |
| 115 /** | |
| 116 * Indicates is destination pixel memory is zero initialized. | |
| 117 */ | |
| 118 SkCodec::ZeroInitialized fZeroInitialized; | |
| 119 | |
| 120 /** | |
| 121 * If not NULL, represents a subset of the original image to decode. | |
| 122 * | |
| 123 * Must be within the bounds returned by getInfo(). | |
| 124 * | |
| 125 * If the EncodedFormat is kWEBP_SkEncodedFormat, the top and left | |
| 126 * values must be even. | |
| 127 */ | |
| 128 SkIRect* fSubset; | |
| 129 | |
| 130 /** | |
| 131 * If the client has requested a decode to kIndex8_SkColorType | |
| 132 * (specified in the SkImageInfo), then the caller must provide | |
| 133 * storage for up to 256 SkPMColor values in fColorPtr. On success, | |
| 134 * the codec must copy N colors into that storage, (where N is the | |
| 135 * logical number of table entries) and set fColorCount to N. | |
| 136 * | |
| 137 * If the client does not request kIndex8_SkColorType, then the last | |
| 138 * two parameters may be NULL. If fColorCount is not null, it will be | |
| 139 * set to 0. | |
| 140 */ | |
| 141 SkPMColor* fColorPtr; | |
| 142 int* fColorCount; | |
| 143 | |
| 144 /** | |
| 145 * The client may provide an integer downscale factor for the decode. | |
| 146 * The codec may implement this downscaling by sampling or another | |
| 147 * method if it is more efficient. | |
| 148 */ | |
| 149 int fSampleSize; | |
| 150 }; | |
| 151 | |
| 152 /** | |
| 153 * Decode into the given pixels, a block of memory of size at | |
| 154 * least (info.fHeight - 1) * rowBytes + (info.fWidth * | |
| 155 * bytesPerPixel) | |
| 156 * | |
| 157 * Repeated calls to this function should give the same results, | |
| 158 * allowing the PixelRef to be immutable. | |
| 159 * | |
| 160 * @param info A description of the format (config, size) | |
| 161 * expected by the caller. This can simply be identical | |
| 162 * to the info returned by getInfo(). | |
| 163 * | |
| 164 * This contract also allows the caller to specify | |
| 165 * different output-configs, which the implementation can | |
| 166 * decide to support or not. | |
| 167 * | |
| 168 * A size that does not match getInfo() implies a request | |
| 169 * to scale or subset. If the codec cannot perform this | |
| 170 * scaling or subsetting, it will return an error code. | |
| 171 * | |
| 172 * If info is kIndex8_SkColorType, then the caller must provide storage for up to 256 | |
| 173 * SkPMColor values in options->fColorPtr. On success the codec must copy N colors into | |
| 174 * that storage, (where N is the logical number of table entries) and set | |
| 175 * options->fColorCount to N. | |
| 176 * | |
| 177 * If info is not kIndex8_SkColorType, options->fColorPtr and options->fCol orCount may | |
| 178 * be nullptr. | |
| 179 * | |
| 180 * The AndroidOptions object is also used to specify any requested scaling or subsetting | |
| 181 * using options->fSampleSize and options->fSubset. | |
| 182 * | |
| 183 * @return Result kSuccess, or another value explaining the type of failure . | |
| 184 */ | |
| 185 SkCodec::Result getAndroidPixels(const SkImageInfo& info, void* pixels, size _t rowBytes, | |
|
scroggo
2015/10/16 21:13:55
I don't think it's necessary to put "Android" in t
msarett
2015/10/19 16:06:10
Yeah you're right. I was struggling to come up wi
| |
| 186 AndroidOptions* options); | |
| 187 | |
| 188 /** | |
| 189 * Simplified version of getAndroidPixels() where we supply the default And roidOptions. | |
| 190 * | |
| 191 * This will return an error if the info is kIndex_8_SkColorType and also w ill not perform | |
| 192 * any scaling or subsetting. | |
| 193 */ | |
| 194 SkCodec::Result getAndroidPixels(const SkImageInfo& info, void* pixels, size _t rowBytes); | |
| 195 | |
| 196 protected: | |
| 197 | |
| 198 SkAndroidCodec(const SkImageInfo&); | |
| 199 | |
| 200 virtual SkEncodedFormat onGetEncodedFormat() const = 0; | |
| 201 | |
| 202 virtual SkISize onGetSampledDimensions(int sampleSize) const = 0; | |
| 203 | |
| 204 virtual bool onGetSubset(SkIRect* desiredSubset) const = 0; | |
| 205 | |
| 206 virtual SkISize onGetSampledSubsetDimensions(int sampleSize, const SkIRect& subset) const = 0; | |
| 207 | |
| 208 virtual SkCodec::Result onGetAndroidPixels(const SkImageInfo& info, void* pi xels, | |
| 209 size_t rowBytes, AndroidOptions& options) = 0; | |
| 210 | |
| 211 private: | |
| 212 | |
| 213 const SkImageInfo& fInfo; | |
|
scroggo
2015/10/16 21:13:55
Maybe a note that this will always be the info of
msarett
2015/10/19 16:06:10
Will add a note. It may be a bit dangerous to dep
| |
| 214 }; | |
| 215 #endif // SkAndroidCodec_DEFINED | |
| OLD | NEW |