Technical Documentation - Dungeon Master II Graphics.dat: How to read some messed up images

Author of this documentation: Kentaro.k-21
I'm not good at explain in English, so I prepared enough screen shots to explain.
This explanation refers to the DM2 GRAPHICS.DAT of Amiga version, which is formatted in big endian.

I'll show how to extract the next image.

Image 1

This operation uses 3 images to combine and merges into one complete image.

Image 2 + Image 3 + Image 4 = Image 1

In convenience, I allocate the index number for them. The index is based on order from GRAPHICS.DAT.

#4537 + #4539 + #4540 = New #4540 Image

About 1st image.

You can extract the first image(#4537) easily.

Please visit Technical Documentation - File Formats - Data Files for further information about IMG3 and IMG4 formats. It's great resource!

This image requires to combine with 2nd image.

About 2nd image.

Generally, it appears to be the messed up image.

I'll explain with the next figure.

Image 5

This shows the binary image of 2nd image(#4539).

This tool divides a raw data into 3 parts automatically.
They are Prefix, Compressed Binary bytes and Suffix.

Part Size of each part (in bytes)
Prefix 7
Binary 2,348
Suffix 16
Total 2,371

I copied the each heading binary into a table.

Part Heading hex binary
Prefix 00 A0 00 74 96 F1 2D
Binary FF F0 54 C2 D3 2D F8 4A 01 0D 28 19 0A 0D F7 E2 ...
Suffix 00 E9 EB A8 A6 AA 58 00 BC 3D 00 8C E7 ED 00 EF

I highlighted the 6 components of "Prefix" (9, 6, F, 1, 2, D) and the entire "Binary".
The 6 components means "Local palette of 6 most used colors in image" (from Christophe's Data files description).

Generally, It is believed that the compressed image starts from "Binary".

However, this 2nd image is some bit different.

Part Heading hex binary
Prefix 00 A0 00 74 96 F1 2D
Binary FF F0 54 C2 D3 2D F8 4A 01 0D 28 19 0A 0D F7 E2 ...
Suffix 00 E9 EB A8 A6 AA 58 00 BC 3D 00 8C E7 ED 00 EF

The 2nd image starts from 52th bit (8*6+4) in "Prefix".

If decompression work start from 52th bit, You can get the next image.

Image 6

In this case, the last component of "Prefix" (0xD) is part of compressed image.
So, you should not contain it to decode Local palette.
They should be consisted from 5 components (9, 6, F, 1, 2).

Next problem is "What's the mask color? or transparent color?"

I brought 2 words in my discretion. (I may need the correct for these expression.)

Empty color from Christophe's Data files description
"Copy pixels from the previous line of the image"
Transparent color Copy the pixels from previous image at same position.
In this case, it's the 1st image.

Allocation for "Empty color" is same as IMG3 or IMG4 (described at Christophe's Data files description).

Allocation for "Transparent color".
I tried and decided the colors with my feeling. They are 6th Color and 14th Color.

I arranged role of colors/palettes to next table. ("-" means it doesn't change the existing role.)

Colour Role Colour Role
1st Color:0 - Palette:0 -
2nd Color:1 - Palette:1 -
3rd Color:2 - Palette:2 -
4th Color:3 - Palette:3 -
5th Color:4 - Palette:4 -
6th Color:5 Transparent color Palette:5 -
7th Color:6 - (Empty color) Palette:6 -
8th Color:7 - Palette:7 -
9th Color:8 - Palette:8 -
10th Color:9 - Palette:9 -
11th Color:10 - Palette:10 -
12th Color:11 - Palette:11 -
13th Color:12 - Palette:12 -
14th Color:13 Transparent color Palette:13 -
15th Color:14 - (Empty color) Palette:14 -
16th Color:15 - Palette:15 -

If combine work proceeded successfully, You can finally get the next image.

Image 2 + Image 6 = Image 7

About 3rd image

It's the same way as method against 2nd image.

How to decide the 3 Images (1st image, 2nd image and 3rd image)

Please remember this screen shot.

Image 8

The raw data at "0001" is that.

The next heading binary from this entry.

ADDRESS 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 0123456789ABCDEF
0000000 00 0B 00 38 00 11 00 03 00 38 00 11 00 45 00 6D ...8.....8...E.m
0000010 00 6D 00 77 00 77 00 03 00 7E 00 77 00 DB 00 DA .m.w.w...~.w....
0000020 00 DE 00 DD 00 E5 00 E1 00 E7 00 E6 00 EA 00 E6 ................
0000030 00 EB 00 EA 00 ED 00 F2 00 EE 00 DF 00 F0 00 EF ................

This raw data is read as next table shows.

Offset What image do you want to render That image inherits from the following image
0000 000B 0038
0004 0011 0003
0008 0038 0011
000C 0045 006D
... ... ...
0F68 11BB (4539, the 2nd img) 11B9 (4537, the 1st img)
0F6C 11BC (4540, the 3rd img) 11BB (4539, the 2nd img)
... ... ...

I arranged in logical consideration for extraction.

To render image #4540, it requires #4539 has been already rendered.
To render image #4539, it requires #4537 has been already rendered.
To render image #4537, it doesn't require any image has been rendered.

Renders #4537 as 1st image.
Renders #4539 as 2nd image and overrides the previous image.
Renders #4540 as 3rd image and overrides the previous image.

These explanations are way how to read some messed up images in DM2 GRAPHICS.DAT.

And this document doesn't have complete information.
This means that some images can be obtained with this method but other images won't be able to be obtained correctly with this method.
So I'm welcome to have any correction for this document.



Revision 1 (2003-03-07)
First release
Revision 2 (2003-03-08)
Corrects for some miscalculation ;)
Detailed description for boundary between Local palette and compressed image.