OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.media; | 5 package org.chromium.media; |
6 | 6 |
7 import android.annotation.TargetApi; | 7 import android.annotation.TargetApi; |
8 import android.content.Context; | 8 import android.content.Context; |
9 import android.graphics.ImageFormat; | 9 import android.graphics.ImageFormat; |
10 import android.graphics.Rect; | 10 import android.graphics.Rect; |
(...skipping 723 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
734 builder.setCurrentWidth((mPhotoWidth > 0) ? mPhotoWidth : mCaptureFormat
.getWidth()); | 734 builder.setCurrentWidth((mPhotoWidth > 0) ? mPhotoWidth : mCaptureFormat
.getWidth()); |
735 | 735 |
736 final float currentZoom = | 736 final float currentZoom = |
737 cameraCharacteristics.get(CameraCharacteristics.SENSOR_INFO_ACTI
VE_ARRAY_SIZE) | 737 cameraCharacteristics.get(CameraCharacteristics.SENSOR_INFO_ACTI
VE_ARRAY_SIZE) |
738 .width() | 738 .width() |
739 / (float) mPreviewRequest.get(CaptureRequest.SCALER_CROP_REGION)
.width(); | 739 / (float) mPreviewRequest.get(CaptureRequest.SCALER_CROP_REGION)
.width(); |
740 // There is no min-zoom per se, so clamp it to always 1. | 740 // There is no min-zoom per se, so clamp it to always 1. |
741 builder.setMinZoom(1.0).setMaxZoom(mMaxZoom); | 741 builder.setMinZoom(1.0).setMaxZoom(mMaxZoom); |
742 builder.setCurrentZoom(currentZoom).setStepZoom(0.1); | 742 builder.setCurrentZoom(currentZoom).setStepZoom(0.1); |
743 | 743 |
744 final int focusMode = mPreviewRequest.get(CaptureRequest.CONTROL_AF_MODE
); | |
745 // Classify the Focus capabilities. In CONTINUOUS and SINGLE_SHOT, we ca
n call | 744 // Classify the Focus capabilities. In CONTINUOUS and SINGLE_SHOT, we ca
n call |
746 // autoFocus(AutoFocusCallback) to configure region(s) to focus onto. | 745 // autoFocus(AutoFocusCallback) to configure region(s) to focus onto. |
| 746 final int[] jniFocusModes = |
| 747 cameraCharacteristics.get(CameraCharacteristics.CONTROL_AF_AVAIL
ABLE_MODES); |
| 748 ArrayList<Integer> focusModes = new ArrayList<Integer>(3); |
| 749 for (int mode : jniFocusModes) { |
| 750 if (mode == CameraMetadata.CONTROL_AF_MODE_OFF) { |
| 751 focusModes.add(Integer.valueOf(AndroidMeteringMode.FIXED)); |
| 752 } else if (mode == CameraMetadata.CONTROL_AF_MODE_AUTO |
| 753 || mode == CameraMetadata.CONTROL_AF_MODE_MACRO) { |
| 754 // CONTROL_AF_MODE_{AUTO,MACRO} do not imply continuously focusi
ng. |
| 755 if (!focusModes.contains(Integer.valueOf(AndroidMeteringMode.SIN
GLE_SHOT))) { |
| 756 focusModes.add(Integer.valueOf(AndroidMeteringMode.SINGLE_SH
OT)); |
| 757 } |
| 758 } else if (mode == CameraMetadata.CONTROL_AF_MODE_CONTINUOUS_VIDEO |
| 759 || mode == CameraMetadata.CONTROL_AF_MODE_CONTINUOUS_PICTURE |
| 760 || mode == CameraMetadata.CONTROL_AF_MODE_EDOF) { |
| 761 if (!focusModes.contains(Integer.valueOf(AndroidMeteringMode.CON
TINUOUS))) { |
| 762 focusModes.add(Integer.valueOf(AndroidMeteringMode.CONTINUOU
S)); |
| 763 } |
| 764 } |
| 765 } |
| 766 builder.setFocusModes(integerArrayListToArray(focusModes)); |
| 767 |
| 768 final int focusMode = mPreviewRequest.get(CaptureRequest.CONTROL_AF_MODE
); |
747 int jniFocusMode = AndroidMeteringMode.NONE; | 769 int jniFocusMode = AndroidMeteringMode.NONE; |
748 if (focusMode == CameraMetadata.CONTROL_AF_MODE_CONTINUOUS_VIDEO | 770 if (focusMode == CameraMetadata.CONTROL_AF_MODE_CONTINUOUS_VIDEO |
749 || focusMode == CameraMetadata.CONTROL_AF_MODE_CONTINUOUS_PICTUR
E) { | 771 || focusMode == CameraMetadata.CONTROL_AF_MODE_CONTINUOUS_PICTUR
E) { |
750 jniFocusMode = AndroidMeteringMode.CONTINUOUS; | 772 jniFocusMode = AndroidMeteringMode.CONTINUOUS; |
751 } else if (focusMode == CameraMetadata.CONTROL_AF_MODE_AUTO | 773 } else if (focusMode == CameraMetadata.CONTROL_AF_MODE_AUTO |
752 || focusMode == CameraMetadata.CONTROL_AF_MODE_MACRO) { | 774 || focusMode == CameraMetadata.CONTROL_AF_MODE_MACRO) { |
753 jniFocusMode = AndroidMeteringMode.SINGLE_SHOT; | 775 jniFocusMode = AndroidMeteringMode.SINGLE_SHOT; |
754 } else if (focusMode == CameraMetadata.CONTROL_AF_MODE_OFF) { | 776 } else if (focusMode == CameraMetadata.CONTROL_AF_MODE_OFF) { |
755 jniFocusMode = AndroidMeteringMode.FIXED; | 777 jniFocusMode = AndroidMeteringMode.FIXED; |
756 } else { | 778 } else { |
757 assert jniFocusMode == CameraMetadata.CONTROL_AF_MODE_EDOF; | 779 assert jniFocusMode == CameraMetadata.CONTROL_AF_MODE_EDOF; |
758 } | 780 } |
759 builder.setFocusMode(jniFocusMode); | 781 builder.setFocusMode(jniFocusMode); |
760 | 782 |
| 783 // Auto Exposure is the usual capability and state, unless AE is not ava
ilable at all, which |
| 784 // is signalled by an empty CONTROL_AE_AVAILABLE_MODES list. Exposure Co
mpensation can also |
| 785 // support or be locked, this is equivalent to AndroidMeteringMode.FIXED
. |
| 786 final int[] jniExposureModes = |
| 787 cameraCharacteristics.get(CameraCharacteristics.CONTROL_AE_AVAIL
ABLE_MODES); |
| 788 ArrayList<Integer> exposureModes = new ArrayList<Integer>(1); |
| 789 for (int mode : jniExposureModes) { |
| 790 if (mode == CameraMetadata.CONTROL_AE_MODE_ON |
| 791 || mode == CameraMetadata.CONTROL_AE_MODE_ON_AUTO_FLASH |
| 792 || mode == CameraMetadata.CONTROL_AE_MODE_ON_ALWAYS_FLASH |
| 793 || mode == CameraMetadata.CONTROL_AE_MODE_ON_AUTO_FLASH_REDE
YE) { |
| 794 exposureModes.add(Integer.valueOf(AndroidMeteringMode.CONTINUOUS
)); |
| 795 break; |
| 796 } |
| 797 } |
| 798 // TODO(mcasas): query |cameraCharacteristics| for CONTROL_AE_LOCK_AVAIL
ABLE (API 23) |
| 799 builder.setExposureModes(integerArrayListToArray(exposureModes)); |
| 800 |
761 int jniExposureMode = AndroidMeteringMode.CONTINUOUS; | 801 int jniExposureMode = AndroidMeteringMode.CONTINUOUS; |
762 if (mPreviewRequest.get(CaptureRequest.CONTROL_AE_MODE) | 802 if (mPreviewRequest.get(CaptureRequest.CONTROL_AE_MODE) |
763 == CameraMetadata.CONTROL_AE_MODE_OFF) { | 803 == CameraMetadata.CONTROL_AE_MODE_OFF) { |
764 jniExposureMode = AndroidMeteringMode.NONE; | 804 jniExposureMode = AndroidMeteringMode.NONE; |
765 } | 805 } |
766 if (mPreviewRequest.get(CaptureRequest.CONTROL_AE_LOCK)) { | 806 if (mPreviewRequest.get(CaptureRequest.CONTROL_AE_LOCK)) { |
767 jniExposureMode = AndroidMeteringMode.FIXED; | 807 jniExposureMode = AndroidMeteringMode.FIXED; |
768 } | 808 } |
769 builder.setExposureMode(jniExposureMode); | 809 builder.setExposureMode(jniExposureMode); |
770 | 810 |
771 final float step = | 811 final float step = |
772 cameraCharacteristics.get(CameraCharacteristics.CONTROL_AE_COMPE
NSATION_STEP) | 812 cameraCharacteristics.get(CameraCharacteristics.CONTROL_AE_COMPE
NSATION_STEP) |
773 .floatValue(); | 813 .floatValue(); |
774 builder.setStepExposureCompensation(step); | 814 builder.setStepExposureCompensation(step); |
775 final Range<Integer> exposureCompensationRange = | 815 final Range<Integer> exposureCompensationRange = |
776 cameraCharacteristics.get(CameraCharacteristics.CONTROL_AE_COMPE
NSATION_RANGE); | 816 cameraCharacteristics.get(CameraCharacteristics.CONTROL_AE_COMPE
NSATION_RANGE); |
777 builder.setMinExposureCompensation(exposureCompensationRange.getLower()
* step); | 817 builder.setMinExposureCompensation(exposureCompensationRange.getLower()
* step); |
778 builder.setMaxExposureCompensation(exposureCompensationRange.getUpper()
* step); | 818 builder.setMaxExposureCompensation(exposureCompensationRange.getUpper()
* step); |
779 builder.setCurrentExposureCompensation( | 819 builder.setCurrentExposureCompensation( |
780 mPreviewRequest.get(CaptureRequest.CONTROL_AE_EXPOSURE_COMPENSAT
ION) * step); | 820 mPreviewRequest.get(CaptureRequest.CONTROL_AE_EXPOSURE_COMPENSAT
ION) * step); |
781 | 821 |
| 822 final int[] jniWhiteBalanceMode = |
| 823 cameraCharacteristics.get(CameraCharacteristics.CONTROL_AWB_AVAI
LABLE_MODES); |
| 824 ArrayList<Integer> whiteBalanceModes = new ArrayList<Integer>(1); |
| 825 for (int mode : jniWhiteBalanceMode) { |
| 826 if (mode == CameraMetadata.CONTROL_AWB_MODE_AUTO) { |
| 827 whiteBalanceModes.add(Integer.valueOf(AndroidMeteringMode.CONTIN
UOUS)); |
| 828 break; |
| 829 } |
| 830 } |
| 831 // TODO(mcasas): query |cameraCharacteristics| for CONTROL_AWE_LOCK_AVAI
LABLE (API 23) |
| 832 builder.setWhiteBalanceModes(integerArrayListToArray(whiteBalanceModes))
; |
| 833 |
782 final int whiteBalanceMode = mPreviewRequest.get(CaptureRequest.CONTROL_
AWB_MODE); | 834 final int whiteBalanceMode = mPreviewRequest.get(CaptureRequest.CONTROL_
AWB_MODE); |
783 if (whiteBalanceMode == CameraMetadata.CONTROL_AWB_MODE_OFF) { | 835 if (whiteBalanceMode == CameraMetadata.CONTROL_AWB_MODE_OFF) { |
784 builder.setWhiteBalanceMode(AndroidMeteringMode.NONE); | 836 builder.setWhiteBalanceMode(AndroidMeteringMode.NONE); |
785 } else if (whiteBalanceMode == CameraMetadata.CONTROL_AWB_MODE_AUTO) { | 837 } else if (whiteBalanceMode == CameraMetadata.CONTROL_AWB_MODE_AUTO) { |
786 builder.setWhiteBalanceMode(AndroidMeteringMode.CONTINUOUS); | 838 builder.setWhiteBalanceMode(AndroidMeteringMode.CONTINUOUS); |
787 } else { | 839 } else { |
788 builder.setWhiteBalanceMode(AndroidMeteringMode.FIXED); | 840 builder.setWhiteBalanceMode(AndroidMeteringMode.FIXED); |
789 } | 841 } |
790 builder.setMinColorTemperature(COLOR_TEMPERATURES_MAP.keyAt(0)); | 842 builder.setMinColorTemperature(COLOR_TEMPERATURES_MAP.keyAt(0)); |
791 builder.setMaxColorTemperature( | 843 builder.setMaxColorTemperature( |
(...skipping 21 matching lines...) Expand all Loading... |
813 ArrayList<Integer> modes = new ArrayList<Integer>(0); | 865 ArrayList<Integer> modes = new ArrayList<Integer>(0); |
814 for (int flashMode : flashModes) { | 866 for (int flashMode : flashModes) { |
815 if (flashMode == CameraMetadata.FLASH_MODE_OFF) { | 867 if (flashMode == CameraMetadata.FLASH_MODE_OFF) { |
816 modes.add(Integer.valueOf(AndroidFillLightMode.OFF)); | 868 modes.add(Integer.valueOf(AndroidFillLightMode.OFF)); |
817 } else if (flashMode == CameraMetadata.CONTROL_AE_MODE_ON_AUTO_F
LASH) { | 869 } else if (flashMode == CameraMetadata.CONTROL_AE_MODE_ON_AUTO_F
LASH) { |
818 modes.add(Integer.valueOf(AndroidFillLightMode.AUTO)); | 870 modes.add(Integer.valueOf(AndroidFillLightMode.AUTO)); |
819 } else if (flashMode == CameraMetadata.CONTROL_AE_MODE_ON_ALWAYS
_FLASH) { | 871 } else if (flashMode == CameraMetadata.CONTROL_AE_MODE_ON_ALWAYS
_FLASH) { |
820 modes.add(Integer.valueOf(AndroidFillLightMode.FLASH)); | 872 modes.add(Integer.valueOf(AndroidFillLightMode.FLASH)); |
821 } | 873 } |
822 } | 874 } |
823 int[] modesAsIntArray = new int[modes.size()]; | 875 builder.setFillLightModes(integerArrayListToArray(modes)); |
824 for (int i = 0; i < modes.size(); i++) modesAsIntArray[i] = modes.ge
t(i).intValue(); | |
825 builder.setFillLightModes(modesAsIntArray); | |
826 } | 876 } |
827 | 877 |
828 return builder.build(); | 878 return builder.build(); |
829 } | 879 } |
830 | 880 |
831 @Override | 881 @Override |
832 public void setPhotoOptions(double zoom, int focusMode, int exposureMode, do
uble width, | 882 public void setPhotoOptions(double zoom, int focusMode, int exposureMode, do
uble width, |
833 double height, float[] pointsOfInterest2D, boolean hasExposureCompen
sation, | 883 double height, float[] pointsOfInterest2D, boolean hasExposureCompen
sation, |
834 double exposureCompensation, int whiteBalanceMode, double iso, | 884 double exposureCompensation, int whiteBalanceMode, double iso, |
835 boolean hasRedEyeReduction, boolean redEyeReduction, int fillLightMo
de, | 885 boolean hasRedEyeReduction, boolean redEyeReduction, int fillLightMo
de, |
(...skipping 27 matching lines...) Expand all Loading... |
863 // Also clear |mAreaOfInterest| if the user sets it as NONE. | 913 // Also clear |mAreaOfInterest| if the user sets it as NONE. |
864 if (mFocusMode == AndroidMeteringMode.NONE || mExposureMode == AndroidMe
teringMode.NONE) { | 914 if (mFocusMode == AndroidMeteringMode.NONE || mExposureMode == AndroidMe
teringMode.NONE) { |
865 mAreaOfInterest = null; | 915 mAreaOfInterest = null; |
866 } | 916 } |
867 // Update |mAreaOfInterest| if the camera supports and there are |points
OfInterest2D|. | 917 // Update |mAreaOfInterest| if the camera supports and there are |points
OfInterest2D|. |
868 final boolean pointsOfInterestSupported = | 918 final boolean pointsOfInterestSupported = |
869 cameraCharacteristics.get(CameraCharacteristics.CONTROL_MAX_REGI
ONS_AF) > 0 | 919 cameraCharacteristics.get(CameraCharacteristics.CONTROL_MAX_REGI
ONS_AF) > 0 |
870 || cameraCharacteristics.get(CameraCharacteristics.CONTROL_MAX_R
EGIONS_AE) > 0 | 920 || cameraCharacteristics.get(CameraCharacteristics.CONTROL_MAX_R
EGIONS_AE) > 0 |
871 || cameraCharacteristics.get(CameraCharacteristics.CONTROL_MAX_R
EGIONS_AWB) > 0; | 921 || cameraCharacteristics.get(CameraCharacteristics.CONTROL_MAX_R
EGIONS_AWB) > 0; |
872 if (pointsOfInterestSupported && pointsOfInterest2D.length > 0) { | 922 if (pointsOfInterestSupported && pointsOfInterest2D.length > 0) { |
873 assert pointsOfInterest2D.length == 1 : "Only 1 point of interest su
pported"; | 923 assert pointsOfInterest2D.length == 2 : "Only 1 point of interest su
pported"; |
874 assert pointsOfInterest2D[0] <= 1.0 && pointsOfInterest2D[0] >= 0.0; | 924 assert pointsOfInterest2D[0] <= 1.0 && pointsOfInterest2D[0] >= 0.0; |
875 assert pointsOfInterest2D[1] <= 1.0 && pointsOfInterest2D[1] >= 0.0; | 925 assert pointsOfInterest2D[1] <= 1.0 && pointsOfInterest2D[1] >= 0.0; |
876 // Calculate a Rect of 1/8 the |visibleRect| dimensions, and center
it w.r.t. |canvas|. | 926 // Calculate a Rect of 1/8 the |visibleRect| dimensions, and center
it w.r.t. |canvas|. |
877 final Rect visibleRect = (mCropRect.isEmpty()) ? canvas : mCropRect; | 927 final Rect visibleRect = (mCropRect.isEmpty()) ? canvas : mCropRect; |
878 int centerX = Math.round(pointsOfInterest2D[0] * visibleRect.width()
); | 928 int centerX = Math.round(pointsOfInterest2D[0] * visibleRect.width()
); |
879 int centerY = Math.round(pointsOfInterest2D[1] * visibleRect.height(
)); | 929 int centerY = Math.round(pointsOfInterest2D[1] * visibleRect.height(
)); |
880 if (visibleRect.equals(mCropRect)) { | 930 if (visibleRect.equals(mCropRect)) { |
881 centerX += (canvas.width() - visibleRect.width()) / 2; | 931 centerX += (canvas.width() - visibleRect.width()) / 2; |
882 centerY += (canvas.height() - visibleRect.height()) / 2; | 932 centerY += (canvas.height() - visibleRect.height()) / 2; |
883 } | 933 } |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
970 return false; | 1020 return false; |
971 } | 1021 } |
972 return true; | 1022 return true; |
973 } | 1023 } |
974 | 1024 |
975 @Override | 1025 @Override |
976 public void deallocate() { | 1026 public void deallocate() { |
977 Log.d(TAG, "deallocate"); | 1027 Log.d(TAG, "deallocate"); |
978 } | 1028 } |
979 } | 1029 } |
OLD | NEW |