优化RAW格式拍摄的实现

TempBranch
Matthew 9 months ago
parent b073ab05b3
commit 9116ca8bc9

@ -722,6 +722,12 @@ Java_com_xypower_mpapp_MicroPhotoService_captureFinished(
IDevice* dev = pTerminal->GetDevice();
if (dev != NULL)
{
if (result == JNI_FALSE || bitmap == NULL)
{
cv::Mat mat;
((CPhoneDevice *)dev)->OnCaptureReady(photoOrVideo != JNI_FALSE, result != JNI_FALSE, mat, (unsigned long)photoId);
return;
}
AndroidBitmapInfo info = { 0 };
int res = AndroidBitmap_getInfo(env, bitmap, &info);
if (res < 0 || info.format != ANDROID_BITMAP_FORMAT_RGBA_8888)

@ -418,7 +418,7 @@ public class MicroPhotoService extends Service {
@Override
public void onHeaderDecoded(@NonNull ImageDecoder decoder, @NonNull ImageDecoder.ImageInfo info, @NonNull ImageDecoder.Source source) {
decoder.setAllocator(ImageDecoder.ALLOCATOR_SOFTWARE);
decoder.setTargetSize(info.getSize().getWidth(), info.getSize().getHeight());
// decoder.setTargetSize(info.getSize().getWidth(), info.getSize().getHeight());
}
};

@ -52,6 +52,10 @@ public class AutoFitTextureView extends TextureView {
if (width < 0 || height < 0) {
throw new IllegalArgumentException("Size cannot be negative.");
}
if (mRatioWidth == width && mRatioHeight == height) {
return;
}
mRatioWidth = width;
mRatioHeight = height;
requestLayout();

@ -12,6 +12,7 @@ import android.os.Build;
import android.os.Looper;
import android.os.Message;
import android.os.SystemClock;
import android.text.TextUtils;
import android.view.OrientationEventListener;
import java.util.TreeMap;
@ -155,6 +156,18 @@ public class RawActivity extends AppCompatActivity {
*/
private static final int STATE_WAITING_FOR_3A_CONVERGENCE = 3;
private Runnable mTakePictureRunner = new Runnable() {
@Override
public void run() {
mMessageHandler.postDelayed(new Runnable() {
@Override
public void run() {
takePicture();
}
}, 400);
}
};
/**
* An {@link OrientationEventListener} used to determine when device rotation has occurred.
* This is mainly necessary for when the device is rotated by 180 degrees, in which case
@ -181,12 +194,8 @@ public class RawActivity extends AppCompatActivity {
if (!mTaken) {
mTaken = true;
mMessageHandler.postDelayed(new Runnable() {
@Override
public void run() {
takePicture();
}
}, 400);
mMessageHandler.removeCallbacks(mTakePictureRunner);
mMessageHandler.postDelayed(mTakePictureRunner, 400);
}
}
@ -199,12 +208,8 @@ public class RawActivity extends AppCompatActivity {
if (!mTaken) {
mTaken = true;
mMessageHandler.postDelayed(new Runnable() {
@Override
public void run() {
takePicture();
}
}, 400);
mMessageHandler.removeCallbacks(mTakePictureRunner);
mMessageHandler.postDelayed(mTakePictureRunner, 400);
}
}
@ -357,6 +362,9 @@ public class RawActivity extends AppCompatActivity {
public void onOpened(CameraDevice cameraDevice) {
// This method is called when the camera is opened. We start camera preview here if
// the TextureView displaying this has been set up.
MicroPhotoService.infoLog("RawActivity onOpened PHOTOID=" + Long.toString(mPhotoId));
synchronized (mCameraStateLock) {
mState = STATE_OPENED;
mCameraOpenCloseLock.release();
@ -381,15 +389,28 @@ public class RawActivity extends AppCompatActivity {
@Override
public void onError(CameraDevice cameraDevice, int error) {
Log.e(TAG, "Received camera device error: " + error);
MicroPhotoService.infoLog("RawActivity Received camera device error: " + Integer.toString(error) + " PHOTOID=" + Long.toString(mPhotoId));
synchronized (mCameraStateLock) {
mState = STATE_CLOSED;
mCameraOpenCloseLock.release();
cameraDevice.close();
mCameraDevice = null;
}
broadcastPhotoFile(false, "");
finish();
runOnUiThread(new Runnable() {
@Override
public void run() {
broadcastPhotoFile(false, "");
mMessageHandler.postDelayed(new Runnable() {
@Override
public void run() {
finish();
}
}, 100);
}
});
}
};
@ -582,6 +603,17 @@ public class RawActivity extends AppCompatActivity {
*/
private final Handler mMessageHandler = new Handler(Looper.getMainLooper());
private int getDeviceRotation() {
int deviceRotation = getWindowManager().getDefaultDisplay().getRotation();
/*
if (mOrientation > 0) {
deviceRotation = mOrientation / 90;
} else {
deviceRotation = 0;
}
*/
return deviceRotation;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -723,11 +755,13 @@ public class RawActivity extends AppCompatActivity {
Size largestJpeg = Collections.max(
Arrays.asList(map.getOutputSizes(ImageFormat.JPEG)),
new CompareSizesByArea());
largestJpeg = mImageSize;
outputSizes = map.getOutputSizes(ImageFormat.RAW_SENSOR);
Size largestRaw = Collections.max(
Arrays.asList(map.getOutputSizes(ImageFormat.RAW_SENSOR)),
new CompareSizesByArea());
largestRaw = mImageSize;
synchronized (mCameraStateLock) {
// Set up ImageReaders for JPEG and RAW outputs. Place these in a reference
@ -735,16 +769,16 @@ public class RawActivity extends AppCompatActivity {
// using them are finished.
if (mJpegImageReader == null || mJpegImageReader.getAndRetain() == null) {
mJpegImageReader = new RefCountedAutoCloseable<>(
ImageReader.newInstance(mImageSize.getWidth(),
mImageSize.getHeight(), ImageFormat.JPEG, /*maxImages*/5));
ImageReader.newInstance(largestJpeg.getWidth(),
largestJpeg.getHeight(), ImageFormat.JPEG, /*maxImages*/5));
}
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));
ImageReader.newInstance(largestRaw.getWidth(),
largestRaw.getHeight(), ImageFormat.RAW_SENSOR, /*maxImages*/ 5));
}
mRawImageReader.get().setOnImageAvailableListener(
mOnRawImageAvailableListener, mBackgroundHandler);
@ -997,10 +1031,7 @@ public class RawActivity extends AppCompatActivity {
new CompareSizesByArea());
// Find the rotation of the device relative to the native device orientation.
int deviceRotation = getWindowManager().getDefaultDisplay().getRotation();
if (mOrientation > 0) {
deviceRotation = mOrientation - 1;
}
int deviceRotation = getDeviceRotation();
Point displaySize = new Point();
getWindowManager().getDefaultDisplay().getSize(displaySize);
@ -1106,6 +1137,8 @@ public class RawActivity extends AppCompatActivity {
* auto-white-balance to converge.
*/
private void takePicture() {
MicroPhotoService.infoLog("RawActivity takePicture PHOTOID=" + Long.toString(mPhotoId));
synchronized (mCameraStateLock) {
mPendingUserCaptures++;
@ -1169,7 +1202,7 @@ public class RawActivity extends AppCompatActivity {
setup3AControlsLocked(captureBuilder);
// Set orientation.
int rotation = getWindowManager().getDefaultDisplay().getRotation();
int rotation = getDeviceRotation();
captureBuilder.set(CaptureRequest.JPEG_ORIENTATION,
sensorToDeviceRotation(mCharacteristics, rotation));
@ -1353,14 +1386,16 @@ public class RawActivity extends AppCompatActivity {
mImage.close();
closeOutput(output);
}
*/
*/
mImage.close();
break;
}
case ImageFormat.RAW_SENSOR: {
DngCreator dngCreator = new DngCreator(mCharacteristics, mCaptureResult);
FileOutputStream output = null;
try {
MicroPhotoService.infoLog("RawActivity Image Size=" + Integer.toString(mImage.getWidth()) + "," + Integer.toString(mImage.getHeight()));
String log = "RawActivity Image Size=" + Integer.toString(mImage.getWidth()) + "," + Integer.toString(mImage.getHeight());
MicroPhotoService.infoLog(log);
output = new FileOutputStream(mFile);
dngCreator.writeImage(output, mImage);
mResult = true;
@ -1770,7 +1805,9 @@ public class RawActivity extends AppCompatActivity {
// intent.setPackage(packageName);
intent.putExtra("photoOrVideo", true);
intent.putExtra("result", result);
intent.putExtra("path", path);
if (!TextUtils.isEmpty(path)) {
intent.putExtra("path", path);
}
intent.putExtra("videoId", mPhotoId);
// intent.setComponent(new ComponentName(packageName, receiverName));

Loading…
Cancel
Save