www.flickr.com

8.2.09

Dissecting Panasonic RW2 files

I mentioned in an earlier post that I was intending to go to the bottom of certain rumors about Panasonic including lens defect correction data in the EXIF information of RW2 files. A number of commercial photo software programs are known to manipulate the RAW image data to remove geometry distortion, chromatic aberration and vignetting silently, which lead to enthusiastic reviews posted on certain digital photography sites about the quality of the Lumix G1 kit lens. However, I know from developing my RAW files with ufraw and digikam that the kit lense has a significant barrel distortion at short focal lengths.

One way to automatically correct those distortions is collecting correction data in a database like PTLens and Lensfun. The photo software knows what corrections to apply to images taken by a certain camera with a certain lens at a certain focal length. That approach however requires significant effort for maintaining the database plus you will always be playing catch up with the camera manufacturer developing new lenses. Not an issue for independent open source efforts, we've been running after information from vendors ever since, but not a good situation for the camera vendor. Unless he runs after the software companies to update their databases whenever he releases a new lens, images developed from his cameras RAW files will be not optimal. I would not want that, especially not if I wanted to reduce development cost and retail price for new products.

Panasonic most likely went the second way, which is having software makers implement the same correction algorithms they use in their cameras and embedding the necessary correction parameters inside the photos meta data. Doing it that way allows for lesser synchronization effort between Panasonic and software vendors and faster time to market. With some effort it might be possible to use this correction data also in open source software.

That being said, there's now a couple of tasks to be done until the correction data can be used:
  1. find out what information is stored, and where
  2. reverse engineer the format of the correction parameters
  3. understand how it's applied to image data
  4. proof of concept implementation
I believe I've made some progress today on 1.), finding out what information is stored and where. I inspected some of my RW2 files to see what Exif tags they contain and found a couple of tags that are not decoded by exiftool or exiv2. They just contain some data bytes in unspecified format. I noticed that they seem to vary from file to file and decided to find out if I could reproduce the values.

Reverse engineering is a black box approach. In our case the camera is the black box, inputs are the controls like aperture, focal length, exposure program etc, output are the generated RW2 files. You cannot observe the inner workings of the black box other than by observing differences in the output when making modifications to the input. It definitely helps if you can make an educated guess about the inner workings of the black box. For geometry correction, I know a bit about how its corrected, so that is my first target.

I know that geometry distortion depends on the focal length, so I made a couple of shots with the kit lens at 14mm and 45mm, two at each. Then I looked at the Exif data and found one tag, "Exif.PanasonicRaw.0x0119", where the data did not change for images taken at 14mm, but changed significantly when going to 45mm.

14mm:
84 236 201 47 38 0 0 0 43 1 0 0 141 1 1 0 208 14 238 1 86 2 2 252 196 9 226 3 228 72 36 134

45mm:
152 94 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 86 2 0 0 196 9 0 0 35 234 24 155
Looking at the data, you see something interesting - a lot of Zeros appearing at 45mm. Nothing changes from 45mm to 35mm, which looks like this:

35mm:
161 54 43 194 51 0 0 0 0 0 0 0 0 0 1 0 42 0 1 0 86 2 1 0 196 9 245 1 176 16 17 65
Still a lot of Zeros, but lesser. What does this tell us? Now, I know that the geometry of the lens is almost perfect at 45mm, so I expect that there is less correction necessary. It's reasonable to assume that some parameters of the correction formula will become very small, or zero. The data in the Exif tag apparently follows our expectations. I also assume that the data is not encrypted.

The next task is now to find out how the data is formatted. Most likely these parameters are rational numbers. What I don't know yet is the representation. Is it 16, 32 or 64 bit per coefficient? Am I looking at fixed or floating point numbers, little or big endian? Does this tag only contain correction parameters for geometry, or also for chromatic aberration? The tag contains 32 bytes, so it's either 16, 8, or 4 coefficients. I'll have to do some research on geometry correction, maybe Panasonic uses something that is public domain.

It looks like a prominent method of correcting lens geometry is based on Zernike polynomials. The PanoTools lens model uses polynomials as well. One property of polynomials is that you can use as many parameters as you like, it just depends on the order of the polynomial. It's merely a question of computing power available. I could start with a 2nd or 4th order polynomial like the PanoTools model and try to match the tag information with coefficients computed by Hugin.

Success: Sony Vaio VGN-Z21 3G modem with Linux!

I'm happy to report that my hack to the sony-laptop kernel module works. We were able yesterday to make the first UMTS data connection with my wifes' Z21, using HSOconnect on openSUSE 11.1. Her detailed description of installing openSUSE 11.1 on the Z21 can be found here, you can also download the source code of the sony-laptop.ko. It's a very rough first version, don't expect packages or inclusion into mainline kernels soon. Still, it gets you where you want.

