Loading api/current.xml +100 −4 Original line number Original line Diff line number Diff line Loading @@ -60412,6 +60412,102 @@ </parameter> </parameter> </constructor> </constructor> </class> </class> <class name="ImageFormat" extends="java.lang.Object" abstract="false" static="false" final="false" deprecated="not deprecated" visibility="public" > <constructor name="ImageFormat" type="android.graphics.ImageFormat" static="false" final="false" deprecated="not deprecated" visibility="public" > </constructor> <method name="getBitsPerPixel" return="int" abstract="false" native="false" synchronized="false" static="true" final="false" deprecated="not deprecated" visibility="public" > <parameter name="format" type="int"> </parameter> </method> <field name="JPEG" type="int" transient="false" volatile="false" value="256" static="true" final="true" deprecated="not deprecated" visibility="public" > </field> <field name="NV16" type="int" transient="false" volatile="false" value="16" static="true" final="true" deprecated="not deprecated" visibility="public" > </field> <field name="NV21" type="int" transient="false" volatile="false" value="17" static="true" final="true" deprecated="not deprecated" visibility="public" > </field> <field name="RGB_565" type="int" transient="false" volatile="false" value="4" static="true" final="true" deprecated="not deprecated" visibility="public" > </field> <field name="UNKNOWN" type="int" transient="false" volatile="false" value="0" static="true" final="true" deprecated="not deprecated" visibility="public" > </field> <field name="YUY2" type="int" transient="false" volatile="false" value="20" static="true" final="true" deprecated="not deprecated" visibility="public" > </field> </class> <class name="Interpolator" <class name="Interpolator" extends="java.lang.Object" extends="java.lang.Object" abstract="false" abstract="false" Loading Loading @@ -64473,7 +64569,7 @@ value="256" value="256" static="true" static="true" final="true" final="true" deprecated="not deprecated" deprecated="deprecated" visibility="public" visibility="public" > > </field> </field> Loading Loading @@ -64627,7 +64723,7 @@ value="17" value="17" static="true" static="true" final="true" final="true" deprecated="not deprecated" deprecated="deprecated" visibility="public" visibility="public" > > </field> </field> Loading @@ -64638,7 +64734,7 @@ value="20" value="20" static="true" static="true" final="true" final="true" deprecated="not deprecated" deprecated="deprecated" visibility="public" visibility="public" > > </field> </field> Loading @@ -64649,7 +64745,7 @@ value="16" value="16" static="true" static="true" final="true" final="true" deprecated="not deprecated" deprecated="deprecated" visibility="public" visibility="public" > > </field> </field> core/java/android/hardware/Camera.java +31 −31 Original line number Original line Diff line number Diff line Loading @@ -26,7 +26,7 @@ import java.io.IOException; import android.util.Log; import android.util.Log; import android.view.Surface; import android.view.Surface; import android.view.SurfaceHolder; import android.view.SurfaceHolder; import android.graphics.PixelFormat; import android.graphics.ImageFormat; import android.os.Handler; import android.os.Handler; import android.os.Looper; import android.os.Looper; import android.os.Message; import android.os.Message; Loading Loading @@ -192,7 +192,7 @@ public class Camera { * The callback that delivers the preview frames. * The callback that delivers the preview frames. * * * @param data The contents of the preview frame in the format defined * @param data The contents of the preview frame in the format defined * by {@link android.graphics.PixelFormat}, which can be queried * by {@link android.graphics.ImageFormat}, which can be queried * with {@link android.hardware.Camera.Parameters#getPreviewFormat()}. * with {@link android.hardware.Camera.Parameters#getPreviewFormat()}. * If {@link android.hardware.Camera.Parameters#setPreviewFormat(int)} * If {@link android.hardware.Camera.Parameters#setPreviewFormat(int)} * is never called, the default will be the YCbCr_420_SP * is never called, the default will be the YCbCr_420_SP Loading Loading @@ -276,7 +276,7 @@ public class Camera { * Adds a pre-allocated buffer to the callback buffer queue. * Adds a pre-allocated buffer to the callback buffer queue. * Preview width and height can be determined from getPreviewSize, and bitsPerPixel can be * Preview width and height can be determined from getPreviewSize, and bitsPerPixel can be * found from from {@link android.hardware.Camera.Parameters#getPreviewFormat()} and * found from from {@link android.hardware.Camera.Parameters#getPreviewFormat()} and * {@link android.graphics.PixelFormat#getPixelFormatInfo(int, PixelFormat)} * {@link android.graphics.ImageFormat#getBitsPerPixel(int)} * * * Alternatively, a buffer from a previous callback may be passed in or used * Alternatively, a buffer from a previous callback may be passed in or used * to determine the size of new preview frame buffers. * to determine the size of new preview frame buffers. Loading Loading @@ -1086,15 +1086,15 @@ public class Camera { /** /** * Sets the image format for preview pictures. * Sets the image format for preview pictures. * <p>If this is never called, the default format will be * <p>If this is never called, the default format will be * {@link android.graphics.PixelFormat#YCbCr_420_SP}, which * {@link android.graphics.ImageFormat#NV21}, which * uses the NV21 encoding format.</p> * uses the NV21 encoding format.</p> * * * @param pixel_format the desired preview picture format, defined * @param pixel_format the desired preview picture format, defined * by one of the {@link android.graphics.PixelFormat} constants. * by one of the {@link android.graphics.ImageFormat} constants. * (E.g., <var>PixelFormat.YCbCr_420_SP</var> (default), * (E.g., <var>ImageFormat.NV21</var> (default), * <var>PixelFormat.RGB_565</var>, or * <var>ImageFormat.RGB_565</var>, or * <var>PixelFormat.JPEG</var>) * <var>ImageFormat.JPEG</var>) * @see android.graphics.PixelFormat * @see android.graphics.ImageFormat */ */ public void setPreviewFormat(int pixel_format) { public void setPreviewFormat(int pixel_format) { String s = cameraFormatForPixelFormat(pixel_format); String s = cameraFormatForPixelFormat(pixel_format); Loading @@ -1110,7 +1110,7 @@ public class Camera { * Returns the image format for preview pictures got from * Returns the image format for preview pictures got from * {@link PreviewCallback}. * {@link PreviewCallback}. * * * @return the {@link android.graphics.PixelFormat} int representing * @return the {@link android.graphics.ImageFormat} int representing * the preview picture format. * the preview picture format. */ */ public int getPreviewFormat() { public int getPreviewFormat() { Loading @@ -1128,7 +1128,7 @@ public class Camera { ArrayList<Integer> formats = new ArrayList<Integer>(); ArrayList<Integer> formats = new ArrayList<Integer>(); for (String s : split(str)) { for (String s : split(str)) { int f = pixelFormatForCameraFormat(s); int f = pixelFormatForCameraFormat(s); if (f == PixelFormat.UNKNOWN) continue; if (f == ImageFormat.UNKNOWN) continue; formats.add(f); formats.add(f); } } return formats; return formats; Loading Loading @@ -1171,10 +1171,10 @@ public class Camera { * Sets the image format for pictures. * Sets the image format for pictures. * * * @param pixel_format the desired picture format * @param pixel_format the desired picture format * (<var>PixelFormat.YCbCr_420_SP (NV21)</var>, * (<var>ImageFormat.NV21</var>, * <var>PixelFormat.RGB_565</var>, or * <var>ImageFormat.RGB_565</var>, or * <var>PixelFormat.JPEG</var>) * <var>ImageFormat.JPEG</var>) * @see android.graphics.PixelFormat * @see android.graphics.ImageFormat */ */ public void setPictureFormat(int pixel_format) { public void setPictureFormat(int pixel_format) { String s = cameraFormatForPixelFormat(pixel_format); String s = cameraFormatForPixelFormat(pixel_format); Loading @@ -1189,7 +1189,7 @@ public class Camera { /** /** * Returns the image format for pictures. * Returns the image format for pictures. * * * @return the PixelFormat int representing the picture format * @return the ImageFormat int representing the picture format */ */ public int getPictureFormat() { public int getPictureFormat() { return pixelFormatForCameraFormat(get(KEY_PICTURE_FORMAT)); return pixelFormatForCameraFormat(get(KEY_PICTURE_FORMAT)); Loading @@ -1198,7 +1198,7 @@ public class Camera { /** /** * Gets the supported picture formats. * Gets the supported picture formats. * * * @return a List of Integer objects (values are PixelFormat.XXX). This * @return a List of Integer objects (values are ImageFormat.XXX). This * method will always return a list with at least one element. * method will always return a list with at least one element. */ */ public List<Integer> getSupportedPictureFormats() { public List<Integer> getSupportedPictureFormats() { Loading @@ -1206,7 +1206,7 @@ public class Camera { ArrayList<Integer> formats = new ArrayList<Integer>(); ArrayList<Integer> formats = new ArrayList<Integer>(); for (String s : split(str)) { for (String s : split(str)) { int f = pixelFormatForCameraFormat(s); int f = pixelFormatForCameraFormat(s); if (f == PixelFormat.UNKNOWN) continue; if (f == ImageFormat.UNKNOWN) continue; formats.add(f); formats.add(f); } } return formats; return formats; Loading @@ -1214,35 +1214,35 @@ public class Camera { private String cameraFormatForPixelFormat(int pixel_format) { private String cameraFormatForPixelFormat(int pixel_format) { switch(pixel_format) { switch(pixel_format) { case PixelFormat.YCbCr_422_SP: return PIXEL_FORMAT_YUV422SP; case ImageFormat.NV16: return PIXEL_FORMAT_YUV422SP; case PixelFormat.YCbCr_420_SP: return PIXEL_FORMAT_YUV420SP; case ImageFormat.NV21: return PIXEL_FORMAT_YUV420SP; case PixelFormat.YCbCr_422_I: return PIXEL_FORMAT_YUV422I; case ImageFormat.YUY2: return PIXEL_FORMAT_YUV422I; case PixelFormat.RGB_565: return PIXEL_FORMAT_RGB565; case ImageFormat.RGB_565: return PIXEL_FORMAT_RGB565; case PixelFormat.JPEG: return PIXEL_FORMAT_JPEG; case ImageFormat.JPEG: return PIXEL_FORMAT_JPEG; default: return null; default: return null; } } } } private int pixelFormatForCameraFormat(String format) { private int pixelFormatForCameraFormat(String format) { if (format == null) if (format == null) return PixelFormat.UNKNOWN; return ImageFormat.UNKNOWN; if (format.equals(PIXEL_FORMAT_YUV422SP)) if (format.equals(PIXEL_FORMAT_YUV422SP)) return PixelFormat.YCbCr_422_SP; return ImageFormat.NV16; if (format.equals(PIXEL_FORMAT_YUV420SP)) if (format.equals(PIXEL_FORMAT_YUV420SP)) return PixelFormat.YCbCr_420_SP; return ImageFormat.NV21; if (format.equals(PIXEL_FORMAT_YUV422I)) if (format.equals(PIXEL_FORMAT_YUV422I)) return PixelFormat.YCbCr_422_I; return ImageFormat.YUY2; if (format.equals(PIXEL_FORMAT_RGB565)) if (format.equals(PIXEL_FORMAT_RGB565)) return PixelFormat.RGB_565; return ImageFormat.RGB_565; if (format.equals(PIXEL_FORMAT_JPEG)) if (format.equals(PIXEL_FORMAT_JPEG)) return PixelFormat.JPEG; return ImageFormat.JPEG; return PixelFormat.UNKNOWN; return ImageFormat.UNKNOWN; } } /** /** Loading core/jni/android/graphics/YuvToJpegEncoder.cpp +2 −2 Original line number Original line Diff line number Diff line Loading @@ -7,9 +7,9 @@ #include <jni.h> #include <jni.h> YuvToJpegEncoder* YuvToJpegEncoder::create(int format, int* strides) { YuvToJpegEncoder* YuvToJpegEncoder::create(int format, int* strides) { // Only PIXEL_FORMAT_YCbCr_420_SP and PIXEl_FOMAT_YCbCr_422_I are supported // Only ImageFormat.NV21 and ImageFormat.YUY2 are supported // for now. // for now. if (format == HAL_PIXEL_FORMAT_YCbCr_420_SP) { if (format == HAL_PIXEL_FORMAT_YCrCb_420_SP) { return new Yuv420SpToJpegEncoder(strides); return new Yuv420SpToJpegEncoder(strides); } else if (format == HAL_PIXEL_FORMAT_YCbCr_422_I) { } else if (format == HAL_PIXEL_FORMAT_YCbCr_422_I) { return new Yuv422IToJpegEncoder(strides); return new Yuv422IToJpegEncoder(strides); Loading core/jni/android_graphics_PixelFormat.cpp +25 −1 Original line number Original line Diff line number Diff line Loading @@ -48,11 +48,35 @@ static void android_graphics_getPixelFormatInfo( JNIEnv* env, jobject clazz, jint format, jobject pixelFormatObject) JNIEnv* env, jobject clazz, jint format, jobject pixelFormatObject) { { PixelFormatInfo info; PixelFormatInfo info; status_t err = getPixelFormatInfo(format, &info); status_t err; // we need this for backward compatibility with PixelFormat's // deprecated constants switch (format) { case HAL_PIXEL_FORMAT_YCbCr_422_SP: // defined as the bytes per pixel of the Y plane info.bytesPerPixel = 1; info.bitsPerPixel = 16; goto done; case HAL_PIXEL_FORMAT_YCrCb_420_SP: // defined as the bytes per pixel of the Y plane info.bytesPerPixel = 1; info.bitsPerPixel = 12; goto done; case HAL_PIXEL_FORMAT_YCbCr_422_I: // defined as the bytes per pixel of the Y plane info.bytesPerPixel = 1; info.bitsPerPixel = 16; goto done; } err = getPixelFormatInfo(format, &info); if (err < 0) { if (err < 0) { doThrow(env, "java/lang/IllegalArgumentException"); doThrow(env, "java/lang/IllegalArgumentException"); return; return; } } done: env->SetIntField(pixelFormatObject, offsets.bytesPerPixel, info.bytesPerPixel); env->SetIntField(pixelFormatObject, offsets.bytesPerPixel, info.bytesPerPixel); env->SetIntField(pixelFormatObject, offsets.bitsPerPixel, info.bitsPerPixel); env->SetIntField(pixelFormatObject, offsets.bitsPerPixel, info.bitsPerPixel); } } Loading graphics/java/android/graphics/ImageFormat.java 0 → 100644 +76 −0 Original line number Original line Diff line number Diff line /* * Copyright (C) 2010 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; public class ImageFormat { /* these constants are chosen to be binary compatible with * their previous location in PixelFormat.java */ public static final int UNKNOWN = 0; /** RGB format used for pictures encoded as RGB_565 * see {@link android.hardware.Camera.Parameters#setPictureFormat(int)}. */ public static final int RGB_565 = 4; /** * YCbCr formats, used for video. These are not necessarily supported * by the hardware. */ public static final int NV16 = 0x10; /** YCrCb format used for images, which uses the NV21 encoding format. * This is the default format for camera preview images, when not * otherwise set with * {@link android.hardware.Camera.Parameters#setPreviewFormat(int)}. */ public static final int NV21 = 0x11; /** YCbCr format used for images, which uses YUYV (YUY2) encoding format. * This is an alternative format for camera preview images. Whether this * format is supported by the camera hardware can be determined by * {@link android.hardware.Camera.Parameters#getSupportedPreviewFormats()}. */ public static final int YUY2 = 0x14; /** * Encoded formats. These are not necessarily supported by the hardware. */ public static final int JPEG = 0x100; /** * Use this function to retrieve the number of bits per pixel of * an ImageFormat. * @param format * @return the number of bits per pixel of the given format or -1 if the * format doesn't exist or is not supported. */ public static int getBitsPerPixel(int format) { switch (format) { case RGB_565: return 16; case NV16: return 16; case NV21: return 12; case YUY2: return 16; } return -1; } } Loading
api/current.xml +100 −4 Original line number Original line Diff line number Diff line Loading @@ -60412,6 +60412,102 @@ </parameter> </parameter> </constructor> </constructor> </class> </class> <class name="ImageFormat" extends="java.lang.Object" abstract="false" static="false" final="false" deprecated="not deprecated" visibility="public" > <constructor name="ImageFormat" type="android.graphics.ImageFormat" static="false" final="false" deprecated="not deprecated" visibility="public" > </constructor> <method name="getBitsPerPixel" return="int" abstract="false" native="false" synchronized="false" static="true" final="false" deprecated="not deprecated" visibility="public" > <parameter name="format" type="int"> </parameter> </method> <field name="JPEG" type="int" transient="false" volatile="false" value="256" static="true" final="true" deprecated="not deprecated" visibility="public" > </field> <field name="NV16" type="int" transient="false" volatile="false" value="16" static="true" final="true" deprecated="not deprecated" visibility="public" > </field> <field name="NV21" type="int" transient="false" volatile="false" value="17" static="true" final="true" deprecated="not deprecated" visibility="public" > </field> <field name="RGB_565" type="int" transient="false" volatile="false" value="4" static="true" final="true" deprecated="not deprecated" visibility="public" > </field> <field name="UNKNOWN" type="int" transient="false" volatile="false" value="0" static="true" final="true" deprecated="not deprecated" visibility="public" > </field> <field name="YUY2" type="int" transient="false" volatile="false" value="20" static="true" final="true" deprecated="not deprecated" visibility="public" > </field> </class> <class name="Interpolator" <class name="Interpolator" extends="java.lang.Object" extends="java.lang.Object" abstract="false" abstract="false" Loading Loading @@ -64473,7 +64569,7 @@ value="256" value="256" static="true" static="true" final="true" final="true" deprecated="not deprecated" deprecated="deprecated" visibility="public" visibility="public" > > </field> </field> Loading Loading @@ -64627,7 +64723,7 @@ value="17" value="17" static="true" static="true" final="true" final="true" deprecated="not deprecated" deprecated="deprecated" visibility="public" visibility="public" > > </field> </field> Loading @@ -64638,7 +64734,7 @@ value="20" value="20" static="true" static="true" final="true" final="true" deprecated="not deprecated" deprecated="deprecated" visibility="public" visibility="public" > > </field> </field> Loading @@ -64649,7 +64745,7 @@ value="16" value="16" static="true" static="true" final="true" final="true" deprecated="not deprecated" deprecated="deprecated" visibility="public" visibility="public" > > </field> </field>
core/java/android/hardware/Camera.java +31 −31 Original line number Original line Diff line number Diff line Loading @@ -26,7 +26,7 @@ import java.io.IOException; import android.util.Log; import android.util.Log; import android.view.Surface; import android.view.Surface; import android.view.SurfaceHolder; import android.view.SurfaceHolder; import android.graphics.PixelFormat; import android.graphics.ImageFormat; import android.os.Handler; import android.os.Handler; import android.os.Looper; import android.os.Looper; import android.os.Message; import android.os.Message; Loading Loading @@ -192,7 +192,7 @@ public class Camera { * The callback that delivers the preview frames. * The callback that delivers the preview frames. * * * @param data The contents of the preview frame in the format defined * @param data The contents of the preview frame in the format defined * by {@link android.graphics.PixelFormat}, which can be queried * by {@link android.graphics.ImageFormat}, which can be queried * with {@link android.hardware.Camera.Parameters#getPreviewFormat()}. * with {@link android.hardware.Camera.Parameters#getPreviewFormat()}. * If {@link android.hardware.Camera.Parameters#setPreviewFormat(int)} * If {@link android.hardware.Camera.Parameters#setPreviewFormat(int)} * is never called, the default will be the YCbCr_420_SP * is never called, the default will be the YCbCr_420_SP Loading Loading @@ -276,7 +276,7 @@ public class Camera { * Adds a pre-allocated buffer to the callback buffer queue. * Adds a pre-allocated buffer to the callback buffer queue. * Preview width and height can be determined from getPreviewSize, and bitsPerPixel can be * Preview width and height can be determined from getPreviewSize, and bitsPerPixel can be * found from from {@link android.hardware.Camera.Parameters#getPreviewFormat()} and * found from from {@link android.hardware.Camera.Parameters#getPreviewFormat()} and * {@link android.graphics.PixelFormat#getPixelFormatInfo(int, PixelFormat)} * {@link android.graphics.ImageFormat#getBitsPerPixel(int)} * * * Alternatively, a buffer from a previous callback may be passed in or used * Alternatively, a buffer from a previous callback may be passed in or used * to determine the size of new preview frame buffers. * to determine the size of new preview frame buffers. Loading Loading @@ -1086,15 +1086,15 @@ public class Camera { /** /** * Sets the image format for preview pictures. * Sets the image format for preview pictures. * <p>If this is never called, the default format will be * <p>If this is never called, the default format will be * {@link android.graphics.PixelFormat#YCbCr_420_SP}, which * {@link android.graphics.ImageFormat#NV21}, which * uses the NV21 encoding format.</p> * uses the NV21 encoding format.</p> * * * @param pixel_format the desired preview picture format, defined * @param pixel_format the desired preview picture format, defined * by one of the {@link android.graphics.PixelFormat} constants. * by one of the {@link android.graphics.ImageFormat} constants. * (E.g., <var>PixelFormat.YCbCr_420_SP</var> (default), * (E.g., <var>ImageFormat.NV21</var> (default), * <var>PixelFormat.RGB_565</var>, or * <var>ImageFormat.RGB_565</var>, or * <var>PixelFormat.JPEG</var>) * <var>ImageFormat.JPEG</var>) * @see android.graphics.PixelFormat * @see android.graphics.ImageFormat */ */ public void setPreviewFormat(int pixel_format) { public void setPreviewFormat(int pixel_format) { String s = cameraFormatForPixelFormat(pixel_format); String s = cameraFormatForPixelFormat(pixel_format); Loading @@ -1110,7 +1110,7 @@ public class Camera { * Returns the image format for preview pictures got from * Returns the image format for preview pictures got from * {@link PreviewCallback}. * {@link PreviewCallback}. * * * @return the {@link android.graphics.PixelFormat} int representing * @return the {@link android.graphics.ImageFormat} int representing * the preview picture format. * the preview picture format. */ */ public int getPreviewFormat() { public int getPreviewFormat() { Loading @@ -1128,7 +1128,7 @@ public class Camera { ArrayList<Integer> formats = new ArrayList<Integer>(); ArrayList<Integer> formats = new ArrayList<Integer>(); for (String s : split(str)) { for (String s : split(str)) { int f = pixelFormatForCameraFormat(s); int f = pixelFormatForCameraFormat(s); if (f == PixelFormat.UNKNOWN) continue; if (f == ImageFormat.UNKNOWN) continue; formats.add(f); formats.add(f); } } return formats; return formats; Loading Loading @@ -1171,10 +1171,10 @@ public class Camera { * Sets the image format for pictures. * Sets the image format for pictures. * * * @param pixel_format the desired picture format * @param pixel_format the desired picture format * (<var>PixelFormat.YCbCr_420_SP (NV21)</var>, * (<var>ImageFormat.NV21</var>, * <var>PixelFormat.RGB_565</var>, or * <var>ImageFormat.RGB_565</var>, or * <var>PixelFormat.JPEG</var>) * <var>ImageFormat.JPEG</var>) * @see android.graphics.PixelFormat * @see android.graphics.ImageFormat */ */ public void setPictureFormat(int pixel_format) { public void setPictureFormat(int pixel_format) { String s = cameraFormatForPixelFormat(pixel_format); String s = cameraFormatForPixelFormat(pixel_format); Loading @@ -1189,7 +1189,7 @@ public class Camera { /** /** * Returns the image format for pictures. * Returns the image format for pictures. * * * @return the PixelFormat int representing the picture format * @return the ImageFormat int representing the picture format */ */ public int getPictureFormat() { public int getPictureFormat() { return pixelFormatForCameraFormat(get(KEY_PICTURE_FORMAT)); return pixelFormatForCameraFormat(get(KEY_PICTURE_FORMAT)); Loading @@ -1198,7 +1198,7 @@ public class Camera { /** /** * Gets the supported picture formats. * Gets the supported picture formats. * * * @return a List of Integer objects (values are PixelFormat.XXX). This * @return a List of Integer objects (values are ImageFormat.XXX). This * method will always return a list with at least one element. * method will always return a list with at least one element. */ */ public List<Integer> getSupportedPictureFormats() { public List<Integer> getSupportedPictureFormats() { Loading @@ -1206,7 +1206,7 @@ public class Camera { ArrayList<Integer> formats = new ArrayList<Integer>(); ArrayList<Integer> formats = new ArrayList<Integer>(); for (String s : split(str)) { for (String s : split(str)) { int f = pixelFormatForCameraFormat(s); int f = pixelFormatForCameraFormat(s); if (f == PixelFormat.UNKNOWN) continue; if (f == ImageFormat.UNKNOWN) continue; formats.add(f); formats.add(f); } } return formats; return formats; Loading @@ -1214,35 +1214,35 @@ public class Camera { private String cameraFormatForPixelFormat(int pixel_format) { private String cameraFormatForPixelFormat(int pixel_format) { switch(pixel_format) { switch(pixel_format) { case PixelFormat.YCbCr_422_SP: return PIXEL_FORMAT_YUV422SP; case ImageFormat.NV16: return PIXEL_FORMAT_YUV422SP; case PixelFormat.YCbCr_420_SP: return PIXEL_FORMAT_YUV420SP; case ImageFormat.NV21: return PIXEL_FORMAT_YUV420SP; case PixelFormat.YCbCr_422_I: return PIXEL_FORMAT_YUV422I; case ImageFormat.YUY2: return PIXEL_FORMAT_YUV422I; case PixelFormat.RGB_565: return PIXEL_FORMAT_RGB565; case ImageFormat.RGB_565: return PIXEL_FORMAT_RGB565; case PixelFormat.JPEG: return PIXEL_FORMAT_JPEG; case ImageFormat.JPEG: return PIXEL_FORMAT_JPEG; default: return null; default: return null; } } } } private int pixelFormatForCameraFormat(String format) { private int pixelFormatForCameraFormat(String format) { if (format == null) if (format == null) return PixelFormat.UNKNOWN; return ImageFormat.UNKNOWN; if (format.equals(PIXEL_FORMAT_YUV422SP)) if (format.equals(PIXEL_FORMAT_YUV422SP)) return PixelFormat.YCbCr_422_SP; return ImageFormat.NV16; if (format.equals(PIXEL_FORMAT_YUV420SP)) if (format.equals(PIXEL_FORMAT_YUV420SP)) return PixelFormat.YCbCr_420_SP; return ImageFormat.NV21; if (format.equals(PIXEL_FORMAT_YUV422I)) if (format.equals(PIXEL_FORMAT_YUV422I)) return PixelFormat.YCbCr_422_I; return ImageFormat.YUY2; if (format.equals(PIXEL_FORMAT_RGB565)) if (format.equals(PIXEL_FORMAT_RGB565)) return PixelFormat.RGB_565; return ImageFormat.RGB_565; if (format.equals(PIXEL_FORMAT_JPEG)) if (format.equals(PIXEL_FORMAT_JPEG)) return PixelFormat.JPEG; return ImageFormat.JPEG; return PixelFormat.UNKNOWN; return ImageFormat.UNKNOWN; } } /** /** Loading
core/jni/android/graphics/YuvToJpegEncoder.cpp +2 −2 Original line number Original line Diff line number Diff line Loading @@ -7,9 +7,9 @@ #include <jni.h> #include <jni.h> YuvToJpegEncoder* YuvToJpegEncoder::create(int format, int* strides) { YuvToJpegEncoder* YuvToJpegEncoder::create(int format, int* strides) { // Only PIXEL_FORMAT_YCbCr_420_SP and PIXEl_FOMAT_YCbCr_422_I are supported // Only ImageFormat.NV21 and ImageFormat.YUY2 are supported // for now. // for now. if (format == HAL_PIXEL_FORMAT_YCbCr_420_SP) { if (format == HAL_PIXEL_FORMAT_YCrCb_420_SP) { return new Yuv420SpToJpegEncoder(strides); return new Yuv420SpToJpegEncoder(strides); } else if (format == HAL_PIXEL_FORMAT_YCbCr_422_I) { } else if (format == HAL_PIXEL_FORMAT_YCbCr_422_I) { return new Yuv422IToJpegEncoder(strides); return new Yuv422IToJpegEncoder(strides); Loading
core/jni/android_graphics_PixelFormat.cpp +25 −1 Original line number Original line Diff line number Diff line Loading @@ -48,11 +48,35 @@ static void android_graphics_getPixelFormatInfo( JNIEnv* env, jobject clazz, jint format, jobject pixelFormatObject) JNIEnv* env, jobject clazz, jint format, jobject pixelFormatObject) { { PixelFormatInfo info; PixelFormatInfo info; status_t err = getPixelFormatInfo(format, &info); status_t err; // we need this for backward compatibility with PixelFormat's // deprecated constants switch (format) { case HAL_PIXEL_FORMAT_YCbCr_422_SP: // defined as the bytes per pixel of the Y plane info.bytesPerPixel = 1; info.bitsPerPixel = 16; goto done; case HAL_PIXEL_FORMAT_YCrCb_420_SP: // defined as the bytes per pixel of the Y plane info.bytesPerPixel = 1; info.bitsPerPixel = 12; goto done; case HAL_PIXEL_FORMAT_YCbCr_422_I: // defined as the bytes per pixel of the Y plane info.bytesPerPixel = 1; info.bitsPerPixel = 16; goto done; } err = getPixelFormatInfo(format, &info); if (err < 0) { if (err < 0) { doThrow(env, "java/lang/IllegalArgumentException"); doThrow(env, "java/lang/IllegalArgumentException"); return; return; } } done: env->SetIntField(pixelFormatObject, offsets.bytesPerPixel, info.bytesPerPixel); env->SetIntField(pixelFormatObject, offsets.bytesPerPixel, info.bytesPerPixel); env->SetIntField(pixelFormatObject, offsets.bitsPerPixel, info.bitsPerPixel); env->SetIntField(pixelFormatObject, offsets.bitsPerPixel, info.bitsPerPixel); } } Loading
graphics/java/android/graphics/ImageFormat.java 0 → 100644 +76 −0 Original line number Original line Diff line number Diff line /* * Copyright (C) 2010 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; public class ImageFormat { /* these constants are chosen to be binary compatible with * their previous location in PixelFormat.java */ public static final int UNKNOWN = 0; /** RGB format used for pictures encoded as RGB_565 * see {@link android.hardware.Camera.Parameters#setPictureFormat(int)}. */ public static final int RGB_565 = 4; /** * YCbCr formats, used for video. These are not necessarily supported * by the hardware. */ public static final int NV16 = 0x10; /** YCrCb format used for images, which uses the NV21 encoding format. * This is the default format for camera preview images, when not * otherwise set with * {@link android.hardware.Camera.Parameters#setPreviewFormat(int)}. */ public static final int NV21 = 0x11; /** YCbCr format used for images, which uses YUYV (YUY2) encoding format. * This is an alternative format for camera preview images. Whether this * format is supported by the camera hardware can be determined by * {@link android.hardware.Camera.Parameters#getSupportedPreviewFormats()}. */ public static final int YUY2 = 0x14; /** * Encoded formats. These are not necessarily supported by the hardware. */ public static final int JPEG = 0x100; /** * Use this function to retrieve the number of bits per pixel of * an ImageFormat. * @param format * @return the number of bits per pixel of the given format or -1 if the * format doesn't exist or is not supported. */ public static int getBitsPerPixel(int format) { switch (format) { case RGB_565: return 16; case NV16: return 16; case NV21: return 12; case YUY2: return 16; } return -1; } }