Skip to content
This repository was archived by the owner on Dec 29, 2022. It is now read-only.
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: google/cameraview
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: necolt/cameraview
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Able to merge. These branches can be automatically merged.
  • 4 commits
  • 3 files changed
  • 2 contributors

Commits on Jun 30, 2017

  1. Use smaller resolution picture.

    Marius Jasinskas committed Jun 30, 2017

    Unverified

    This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
    Copy the full SHA
    e98745c View commit details
  2. Merge pull request #1 from emjei/master

    Use smaller resolution picture.
    sauliusgrigaitis authored Jun 30, 2017
    Copy the full SHA
    46a5ac3 View commit details

Commits on Jul 22, 2017

  1. Fix resolution for android < v21 API.

    Marius Jašinskas committed Jul 22, 2017
    Copy the full SHA
    251d648 View commit details

Commits on Jul 24, 2017

  1. Merge pull request #2 from emjei/smaller-resolution-older-android

    Fix resolution for android < v21 API.
    sauliusgrigaitis authored Jul 24, 2017
    Copy the full SHA
    b220331 View commit details
38 changes: 31 additions & 7 deletions library/src/main/api14/com/google/android/cameraview/Camera1.java
Original file line number Diff line number Diff line change
@@ -321,16 +321,40 @@ private AspectRatio chooseAspectRatio() {
}

void adjustCameraParameters() {
SortedSet<Size> sizes = mPreviewSizes.sizes(mAspectRatio);
if (sizes == null) { // Not supported
mAspectRatio = chooseAspectRatio();
int targetWidth = 640;
int targetHeight = 480;
AspectRatio targetAspectRatio = AspectRatio.of(targetWidth, targetHeight);
SortedSet<Size> sizes = mPictureSizes.sizes(targetAspectRatio);
Size bestSize = null;
for (Size size : sizes) {
if (size.getWidth() == targetWidth && size.getHeight() == targetHeight) {
bestSize = size;
break;
}

if (size.getWidth() >= targetWidth && size.getHeight() >= targetHeight) {
if (bestSize == null || size.getWidth() < bestSize.getWidth() || size.getHeight() < bestSize.getHeight()) {
bestSize = size;
}
}
}

Size size = bestSize;
Size pictureSize = bestSize;

if (size == null) {
sizes = mPreviewSizes.sizes(mAspectRatio);
if (sizes == null) { // Not supported
mAspectRatio = chooseAspectRatio();
sizes = mPreviewSizes.sizes(mAspectRatio);
}
size = chooseOptimalSize(sizes);

// Always re-apply camera parameters
// Largest picture size in this ratio
pictureSize = mPictureSizes.sizes(mAspectRatio).last();
}
Size size = chooseOptimalSize(sizes);

// Always re-apply camera parameters
// Largest picture size in this ratio
final Size pictureSize = mPictureSizes.sizes(mAspectRatio).last();
if (mShowingPreview) {
mCamera.stopPreview();
}
Original file line number Diff line number Diff line change
@@ -438,8 +438,29 @@ private void collectCameraInfo() {
}

protected void collectPictureSizes(SizeMap sizes, StreamConfigurationMap map) {
int targetWidth = 640;
int targetHeight = 480;
AspectRatio targetAspectRatio = AspectRatio.of(targetWidth, targetHeight);
android.util.Size bestSize = null;

for (android.util.Size size : map.getOutputSizes(ImageFormat.JPEG)) {
mPictureSizes.add(new Size(size.getWidth(), size.getHeight()));
if (size.getWidth() == targetWidth && size.getHeight() == targetHeight) {
bestSize = size;
break;
}

boolean aspectRatioCorrect = targetAspectRatio.matches(new Size(size.getWidth(), size.getHeight()));
if (!aspectRatioCorrect) continue;

if (size.getWidth() >= targetWidth && size.getHeight() >= targetHeight) {
if (bestSize == null || size.getWidth() < bestSize.getWidth() || size.getHeight() < bestSize.getHeight()) {
bestSize = size;
}
}
}

if (bestSize != null) {
mPictureSizes.add(new Size(bestSize.getWidth(), bestSize.getHeight()));
}
}

Original file line number Diff line number Diff line change
@@ -31,16 +31,7 @@ class Camera2Api23 extends Camera2 {

@Override
protected void collectPictureSizes(SizeMap sizes, StreamConfigurationMap map) {
// Try to get hi-res output sizes
android.util.Size[] outputSizes = map.getHighResolutionOutputSizes(ImageFormat.JPEG);
if (outputSizes != null) {
for (android.util.Size size : map.getHighResolutionOutputSizes(ImageFormat.JPEG)) {
sizes.add(new Size(size.getWidth(), size.getHeight()));
}
}
if (sizes.isEmpty()) {
super.collectPictureSizes(sizes, map);
}
super.collectPictureSizes(sizes, map);
}

}