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 enum SubsetType { | |
16 kFullyInside_SubsetType, | |
17 kPartiallyInside_SubsetType, | |
18 kInvalid_SubsetType, | |
scroggo
2015/10/21 20:56:20
Maybe kOutside?
msarett
2015/10/21 22:00:00
Done.
| |
19 }; | |
20 | |
21 /* | |
22 * 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 | |
24 * output bitmap. | |
25 * | |
26 * Values of output variables are undefined if the SubsetType is kInvalid. | |
27 * | |
28 * @param imageDims Original image dimensions. | |
29 * @param subset As input, the subset that the client requested. | |
30 * As output, the image subset that we will decode. | |
31 * @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. | |
33 * | |
34 * @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. | |
36 */ | |
37 inline SubsetType adjust_subset_rect(const SkISize& imageDims, SkIRect* subset, int* outX, | |
38 int* outY) { | |
39 // 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); | |
41 int top = SkTMax(0, subset->fTop); | |
42 | |
43 // If input offsets are less than zero, we decode to an offset location in t he output bitmap. | |
44 *outX = left - subset->fLeft; | |
45 *outY = top - subset->fTop; | |
46 | |
47 // Make sure we don't decode pixels past the edge of the image or past the e dge of the region. | |
scroggo
2015/10/21 20:56:20
nit: region -> subset
Android called it BitmapReg
msarett
2015/10/21 22:00:00
Yes thanks!
I generally try to say subset, but I'
| |
48 int width = SkTMin(imageDims.width() - left, subset->width() - *outX); | |
49 int height = SkTMin(imageDims.height() - top, subset->height() - *outY); | |
50 if (width <= 0 || height <= 0) { | |
51 return SubsetType::kInvalid_SubsetType; | |
52 } | |
53 | |
54 subset->setXYWH(left, top, width, height); | |
55 if ((*outX != 0) || (*outY != 0) || (width != subset->width()) || | |
56 (height != subset->height())) { | |
57 return SubsetType::kPartiallyInside_SubsetType; | |
58 } | |
59 | |
60 return SubsetType::kFullyInside_SubsetType; | |
61 } | |
62 | |
15 #endif // SkCodecTools_DEFINED | 63 #endif // SkCodecTools_DEFINED |
OLD | NEW |