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