Introducing Cheese

Posted 2007/04/29 09:51:36.

A lightweight cross platform replacement for Photo Studio.

In the last few months I've pretty much moved away from using Windows altogether, having developed a real liking for all things Mac and Unix. However the one thing I really miss about Windows is good old Photo Studio - sure it was clunky, buggy, and had a user interface very much stuck in the last century, but it did exactly what I wanted it to, in (more or less) exactly the way I wanted it to do it. That is, the job of getting pictures from my digital camera into a form where I could upload them to the web. I've tried several other applications on the Mac but none quite work in the way I want them to, so eventually I decided it was time to bring Photo Studio to OS X. Or at least write a new app that does something roughly similar. So there's two things I want to achieve:

First of all it has to be simple. I just don't have the hundreds of man hours to pour into a piece of software that I had back in the days when I was writing Photo Studio. Moreover I also felt Photo Studio had a UI that was in places far too over complicated - most of the time even I only used about 5% of it.

Secondly, I want something cross platform. I want something that runs on the Mac now, but should my dalliance with OS X not turn out to be a permanent thing, I want something I can also run on Windows.

So in the occasional bits of spare time I've had here and there over the past few months I've been working on a simple cross platform replaccement for Photo Studio, written using wxWidgets. It's not quite ready to release anything, but I can at least unveil the first screenshot. It isn't particularly earth-shattering, but I feel quietly proud of it nonetheless.

Currently it lets you view a directory of images as thumbnails, and as you step through it shows the currently focused image in full on the right hand side of the main window. In addition it'll display comments as you go, and let you edit them. Finally, although it's probably not apparent from the screenshot, it lets you do lossless rotation of your images.

The latter bit is the feature I'm most pleased with right now - while rotation for the main image is handled by the excellent libjpeg there's always the thorny issue of what do with the embedded thumbnail images in the EXIF data (which your digital camera writes in for fast previewing on the camera).

Given that Cheese also uses the embedded thumbnail to quickly browse a directory of images, it would quickly get frustrating if the main image had been rotated but the thumbnail had not. Unfortunately the format of the EXIF data in which the thumbnail is contained is not all that straightforward - effectively a TIFF file with a spaghetti of references from one place to another. If in the process of rotating the embedded thumbnail the image data changes size (which given the way JPEGs work is often the case) then you'd potentially end up overwriting other bits of the EXIF data, which could make all your precious camera settings (and whatever other meta data is in there) unreadable.

In Photo Studio I had spent ages writing some fairly complex code to allow restructuring of the EXIF data, to let you change the size of components (such as thumbnails) therein. It was never quite perfect though - each manufacturer would typically write their own block of camera specific data as part of the EXIF header, and the format of this varied. Again, because of the use of references, trying to move this data around without fully understanding it would generally lead to corrupt files. Whilst I was able to get sample images for most of the major manufacturers, there was always the chance that some minor manufactuer might do things differently, or even that a major manufacturer might change their format. The EXIF standard recommends that EXIF data be effectively treated as read-only for this reason.

So in Cheese I set out to have the embedded thumbnail file rotated, but kept at the same point in the EXIF data and with the same size. The solution to this is a bit hacky, but I think it is probably the safest possible approach.

First, Cheese decodes the thumbnail to a bitmap and rotates it lossily - generally speaking preserving the quality of a thumbnail doesn't matter that much, as it is only there for previewing, and could always be regenerated from the main image if necessary.

Next - and here's the cunning bit - it takes advantage of the JPEG quality setting and some intelligent trial and error. Libjpeg lets you specify a quality for the JPEGs you are saving, on a scale of 0 to 100. Zero is the poorest quality (and therefore smallest file), and correspondingly 100 gives the best quality (but the largest file size). There isn't, however, a function to tell you what the file size is going to be based on the quality setting, or indeed a function which lets you set the quality based on an intended file size. So I wrote it - it's our old friend the binary search. It basically saves the JPEG file in memory several times until it determines the quality setting which gives us the output file size closest to the original. Whilst this might sound a bit inefficient, thumbnails are by definition small files (typically 160x120) so saving them is a relatively inexpensive operation. Plus the laws of binary search mean that generally speaking we shouldn't have to make more than log to the base 2 of 100 attempts - which comes at out 7.

The above technique isn't likely to get an exact match - so what we actually aim for is the highest quality that will deliver a file smaller than the target size. Then the final bit of trickery is to use the JPEG comment field to pad the file out to exactly the size we want - given that the comment is part of the JPEG standard, any compliant reader should be able to skip over it harmlessly.

All that remains now to cover the basic functionality is generation of HTML pages, so with any luck version 1.0 ought to be ready for release within a few weeks.

Comment 1

As someone who is restricted in programming to something like 10 PRINT "HELLO"
20 GOTO 10
(well, almost!!!) this is all way over my head, but it is fascinating when you think just how much work, knowledge and thought goes into programs which we all use without a second thought. I think Photo Studio is a great program, it has certainly saved me a lot of time in picture processing for my "family and friends" online photo journal, and I am looking forward to seeing more of Cheese, John!

