Hacking .ithmb file format

GO TO ADMIN PANEL > ADD-ONS AND INSTALL VERTIFORO SIDEBAR TO SEE FORUMS AND SIDEBAR

KeithW

New member
Joined
Jul 22, 2005
Messages
22
Points
0
Age
44
Location
Seattle, WA
Website
www.cs.unm.edu
Please choose the appropriate forum for this topic. Thank you. Has anyone fully deciphered the .ithmb file format yet? I am very very close. If anyone is interested in helping me finish this off, I would like to write a simple Mac app that let's users view/parse/split/save/etc. their .ithmb files.

Here's what I figured out this afternoon:

I am working the largest resolution files, such as F1019_1.ithmb.
I determined from another thread that this stores 720x480 res images. I divided the total number of pixels (345600) into the number of photos in my library and got a perfect integer, suggesting the resolution is correct, it really does store 720x480. However, it clearly uses two bytes per pixels since that's how the math works out.

I copied off one image's worth of data into a separate file (691200 bytes) and started writing a Mac app to open and interpret the data.

At first I tried a straight-forward 16-bit color mapping, packed as ARRRRRGGGGGBBBBB, where the A is an unused bit (designated A since that bit is used as a 1-bit alpha map in some cases).

That didn't work. It was clear that the spacial information was vertically doubled because the top half and the bottom half look like squashed versions of the whole...plus the colors were a complete disaster.

After much gnashing of teeth it dawned on me that this format is intended for TV output, which is interlaced. It became immediately obvious that this must be what is going on in the file format. So I interlaced the file, assuming even rows were in the first half of the file and odd rows were in the second half of the file. Voila! Magnifier inspection suggests I have got this part right.

The colors were still wretched.

I finally figured out that that color encoding must not be RGB, it must be some luminance/chrominance separation, like YUV. I gave that a whirl. I tried taking the first byte of each pair and interpreting it as luminance while discarding the chrominance. This didn't work very well, much to my disappointment. After some experimentation I discovered that the Y channel is actually in the second of each pair of bytes...which seems very odd to me, but nevertheless, that seems to be the case. I can now successfully open and produce perfect grayscale images from the .ithmb file, not bad for a few hours worth of work.

That left me with simply converting the first byte to UV, doing a simply YUV->RGB conversion, and I should be done.

Unfortunately, I am totally stuck. The colors just don't come out right at all. I tried the obvious approach of the first four bits as U and the second as V, and I even tried switching it so V is first and then U, since Y was switch with UV in the first place. Still no luck. In addition to YUV, I have tried YIQ, and as stated, I tried switching Q and I. Still no luck. I am soooooo close, but I am kind of out of ideas right now.

Does anyone have any idea what might be going on in the chrominance channels that I'm missing?

Close, but definitely no cigar yet.
 

Will403536

New member
Joined
Jul 26, 2005
Messages
87
Points
0
Age
40
Location
VEGAS, BABY!
Website
www.will403536.tk
I may not be only speaking for myself when I say that good job, but I personally have NO CLUE what those things are and how you hacked it.

What do those ithmb files do anyway? Photos?
 

KeithW

New member
Joined
Jul 22, 2005
Messages
22
Points
0
Age
44
Location
Seattle, WA
Website
www.cs.unm.edu
Yeah, they store the photos on the iPod photo. There are multiple .ithmb files, one per resolution that the iPod requires (about four I think), where each file contains a concatenated list of every single photo in the library (up to some max number afterwhich a second file is started and so on).

I think the next thing I will try is creating images of pure red, green, and blue, and then putting them on the iPod to see how the colors get encoded in the .ithmb files. That should provide me with the necessary information I need...I think.
 

KeithW

New member
Joined
Jul 22, 2005
Messages
22
Points
0
Age
44
Location
Seattle, WA
Website
www.cs.unm.edu
Okay, I'm pretty sure the YUV is YUV 4:2:2, such that each pixel requires two adjacent pixels for its full information. Each pair of pixels is stored in 4 bytes, and encoded CLCL, meaning a chrominance byte, a luminance byte, a chrominance byte, and another luminance byte. The luminance for the left pixel comes from the second byte, the luminance for the right pixel comes from the fourth byte. There are two alternatives for chrominance. One is that both pixels use the same chrominance (they will have the same hue, or color, but their luminance is independent). The other is that the first pixel gets the two chrominances present in the 4 bytes and the second pixel gets an average relative to the next 4 byte word.

The problem is, the CLCL bytes have to be converted from their original values before they can be further converted into brightess, red, green, and blue for the final color...and I can't figure out what the conversion is. I have tried some fairly standard conversions, such as YUV and YIQ, and so far the colors are all wrong.

I tried both of the following, and they produce freakish colors:

YUV:
r = 1.0 * y + 1.140 * v
g = 1.0 * y + -0.394 * u + -0.581 * v
b = 1.0 * y + 2.028 * u

