Chromium Code Reviews| 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) { | |
|
msarett
2015/10/01 19:34:33
I'm guessing that, for some reason (maybe the kSub
scroggo
2015/10/01 21:16:57
That is correct. I don't think this is best long t
| |
| 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 | |
|
msarett
2015/10/01 19:34:33
There's a couple ways we could go about this, I do
scroggo
2015/10/01 21:16:57
Yeah, I considered that. I decided to punt that un
msarett
2015/10/01 22:53:07
That makes perfect sense.
| |
| 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 (rowBytes < fDstInfo.minRowBytes() && countLines > 1) { |
| 244 // FIXME: This check breaks down when we sample without letting SkCodec | |
|
scroggo
2015/10/01 15:33:14
The problem shows up when we want to scale down an
msarett
2015/10/01 19:34:33
I've deleted this check in my scaled subsetting CL
scroggo
2015/10/01 21:16:57
Done.
| |
| 245 // know about it. | |
| 246 // return kInvalidParameters; | |
| 247 } | |
| 248 | |
| 249 if (countLines <= 0 || fCurrScanline + countLines > fDstInfo.height()) { | |
| 218 return kInvalidParameters; | 250 return kInvalidParameters; |
| 219 } | 251 } |
| 220 | 252 |
| 221 const Result result = this->onGetScanlines(dst, countLines, rowBytes); | 253 const Result result = this->onGetScanlines(dst, countLines, rowBytes); |
| 222 fCurrScanline += countLines; | 254 fCurrScanline += countLines; |
| 223 return result; | 255 return result; |
| 224 } | 256 } |
| 225 | 257 |
| 226 SkCodec::Result SkCodec::skipScanlines(int countLines) { | 258 SkCodec::Result SkCodec::skipScanlines(int countLines) { |
| 227 if (fCurrScanline < 0) { | 259 if (fCurrScanline < 0) { |
| 228 return kScanlineDecodingNotStarted; | 260 return kScanlineDecodingNotStarted; |
| 229 } | 261 } |
| 230 | 262 |
| 231 SkASSERT(!fDstInfo.isEmpty()); | 263 SkASSERT(!fDstInfo.isEmpty()); |
| 232 if (fCurrScanline + countLines > fDstInfo.height()) { | 264 if (fCurrScanline + countLines > fDstInfo.height()) { |
| 233 // Arguably, we could just skip the scanlines which are remaining, | 265 // Arguably, we could just skip the scanlines which are remaining, |
| 234 // and return kSuccess. We choose to return invalid so the client | 266 // and return kSuccess. We choose to return invalid so the client |
| 235 // can catch their bug. | 267 // can catch their bug. |
| 236 return SkCodec::kInvalidParameters; | 268 return SkCodec::kInvalidParameters; |
| 237 } | 269 } |
| 238 | 270 |
| 239 const Result result = this->onSkipScanlines(countLines); | 271 const Result result = this->onSkipScanlines(countLines); |
| 240 fCurrScanline += countLines; | 272 fCurrScanline += countLines; |
| 241 return result; | 273 return result; |
| 242 } | 274 } |
| OLD | NEW |