Skip to content

Commit

Permalink
优化局部测光,适配横竖屏
Browse files Browse the repository at this point in the history
  • Loading branch information
ailiwean committed Sep 27, 2020
1 parent ef4d960 commit f3b4105
Show file tree
Hide file tree
Showing 31 changed files with 385 additions and 151 deletions.
61 changes: 61 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/smartfox_info.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ android {
}

debug {
minifyEnabled true
shrinkResources true
minifyEnabled false
shrinkResources false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@

import android.annotation.SuppressLint;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.SurfaceTexture;
import android.hardware.Camera;
import android.util.Log;
import android.view.SurfaceHolder;

import androidx.collection.SparseArrayCompat;

import com.ailiwean.core.Config;
import com.ailiwean.core.helper.CameraHelper;
import com.ailiwean.core.helper.LightHelper;
import com.ailiwean.core.helper.ScanHelper;

import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Set;
Expand Down Expand Up @@ -290,10 +290,13 @@ void setDisplayOrientation(int displayOrientation) {
return;
}
mDisplayOrientation = displayOrientation;
if (isCameraOpened()) {
mCameraParameters.setRotation(calcCameraRotation(displayOrientation));
mCamera.setParameters(mCameraParameters);
mCamera.setDisplayOrientation(calcDisplayOrientation(displayOrientation));
try {
if (isCameraOpened()) {
mCameraParameters.setRotation(calcCameraRotation(displayOrientation));
mCamera.setParameters(mCameraParameters);
mCamera.setDisplayOrientation(calcDisplayOrientation(displayOrientation));
}
} catch (Exception ignored) {
}
}

Expand Down Expand Up @@ -584,12 +587,18 @@ protected void rectMeteringWithFocus() {
if (Config.scanRect == null || Config.scanRect.getRect() == null)
return;

int left = (int) (2000 * Config.scanRect.getRect().top) - 1000;
int top = (int) (2000 * (1 - Config.scanRect.getRect().right)) - 1000;
int right = (int) (2000 * Config.scanRect.getRect().bottom) - 1000;
int bottom = (int) (2000 * (1 - Config.scanRect.getRect().left)) - 1000;
RectF cropRect = ScanHelper.copyRect(Config.scanRect.getRect());
cropRect.left += (cropRect.right - cropRect.left) / 4;
cropRect.right -= (cropRect.right - cropRect.left) / 4;
cropRect.top += (cropRect.bottom - cropRect.top) / 4;
cropRect.bottom -= (cropRect.bottom - cropRect.top) / 4;

int left = (int) (2000 * cropRect.top) - 1000;
int top = (int) (2000 * (1 - cropRect.right)) - 1000;
int right = (int) (2000 * cropRect.bottom) - 1000;
int bottom = (int) (2000 * (1 - cropRect.left)) - 1000;

Rect realRect = new Rect(left , top, right, bottom);
Rect realRect = new Rect(left, top, right, bottom);
List<Camera.Area> areas = Collections.singletonList(new Camera.Area(realRect, 1000));
mCameraParameters.setFocusAreas(areas);
mCameraParameters.setMeteringAreas(areas);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,21 @@

import android.annotation.TargetApi;
import android.content.Context;
import android.content.res.Configuration;
import android.graphics.Matrix;
import android.graphics.SurfaceTexture;
import android.util.Log;
import android.view.Surface;
import android.view.TextureView;
import android.view.View;
import android.view.ViewGroup;

import com.ailiwean.core.Config;
import com.ailiwean.core.Utils;

@TargetApi(14)
class TextureViewPreview extends PreviewImpl {

private final TextureView mTextureView;

private int mDisplayOrientation;

TextureViewPreview(Context context, ViewGroup parent) {
Expand Down Expand Up @@ -65,6 +65,7 @@ public void onSurfaceTextureUpdated(SurfaceTexture surface) {

}
});

}

@TargetApi(15)
Expand All @@ -74,36 +75,6 @@ void setBufferSize(int widthData, int heightData) {
Config.scanRect.setDataY(heightData);
if (getSurfaceTexture() != null)
getSurfaceTexture().setDefaultBufferSize(widthData, heightData);
else {
TextureView.SurfaceTextureListener listener = mTextureView.getSurfaceTextureListener();
mTextureView.setSurfaceTextureListener(new TextureView.SurfaceTextureListener() {
@Override
public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
if (listener != null)
listener.onSurfaceTextureAvailable(surface, width, height);
getSurfaceTexture().setDefaultBufferSize(widthData, heightData);
}

@Override
public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) {
if (listener != null)
listener.onSurfaceTextureSizeChanged(surface, width, height);
}

@Override
public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
if (listener != null)
return listener.onSurfaceTextureDestroyed(surface);
return false;
}

@Override
public void onSurfaceTextureUpdated(SurfaceTexture surface) {
if (listener != null)
listener.onSurfaceTextureUpdated(surface);
}
});
}
}

@Override
Expand Down Expand Up @@ -138,11 +109,16 @@ boolean isReady() {
}

