Search in sources :

Example 6 with Size

use of android.hardware.Camera.Size in project android_packages_apps_Camera by CyanogenMod.

the class CameraSettings method setCameraPictureSize.

public static boolean setCameraPictureSize(String candidate, List<Size> supported, Parameters parameters) {
    int index = candidate.indexOf('x');
    if (index == NOT_FOUND)
        return false;
    int width = Integer.parseInt(candidate.substring(0, index));
    int height = Integer.parseInt(candidate.substring(index + 1));
    for (Size size : supported) {
        if (size.width == width && size.height == height) {
            parameters.setPictureSize(width, height);
            return true;
        }
    }
    return false;
}
Also used : Size(android.hardware.Camera.Size)

Example 7 with Size

use of android.hardware.Camera.Size in project android_packages_apps_Camera by CyanogenMod.

the class Util method getOptimalPreviewSize.

public static Size getOptimalPreviewSize(Activity currentActivity, List<Size> sizes, double targetRatio) {
    // Use a very small tolerance because we want an exact match.
    final double ASPECT_TOLERANCE = 0.001;
    if (sizes == null)
        return null;
    Size optimalSize = null;
    double minDiff = Double.MAX_VALUE;
    // Because of bugs of overlay and layout, we sometimes will try to
    // layout the viewfinder in the portrait orientation and thus get the
    // wrong size of preview surface. When we change the preview size, the
    // new overlay will be created before the old one closed, which causes
    // an exception. For now, just get the screen size.
    Point point = getDefaultDisplaySize(currentActivity, new Point());
    int targetHeight = Math.min(point.x, point.y);
    // Try to find an size match aspect ratio and size
    for (Size size : sizes) {
        double ratio = (double) size.width / size.height;
        if (Math.abs(ratio - targetRatio) > ASPECT_TOLERANCE)
            continue;
        if (Math.abs(size.height - targetHeight) < minDiff) {
            optimalSize = size;
            minDiff = Math.abs(size.height - targetHeight);
        }
    }
    // Ignore the requirement.
    if (optimalSize == null) {
        Log.w(TAG, "No preview size match the aspect ratio");
        minDiff = Double.MAX_VALUE;
        for (Size size : sizes) {
            if (Math.abs(size.height - targetHeight) < minDiff) {
                optimalSize = size;
                minDiff = Math.abs(size.height - targetHeight);
            }
        }
    }
    return optimalSize;
}
Also used : Size(android.hardware.Camera.Size) Point(android.graphics.Point) Point(android.graphics.Point)

Example 8 with Size

use of android.hardware.Camera.Size in project android_packages_apps_Camera by CyanogenMod.

the class PhotoModule method capture.

@Override
public boolean capture() {
    // If we are already in the middle of taking a snapshot then ignore.
    if (mCameraDevice == null || mCameraState == SNAPSHOT_IN_PROGRESS || mCameraState == SWITCHING_CAMERA) {
        return false;
    }
    mCaptureStartTime = System.currentTimeMillis();
    mPostViewPictureCallbackTime = 0;
    mJpegImageData = null;
    final boolean animateBefore = (mSceneMode == Util.SCENE_MODE_HDR);
    if (animateBefore) {
        animateFlash();
    }
    // Save data
    mResetExposure = mParameters.getExposureCompensation();
    // Set rotation and gps data
    if (mSceneMode == Util.SCENE_MODE_HDR && Util.needSamsungHDRFormat()) {
        // Samsung actually specifies max range via exposure compensation
        mParameters.setExposureCompensation(mParameters.getMaxExposureCompensation());
    }
    mJpegRotation = Util.getJpegRotation(mCameraId, mOrientation);
    mParameters.setRotation(mJpegRotation);
    Location loc = mLocationManager.getCurrentLocation();
    Util.setGpsParameters(mParameters, loc);
    mCameraDevice.setParameters(mParameters);
    mCameraDevice.takePicture2(mShutterCallback, mRawPictureCallback, mPostViewPictureCallback, new JpegPictureCallback(loc), mCameraState, mFocusManager.getFocusState());
    if (Util.enableZSL() && (mSceneMode != Util.SCENE_MODE_HDR || !Util.needSamsungHDRFormat())) {
        mRestartPreview = false;
    }
    if (!animateBefore) {
        animateFlash();
    }
    Size size = mParameters.getPictureSize();
    mImageNamer.prepareUri(mContentResolver, mCaptureStartTime, size.width, size.height, mJpegRotation);
    mFaceDetectionStarted = false;
    setCameraState(SNAPSHOT_IN_PROGRESS);
    return true;
}
Also used : Size(android.hardware.Camera.Size) Location(android.location.Location)

