Commit Graph

25 Commits

Author SHA1 Message Date
Leon Scroggins III
6116e5c0d8 AImageDecoder: return BAD_PARAMETER on null info
Bug: 186656488
Test: I4dc406e85709dda14af8b414e2da3d39bb07643b
Change-Id: Ibd7c1c3d1319818e86ac29bdc231e0e05cec2132
2021-05-03 11:34:34 -04:00
Leon Scroggins III
df33b95e68 AImageDecoder: only support animation for F16 and 8888 (impl)
Bug: 180594747
Test: I51dedd94aa8ff5d6846cada96861ffca30d509d7

See I03818703dc79942be4e574db31c6e2927ab571ed

Change-Id: Ibce55e4af38713d2e40fcb8846d9d7a939367fd6
2021-04-26 15:35:56 -04:00
Leon Scroggins III
5a5c2ce593 (A)ImageDecoder: fix sampled dimensions with exif
Test: I138ec784a77253c7ae94765d0670e5947d97caf5

Recently (Ib93b0ced09fa3cca4a6681745406355c48158fae), handling exif
moved from SkAndroidCodec to hwui/ImageDecoder. This missed
getSampledDimensions, which reports the sampled dimensions without
taking exif into account. Fix this for both
android.graphics.ImageDecoder and AImageDecoder. Note that in the Java
case, the method is private, and although the method was returning
swapped dimensions in some cases, it gets corrected by
getTargetDimension, so there is no user visible change.

Change-Id: I918328c39d6230ae6ba4cab0733fff0732b39888
2021-01-19 09:57:35 -05:00
Leon Scroggins III
c72d0fb15d Build libjnigraphics, imagedecoder_fuzzer on host
Bug: 142252770
Bug: 169137236
Bug: 169139756
Test: SANITIZE_HOST=address make imagedecoder_fuzzer

This will allow running the fuzzer much faster in order to find bugs. It
also allows running with ASAN to help find memory leaks.

Some symbols (e.g. ABitmap, AAssetStreamAdaptor) rely on
Android-specific features, so disable them when building on the host.
This still allows using the core features of AImageDecoder.

This requires a change in frameworks/native
(Iefdb4132d6f10f9164be85f4dc6e11883f6fd37e).

Disable detecting ODR violations when building with ASAN (which is how
host builds are built). Without this change, the host detects the
following:

    =================================================================
    ==4072183==ERROR: AddressSanitizer: odr-violation (0x7fb7d52b4100):
      [1] size=80 'vtable for android::VectorImpl' system/core/libutils/VectorImpl.cpp
      [2] size=80 'vtable for android::VectorImpl' system/core/libutils/VectorImpl.cpp
    These globals were registered at these points:
      [1]:
        #0 0x55fefda47e0d in __asan_register_globals /out/llvm-project/compiler-rt/lib/asan/asan_globals.cpp:360:3
        #1 0x7fb7d43aa77b in asan.module_ctor (/usr/local/ssd/android/master/out/host/linux-x86/fuzz/x86_64/imagedecoder_fuzzer/../lib/libhw
ui.so+0x17c677b)

      [2]:
        #0 0x55fefda47e0d in __asan_register_globals /out/llvm-project/compiler-rt/lib/asan/asan_globals.cpp:360:3
        #1 0x7fb7d52a0e6b in asan.module_ctor (/usr/local/ssd/android/master/out/host/linux-x86/fuzz/x86_64/imagedecoder_fuzzer/../lib/libutils.so+0x3de6b)

    ==4072183==HINT: if you don't care about these errors you may set ASAN_OPTIONS=detect_odr_violation=0
    SUMMARY: AddressSanitizer: odr-violation: global 'vtable for android::VectorImpl' at system/core/libutils/VectorImpl.cpp
    ==4072183==ABORTING

Change-Id: I0ffc4e90b4083db79fbb12012e2e1284206b43e3
2021-01-14 12:22:05 -05:00
Leon Scroggins III
c2ebc2bcf3 Implement AImageDecoder_setInternallyHandleDisposePrevious
Bug: 160984428
Test: I00682f201a52f894b0e1335c00c4368ce675a805

Also fix a bug caught by the new test. If the current frame is the first
in a series of one or more RestorePrevious frames, fPriorFrame should be
set to |currentFrame - 1|. Otherwise SkCodec will decode the required
frame. This is wasted work, since the prior frame should already be
prepared (either by AImageDecoder or by the client).

Change-Id: I1fb9f91dc66fd3121f187b9a91c15f625eb17f8d
2021-01-13 12:09:18 -05:00
Leon Scroggins III
946f8d41bc Implement AImageDecoder_resultToString
Bug: 160984428
Test: I118eaa99cd65b70dbfb2c8a7731c714564911a34
Change-Id: Iac444b04521056ae6f08cf7bbf12a79a80698c4c
2021-01-08 09:37:22 -05:00
Leon Scroggins III
0621313fe6 Implement FrameInfo methods on AImageDecoder
Bug: 160984428
Test: If47d475233f6b9973abf68029b63a610ff47cdae

