Camera.java revision e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8ab
1/* 2 * Copyright (C) 2008 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package android.hardware; 18 19import java.lang.ref.WeakReference; 20import java.util.HashMap; 21import java.util.StringTokenizer; 22import java.io.IOException; 23 24import android.util.Log; 25import android.view.Surface; 26import android.view.SurfaceHolder; 27import android.graphics.PixelFormat; 28import android.os.Handler; 29import android.os.Looper; 30import android.os.Message; 31 32/** 33 * The Camera class is used to connect/disconnect with the camera service, 34 * set capture settings, start/stop preview, snap a picture, and retrieve 35 * frames for encoding for video. 36 * <p>There is no default constructor for this class. Use {@link #open()} to 37 * get a Camera object.</p> 38 */ 39public class Camera { 40 private static final String TAG = "Camera"; 41 42 // These match the enums in frameworks/base/include/ui/Camera.h 43 private static final int CAMERA_MSG_ERROR = 0; 44 private static final int CAMERA_MSG_SHUTTER = 1; 45 private static final int CAMERA_MSG_FOCUS = 2; 46 private static final int CAMERA_MSG_ZOOM = 3; 47 private static final int CAMERA_MSG_PREVIEW_FRAME = 4; 48 private static final int CAMERA_MSG_VIDEO_FRAME = 5; 49 private static final int CAMERA_MSG_POSTVIEW_FRAME = 6; 50 private static final int CAMERA_MSG_RAW_IMAGE = 7; 51 private static final int CAMERA_MSG_COMPRESSED_IMAGE = 8; 52 53 private int mNativeContext; // accessed by native methods 54 private EventHandler mEventHandler; 55 private ShutterCallback mShutterCallback; 56 private PictureCallback mRawImageCallback; 57 private PictureCallback mJpegCallback; 58 private PreviewCallback mPreviewCallback; 59 private PictureCallback mPostviewCallback; 60 private AutoFocusCallback mAutoFocusCallback; 61 private ZoomCallback mZoomCallback; 62 private ErrorCallback mErrorCallback; 63 private boolean mOneShot; 64 65 /** 66 * Returns a new Camera object. 67 */ 68 public static Camera open() { 69 return new Camera(); 70 } 71 72 Camera() { 73 mShutterCallback = null; 74 mRawImageCallback = null; 75 mJpegCallback = null; 76 mPreviewCallback = null; 77 mPostviewCallback = null; 78 mZoomCallback = null; 79 80 Looper looper; 81 if ((looper = Looper.myLooper()) != null) { 82 mEventHandler = new EventHandler(this, looper); 83 } else if ((looper = Looper.getMainLooper()) != null) { 84 mEventHandler = new EventHandler(this, looper); 85 } else { 86 mEventHandler = null; 87 } 88 89 native_setup(new WeakReference<Camera>(this)); 90 } 91 92 protected void finalize() { 93 native_release(); 94 } 95 96 private native final void native_setup(Object camera_this); 97 private native final void native_release(); 98 99 100 /** 101 * Disconnects and releases the Camera object resources. 102 * <p>It is recommended that you call this as soon as you're done with the 103 * Camera object.</p> 104 */ 105 public final void release() { 106 native_release(); 107 } 108 109 /** 110 * Reconnect to the camera after passing it to MediaRecorder. To save 111 * setup/teardown time, a client of Camera can pass an initialized Camera 112 * object to a MediaRecorder to use for video recording. Once the 113 * MediaRecorder is done with the Camera, this method can be used to 114 * re-establish a connection with the camera hardware. NOTE: The Camera 115 * object must first be unlocked by the process that owns it before it 116 * can be connected to another proces. 117 * 118 * @throws IOException if the method fails. 119 * 120 * FIXME: Unhide after approval 121 * @hide 122 */ 123 public native final void reconnect() throws IOException; 124 125 /** 126 * Lock the camera to prevent other processes from accessing it. To save 127 * setup/teardown time, a client of Camera can pass an initialized Camera 128 * object to another process. This method is used to re-lock the Camera 129 * object prevent other processes from accessing it. By default, the 130 * Camera object is locked. Locking it again from the same process will 131 * have no effect. Attempting to lock it from another process if it has 132 * not been unlocked will fail. 133 * Returns 0 if lock was successful. 134 * 135 * FIXME: Unhide after approval 136 * @hide 137 */ 138 public native final int lock(); 139 140 /** 141 * Unlock the camera to allow aother process to access it. To save 142 * setup/teardown time, a client of Camera can pass an initialized Camera 143 * object to another process. This method is used to unlock the Camera 144 * object before handing off the Camera object to the other process. 145 146 * Returns 0 if unlock was successful. 147 * 148 * FIXME: Unhide after approval 149 * @hide 150 */ 151 public native final int unlock(); 152 153 /** 154 * Sets the SurfaceHolder to be used for a picture preview. If the surface 155 * changed since the last call, the screen will blank. Nothing happens 156 * if the same surface is re-set. 157 * 158 * @param holder the SurfaceHolder upon which to place the picture preview 159 * @throws IOException if the method fails. 160 */ 161 public final void setPreviewDisplay(SurfaceHolder holder) throws IOException { 162 if (holder != null) { 163 setPreviewDisplay(holder.getSurface()); 164 } else { 165 setPreviewDisplay((Surface)null); 166 } 167 } 168 169 private native final void setPreviewDisplay(Surface surface); 170 171 /** 172 * Used to get a copy of each preview frame. 173 */ 174 public interface PreviewCallback 175 { 176 /** 177 * The callback that delivers the preview frames. 178 * 179 * @param data The contents of the preview frame in getPreviewFormat() 180 * format. 181 * @param camera The Camera service object. 182 */ 183 void onPreviewFrame(byte[] data, Camera camera); 184 }; 185 186 /** 187 * Start drawing preview frames to the surface. 188 */ 189 public native final void startPreview(); 190 191 /** 192 * Stop drawing preview frames to the surface. 193 */ 194 public native final void stopPreview(); 195 196 /** 197 * Return current preview state. 198 * 199 * FIXME: Unhide before release 200 * @hide 201 */ 202 public native final boolean previewEnabled(); 203 204 /** 205 * Can be called at any time to instruct the camera to use a callback for 206 * each preview frame in addition to displaying it. 207 * 208 * @param cb A callback object that receives a copy of each preview frame. 209 * Pass null to stop receiving callbacks at any time. 210 */ 211 public final void setPreviewCallback(PreviewCallback cb) { 212 mPreviewCallback = cb; 213 mOneShot = false; 214 setHasPreviewCallback(cb != null, false); 215 } 216 217 /** 218 * Installs a callback to retrieve a single preview frame, after which the 219 * callback is cleared. 220 * 221 * @param cb A callback object that receives a copy of the preview frame. 222 */ 223 public final void setOneShotPreviewCallback(PreviewCallback cb) { 224 if (cb != null) { 225 mPreviewCallback = cb; 226 mOneShot = true; 227 setHasPreviewCallback(true, true); 228 } 229 } 230 231 private native final void setHasPreviewCallback(boolean installed, boolean oneshot); 232 233 private class EventHandler extends Handler 234 { 235 private Camera mCamera; 236 237 public EventHandler(Camera c, Looper looper) { 238 super(looper); 239 mCamera = c; 240 } 241 242 @Override 243 public void handleMessage(Message msg) { 244 switch(msg.what) { 245 case CAMERA_MSG_SHUTTER: 246 if (mShutterCallback != null) { 247 mShutterCallback.onShutter(); 248 } 249 return; 250 251 case CAMERA_MSG_RAW_IMAGE: 252 if (mRawImageCallback != null) { 253 mRawImageCallback.onPictureTaken((byte[])msg.obj, mCamera); 254 } 255 return; 256 257 case CAMERA_MSG_COMPRESSED_IMAGE: 258 if (mJpegCallback != null) { 259 mJpegCallback.onPictureTaken((byte[])msg.obj, mCamera); 260 } 261 return; 262 263 case CAMERA_MSG_PREVIEW_FRAME: 264 if (mPreviewCallback != null) { 265 mPreviewCallback.onPreviewFrame((byte[])msg.obj, mCamera); 266 if (mOneShot) { 267 mPreviewCallback = null; 268 } 269 } 270 return; 271 272 case CAMERA_MSG_POSTVIEW_FRAME: 273 if (mPostviewCallback != null) { 274 mPostviewCallback.onPictureTaken((byte[])msg.obj, mCamera); 275 } 276 return; 277 278 case CAMERA_MSG_FOCUS: 279 if (mAutoFocusCallback != null) { 280 mAutoFocusCallback.onAutoFocus(msg.arg1 == 0 ? false : true, mCamera); 281 } 282 return; 283 284 case CAMERA_MSG_ZOOM: 285 if (mZoomCallback != null) { 286 mZoomCallback.onZoomUpdate(msg.arg1, mCamera); 287 } 288 return; 289 290 case CAMERA_MSG_ERROR : 291 Log.e(TAG, "Error " + msg.arg1); 292 if (mErrorCallback != null) { 293 mErrorCallback.onError(msg.arg1, mCamera); 294 } 295 return; 296 297 default: 298 Log.e(TAG, "Unknown message type " + msg.what); 299 return; 300 } 301 } 302 } 303 304 private static void postEventFromNative(Object camera_ref, 305 int what, int arg1, int arg2, Object obj) 306 { 307 Camera c = (Camera)((WeakReference)camera_ref).get(); 308 if (c == null) 309 return; 310 311 if (c.mEventHandler != null) { 312 Message m = c.mEventHandler.obtainMessage(what, arg1, arg2, obj); 313 c.mEventHandler.sendMessage(m); 314 } 315 } 316 317 /** 318 * Handles the callback for the camera auto focus. 319 */ 320 public interface AutoFocusCallback 321 { 322 /** 323 * Callback for the camera auto focus. 324 * 325 * @param success true if focus was successful, false if otherwise 326 * @param camera the Camera service object 327 */ 328 void onAutoFocus(boolean success, Camera camera); 329 }; 330 331 /** 332 * Starts auto-focus function and registers a callback function to 333 * run when camera is focused. Only valid after startPreview() has 334 * been called. 335 * 336 * @param cb the callback to run 337 */ 338 public final void autoFocus(AutoFocusCallback cb) 339 { 340 mAutoFocusCallback = cb; 341 native_autoFocus(); 342 } 343 private native final void native_autoFocus(); 344 345 /** 346 * An interface which contains a callback for the shutter closing after taking a picture. 347 */ 348 public interface ShutterCallback 349 { 350 /** 351 * Can be used to play a shutter sound as soon as the image has been captured, but before 352 * the data is available. 353 */ 354 void onShutter(); 355 } 356 357 /** 358 * Handles the callback for when a picture is taken. 359 */ 360 public interface PictureCallback { 361 /** 362 * Callback for when a picture is taken. 363 * 364 * @param data a byte array of the picture data 365 * @param camera the Camera service object 366 */ 367 void onPictureTaken(byte[] data, Camera camera); 368 }; 369 370 /** 371 * Triggers an asynchronous image capture. The camera service 372 * will initiate a series of callbacks to the application as the 373 * image capture progresses. The shutter callback occurs after 374 * the image is captured. This can be used to trigger a sound 375 * to let the user know that image has been captured. The raw 376 * callback occurs when the raw image data is available. The jpeg 377 * callback occurs when the compressed image is available. If the 378 * application does not need a particular callback, a null can be 379 * passed instead of a callback method. 380 * 381 * @param shutter callback after the image is captured, may be null 382 * @param raw callback with raw image data, may be null 383 * @param jpeg callback with jpeg image data, may be null 384 */ 385 public final void takePicture(ShutterCallback shutter, PictureCallback raw, 386 PictureCallback jpeg) { 387 takePicture(shutter, raw, null, jpeg); 388 } 389 private native final void native_takePicture(); 390 391 /** 392 * Triggers an asynchronous image capture. The camera service 393 * will initiate a series of callbacks to the application as the 394 * image capture progresses. The shutter callback occurs after 395 * the image is captured. This can be used to trigger a sound 396 * to let the user know that image has been captured. The raw 397 * callback occurs when the raw image data is available. The 398 * postview callback occurs when a scaled, fully processed 399 * postview image is available (NOTE: not all hardware supports 400 * this). The jpeg callback occurs when the compressed image is 401 * available. If the application does not need a particular 402 * callback, a null can be passed instead of a callback method. 403 * 404 * @param shutter callback after the image is captured, may be null 405 * @param raw callback with raw image data, may be null 406 * @param postview callback with postview image data, may be null 407 * @param jpeg callback with jpeg image data, may be null 408 */ 409 public final void takePicture(ShutterCallback shutter, PictureCallback raw, 410 PictureCallback postview, PictureCallback jpeg) { 411 mShutterCallback = shutter; 412 mRawImageCallback = raw; 413 mPostviewCallback = postview; 414 mJpegCallback = jpeg; 415 native_takePicture(); 416 } 417 418 /** 419 * Handles the zoom callback. 420 */ 421 public interface ZoomCallback 422 { 423 /** 424 * Callback for zoom updates 425 * @param zoomLevel new zoom level in 1/1000 increments, 426 * e.g. a zoom of 3.2x is stored as 3200. Accuracy of the 427 * value is dependent on the hardware implementation. Not 428 * all devices will generate this callback. 429 * @param camera the Camera service object 430 */ 431 void onZoomUpdate(int zoomLevel, Camera camera); 432 }; 433 434 /** 435 * Registers a callback to be invoked when the zoom 436 * level is updated by the camera driver. 437 * @param cb the callback to run 438 */ 439 public final void setZoomCallback(ZoomCallback cb) 440 { 441 mZoomCallback = cb; 442 } 443 444 // These match the enum in include/ui/Camera.h 445 /** Unspecified camerar error. @see #ErrorCallback */ 446 public static final int CAMERA_ERROR_UNKNOWN = 1; 447 /** Media server died. In this case, the application must release the 448 * Camera object and instantiate a new one. @see #ErrorCallback */ 449 public static final int CAMERA_ERROR_SERVER_DIED = 100; 450 451 /** 452 * Handles the camera error callback. 453 */ 454 public interface ErrorCallback 455 { 456 /** 457 * Callback for camera errors. 458 * @param error error code: 459 * <ul> 460 * <li>{@link #CAMERA_ERROR_UNKNOWN} 461 * <li>{@link #CAMERA_ERROR_SERVER_DIED} 462 * </ul> 463 * @param camera the Camera service object 464 */ 465 void onError(int error, Camera camera); 466 }; 467 468 /** 469 * Registers a callback to be invoked when an error occurs. 470 * @param cb the callback to run 471 */ 472 public final void setErrorCallback(ErrorCallback cb) 473 { 474 mErrorCallback = cb; 475 } 476 477 private native final void native_setParameters(String params); 478 private native final String native_getParameters(); 479 480 /** 481 * Sets the Parameters for pictures from this Camera service. 482 * 483 * @param params the Parameters to use for this Camera service 484 */ 485 public void setParameters(Parameters params) { 486 native_setParameters(params.flatten()); 487 } 488 489 /** 490 * Returns the picture Parameters for this Camera service. 491 */ 492 public Parameters getParameters() { 493 Parameters p = new Parameters(); 494 String s = native_getParameters(); 495 p.unflatten(s); 496 return p; 497 } 498 499 /** 500 * Handles the picture size (dimensions). 501 */ 502 public class Size { 503 /** 504 * Sets the dimensions for pictures. 505 * 506 * @param w the photo width (pixels) 507 * @param h the photo height (pixels) 508 */ 509 public Size(int w, int h) { 510 width = w; 511 height = h; 512 } 513 /** width of the picture */ 514 public int width; 515 /** height of the picture */ 516 public int height; 517 }; 518 519 /** 520 * Handles the parameters for pictures created by a Camera service. 521 */ 522 public class Parameters { 523 private HashMap<String, String> mMap; 524 525 private Parameters() { 526 mMap = new HashMap<String, String>(); 527 } 528 529 /** 530 * Writes the current Parameters to the log. 531 * @hide 532 * @deprecated 533 */ 534 public void dump() { 535 Log.e(TAG, "dump: size=" + mMap.size()); 536 for (String k : mMap.keySet()) { 537 Log.e(TAG, "dump: " + k + "=" + mMap.get(k)); 538 } 539 } 540 541 /** 542 * Creates a single string with all the parameters set in 543 * this Parameters object. 544 * <p>The {@link #unflatten(String)} method does the reverse.</p> 545 * 546 * @return a String with all values from this Parameters object, in 547 * semi-colon delimited key-value pairs 548 */ 549 public String flatten() { 550 StringBuilder flattened = new StringBuilder(); 551 for (String k : mMap.keySet()) { 552 flattened.append(k); 553 flattened.append("="); 554 flattened.append(mMap.get(k)); 555 flattened.append(";"); 556 } 557 // chop off the extra semicolon at the end 558 flattened.deleteCharAt(flattened.length()-1); 559 return flattened.toString(); 560 } 561 562 /** 563 * Takes a flattened string of parameters and adds each one to 564 * this Parameters object. 565 * <p>The {@link #flatten()} method does the reverse.</p> 566 * 567 * @param flattened a String of parameters (key-value paired) that 568 * are semi-colon delimited 569 */ 570 public void unflatten(String flattened) { 571 mMap.clear(); 572 573 StringTokenizer tokenizer = new StringTokenizer(flattened, ";"); 574 while (tokenizer.hasMoreElements()) { 575 String kv = tokenizer.nextToken(); 576 int pos = kv.indexOf('='); 577 if (pos == -1) { 578 continue; 579 } 580 String k = kv.substring(0, pos); 581 String v = kv.substring(pos + 1); 582 mMap.put(k, v); 583 } 584 } 585 586 public void remove(String key) { 587 mMap.remove(key); 588 } 589 590 /** 591 * Sets a String parameter. 592 * 593 * @param key the key name for the parameter 594 * @param value the String value of the parameter 595 */ 596 public void set(String key, String value) { 597 if (key.indexOf('=') != -1 || key.indexOf(';') != -1) { 598 Log.e(TAG, "Key \"" + key + "\" contains invalid character (= or ;)"); 599 return; 600 } 601 if (value.indexOf('=') != -1 || value.indexOf(';') != -1) { 602 Log.e(TAG, "Value \"" + value + "\" contains invalid character (= or ;)"); 603 return; 604 } 605 606 mMap.put(key, value); 607 } 608 609 /** 610 * Sets an integer parameter. 611 * 612 * @param key the key name for the parameter 613 * @param value the int value of the parameter 614 */ 615 public void set(String key, int value) { 616 mMap.put(key, Integer.toString(value)); 617 } 618 619 /** 620 * Returns the value of a String parameter. 621 * 622 * @param key the key name for the parameter 623 * @return the String value of the parameter 624 */ 625 public String get(String key) { 626 return mMap.get(key); 627 } 628 629 /** 630 * Returns the value of an integer parameter. 631 * 632 * @param key the key name for the parameter 633 * @return the int value of the parameter 634 */ 635 public int getInt(String key) { 636 return Integer.parseInt(mMap.get(key)); 637 } 638 639 /** 640 * Sets the dimensions for preview pictures. 641 * 642 * @param width the width of the pictures, in pixels 643 * @param height the height of the pictures, in pixels 644 */ 645 public void setPreviewSize(int width, int height) { 646 String v = Integer.toString(width) + "x" + Integer.toString(height); 647 set("preview-size", v); 648 } 649 650 /** 651 * Returns the dimensions setting for preview pictures. 652 * 653 * @return a Size object with the height and width setting 654 * for the preview picture 655 */ 656 public Size getPreviewSize() { 657 String pair = get("preview-size"); 658 if (pair == null) 659 return null; 660 String[] dims = pair.split("x"); 661 if (dims.length != 2) 662 return null; 663 664 return new Size(Integer.parseInt(dims[0]), 665 Integer.parseInt(dims[1])); 666 667 } 668 669 /** 670 * Sets the dimensions for EXIF thumbnails. 671 * 672 * @param width the width of the thumbnail, in pixels 673 * @param height the height of the thumbnail, in pixels 674 * 675 * FIXME: unhide before release 676 * @hide 677 */ 678 public void setThumbnailSize(int width, int height) { 679 set("jpeg-thumbnail-width", width); 680 set("jpeg-thumbnail-height", height); 681 } 682 683 /** 684 * Returns the dimensions for EXIF thumbnail 685 * 686 * @return a Size object with the height and width setting 687 * for the EXIF thumbnails 688 * 689 * FIXME: unhide before release 690 * @hide 691 */ 692 public Size getThumbnailSize() { 693 return new Size(getInt("jpeg-thumbnail-width"), 694 getInt("jpeg-thumbnail-height")); 695 } 696 697 /** 698 * Sets the quality of the EXIF thumbnail 699 * 700 * @param quality the JPEG quality of the EXIT thumbnail 701 * 702 * FIXME: unhide before release 703 * @hide 704 */ 705 public void setThumbnailQuality(int quality) { 706 set("jpeg-thumbnail-quality", quality); 707 } 708 709 /** 710 * Returns the quality setting for the EXIF thumbnail 711 * 712 * @return the JPEG quality setting of the EXIF thumbnail 713 * 714 * FIXME: unhide before release 715 * @hide 716 */ 717 public int getThumbnailQuality() { 718 return getInt("jpeg-thumbnail-quality"); 719 } 720 721 /** 722 * Sets the rate at which preview frames are received. 723 * 724 * @param fps the frame rate (frames per second) 725 */ 726 public void setPreviewFrameRate(int fps) { 727 set("preview-frame-rate", fps); 728 } 729 730 /** 731 * Returns the setting for the rate at which preview frames 732 * are received. 733 * 734 * @return the frame rate setting (frames per second) 735 */ 736 public int getPreviewFrameRate() { 737 return getInt("preview-frame-rate"); 738 } 739 740 /** 741 * Sets the image format for preview pictures. 742 * 743 * @param pixel_format the desired preview picture format 744 * (<var>PixelFormat.YCbCr_420_SP</var>, 745 * <var>PixelFormat.RGB_565</var>, or 746 * <var>PixelFormat.JPEG</var>) 747 * @see android.graphics.PixelFormat 748 */ 749 public void setPreviewFormat(int pixel_format) { 750 String s = cameraFormatForPixelFormat(pixel_format); 751 if (s == null) { 752 throw new IllegalArgumentException(); 753 } 754 755 set("preview-format", s); 756 } 757 758 /** 759 * Returns the image format for preview pictures. 760 * 761 * @return the PixelFormat int representing the preview picture format 762 */ 763 public int getPreviewFormat() { 764 return pixelFormatForCameraFormat(get("preview-format")); 765 } 766 767 /** 768 * Sets the dimensions for pictures. 769 * 770 * @param width the width for pictures, in pixels 771 * @param height the height for pictures, in pixels 772 */ 773 public void setPictureSize(int width, int height) { 774 String v = Integer.toString(width) + "x" + Integer.toString(height); 775 set("picture-size", v); 776 } 777 778 /** 779 * Returns the dimension setting for pictures. 780 * 781 * @return a Size object with the height and width setting 782 * for pictures 783 */ 784 public Size getPictureSize() { 785 String pair = get("picture-size"); 786 if (pair == null) 787 return null; 788 String[] dims = pair.split("x"); 789 if (dims.length != 2) 790 return null; 791 792 return new Size(Integer.parseInt(dims[0]), 793 Integer.parseInt(dims[1])); 794 795 } 796 797 /** 798 * Sets the image format for pictures. 799 * 800 * @param pixel_format the desired picture format 801 * (<var>PixelFormat.YCbCr_420_SP</var>, 802 * <var>PixelFormat.RGB_565</var>, or 803 * <var>PixelFormat.JPEG</var>) 804 * @see android.graphics.PixelFormat 805 */ 806 public void setPictureFormat(int pixel_format) { 807 String s = cameraFormatForPixelFormat(pixel_format); 808 if (s == null) { 809 throw new IllegalArgumentException(); 810 } 811 812 set("picture-format", s); 813 } 814 815 /** 816 * Returns the image format for pictures. 817 * 818 * @return the PixelFormat int representing the picture format 819 */ 820 public int getPictureFormat() { 821 return pixelFormatForCameraFormat(get("picture-format")); 822 } 823 824 private String cameraFormatForPixelFormat(int pixel_format) { 825 switch(pixel_format) { 826 case PixelFormat.YCbCr_422_SP: return "yuv422sp"; 827 case PixelFormat.YCbCr_420_SP: return "yuv420sp"; 828 case PixelFormat.RGB_565: return "rgb565"; 829 case PixelFormat.JPEG: return "jpeg"; 830 default: return null; 831 } 832 } 833 834 private int pixelFormatForCameraFormat(String format) { 835 if (format == null) 836 return PixelFormat.UNKNOWN; 837 838 if (format.equals("yuv422sp")) 839 return PixelFormat.YCbCr_422_SP; 840 841 if (format.equals("yuv420sp")) 842 return PixelFormat.YCbCr_420_SP; 843 844 if (format.equals("rgb565")) 845 return PixelFormat.RGB_565; 846 847 if (format.equals("jpeg")) 848 return PixelFormat.JPEG; 849 850 return PixelFormat.UNKNOWN; 851 } 852 853 }; 854} 855 856 857