MR image: Difference between revisions

From dreamcast.wiki
Jump to navigation Jump to search
(13 intermediate revisions by the same user not shown)
Line 1: Line 1:
==About==
==About==
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. [[File:Windows CE boot screen.png|thumb|Games powered by Windows CE boot screen]]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. Since [[IP.BIN]] is restricted to a 32k file size and the MR image must be inserted into that file in order to be displayed during the boot process, there are a couple of guidelines the MR image must meet to be shown during the boot process.
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. [[File:Windows CE boot screen.png|thumb|Games powered by Windows CE boot screen]]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]].
<br/>
'''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
<br/>
==Tools==
'''Selfboot-Inducer'''
 
SiZious's Windows [https://sizious.com/download/dreamcast/#selfboot-inducer Tool] to create homebrew compilations. Using this application you can view and create MR images from other various other image formats.
 
<br/>
'''MR GIMP Plugin'''
 
[https://www.gimp.org/ GIMP] is a cross-platform image editor available for GNU/Linux, OS X, Windows.
 
Using this GIMP plugin([https://gitlab.com/BBHoodsta/makeip "file-mr.py"]), you can create view, edit, and create a MR image from any other image format that GIMP supports.
 
==File Format==
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.
===File Header===
{| class="wikitable" style="text-align: center"
|-
! Size (bytes) !! Contents
|-
| 2
|style="text-align: left;"| "MR"
|-
| 4
|style="text-align: left;"| Total file size
|-
| 4
|style="text-align: left;"| Crap (fill with 0's)
|-
| 4
|style="text-align: left;"| Image data offset in bytes (Header size + Palette size)
|-
| 4
|style="text-align: left;"| Image width
|-
| 4
|style="text-align: left;"| Image height
|-
| 4
|style="text-align: left;"| Crap (fill with 0's)
|-
| 4
|style="text-align: left;"| Amount of colors in palette
|}
 
===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'''.
{| class="wikitable"
|-
! colspan="4"|Palette Entry
|-
| B || G || R || A
|}
 
In total, the byte size of your palette should be number of colors * 4.
===Image Data===
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.
 
==Encoding Algorithm==
<syntaxhighlight lang="c" line="line">
# input: Byte array
# output: Byte array
# input_size: Size of input in bytes (image width * image height)
# returns: Size of the compressed data
def mr_encode(input, output, input_size):
    run = 0
    length = 0
    position = 0
 
    while(position < input_size):
        run = 1
 
        while((run < 0x17f) and (position+run < input_size) and (input[position] == input[position+run])):
            run += 1
 
        if(run > 0xff):
            output[length] = 0x82
            length += 1
            output[length] = 0x80 | (run - 0x100)
            length += 1
            output[length] = input[position]
            length += 1
        elif(run > 0x7f):
            output[length] = 0x81
            length += 1
            output[length] = run
            length += 1
            output[length] = input[position]
            length += 1
        elif(run > 1):
            output[length] = 0x80 | run
            length += 1
            output[length] = input[position]
            length += 1
        else:
            output[length] = input[position]
            length += 1
       
        position += run
 
    return length
</syntaxhighlight>
==Decoding Algorithm==
<syntaxhighlight lang="c" line="line">
# input: Byte array
# input_size: Size of input in bytes
# uncompressed_size: Size of uncompressed data in bytes (image width * image height)
# returns: Decoded image data
def mr_decode(input, input_size, uncompressed_size):
    run = 0
    position = 0
    idx_position = 0
    indexed_data = array("B", "\x00" * uncompressed_size)
 
    while(position < input_size):
        first_byte = input[position]
        if((position+1) < input_size):
            second_byte = input[position+1]


'''MR Image must be:'''
        # The bytes lower than 0x80 are recopied just as they are in the Bitmap
        if(first_byte < 0x80):
            run = 1
            position += 1
        # The tag 0x81 is followed by a byte giving directly the count of points
        elif(first_byte == 0x81):
            run = second_byte
            first_byte = input[position+2]
            position += 3
        # The tag 0x82 is followed by the number of the points decoded in Run
        # By retaining only the first byte for each point
        elif(first_byte == 0x82 and second_byte >= 0x80):
            run = second_byte - 0x80 + 0x100
            first_byte = input[position+2]
            position += 3
        else:
            run = first_byte - 0x80
            first_byte = second_byte
            position += 2


* 320x90 or less
        # Writing decompressed bytes
* Max 128 colors
        for i in range(run):
* Less than 8192 bytes to fit in a IP.BIN
            if(idx_position+i < uncompressed_size):
* The transparent color is #c0c0c0, or 192, 192, 192 in RGB
                indexed_data[idx_position+i] = first_byte
<br><br>


==File Structure==
        idx_position += run


==Encoding==
    return indexed_data
==Decoding==
</syntaxhighlight>

Revision as of 23:56, 13 October 2020

About

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.

Games powered by Windows CE boot screen

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


Tools

Selfboot-Inducer

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.

File Format

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.

File Header

Size (bytes) Contents
2 "MR"
4 Total file size
4 Crap (fill with 0's)
4 Image data offset in bytes (Header size + Palette size)
4 Image width
4 Image height
4 Crap (fill with 0's)
4 Amount of colors in palette

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.

Palette Entry
B G R A

In total, the byte size of your palette should be number of colors * 4.

Image Data

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.

Encoding Algorithm

# input: Byte array
# output: Byte array
# input_size: Size of input in bytes (image width * image height)
# returns: Size of the compressed data
def mr_encode(input, output, input_size):
    run = 0
    length = 0
    position = 0
   
    while(position < input_size):
        run = 1

        while((run < 0x17f) and (position+run < input_size) and (input[position] == input[position+run])):
            run += 1

        if(run > 0xff):
            output[length] = 0x82
            length += 1
            output[length] = 0x80 | (run - 0x100)
            length += 1
            output[length] = input[position]
            length += 1
        elif(run > 0x7f):
            output[length] = 0x81
            length += 1
            output[length] = run
            length += 1
            output[length] = input[position]
            length += 1
        elif(run > 1):
            output[length] = 0x80 | run
            length += 1
            output[length] = input[position]
            length += 1
        else:
            output[length] = input[position]
            length += 1
        
        position += run

    return length

Decoding Algorithm

# input: Byte array
# input_size: Size of input in bytes
# uncompressed_size: Size of uncompressed data in bytes (image width * image height)
# returns: Decoded image data
def mr_decode(input, input_size, uncompressed_size):
    run = 0
    position = 0
    idx_position = 0
    indexed_data = array("B", "\x00" * uncompressed_size)

    while(position < input_size):
        first_byte = input[position]
        if((position+1) < input_size):
            second_byte = input[position+1]

        # The bytes lower than 0x80 are recopied just as they are in the Bitmap
        if(first_byte < 0x80):
            run = 1
            position += 1
        # The tag 0x81 is followed by a byte giving directly the count of points
        elif(first_byte == 0x81):
            run = second_byte
            first_byte = input[position+2]
            position += 3
        # The tag 0x82 is followed by the number of the points decoded in Run
        # By retaining only the first byte for each point
        elif(first_byte == 0x82 and second_byte >= 0x80):
            run = second_byte - 0x80 + 0x100
            first_byte = input[position+2]
            position += 3
        else:
            run = first_byte - 0x80
            first_byte = second_byte
            position += 2

        # Writing decompressed bytes
        for i in range(run):
            if(idx_position+i < uncompressed_size):
                indexed_data[idx_position+i] = first_byte

        idx_position += run

    return indexed_data