Loading the module will generate a new file /sys/devices/platform/sony-laptop/snc_wwanpower, you can switch the modem power with "echo 1" and "echo 0".

I'm still working on the graphic card problem, hopefully I'll have a solution soon.

1.2.09

Sony Vaio Z21 DSDT fun

My wife urged me today to work on her new Sony Vaio Z21, which is, as anyone able to use Google will know, not particularly well supported by any recent Linux distribution. This is not exactly due to the completely fancy hardware components, rather by the completely undocumented methods of how to switch them on and off.

As an example, the Z21 has a builtin 3G modem, an Option Globetrotter, which is connected to an internal PCIe slot, which means it should just show up on the USB bus. Unfortunately it does not, not under Linux at least. The reason is that Sony chose to switch the modems power supply through an embedded controller chip on the motherboard. This embedded controller is nonstandard and therefore not managed through standard ACPI methods you would find under /proc/acpi, however there is a small kernel module, sony-laptop.ko, which provides an interface to some of the Sony proprietary device functions. The Z21 is unfortunately not supported yet by this module.

Well, it was not difficult to make the module detect the Z21, but the fun just started at this point: None of the functions provided by this module worked. Nada. Zero. OK. Turned out that while the Z21 contains the same "Sony Notebook Controller" as other Vaios, it did not react to any of the known ACPI method calls. So, I started looking deeper into the DSDT. I had never done that in depth before, but looking at the decompiled DSDT ASL, knowing that the DSDT is really not a table but rather byte code, it wasn't difficult to understand that the "SN07" method of "SNC" device was the key to switching the modem on and off. After traversing several levels of If/Else statements I found that calling "SN07" with 0x9f070803 as argument switches on the 3G modem, while 0x00000803 turns it off again.

Unfortunately this is not the end of the story. While the modem is now accessible via USB and even recognized by the hso.ko driver module, and even while we're able to talk AT commands via ttyHS0, we have yet to make the first data connection.

The biggest challenge will however be to understand the weird inner workings of the graphics adapters. The Z21 has two of them, an Intel GM45, and and some Nvidia with a name that I currently cannot remember. Under Vista you can dynamically switch between them, and unfortunately the BIOS lacks any preset, so when you cold boot into Linux, both of them are active which completey confuses the drivers and disables direct rendering. I know the answer is somewhere inside the DSDT devices and methods, but it's hard to understand this from reading the disassembled bytecode, without comments or sensible variable names.

26.1.09

Digital photography, a new passion..


Ready!
Originally uploaded by thinkfat
Since we got our new digital camera I have been using it quite regularly and I got very much interested again in digital photography and everything around it. I used to shoot lots of photos when I inherited my grandfathers Cosina SLR, despite the tedious act of having the film developed and paying for prints just to throw lots of them away.

I don't quite remember why I never picked up a digital SLR camera when they became fashionable, but they were quite expensive back then and anyway I spent most of my money (and most of my time) on amateur radio equipment. Today the situation has changed. DSLR cameras today are mass market products, not just for photography enthusiasts.

So, I familiarized with the Lumix G1 quickly and today I carry it with me almost constantly. The photo in this blog post links back to my flickr account, you're welcome to have a look at some results of my early ventures into digital photography.

Interestingly, this camera got me back to KDE programming again. Of course I started using various 'K' programs like KPhotoAlbum or DigiKam to keep track of my growing collection. And sure enough, once you start using a 'K' program, you find lots of small annoyances that demand fixing. So I hacked kflickr to upload resized pictures with an adjustable quality instead of some default value, digikam to recognize the lens description of the Lumix G1, the flickr export plugin to allow uploading to the photostream only instead of requiring a set and I'm now trying to automatize lens defect correction using information embedded in the RW2 files this camera generates when shooting 'RAW'.

25.1.09

First motobike trip of the year


p1020151.jpeg
Originally uploaded by thinkfat
If the motorbike virus has you, somehow it's not a question of convenience any more to go for a quick ride or not. So right after lunch today we took out our bikes for the first time this year. It was sure a bit chilly still at 5°C but with the right clothing it was bearable. We drove up to Neunkirchen, had a coffee and apple pie and went back home again.

I also took the opportunity to see if the camera setup I envisioned for our summer vacations would work out, and I'm happy to report that the Lumix G1 fits nicely into the tank pack as planned and is easy enough to operate while on the bike.

I also experimented with the geotagging feature of digikam, which worked quite nicely. I downloaded the trip log from my GPS after the ride and told digikam to correlate the images I had taken. It added a set of tags to the EXIF information that show the location where the photo was taken - well, to be precise, the location where the GPS receiver was when the photo was taken, but since it's mounted on the bike, that's not going to be too far off.

Now if I only could get flickr to consistenly import the location data. It's working only sometimes and I don't know why.