MIG Image File Format
The MIG image file format is designed to represent all Iray supported image pixel formats in a straightforward structure which guarantees that no internal reinterpretation of data will occur. When dealing with non-color render targets (like depth renders, normal maps, UV coordinates etc.) it can be difficult to find an image format that will natively support the data type. In these cases you often end up converting them to a color format which results in loss of precision. Additionally, when reloading the file Iray may perform unexpected data conversions internally which result in further information loss. The MIG format is always able to encode canvases in their original format and decode them back into Iray without loss.
The format uses the file extension mig
to identify files using the format. You can use mig
anywhere that accepts an image encoding format to encode a mig image.
For example the following JSON-RPC command will render a normal map image to the mig file format and save it to disk:
{ "method":"render_to_disk", "params":{ "scene_name": "my_scene", "canvas_content": "normal", "canvas_pixel_type": "Float32<3>", "pixel_type": "Float32<3>", "path": "normalmap.mig", "format": "mig" } }
File Format
The format is simply uncompressed image data with a small header. All values are stored in big endian format and must be byte swapped as required.
Signature
Files begin with an 8 byte signature.
mi::Uint8[4] magic number
-0x6d 0x67 0x74 0x63
In ASCII the string"mgtc"
.mi::Uint32 version_number
- Format version number, currently 3.
Header
The signature is followed by a header describing the image properties. For version 3 files this is 36 bytes.
mi::Uint32 x resolution
- Image resolution in x direction.mi::Uint32 y resolution
- Image resolution in y direction.mi::Uint32 number of layers
- Number of layers in the image.mi::Uint32 component format
- The format of each pixel component. One of:0x1
- mi::Float32 (4 byte components)0x2
- mi::Uint16 (2 byte components)0x3
- mi::Uint8 (1 byte components)0x4
- mi::Sint8 (1 byte components)0x5
- mi::Sint32 (4 byte components)
mi::Uint32 components per pixel
- The number of components per pixel. This value and component_format together specify how many bytes are used to store each pixel.mi::Uint32 pixel format
- The pixel format. This describes how pixels are interpreted. One of:0x0
- Float32 (1 x mi::Float32)0x1
- Float32<2> (2 x mi::Float32)0x2
- Float32<3> (3 x mi::Float32)0x3
- Float32<4> (4 x mi::Float32)0x4
- Rgb_fp (3 x mi::Float32)0x5
- Color (4 x mi::Float32)0x6
- Rgb (3 x mi::Uint8)0x7
- Rgba (4 x mi::Uint8)0x8
- Rgbe (4 x mi::Uint8)0x9
- Rgbea (5 x mi::Uint8)0xa
- Rgb_16 (3 x mi::Uint16)0xb
- Rgba_16 (4 x mi::Uint16)0xc
- Sint8 (1 x mi::Sint8)0xd
- Sint32 (1 x mi::Sint32)
mi::Float32 gamma
The gamma value of the image.mi::Uint32 flags
Format flags bitmap. The following flags are currently supported:0x1
- cubemap, this image represents a cubemap.
mi::Uint32 mipmap levels
- The number of mip map levels per layer in this image. Currently the only supported value is 1.
Image data
Following the header arenumber of layers
blocks of image data (lowest numbered layers first). Image data is in row-major, bottom-top format. Each block is
x resolution
* y resolution
* component byte size
* componenets per pixel
bytes in size. Each block has
x resolution
* y resolution
pixels and each pixel needs to be intrepreted accoring to the pixel format
.