Camera - Manual Focus

Search This thread

hypest

Retired Recognized Developer
Feb 1, 2008
235
4
Thessaloniki
Hello devs!

I wonder if anyone is interested in/capable of implementing a manual focus feature in android, at least for G1. Hardware-wise, I think it is probably feasible since (the great dev) DZO has already done it for the Kaiser (and I have seen it in action)!

CLARIFICATION EDIT: by Manual Focus I mean controlling the focal length, not just triggering the autofocus. For example, on the Kaiser, dzo has mapped the up/down side-wheel to focus-farther/focus-nearer!

See here the source code commit.

It would be great if the implementation introduced a relevant Java-level API, or extent the current Camera API.

My idea is to use this feature to fix-focus the camera, just a few centimeters away and make barcode scanning faster, not relying so much on auto-focusing. But I'm sure that there are plenty more useful stuff that can be done with manual focus (e.g. inspiring/artistic photo captures).

I'm rather new in android-dev and not experienced enough (yet) to work on the below-Java space, that's why I'm kindly asking for someone else to have a look at it :)

any thoughts?

have fun,
hypest
 
Last edited:

Geniusdog254

Retired Recognized Developer
Jan 2, 2009
1,110
169
St. Louis
No, but it's not in my pocket most or all of the time, either. In a pinch, between 3Mpixel and 0Mpixel, the photographer will usually choose the former.

Yeah exactly. I love my dSLR to death, but I can't always have that beast with me. My phone is ALWAYS with me. I would a lot rather take a quick shot with it than no shot at all.

To the OP. Look in the android source repo at the camera code. Or is the G1 camera drivers in the closed source area? I know the actual camera driver is (thats why 2.X didnt have a camera at first) but is the AF code there too?
 
Last edited:

Meltus

Senior Member
Jan 11, 2009
1,903
1,023
Manchester
www.androidaudiohacks.com
As the phone has auto focus i see no reason why manual focus couldn't be coded in.
In fact, i'm surprised no one has done it yet. I remember it being done on my old LG Viewty (that had a fantastic camera) and my SE k750i and was great for the really close up shots that the auto focus can't normally achieve. :)
 

Geniusdog254

Retired Recognized Developer
Jan 2, 2009
1,110
169
St. Louis
Ok I looked at the code. Here is the camera code for the MSM7xxx chips:

http://android.git.kernel.org/?p=pl...=libcamera/QualcommCameraHardware.cpp;hb=HEAD

http://android.git.kernel.org/?p=pl...;f=libcamera/QualcommCameraHardware.h;hb=HEAD

http://android.git.kernel.org/?p=pl...a=blob_plain;f=libcamera/camera_ifc.h;hb=HEAD

If you look at the first one, it does all its autofocus calls thru libqcamera. That is one of the proprietary HTC/Qualcomm drivers. Here is the code:

Code:
status_t QualcommCameraHardware::autoFocus(autofocus_callback af_cb,
                                               void *user)
    {
        LOGV("Starting auto focus.");
        Mutex::Autolock l(&mLock);
        Mutex::Autolock lock(&mStateLock);

        if (mCameraState != QCS_PREVIEW_IN_PROGRESS) {
            LOGE("Invalid camera state %s: expecting QCS_PREVIEW_IN_PROGRESS,"
                 " cannot start autofocus!",
                 getCameraStateStr(mCameraState));
            return INVALID_OPERATION;
        }

        if (mAutoFocusCallback != NULL) {
            LOGV("Auto focus is already in progress");
            return mAutoFocusCallback == af_cb ? NO_ERROR : INVALID_OPERATION;
        }

        mAutoFocusCallback = af_cb;
        mAutoFocusCallbackCookie = user;
        LINK_camera_start_focus(CAMERA_AUTO_FOCUS, camera_cb, this);
        return NO_ERROR;
    }

First off you can see its calling the QualcommCameraHardware library which is libqcamera and then the method autoFocus. I think this is a dead end.

