CRI Radio

Apr 23, 2007

jPhoto

Java USB Camera Tools

http://jphoto.sourceforge.net/

About jPhoto

This project produces and supports GPL'd camera software such as:

  • Command Line camera access tools (follow link at left) using JITted classfiles or conventional GCJ executables;
  • Protocol libraries, initially PTP over USB (see Javadoc and PTP links at left), usable from Java or, with GCJ/CNI, from C/C++
  • ... more as contributed. User Interface support is on the wishlist, preferably using Free Java.

The software runs on recent USB-enabled GNU/Linux OS distributions, such as RedHat 7. For more information, see the "Requirements" link from the jUSB Project link at the left. Distributions dated before mid-year 2000 need updates for at least kernel and modutils; and possibly the C runtime threading support for distributions before early 2000.

This software works with a variety of cameras, including:

  • Kodak ... DC-4800, MC3; "the whole DX line" including: DX-3215, DX-3500, DX-3600, DX-3700, DX-3900
  • Sony ... DSC-P5 and DSC-F707 (turn the switch to "PTP" mode, otherwise you'll need to use the usb-storage kernel driver and mount a filesystem; and there see to be some camera firmware bugs preventing all PTP commands from working)
  • Hewlett-Packard ... PhotoSmart 318
  • Canon ... Powershot A70

PTP cameras from other vendors are in the works. If you need "capture" capability, taking pictures under program control, the DC-4800 has good support for this, but not all other cameras do. In particular, not all of the DX line does.

If you use a camera without a CF card (internal memory only) you'll want the CVS version of this software.

If you want to see the picture metadata from EXIF headers (time picture was taken, f/2.8 at 1/250 second, etc) look at the jhead program in the links section.

News, 4 August: The GCJ distribution in the SuSE 7.2 release has a different version of GCJ and "libgcj.so" (GCJ 2.95.2 and libgcj.so.0) than RedHat 7.x (GCJ 2.96rh and libgcj.so.1). So the RPM won't work on SuSE, since it uses that version of GCJ. Neither will it build there using that old version of GCJ, since that it doesn't support basics like inner classes. Get the "jphoto-0.3.6.tgz" tar file and use a JDK.

Also, the HotSync instructions can't work out of the box on SuSE. Until SuSE provides hotplugging RPMs, you will need to get the Linux Hotplug package (see the link from the HotSync page) and probably disable the "usbmgr" software bundled with SuSE.

This binary portability problem should vanish when the RPM can rely on GCJ 3.x installation everywhere. If you try building with GCJ 3.0, you'll notice that the name mangling has changed, so if you're using the latest GCC distribution with the Source RPM you will need to modify the Makefile's linking instructions appropriately.

News, 21 May: Kodak has two more PTP cameras out, the DX-3500 and DX-3600. CVS has MC3 related updates to let you download the QuickTime videos like other images, and work with storage that's not present (like a DX-3500 without an add-on CF card).

Note that kernels 2.4.3 and 2.4.4 don't handle usbdevfs "mount" options (which help when running without root privileges, like devmode=0666) correctly, but this is fixed in the 2.4.5 kernel.

News, 13 February: The new Kodak MC3 camera seems to work with jPhoto 0.3.6; no updates needed for photo support, though MP3 and video formats need them.

News, 22 November: If you're running RedHat 7, you may be interested in a conventional executable for jPhoto, build with the GNU "libgcj" JVM. It's available as an RPM; you'll need the "libgcj" RPM (from the second distribution CD).

News, 20 November: New release: jPhoto 0.3.5 has the "capture" command, and matches jUSB 0.4.2 API updates.

Command Line

Your version may support more commands than are shown here. Only the basic commands have examples. See the source code to the JPhoto class for more information; it currently only uses a PTP (over USB) device access library.

bash$ jphoto
Usage: jphoto command [options]
Key commands include:
cameras ... lists devices by portid
capture ... starts image/object capture
devinfo ... shows device info
devprops ... shows all device properties
images ... download images to directory (default 'images')
storage ... shows storage info
thumbs ... download thumbs to directory (default 'thumbs')
tree ... lists storage contents
Other commands include:
devices ... (same as 'cameras')
getprop propname ... shows one device property
help ... shows this message
powerdown ... powers down device
selftest ... runs basic selftest
status ... status summary
Options include:
--camera value (or, -c value)
--directory value (or, -d value)
--help (or, -h)
--storage value (or, -s value)
Documentation and Copyright at: http://jphoto.sourceforge.net/
Licensed under the GNU General Public License.
No Warranty.

bash$

Hot Syncing

You can get a "docking cradle" for various Kodak cameras; the idea is similar to the cradle most PDAs have. It turns out that it's easy to make these sync up automatically when you connect. The same setup works even if you don't use that cradle, any PTP camera will be just as happy.

If you have current-enough versions of the Linux Hotplug scripts (in early April 2001, that means "latest from CVS), you can arrange to automatically download images from your camera when you plug it in to your GNU/Linux system. You'll have to update two things, currently by hand. And this isn't something you should do on a system shared with other users, for obvious reasons!

First, you'll need to update the /etc/hotplug/usb.usermap file to tell it to invoke a /etc/hotplug/usb/jphoto script when it sees a PTP camera. Be careful you copy this exactly as shown here; if you drop a number, or add extra lines, it won't work right. (And the current "usbmodules" doesn't like comment syntax either!)

#
# USB-IF "Still Imaging Class" interface (6/1/1) -- for all future PTP devices
#
jphoto 0x380 0 0 0 0 0 0 0 6 1 1 0
#
# Kodak DC-4800 (0160, predates 6/1/1) and DC-240 firmware prototype (0x121)
#
jphoto 0x03 0x040a 0x0160 0 0 0 0 0 0 0 0 0
jphoto 0x03 0x040a 0x0121 0 0 0 0 0 0 0 0 0

Second, you'll need to provide that /etc/hotplug/usb/jphoto script! This one should do the job, if you only connect one PTP camera at a time. (Currently, you need the CVS version to use /proc/bus/usb/BBB/DDD paths as --camera specifiers.) Note that this could be extended to do different things based on $PRODUCT or other hotplug parameters.

#!/bin/sh

# if present, images are automatically downloaded
# CUSTOMIZE THIS
DOWNLOAD=/root/jphoto-images

# where jPhoto executable (or modified script) is installed
JPHOTO=/usr/bin/jphoto

# maybe download images, videos, ... mp3s
if [ -d $DOWNLOAD ]; then
cd $DOWNLOAD
(echo '*** '$(date); $JPHOTO images --camera $DEVICE --directory .; echo ') \
>> images.$(date '+%Y-%m.%d')
fi

Then, whenever you connect your camera to your GNU/Linux system using USB, its pictures (and videos) will automatically "hot sync" to your specified directory. They won't overwrite files of the same name that are already there. Look at each day's log file to make sure you got the files you expected, and then file the pictures as appropriate.

Use standard Free Software GUI utilities such as kview or ee to browse the images, and ones like gimp to edit and save them. Programs like jhead can help you maintain EXIF metadata, such as camera settings and when you took the pictures.

Links

General background information includes:

GNOME and Free Java resources:

Some Java Imaging resources:

Some digital photography resources:

Linux-oriented digital photography:

  • The Gimp akin to a Linux digital darkroom
  • GNU/Linux PTP related resources
  • Linux-USB guide has a section on Digital Still Cameras
  • gPhoto camera tools (gphoto2 supports PTP in C)
  • gPhoto2 camera libraries (no PTP; more USB support; libraries only, gui separate)
  • Open Digita Services commandline tools for Digita-based cameras (works with USB)
  • For QuickTime support on Linux, you can use Basilisk II/JIT to emulate an M68K and then run Apple's M68K QuickTime viewer. Needs ROM images from an M68K Mac though.