summaryrefslogtreecommitdiffstats
path: root/graphics/java
diff options
context:
space:
mode:
authorMathias Agopian <mathias@google.com>2010-02-17 17:53:09 -0800
committerMathias Agopian <mathias@google.com>2010-02-18 15:32:47 -0800
commita696f5d667227365da732481770767dcb330dd23 (patch)
tree0a89f08df3f88daea3f29948c8d5cdd7675a3fff /graphics/java
parentbe8af08cf4cf9384b3fa13c853c40d761211ceed (diff)
downloadframeworks_base-a696f5d667227365da732481770767dcb330dd23.zip
frameworks_base-a696f5d667227365da732481770767dcb330dd23.tar.gz
frameworks_base-a696f5d667227365da732481770767dcb330dd23.tar.bz2
Add ImageFormat.java and move the Camera/YUV constants from PixelFormat to it.
PixelFormat's corresponding constansts are now deprecated.
Diffstat (limited to 'graphics/java')
-rw-r--r--graphics/java/android/graphics/ImageFormat.java76
-rw-r--r--graphics/java/android/graphics/PixelFormat.java31
-rw-r--r--graphics/java/android/graphics/YuvImage.java24
3 files changed, 105 insertions, 26 deletions
diff --git a/graphics/java/android/graphics/ImageFormat.java b/graphics/java/android/graphics/ImageFormat.java
new file mode 100644
index 0000000..f126374
--- /dev/null
+++ b/graphics/java/android/graphics/ImageFormat.java
@@ -0,0 +1,76 @@
+/*
+ * 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;
+ }
+}
diff --git a/graphics/java/android/graphics/PixelFormat.java b/graphics/java/android/graphics/PixelFormat.java
index c76cee7..182f14d 100644
--- a/graphics/java/android/graphics/PixelFormat.java
+++ b/graphics/java/android/graphics/PixelFormat.java
@@ -18,8 +18,7 @@ package android.graphics;
public class PixelFormat
{
- /* these constants need to match those
- in ui/PixelFormat.h & pixelflinger/format.h */
+ /* these constants need to match those in hardware/hardware.h */
public static final int UNKNOWN = 0;
@@ -46,30 +45,34 @@ public class PixelFormat
public static final int L_8 = 9;
public static final int LA_88 = 0xA;
public static final int RGB_332 = 0xB;
-
+
+
/**
- * YCbCr formats, used for video. These are not necessarily supported
- * by the hardware.
+ * @deprecated use {@link android.graphics.ImageFormat#NV16
+ * ImageFormat.NV16} instead.
*/
+ @Deprecated
public static final int YCbCr_422_SP= 0x10;
- /** YCbCr 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)}.
+ /**
+ * @deprecated use {@link android.graphics.ImageFormat#NV21
+ * ImageFormat.NV21} instead.
*/
+ @Deprecated
public static final int YCbCr_420_SP= 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()}.
+ /**
+ * @deprecated use {@link android.graphics.ImageFormat#YUY2
+ * ImageFormat.YUY2} instead.
*/
+ @Deprecated
public static final int YCbCr_422_I = 0x14;
/**
- * Encoded formats. These are not necessarily supported by the hardware.
+ * @deprecated use {@link android.graphics.ImageFormat#JPEG
+ * ImageFormat.JPEG} instead.
*/
+ @Deprecated
public static final int JPEG = 0x100;
/*
diff --git a/graphics/java/android/graphics/YuvImage.java b/graphics/java/android/graphics/YuvImage.java
index 5a4531b..9368da6 100644
--- a/graphics/java/android/graphics/YuvImage.java
+++ b/graphics/java/android/graphics/YuvImage.java
@@ -22,7 +22,7 @@ import java.io.OutputStream;
* YuvImage contains YUV data and provides a method that compresses a region of
* the YUV data to a Jpeg. The YUV data should be provided as a single byte
* array irrespective of the number of image planes in it.
- * Currently only PixelFormat.YCbCr_420_SP and PixelFormat.YCbCr_422_I are supported.
+ * Currently only ImageFormat.NV21 and ImageFormat.YUY2 are supported.
*
* To compress a rectangle region in the YUV data, users have to specify the
* region by left, top, width and height.
@@ -77,11 +77,11 @@ public class YuvImage {
* null.
*/
public YuvImage(byte[] yuv, int format, int width, int height, int[] strides) {
- if (format != PixelFormat.YCbCr_420_SP &&
- format != PixelFormat.YCbCr_422_I) {
+ if (format != ImageFormat.NV21 &&
+ format != ImageFormat.YUY2) {
throw new IllegalArgumentException(
- "only support PixelFormat.YCbCr_420_SP " +
- "and PixelFormat.YCbCr_422_I for now");
+ "only support ImageFormat.NV21 " +
+ "and ImageFormat.YUY2 for now");
}
if (width <= 0 || height <= 0) {
@@ -107,7 +107,7 @@ public class YuvImage {
/**
* Compress a rectangle region in the YuvImage to a jpeg.
- * Only PixelFormat.YCbCr_420_SP and PixelFormat.YCbCr_422_I
+ * Only ImageFormat.NV21 and ImageFormat.YUY2
* are supported for now.
*
* @param rectangle The rectangle region to be compressed. The medthod checks if rectangle is
@@ -181,14 +181,14 @@ public class YuvImage {
int[] calculateOffsets(int left, int top) {
int[] offsets = null;
- if (mFormat == PixelFormat.YCbCr_420_SP) {
+ if (mFormat == ImageFormat.NV21) {
offsets = new int[] {top * mStrides[0] + left,
mHeight * mStrides[0] + top / 2 * mStrides[1]
+ left / 2 * 2 };
return offsets;
}
- if (mFormat == PixelFormat.YCbCr_422_I) {
+ if (mFormat == ImageFormat.YUY2) {
offsets = new int[] {top * mStrides[0] + left / 2 * 4};
return offsets;
}
@@ -198,12 +198,12 @@ public class YuvImage {
private int[] calculateStrides(int width, int format) {
int[] strides = null;
- if (format == PixelFormat.YCbCr_420_SP) {
+ if (format == ImageFormat.NV21) {
strides = new int[] {width, width};
return strides;
}
- if (format == PixelFormat.YCbCr_422_I) {
+ if (format == ImageFormat.YUY2) {
strides = new int[] {width * 2};
return strides;
}
@@ -214,7 +214,7 @@ public class YuvImage {
private void adjustRectangle(Rect rect) {
int width = rect.width();
int height = rect.height();
- if (mFormat == PixelFormat.YCbCr_420_SP) {
+ if (mFormat == ImageFormat.NV21) {
// Make sure left, top, width and height are all even.
width &= ~1;
height &= ~1;
@@ -224,7 +224,7 @@ public class YuvImage {
rect.bottom = rect.top + height;
}
- if (mFormat == PixelFormat.YCbCr_422_I) {
+ if (mFormat == ImageFormat.YUY2) {
// Make sure left and width are both even.
width &= ~1;
rect.left &= ~1;