优化RAW格式拍照

TempBranch
Matthew 9 months ago
parent 7a9824b4a6
commit 23c3a482ee

@ -727,6 +727,8 @@ Java_com_xypower_mpapp_MicroPhotoService_captureFinished(
if (res < 0 || info.format != ANDROID_BITMAP_FORMAT_RGBA_8888)
{
}
bool hardwareBitmap = (info.flags & ANDROID_BITMAP_FLAGS_IS_HARDWARE) != 0;
void* pixels = NULL;
res = AndroidBitmap_lockPixels(env, bitmap, &pixels);
if (res < 0)

@ -1439,13 +1439,13 @@ void CPhoneDevice::CloseCamera2(CPhoneDevice::CPhoneCamera* camera, unsigned int
delete camera;
}
XYLOG(XYLOG_SEVERITY_DEBUG, "TP: Will Turn Off Power=%u", photoId);
XYLOG(XYLOG_SEVERITY_DEBUG, "TP: Will Turn Off Power PHOTOID=%u", photoId);
if (turnOffOtg)
{
TurnOffOtg(NULL);
}
TurnOffCameraPower(NULL);
XYLOG(XYLOG_SEVERITY_DEBUG, "TP: End Turn Off Power=%u", photoId);
XYLOG(XYLOG_SEVERITY_DEBUG, "TP: End Turn Off Power PHOTOID=%u", photoId);
XYLOG(XYLOG_SEVERITY_DEBUG, "TP: CloseCamera PHOTOID=%u", photoId);
@ -1789,6 +1789,7 @@ bool CPhoneDevice::OnImageReady(cv::Mat& mat)
bool CPhoneDevice::OnCaptureReady(bool photoOrVideo, bool result, cv::Mat& mat, unsigned int photoId)
{
XYLOG(XYLOG_SEVERITY_INFO, "RAW Capture finished: %u RES=%d", photoId, (result ? 1 : 0));
if (photoOrVideo)
{
if (result)
@ -1799,8 +1800,21 @@ bool CPhoneDevice::OnCaptureReady(bool photoOrVideo, bool result, cv::Mat& mat,
{
std::vector<IDevice::RECOG_OBJECT> objs;
TakePhotoCb(result, mPhotoInfo, "", time(NULL), objs);
CPhoneCamera* pCamera = mCamera;
mCamera = NULL;
bool turnOffOtg = (mPhotoInfo.usbCamera != 0);
std::thread closeThread(&CPhoneDevice::CloseCamera2, this, pCamera, mPhotoInfo.photoId, turnOffOtg);
m_threadClose.swap(closeThread);
if (closeThread.joinable())
{
closeThread.detach();
}
}
}
return true;
}
bool CPhoneDevice::OnVideoReady(bool photoOrVideo, bool result, const char* path, unsigned int photoId)

@ -14,6 +14,7 @@ import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.ImageDecoder;
import android.location.Location;
import android.location.LocationListener;
@ -405,14 +406,14 @@ public class MicroPhotoService extends Service {
@Override
public void run() {
Bitmap bm = null;
ImageDecoder.Source src = ImageDecoder.createSource(new File(path));
// ImageDecoder.Source src = ImageDecoder.createSource(new File(path));
try {
bm = ImageDecoder.decodeBitmap(src);
// bm = ImageDecoder.decodeBitmap(src);
bm = BitmapFactory.decodeFile(path);
} catch (Exception ex) {
}
mService.captureFinished(mService.mNativeHandle, photoOrVideo, result && bm != null, bm, videoId);
}
});

@ -551,12 +551,7 @@ public class RawActivity extends AppCompatActivity {
/**
* A {@link Handler} for showing {@link Toast}s on the UI thread.
*/
private final Handler mMessageHandler = new Handler(Looper.getMainLooper()) {
@Override
public void handleMessage(Message msg) {
}
};
private final Handler mMessageHandler = new Handler(Looper.getMainLooper());
@Override
@ -584,19 +579,15 @@ public class RawActivity extends AppCompatActivity {
mCameraId = Integer.toString(intent.getIntExtra("cameraId", 0));
mOrientation = intent.getIntExtra("orientation", -1);
int width = intent.getIntExtra("width", 0);
int height = intent.getIntExtra("height", 0);
int width = intent.getIntExtra("width", MAX_PREVIEW_WIDTH);
int height = intent.getIntExtra("height", MAX_PREVIEW_HEIGHT);
mImageSize = new Size(width, height);
mPhotoId = intent.getLongExtra("videoId", 0);
mMessageHandler.postDelayed(new Runnable() {
@Override
public void run() {
takePicture();
}
}, 400);
mTextureView.setAspectRatio(width, height);
}
@ -618,6 +609,13 @@ public class RawActivity extends AppCompatActivity {
if (mOrientationListener != null && mOrientationListener.canDetectOrientation()) {
mOrientationListener.enable();
}
mMessageHandler.postDelayed(new Runnable() {
@Override
public void run() {
takePicture();
}
}, 400);
}
@Override
@ -641,62 +639,55 @@ public class RawActivity extends AppCompatActivity {
return false;
}
try {
String[] cameraIds = manager.getCameraIdList();
// Find a CameraDevice that supports RAW captures, and configure state.
for (String cameraId : cameraIds) {
CameraCharacteristics characteristics
= manager.getCameraCharacteristics(cameraId);
int[] capabilities = characteristics.get(
CameraCharacteristics.REQUEST_AVAILABLE_CAPABILITIES);
// We only use a camera that supports RAW in this sample.
if (!contains(capabilities,
CameraCharacteristics.REQUEST_AVAILABLE_CAPABILITIES_RAW)) {
continue;
}
CameraCharacteristics characteristics
= manager.getCameraCharacteristics(mCameraId);
int[] capabilities = characteristics.get(
CameraCharacteristics.REQUEST_AVAILABLE_CAPABILITIES);
// We only use a camera that supports RAW in this sample.
if (!contains(capabilities,
CameraCharacteristics.REQUEST_AVAILABLE_CAPABILITIES_RAW)) {
return false;
}
Integer facing = characteristics.get(CameraCharacteristics.LENS_FACING);
if (facing != CameraMetadata.LENS_FACING_FRONT) {
continue;
}
StreamConfigurationMap map = characteristics.get(
CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
StreamConfigurationMap map = characteristics.get(
CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
// For still image captures, we use the largest available size.
Size largestJpeg = Collections.max(
Arrays.asList(map.getOutputSizes(ImageFormat.JPEG)),
new CompareSizesByArea());
Size largestRaw = Collections.max(
Arrays.asList(map.getOutputSizes(ImageFormat.RAW_SENSOR)),
new CompareSizesByArea());
synchronized (mCameraStateLock) {
// Set up ImageReaders for JPEG and RAW outputs. Place these in a reference
// counted wrapper to ensure they are only closed when all background tasks
// using them are finished.
if (mJpegImageReader == null || mJpegImageReader.getAndRetain() == null) {
mJpegImageReader = new RefCountedAutoCloseable<>(
ImageReader.newInstance(largestJpeg.getWidth(),
largestJpeg.getHeight(), ImageFormat.JPEG, /*maxImages*/5));
}
mJpegImageReader.get().setOnImageAvailableListener(
mOnJpegImageAvailableListener, mBackgroundHandler);
// For still image captures, we use the largest available size.
Size[] outputSizes = map.getOutputSizes(ImageFormat.JPEG);
Size largestJpeg = Collections.max(
Arrays.asList(map.getOutputSizes(ImageFormat.JPEG)),
new CompareSizesByArea());
if (mRawImageReader == null || mRawImageReader.getAndRetain() == null) {
mRawImageReader = new RefCountedAutoCloseable<>(
ImageReader.newInstance(largestRaw.getWidth(),
largestRaw.getHeight(), ImageFormat.RAW_SENSOR, /*maxImages*/ 5));
}
mRawImageReader.get().setOnImageAvailableListener(
mOnRawImageAvailableListener, mBackgroundHandler);
outputSizes = map.getOutputSizes(ImageFormat.RAW_SENSOR);
Size largestRaw = Collections.max(
Arrays.asList(map.getOutputSizes(ImageFormat.RAW_SENSOR)),
new CompareSizesByArea());
mCharacteristics = characteristics;
mCameraId = cameraId;
synchronized (mCameraStateLock) {
// Set up ImageReaders for JPEG and RAW outputs. Place these in a reference
// counted wrapper to ensure they are only closed when all background tasks
// using them are finished.
if (mJpegImageReader == null || mJpegImageReader.getAndRetain() == null) {
mJpegImageReader = new RefCountedAutoCloseable<>(
ImageReader.newInstance(mImageSize.getWidth(),
mImageSize.getHeight(), ImageFormat.JPEG, /*maxImages*/5));
}
return true;
mJpegImageReader.get().setOnImageAvailableListener(
mOnJpegImageAvailableListener, mBackgroundHandler);
if (mRawImageReader == null || mRawImageReader.getAndRetain() == null) {
mRawImageReader = new RefCountedAutoCloseable<>(
ImageReader.newInstance(mImageSize.getWidth(),
mImageSize.getHeight(), ImageFormat.RAW_SENSOR, /*maxImages*/ 5));
}
mRawImageReader.get().setOnImageAvailableListener(
mOnRawImageAvailableListener, mBackgroundHandler);
mCharacteristics = characteristics;
}
return true;
} catch (CameraAccessException e) {
e.printStackTrace();
}
@ -854,6 +845,7 @@ public class RawActivity extends AppCompatActivity {
@Override
public void onConfigureFailed(CameraCaptureSession cameraCaptureSession) {
// showToast("Failed to configure camera.");
int aa = 0;
}
}, mBackgroundHandler
);
@ -941,6 +933,9 @@ public class RawActivity extends AppCompatActivity {
// Find the rotation of the device relative to the native device orientation.
int deviceRotation = getWindowManager().getDefaultDisplay().getRotation();
if (mOrientation > 0) {
deviceRotation = mOrientation - 1;
}
Point displaySize = new Point();
getWindowManager().getDefaultDisplay().getSize(displaySize);

Loading…
Cancel
Save