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 "SkCodecPriv.h" | 8 #include "SkCodecPriv.h" |
9 #include "SkScaledCodec.h" | 9 #include "SkScaledCodec.h" |
10 #include "SkStream.h" | 10 #include "SkStream.h" |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 | 214 |
215 SkImageInfo info = requestedInfo; | 215 SkImageInfo info = requestedInfo; |
216 // use original height as scanlineDecoder does not support y sampling native
ly | 216 // use original height as scanlineDecoder does not support y sampling native
ly |
217 info = info.makeWH(requestedInfo.width(), srcHeight); | 217 info = info.makeWH(requestedInfo.width(), srcHeight); |
218 | 218 |
219 // update scanlineDecoder with new info | 219 // update scanlineDecoder with new info |
220 result = fScanlineDecoder->start(info, &options, ctable, ctableCount); | 220 result = fScanlineDecoder->start(info, &options, ctable, ctableCount); |
221 if (kSuccess != result) { | 221 if (kSuccess != result) { |
222 return result; | 222 return result; |
223 } | 223 } |
224 | |
225 const bool requiresPostYSampling = fScanlineDecoder->requiresPostYSampling()
; | |
226 | 224 |
227 if (requiresPostYSampling) { | 225 switch(fScanlineDecoder->getScanlineOrder()) { |
228 SkAutoMalloc storage(srcHeight * rowBytes); | 226 case SkScanlineDecoder::kTopDown_SkScanlineOrder: { |
229 uint8_t* storagePtr = static_cast<uint8_t*>(storage.get()); | 227 result = fScanlineDecoder->skipScanlines(Y0); |
230 result = fScanlineDecoder->getScanlines(storagePtr, srcHeight, rowBytes)
; | |
231 if (kSuccess != result) { | |
232 return result; | |
233 } | |
234 storagePtr += Y0 * rowBytes; | |
235 for (int y = 0; y < dstHeight; y++) { | |
236 memcpy(dst, storagePtr, rowBytes); | |
237 storagePtr += sampleY * rowBytes; | |
238 dst = SkTAddOffset<void>(dst, rowBytes); | |
239 } | |
240 } else { | |
241 // does not require post y sampling | |
242 result = fScanlineDecoder->skipScanlines(Y0); | |
243 if (kSuccess != result) { | |
244 return result; | |
245 } | |
246 for (int y = 0; y < dstHeight; y++) { | |
247 result = fScanlineDecoder->getScanlines(dst, 1, rowBytes); | |
248 if (kSuccess != result) { | 228 if (kSuccess != result) { |
249 return result; | 229 return result; |
250 } | 230 } |
251 if (y < dstHeight - 1) { | 231 for (int y = 0; y < dstHeight; y++) { |
252 result = fScanlineDecoder->skipScanlines(sampleY - 1); | 232 result = fScanlineDecoder->getScanlines(dst, 1, rowBytes); |
253 if (kSuccess != result) { | 233 if (kSuccess != result) { |
254 return result; | 234 return result; |
255 } | 235 } |
| 236 if (y < dstHeight - 1) { |
| 237 result = fScanlineDecoder->skipScanlines(sampleY - 1); |
| 238 if (kSuccess != result) { |
| 239 return result; |
| 240 } |
| 241 } |
| 242 dst = SkTAddOffset<void>(dst, rowBytes); |
256 } | 243 } |
257 dst = SkTAddOffset<void>(dst, rowBytes); | 244 return kSuccess; |
258 } | 245 } |
| 246 case SkScanlineDecoder::kOutOfOrder_SkScanlineOrder: { |
| 247 for (int y = 0; y < srcHeight; y++) { |
| 248 int srcY = fScanlineDecoder->getY(); |
| 249 if (is_coord_necessary(srcY, Y0, sampleY, dstHeight)) { |
| 250 void* dstPtr = SkTAddOffset<void>(dst, rowBytes * (srcY / sa
mpleY)); |
| 251 result = fScanlineDecoder->getScanlines(dstPtr, 1, rowBytes)
; |
| 252 if (kSuccess != result) { |
| 253 return result; |
| 254 } |
| 255 } else { |
| 256 result = fScanlineDecoder->skipScanlines(1); |
| 257 if (kSuccess != result) { |
| 258 return result; |
| 259 } |
| 260 } |
| 261 } |
| 262 return kSuccess; |
| 263 } |
| 264 case SkScanlineDecoder::kNone_SkScanlineOrder: { |
| 265 SkAutoMalloc storage(srcHeight * rowBytes); |
| 266 uint8_t* storagePtr = static_cast<uint8_t*>(storage.get()); |
| 267 result = fScanlineDecoder->getScanlines(storagePtr, srcHeight, rowBy
tes); |
| 268 if (kSuccess != result) { |
| 269 return result; |
| 270 } |
| 271 storagePtr += Y0 * rowBytes; |
| 272 for (int y = 0; y < dstHeight; y++) { |
| 273 memcpy(dst, storagePtr, rowBytes); |
| 274 storagePtr += sampleY * rowBytes; |
| 275 dst = SkTAddOffset<void>(dst, rowBytes); |
| 276 } |
| 277 return kSuccess; |
| 278 } |
| 279 default: |
| 280 SkASSERT(false); |
| 281 return kUnimplemented; |
259 } | 282 } |
260 return kSuccess; | |
261 } | 283 } |
OLD | NEW |