| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 #include "SkBmpCodec.h" | 8 #include "SkBmpCodec.h" |
| 9 #include "SkCodec.h" | 9 #include "SkCodec.h" |
| 10 #include "SkData.h" | 10 #include "SkData.h" |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 } | 145 } |
| 146 | 146 |
| 147 if (!this->rewindIfNeeded()) { | 147 if (!this->rewindIfNeeded()) { |
| 148 return kCouldNotRewind; | 148 return kCouldNotRewind; |
| 149 } | 149 } |
| 150 | 150 |
| 151 // Default options. | 151 // Default options. |
| 152 Options optsStorage; | 152 Options optsStorage; |
| 153 if (nullptr == options) { | 153 if (nullptr == options) { |
| 154 options = &optsStorage; | 154 options = &optsStorage; |
| 155 } else if (options->fSubset) { |
| 156 SkIRect subset(*options->fSubset); |
| 157 if (!this->onGetValidSubset(&subset) || subset != *options->fSubset) { |
| 158 // FIXME: How to differentiate between not supporting subset at all |
| 159 // and not supporting this particular subset? |
| 160 return kUnimplemented; |
| 161 } |
| 155 } | 162 } |
| 163 |
| 164 // FIXME: Support subsets somehow? Note that this works for SkWebpCodec |
| 165 // because it supports arbitrary scaling/subset combinations. |
| 166 if (!this->dimensionsSupported(info.dimensions())) { |
| 167 return kInvalidScale; |
| 168 } |
| 169 |
| 156 const Result result = this->onGetPixels(info, pixels, rowBytes, *options, ct
able, ctableCount); | 170 const Result result = this->onGetPixels(info, pixels, rowBytes, *options, ct
able, ctableCount); |
| 157 | 171 |
| 158 if ((kIncompleteInput == result || kSuccess == result) && ctableCount) { | 172 if ((kIncompleteInput == result || kSuccess == result) && ctableCount) { |
| 159 SkASSERT(*ctableCount >= 0 && *ctableCount <= 256); | 173 SkASSERT(*ctableCount >= 0 && *ctableCount <= 256); |
| 160 } | 174 } |
| 161 return result; | 175 return result; |
| 162 } | 176 } |
| 163 | 177 |
| 164 SkCodec::Result SkCodec::getPixels(const SkImageInfo& info, void* pixels, size_t
rowBytes) { | 178 SkCodec::Result SkCodec::getPixels(const SkImageInfo& info, void* pixels, size_t
rowBytes) { |
| 165 return this->getPixels(info, pixels, rowBytes, nullptr, nullptr, nullptr); | 179 return this->getPixels(info, pixels, rowBytes, nullptr, nullptr, nullptr); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 183 } | 197 } |
| 184 | 198 |
| 185 if (!this->rewindIfNeeded()) { | 199 if (!this->rewindIfNeeded()) { |
| 186 return kCouldNotRewind; | 200 return kCouldNotRewind; |
| 187 } | 201 } |
| 188 | 202 |
| 189 // Set options. | 203 // Set options. |
| 190 Options optsStorage; | 204 Options optsStorage; |
| 191 if (nullptr == options) { | 205 if (nullptr == options) { |
| 192 options = &optsStorage; | 206 options = &optsStorage; |
| 207 } else if (options->fSubset) { |
| 208 SkIRect subset(*options->fSubset); |
| 209 if (!this->onGetValidSubset(&subset) || subset != *options->fSubset) { |
| 210 // FIXME: How to differentiate between not supporting subset at all |
| 211 // and not supporting this particular subset? |
| 212 return kUnimplemented; |
| 213 } |
| 214 } |
| 215 |
| 216 // FIXME: Support subsets somehow? |
| 217 if (!this->dimensionsSupported(dstInfo.dimensions())) { |
| 218 return kInvalidScale; |
| 193 } | 219 } |
| 194 | 220 |
| 195 const Result result = this->onStartScanlineDecode(dstInfo, *options, ctable,
ctableCount); | 221 const Result result = this->onStartScanlineDecode(dstInfo, *options, ctable,
ctableCount); |
| 196 if (result != SkCodec::kSuccess) { | 222 if (result != SkCodec::kSuccess) { |
| 197 return result; | 223 return result; |
| 198 } | 224 } |
| 199 | 225 |
| 200 fCurrScanline = 0; | 226 fCurrScanline = 0; |
| 201 fDstInfo = dstInfo; | 227 fDstInfo = dstInfo; |
| 202 fOptions = *options; | 228 fOptions = *options; |
| 203 return kSuccess; | 229 return kSuccess; |
| 204 } | 230 } |
| 205 | 231 |
| 206 SkCodec::Result SkCodec::startScanlineDecode(const SkImageInfo& dstInfo) { | 232 SkCodec::Result SkCodec::startScanlineDecode(const SkImageInfo& dstInfo) { |
| 207 return this->startScanlineDecode(dstInfo, nullptr, nullptr, nullptr); | 233 return this->startScanlineDecode(dstInfo, nullptr, nullptr, nullptr); |
| 208 } | 234 } |
| 209 | 235 |
| 210 SkCodec::Result SkCodec::getScanlines(void* dst, int countLines, size_t rowBytes
) { | 236 SkCodec::Result SkCodec::getScanlines(void* dst, int countLines, size_t rowBytes
) { |
| 211 if (fCurrScanline < 0) { | 237 if (fCurrScanline < 0) { |
| 212 return kScanlineDecodingNotStarted; | 238 return kScanlineDecodingNotStarted; |
| 213 } | 239 } |
| 214 | 240 |
| 215 SkASSERT(!fDstInfo.isEmpty()); | 241 SkASSERT(!fDstInfo.isEmpty()); |
| 216 if ((rowBytes < fDstInfo.minRowBytes() && countLines > 1 ) || countLines <=
0 | 242 |
| 217 || fCurrScanline + countLines > fDstInfo.height()) { | 243 if (countLines <= 0 || fCurrScanline + countLines > fDstInfo.height()) { |
| 218 return kInvalidParameters; | 244 return kInvalidParameters; |
| 219 } | 245 } |
| 220 | 246 |
| 221 const Result result = this->onGetScanlines(dst, countLines, rowBytes); | 247 const Result result = this->onGetScanlines(dst, countLines, rowBytes); |
| 222 fCurrScanline += countLines; | 248 fCurrScanline += countLines; |
| 223 return result; | 249 return result; |
| 224 } | 250 } |
| 225 | 251 |
| 226 SkCodec::Result SkCodec::skipScanlines(int countLines) { | 252 SkCodec::Result SkCodec::skipScanlines(int countLines) { |
| 227 if (fCurrScanline < 0) { | 253 if (fCurrScanline < 0) { |
| 228 return kScanlineDecodingNotStarted; | 254 return kScanlineDecodingNotStarted; |
| 229 } | 255 } |
| 230 | 256 |
| 231 SkASSERT(!fDstInfo.isEmpty()); | 257 SkASSERT(!fDstInfo.isEmpty()); |
| 232 if (fCurrScanline + countLines > fDstInfo.height()) { | 258 if (fCurrScanline + countLines > fDstInfo.height()) { |
| 233 // Arguably, we could just skip the scanlines which are remaining, | 259 // Arguably, we could just skip the scanlines which are remaining, |
| 234 // and return kSuccess. We choose to return invalid so the client | 260 // and return kSuccess. We choose to return invalid so the client |
| 235 // can catch their bug. | 261 // can catch their bug. |
| 236 return SkCodec::kInvalidParameters; | 262 return SkCodec::kInvalidParameters; |
| 237 } | 263 } |
| 238 | 264 |
| 239 const Result result = this->onSkipScanlines(countLines); | 265 const Result result = this->onSkipScanlines(countLines); |
| 240 fCurrScanline += countLines; | 266 fCurrScanline += countLines; |
| 241 return result; | 267 return result; |
| 242 } | 268 } |
| OLD | NEW |