YIQ:
r = 1.0 * y + 0.956 * i + 0.621 * q
g = 1.0 * y + -0.272 * i + -0.647 * q
b = 1.0 * y + -1.105 * i + 1.702 * q

If anyone has any idea what to do, I would appreciate it.

Thanks.
 

KeithW

New member
Joined
Jul 22, 2005
Messages
22
Points
0
Age
44
Location
Seattle, WA
Website
www.cs.unm.edu
GOT IT! The YUV conversion is the correct one to use. I just had to shift the pixel values down by half (so they center on 0 and have a -128 - 127 range), and then had to shift the converted rgb values back up by half (so they center on 128 and have a 0-255 range). That's it.

I'll write a little Mac app that lets you open and peruse these files soon. It's all kind of stupid I suppose since you can easily load the originals onto the iPod anyway...and these thumbnails are stretched in some weird ways to make them fit the dimensions of the prescribed thumbnail, such as 720x480.

Woo hoo!
 

KeithW

New member
Joined
Jul 22, 2005
Messages
22
Points
0
Age
44
Location
Seattle, WA
Website
www.cs.unm.edu
Actually, I wasn't suggesting changing the .ithmb files, just reading them. What are the benefits? I have no idea. There is a Windows application for doing this, made by Xplay, but there is no such Mac application. Thought I'd level the playing field. It's kind of pointless since the highest res images stored in the .ithmb files are 720x480 and you can easily store the original hi-res photos on the ipod anyway. The real point of reverse engineering and otherwise hacking things like this isn't to invent a useful application. The point is simply to hack it for the sake of hacking it, to learn how it works, to prove ourselves clever enough to tease out its secrets, and ultimately to provide the knowledge for whatever use someone more inventive than myself may dream up.

Cheers!
 

Dopple2005

Banned
Joined
Jan 3, 2005
Messages
27
Points
0
Hi Keith,
As a programmer as well - I thought Id try this out for myself.

Im reading the files ok and getting out the YUV data but the color is going crazy on me as well. Im getting an odd yellow hue accross the whole photo.

So how did you fiz it in the end ?

Subtract 128 from each v and u value prior to using these equations ?

r = 1.0 * y + 1.140 * v
g = 1.0 * y + -0.394 * u + -0.581 * v
b = 1.0 * y + 2.028 * u

Did you end up using these contsant value ? What types are your variables ? 17 bit unsigned or signed ints.

When reading out the YUV data from the ithmb, do you read it out as...

bit stream...
Y1 U Y2 V


pixel
Y1UV
Y2UV

This is driving me nuts.
Can you send me some sample code for the YUV to RGB conversion - or seudo code ?
 

KeithW

New member
Joined
Jul 22, 2005
Messages
22
Points
0
Age
44
Location
Seattle, WA
Website
www.cs.unm.edu
Here's my code. You will have to pick around some of the Mac-graphics-specific details, but the general math is the same. Note that my code produces final rgb values in the range [0-65535], not [0-1] or [0-255]. Adjust to your requirements. Sorry for the lack of commenting.

int gImageWidth = 720, gImageHeight = 480;

//Takes a buffer of bytes corresponding to a single image (so the buffer is exactly 691200 long)
void DrawInterlacedYUV422SharedChrominanceImageIntoGWorld(unsigned char* buffer, GWorldWrapper* gww)
{
gww->StartUsingGWorld();

int imagePixels = gImageWidth * gImageHeight;

unsigned char evenC, evenL, oddC, oddL;
RGBColor c;
int xTimes2, xMinus1Times2, yOver2, yMinus1Over2;
int imageWidthTimes2 = gImageWidth * 2;
unsigned char* cPtr;
long fourBytes;
for (int y = 0; y < gImageHeight; y++)
{
yOver2 = y / 2;
yMinus1Over2 = (y - 1) / 2;

for (int x = 0; x < gImageWidth; x++)
{
xTimes2 = x * 2;
xMinus1Times2 = (x - 1) * 2;

if (y % 2 == 0)
{
if (x % 2 == 0)
{
fourBytes = *(long*)(buffer + yOver2 * imageWidthTimes2 + xTimes2);
c = ConvertCLCLToRGBColorXeven(fourBytes);
}
else
{
fourBytes = *(long*)(buffer + yOver2 * imageWidthTimes2 + xMinus1Times2);
c = ConvertCLCLToRGBColorXodd(fourBytes);
}
}
else
{
if (x % 2 == 0)
{
fourBytes = *(long*)(buffer + imagePixels + yMinus1Over2 * imageWidthTimes2 + xTimes2);
c = ConvertCLCLToRGBColorXeven(fourBytes);
}
else
{
fourBytes = *(long*)(buffer + imagePixels + yMinus1Over2 * imageWidthTimes2 + xMinus1Times2);
c = ConvertCLCLToRGBColorXodd(fourBytes);
}
}

SetCPixel(x, y, &c);
}
}

gww->FinishUsingGWorld();
}

