7

I am working on an app with custom Camera functionality. The Camera is working fine on the Galaxy S3, S4, HTC, Nexus, but on the S5, all of the photos that require flash come out dark. The photo looks fine in the preview, the flash fires, but what is captured by the sensor is always too dark, as if the flash never fired off, or the firing of the flash and the capturing of the image happened at different times. The flash can be either set to auto or to always on, with the same effect. I've tried FOCUS_MODE_CONTINUOUS_PICTURE and FOCUS_MODE_AUTO, with the same result.

Does anyone have any suggestions what else to try?

Thank You, Gary

divibisan
  • 11,659
  • 11
  • 40
  • 58
Gary Kipnis
  • 722
  • 14
  • 33
  • This question appears to be off-topic because it has nothing to do with programming – PeeHaa Oct 11 '14 at 19:15
  • 3
    @PeeHaa This questions has everything to do with programming. I am seeking help with properly configuring (programming) the camera in my application. – Gary Kipnis Oct 11 '14 at 19:19
  • I am having a similar issue with my Nexus 4. Taking a picture with the stock camera, there is a flash and the picture comes out fine. Taking it in my custom camera with a flash has the entire image incredibly dark. – Patrick Dattilio Nov 07 '14 at 22:51
  • 1
    @PatrickDattilio Did you ever resolve your issues? I've switched to using the stock camera, as it is definitely optimized to work perfectly for the device, but I end up losing some UI features, but I suppose it's better to have good quality photos at the expense of some features :) – Gary Kipnis Nov 13 '14 at 19:23
  • Unfortunately no, I'm hoping this post gains some traction. I tried Continuous Focus, setting the white balance and scene to auto. Nothing works. The image is absurdly dark. I'm guessing [this other Stackoverflow post](http://stackoverflow.com/questions/25344770/android-save-image-taken-with-flash-on-nexus-4) is related. – Patrick Dattilio Nov 14 '14 at 05:23

2 Answers2

9

It seems like there are 2 unrelated bugs here, one on the Nexus 4, the other on the Samsung S5. They both seem to manifest as the same issue, pictures taken in low light conditions with the flash on appear extremely dark, but have very different root causes.

Nexus 4

The Nexus 4 breaks when using continuous focus in conjunction with the flash. This seems like a relatively well known issue and the only solution seems to be to use FOCUS_MODE_AUTO instead of FOCUS_MODE_CONTINUOUS_PICTURE. The root cause seems to be related to taking the picture too early, before the flash gets a chance to fire.

As far as I know, the Nexus 4 is the only device that needs this kind of special casing (i.e. it reports supporting FOCUS_MODE_CONTINUOUS_PICTURE but breaks horribly with it).

// dummy method, replace with wherever you setup camera params
public void onCameraOpened(Camera camera) {
    Camera.Parameters params = camera.getParameters();

    setFocusModeParameter(
        params,
        Build.MODEL.equals("Nexus 4")
            ? new String[] {
                Camera.Parameters.FOCUS_MODE_AUTO
            }
            : new String[] {
                Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE,
                Camera.Parameters.FOCUS_MODE_AUTO,
            }
    );

    camera.setParameters(params);
}

public static void setFocusModeParameter(Camera.Parameters params, String... preferences) {
    List<String> supported_focus_modes = params.getSupportedFocusModes();
    if (supported_focus_modes == null) {
        return;
    }

    for (String pref : preferences) {
        if (supported_focus_modes.contains(pref)) {
            params.setFocusMode(pref);
            return;
        }
    }
}

Samsung S5

Unlike the Nexus 4, the Samsung S5 seems to lag behind the flash which causes a dark picture. As far as I can tell, turning on the hidden zero shutter lag parameter (in the safe manner described in the robust section) seems to have no ill effects on the following devices: Nexus 4, Nexus 5, Samsung S3, Samsung S4, Samsung Galaxy Tab S (SM-T700).

Turn on Zero Shutter Lag

Try setting the following hidden camera parameter, which seems to solve the problem on my S5.

Camera.Parameters params = camera.getParameters();
params.set("zsl", "on");
camera.setParameters(params);

More Robust Solution

If the solution above works, I'm using a slightly more robust way to detect when the zsl parameter is available:

// dummy method, replace with whatever sets up camera parameters
public void onCameraOpened(Camera camera) {
    Camera.Parameters params = camera.getParameters();
    setHiddenParameter(params, "zsl-values", "zsl", "on");
    camera.setParameters(params);
}

public static void setHiddenParameter(Camera.Parameters params, String values_key, String key, String value) {
    if (params.get(key) == null) {
        return;
    }

    String possible_values_str = params.get(values_key);
    if (possible_values_str == null) {
        return;
    }

    String[] possible_values = possible_values_str.split(",");
    for (String possible : possible_values) {
        if (possible.equals(value)) {
            params.set(key, value);
            return;
        }
    }
}

Explanations

This part is only here to document the rabbit hole to find this parameter, hopefully someone that knows more than me can expand on this.

Symptoms:

  • On the Samsung S5, taking pictures in extremely dark conditions with the flash set to FLASH_MODE_ON or FLASH_MODE_AUTO leads to dark or completely black photos.
  • This does not seem to happen on any other device I have tested (Nexus 4, Nexus 5, Samsung S3, Samsung S4)
  • If I take pictures standing close to the objects (~3 ft) in a completely dark room, I get a extremely dark picture with only a few things visible.
  • If I take pictures in front of an open space (>5 ft) in a completely dark room, I get a completely black picture.

The first thing I tried was messing with focus related settings, reasoning that the open space would cause the focus to take longer, thus messing with the timing of taking the picture with the flash. Neither FOCUS_MODE_AUTO nor FOCUS_MODE_CONTINUOUS_PICTURE seemed to help the situation.

I also tried locking the auto-exposure and auto-whitebalance adjustments before calling camera.takePicture(...) to make sure those process weren't throwing the flash timing off, but that did not seem to help either.

It still felt like a timing issue though, so I started comparing the difference in parameters between the parameters my app was using vs. the native camera app.

Native Camera

12-10 15:49:08.659: W/QCameraParameters(265): [FW_DBG] setFirmwareMode: none
12-10 15:49:08.659: W/QCameraParameters(265): [PARM_DBG] Requested preview size 1920 x 1080
12-10 15:49:08.659: W/QCameraParameters(265): [PARM_DBG] dualrecording-hint : 0 m_FaceAE=1 Camera ID=0
12-10 15:49:08.659: W/QCameraParameters(265): [PARM_DBG] Requested video size 1920 x 1080
12-10 15:49:08.659: W/QCameraParameters(265): [PARM_DBG] Requested picture size 2048 x 1152
12-10 15:49:08.659: W/QCameraParameters(265): [PARM_DBG] Requested FOV 62.000000
12-10 15:49:08.659: W/QCameraParameters(265): [PARM_DBG] requested jpeg thumbnail size 512 x 288
12-10 15:49:08.659: W/QCameraParameters(265): [PARM_DBG] set optimal jpeg thumbnail size 512 x 288
12-10 15:49:08.659: W/QCameraParameters(265): [PARM_DBG] rotation val = 90
12-10 15:49:08.659: W/QCameraParameters(265): [PARM_DBG] m_bNoDisplayMode = 0
12-10 15:49:08.659: W/QCameraParameters(265): setZslMode : m_nDualMode=0, mHdrMode=0, mTakeLowlight=0, m_bRecordingHint=0, mAutoLLS=0, m_nDualRecordingHint=0
12-10 15:49:08.659: W/QCameraParameters(265): [PARM_DBG] ZSL = ON
12-10 15:49:08.659: I/QCameraParameters(265): [PARM_DBG] Requested FpsRange Values:(15000, 30000)
12-10 15:49:08.659: W/QCameraParameters(265): [PARM_DBG] flash mode = on
12-10 15:49:08.659: W/QCameraParameters(265): [PARM_DBG] AEC lock = false
12-10 15:49:08.659: W/QCameraParameters(265): [PARM_DBG] AWB lock = false
12-10 15:49:08.659: W/QCameraParameters(265): [PARM_DBG] mHdrMode 0 mTakeLowlight 0
12-10 15:49:08.659: E/QCameraParameters(265): SAMSUNG APPS HDR MODE
12-10 15:49:08.659: W/QCameraParameters(265): [PARM_DBG] live snapshot size 2048 x 1152
12-10 15:49:08.659: E/QCameraParameters(265): [syscamera][setRthdrModes::2831][str::off][prev_str::off]
12-10 15:49:08.659: E/QCameraParameters(265): [syscamera][setPafModes::2863][str::on][prev_str::on]
12-10 15:49:08.659: E/QCameraParameters(265): [syscamera][setDrcModes::2891][str::on][prev_str::on]
12-10 15:49:08.659: W/QCameraParameters(265): updateParameters : X - mCameraId=0, final_rc=0, line=4465
12-10 15:49:08.659: W/QCameraParameters(265): [PARM_DBG] setNumOfSnapshot : nBurstNum = 1, nExpnum = 1

My App

12-10 15:48:33.109: W/QCameraParameters(265): [PARM_DBG] Requested preview size 1920 x 1080
12-10 15:48:33.109: W/QCameraParameters(265): [PARM_DBG] dualrecording-hint : 0 m_FaceAE=1 Camera ID=0
12-10 15:48:33.109: W/QCameraParameters(265): [PARM_DBG] Requested video size 1920 x 1080
12-10 15:48:33.109: W/QCameraParameters(265): [PARM_DBG] Requested picture size 2048 x 1152
12-10 15:48:33.109: W/QCameraParameters(265): [PARM_DBG] Requested FOV 62.000000
12-10 15:48:33.109: W/QCameraParameters(265): [PARM_DBG] requested jpeg thumbnail size 512 x 288
12-10 15:48:33.109: W/QCameraParameters(265): [PARM_DBG] set optimal jpeg thumbnail size 512 x 288
12-10 15:48:33.109: W/QCameraParameters(265): [PARM_DBG] m_bNoDisplayMode = 0
12-10 15:48:33.109: W/QCameraParameters(265): [PARM_DBG] ZSL = off
12-10 15:48:33.109: I/QCameraParameters(265): [PARM_DBG] Requested FpsRange Values:(10000, 30000)
12-10 15:48:33.109: W/QCameraParameters(265): [PARM_DBG] flash mode = on
12-10 15:48:33.109: W/QCameraParameters(265): [PARM_DBG] AEC lock = false
12-10 15:48:33.109: W/QCameraParameters(265): [PARM_DBG] AWB lock = false
12-10 15:48:33.109: W/QCameraParameters(265): [PARM_DBG] mHdrMode 0 mTakeLowlight 0
12-10 15:48:33.109: W/QCameraParameters(265): [PARM_DBG] live snapshot size 2048 x 1152
12-10 15:48:33.109: E/QCameraParameters(265): [syscamera][setPafModes::2863][str::off][prev_str::off]
12-10 15:48:33.109: E/QCameraParameters(265): [syscamera][setDrcModes::2891][str::off][prev_str::off]
12-10 15:48:33.109: W/QCameraParameters(265): updateParameters : X - mCameraId=0, final_rc=0, line=4465
12-10 15:48:33.109: W/QCameraParameters(265): [PARM_DBG] setNumOfSnapshot : nBurstNum = 1, nExpnum = 1

Native vs. My App

The AEC (auto exposure) and AWB (white balance) lines are the same, so that's consistent with what I've tried before. The one difference is the ZSL parameter, which I've never heard of before.

Googling for ZSL finds this SO answer:

To achieve zero shutter lag, the camera driver must maintain a small circular buffer pool containing full resolution frames. Images are captured at sensor rate and are sent to preview and to the circular buffer pool (either as raw Bayer or as processed/semi-processed YUV). When the use presses the shutter, the newest buffer in the circular pool is extracted, processed and compressed as JPEG. On older mobile phone cameras, the sensor is not able to capture full resolution frames at a high enough frame rate, and therefore ZSL cannot be implemented.

So it seems like the shutter lag causes a timing mismatch between when the flash fires and when the picture is captured. Turning on ZSL seems to eliminate the issue entirely. It should probably be on by default given that flash behaviour is broken without it, but I'm not going to hold my breath on that one.

Community
  • 1
  • 1
rraval
  • 1,007
  • 1
  • 9
  • 11
  • I think this is what i am experiencing. See my question http://stackoverflow.com/questions/27277650/ When i add the secret parameter for the sg5 however my preview screen breaks. (the camera doesn't pause onPictureTaken) did this happen to you? thanks for the tip! – BBaker Jan 14 '15 at 17:50
  • 1
    Also.. this was happening to me when using FLASH_MODE_TORCH. It affected my auto focus as well as overall brightness(because it wouldn't auto focus) on my sg5. Not so on Nexus 5 but still had the delay in actual image saved vs on screen preview pause. – BBaker Jan 15 '15 at 16:43
  • I have some users reporting a broken black screen, but I haven't been able to nail it down. Could you describe the problems you're running into? Also, googling around found this patch which talks about manually stopping the preview in ZSL mode: http://review.cyanogenmod.org/#/c/45730/ – rraval Jan 15 '15 at 18:42
  • 1
    No issue with black screens. My camera app calls for FLASH_MODE_TORCH to be on the whole time and for images to be close up. Before using the zsl param i was unable to get the sg5 to focus up close.. it would act like it was focussing but skip the clear image and stop at a blurry spot. My images appeared dark even with torch mode on, very frustrating. ALL of that was fixed AND the issue I was facing.. ( the delay between the button click and the actual image taken was so long i often got blurred movement pictures as the user moved away from the taken pic) thanks again rraval! – BBaker Jan 16 '15 at 17:20
  • @BBaker - I have the same issue you were having. ZSL fixed my focus mode with the flash mode turned ON. But I can't get FLASH_MODE_TORCH to set the torch ON for the Samsung Galaxy S5 model SM-G900W8. We found a post where Samsung Support replied that for the S5 torch mode is not publicly available! How are you able to get the torch to come on? I have posted a question here: http://stackoverflow.com/q/28160616/1735836 – Patricia Jan 27 '15 at 18:02
  • Great info! rraval! Are you able to set the flash mode to FLASH_MODE_TORCH and get the torch to light up on the S5? I have posted a question here: http://stackoverflow.com/q/28160616/1735836 – Patricia Jan 27 '15 at 18:05
  • @Lucy I copied and pasted my working code on the question you asked.. hope it helps. – BBaker Jan 28 '15 at 18:22
  • Hello @BBaker - I am trying to take close-up photos using an sg5 while keeping the torch on. It takes the photo automatically after autofocus finishes. I tried using ZSL on but my photo gets a stuck at a blury spot like in your case. Can you please share the code that worked for you? Thank you. – Constantin Georgiu Jul 14 '16 at 12:32
  • @ConstantinGeorgiu see the link listed above for my code. It's been too long and I don't have a copy of the production code anymore. Good luck. – BBaker Jul 15 '16 at 18:46
0

I solved it on my samsung galaxy S5. I have oppened camera, setting (top left) and turned everything off except the flash. Now it takes pics when it flashes (not after it flashes). Pictures are clear and lit. For more info here is my setting which came in automaticaly after I have turned everything off. 16M Picture size 5312X2988 Burst shots Off Low-light detection Off Face detection Off ISD AUTO ISO Auto Metering modes Center-weighted Tap to take pics off Selective focus off Effects No effects flash on timer off hdr (rich tone) off Metering Modes Center weighted

Arpi
  • 1