Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4beceead authored by Sally Qi's avatar Sally Qi Committed by Android (Google) Code Review
Browse files

Merge "Accept RGBA_1010102 buffer in ImageUtils#getEstimatedNativeAllocBytes...

Merge "Accept RGBA_1010102 buffer in ImageUtils#getEstimatedNativeAllocBytes and other util functions." into udc-dev
parents c1e42bd0 1f83efcb
Loading
Loading
Loading
Loading
+14 −4
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import android.graphics.ImageFormat;
import android.graphics.PixelFormat;
import android.hardware.HardwareBuffer;
import android.media.Image.Plane;
import android.util.Log;
import android.util.Size;

import libcore.io.Memory;
@@ -30,6 +31,7 @@ import java.nio.ByteBuffer;
 * Package private utility class for hosting commonly used Image related methods.
 */
class ImageUtils {
    private static final String IMAGEUTILS_LOG_TAG = "ImageUtils";

    /**
     * Only a subset of the formats defined in
@@ -266,11 +268,15 @@ class ImageUtils {
                break;
            case PixelFormat.RGBA_8888:
            case PixelFormat.RGBX_8888:
            case PixelFormat.RGBA_1010102:
                estimatedBytePerPixel = 4.0;
                break;
            default:
                throw new UnsupportedOperationException(
                        String.format("Invalid format specified %d", format));
                if (Log.isLoggable(IMAGEUTILS_LOG_TAG, Log.VERBOSE)) {
                    Log.v(IMAGEUTILS_LOG_TAG, "getEstimatedNativeAllocBytes() uses default"
                            + "estimated native allocation size.");
                }
                estimatedBytePerPixel = 1.0;
        }

        return (int)(width * height * estimatedBytePerPixel * numImages);
@@ -295,6 +301,7 @@ class ImageUtils {
                }
            case PixelFormat.RGB_565:
            case PixelFormat.RGBA_8888:
            case PixelFormat.RGBA_1010102:
            case PixelFormat.RGBX_8888:
            case PixelFormat.RGB_888:
            case ImageFormat.JPEG:
@@ -312,8 +319,11 @@ class ImageUtils {
            case ImageFormat.PRIVATE:
                return new Size(0, 0);
            default:
                throw new UnsupportedOperationException(
                        String.format("Invalid image format %d", image.getFormat()));
                if (Log.isLoggable(IMAGEUTILS_LOG_TAG, Log.VERBOSE)) {
                    Log.v(IMAGEUTILS_LOG_TAG, "getEffectivePlaneSizeForImage() uses"
                            + "image's width and height for plane size.");
                }
                return new Size(image.getWidth(), image.getHeight());
        }
    }