- AImageDecoder_getFrameInfo
- AImageDecoderFrameInfo_create
- AImageDecoderFrameInfo_delete
- AImageDecoderFrameInfo_getDuration
- AImageDecoderFrameInfo_getFrameRect
- AImageDecoderFrameInfo_getDisposeOp
- AImageDecoderFrameInfo_getBlendOp
- AImageDecoderFrameInfo_hasAlphaWithinBounds

These allow querying for information specific to a single frame in an
encoded image.

Change-Id: I6ce5665e9c25aed23f99ce88290e520d68fcb60e
2021-01-06 13:53:20 -05:00
Leon Scroggins III
b26aebc325 Implement AImageDecoder _advanceFrame and _rewind
Bug: 160984428
Test: Iae7d274b69999c471fd5610c6ef4d148cca81bec

Disallow AImageDecoder_set* methods after the first frame, since
changing the settings would interfere with blending and caching for
kRestorePrevious frames.

Add a cache (and a state machine) for handling kRestorePrevious frames.

Follow-on to Ib93b0ced09fa3cca4a6681745406355c48158fae - support using
a matrix for unpremul + orientation (the orientation was previously
handled by a matrix internally in SkAndroidCodec).

Change-Id: I7c32ede013fa83f1fe95c35778c33278ca6fe6a3
2021-01-05 12:37:47 -05:00
Leon Scroggins III
139145be80 Handle EXIF orientation in hwui/ImageDecoder
Bug: 160984428
Test: AImageDecoderTest#testRespectOrientation
       ImageDecoderTest#testRespectOrientation
      Ieda439910ae52e609f0710d424503616d99ae5c7
      I23caef26b4c82173c758dd0ce7fb6f04e4154588
      I345a13d20776a007052d32e74fa42865b42f726d

It is possible to create an animated image with an exif orientation.
Using kRespect, there is no clean way to handle the orientation plus
compositing frames. Switch ImageDecoder to use kIgnore (the default).

