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

Commit 5ea17442 authored by Lajos Molnar's avatar Lajos Molnar
Browse files

MediaCodec/Image: handle null cropRect correctly

- allow Media.Image.setCropRect(null) to unset cropRect
- use full image if cropRect is null in MediaCodec$Image

Bug: 18124320
Change-Id: I7abb6175402a1fe913e16c0a682fabee79c55741
parent ac7d8c5c
Loading
Loading
Loading
Loading
+4 −2
Original line number Original line Diff line number Diff line
@@ -146,8 +146,10 @@ public abstract class Image implements AutoCloseable {
     * using coordinates in the largest-resolution plane.
     * using coordinates in the largest-resolution plane.
     */
     */
    public void setCropRect(Rect cropRect) {
    public void setCropRect(Rect cropRect) {
        if (cropRect != null) {
            cropRect = new Rect(cropRect);  // make a copy
            cropRect = new Rect(cropRect);  // make a copy
            cropRect.intersect(0, 0, getWidth(), getHeight());
            cropRect.intersect(0, 0, getWidth(), getHeight());
        }
        mCropRect = cropRect;
        mCropRect = cropRect;
    }
    }


+6 −4
Original line number Original line Diff line number Diff line
@@ -1778,10 +1778,6 @@ final public class MediaCodec {
            mIsValid = true;
            mIsValid = true;
            mIsReadOnly = buffer.isReadOnly();
            mIsReadOnly = buffer.isReadOnly();
            mBuffer = buffer.duplicate();
            mBuffer = buffer.duplicate();
            if (cropRect != null) {
                cropRect.offset(-xOffset, -yOffset);
            }
            super.setCropRect(cropRect);


            // save offsets and info
            // save offsets and info
            mXOffset = xOffset;
            mXOffset = xOffset;
@@ -1833,6 +1829,12 @@ final public class MediaCodec {
                throw new UnsupportedOperationException(
                throw new UnsupportedOperationException(
                        "unsupported info length: " + info.remaining());
                        "unsupported info length: " + info.remaining());
            }
            }

            if (cropRect == null) {
                cropRect = new Rect(0, 0, mWidth, mHeight);
            }
            cropRect.offset(-xOffset, -yOffset);
            super.setCropRect(cropRect);
        }
        }


        private class MediaPlane extends Plane {
        private class MediaPlane extends Plane {