From f89de633049792b172d5a5653907ddb568b42ac2 Mon Sep 17 00:00:00 2001 From: Leon Scroggins III Date: Sun, 19 Jan 2020 21:22:18 -0500 Subject: Implement AImageDecoder_computeSampledSize Bug: 135133301 Test: If9ed79d8dcf1169369ba454723f4ac8d26427b7b Change-Id: I4926188cf66e2693c09dd7f1197173441936080c --- native/graphics/jni/imagedecoder.cpp | 16 ++++++++++++++++ native/graphics/jni/libjnigraphics.map.txt | 1 + 2 files changed, 17 insertions(+) (limited to 'native') diff --git a/native/graphics/jni/imagedecoder.cpp b/native/graphics/jni/imagedecoder.cpp index 51439672d404..bd5914a55042 100644 --- a/native/graphics/jni/imagedecoder.cpp +++ b/native/graphics/jni/imagedecoder.cpp @@ -131,6 +131,10 @@ static ImageDecoder* toDecoder(AImageDecoder* d) { return reinterpret_cast(d); } +static const ImageDecoder* toDecoder(const AImageDecoder* d) { + return reinterpret_cast(d); +} + // Note: This differs from the version in android_bitmap.cpp in that this // version returns kGray_8_SkColorType for ANDROID_BITMAP_FORMAT_A_8. SkCodec // allows decoding single channel images to gray, which Android then treats @@ -258,6 +262,18 @@ int AImageDecoder_setTargetSize(AImageDecoder* decoder, int width, int height) { ? ANDROID_IMAGE_DECODER_SUCCESS : ANDROID_IMAGE_DECODER_INVALID_SCALE; } +int AImageDecoder_computeSampledSize(const AImageDecoder* decoder, int sampleSize, + int* width, int* height) { + if (!decoder || !width || !height || sampleSize < 1) { + return ANDROID_IMAGE_DECODER_BAD_PARAMETER; + } + + SkISize size = toDecoder(decoder)->mCodec->getSampledDimensions(sampleSize); + *width = size.width(); + *height = size.height(); + return ANDROID_IMAGE_DECODER_SUCCESS; +} + int AImageDecoder_setCrop(AImageDecoder* decoder, ARect crop) { if (!decoder) { return ANDROID_IMAGE_DECODER_BAD_PARAMETER; diff --git a/native/graphics/jni/libjnigraphics.map.txt b/native/graphics/jni/libjnigraphics.map.txt index 6843e7a8552f..d9e7828d852a 100644 --- a/native/graphics/jni/libjnigraphics.map.txt +++ b/native/graphics/jni/libjnigraphics.map.txt @@ -10,6 +10,7 @@ LIBJNIGRAPHICS { AImageDecoder_getMinimumStride; # introduced=30 AImageDecoder_decodeImage; # introduced=30 AImageDecoder_setTargetSize; # introduced=30 + AImageDecoder_computeSampledSize; # introduced=30 AImageDecoder_setCrop; # introduced=30 AImageDecoderHeaderInfo_getWidth; # introduced=30 AImageDecoderHeaderInfo_getHeight; # introduced=30 -- cgit v1.2.3