>> Sunday, May 31, 2009
This article contains information about what we know about CD-I pictures formats and what we've done in trying to decode them. Requirements : You will need a Hexadecimal editor to extract a track of bytes. You will need to install the shareware ISOBuster to extract the files (or another working tool). Well the problem is : how do I convert CD-i pictures ? The easiest solution would be to get the picture you want to decode and then using the convert tools found at icdia.co.uk. Unfortunately, that doesn't work because the pictures are wrapped into huge files and - what kills any chance - all "headers" of the image data are missing. Till we find a better way, here are the steps needed to see some of the pictures. NOTICE : We've only decoded two formats : CLUT8 and RLE7 at 384px width. There are many other formats used by CD-i.
CD-i's CLUT 8: The CLUT8 (Color Look Up Table, 8bits/pixels) is an uncompressed image format. At the begin of a CLUT8 file there is a header (describing dimensions of the image but seems to be not in the CD-i files). Then, there is the palette with the color codes. The first color (e.g. 10 10 FF) is the color 0, the second is the color 1, etc... The palette ends with the characters "IDAT". The next 4 bytes are the remaining length of the file. Next part, each byte describe one pixel with a code reffering to the color read before in the palette. If the header is not present, you have to guess the width. The width of these images usually is 384 pixels.
The CD-i RLE7 is similar to CLUT8 but it's a compressed format. However its size is generally smaller, its palette may not contains more than 128 colors (against 256 for CLUT 8). RLE is one of the simplest compression methods. Here are the rules: If the first bit of the byte is false, the next 7 bits are the color code (reffering to the palette) to be drawn 1 time. Else, the next 7 bits are the color code (refering to the palette) to be drawn x times. x actually is the following byte. In the second case, if the following byte is 0 then draw the color to the end of the image's width. For example, we have an image 2x4 pixels with two colors. if the pixel part is the next 5 hexa bytes : 0x80 0x00 0x01 0x00 0x81 0x00, the output will be :
0 0 0 0
1 0 1 1
Extract the CD-i files: CD-i disks can be read by ISOBuster and you can use it to extract the files from the disk. It can took more minutes if the disk is scratched. Extract the Track into a ISO file and then open it with ISOBuster. You should see all the CD-i files. It's recommended to extract them normally.
Find recognizable image data: We're close. You may want to use the program we made to search image automatically. However, We've tested it with only one CD-i (hotel mario) so it might not be able to find all the images. If you use the little tool below, it would be more tedious but you might get more results. Open suspected files that may contains such data - their name usually end with .rtf - with a hex editor. Look for the string "IDAT" or this list of bytes : "0x49444154". If the search found matches, you probably have found image data. If not, try another file. Extract the bytes in two files - needed step for the tool. Look at the bytes before "IDAT". That should be the image palette. Extract these bytes in a separate file named image.palette.
IDAT is followed by 4 bytes indicating the number of bytes describing the pixel part (useful to know the end of the file). After these 4 bytes, the pixel part begins. Extract the pixel part in a new file, for instance "image.data". The end of this part just ends before a lot of zeros.
Now you have two files : a palette file and a data file, both without the 8 IDAT xxxx bytes. Now you must determine the format. RLE and CLUT images use both a palette, but the pixel part of the CLUT is uncompressed. You will notice it by looking at the bytes : each next byte is a number close to the previous one, and the file is big ? It should be a CLUT file. Other if it looks more like the example it may be RLE.
Decode into ... HTML ! It's up to you about the way you want to decode the image (see the About formats section if want some tips). Open the suited tool (RLE drawer, Clut Drawer) and tell the program where is the palette and the data of the image. Choose a name for the HTML output file (e.g. image.html). Beep ! You can now open the toasted HTML file.
Fixing the colors: Some colors may not appear correctly. Make sure that the palette file contains x bytes, x must be divisible by 3(each color is 3 bytes, RGB). Try to add 1 or 2 "00" bytes at the begin of the palette file and try to decode again. CD-i Image drawer: An image extractor that tries to look for image data and CD-i RTF files. Extracts in BMP. Functions :
Extr selected : Extracts the selected image.
View : view the selected image.
Edit : edit the location of the image in the RTF file.
QuickFix : If the image is not at the center, it will try to adjust it.
Multiframe : Extracts a set of images, after the selected one. Useful when you want to extract the video frames.
Analyse : find all the images recognized in the RTF file.
Extract : extract each element of the list.
Issues : many. Crops the top of some images, or the bottom (+- 6*384 pixels).
Tools: CLUT8 Drawer (Little tool that converts a CLUT 8 image splitted into a palette file and a data file into a heavy HTML file) and RLE7 Drawer (Little tool that converts a RLE 7 image splitted into a palette file and a data file into a heavy HTML file.)
You can download the tools here.
Credits: © P.L. 2009 - paolo.liistro[at]gmail.com