Depends on a change in Skia (https://review.skia.org/344762) to make
SkAnimatedImage handle the orientation even with kIgnore.

Change-Id: Ib93b0ced09fa3cca4a6681745406355c48158fae
2021-01-05 12:37:47 -05:00
Leon Scroggins III
3ad12c4301 Implement AImageDecoder_getRepeatCount
Bug: 160984428
Test: Ia09c95173d7e53dc2c0f6d170c67a3f3360275b9
Change-Id: Ia1eac93d46a6cc3498a5289c28a5475b3aae3cba
2020-10-12 10:56:42 -04:00
Leon Scroggins III
24ae7d7f85 Implement AImageDecoder_isAnimated
Bug: 160984428
Test: Ie98a7e80c2d0d6101bdf0ac3549a1fa6581aeba6
Change-Id: Iab70514cda54955368cedb472d84f89763569166
2020-10-09 13:14:35 -04:00
Derek Sollenberger
2173ea286a Export symbols for the newly exposed APEX/internal headers
Bug: 137655431
Test: CtsUiRenderingTestCases
Change-Id: I71c6d1a53ae080bf104848679ee62a77cf07c9fa
2020-02-20 21:50:06 -05:00
Leon Scroggins
69b9dcf528 Merge "AImageDecoder: Make create enforce int32_t dimensions" 2020-02-12 15:41:51 +00:00
Leon Scroggins III
2e6bedf937 AImageDecoder: Make create enforce int32_t dimensions
Bug: 135133301
Test: AImageDecoderTest

AImageDecoderHeaderInfo_getWidth/Height return an int32_t. Ensure at
creation time that the actual image dimensions will fit in int32_t.

In today's code, this should almost never happen:
- PNGs have their dimensions limited to 1000000
  - see PNG_USER_WIDTH_MAX and PNG_USER_HEIGHT_MAX in pnglibconf.h
- JPEGs are limited to 65500
  - see JPEG_MAX_DIMENSION in jmorecfg.h
- WebPs' dimensions are encoded in 14 bits
- GIFs' dimensions are encoded in 16 bits
- SkBmpCodec and SkWbmpCodec require dimensions to fit in 16 bits
- SkIcoCodec uses SkBmpCodec or SkPngCodec, so their limits are
  enforced
- libheif limits to a size smaller than int32_t

It might be possible for a DNG image to be larger, and some of the above
are configurable. Just in case, make AImageDecoder_create fail on such a
large image.

Change-Id: Id520dfbc0581f990c4f52cb6675e987bf71c558c
2020-02-11 17:01:46 -05:00
Leon Scroggins III
6eeca5c776 AImageDecoder: allow no color conversion
Bug: 135133301
Test: I5e8bdcdae6837db23c0f4ef08f931f3bebe0ce0d

Previously the default SkColorSpace for AImageDecoder was set to the
result of SkAndroidCodec::computeOutputColorSpace. If the image has a
profile that does not map to an SkColorSpace, it will return either
DISPLAY_P3 or SRGB. Using that at decode time will result in color
conversion.

Instead, default to a null SkColorSpace for such a profile, resulting in
no color conversion. If the image has no profile, default to SRGB, as
usual.

A client that wants SRGB can still request and get that, but this allows
getting the raw pixels for an advanced client that may want to do its
own conversion.

Change-Id: I489f31fef79dec11e97c8e8fb9207adb77a3d0c7
2020-02-04 16:11:25 -05:00
TreeHugger Robot
a4a8be3748 Merge "AImageDecoder: ensure that stride is pixel aligned" 2020-01-27 16:06:27 +00:00
Leon Scroggins III
64301cbed1 Update imagedecoder for header updates
Bug: 135133301
Test: Ibf7c0e563feeb08ce6dbabb5e86ddb385c9dff54

Remove isAnimated and update parameters/returns to match
I93df851dd9fee2eb8d097e2158fb95003a0474db.

Change-Id: Ida2af1682b5f9b91e37079005391b1594239d345
2020-01-23 09:47:47 -05:00
Leon Scroggins
569229f0bb Merge "Implement AImageDecoder dataspace methods" 2020-01-22 19:39:06 +00:00
Leon Scroggins III
d894c59881 AImageDecoder: ensure that stride is pixel aligned
Bug: 147749998
Test: I902de3410c45a21cf27b48a02cdc5d514b7ada60

If the client uses a stride that is not pixel aligned, AImageDecoder
will crash internally trying to access the memory. Return a failure
instead of crashing. Rely on SkImageInfo to compute the minimum size
required, too.

Change-Id: Ia4d14d6209e6f4af74906ff43208fa83ac82cbcd
2020-01-22 14:18:12 -05:00
Leon Scroggins III
e5ace3f9cb Implement AImageDecoder dataspace methods
Bug: 135133301
Test: Iffe659e50078139188c3325545624640ae177cc2

Implement AImageDecoderHeaderInfo_getDataSpace, which reports the
default ADataSpace to decode to. It may report ADATASPACE_UNKNOWN, which
means that we've mostly left the colors in their original color profile.
This matches android.graphics.ImageDecoder/BitmapFactory, which would
use a ColorSpace named "Unknown". (It will standardize on DISPLAY_P3 for
some profiles, which again matches the Java classes.)

Implement AImageDecoder_setDataSpace, which allows specifying the
ADataSpace to decode to. It only supports explicit ADataSpaces.

Change-Id: Iba2f9e09531c23fae83ebe13cb9d18394ee3cd59
2020-01-21 13:27:58 -05:00
Leon Scroggins III
f89de63304 Implement AImageDecoder_computeSampledSize
Bug: 135133301
Test: If9ed79d8dcf1169369ba454723f4ac8d26427b7b
Change-Id: I4926188cf66e2693c09dd7f1197173441936080c
2020-01-19 21:22:18 -05:00
Leon Scroggins
83d7f05c66 Merge "Update AImageDecoder_getAlphaFlags return value" 2020-01-18 14:07:55 +00:00
Leon Scroggins III
1ade46d272 Replace setAlphaFlags with setUnpremultipliedRequired
Bug: 135133301
Test: I48e49ee08ab1954eddf62ecae87942aeb128c10d

As described in I3381582e27894e1072db9b8635f3762b801f5d69, this is a
more sensible API.

In addition, remove unused methods on ImageDecoder.

Lastly, update AImageDecoder methods in the map to document which API
level they were introduced in.

Change-Id: I1aff544e8d6932b9ed0931a00da66a0aba6cd536
2020-01-16 12:17:56 -05:00
Leon Scroggins III
d8840bd9f0 Update AImageDecoder_getAlphaFlags return value
Bug: 135133301
Test: I2ea58bede5cf49a7947c96e7e6e37f967632ad6b

BAD_PARAMETER is a more sensible value than -1. The other return will
not be reached, but the code is clearer.

Change-Id: I4bee8f238f61a6c6cd13b5458f201f34d34315d9
2020-01-15 04:09:48 -05:00
Leon Scroggins III
407b544925 Implement new NDK image decoding apis
Bug: 135133301
Test: Ib84462ea5fa8a7779eaa44494775e182e52ecaca

Separate out the code for encodedFormatToString into a piece which
returns a const char* that can be used by AImageDecoder (with its own
header) and the part that the JNI code uses to convert that into a Java
String.

Change-Id: I4cf8bfb0aacfb8e22c3f9b1689bd614ed1253673
2020-01-10 09:27:38 -05:00