@SuppressWarnings("WrongConstant") private void setCameraDisplayOrientation(Camera.Parameters parameters) { Camera.CameraInfo info = new Camera.CameraInfo(); Camera.getCameraInfo(getCurrentCameraId(), info); final int deviceOrientation = Degrees.getDisplayRotation(getActivity()); mDisplayOrientation = Degrees.getDisplayOrientation( info.orientation, deviceOrientation, info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT); Log.d( "CameraFragment", String.format( "Orientations: Sensor = %d˚, Device = %d˚, Display = %d˚", info.orientation, deviceOrientation, mDisplayOrientation)); int previewOrientation; if (CameraUtil.isArcWelder()) { previewOrientation = 0; } else { previewOrientation = mDisplayOrientation; if (Degrees.isPortrait(deviceOrientation) && getCurrentCameraPosition() == CAMERA_POSITION_FRONT) previewOrientation = Degrees.mirror(mDisplayOrientation); } parameters.setRotation(previewOrientation); mCamera.setDisplayOrientation(previewOrientation); }
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) { Log.e(TAG, "surfaceChanged => w=" + w + ", h=" + h); // If your preview can change or rotate, take care of those events here. // Make sure to stop the preview before resizing or reformatting it. if (mHolder.getSurface() == null) { // preview surface does not exist return; } // stop preview before making changes try { mCamera.stopPreview(); } catch (Exception e) { // ignore: tried to stop a non-existent preview } // set preview size and make any resize, rotate or reformatting changes here // start preview with new settings try { Camera.Parameters parameters = mCamera.getParameters(); /* INSERT ZOOM HERE */ parameters.setPreviewSize(mPreviewSize.width, mPreviewSize.height); parameters.setRotation(90); mCamera.setParameters(parameters); mCamera.setDisplayOrientation(90); mCamera.setPreviewDisplay(mHolder); mCamera.startPreview(); } catch (Exception e) { Log.d(TAG, "Error starting camera preview: " + e.getMessage()); } }
/** sets the Orientation of the camera Preview o be the same as MoSyncApp */ private void setCameraDisplayOrientation() { // Use reflection to correct the preview on 2.2 and higher versions try { mCameraDisplayOrientation = mCamera.getClass().getMethod("setDisplayOrientation", Integer.TYPE); // Set the orientation of the picture on old Android phones Camera.Parameters parameters = mCamera.getParameters(); if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) { parameters.set("orientation", "portrait"); // default camera orientation on android is landscape // So we need to rotate the preview parameters.setRotation(90); mCamera.setDisplayOrientation(90); } else if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) { parameters.set("orientation", "landscape"); parameters.setRotation(0); mCamera.setDisplayOrientation(0); } mCamera.setParameters(parameters); } catch (NoSuchMethodException nsme) { SYSLOG("ANDROID Version is less than 2.2!!"); // Set the orientation of the picture on old Android phones Camera.Parameters parameters = mCamera.getParameters(); // an Ugly hack to make HTC wildfire work if (Build.MANUFACTURER.equals("HTC")) { parameters.set("orientation", "landscape"); parameters.setRotation(90); } // rest of the phones work fine with the standard settings else if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) { parameters.set("orientation", "portrait"); parameters.setRotation(90); } else if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) { parameters.set("orientation", "landscape"); parameters.setRotation(0); } mCamera.setParameters(parameters); } catch (RuntimeException e) { SYSLOG("Failed to set camera Parameters"); } }
public CustomeCamera( Activity activity, FrameLayout cameraPreviewLayout, Integer size, Integer quality) throws Exception { this.activity = activity; this.size = size; this.quality = quality; // Create an instance of Camera try { mCamera = getCameraInstance(); } catch (Exception e) { throw new Exception(e.getMessage()); } try { mCamera.setDisplayOrientation(90); } catch (Exception e) { Log.d(TAG, e.getMessage()); } Camera.CameraInfo info = new Camera.CameraInfo(); Camera.getCameraInfo(Camera.CameraInfo.CAMERA_FACING_BACK, info); int rotation = activity.getWindowManager().getDefaultDisplay().getRotation(); int degrees = 0; switch (rotation) { case Surface.ROTATION_0: degrees = 0; break; // Natural orientation case Surface.ROTATION_90: degrees = 90; break; // Landscape left case Surface.ROTATION_180: degrees = 180; break; // Upside down case Surface.ROTATION_270: degrees = 270; break; // Landscape right } int rotate = (info.orientation - degrees + 360) % 360; // STEP #2: Set the 'rotation' parameter Camera.Parameters params = mCamera.getParameters(); params.setRotation(rotate); List<String> focusModes = params.getSupportedFocusModes(); if (focusModes.contains(Camera.Parameters.FOCUS_MODE_AUTO)) { params.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO); } if (params.getFocusMode() == Camera.Parameters.FOCUS_MODE_AUTO) autoFocusEnabled = true; else autoFocusEnabled = false; // TODO for the test autoFocusEnabled = false; mCamera.setParameters(params); // Create our Preview view and set it as the content of our activity. mPreview = new CameraPreview(activity, mCamera); cameraPreviewLayout.addView(mPreview); }
@SuppressLint("NewApi") @Override public void doTakePicture(Activity previewActivity, int rotation) { Logger.T(TAG, "doTakePicture: rotation: " + rotation); openCamera(); Camera.Parameters params = getCamera().getParameters(); params.setRotation((90 + rotation) % 360); getCamera().setParameters(params); getCamera().takePicture(null, null, new TakePictureCallback(previewActivity)); closeCamera(); }
/** Handles camera opening */ private void openCamera(int which) { if (mCamera != null) { mCamera.stopPreview(); mCamera.release(); mCamera = null; } if (mCameraId >= 0) { Camera.getCameraInfo(mCameraId, mCameraInfo); if (which == FRONT) mCamera = Camera.open(Camera.CameraInfo.CAMERA_FACING_FRONT); else mCamera = Camera.open(Camera.CameraInfo.CAMERA_FACING_BACK); params = mCamera.getParameters(); params.setRotation(0); /** set focus mode */ List<String> FocusModes = params.getSupportedFocusModes(); if (FocusModes.contains(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE)) { params.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE); } mCamera.setParameters(params); try { if (mSurfaceTexture != null) { mCamera.setPreviewTexture(mSurfaceTexture); mCamera.startPreview(); } } catch (Exception ex) { } } if (mCamera == null || mSharedData == null) { return; } int orientation = mCameraInfo.orientation + rot_angle; Matrix.setRotateM(mSharedData.mOrientationM, 0, orientation, 0f, 0f, 1f); Camera.Size size = mCamera.getParameters().getPreviewSize(); if (orientation % 90 == 0) { int w = size.width; size.width = size.height; size.height = w; } mSharedData.mAspectRatioPreview[0] = (float) Math.min(size.width, size.height) / size.width; mSharedData.mAspectRatioPreview[1] = (float) Math.min(size.width, size.height) / size.height; }
public void adjustPreviewLayout(int type) { Camera camera = _cameras.get(type); if (null == camera) { return; } CameraInfoWrapper cameraInfo = _cameraInfos.get(type); int displayRotation; int rotation; int orientation = cameraInfo.info.orientation; if (cameraInfo.info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { rotation = (orientation + _actualDeviceOrientation * 90) % 360; displayRotation = (720 - orientation - _actualDeviceOrientation * 90) % 360; } else { rotation = (orientation - _actualDeviceOrientation * 90 + 360) % 360; displayRotation = rotation; } cameraInfo.rotation = rotation; // TODO: take in account the _orientation prop setAdjustedDeviceOrientation(rotation); camera.setDisplayOrientation(displayRotation); Camera.Parameters parameters = camera.getParameters(); parameters.setRotation(cameraInfo.rotation); // set preview size // defaults to highest resolution available Camera.Size optimalPreviewSize = getBestSize(parameters.getSupportedPreviewSizes(), Integer.MAX_VALUE, Integer.MAX_VALUE); int width = optimalPreviewSize.width; int height = optimalPreviewSize.height; parameters.setPreviewSize(width, height); try { camera.setParameters(parameters); } catch (Exception e) { e.printStackTrace(); } if (cameraInfo.rotation == 0 || cameraInfo.rotation == 180) { cameraInfo.previewWidth = width; cameraInfo.previewHeight = height; } else { cameraInfo.previewWidth = height; cameraInfo.previewHeight = width; } }
@Override public void onOrientationChanged(int orientation) { if (camera != null && orientation != ORIENTATION_UNKNOWN) { int newOutputOrientation = getCameraPictureRotation(orientation); if (newOutputOrientation != outputOrientation) { outputOrientation = newOutputOrientation; Camera.Parameters params = camera.getParameters(); params.setRotation(outputOrientation); camera.setParameters(params); lastPictureOrientation = outputOrientation; } } }
private void setCameraPictureOrientation(Camera.Parameters params) { CameraInfo info = new CameraInfo(); Camera.getCameraInfo(cameraId, info); if (getActivity().getRequestedOrientation() != ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) { outputOrientation = getCameraPictureRotation( getActivity().getWindowManager().getDefaultDisplay().getOrientation()); } else if (info.facing == CameraInfo.CAMERA_FACING_FRONT) { outputOrientation = (360 - displayOrientation) % 360; } else { outputOrientation = displayOrientation; } if (lastPictureOrientation != outputOrientation) { params.setRotation(outputOrientation); lastPictureOrientation = outputOrientation; } }
@Override public void surfaceCreated(SurfaceHolder holder) { try { camera.setPreviewDisplay(holder); Size size = choosePictureSize(camera.getParameters().getSupportedPictureSizes()); Camera.Parameters params = camera.getParameters(); params.setPictureSize(size.width, size.height); params.setJpegQuality(100); params.setJpegThumbnailQuality(100); params.setRotation(mRotation); // set rotation to save the picture // TODO: set the camera image size that is uniform and small. camera.setParameters(params); } catch (IOException e) { Log.e(LOG, e.toString()); } }
/** * Calculates the correct rotation for the given camera id and sets the rotation in the * parameters. It also sets the camera's display orientation and rotation. * * @param parameters the camera parameters for which to set the rotation * @param cameraId the camera id to set rotation based on */ private void setRotation(Camera camera, Camera.Parameters parameters, int cameraId) { WindowManager windowManager = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE); int degrees = 0; int rotation = windowManager.getDefaultDisplay().getRotation(); switch (rotation) { case Surface.ROTATION_0: degrees = 0; break; case Surface.ROTATION_90: degrees = 90; break; case Surface.ROTATION_180: degrees = 180; break; case Surface.ROTATION_270: degrees = 270; break; default: Log.e(TAG, mContext.getString(R.string.bad_rotation) + rotation); } CameraInfo cameraInfo = new CameraInfo(); Camera.getCameraInfo(cameraId, cameraInfo); int angle; int displayAngle; if (cameraInfo.facing == CameraInfo.CAMERA_FACING_FRONT) { angle = (cameraInfo.orientation + degrees) % 360; displayAngle = (360 - angle); // compensate for it being mirrored } else { // back-facing angle = (cameraInfo.orientation - degrees + 360) % 360; displayAngle = angle; } // This corresponds to the rotation constants in {@link Frame}. mRotation = angle / 90; camera.setDisplayOrientation(displayAngle); parameters.setRotation(angle); }
@Override public void surfaceCreated(SurfaceHolder arg0) { camera = Camera.open(); Camera.Parameters params = camera.getParameters(); camera.setDisplayOrientation(90); params.setRotation(90); params.set("orientation", "landscape"); params.set("rotation", 90); params.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO); Camera.Size previewSize = params.getPreviewSize(); List<Camera.Size> previewSizes = params.getSupportedPreviewSizes(); int i = 0; for (Camera.Size cs : previewSizes) { Log.d(MarvinActivity.TAG, "Camera - supports:(" + (i++) + ") " + cs.width + "x" + cs.height); } previewSize.width = 720; previewSize.height = 480; params.setSceneMode("portrait"); Log.d(MarvinActivity.TAG, "w: " + previewSize.width + " h: " + previewSize.height); List<Integer> formats = params.getSupportedPreviewFormats(); for (Integer format : formats) { Log.d(MarvinActivity.TAG, "Camera - supports preview format: " + format); } params.setPreviewSize(previewSize.width, previewSize.height); camera.setParameters(params); detectThread = new FaceDetectThread(context, user, params); detectThread.start(); camera.setPreviewCallback(detectThread); try { camera.setPreviewDisplay(cameraView.getHolder()); camera.startPreview(); Log.d(MarvinActivity.TAG, "preview started"); } catch (Exception e) { Log.e(MarvinActivity.TAG, e.getMessage(), e); } user.onEyeStarted(); }
void initCameraParameters() { Camera.Parameters parameters = mCamera.getParameters(); parameters.setPictureFormat(ImageFormat.JPEG); List<Camera.Size> previewSizes = parameters.getSupportedPreviewSizes(); // for(Size s:previewSizes){ // System.out.println("("+s.width+","+s.height+")"); // } rate = CameraUtil.getScreenRate(RegistCameraActivity.this); Size previewSize = CameraUtil.getPropPreviewSize(previewSizes, rate, 800); parameters.setPreviewSize(previewSize.width, previewSize.height); List<Camera.Size> pictureSizes = parameters.getSupportedPictureSizes(); Size pictureSize = CameraUtil.getPropPictureSize(pictureSizes, rate, 800); parameters.setPictureSize(pictureSize.width, pictureSize.height); if (CURRENT_CAMERA == CameraInfo.CAMERA_FACING_FRONT) { mCameraOrientation = 270; } else { mCameraOrientation = 90; } parameters.setRotation(mCameraOrientation); // parameters.setFocusMode(Parameters.FOCUS_MODE_CONTINUOUS_PICTURE); mCamera.setParameters(parameters); }
public void adjustCameraRotationToDeviceOrientation(int type, int deviceOrientation) { Camera camera = _cameras.get(type); if (null == camera) { return; } CameraInfoWrapper cameraInfo = _cameraInfos.get(type); int rotation; int orientation = cameraInfo.info.orientation; if (cameraInfo.info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { rotation = (orientation + deviceOrientation * 90) % 360; } else { rotation = (orientation - deviceOrientation * 90 + 360) % 360; } cameraInfo.rotation = rotation; Camera.Parameters parameters = camera.getParameters(); parameters.setRotation(cameraInfo.rotation); try { camera.setParameters(parameters); } catch (Exception e) { e.printStackTrace(); } }
/** * Set the legacy parameters using the {@link LegacyRequest legacy request}. * * <p>The legacy request's parameters are changed as a side effect of calling this method. * * @param legacyRequest a non-{@code null} legacy request */ public static void convertRequestMetadata(LegacyRequest legacyRequest) { CameraCharacteristics characteristics = legacyRequest.characteristics; CaptureRequest request = legacyRequest.captureRequest; Size previewSize = legacyRequest.previewSize; Camera.Parameters params = legacyRequest.parameters; Rect activeArray = characteristics.get(CameraCharacteristics.SENSOR_INFO_ACTIVE_ARRAY_SIZE); /* * scaler.cropRegion */ ParameterUtils.ZoomData zoomData; { zoomData = ParameterUtils.convertScalerCropRegion( activeArray, request.get(SCALER_CROP_REGION), previewSize, params); if (params.isZoomSupported()) { params.setZoom(zoomData.zoomIndex); } else if (VERBOSE) { Log.v(TAG, "convertRequestToMetadata - zoom is not supported"); } } /* * colorCorrection.* */ // colorCorrection.aberrationMode { int aberrationMode = ParamsUtils.getOrDefault( request, COLOR_CORRECTION_ABERRATION_MODE, /*defaultValue*/ COLOR_CORRECTION_ABERRATION_MODE_FAST); if (aberrationMode != COLOR_CORRECTION_ABERRATION_MODE_FAST) { Log.w( TAG, "convertRequestToMetadata - Ignoring unsupported " + "colorCorrection.aberrationMode = " + aberrationMode); } } /* * control.ae* */ // control.aeAntibandingMode { String legacyMode; Integer antiBandingMode = request.get(CONTROL_AE_ANTIBANDING_MODE); if (antiBandingMode != null) { legacyMode = convertAeAntiBandingModeToLegacy(antiBandingMode); } else { legacyMode = ListUtils.listSelectFirstFrom( params.getSupportedAntibanding(), new String[] { Parameters.ANTIBANDING_AUTO, Parameters.ANTIBANDING_OFF, Parameters.ANTIBANDING_50HZ, Parameters.ANTIBANDING_60HZ, }); } if (legacyMode != null) { params.setAntibanding(legacyMode); } } /* * control.aeRegions, afRegions */ { // aeRegions { // Use aeRegions if available, fall back to using awbRegions if present MeteringRectangle[] aeRegions = request.get(CONTROL_AE_REGIONS); if (request.get(CONTROL_AWB_REGIONS) != null) { Log.w( TAG, "convertRequestMetadata - control.awbRegions setting is not " + "supported, ignoring value"); } int maxNumMeteringAreas = params.getMaxNumMeteringAreas(); List<Camera.Area> meteringAreaList = convertMeteringRegionsToLegacy( activeArray, zoomData, aeRegions, maxNumMeteringAreas, /*regionName*/ "AE"); // WAR: for b/17252693, some devices can't handle params.setFocusAreas(null). if (maxNumMeteringAreas > 0) { params.setMeteringAreas(meteringAreaList); } } // afRegions { MeteringRectangle[] afRegions = request.get(CONTROL_AF_REGIONS); int maxNumFocusAreas = params.getMaxNumFocusAreas(); List<Camera.Area> focusAreaList = convertMeteringRegionsToLegacy( activeArray, zoomData, afRegions, maxNumFocusAreas, /*regionName*/ "AF"); // WAR: for b/17252693, some devices can't handle params.setFocusAreas(null). if (maxNumFocusAreas > 0) { params.setFocusAreas(focusAreaList); } } } // control.aeTargetFpsRange Range<Integer> aeFpsRange = request.get(CONTROL_AE_TARGET_FPS_RANGE); if (aeFpsRange != null) { int[] legacyFps = convertAeFpsRangeToLegacy(aeFpsRange); // TODO - Should we enforce that all HAL1 devices must include (30, 30) FPS range? boolean supported = false; for (int[] range : params.getSupportedPreviewFpsRange()) { if (legacyFps[0] == range[0] && legacyFps[1] == range[1]) { supported = true; break; } } if (supported) { params.setPreviewFpsRange( legacyFps[Camera.Parameters.PREVIEW_FPS_MIN_INDEX], legacyFps[Camera.Parameters.PREVIEW_FPS_MAX_INDEX]); } else { Log.w(TAG, "Unsupported FPS range set [" + legacyFps[0] + "," + legacyFps[1] + "]"); } } /* * control */ // control.aeExposureCompensation { Range<Integer> compensationRange = characteristics.get(CameraCharacteristics.CONTROL_AE_COMPENSATION_RANGE); int compensation = ParamsUtils.getOrDefault(request, CONTROL_AE_EXPOSURE_COMPENSATION, /*defaultValue*/ 0); if (!compensationRange.contains(compensation)) { Log.w( TAG, "convertRequestMetadata - control.aeExposureCompensation " + "is out of range, ignoring value"); compensation = 0; } params.setExposureCompensation(compensation); } // control.aeLock { Boolean aeLock = getIfSupported( request, CONTROL_AE_LOCK, /*defaultValue*/ false, params.isAutoExposureLockSupported(), /*allowedValue*/ false); if (aeLock != null) { params.setAutoExposureLock(aeLock); } if (VERBOSE) { Log.v(TAG, "convertRequestToMetadata - control.aeLock set to " + aeLock); } // TODO: Don't add control.aeLock to availableRequestKeys if it's not supported } // control.aeMode, flash.mode mapAeAndFlashMode(request, /*out*/ params); // control.afMode { int afMode = ParamsUtils.getOrDefault(request, CONTROL_AF_MODE, /*defaultValue*/ CONTROL_AF_MODE_OFF); String focusMode = LegacyMetadataMapper.convertAfModeToLegacy(afMode, params.getSupportedFocusModes()); if (focusMode != null) { params.setFocusMode(focusMode); } if (VERBOSE) { Log.v( TAG, "convertRequestToMetadata - control.afMode " + afMode + " mapped to " + focusMode); } } // control.awbMode { Integer awbMode = getIfSupported( request, CONTROL_AWB_MODE, /*defaultValue*/ CONTROL_AWB_MODE_AUTO, params.getSupportedWhiteBalance() != null, /*allowedValue*/ CONTROL_AWB_MODE_AUTO); String whiteBalanceMode = null; if (awbMode != null) { // null iff AWB is not supported by camera1 api whiteBalanceMode = convertAwbModeToLegacy(awbMode); params.setWhiteBalance(whiteBalanceMode); } if (VERBOSE) { Log.v( TAG, "convertRequestToMetadata - control.awbMode " + awbMode + " mapped to " + whiteBalanceMode); } } // control.awbLock { Boolean awbLock = getIfSupported( request, CONTROL_AWB_LOCK, /*defaultValue*/ false, params.isAutoWhiteBalanceLockSupported(), /*allowedValue*/ false); if (awbLock != null) { params.setAutoWhiteBalanceLock(awbLock); } // TODO: Don't add control.awbLock to availableRequestKeys if it's not supported } // control.captureIntent { int captureIntent = ParamsUtils.getOrDefault( request, CONTROL_CAPTURE_INTENT, /*defaultValue*/ CONTROL_CAPTURE_INTENT_PREVIEW); captureIntent = filterSupportedCaptureIntent(captureIntent); params.setRecordingHint( captureIntent == CONTROL_CAPTURE_INTENT_VIDEO_RECORD || captureIntent == CONTROL_CAPTURE_INTENT_VIDEO_SNAPSHOT); } // control.videoStabilizationMode { Integer stabMode = getIfSupported( request, CONTROL_VIDEO_STABILIZATION_MODE, /*defaultValue*/ CONTROL_VIDEO_STABILIZATION_MODE_OFF, params.isVideoStabilizationSupported(), /*allowedValue*/ CONTROL_VIDEO_STABILIZATION_MODE_OFF); if (stabMode != null) { params.setVideoStabilization(stabMode == CONTROL_VIDEO_STABILIZATION_MODE_ON); } } // lens.focusDistance { boolean infinityFocusSupported = ListUtils.listContains(params.getSupportedFocusModes(), Parameters.FOCUS_MODE_INFINITY); Float focusDistance = getIfSupported( request, LENS_FOCUS_DISTANCE, /*defaultValue*/ 0f, infinityFocusSupported, /*allowedValue*/ 0f); if (focusDistance == null || focusDistance != 0f) { Log.w( TAG, "convertRequestToMetadata - Ignoring android.lens.focusDistance " + infinityFocusSupported + ", only 0.0f is supported"); } } // control.sceneMode, control.mode { // TODO: Map FACE_PRIORITY scene mode to face detection. if (params.getSupportedSceneModes() != null) { int controlMode = ParamsUtils.getOrDefault(request, CONTROL_MODE, /*defaultValue*/ CONTROL_MODE_AUTO); String modeToSet; switch (controlMode) { case CONTROL_MODE_USE_SCENE_MODE: { int sceneMode = ParamsUtils.getOrDefault( request, CONTROL_SCENE_MODE, /*defaultValue*/ CONTROL_SCENE_MODE_DISABLED); String legacySceneMode = LegacyMetadataMapper.convertSceneModeToLegacy(sceneMode); if (legacySceneMode != null) { modeToSet = legacySceneMode; } else { modeToSet = Parameters.SCENE_MODE_AUTO; Log.w(TAG, "Skipping unknown requested scene mode: " + sceneMode); } break; } case CONTROL_MODE_AUTO: { modeToSet = Parameters.SCENE_MODE_AUTO; break; } default: { Log.w(TAG, "Control mode " + controlMode + " is unsupported, defaulting to AUTO"); modeToSet = Parameters.SCENE_MODE_AUTO; } } params.setSceneMode(modeToSet); } } // control.effectMode { if (params.getSupportedColorEffects() != null) { int effectMode = ParamsUtils.getOrDefault( request, CONTROL_EFFECT_MODE, /*defaultValue*/ CONTROL_EFFECT_MODE_OFF); String legacyEffectMode = LegacyMetadataMapper.convertEffectModeToLegacy(effectMode); if (legacyEffectMode != null) { params.setColorEffect(legacyEffectMode); } else { params.setColorEffect(Parameters.EFFECT_NONE); Log.w(TAG, "Skipping unknown requested effect mode: " + effectMode); } } } /* * sensor */ // sensor.testPattern { int testPatternMode = ParamsUtils.getOrDefault( request, SENSOR_TEST_PATTERN_MODE, /*defaultValue*/ SENSOR_TEST_PATTERN_MODE_OFF); if (testPatternMode != SENSOR_TEST_PATTERN_MODE_OFF) { Log.w( TAG, "convertRequestToMetadata - ignoring sensor.testPatternMode " + testPatternMode + "; only OFF is supported"); } } /* * jpeg.* */ // jpeg.gpsLocation { Location location = request.get(JPEG_GPS_LOCATION); if (location != null) { if (checkForCompleteGpsData(location)) { params.setGpsAltitude(location.getAltitude()); params.setGpsLatitude(location.getLatitude()); params.setGpsLongitude(location.getLongitude()); params.setGpsProcessingMethod(location.getProvider().toUpperCase()); params.setGpsTimestamp(location.getTime()); } else { Log.w(TAG, "Incomplete GPS parameters provided in location " + location); } } else { params.removeGpsData(); } } // jpeg.orientation { Integer orientation = request.get(CaptureRequest.JPEG_ORIENTATION); params.setRotation( ParamsUtils.getOrDefault( request, JPEG_ORIENTATION, (orientation == null) ? 0 : orientation)); } // jpeg.quality { params.setJpegQuality( 0xFF & ParamsUtils.getOrDefault(request, JPEG_QUALITY, DEFAULT_JPEG_QUALITY)); } // jpeg.thumbnailQuality { params.setJpegThumbnailQuality( 0xFF & ParamsUtils.getOrDefault(request, JPEG_THUMBNAIL_QUALITY, DEFAULT_JPEG_QUALITY)); } // jpeg.thumbnailSize { List<Camera.Size> sizes = params.getSupportedJpegThumbnailSizes(); if (sizes != null && sizes.size() > 0) { Size s = request.get(JPEG_THUMBNAIL_SIZE); boolean invalidSize = (s == null) ? false : !ParameterUtils.containsSize(sizes, s.getWidth(), s.getHeight()); if (invalidSize) { Log.w(TAG, "Invalid JPEG thumbnail size set " + s + ", skipping thumbnail..."); } if (s == null || invalidSize) { // (0,0) = "no thumbnail" in Camera API 1 params.setJpegThumbnailSize(/*width*/ 0, /*height*/ 0); } else { params.setJpegThumbnailSize(s.getWidth(), s.getHeight()); } } } /* * noiseReduction.* */ // noiseReduction.mode { int mode = ParamsUtils.getOrDefault( request, NOISE_REDUCTION_MODE, /*defaultValue*/ NOISE_REDUCTION_MODE_FAST); if (mode != NOISE_REDUCTION_MODE_FAST) { Log.w( TAG, "convertRequestToMetadata - Ignoring unsupported " + "noiseReduction.mode = " + mode); } } }