Skip to content

Commit

Permalink
[ IntrensicResize ] v1.2 : Refactor 'hdr.corehdr' library and 'hdr.ca…
Browse files Browse the repository at this point in the history
…mera' library

---------------------------------------------------------------------------------------
TODO : Some implementation modification of hdr.camera lib.
  • Loading branch information
AdarshRevankar committed Mar 9, 2020
1 parent fe3c8c0 commit 96e87e4
Show file tree
Hide file tree
Showing 16 changed files with 78 additions and 119 deletions.
1 change: 0 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ dependencies {
implementation 'com.android.support:appcompat-v7:29.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.github.bumptech.glide:glide:3.7.0'
implementation 'com.asksira.android:bsimagepicker:1.3.2'
testImplementation 'junit:junit:4.13'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
Expand Down
9 changes: 4 additions & 5 deletions app/src/main/java/com/adrino/renderscript/CameraActivity.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package com.adrino.renderscript;

import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

import java.util.Objects;
import androidx.appcompat.app.AppCompatActivity;

import com.adrino.hdr.camera.CameraCapture;

public class CameraActivity extends AppCompatActivity {

Expand All @@ -16,7 +15,7 @@ protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_camera);
if (null == savedInstanceState) {
getSupportFragmentManager().beginTransaction()
.replace(R.id.container, CameraCapture.newInstance())
.replace(R.id.container, CameraCapture.newInstance(MainActivity.class))
.commit();
}
}
Expand Down
4 changes: 1 addition & 3 deletions app/src/main/res/layout/activity_camera.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@
limitations under the License.
-->
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000"
tools:context="com.adrino.renderscript.CameraActivity" />
android:background="#000"/>
20 changes: 12 additions & 8 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context=".MainActivity">

<LinearLayout
Expand Down Expand Up @@ -172,7 +171,8 @@
android:onClick="setContrast"
android:scaleType="fitCenter"
android:background="#000000"
android:src="@drawable/icon_c"/>
android:src="@drawable/icon_c"
style="@android:style/Widget.Material.Light.Button.Borderless"/>

<ImageButton
android:id="@+id/Saturation"
Expand All @@ -183,7 +183,8 @@
android:onClick="setSaturation"
android:scaleType="fitCenter"
android:background="#000000"
android:src="@drawable/icon_s" />
android:src="@drawable/icon_s"
style="@android:style/Widget.Material.Light.Button.Borderless"/>

<ImageButton
android:layout_weight="1"
Expand All @@ -194,8 +195,8 @@
android:background="#000000"
android:onClick="setExposure"
android:scaleType="fitCenter"

android:src="@drawable/icon_e"/>
android:src="@drawable/icon_e"
style="@android:style/Widget.Material.Light.Button.Borderless"/>

<ImageButton
android:layout_weight="1"
Expand All @@ -206,7 +207,8 @@
android:onClick="setNormal"
android:src="@drawable/icon_n"
android:scaleType="fitCenter"
android:background="#000000"/>
android:background="#000000"
style="@android:style/Widget.Material.Light.Button.Borderless"/>

<ImageButton
android:layout_weight="1"
Expand All @@ -217,7 +219,8 @@
android:background="#000000"
android:scaleType="fitCenter"
android:src="@drawable/icon_pyramid"
android:onClick="doGaussianLaplacian"/>
android:onClick="doGaussianLaplacian"
style="@android:style/Widget.Material.Light.Button.Borderless"/>
<ImageButton
android:layout_weight="1"
android:padding="5dp"
Expand All @@ -227,7 +230,8 @@
android:scaleType="fitCenter"
android:background="#000000"
android:src="@drawable/icon_combine"
android:onClick="doCollapse"/>
android:onClick="doCollapse"
style="@android:style/Widget.Material.Light.Button.Borderless"/>
</LinearLayout>

<LinearLayout
Expand Down
16 changes: 0 additions & 16 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,19 +1,3 @@
<resources>
<string name="app_name">RenderScript</string>
<string name="cameraCapture">Capture</string>
<string name="picture">Picture</string>
<string name="description_info">Info</string>
<string name="process">Create HDR</string>
<string name="request_permission">This sample needs camera permission.</string>
<string name="camera_error">This device doesn\'t support Camera2 API.</string>
<string name="intro_message">
<![CDATA[
This sample demonstrates the basic use of Camera2 API. Check the source code to see how
you can display camera preview and take pictures.
]]>
</string>
</resources>
2 changes: 1 addition & 1 deletion hdr/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.adrino.hdr" >