However, for 2.X we reverse engineered the drivers since we didn't have them available. They are open source. We may be able to look at them and get how they use the AF code.
 

hypest

Retired Recognized Developer
Feb 1, 2008
235
4
Thessaloniki
Geniusdog254, thanx for sharing your thoughts, info and findings.

I'm assuming here: if the AF is done in software, even in proprietry drivers, it may indeed be possible to use it by RE it. Best case scenario would be to find functions lingering in there, waiting to be called :)

I'm wondering though, if the IOCTL's dzo is using are directly triggering hardware "switches", or are they handled in the drivers...

Could you please also share links to the open sourced 2.x driver?
 

marxmarv

Member
Oct 16, 2009
36
1
First off you can see its calling the QualcommCameraHardware library which is libqcamera and then the method autoFocus. I think this is a dead end.

Maybe not. I vaguely remember that the HTC camera app from CM 4.0 or 4.1 would allow you to switch between autofocus and infinity focus. Maybe that's a start?
 

hypest

Retired Recognized Developer
Feb 1, 2008
235
4
Thessaloniki
I found these symbols in the libqcamera.so on my CM g1 (and highlighted some interesting ones):

Code:
af_algo_config
af_algo_execution
af_algo_preview
af_check_aec_settled_cnt
[SIZE="5"][B]af_do_move_lens[/B][/SIZE]
af_done
af_do_process_exhaustive_search
af_do_process_hill_climbing
[SIZE="5"][B]af_do_reset_lens[/B][/SIZE]
af_do_safe_move
af_init_process_exhaustive_search
af_init_process_hill_climbing
af_is_active
[SIZE="5"][B]af_move_lens_to[/B][/SIZE]
af_process_focus_sensor
af_process_lens_move_done
af_process_start_focus
af_process_stats
af_read_process_type
af_read_sharpness
af_start_stats
af_stop_focus

seems to me that maybe there are suitable means for manipulating the lens/focus.

I've attached the whole readelf dump...
 

Attachments

  • libqcamera_so_readelf_output.zip
    12.8 KB · Views: 235

carnegie0107

Senior Member
Jul 26, 2009
403
6
Springytown
I think that if with proprietary drivers we can't manually move the hardware, perhaps we can indirectly trick it into focusing closer, thinking that it's "autofocusing" on a close object. Either one of these methods is a bit of a longshot with a proprietary driver, but they are both worth exploring. I'd LOVE to see some control over the focus of the camera, and if we can't do it with the AOSP code, let's look at Hero.... it offers significantly more focus control, with touch-to-focus. I haven't even glanced at the code there, though, so I have no idea. I'm just throwing thoughts at the wall in hopes that one of them will stick.
 

Geniusdog254

Retired Recognized Developer
Jan 2, 2009
1,110
169
St. Louis
Here is the code for the opensource, reverse engineered driver for eclair. Have it at, I may look & post my findings:

http://gitorious.org/eclair-camera-drivers

EDIT: Well of course I'm looking at it lol, I can't resist.

Look on line 345 of this page (they're numbered): http://gitorious.org/eclair-camera-...are_msm7k/blobs/master/libcamera/camera_ifc.h

CAMERA_PARM_FOCUS_STEP is defined. It sounds like a way to step the focus forward/backward but I don't know which way.

Also, there is a LOT of interesting things in here, including some that our hardware doesn't support, so take it with a grain of salt (it has flash & all kinds of stuff, pretty much a generic Qualcomm camera driver). Anyways, here are some of the interesting ones;

CAMERA_PARM_ISO, (duh)
CAMERA_PARM_APERTURE, (maybe change aperture speed for better shots?)
CAMERA_PARM_SHUTTER_SPEED, (better response time?)
CAMERA_PARM_HISTOGRAM, (not useful for me, but neat)
CAMERA_PARM_FPS_LIST, (this one is defined under a video section, maybe change frame rate??)

Neat huh? :)

