Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Side by Side Diff: tools/android/SkBitmapRegionDecoderPriv.h

Issue 1438873002: Move SkBitmapRegionDecoder to include/android and src/android (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Rebase (header guards) Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tools/android/SkBitmapRegionDecoder.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2015 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #ifndef SkBitmapRegionDecoderPriv_DEFINED
9 #define SkBitmapRegionDecoderPriv_DEFINED
10
11 inline float get_scale_from_sample_size(uint32_t sampleSize) {
12 return 1.0f / (float) sampleSize;
13 }
14
15 enum SubsetType {
16 kFullyInside_SubsetType,
17 kPartiallyInside_SubsetType,
18 kOutside_SubsetType,
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 subset.
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::kOutside_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
63 #endif // SkBitmapRegionDecoderPriv_DEFINED
OLDNEW
« no previous file with comments | « tools/android/SkBitmapRegionDecoder.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698