优化RAW格式照片的处理

TempBranch
Matthew 9 months ago
parent 965c3dbd5e
commit 1fdbc1701e

@ -730,15 +730,34 @@ Java_com_xypower_mpapp_MicroPhotoService_captureFinished(
bool hardwareBitmap = (info.flags & ANDROID_BITMAP_FLAGS_IS_HARDWARE) != 0;
void* pixels = NULL;
res = AndroidBitmap_lockPixels(env, bitmap, &pixels);
if (res < 0)
AHardwareBuffer* hardwareBuffer = NULL;
if (hardwareBitmap)
{
}
#if 0
res = AndroidBitmap_getHardwareBuffer(env, bitmap, &hardwareBuffer);
int32_t fence = -1;
res = AHardwareBuffer_lock(hardwareBuffer, AHARDWAREBUFFER_USAGE_CPU_READ_OFTEN, fence, NULL, &pixels);
cv::Mat mat(info.height, info.width, CV_8UC4, pixels);
AHardwareBuffer_unlock(hardwareBuffer, &fence);
cv::Mat mat(info.height, info.width, CV_8UC4, pixels);
AndroidBitmap_unlockPixels(env, bitmap);
cv::cvtColor(mat, mat, cv::COLOR_RGB2BGR);
((CPhoneDevice *)dev)->OnCaptureReady(photoOrVideo != JNI_FALSE, result != JNI_FALSE, mat, (unsigned long)photoId);
#endif // 0
} else
{
res = AndroidBitmap_lockPixels(env, bitmap, &pixels);
cv::Mat tmp(info.height, info.width, CV_8UC4, pixels);
((CPhoneDevice *)dev)->OnCaptureReady(photoOrVideo != JNI_FALSE, result != JNI_FALSE, mat, (unsigned long)photoId);
cv::Mat mat(info.height, info.width, CV_8UC4);
// tmp.copyTo(mat);
cv::cvtColor(tmp, mat, cv::COLOR_RGBA2BGR);
AndroidBitmap_unlockPixels(env, bitmap);
((CPhoneDevice *)dev)->OnCaptureReady(photoOrVideo != JNI_FALSE, result != JNI_FALSE, mat, (unsigned long)photoId);
}
}
}

@ -38,6 +38,7 @@ import android.os.PowerManager;
import android.os.RemoteException;
import android.os.SystemClock;
import androidx.annotation.NonNull;
import androidx.core.app.NotificationCompat;
import androidx.core.content.FileProvider;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
@ -406,12 +407,22 @@ public class MicroPhotoService extends Service {
@Override
public void run() {
Bitmap bm = null;
// ImageDecoder.Source src = ImageDecoder.createSource(new File(path));
try {
// bm = ImageDecoder.decodeBitmap(src);
bm = BitmapFactory.decodeFile(path);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
ImageDecoder.Source src = ImageDecoder.createSource(new File(path));
ImageDecoder.OnHeaderDecodedListener listener =
new ImageDecoder.OnHeaderDecodedListener(){
@Override
public void onHeaderDecoded(@NonNull ImageDecoder decoder, @NonNull ImageDecoder.ImageInfo info, @NonNull ImageDecoder.Source source) {
decoder.setAllocator(ImageDecoder.ALLOCATOR_SOFTWARE);
}
};
bm = ImageDecoder.decodeBitmap(src, listener);
} else {
bm = BitmapFactory.decodeFile(path);
}
} catch (Exception ex) {
}
mService.captureFinished(mService.mNativeHandle, photoOrVideo, result && bm != null, bm, videoId);
}

@ -8,6 +8,7 @@ import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.ImageDecoder;
import android.media.midi.MidiDevice;
import android.os.Build;
import android.os.Looper;
import android.os.Message;
import android.os.SystemClock;
@ -52,6 +53,8 @@ import android.util.Size;
import android.util.SparseIntArray;
import android.view.Surface;
import android.view.TextureView;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Toast;
import com.xypower.mpapp.MicroPhotoService;
@ -167,14 +170,38 @@ public class RawActivity extends AppCompatActivity {
private final TextureView.SurfaceTextureListener mSurfaceTextureListener
= new TextureView.SurfaceTextureListener() {
private boolean mTaken = false;
@Override
public void onSurfaceTextureAvailable(SurfaceTexture texture, int width, int height) {
configureTransform(width, height);
if (!mTaken) {
mTaken = true;
mMessageHandler.postDelayed(new Runnable() {
@Override
public void run() {
takePicture();
}
}, 400);
}
}
@Override
public void onSurfaceTextureSizeChanged(SurfaceTexture texture, int width, int height) {
configureTransform(width, height);
if (!mTaken) {
mTaken = true;
mMessageHandler.postDelayed(new Runnable() {
@Override
public void run() {
takePicture();
}
}, 400);
}
}
@Override
@ -558,6 +585,23 @@ public class RawActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Window win = getWindow();
int flags = /*WindowManager.LayoutParams.FLAG_FULLSCREEN
| */WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
| WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
| WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
| WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD;
int mask = /*WindowManager.LayoutParams.FLAG_FULLSCREEN |
| */WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
| WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
| WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
| WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD;
win.setFlags(flags, mask);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
setShowWhenLocked(true);
}
setContentView(R.layout.activity_raw);
mTextureView = (AutoFitTextureView) findViewById(R.id.texture);
@ -590,12 +634,7 @@ public class RawActivity extends AppCompatActivity {
MicroPhotoService.infoLog("RawActivity created PHOTOID=" + Long.toString(mPhotoId));
mTextureView.setAspectRatio(width, height);
}
@Override
public void onResume() {
super.onResume();
startBackgroundThread();
openCamera();
@ -605,28 +644,35 @@ public class RawActivity extends AppCompatActivity {
// the SurfaceTextureListener).
if (mTextureView.isAvailable()) {
configureTransform(mTextureView.getWidth(), mTextureView.getHeight());
mMessageHandler.postDelayed(new Runnable() {
@Override
public void run() {
takePicture();
}
}, 400);
} else {
mTextureView.setSurfaceTextureListener(mSurfaceTextureListener);
}
if (mOrientationListener != null && mOrientationListener.canDetectOrientation()) {
mOrientationListener.enable();
}
}
@Override
public void onResume() {
super.onResume();
MicroPhotoService.infoLog("RawActivity onResume PHOTOID=" + Long.toString(mPhotoId));
mMessageHandler.postDelayed(new Runnable() {
@Override
public void run() {
takePicture();
}
}, 400);
}
@Override
public void onPause() {
if (mOrientationListener != null) {
mOrientationListener.disable();
}
closeCamera();
stopBackgroundThread();
MicroPhotoService.infoLog("RawActivity onPause PHOTOID=" + Long.toString(mPhotoId));
super.onPause();
}
@ -634,6 +680,12 @@ public class RawActivity extends AppCompatActivity {
protected void onDestroy() {
super.onDestroy();
if (mOrientationListener != null) {
mOrientationListener.disable();
}
closeCamera();
stopBackgroundThread();
MicroPhotoService.infoLog("RawActivity destroyed PHOTOID=" + Long.toString(mPhotoId));
}

@ -4,6 +4,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:keepScreenOn="true"
tools:context=".video.RawActivity">
<com.xypower.mpapp.video.AutoFitTextureView

Loading…
Cancel
Save