Example 9 with Size

use of android.hardware.Camera.Size in project android_packages_apps_Camera by CyanogenMod.

the class PhotoModule method onShutterButtonClick.

@Override
public void onShutterButtonClick() {
    int nbBurstShots = Integer.valueOf(mPreferences.getString(CameraSettings.KEY_BURST_MODE, "1"));
    if (!mTimerMode) {
        if (mCaptureMode > 0) {
            mTimerMode = true;
            updateTimer(mCaptureMode);
            return;
        }
    } else if (mTimerMode) {
        mTimerMode = false;
        mHandler.removeMessages(CAMERA_TIMER);
        return;
    }
    if (Util.getDoSoftwareHDRShot() && !mHDRShotInProgress && !mHDRRendering) {
        Log.d(TAG, "Starting HDR shot - set min exposure");
        mParameters.setExposureCompensation(mParameters.getMinExposureCompensation());
        mCameraDevice.setParameters(mParameters);
        mHDRShotInProgress = true;
        sHDRShotsPaths.clear();
        // We hide controls while we are shooting
        mActivity.hideSwitcher();
        mActivity.setSwipingEnabled(false);
        // We queue the shot so exposure gets set
        mHandler.postDelayed(new Runnable() {

            public void run() {
                mHDRExposureSet = true;
                onShutterButtonClick();
            }
        }, 1000);
        return;
    } else if (Util.getDoSoftwareHDRShot() && mHDRShotInProgress && !mHDRExposureSet) {
        // We do min, 0, max exposure shots
        int value = mParameters.getExposureCompensation();
        int max = mParameters.getMaxExposureCompensation();
        // Non-ZSL devices hates setting parameters while shot is being taken. We
        // use SnapshotOnIdle as a callback when a shot is ready to be taken, and
        // we manually queue another shot.
        boolean queueShot = false;
        if (mParameters.getMinExposureCompensation() == value) {
            mParameters.setExposureCompensation(0);
            Log.d(TAG, "HDR - Set exposure to 0");
            mCameraDevice.setParameters(mParameters);
            queueShot = true;
            mHDRExposureSet = true;
        } else if (value == 0) {
            mParameters.setExposureCompensation(mParameters.getMaxExposureCompensation());
            Log.d(TAG, "HDR - Set exposure to max");
            mCameraDevice.setParameters(mParameters);
            queueShot = true;
            mHDRExposureSet = true;
        } else {
            // We did all exposures the sensor is capable of, we stop HDR shot
            mHDRShotInProgress = false;
            mHDRRendering = true;
            mSnapshotOnIdle = false;
            mBurstShotsDone = 0;
            Log.d(TAG, "Done shooting all exposures, computing HDR");
            // We release controls
            mActivity.showSwitcher();
            mActivity.setSwipingEnabled(true);
            // And we compute the final image
            final HdrSoftwareProcessor hdr = new HdrSoftwareProcessor(mActivity);
            mHdrProgressDialog = ProgressDialog.show(mActivity, mActivity.getString(R.string.pref_camera_scenemode_entry_hdr), mActivity.getString(R.string.wait), true);
            // Let a second for the shot to get recorded on SDcard, then go!
            mHandler.postDelayed(new Runnable() {

                public void run() {
                    new Thread() {

                        public void run() {
                            Uri[] strArray = new Uri[sHDRShotsPaths.size()];
                            sHDRShotsPaths.toArray(strArray);
                            try {
                                Size s = mParameters.getPictureSize();
                                mImageNamer.prepareUri(mContentResolver, mCaptureStartTime, s.width, s.height, mJpegRotation);
                                hdr.prepare(mActivity, strArray);
                                byte[] jpegData = hdr.computeHDR(mActivity);
                                Uri uri = mImageNamer.getUri();
                                mActivity.addSecureAlbumItemIfNeeded(false, uri);
                                String title = mImageNamer.getTitle();
                                mImageSaver.addImage(jpegData, uri, title, mLocationManager.getCurrentLocation(), s.width, s.height, 0);
                            } catch (Exception e) {
                                Log.e(TAG, "Could not make HDR final shot: " + e.getMessage());
                            }
                            // delete source images
                            for (int i = 0; i < sHDRShotsPaths.size() - 1; i++) {
                                Storage.getStorage().deleteImage(mContentResolver, sHDRShotsPaths.get(i));
                            }
                            // reset exposure
                            mParameters.setExposureCompensation(CameraSettings.readExposure(mPreferences));
                            mCameraDevice.setParameters(mParameters);
                            mHdrProgressDialog.dismiss();
                            mHDRRendering = false;
                        }
                    }.start();
                }
            }, 1000);
            return;
        }
        if (queueShot) {
            mSnapshotOnIdle = false;
            mHandler.postDelayed(new Runnable() {

                public void run() {
                    mHDRExposureSet = true;
                    onShutterButtonClick();
                }
            }, Util.getSoftwareHDRExposureSettleTime());
            return;
        }
    }
    if (mPaused || collapseCameraControls() || (mCameraState == SWITCHING_CAMERA) || (mCameraState == PREVIEW_STOPPED))
        return;
    // Do not take the picture if there is not enough storage.
    if (mActivity.getStorageSpace() <= Storage.LOW_STORAGE_THRESHOLD) {
        Log.i(TAG, "Not enough space or storage not ready. remaining=" + mActivity.getStorageSpace());
        return;
    }
    Log.v(TAG, "onShutterButtonClick: mCameraState=" + mCameraState);
    // focus callback arrives.
    if ((mFocusManager.isFocusingSnapOnFinish() || mCameraState == SNAPSHOT_IN_PROGRESS) && !mIsImageCaptureIntent) {
        mSnapshotOnIdle = true;
        return;
    }
    mFocusManager.doSnap();
    mBurstShotsDone++;
    if (mHDRShotInProgress) {
        mHDRExposureSet = false;
        mSnapshotOnIdle = true;
    }
    if (mBurstShotsDone >= nbBurstShots) {
        if (!mHDRShotInProgress) {
            mBurstShotsDone = 0;
            mBurstShotInProgress = false;
            mSnapshotOnIdle = false;
        }
    } else if (mSnapshotOnIdle == false) {
        // queue a new shot until we done all our shots
        mSnapshotOnIdle = true;
        mBurstShotInProgress = true;
    }
}
Also used : Size(android.hardware.Camera.Size) Uri(android.net.Uri) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException)

