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

Commit 7c3997d9 authored by Zhijun He's avatar Zhijun He
Browse files

ImageReader: Image getFormat should return the Image buffer format

Also return buffer size correctly.

Bug: 19527410
Change-Id: I9a912afc61d577571c1b2a7f6df21da40838e925
parent 71b0cb04
Loading
Loading
Loading
Loading
+9 −8
Original line number Original line Diff line number Diff line
@@ -703,26 +703,26 @@ public class ImageReader implements AutoCloseable {
        @Override
        @Override
        public int getFormat() {
        public int getFormat() {
            throwISEIfImageIsInvalid();
            throwISEIfImageIsInvalid();
            int readerFormat = ImageReader.this.getImageFormat();
            // Assume opaque reader always produce opaque images.
            mFormat = (readerFormat == ImageFormat.PRIVATE) ? readerFormat :
                nativeGetFormat(readerFormat);
            return mFormat;
            return mFormat;
        }
        }


        @Override
        @Override
        public int getWidth() {
        public int getWidth() {
            throwISEIfImageIsInvalid();
            throwISEIfImageIsInvalid();
            if (mWidth == -1) {
            mWidth = (getFormat() == ImageFormat.JPEG) ? ImageReader.this.getWidth() :
            mWidth = (getFormat() == ImageFormat.JPEG) ? ImageReader.this.getWidth() :
                    nativeGetWidth(mFormat);
                    nativeGetWidth(mFormat);
            }
            return mWidth;
            return mWidth;
        }
        }


        @Override
        @Override
        public int getHeight() {
        public int getHeight() {
            throwISEIfImageIsInvalid();
            throwISEIfImageIsInvalid();
            if (mHeight == -1) {
            mHeight = (getFormat() == ImageFormat.JPEG) ? ImageReader.this.getHeight() :
            mHeight = (getFormat() == ImageFormat.JPEG) ? ImageReader.this.getHeight() :
                    nativeGetHeight(mFormat);
                    nativeGetHeight(mFormat);
            }
            return mHeight;
            return mHeight;
        }
        }


@@ -876,6 +876,7 @@ public class ImageReader implements AutoCloseable {
        private synchronized native SurfacePlane nativeCreatePlane(int idx, int readerFormat);
        private synchronized native SurfacePlane nativeCreatePlane(int idx, int readerFormat);
        private synchronized native int nativeGetWidth(int format);
        private synchronized native int nativeGetWidth(int format);
        private synchronized native int nativeGetHeight(int format);
        private synchronized native int nativeGetHeight(int format);
        private synchronized native int nativeGetFormat(int readerFormat);
    }
    }


    private synchronized native void nativeInit(Object weakSelf, int w, int h,
    private synchronized native void nativeInit(Object weakSelf, int w, int h,
+16 −2
Original line number Original line Diff line number Diff line
@@ -1222,6 +1222,19 @@ static jint Image_getHeight(JNIEnv* env, jobject thiz, jint format)
    }
    }
}
}


static jint Image_getFormat(JNIEnv* env, jobject thiz, jint readerFormat)
{
    if (isFormatOpaque(readerFormat)) {
        // Assuming opaque reader produce opaque images.
        return static_cast<jint>(PublicFormat::PRIVATE);
    } else {
        CpuConsumer::LockedBuffer* buffer = Image_getLockedBuffer(env, thiz);
        PublicFormat publicFmt = android_view_Surface_mapHalFormatDataspaceToPublicFormat(
                buffer->flexFormat, buffer->dataSpace);
        return static_cast<jint>(publicFmt);
    }
}

} // extern "C"
} // extern "C"


// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
@@ -1242,6 +1255,7 @@ static JNINativeMethod gImageMethods[] = {
                                                              (void*)Image_createSurfacePlane },
                                                              (void*)Image_createSurfacePlane },
    {"nativeGetWidth",         "(I)I",                        (void*)Image_getWidth },
    {"nativeGetWidth",         "(I)I",                        (void*)Image_getWidth },
    {"nativeGetHeight",        "(I)I",                        (void*)Image_getHeight },
    {"nativeGetHeight",        "(I)I",                        (void*)Image_getHeight },
    {"nativeGetFormat",        "(I)I",                        (void*)Image_getFormat },
};
};


int register_android_media_ImageReader(JNIEnv *env) {
int register_android_media_ImageReader(JNIEnv *env) {