/**
* Configures the transform matrix for TextureView based on {@link #mDisplayOrientation} and
* Configures the transform matrix for TextureView based on {@link Config} and
* the surface size.
*/
void configureTransform() {
Matrix matrix = new Matrix();

if (Utils.getContext().getResources().getConfiguration().orientation ==
Configuration.ORIENTATION_LANDSCAPE && mDisplayOrientation == 0)
mDisplayOrientation = Config.displayOrientation;

if (mDisplayOrientation % 180 == 90) {
final int width = getWidth();
final int height = getHeight();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import android.content.Context;
import android.graphics.ImageFormat;
import android.graphics.Rect;
import android.hardware.camera2.CameraAccessException;
import android.graphics.RectF;
import android.hardware.camera2.CameraCaptureSession;
import android.hardware.camera2.CameraCharacteristics;
import android.hardware.camera2.CameraDevice;
Expand All @@ -32,18 +32,17 @@
import android.media.Image;
import android.media.ImageReader;
import android.os.Build;
import android.util.Log;
import android.util.SparseIntArray;
import android.view.Surface;

import androidx.annotation.NonNull;

import com.ailiwean.core.Config;
import com.ailiwean.core.helper.CameraHelper;
import com.ailiwean.core.helper.ScanHelper;

import java.nio.ByteBuffer;
import java.util.Arrays;
import java.util.Collections;
import java.util.Set;
import java.util.SortedSet;

Expand Down Expand Up @@ -909,17 +908,23 @@ protected void rectMeteringWithFocus() {
if (Config.scanRect == null || Config.scanRect.getRect() == null)
return;

Rect rect = mCameraCharacteristics.get(CameraCharacteristics.SENSOR_INFO_ACTIVE_ARRAY_SIZE);
if (rect == null)
rect = new Rect(0, 0, 1, 1);
Rect dateRect = mCameraCharacteristics.get(CameraCharacteristics.SENSOR_INFO_ACTIVE_ARRAY_SIZE);
if (dateRect == null)
dateRect = new Rect(0, 0, 1, 1);

int dataWidth = rect.width() - 1;
int dataHeight = rect.height() - 1;
int dataWidth = dateRect.width() - 1;
int dataHeight = dateRect.height() - 1;

int left = (int) (Config.scanRect.getRect().top * dataWidth);
int top = (int) ((1f - Config.scanRect.getRect().right) * dataHeight);
int right = (int) (Config.scanRect.getRect().bottom * dataWidth);
int bottom = (int) ((1f - (Config.scanRect.getRect().left)) * dataHeight);
RectF cropRect = ScanHelper.copyRect(Config.scanRect.getRect());
cropRect.left += (cropRect.right - cropRect.left) / 4;
cropRect.right -= (cropRect.right - cropRect.left) / 4;
cropRect.top += (cropRect.bottom - cropRect.top) / 4;
cropRect.bottom -= (cropRect.bottom - cropRect.top) / 4;

int left = (int) (cropRect.top * dataWidth);
int top = (int) ((1f - cropRect.right) * dataHeight);
int right = (int) (cropRect.bottom * dataWidth);
int bottom = (int) ((1f - cropRect.left) * dataHeight);
Rect realRect = new Rect(left, top, right, bottom);
MeteringRectangle[] meteringRectangles = new MeteringRectangle[]{new MeteringRectangle(realRect, 1000)};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@
package com.google.android.cameraview;

import android.os.Handler;
import android.util.Log;
import android.view.Surface;
import android.view.SurfaceHolder;
import android.view.View;
import android.view.ViewGroup;


/**
Expand Down
17 changes: 17 additions & 0 deletions module_camera/src/main/java/com/ailiwean/core/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,29 @@ public class Config {
//扫码区域
public static ScanRect scanRect;


public static int displayOrientation;

//灰度算法类路径
public static final String GARY_SCALE_PATH = "com.ailiwean.module_grayscale.GrayScaleDispatch";

public static void initConfig() {
currentZoom = 0f;
displayOrientation = 0;
scanRect = new ScanRect();
}

//屏幕方向
public static boolean is0() {
return displayOrientation == 0;
}

public static boolean is90() {
return displayOrientation == 90;
}

public static boolean is270() {
return displayOrientation == 270;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ private WorkThreadServer() {
new ThreadPoolExecutor.DiscardOldestPolicy());
else executor = new RespectScalePool(
corePoolSize, corePoolSize, keepAliveTime, TimeUnit.SECONDS,
RespectScaleQueue.create(maximumPoolSize / 3 * 2, maximumPoolSize / 3),
RespectScaleQueue.create(maximumPoolSize / 2, maximumPoolSize / 2),
new RespectScalePool.RespectScalePolicy());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ class AbleManager private constructor(handler: Handler) : PixsValuesAble(handler
fun loadAbility() {
ableList.clear()
ableList.add(XQRScanCrudeAble(handlerHolder.get()))
ableList.add(XQRScanFineAble(handlerHolder.get()))
ableList.add(XQRScanZoomAble(handlerHolder.get()))
ableList.add(XQRScanAbleRotate(handlerHolder.get()))
ableList.add(LighSolveAble(handlerHolder.get()))
// ableList.add(XQRScanFineAble(handlerHolder.get()))
// ableList.add(XQRScanAble(handler))
// ableList.add(GrayscaleStrengAble(handler))
// ableList.add(XQRScanFastAble(handler))
Expand Down Expand Up @@ -96,7 +96,7 @@ class AbleManager private constructor(handler: Handler) : PixsValuesAble(handler

override fun release() {
ableList.forEach {
it.release()
it.release()
}
ableList.clear()
server.quit()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package com.ailiwean.core.able;

import android.os.Handler;
import android.os.Message;
import android.util.Log;

import com.ailiwean.core.Config;
import com.ailiwean.core.helper.LightHelper;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import android.os.Handler;
import android.os.Message;
import android.util.Log;

import com.ailiwean.core.zxing.CustomMultiFormatReader;
import com.ailiwean.core.zxing.core.Binarizer;
Expand Down
Loading

0 comments on commit f3b4105

Please sign in to comment.