Register now    |   Login  

COMMUNITY





Back to Forum Index
   Development & Bugs
     Hints for album art support
Register To Post
Poster Thread
Remoulade
(Just popping in)


Joined: 2008/1/7
Posts: 2

Posted on: 2008/1/8 18:22

Hints for album art support
Hi everybody,

Though I'm pretty sure this is no news for those of you developing stuff around your iPod, I just pass the info. I'm always happy to help !

I've developed a short program in python to extract album arts from the artworkDB of my 5th Gen Ipod and it works pretty well. I know for sure that writing is always trickier than reading but it could be a good place to start for anyone who would like to try...

My source of info was ipodlinux.org (http://ipodlinux.org/ITunesDB#Artwork_Database) which says all about it.
Working with the MHIIs and MHOD is done using the same principles as with itunesDB parsing-wise.
The *.ithmb files contains the actual data of the image. It is stored as BMP (or DIB) data, 16bits color depth. In my case (5th gen Video Ipod), this was exactly "RGB565_LE". It means that the red componant is on 5 bits, the green on 6bits and the blue on 5 bits.

Once data extracted from the file, you have to add the correct BMP header and write the result in a file and it's done.
The "compression method" in the header must be set on 3 and the compression mask is as follow :
red_mask = 0xf800
green_mask = 0x7e0
blue_mask = 0x1f

For those of you fluent in python, here is the code snippet that writes the actual bmp file :

def create_bmp(source_filename, source_offset, dest_filename, px_width, px_height, im_size) :
explicit_size = { 20000 : "small" , 80000 : "big"}
bmpv3hd_fmt = "<2sLHHLLLLHHLLLLLLLLL"
bmpv3hd_size = 40
bmp_offset = struct.calcsize(bmpv3hd_fmt)
bit_per_px_nb = 16
comp_method = 3 # bitfield - cf masking below (565RGBLE)
red_mask = 0xf800
green_mask = 0x7e0
blue_mask = 0x1f
im_resol = 2835 # i.e. 72dpi
#opening the soon-to-be bmp file
bmp_file = open("%s\\%s.bmp"%(explicit_size[im_size], hex(dest_filename)), "wb")
# preparing bmp file header
bmpv3hd_string = struct.pack(bmpv3hd_fmt, "BM", bmp_offset + im_size, 0, 0, bmp_offset, bmpv3hd_size, px_width, - px_height, 1, \
bit_per_px_nb, comp_method, im_size, im_resol, im_resol, 0, 0, red_mask, green_mask, blue_mask)
bmp_file.write(bmpv3hd_string)

#opening the source file "something.ithmb"
source_file = open(source_filename, "rb")
source_file.seek(source_offset) #seeking data
bmp_file.write(source_file.read(im_size))
source_file.close()
bmp_file.close()
# and the magic is done

In fact, the real difficulty in this album-art stuff is not the technical stuff about writing or reading files, it's much more about the way you want to present the service to the user, from a functional and ergonomical point of view. Once you've decided that, there is just coding left

I hope it is of help...

Register To Post