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 #include "SkBitmapRegionDecoderInterface.h" | |
12 | |
11 inline float get_scale_from_sample_size(uint32_t sampleSize) { | 13 inline float get_scale_from_sample_size(uint32_t sampleSize) { |
12 return 1.0f / (float) sampleSize; | 14 return 1.0f / (float) sampleSize; |
13 } | 15 } |
14 | 16 |
15 enum SubsetType { | |
16 kFullyInside_SubsetType, | |
17 kPartiallyInside_SubsetType, | |
18 kOutside_SubsetType, | |
19 }; | |
20 | |
21 /* | 17 /* |
22 * Corrects image subset offsets and dimensions in order to perform a valid deco de. | 18 * Corrects image subset offsets and dimensions in order to perform a valid deco de. |
23 * Also indicates if the image subset should be placed at an offset within the | 19 * Also indicates if the image subset should be placed at an offset within the |
24 * output bitmap. | 20 * output bitmap. |
25 * | 21 * |
26 * Values of output variables are undefined if the SubsetType is kInvalid. | 22 * Values of output variables are undefined if the SubsetType is kInvalid. |
27 * | 23 * |
28 * @param imageDims Original image dimensions. | 24 * @param imageDims Original image dimensions. |
29 * @param subset As input, the subset that the client requested. | 25 * @param subset As input, the subset that the client requested. |
30 * As output, the image subset that we will decode. | 26 * As output, the image subset that we will decode. |
31 * @param outX The left offset of the image subset within the output bitmap . | 27 * @param outX The left offset of the image subset within the output bitmap . |
32 * @param outY The top offset of the image subset within the output bitmap. | 28 * @param outY The top offset of the image subset within the output bitmap. |
33 * | 29 * |
34 * @return An indication of how the subset is contained in the image. | 30 * @return An indication of how the subset is contained in the image. |
35 * If the return value is kInvalid, values of output variables are undef ined. | 31 * If the return value is kInvalid, values of output variables are undef ined. |
36 */ | 32 */ |
37 inline SubsetType adjust_subset_rect(const SkISize& imageDims, SkIRect* subset, int* outX, | 33 inline SkBitmapRegionDecoderInterface::SubsetType adjust_subset_rect(const SkISi ze& imageDims, |
scroggo
2015/10/27 15:00:51
Should this be a method on SkBitmapRegionDecoderIn
| |
38 int* outY) { | 34 SkIRect* subset, int* outX, int* outY) { |
39 // These must be at least zero, we can't start decoding the image at a negat ive coordinate. | 35 // These must be at least zero, we can't start decoding the image at a negat ive coordinate. |
40 int left = SkTMax(0, subset->fLeft); | 36 int left = SkTMax(0, subset->fLeft); |
41 int top = SkTMax(0, subset->fTop); | 37 int top = SkTMax(0, subset->fTop); |
42 | 38 |
43 // If input offsets are less than zero, we decode to an offset location in t he output bitmap. | 39 // If input offsets are less than zero, we decode to an offset location in t he output bitmap. |
44 *outX = left - subset->fLeft; | 40 *outX = left - subset->fLeft; |
45 *outY = top - subset->fTop; | 41 *outY = top - subset->fTop; |
46 | 42 |
47 // Make sure we don't decode pixels past the edge of the image or past the e dge of the subset. | 43 // Make sure we don't decode pixels past the edge of the image or past the e dge of the subset. |
48 int width = SkTMin(imageDims.width() - left, subset->width() - *outX); | 44 int width = SkTMin(imageDims.width() - left, subset->width() - *outX); |
49 int height = SkTMin(imageDims.height() - top, subset->height() - *outY); | 45 int height = SkTMin(imageDims.height() - top, subset->height() - *outY); |
50 if (width <= 0 || height <= 0) { | 46 if (width <= 0 || height <= 0) { |
51 return SubsetType::kOutside_SubsetType; | 47 return SkBitmapRegionDecoderInterface::kOutside_SubsetType; |
52 } | 48 } |
53 | 49 |
54 subset->setXYWH(left, top, width, height); | 50 subset->setXYWH(left, top, width, height); |
55 if ((*outX != 0) || (*outY != 0) || (width != subset->width()) || | 51 if ((*outX != 0) || (*outY != 0) || (width != subset->width()) || |
56 (height != subset->height())) { | 52 (height != subset->height())) { |
57 return SubsetType::kPartiallyInside_SubsetType; | 53 return SkBitmapRegionDecoderInterface::kPartiallyInside_SubsetType; |
58 } | 54 } |
59 | 55 |
60 return SubsetType::kFullyInside_SubsetType; | 56 return SkBitmapRegionDecoderInterface::kFullyInside_SubsetType; |
61 } | 57 } |
62 | 58 |
63 #endif // SkCodecTools_DEFINED | 59 #endif // SkCodecTools_DEFINED |
OLD | NEW |