From 593ce5457a2cda6b750cee380399f0abe4358b15 Mon Sep 17 00:00:00 2001 From: n8fr8 Date: Tue, 8 Aug 2017 23:57:19 -0400 Subject: [PATCH] captured photos should be in full color! --- .../sensors/media/MotionAsyncTask.java | 21 +++++++++++++++++++ .../phoneypot/sensors/motion/Preview.java | 15 +++++++------ .../phoneypot/ui/CameraFragment.java | 3 ++- 3 files changed, 30 insertions(+), 9 deletions(-) diff --git a/src/main/java/info/guardianproject/phoneypot/sensors/media/MotionAsyncTask.java b/src/main/java/info/guardianproject/phoneypot/sensors/media/MotionAsyncTask.java index 03e77111..27756fed 100644 --- a/src/main/java/info/guardianproject/phoneypot/sensors/media/MotionAsyncTask.java +++ b/src/main/java/info/guardianproject/phoneypot/sensors/media/MotionAsyncTask.java @@ -7,6 +7,7 @@ package info.guardianproject.phoneypot.sensors.media; +import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; @@ -15,7 +16,9 @@ import java.util.List; import android.graphics.Bitmap; +import android.graphics.BitmapFactory; import android.graphics.Color; +import android.graphics.ImageFormat; import android.graphics.Rect; import android.graphics.YuvImage; import android.os.Environment; @@ -49,11 +52,13 @@ public class MotionAsyncTask extends Thread { private Bitmap lastBitmap; private Bitmap newBitmap; + private Bitmap rawBitmap; private boolean hasChanged; public interface MotionListener { public void onProcess(Bitmap oldBitmap, Bitmap newBitmap, + Bitmap rawBitmap, boolean motionDetected); } @@ -101,6 +106,21 @@ public void run() { lastBitmap = ImageCodec.lumaToBitmapGreyscale(oldPicLuma, width, height); newBitmap = Bitmap.createBitmap(newPic, width, height, Bitmap.Config.RGB_565); + + if (hasChanged) { + YuvImage image = new YuvImage(rawNewPic, ImageFormat.NV21, width, height, null); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + image.compressToJpeg( + new Rect(0, 0, image.getWidth(), image.getHeight()), 90, + baos); + + byte[] imageBytes = baos.toByteArray(); + rawBitmap = BitmapFactory.decodeByteArray(imageBytes, 0, imageBytes.length); + } + else + { + rawBitmap = null; + } } Log.i("MotionAsyncTask", "Finished processing, sending results"); @@ -112,6 +132,7 @@ public void run() { listener.onProcess( lastBitmap, newBitmap, + rawBitmap, hasChanged); } diff --git a/src/main/java/info/guardianproject/phoneypot/sensors/motion/Preview.java b/src/main/java/info/guardianproject/phoneypot/sensors/motion/Preview.java index 252c2d08..8754a219 100644 --- a/src/main/java/info/guardianproject/phoneypot/sensors/motion/Preview.java +++ b/src/main/java/info/guardianproject/phoneypot/sensors/motion/Preview.java @@ -244,6 +244,7 @@ public void onPreviewFrame(byte[] data, Camera cam) { task.addListener(new MotionAsyncTask.MotionListener() { public void onProcess(Bitmap oldBitmap, Bitmap newBitmap, + Bitmap rawBitmap, boolean motionDetected) { if (motionDetected) { @@ -260,24 +261,22 @@ public void onProcess(Bitmap oldBitmap, Bitmap newBitmap, String ts = new Date().getTime() + ".jpg"; - /** File fileImage = new File(fileImageDir, "detected.original." + ts); FileOutputStream stream = new FileOutputStream(fileImage); - newBitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream); + rawBitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream); stream.flush(); stream.close(); + message.getData().putString("path", fileImage.getAbsolutePath()); - message.getData().putString("original", fileImage.getAbsolutePath()); - **/ - - File fileImage = new File(fileImageDir, "detected.match." + ts); - FileOutputStream stream = new FileOutputStream(fileImage); + /** + fileImage = new File(fileImageDir, "detected.match." + ts); + stream = new FileOutputStream(fileImage); oldBitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream); stream.flush(); stream.close(); message.getData().putString("path", fileImage.getAbsolutePath()); - + **/ serviceMessenger.send(message); diff --git a/src/main/java/info/guardianproject/phoneypot/ui/CameraFragment.java b/src/main/java/info/guardianproject/phoneypot/ui/CameraFragment.java index cc777b74..b3c82ae5 100644 --- a/src/main/java/info/guardianproject/phoneypot/ui/CameraFragment.java +++ b/src/main/java/info/guardianproject/phoneypot/ui/CameraFragment.java @@ -68,7 +68,7 @@ public void onResume() { preview.addListener(new MotionAsyncTask.MotionListener() { - public void onProcess(Bitmap oldBitmap, Bitmap newBitmap, + public void onProcess(Bitmap oldBitmap, Bitmap newBitmap, Bitmap rawBitmap, boolean motionDetected) { int rotation = 0; boolean reflex = false; @@ -78,6 +78,7 @@ public void onProcess(Bitmap oldBitmap, Bitmap newBitmap, rotation = 270; reflex = true; } + // oldImage.setImageBitmap(ImageCodec.rotate(oldBitmap, rotation, reflex)); newImage.setImageBitmap(ImageCodec.rotate(newBitmap, rotation, reflex)); }