Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0b72e17b authored by Mark Harman's avatar Mark Harman
Browse files

Fix HDR problems due to tonemap_scale_c too small; add tests testHDR58,...

Fix HDR problems due to tonemap_scale_c too small; add tests testHDR58, testHDR59, testHDR60 for this.
parent 60cf2d49
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -57,6 +57,8 @@ FIXED Photos would sometimes fail to save on some devices with Storage Access
        options were enabled (options like DRO, HDR, auto-level, photostamp that require
        post-processing; custom Exif tags like artist or copyright; or when using geotagging with
        Camera2 API).
FIXED   Fix for HDR scenes with both very bright and very dark regions, result would be over
        exposed.
FIXED   Corrupt videos could be left over if video failed to start.
FIXED   Possible problem taking photos on some devices with LIMITED Camera2 API support.
FIXED   Possible problem with default edge mode and noise reduction mode behaviours on some devices
+3 −0
Original line number Diff line number Diff line
@@ -74,6 +74,9 @@ public class HDRTests {
        suite.addTest(TestSuite.createTest(MainActivityTest.class, "testHDR55"));
        suite.addTest(TestSuite.createTest(MainActivityTest.class, "testHDR56"));
        suite.addTest(TestSuite.createTest(MainActivityTest.class, "testHDR57"));
        suite.addTest(TestSuite.createTest(MainActivityTest.class, "testHDR58"));
        suite.addTest(TestSuite.createTest(MainActivityTest.class, "testHDR59"));
        suite.addTest(TestSuite.createTest(MainActivityTest.class, "testHDR60"));
        return suite;
    }
}
+65 −4
Original line number Diff line number Diff line
@@ -13254,7 +13254,8 @@ public class MainActivityTest extends ActivityInstrumentationTestCase2<MainActiv
        checkHDROffsets(exp_offsets_x, exp_offsets_y);
        //checkHistogramDetails(hdrHistogramDetails, 17, 81, 255);
        checkHistogramDetails(hdrHistogramDetails, 32, 74, 255);
        //checkHistogramDetails(hdrHistogramDetails, 32, 74, 255);
        checkHistogramDetails(hdrHistogramDetails, 29, 68, 255);
    }
    /** Tests HDR algorithm on test samples "testHDR23", but with 4 images.
@@ -13303,7 +13304,8 @@ public class MainActivityTest extends ActivityInstrumentationTestCase2<MainActiv
        checkHDROffsets(exp_offsets_x, exp_offsets_y);
        //checkHistogramDetails(hdrHistogramDetails, 17, 81, 255);
        checkHistogramDetails(hdrHistogramDetails, 28, 82, 255);
        //checkHistogramDetails(hdrHistogramDetails, 28, 82, 255);
        checkHistogramDetails(hdrHistogramDetails, 21, 74, 255);
    }
    /** Tests HDR algorithm on test samples "testHDR23", but with 6 images.
@@ -13356,7 +13358,8 @@ public class MainActivityTest extends ActivityInstrumentationTestCase2<MainActiv
        checkHDROffsets(exp_offsets_x, exp_offsets_y);
        //checkHistogramDetails(hdrHistogramDetails, 17, 81, 255);
        checkHistogramDetails(hdrHistogramDetails, 28, 82, 255);
        //checkHistogramDetails(hdrHistogramDetails, 28, 82, 255);
        checkHistogramDetails(hdrHistogramDetails, 20, 72, 255);
    }
    /** Tests HDR algorithm on test samples "testHDR24".
@@ -14108,7 +14111,8 @@ public class MainActivityTest extends ActivityInstrumentationTestCase2<MainActiv
        HistogramDetails hdrHistogramDetails = subTestHDR(inputs, "testHDR49_exp4_output.jpg", false, -1, -1);
        checkHistogramDetails(hdrHistogramDetails, 0, 100, 245);
        //checkHistogramDetails(hdrHistogramDetails, 0, 100, 245);
        checkHistogramDetails(hdrHistogramDetails, 0, 94, 244);
    }
    /** Tests HDR algorithm on test samples "testHDR49".
@@ -14275,6 +14279,63 @@ public class MainActivityTest extends ActivityInstrumentationTestCase2<MainActiv
        //checkHistogramDetails(hdrHistogramDetails, 0, 75, 255);
    }
    /** Tests HDR algorithm on test samples "testHDR58".
     */
    public void testHDR58() throws IOException, InterruptedException {
        Log.d(TAG, "testHDR58");
        setToDefault();
        // list assets
        List<Bitmap> inputs = new ArrayList<>();
        inputs.add( getBitmapFromFile(hdr_images_path + "testHDR58/IMG_20190911_210146_0.jpg") );
        inputs.add( getBitmapFromFile(hdr_images_path + "testHDR58/IMG_20190911_210146_1.jpg") );
        inputs.add( getBitmapFromFile(hdr_images_path + "testHDR58/IMG_20190911_210146_2.jpg") );
        HistogramDetails hdrHistogramDetails = subTestHDR(inputs, "testHDR58_output.jpg", false, 1250, 1000000000L/10);
        //HistogramDetails hdrHistogramDetails = subTestHDR(inputs, "testHDR58_output.jpg", false, 1250, 1000000000L/10, HDRProcessor.TonemappingAlgorithm.TONEMAPALGORITHM_CLAMP);
        checkHistogramDetails(hdrHistogramDetails, 11, 119, 255);
    }
    /** Tests HDR algorithm on test samples "testHDR59".
     */
    public void testHDR59() throws IOException, InterruptedException {
        Log.d(TAG, "testHDR59");
        setToDefault();
        // list assets
        List<Bitmap> inputs = new ArrayList<>();
        inputs.add( getBitmapFromFile(hdr_images_path + "testHDR59/IMG_20190911_210154_0.jpg") );
        inputs.add( getBitmapFromFile(hdr_images_path + "testHDR59/IMG_20190911_210154_1.jpg") );
        inputs.add( getBitmapFromFile(hdr_images_path + "testHDR59/IMG_20190911_210154_2.jpg") );
        HistogramDetails hdrHistogramDetails = subTestHDR(inputs, "testHDR59_output.jpg", false, 1250, 1000000000L/10);
        //HistogramDetails hdrHistogramDetails = subTestHDR(inputs, "testHDR59_output.jpg", false, 1250, 1000000000L/10, HDRProcessor.TonemappingAlgorithm.TONEMAPALGORITHM_CLAMP);
        //checkHistogramDetails(hdrHistogramDetails, 0, 75, 255);
    }
    /** Tests HDR algorithm on test samples "testHDR60".
     */
    public void testHDR60() throws IOException, InterruptedException {
        Log.d(TAG, "testHDR60");
        setToDefault();
        // list assets
        List<Bitmap> inputs = new ArrayList<>();
        inputs.add( getBitmapFromFile(hdr_images_path + "testHDR60/IMG_20200507_020319_0.jpg") );
        inputs.add( getBitmapFromFile(hdr_images_path + "testHDR60/IMG_20200507_020319_1.jpg") );
        inputs.add( getBitmapFromFile(hdr_images_path + "testHDR60/IMG_20200507_020319_2.jpg") );
        HistogramDetails hdrHistogramDetails = subTestHDR(inputs, "testHDR60_output.jpg", false, 491, 1000000000L/10);
        //HistogramDetails hdrHistogramDetails = subTestHDR(inputs, "testHDR60_output.jpg", false, 491, 1000000000L/10, HDRProcessor.TonemappingAlgorithm.TONEMAPALGORITHM_CLAMP);
        //checkHistogramDetails(hdrHistogramDetails, 0, 75, 255);
    }
    /** Tests HDR algorithm on test samples "testHDRtemp".
     *  Used for one-off testing, or to recreate HDR images from the base exposures to test an updated alorithm.
     *  The test images should be copied to the test device into DCIM/testOpenCamera/testdata/hdrsamples/testHDRtemp/ .
+10 −1
Original line number Diff line number Diff line
@@ -797,8 +797,17 @@ public class HDRProcessor {
            final float tonemap_denom = ((float)median_target)/(float)median_brightness - (255.0f / max_possible_value);
            if( MyDebug.LOG )
                Log.d(TAG, "tonemap_denom: " + tonemap_denom);
            if( tonemap_denom != 0.0f ) // just in case
            if( tonemap_denom != 0.0f ) { // just in case
                tonemap_scale_c = (255.0f - median_target) / tonemap_denom;
                if( MyDebug.LOG )
                    Log.d(TAG, "tonemap_scale_c (before setting min): " + tonemap_scale_c);
                /*if( tonemap_scale_c < 0.5f*255.0f ) {
                    throw new RuntimeException("tonemap_scale_c: " + tonemap_scale_c);
                }*/
                // important to set a min value, see testHDR58, testHDR59, testHDR60 - at least 0.25, but 0.5 works better:
                //tonemap_scale_c = Math.max(tonemap_scale_c, 0.25f*255.0f);
                tonemap_scale_c = Math.max(tonemap_scale_c, 0.5f*255.0f);
            }
            //throw new RuntimeException(); // test
        }
        // Higher tonemap_scale_c values means darker results from the Reinhard tonemapping.