Files
frameworks_base/graphics/java/android/graphics/PostProcess.java
Leon Scroggins III 0c01dbf8f2 ImageDecoder (BitmapFactory 2.0)
Bug: 63909536
Bug: 63908092

Test: CTS: I0f36ce34c968fd7fae4d8edebabea3a421859615

One-pager:
https://docs.google.com/document/d/1IWSdXb5O9lu-Zbj7SaNWo5pS7-FHlonFnqazjnecozM/
Design doc:
https://docs.google.com/document/d/15S6DSAV4EwOuJLv29UC_9cdSGdPg3KvOJVn2EHoP3fw/

ImageDecoder is designed to streamline certain patterns of BitmapFactory
use:
- choosing sample size based on actual dimensions
- choosing a specific output size
- post-processing (e.g. for rounded corners)
- copying to HARDWARE
- decode directly to ashmem
- creating a Drawable
- use as an alpha mask
- save RAM (e.g. use RGB_565)

In addition, it will include new features:
- animated drawables (TODO)
- report failures *and* optionally create a partial image
- crop

Add PostProcess to handle post-processing. It is separate from
ImageDecoder so that it may be used in the future by other commands that
might want something similar (e.g. capturing a View).

Consolidate NinePatch code for sharing between BitmapFactory and
ImageDecoder.

Some features left out of this CL:
- Create from ContentResolver + URI
- animation
- report more info in ImageInfo
- more overloads (e.g. null OnHeaderDecodedListener)

Change-Id: Icf011dc1b97b492788e47cf51fcf8abe8e9c7b88
2017-12-19 20:22:17 +00:00

92 lines
4.0 KiB
Java

/*
* Copyright (C) 2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.graphics;
import android.annotation.IntDef;
import android.annotation.NonNull;
import android.graphics.drawable.Drawable;
/**
* Helper interface for adding custom processing to an image.
*
* The image being processed may be a {@link Drawable}, {@link Bitmap} or frame
* of an animated image produced by {@link ImageDecoder}. This is called before
* the requested object is returned.
*
* This custom processing also applies to image types that are otherwise
* immutable, such as {@link Bitmap.Config#HARDWARE}.
*
* On an animated image, the callback will only be called once, but the drawing
* commands will be applied to each frame, as if the {@code Canvas} had been
* returned by {@link Picture#beginRecording}.
*
* Supplied to ImageDecoder via {@link ImageDecoder#setPostProcess}.
* @hide
*/
public interface PostProcess {
/**
* Do any processing after (for example) decoding.
*
* Drawing to the {@link Canvas} will behave as if the initial processing
* (e.g. decoding) already exists in the Canvas. An implementation can draw
* effects on top of this, or it can even draw behind it using
* {@link PorterDuff.Mode#DST_OVER}. A common effect is to add transparency
* to the corners to achieve rounded corners. That can be done with the
* following code:
*
* <code>
* Path path = new Path();
* path.setFillType(Path.FillType.INVERSE_EVEN_ODD);
* path.addRoundRect(0, 0, width, height, 20, 20, Path.Direction.CW);
* Paint paint = new Paint();
* paint.setAntiAlias(true);
* paint.setColor(Color.TRANSPARENT);
* paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC));
* canvas.drawPath(path, paint);
* return PixelFormat.TRANSLUCENT;
* </code>
*
*
* @param canvas The {@link Canvas} to draw to.
* @param width Width of {@code canvas}. Anything drawn outside of this
* will be ignored.
* @param height Height of {@code canvas}. Anything drawn outside of this
* will be ignored.
* @return Opacity of the result after drawing.
* {@link PixelFormat#UNKNOWN} means that the implementation did not
* change whether the image has alpha. Return this unless you added
* transparency (e.g. with the code above, in which case you should
* return {@code PixelFormat.TRANSLUCENT}) or you forced the image to
* be opaque (e.g. by drawing everywhere with an opaque color and
* {@code PorterDuff.Mode.DST_OVER}, in which case you should return
* {@code PixelFormat.OPAQUE}).
* {@link PixelFormat#TRANSLUCENT} means that the implementation added
* transparency. This is safe to return even if the image already had
* transparency. This is also safe to return if the result is opaque,
* though it may draw more slowly.
* {@link PixelFormat#OPAQUE} means that the implementation forced the
* image to be opaque. This is safe to return even if the image was
* already opaque.
* {@link PixelFormat#TRANSPARENT} (or any other integer) is not
* allowed, and will result in throwing an
* {@link java.lang.IllegalArgumentException}.
*/
@PixelFormat.Opacity
public int postProcess(@NonNull Canvas canvas, int width, int height);
}