Skip to content

Commit

Permalink
captured photos should be in full color!
Browse files Browse the repository at this point in the history
  • Loading branch information
n8fr8 committed Aug 9, 2017
1 parent 798682f commit 593ce54
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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");
Expand All @@ -112,6 +132,7 @@ public void run() {
listener.onProcess(
lastBitmap,
newBitmap,
rawBitmap,
hasChanged);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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));
}
Expand Down

0 comments on commit 593ce54

Please sign in to comment.