Example 10 with Size

use of android.hardware.Camera.Size in project android_packages_apps_Camera by CyanogenMod.

the class PanoramaModule method findBestPreviewSize.

private boolean findBestPreviewSize(List<Size> supportedSizes, boolean need4To3, boolean needSmaller) {
    int pixelsDiff = DEFAULT_CAPTURE_PIXELS;
    boolean hasFound = false;
    for (Size size : supportedSizes) {
        int h = size.height;
        int w = size.width;
        // we only want 4:3 format.
        int d = DEFAULT_CAPTURE_PIXELS - h * w;
        if (needSmaller && d < 0) {
            // no bigger preview than 960x720.
            continue;
        }
        if (need4To3 && (h * 4 != w * 3)) {
            continue;
        }
        d = Math.abs(d);
        if (d < pixelsDiff) {
            mPreviewWidth = w;
            mPreviewHeight = h;
            pixelsDiff = d;
            hasFound = true;
        }
    }
    return hasFound;
}
Also used : Size(android.hardware.Camera.Size)

Aggregations

Size (android.hardware.Camera.Size)30 Parameters (android.hardware.Camera.Parameters)4 Point (android.graphics.Point)3 Camera (android.hardware.Camera)3 Uri (android.net.Uri)2 IOException (java.io.IOException)2 TargetApi (android.annotation.TargetApi)1 SharedPreferences (android.content.SharedPreferences)1 Editor (android.content.SharedPreferences.Editor)1 SurfaceTexture (android.graphics.SurfaceTexture)1 Location (android.location.Location)1 Bundle (android.os.Bundle)1 Handler (android.os.Handler)1 Message (android.os.Message)1 Nullable (android.support.annotation.Nullable)1 BinaryBitmap (com.google.zxing.BinaryBitmap)1 PlanarYUVLuminanceSource (com.google.zxing.PlanarYUVLuminanceSource)1 ReaderException (com.google.zxing.ReaderException)1 Result (com.google.zxing.Result)1 HybridBinarizer (com.google.zxing.common.HybridBinarizer)1