| 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 26 matching lines...) Expand all Loading... |
| 37 return NewFromStream(new SkMemoryStream(data)); | 37 return NewFromStream(new SkMemoryStream(data)); |
| 38 } | 38 } |
| 39 | 39 |
| 40 SkScaledCodec::SkScaledCodec(SkScanlineDecoder* scanlineDecoder) | 40 SkScaledCodec::SkScaledCodec(SkScanlineDecoder* scanlineDecoder) |
| 41 : INHERITED(scanlineDecoder->getInfo(), nullptr) | 41 : INHERITED(scanlineDecoder->getInfo(), nullptr) |
| 42 , fScanlineDecoder(scanlineDecoder) | 42 , fScanlineDecoder(scanlineDecoder) |
| 43 {} | 43 {} |
| 44 | 44 |
| 45 SkScaledCodec::~SkScaledCodec() {} | 45 SkScaledCodec::~SkScaledCodec() {} |
| 46 | 46 |
| 47 // returns a scaled dimension based on the original dimension and the sampleSize | |
| 48 // NOTE: we round down here for scaled dimension to match the behavior of SkImag
eDecoder | |
| 49 static int get_scaled_dimension(int srcDimension, int sampleSize) { | |
| 50 if (sampleSize > srcDimension) { | |
| 51 return 1; | |
| 52 } | |
| 53 return srcDimension / sampleSize; | |
| 54 } | |
| 55 | |
| 56 static SkISize best_scaled_dimensions(const SkISize& origDims, const SkISize& na
tiveDims, | 47 static SkISize best_scaled_dimensions(const SkISize& origDims, const SkISize& na
tiveDims, |
| 57 const SkISize& scaledCodecDims, float desi
redScale) { | 48 const SkISize& scaledCodecDims, float desi
redScale) { |
| 58 if (nativeDims == scaledCodecDims) { | 49 if (nativeDims == scaledCodecDims) { |
| 59 // does not matter which to return if equal. Return here to skip below c
alculations | 50 // does not matter which to return if equal. Return here to skip below c
alculations |
| 60 return nativeDims; | 51 return nativeDims; |
| 61 } | 52 } |
| 62 float idealWidth = origDims.width() * desiredScale; | 53 float idealWidth = origDims.width() * desiredScale; |
| 63 float idealHeight = origDims.height() * desiredScale; | 54 float idealHeight = origDims.height() * desiredScale; |
| 64 | 55 |
| 65 // calculate difference between native dimensions and ideal dimensions | 56 // calculate difference between native dimensions and ideal dimensions |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 SkPMColor ctable[], int* ctableCount)
{ | 181 SkPMColor ctable[], int* ctableCount)
{ |
| 191 | 182 |
| 192 if (options.fSubset) { | 183 if (options.fSubset) { |
| 193 // Subsets are not supported. | 184 // Subsets are not supported. |
| 194 return kUnimplemented; | 185 return kUnimplemented; |
| 195 } | 186 } |
| 196 | 187 |
| 197 Result result = fScanlineDecoder->start(requestedInfo, &options, ctable, cta
bleCount); | 188 Result result = fScanlineDecoder->start(requestedInfo, &options, ctable, cta
bleCount); |
| 198 if (kSuccess == result) { | 189 if (kSuccess == result) { |
| 199 // native decode supported | 190 // native decode supported |
| 200 return fScanlineDecoder->getScanlines(dst, requestedInfo.height(), rowBy
tes); | 191 switch (fScanlineDecoder->getScanlineOrder()) { |
| 192 case SkScanlineDecoder::kTopDown_SkScanlineOrder: |
| 193 case SkScanlineDecoder::kBottomUp_SkScanlineOrder: |
| 194 case SkScanlineDecoder::kNone_SkScanlineOrder: |
| 195 return fScanlineDecoder->getScanlines(dst, requestedInfo.height(
), rowBytes); |
| 196 case SkScanlineDecoder::kOutOfOrder_SkScanlineOrder: { |
| 197 for (int y = 0; y < requestedInfo.height(); y++) { |
| 198 int dstY = fScanlineDecoder->getY(); |
| 199 void* dstPtr = SkTAddOffset<void>(dst, rowBytes * dstY); |
| 200 result = fScanlineDecoder->getScanlines(dstPtr, 1, rowBytes)
; |
| 201 // FIXME (msarett): Make the SkCodec base class take care of
filling |
| 202 // uninitialized pixels so we can return immediately on kInc
ompleteInput. |
| 203 if (kSuccess != result && kIncompleteInput != result) { |
| 204 return result; |
| 205 } |
| 206 } |
| 207 return result; |
| 208 } |
| 209 } |
| 201 } | 210 } |
| 202 | 211 |
| 203 if (kInvalidScale != result) { | 212 if (kInvalidScale != result) { |
| 204 // no scaling requested | 213 // no scaling requested |
| 205 return result; | 214 return result; |
| 206 } | 215 } |
| 207 | 216 |
| 208 // scaling requested | 217 // scaling requested |
| 209 int sampleX; | 218 int sampleX; |
| 210 int sampleY; | 219 int sampleY; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 239 return result; | 248 return result; |
| 240 } | 249 } |
| 241 if (y < dstHeight - 1) { | 250 if (y < dstHeight - 1) { |
| 242 result = fScanlineDecoder->skipScanlines(sampleY - 1); | 251 result = fScanlineDecoder->skipScanlines(sampleY - 1); |
| 243 if (kSuccess != result && kIncompleteInput != result) { | 252 if (kSuccess != result && kIncompleteInput != result) { |
| 244 return result; | 253 return result; |
| 245 } | 254 } |
| 246 } | 255 } |
| 247 dst = SkTAddOffset<void>(dst, rowBytes); | 256 dst = SkTAddOffset<void>(dst, rowBytes); |
| 248 } | 257 } |
| 249 return kSuccess; | 258 return result; |
| 250 } | 259 } |
| 251 case SkScanlineDecoder::kBottomUp_SkScanlineOrder: | 260 case SkScanlineDecoder::kBottomUp_SkScanlineOrder: |
| 252 case SkScanlineDecoder::kOutOfOrder_SkScanlineOrder: { | 261 case SkScanlineDecoder::kOutOfOrder_SkScanlineOrder: { |
| 253 for (int y = 0; y < srcHeight; y++) { | 262 for (int y = 0; y < srcHeight; y++) { |
| 254 int srcY = fScanlineDecoder->getY(); | 263 int srcY = fScanlineDecoder->getY(); |
| 255 if (is_coord_necessary(srcY, sampleY, dstHeight)) { | 264 if (is_coord_necessary(srcY, sampleY, dstHeight)) { |
| 256 void* dstPtr = SkTAddOffset<void>(dst, rowBytes * get_dst_co
ord(srcY, sampleY)); | 265 void* dstPtr = SkTAddOffset<void>(dst, rowBytes * get_dst_co
ord(srcY, sampleY)); |
| 257 result = fScanlineDecoder->getScanlines(dstPtr, 1, rowBytes)
; | 266 result = fScanlineDecoder->getScanlines(dstPtr, 1, rowBytes)
; |
| 258 if (kSuccess != result && kIncompleteInput != result) { | 267 if (kSuccess != result && kIncompleteInput != result) { |
| 259 return result; | 268 return result; |
| 260 } | 269 } |
| 261 } else { | 270 } else { |
| 262 result = fScanlineDecoder->skipScanlines(1); | 271 result = fScanlineDecoder->skipScanlines(1); |
| 263 if (kSuccess != result && kIncompleteInput != result) { | 272 if (kSuccess != result && kIncompleteInput != result) { |
| 264 return result; | 273 return result; |
| 265 } | 274 } |
| 266 } | 275 } |
| 267 } | 276 } |
| 268 return kSuccess; | 277 return result; |
| 269 } | 278 } |
| 270 case SkScanlineDecoder::kNone_SkScanlineOrder: { | 279 case SkScanlineDecoder::kNone_SkScanlineOrder: { |
| 271 SkAutoMalloc storage(srcHeight * rowBytes); | 280 SkAutoMalloc storage(srcHeight * rowBytes); |
| 272 uint8_t* storagePtr = static_cast<uint8_t*>(storage.get()); | 281 uint8_t* storagePtr = static_cast<uint8_t*>(storage.get()); |
| 273 result = fScanlineDecoder->getScanlines(storagePtr, srcHeight, rowBy
tes); | 282 result = fScanlineDecoder->getScanlines(storagePtr, srcHeight, rowBy
tes); |
| 274 if (kSuccess != result) { | 283 if (kSuccess != result && kIncompleteInput != result) { |
| 275 return result; | 284 return result; |
| 276 } | 285 } |
| 277 storagePtr += Y0 * rowBytes; | 286 storagePtr += Y0 * rowBytes; |
| 278 for (int y = 0; y < dstHeight; y++) { | 287 for (int y = 0; y < dstHeight; y++) { |
| 279 memcpy(dst, storagePtr, rowBytes); | 288 memcpy(dst, storagePtr, rowBytes); |
| 280 storagePtr += sampleY * rowBytes; | 289 storagePtr += sampleY * rowBytes; |
| 281 dst = SkTAddOffset<void>(dst, rowBytes); | 290 dst = SkTAddOffset<void>(dst, rowBytes); |
| 282 } | 291 } |
| 283 return kSuccess; | 292 return result; |
| 284 } | 293 } |
| 285 default: | 294 default: |
| 286 SkASSERT(false); | 295 SkASSERT(false); |
| 287 return kUnimplemented; | 296 return kUnimplemented; |
| 288 } | 297 } |
| 289 } | 298 } |
| OLD | NEW |