| 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 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 | 191 |
| 192 if (options.fSubset) { | 192 if (options.fSubset) { |
| 193 // Subsets are not supported. | 193 // Subsets are not supported. |
| 194 return kUnimplemented; | 194 return kUnimplemented; |
| 195 } | 195 } |
| 196 | 196 |
| 197 Result result = fScanlineDecoder->start(requestedInfo, &options, ctable, cta
bleCount); | 197 Result result = fScanlineDecoder->start(requestedInfo, &options, ctable, cta
bleCount); |
| 198 if (kSuccess == result) { | 198 if (kSuccess == result) { |
| 199 // native decode supported | 199 // native decode supported |
| 200 return fScanlineDecoder->getScanlines(dst, requestedInfo.height(), rowBy
tes); | 200 return fScanlineDecoder->getScanlines(dst, requestedInfo.height(), rowBy
tes); |
| 201 | |
| 202 } | 201 } |
| 203 | 202 |
| 204 if (kInvalidScale != result) { | 203 if (kInvalidScale != result) { |
| 205 // no scaling requested | 204 // no scaling requested |
| 206 return result; | 205 return result; |
| 207 } | 206 } |
| 208 | 207 |
| 209 // scaling requested | 208 // scaling requested |
| 210 int sampleX; | 209 int sampleX; |
| 211 int sampleY; | 210 int sampleY; |
| 212 if (!scaling_supported(requestedInfo, fScanlineDecoder->getInfo(), &sampleX,
&sampleY)) { | 211 if (!scaling_supported(requestedInfo, fScanlineDecoder->getInfo(), &sampleX,
&sampleY)) { |
| 213 return kInvalidScale; | 212 return kInvalidScale; |
| 214 } | 213 } |
| 215 // set first sample pixel in y direction | 214 // set first sample pixel in y direction |
| 216 int Y0 = sampleY >> 1; | 215 int Y0 = get_start_coord(sampleY); |
| 217 | 216 |
| 218 int dstHeight = requestedInfo.height(); | 217 int dstHeight = requestedInfo.height(); |
| 219 int srcHeight = fScanlineDecoder->getInfo().height(); | 218 int srcHeight = fScanlineDecoder->getInfo().height(); |
| 220 | 219 |
| 221 SkImageInfo info = requestedInfo; | 220 SkImageInfo info = requestedInfo; |
| 222 // use original height as scanlineDecoder does not support y sampling native
ly | 221 // use original height as scanlineDecoder does not support y sampling native
ly |
| 223 info = info.makeWH(requestedInfo.width(), srcHeight); | 222 info = info.makeWH(requestedInfo.width(), srcHeight); |
| 224 | 223 |
| 225 // update scanlineDecoder with new info | 224 // update scanlineDecoder with new info |
| 226 result = fScanlineDecoder->start(info, &options, ctable, ctableCount); | 225 result = fScanlineDecoder->start(info, &options, ctable, ctableCount); |
| 227 if (kSuccess != result) { | 226 if (kSuccess != result) { |
| 228 return result; | 227 return result; |
| 229 } | 228 } |
| 230 | |
| 231 const bool requiresPostYSampling = fScanlineDecoder->requiresPostYSampling()
; | |
| 232 | 229 |
| 233 if (requiresPostYSampling) { | 230 switch(fScanlineDecoder->getScanlineOrder()) { |
| 234 SkAutoMalloc storage(srcHeight * rowBytes); | 231 case SkScanlineDecoder::kTopDown_SkScanlineOrder: { |
| 235 uint8_t* storagePtr = static_cast<uint8_t*>(storage.get()); | 232 result = fScanlineDecoder->skipScanlines(Y0); |
| 236 result = fScanlineDecoder->getScanlines(storagePtr, srcHeight, rowBytes)
; | 233 if (kSuccess != result && kIncompleteInput != result) { |
| 237 if (kSuccess != result) { | 234 return result; |
| 238 return result; | 235 } |
| 236 for (int y = 0; y < dstHeight; y++) { |
| 237 result = fScanlineDecoder->getScanlines(dst, 1, rowBytes); |
| 238 if (kSuccess != result && kIncompleteInput != result) { |
| 239 return result; |
| 240 } |
| 241 if (y < dstHeight - 1) { |
| 242 result = fScanlineDecoder->skipScanlines(sampleY - 1); |
| 243 if (kSuccess != result && kIncompleteInput != result) { |
| 244 return result; |
| 245 } |
| 246 } |
| 247 dst = SkTAddOffset<void>(dst, rowBytes); |
| 248 } |
| 249 return kSuccess; |
| 239 } | 250 } |
| 240 storagePtr += Y0 * rowBytes; | 251 case SkScanlineDecoder::kBottomUp_SkScanlineOrder: |
| 241 for (int y = 0; y < dstHeight; y++) { | 252 case SkScanlineDecoder::kOutOfOrder_SkScanlineOrder: { |
| 242 memcpy(dst, storagePtr, rowBytes); | 253 for (int y = 0; y < srcHeight; y++) { |
| 243 storagePtr += sampleY * rowBytes; | 254 int srcY = fScanlineDecoder->getY(); |
| 244 dst = SkTAddOffset<void>(dst, rowBytes); | 255 if (is_coord_necessary(srcY, sampleY, dstHeight)) { |
| 256 void* dstPtr = SkTAddOffset<void>(dst, rowBytes * get_dst_co
ord(srcY, sampleY)); |
| 257 result = fScanlineDecoder->getScanlines(dstPtr, 1, rowBytes)
; |
| 258 if (kSuccess != result && kIncompleteInput != result) { |
| 259 return result; |
| 260 } |
| 261 } else { |
| 262 result = fScanlineDecoder->skipScanlines(1); |
| 263 if (kSuccess != result && kIncompleteInput != result) { |
| 264 return result; |
| 265 } |
| 266 } |
| 267 } |
| 268 return kSuccess; |
| 245 } | 269 } |
| 246 } else { | 270 case SkScanlineDecoder::kNone_SkScanlineOrder: { |
| 247 // does not require post y sampling | 271 SkAutoMalloc storage(srcHeight * rowBytes); |
| 248 result = fScanlineDecoder->skipScanlines(Y0); | 272 uint8_t* storagePtr = static_cast<uint8_t*>(storage.get()); |
| 249 if (kSuccess != result) { | 273 result = fScanlineDecoder->getScanlines(storagePtr, srcHeight, rowBy
tes); |
| 250 return result; | |
| 251 } | |
| 252 for (int y = 0; y < dstHeight; y++) { | |
| 253 result = fScanlineDecoder->getScanlines(dst, 1, rowBytes); | |
| 254 if (kSuccess != result) { | 274 if (kSuccess != result) { |
| 255 return result; | 275 return result; |
| 256 } | 276 } |
| 257 if (y < dstHeight - 1) { | 277 storagePtr += Y0 * rowBytes; |
| 258 result = fScanlineDecoder->skipScanlines(sampleY - 1); | 278 for (int y = 0; y < dstHeight; y++) { |
| 259 if (kSuccess != result) { | 279 memcpy(dst, storagePtr, rowBytes); |
| 260 return result; | 280 storagePtr += sampleY * rowBytes; |
| 261 } | 281 dst = SkTAddOffset<void>(dst, rowBytes); |
| 262 } | 282 } |
| 263 dst = SkTAddOffset<void>(dst, rowBytes); | 283 return kSuccess; |
| 264 } | 284 } |
| 285 default: |
| 286 SkASSERT(false); |
| 287 return kUnimplemented; |
| 265 } | 288 } |
| 266 return kSuccess; | |
| 267 } | 289 } |
| OLD | NEW |