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 #ifndef SkCodecTools_DEFINED | 8 #ifndef SkCodecTools_DEFINED |
9 #define SkCodecTools_DEFINED | 9 #define SkCodecTools_DEFINED |
10 | 10 |
11 inline float get_scale_from_sample_size(uint32_t sampleSize) { | 11 inline float get_scale_from_sample_size(uint32_t sampleSize) { |
12 return 1.0f / (float) sampleSize; | 12 return 1.0f / (float) sampleSize; |
13 } | 13 } |
14 | 14 |
| 15 /* |
| 16 * Chooses the correct image subset offsets and dimensions for the partial decod
e. |
| 17 * |
| 18 * @return true if the subset is completely contained within the image |
| 19 * false otherwise |
| 20 */ |
| 21 inline bool set_subset_region(int inputOffset, int inputDimension, |
| 22 int imageOriginalDimension, int* imageSubsetOffset, int* outOffset, |
| 23 int* imageSubsetDimension) { |
| 24 |
| 25 // This must be at least zero, we can't start decoding the image at a negati
ve coordinate. |
| 26 *imageSubsetOffset = SkTMax(0, inputOffset); |
| 27 |
| 28 // If inputOffset is less than zero, we decode to an offset location in the
output bitmap. |
| 29 *outOffset = *imageSubsetOffset - inputOffset; |
| 30 |
| 31 // Use imageSusetOffset to make sure we don't decode pixels past the edge of
the image. |
| 32 // Use outOffset to make sure we don't decode pixels past the edge of the re
gion. |
| 33 *imageSubsetDimension = SkTMin(imageOriginalDimension - *imageSubsetOffset, |
| 34 inputDimension - *outOffset); |
| 35 |
| 36 return (*outOffset == 0) && (*imageSubsetDimension == inputDimension); |
| 37 } |
| 38 |
15 #endif // SkCodecTools_DEFINED | 39 #endif // SkCodecTools_DEFINED |
OLD | NEW |