Anyway, the really cool part is line 405-409:

typedef enum
{
CAMERA_AUTO_FOCUS,
CAMERA_MANUAL_FOCUS
} camera_focus_e_type;

Now I can't tell you what all this means, but I can read & tell you that that does say manual focus where it defines the options for focus type ;)

Also, ISO options are; MAX, HIGH, DEBLUR, 100, 200, 400, 800. There are also some WB settings that we don't have available, here is the full list; AUTO, CUSTOM, INCANDESCENT, FLUORESCENT, DAYLIGHT, CLOUDY_DAYLIGHT, TWILIGHT, SHADE, MAX_PLUS_1. Most of those are available in the 1.5 HTC based camera apps, but twilight & shade aren't.

Actually speaking of the HTC camera, it does almost EVERYTHING mentioned in this code. It misses a few of them, as I said, but it has debanding, WB, brightness. It is just missing the ISO (different from brightness, I promise).

This is about all I know, that its REALLY interesting to look through, and that we should make a camera app that can use all this :rolleyes:
 
Last edited:

Geniusdog254

Retired Recognized Developer
Jan 2, 2009
1,110
169
St. Louis
Also, just to say in my last post, I DO know what all of those camera terms mean, I'm a photo buff, I just put them in terms that apply to the G1 ;)
 

Geniusdog254

Retired Recognized Developer
Jan 2, 2009
1,110
169
St. Louis
Bump. Isn't there any other interest in this? I don't have the experience nor the time to do this, but I REALLY want it. I already looked at the code & did a writeup. Surely someone can do it...
 

hypest

Retired Recognized Developer
Feb 1, 2008
235
4
Thessaloniki
Bump. Isn't there any other interest in this? I don't have the experience nor the time to do this, but I REALLY want it. I already looked at the code & did a writeup. Surely someone can do it...

Hey Geniusdog254,

thanx for sharing your findings! I guess is just a matter of (spare) time. I'm personally (but slowly) trying to get into kernel building (and low-level dev in general) so to try these myself...

An already experienced and interested fellow dev would certainly help if he/she came forward :)
 

havikx

Senior Member
Feb 4, 2009
494
61
My only advice at this point is to change the title of the thread to [Think Tank] camera manual focus... you'll get more devs to glance at it.
 

Top Liked Posts

  • There are no posts matching your filters.
  • 2
    Hello devs!

    I wonder if anyone is interested in/capable of implementing a manual focus feature in android, at least for G1. Hardware-wise, I think it is probably feasible since (the great dev) DZO has already done it for the Kaiser (and I have seen it in action)!

    CLARIFICATION EDIT: by Manual Focus I mean controlling the focal length, not just triggering the autofocus. For example, on the Kaiser, dzo has mapped the up/down side-wheel to focus-farther/focus-nearer!

    See here the source code commit.

    It would be great if the implementation introduced a relevant Java-level API, or extent the current Camera API.

    My idea is to use this feature to fix-focus the camera, just a few centimeters away and make barcode scanning faster, not relying so much on auto-focusing. But I'm sure that there are plenty more useful stuff that can be done with manual focus (e.g. inspiring/artistic photo captures).

    I'm rather new in android-dev and not experienced enough (yet) to work on the below-Java space, that's why I'm kindly asking for someone else to have a look at it :)

    any thoughts?

    have fun,
    hypest
    1
    This would be awesome! Espcially for photographers like muah
    1
    in my stock LG GT540 rom ,i have an option to control the focus - it was working very well also but after the cynogen update i lost that feature and i'm trying to get that old ROM
    1
    This is one hell of a thread revival for what is now an old phone - does anyone know if there has been any progress, on any android phone or version, on being able to incrementally control a camera's focus?

    Thank you kindly!

    Sara
    1
    LOL!

    I think now.. most ROMS have that built in.. Hell i think its built into AOSP now.

    Hrm! I seem unable to find it though. Lots of point-to-focus but nothing incremental...