<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package com.adrino.renderscript;
package com.adrino.hdr.camera;

import android.content.Context;
import android.util.AttributeSet;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package com.adrino.renderscript;
package com.adrino.hdr.camera;

import android.Manifest;
import android.app.Activity;
Expand Down Expand Up @@ -53,7 +53,6 @@
import android.os.HandlerThread;
import android.provider.MediaStore;
import android.util.Log;
import android.util.Range;
import android.util.Size;
import android.util.SparseIntArray;
import android.view.LayoutInflater;
Expand All @@ -70,7 +69,7 @@
import androidx.fragment.app.DialogFragment;
import androidx.fragment.app.Fragment;

import com.asksira.bsimagepicker.BSImagePicker;
import com.adrino.hdr.R;

import java.io.File;
import java.io.FileOutputStream;
Expand All @@ -85,11 +84,10 @@
import java.util.concurrent.TimeUnit;

import static android.content.Context.SENSOR_SERVICE;
import static com.adrino.hdr.camera.Constants.EXPOSURE_BRACKET;

public class CameraCapture extends Fragment
implements View.OnClickListener, ActivityCompat.OnRequestPermissionsResultCallback,
BSImagePicker.OnMultiImageSelectedListener, SensorEventListener {

implements View.OnClickListener, ActivityCompat.OnRequestPermissionsResultCallback, SensorEventListener {
/**
* Conversion from screen rotation to JPEG orientation.
*/
Expand All @@ -99,6 +97,7 @@ public class CameraCapture extends Fragment
private static final String FRAGMENT_WOBBLE = "wobbleCheck";
private static final String FRAGMENT_SUCCESS = "SUCCESS";
private static final int IMAGE_REQUEST = 100;
private static Class intentClass = null;

static {
ORIENTATIONS.append(Surface.ROTATION_0, 90);
Expand Down Expand Up @@ -263,9 +262,12 @@ public void onError(@NonNull CameraDevice cameraDevice, int error) {

@Override
public void onImageAvailable(ImageReader reader) {
Log.e(TAG, "onImageAvailable: WRONG LISTENER");
// if (imageCount <= 3 && imageCount >= 1)
// mBackgroundHandler.post(new ImageSaver(reader.acquireNextImage(), new File(getActivity().getExternalFilesDir(null), "pic" + imageCount + ".jpg")));
++writtenCount;
Log.e(TAG, "onImageAvailable: Listener " + writtenCount);
mBackgroundHandler.post(new ImageSaver(reader.acquireNextImage(), new File(getActivity().getExternalFilesDir(null), "pic" + writtenCount + ".jpg")));
if (writtenCount >= 3) {
writtenCount = 0;
}
}

};
Expand Down Expand Up @@ -371,37 +373,6 @@ public void onCaptureCompleted(@NonNull CameraCaptureSession session,
};

private int writtenCount = 0;
private int[] EXPOSURE = {20, 0, -20};
private ImageReader.OnImageAvailableListener[] listener =
{
new ImageReader.OnImageAvailableListener() {
@Override
public void onImageAvailable(ImageReader imageReader) {
Log.e(TAG, "onImageAvailable: Listener 1");
}
},

new ImageReader.OnImageAvailableListener() {
@Override
public void onImageAvailable(ImageReader imageReader) {
Log.e(TAG, "onImageAvailable: Listener 2");
}
},

new ImageReader.OnImageAvailableListener() {
@Override
public void onImageAvailable(ImageReader imageReader) {
++writtenCount;
Log.e(TAG, "onImageAvailable: Listener 3 " + writtenCount);
mBackgroundHandler.post(new ImageSaver(imageReader.acquireNextImage(), new File(getActivity().getExternalFilesDir(null), "pic" + writtenCount + ".jpg")));
if (writtenCount >= 3) {
writtenCount = 0;
}
}
}

};
private Range<Integer> range;

/**
* Shows a {@link Toast} on the UI thread.
Expand Down Expand Up @@ -469,14 +440,15 @@ private static Size chooseOptimalSize(Size[] choices, int textureViewWidth,
}
}

public static CameraCapture newInstance() {
public static CameraCapture newInstance(Class targetClass) {
intentClass = targetClass;
return new CameraCapture();
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_camera2_basic, container, false);
return inflater.inflate(com.adrino.hdr.R.layout.fragment_camera2_basic, container, false);
}

@Override
Expand Down Expand Up @@ -524,7 +496,6 @@ public void onPause() {
}



private void requestCameraPermission() {
if (shouldShowRequestPermissionRationale(Manifest.permission.CAMERA)) {
new ConfirmationDialog().show(getChildFragmentManager(), FRAGMENT_DIALOG);
Expand Down Expand Up @@ -561,8 +532,6 @@ private void setUpCameraOutputs(int width, int height) {
CameraCharacteristics characteristics
= manager.getCameraCharacteristics(cameraId);

range = characteristics.get(CameraCharacteristics.CONTROL_AE_COMPENSATION_RANGE);

// We don't use a front facing camera in this sample.
Integer facing = characteristics.get(CameraCharacteristics.LENS_FACING);
if (facing != null && facing == CameraCharacteristics.LENS_FACING_FRONT) {
Expand Down Expand Up @@ -832,7 +801,7 @@ private void configureTransform(int viewWidth, int viewHeight) {
/**
* Initiate a still image capture.
*/
private void takePicture() {
void takePicture() {
lockFocus();
setImageCaptureStart(true);
}
Expand Down Expand Up @@ -883,34 +852,22 @@ private void captureStillPicture() {
return;
}

EXPOSURE[0] = -10;
EXPOSURE[1] = 10;
EXPOSURE[2] = 0;


Log.e(TAG, "captureStillPicture: " + EXPOSURE[0]);
Log.e(TAG, "captureStillPicture: " + EXPOSURE[1]);
Log.e(TAG, "captureStillPicture: " + EXPOSURE[2]);

for (int i = 0; i < 3; i++) {
mImageReader.setOnImageAvailableListener(
listener[i], mBackgroundHandler);
// This is the CaptureRequest.Builder that we use to take a picture.
final CaptureRequest.Builder captureBuilder =
mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE);
captureBuilder.addTarget(mImageReader.getSurface());

// Use the same AE and AF modes as the preview.
captureBuilder.set(CaptureRequest.CONTROL_AE_LOCK, false);
captureBuilder.set(CaptureRequest.CONTROL_AE_EXPOSURE_COMPENSATION, EXPOSURE[i]);
captureBuilder.set(CaptureRequest.CONTROL_AE_EXPOSURE_COMPENSATION, EXPOSURE_BRACKET[i]);

setAutoFlash(captureBuilder);

// Orientation
int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
captureBuilder.set(CaptureRequest.JPEG_ORIENTATION, getOrientation(rotation));


mCaptureSession.stopRepeating();
mCaptureSession.abortCaptures();
mCaptureSession.capture(captureBuilder.build(), null, null);
Expand Down Expand Up @@ -969,27 +926,24 @@ void openImageChooser() {

@Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.picture: {
takePicture();
break;
}
case R.id.process:
Intent i = new Intent(getActivity(), MainActivity.class);
i.putExtra("location", getActivity().getExternalFilesDir(null).toString());
startActivity(i);
break;

case R.id.imgPicker:
openImageChooser();
break;
if (view.getId() == R.id.picture) {
takePicture();
}
if (view.getId() == R.id.process) {
Intent i = new Intent(getActivity(), intentClass);
i.putExtra("location", getActivity().getExternalFilesDir(null).toString());
startActivity(i);
}

if (view.getId() == R.id.imgPicker) {
openImageChooser();
}
}

@Override
public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Intent i = new Intent(getActivity(), MainActivity.class);
Intent i = new Intent(getActivity(), intentClass);
i.putExtra("pickerLocation1", getPathFormUri(data.getData()));
startActivity(i);
}
Expand All @@ -1007,13 +961,6 @@ private String getPathFormUri(Uri uri) {
return res;
}

@Override
public void onMultiImageSelected(List<Uri> uriList, String tag) {
for (Uri uri : uriList) {
Log.e(TAG, "onMultiImageSelected: " + uri.toString());
}
}

private void setAutoFlash(CaptureRequest.Builder requestBuilder) {
if (mFlashSupported) {
requestBuilder.set(CaptureRequest.CONTROL_AE_MODE,
Expand Down Expand Up @@ -1183,7 +1130,6 @@ private synchronized void setMobilePositionChanged(boolean mobilePositionChanged
}



private void initSensor() {
sensorManager = (SensorManager) getActivity().getSystemService(SENSOR_SERVICE);
accelerometer = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
Expand Down
5 changes: 5 additions & 0 deletions hdr/src/main/java/com/adrino/hdr/camera/Constants.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.adrino.hdr.camera;

public class Constants {
public static int[] EXPOSURE_BRACKET = {10, 0, -10};
}
Loading

0 comments on commit 96e87e4

Please sign in to comment.