11package com .adrino .renderscript ;
22
3+ import android .content .Context ;
34import android .graphics .Bitmap ;
45import android .graphics .BitmapFactory ;
56import android .os .Bundle ;
1011
1112import androidx .appcompat .app .AppCompatActivity ;
1213
14+ import com .adrino .hdr .corehdr .Constants ;
15+ import com .adrino .hdr .corehdr .CreateHDR ;
16+
1317import java .io .File ;
1418import java .io .FileNotFoundException ;
1519import java .io .FileOutputStream ;
1620import java .util .ArrayList ;
1721import java .util .List ;
1822
19- import static com .adrino .renderscript .MainActivity .SCALE_THRUSHOLD ;
20- import static com .adrino .renderscript .MainActivity .SOURCE1 ;
21- import static com .adrino .renderscript .MainActivity .SOURCE2 ;
22- import static com .adrino .renderscript .MainActivity .SOURCE3 ;
23-
2423public class Collapse extends AppCompatActivity {
25- ExposureFusion exposureFusion ;
24+ CreateHDR createHDR ;
2625 List <Bitmap > bmpImages ;
2726 private static final String TAG = "Collapse" ;
2827 private List <Bitmap > hdrOutput ;
2928 private boolean set = false ;
29+ private Context context ;
3030
3131 @ Override
3232 protected void onCreate (final Bundle savedInstanceState ) {
3333 super .onCreate (savedInstanceState );
3434 setContentView (R .layout .activity_collapse );
35- exposureFusion = new ExposureFusion (this );
35+ createHDR = new CreateHDR (this );
36+ context = this ;
3637
3738 bmpImages = new ArrayList <>();
3839
39- bmpImages .add (BitmapFactory .decodeResource (getResources (), SOURCE1 ));
40- bmpImages .add (BitmapFactory .decodeResource (getResources (), SOURCE2 ));
41- bmpImages .add (BitmapFactory .decodeResource (getResources (), SOURCE3 ));
42-
43- int imgWidth = bmpImages .get (0 ).getWidth ();
44- int imgHeight = bmpImages .get (0 ).getHeight ();
45- int scaledWidth = imgHeight > imgWidth ? (imgWidth * SCALE_THRUSHOLD ) / imgHeight : SCALE_THRUSHOLD ;
46- int scaledHeight = imgHeight > imgWidth ? SCALE_THRUSHOLD : (imgHeight * SCALE_THRUSHOLD ) / imgWidth ;
47- for (int i = 0 ; i < bmpImages .size (); i ++) {
48- bmpImages .set (i , Bitmap .createScaledBitmap (bmpImages .get (i ), scaledWidth , scaledHeight , false ));
49- }
40+ bmpImages .add (BitmapFactory .decodeResource (getResources (), R .drawable .sarvesh_iphon1 ));
41+ bmpImages .add (BitmapFactory .decodeResource (getResources (), R .drawable .sarvesh_iphone2 ));
42+ bmpImages .add (BitmapFactory .decodeResource (getResources (), R .drawable .sarvesh_iphone3 ));
5043
5144 new Thread (new Runnable () {
5245 @ Override
5346 public void run () {
54- if (! HDRFilter .MEM_BOOST ) {
55- final List <Bitmap > resultant = exposureFusion .perform (bmpImages , ExposureFusion .Actions .RESULTANT );
47+ if (! Constants .MEM_BOOST ) {
48+ final List <Bitmap > resultant = new CreateHDR ( context ) .perform (bmpImages , CreateHDR .Actions .RESULTANT );
5649
5750 runOnUiThread (new Runnable () {
5851 @ Override
@@ -65,14 +58,14 @@ public void run() {
6558 });
6659 }
6760 long start = System .currentTimeMillis ();
68- hdrOutput = exposureFusion .perform (bmpImages , ExposureFusion .Actions .COLLAPSE );
61+ hdrOutput = createHDR .perform (bmpImages , CreateHDR .Actions .HDR );
6962 long end = System .currentTimeMillis ();
7063
71- Log .e (TAG , "run: Total time : " + (float )(end - start )/ 1000 + " s" );
64+ Log .e (TAG , "run: Total time : " + (float ) (end - start ) / 1000 + " s" );
7265 runOnUiThread (new Runnable () {
7366 @ Override
7467 public void run () {
75- ((ImageView )findViewById (R .id .original )).setImageBitmap (bmpImages .get (2 ));
68+ ((ImageView ) findViewById (R .id .original )).setImageBitmap (bmpImages .get (2 ));
7669 ((ImageView ) findViewById (R .id .hdr )).setImageBitmap (hdrOutput .get (0 ));
7770 }
7871 });
@@ -84,14 +77,13 @@ public void run() {
8477 public boolean onLongClick (View v ) {
8578
8679 ImageView imgView = findViewById (R .id .expanded_image );
87- if (!set ){
88- if (hdrOutput != null ) {
80+ if (!set ) {
81+ if (hdrOutput != null ) {
8982 imgView .setVisibility (View .VISIBLE );
9083 imgView .setImageBitmap (hdrOutput .get (0 ));
9184 set = true ;
9285 }
93- }
94- else {
86+ } else {
9587 imgView .setVisibility (View .INVISIBLE );
9688 set = false ;
9789 }
@@ -101,25 +93,25 @@ public boolean onLongClick(View v) {
10193 });
10294 }
10395
104- private void saveBitmaps (Bitmap bitmap , String filename ){
96+ private void saveBitmaps (Bitmap bitmap , String filename ) {
10597 String path = Environment .getExternalStorageDirectory ().toString ();
10698 String directory = "HDRResult" ;
10799
108- path = path + "/" + directory ;
100+ path = path + "/" + directory ;
109101
110- if (!new File (path ).exists ()){
111- Log .e (TAG , "saveBitmaps: " + path );
112- if (new File (path ).mkdir ()){
113- Log .v ("Directory Created :" , "" + path );
102+ if (!new File (path ).exists ()) {
103+ Log .e (TAG , "saveBitmaps: " + path );
104+ if (new File (path ).mkdir ()) {
105+ Log .v ("Directory Created :" , "" + path );
114106
115- try {
116- FileOutputStream out = new FileOutputStream (path + "/" + filename );
107+ try {
108+ FileOutputStream out = new FileOutputStream (path + "/" + filename );
117109 bitmap .compress (Bitmap .CompressFormat .JPEG , 90 , out );
118- } catch (FileNotFoundException e ){
110+ } catch (FileNotFoundException e ) {
119111 Log .e ("Cannot Save" , "File not found" );
120- Log .e ("path" , "" + path );
112+ Log .e ("path" , "" + path );
121113 }
122- } else {
114+ } else {
123115 Log .e ("Directory Error" , "Directory cannot be created" );
124116 }
125117 }
0 commit comments