A MR image is an image format solely used inside an IP.BIN file to show off a logo during the boot screen process of the Sega Dreamcast.
This image format was used in commercialized Dreamcast games utilizing Windows CE SDK where we see a "Powered by Microsoft Windows CE" logo. It is now commonly used in homebrew to distinguish the creator(s) of the application or to disassociate the application being produced by or under license from Sega. The MR image must be inserted into a IP.BIN file at offset 0x3820 in order to be viewed during boot sequence. Since IP.BIN is restricted to a 32k file size, there are a couple of guidelines the MR image must meet to in order to fit inside the IP.BIN.
MR Image must be:
- 320x90 or less
- Max 128 colors
- Less than 8192 bytes to fit in a IP.BIN
- The transparent color is #c0c0c0, or 192, 192, 192 in RGB
SiZious's Windows Tool to create homebrew compilations. Using this application you can view and create MR images from other various other image formats.
MR GIMP Plugin
GIMP is a cross-platform image editor available for GNU/Linux, OS X, Windows.
Using this GIMP plugin("file-mr.py"), you can create view, edit, and create a MR image from any other image format that GIMP supports.
The file format is composed of three sections: Header, Palette, and the Image Data. All of the data written in the file is in little-endian format.
A MR file starts off with a 30 byte header.
|4 bytes||Total file size|
|4 bytes||Crap (fill with 0's)|
|4 bytes||Image data offset in bytes (Header size + Palette size)|
|4 bytes||Image width|
|4 bytes||Image height|
|4 bytes||Crap (fill with 0's)|
|4 bytes||Amount of colors in palette|
The header is followed by the image's palette. The palette is composed of palette entries where each palette entry is 4 bytes long and is stored as BGRA. The alpha byte goes unused. The maximum number of palette entries is 128.
In total, the byte size of your palette should be number of colors * 4.
Lastly, the image data. The image data is basically an array of indices, each a byte long, that refers to a palette entry in the palette. The image data is compressed using a form of Run-Length Encoding (RLE). The python algorithms to encode/decode the image data are shown below.
1 # input: Byte array 2 # output: Byte array 3 # input_size: Size of input in bytes (image width * image height) 4 # returns: Size of the compressed data 5 def mr_encode(input, output, input_size): 6 run = 0 7 length = 0 8 position = 0 9 10 while(position < input_size): 11 run = 1 12 13 while((run < 0x17f) and (position+run < input_size) and (input[position] == input[position+run])): 14 run += 1 15 16 if(run > 0xff): 17 output[length] = 0x82 18 length += 1 19 output[length] = 0x80 | (run - 0x100) 20 length += 1 21 output[length] = input[position] 22 length += 1 23 elif(run > 0x7f): 24 output[length] = 0x81 25 length += 1 26 output[length] = run 27 length += 1 28 output[length] = input[position] 29 length += 1 30 elif(run > 1): 31 output[length] = 0x80 | run 32 length += 1 33 output[length] = input[position] 34 length += 1 35 else: 36 output[length] = input[position] 37 length += 1 38 39 position += run 40 41 return length
1 # input: Byte array 2 # input_size: Size of input in bytes 3 # uncompressed_size: Size of uncompressed data in bytes (image width * image height) 4 # returns: Decoded image data 5 def mr_decode(input, input_size, uncompressed_size): 6 run = 0 7 position = 0 8 idx_position = 0 9 indexed_data = array("B", "\x00" * uncompressed_size) 10 11 while(position < input_size): 12 first_byte = input[position] 13 if((position+1) < input_size): 14 second_byte = input[position+1] 15 16 # The bytes lower than 0x80 are recopied just as they are in the Bitmap 17 if(first_byte < 0x80): 18 run = 1 19 position += 1 20 # The tag 0x81 is followed by a byte giving directly the count of points 21 elif(first_byte == 0x81): 22 run = second_byte 23 first_byte = input[position+2] 24 position += 3 25 # The tag 0x82 is followed by the number of the points decoded in Run 26 # By retaining only the first byte for each point 27 elif(first_byte == 0x82 and second_byte >= 0x80): 28 run = second_byte - 0x80 + 0x100 29 first_byte = input[position+2] 30 position += 3 31 else: 32 run = first_byte - 0x80 33 first_byte = second_byte 34 position += 2 35 36 # Writing decompressed bytes 37 for i in range(run): 38 if(idx_position+i < uncompressed_size): 39 indexed_data[idx_position+i] = first_byte 40 41 idx_position += run 42 43 return indexed_data