Posted by Bryan at 2007/04/30 00:04:03.

Comment 2

Good man! I'll go and download a copy now...

Posted by tom at 2007/07/17 13:54:18.

Comment 3

I chanced upon your site after some Googling on EXIF. I'm a Linux user and am glad you're now on the Unix side of things. Thanks very much for taking the time to explain the challenges you are presented with and your approach to coming up with solutions. It was an interesting read.

Posted by Paul at 2007/07/28 05:28:52.

Comment 4

Hola mardena!

Posted by AnferTuto at 2007/08/03 16:18:44.

Comment 5

not exactly what I'm looking for (rather need a php based one for playing with it) - however, thanks a million for taking time and explaining about the Exif/Thumbs issue. cheers !

Posted by lorenzo at 2007/08/28 00:31:24.

Comment 6

That's a rather neat solution, well done!

Posted by steve at 2007/11/27 11:04:03.

Comment 7

Do comments still work?

Posted by John at 2008/07/22 17:58:06.

Comment 8

good site dude

Posted by Mzvwibzn at 2008/08/01 01:13:15.

Comment 9

Cool site, lesbian pics , %-PP,

Posted by Onexbvsd at 2008/08/02 12:05:08.

Comment 10


Posted by uUPonHGimCZjMS at 2008/08/03 12:17:08.

Comment 11

Candidates Promise National-Service Initiatives

Posted by mona at 2008/09/12 15:38:10.

Comment 12

Has Obama Underestimated McCain?

Posted by lola at 2008/09/12 20:29:59.

Comment 13

great site thanks see u

Posted by bobby at 2008/09/24 01:25:41.

Comment 14


Posted by name at 2008/11/20 00:36:05.

Comment 15


Posted by name at 2008/11/20 11:03:07.

Comment 16


Posted by name at 2008/11/20 13:24:01.

Comment 17


Posted by name at 2008/11/20 20:01:05.

Comment 18


Posted by name at 2008/11/20 23:41:17.

Comment 19


Posted by name at 2008/11/21 01:28:38.

Comment 20

Hello, thx for all,

Posted by Unwulxxj at 2008/12/26 23:51:33.

Comment 21

My site is great,

Posted by Srcoudvv at 2008/12/27 04:05:12.

Comment 22

My site is great, tube8 sign up, avywgm,

Posted by Kmcssecs at 2009/01/02 19:29:47.

Comment 23


Posted by Uctmnysn at 2009/01/03 16:15:36.

Comment 24

Hello, thx for all,

Posted by name at 2009/01/03 16:34:58.

Comment 25


Posted by name at 2009/01/03 20:08:24.

Comment 26


Posted by name at 2009/01/05 13:32:43.

Comment 27

Posted by micronion at 2009/01/12 00:35:49.

Comment 28

Posted by selioneer at 2009/01/12 06:20:46.

Comment 29


Posted by xZAVsXFSn at 2009/02/04 07:26:45.

Comment 30

I want to say - thank you for this!

Posted by mark at 2009/04/11 13:26:28.

Comment 31

Very interesting site, Hope it will always be alive!

Posted by mark at 2009/04/11 16:40:07.

Comment 32

It is the coolest site,keep so!

Posted by mark at 2009/04/11 19:16:42.

Comment 33

Good Job!!

Posted by fabrika at 2009/09/14 17:09:29.

Comment 34

Да уж...

Posted by kinozalvip at 2009/09/28 09:00:58.

Comment 35


Posted by Taaxnstz at 2009/11/06 03:48:03.

Comment 36


Posted by Ncwdfyzd at 2009/11/06 13:58:19.

Comment 37


Posted by Vlnjtmvl at 2009/11/06 19:05:15.

Comment 38


Posted by Xrnuzeyt at 2009/11/07 04:57:31.

Comment 39


Posted by GSkioLxkLmfCaIa at 2009/11/18 10:45:26.

Comment 40


Kayden Kross

Posted by * * * * * * * Kayden Kross at 2010/12/17 22:30:46.

Comment 41

buy sky women's fashion fashion of the 20s 149963

Posted by SeteDopeOptog at 2011/06/22 06:53:49.

Comment 42

Posted by soundtracks at 2011/08/04 06:51:24.

Comment 43

Posted by soundtracks at 2011/08/04 06:51:26.

Comment 44

Posted by soundtracks at 2011/08/04 06:51:28.

Comment 45

Posted by soundtracks at 2011/08/04 06:51:30.

Comment 46

Posted by soundtracks at 2011/08/04 06:51:32.

Comment 47

Магазин обуви: обувь женская батильоны Liska (Лиска), женская обувь пакерсон Liska (Лиска), женская обувь fabiani Liska (Лиска), донецк женская обувь Liska (Лиска), женская обувь на реализацию Liska (Лиска).

Posted by lerafuxsi at 2012/01/18 10:12:50.

Comment 48

to remove EXIF Data By Nasim Mansurov Now that I elepainxd you what EXIF Data is and showed you how you can view EXIF on JPEG files, I will now show you how to remove EXIF Data

Posted by Monie at 2012/09/03 21:30:52.

Post a comment