As an Android user, amateur photographer, and FOSS advocate, I've long wished for a fully FOSS imaging pipeline on Android. I often use my Android phone for photography. It's always on me and the camera hardware in them keeps getting better and better. There's been some great FOSS Android software improvements recently too. I've finally figured out a fully FOSS pipeline that can go from raw image capture right through to a final, processed image. This post is meant to share the pipeline I've discovered, and I hope it will be a guide for others who want to implement a similar imaging pipeline.
Capturing raw images on Android
This part is easy thanks to the really great Open Camera app. This is a truly great camera app, with many excellent capabilities. Most importantly to me, it is FOSS, offers manual exposure controls, and allows raw image capture in .dng format. To enable raw image capture, you must have a phone that implements the "Camera2 API". Here is a list of some phones that support this API. My phone is the Nexus 5x, and Open Camera raw capture works very well with it. To enable raw capture with Open Camera, open the settings (cogwheel icon), scroll down, and check "Use Camera2 API". Then, click the "Photo Settings" option, tap "RAW", and select "JPEG and DNG (RAW)". Now, you will save a jpeg and a .dng raw file of every image you shoot with the Open Camera app.
Developing raw images on Android
This has been the more difficult part of the problem to overcome. But I've recently solved this gap in large part thanks to the very cool FOSS app called Termux. Termux is a really brilliant solution to install a minimal Debian-based CLI Linux distro on Android without the need for root. Termux is really awesome, and includes many smart ways to interact with the terminal using your phone's hardware keys and onscreen keyboard. Read the help here to learn some of these shortcuts. They will be useful.
Now, what's really cool and useful for us is that you can install several of your favorite command line image processing tools, which the Temux project has precompiled for ARM processors and hosted for you in its apt repository. For us, the two important tools are dcraw and imagemagick. First things first, however. Install the Termux app on your phone, open a session, and type
apt update && apt upgrade. Then, install our two needed programs
apt install dcraw imagemagick. You now need to give Termux acess to your file storage by running the included script
termux-setup-storage. A little pop-up will appear asking if you want to give Termux permission to access your file storage. Accept this. Now, you can get to it with basic
cd commands. The main directory for Temux is
storage, and from there you can get to
storage\dcim\OpenCamera, where Open Camera will store all of the .dng raw files that you capture.
The raw development approach that I came up with relies on using your favorite hald CLUTs to alter the colors of your raw images to a final jpeg right from the command line. I use @patdavid's awesome film emulation hald CLUTs. I extracted just a few of my favorites to save space on my device. Using the great FOSS Amaze File Manager, I created a new directory inside the OpenCamera folder, which I named "haldCLUT." I extracted some of my favorite of Pat's hald CLUT's there, and I gave them new shorter names to make my CLI life a little easier.
OK, we now have our raw .dng's, our Termux Linux terminal set up, and our hald CLUTs in place. Here's the really fun part. You can go from raw to processed .dng in one easy command. Use
cd storage/dcim/OpenCamera to get to the base Open Camera directory, and then you can run:
dcraw -c my_raw_imag.dng | convert - haldCLUT/Kodachrome64.png -hald-clut output.jpg
Obviously, replace my made up file names with the real ones of your own files. What this does is to use dcraw to read in your .dng and do basic raw conversion which it sends to standard output (that's the
-c option). You pipe that over to imagemagick's
convert, which will read in the standard input (that's the first
- in that part). The second file name is the name of the hald CLUT you want to use to adjust the colors in your raw file.
convert will know this because of the
-hald-clut option you put in right after that. The last file name is the name you want for your output image.
To make your life easier, you can put this into a simple shell script, which you can save right in the OpenCamera directory. Here's what mine looks like:
dcraw -c $1 | convert - $2 -hald-clut $3
I called mine "filmsim.sh". Before you can run it, you have to have Termux adjust the shebang, so you should run
termux-fix-shebang filmsim.sh. This is necessary, so don't skip it. Now, you can run the script giving the .dng, the hald CLUT and the output file as inline arguments:
sh filmsim.sh my_raw_image.dng haldCLUT/Kodachrom64.png output.jpeg
It takes a minute, and then your final processed jpeg appears in the OpenCamera folder. Yippee!!
Here's a screenshot of me doing these commands:
Here's my processed image:
Here's the raw file used for the above: IMG_20170114_162311.dng (23.6 MB)
I hope this is helpful, and any suggestions for improvements or tweaks will be very much appreciated!
[EDITS for spelling, adding raw file, and resizing the screenshot]
[EDITS 2. Fixed for grammar and clarity]