diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
commit | 2aa4a82499d4becd2284cdb482213d541b8804dd (patch) | |
tree | b80bf8bf13c3766139fbacc530efd0dd9d54394c /gfx/skia/skia/src/android/SkBitmapRegionDecoderPriv.h | |
parent | Initial commit. (diff) | |
download | firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.tar.xz firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.zip |
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'gfx/skia/skia/src/android/SkBitmapRegionDecoderPriv.h')
-rw-r--r-- | gfx/skia/skia/src/android/SkBitmapRegionDecoderPriv.h | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/gfx/skia/skia/src/android/SkBitmapRegionDecoderPriv.h b/gfx/skia/skia/src/android/SkBitmapRegionDecoderPriv.h new file mode 100644 index 0000000000..5f1613a1a6 --- /dev/null +++ b/gfx/skia/skia/src/android/SkBitmapRegionDecoderPriv.h @@ -0,0 +1,61 @@ +/* + * Copyright 2015 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SkBitmapRegionDecoderPriv_DEFINED +#define SkBitmapRegionDecoderPriv_DEFINED + +#include "include/core/SkRect.h" + +enum SubsetType { + kFullyInside_SubsetType, + kPartiallyInside_SubsetType, + kOutside_SubsetType, +}; + +/* + * Corrects image subset offsets and dimensions in order to perform a valid decode. + * Also indicates if the image subset should be placed at an offset within the + * output bitmap. + * + * Values of output variables are undefined if the SubsetType is kInvalid. + * + * @param imageDims Original image dimensions. + * @param subset As input, the subset that the client requested. + * As output, the image subset that we will decode. + * @param outX The left offset of the image subset within the output bitmap. + * @param outY The top offset of the image subset within the output bitmap. + * + * @return An indication of how the subset is contained in the image. + * If the return value is kInvalid, values of output variables are undefined. + */ +inline SubsetType adjust_subset_rect(const SkISize& imageDims, SkIRect* subset, int* outX, + int* outY) { + // These must be at least zero, we can't start decoding the image at a negative coordinate. + int left = SkTMax(0, subset->fLeft); + int top = SkTMax(0, subset->fTop); + + // If input offsets are less than zero, we decode to an offset location in the output bitmap. + *outX = left - subset->fLeft; + *outY = top - subset->fTop; + + // Make sure we don't decode pixels past the edge of the image or past the edge of the subset. + int width = SkTMin(imageDims.width() - left, subset->width() - *outX); + int height = SkTMin(imageDims.height() - top, subset->height() - *outY); + if (width <= 0 || height <= 0) { + return SubsetType::kOutside_SubsetType; + } + + subset->setXYWH(left, top, width, height); + if ((*outX != 0) || (*outY != 0) || (width != subset->width()) || + (height != subset->height())) { + return SubsetType::kPartiallyInside_SubsetType; + } + + return SubsetType::kFullyInside_SubsetType; +} + +#endif // SkBitmapRegionDecoderPriv_DEFINED |