//unsigned char evenC, unsigned char evenL, unsigned char oddC, unsigned char oddL)
RGBColor ConvertCLCLToRGBColorXeven(long fourBytes)
{
float y = (float)((fourBytes >> 16) & 0b11111111) / 255.0;
float u = (float)((fourBytes >> 24) & 0b11111111) / 255.0;
float v = (float)((fourBytes >> 8) & 0b11111111) / 255.0;

return ConvertYUVtoRGBColor(y, u, v);
}

//unsigned char evenC, unsigned char evenL, unsigned char oddC, unsigned char oddL)
RGBColor ConvertCLCLToRGBColorXodd(long fourBytes)
{
float y = (float)(fourBytes & 0b11111111) / 255.0;
float u = (float)((fourBytes >> 24) & 0b11111111) / 255.0;
float v = (float)((fourBytes >> 8) & 0b11111111) / 255.0;

return ConvertYUVtoRGBColor(y, u, v);
}

//Takes y, u, and v in the range [0.0 - 1.0] and creates r, g, and b in the range [0.0 - 65535]
RGBColor ConvertYUVtoRGBColor(float y, float u, float v)
{
RGBColor rgb;

y -= .5;
u -= .5;
v -= .5;

y *= 2.0;
u *= 2.0;
v *= 2.0;

float red = (1.0 * y + 1.140 * v);
float green = (1.0 * y + -0.394 * u + -0.581 * v);
float blue = (1.0 * y + 2.028 * u);

red /= 2.0;
green /= 2.0;
blue /= 2.0;

red += .5;
green += .5;
blue += .5;

float cutoff = 1.0;

if (red < 0)
red = 0;
else if (red > cutoff)
red = cutoff;
if (green < 0)
green = 0;
else if (green > cutoff)
green = cutoff;
if (blue < 0)
blue = 0;
else if (blue > cutoff)
blue = cutoff;

float scaler = 65535.0 / cutoff;

rgb.red = red * scaler;
rgb.green = green * scaler;
rgb.blue = blue * scaler;

return rgb;
}
 

easinewe

New member
Joined
Mar 14, 2006
Messages
2
Points
0
Has anyone been able to save a picture as an .ithmb?
I would like to make the thumbnail image (F1036) different from the full screen image (F1024) that it corresponds with. For example, in the photo menu I could click on a picture of the word Bjork and a full size image of Bjork would show up full size.
 

KeithW

New member
Joined
Jul 22, 2005
Messages
22
Points
0
Age
44
Location
Seattle, WA
Website
www.cs.unm.edu
It would be a simple matter of reversing the process I described earlier in this thread. Instead of decoding a .ithmb file into a raw image data, you would encode raw image data into a .ithmb file using the encoding described. However, bear in mind that the different .ithmb files store the images in different formats. Not only do they store different resolutions, but they might not even use the same encoding. The large 720x480 images I decoded are YUV 4:2:2, but that isn't true of all the other .ithmb file formats. It's just a bit of reverse-engineering. Nothing hard about it, just tedious.
 

easinewe

New member
Joined
Mar 14, 2006
Messages
2
Points
0
That's good news! Do you know of any existing programs that could encode in this format, other than iphoto obviously? Or would I need to know complicated programming to do this. Thanks.
 

Jump_Blueberry

Apple Preacher
Joined
Apr 9, 2005
Messages
323
Points
0
Age
36
Location
Germany - Bavaria
Hi, could you send this code to the guy who makes yamipod?
He has been searching for a method to write such a file for a long time.

A program that can read the itmb.-file is XPlay-Photo-browser... but it can't encode... No program (Windows) can, I guess.
 

KeithW

New member
Joined
Jul 22, 2005
Messages
22
Points
0
Age
44
Location
Seattle, WA
Website
www.cs.unm.edu
The code is included in this very thread. Just send that to him and tell him to reverse the process. I don't even know who he is. I'm really busy this semester. I've already given the code away freely here in this discussion. I don't have any more time to dedicate to this project. I'm sorry.
 

jneugebauer

New member
Joined
Nov 8, 2010
Messages
1
Points
0
Windows Application

I have posted a simple implementation of Keith's code on CodeProject.
If you only want to extract the bitmaps from an ithmb file then this should help.

www_codeproject_com/KB/graphics/iThmbConverter_aspx

or search for "Apple iPod Photo Converter" on CodeProject.
 

beniwal01

New member
Joined
Mar 20, 2014
Messages
6
Points
0
The code is included in this very thread. Just send that to him and tell him to reverse the process. I don't even know who he is. I'm really busy this semester. I've already given the code away freely here in this discussion. I don't have any more time to dedicate to this project. I'm sorry.
I am new to this forms and i m developing an application in which i need to read .ithmb file and extract all images from it on windows platform using c or c++.vc or other possible . can any one give me idea about this how can i do that. I have a iTunes backup of iphone5 (ios7) which have .ithmb file .Please provide me information that how can i do that.


Thanks
 
Top