MBM format specification: 2bytes:MB DWORD: width DWORD: height 2bytes: type and subtype (subtype determines compression used, and 0 value always means no compression) 2*COLORQUAD [palette] - only if type=0 256*COLORQUAD [palette] - only if type=2,0; WORD+x*COLORQUAD ["compressed" palette] - only if type=2 and subtype >0 (WORD describes number of following colors stored in file, must be > 0, must not be > 256) image data -------------------------------------------------------------------------------------------- COLORQUAD consist of 4 following bytes - transparency (0-opaque, 255-fully transparent), red component, green component, blue component for WORD and DWORD an intel architecture is assumed (little endian), so on big-endian platforms switch bytes. -------------------------------------------------------------------------------------------- type=0,0 - 2 colors binary (palette). if there are unused bits of last byte in line - should be 0 type=0,1 - compressed 2 colors (palette), first 7 bits - (number-1) of pixels of color of the youngest bit. (i.e. after obtaining number from 1st 7bits add 1 to it to obtain number of pixels of color of the youngest bit) type=1,0 - 2 colors binary, no palette ( 0 - opposite of background,1 - transparent (background) ). type=1,1 - compressed, analogue to 0,1 type=2,0 - 256 colors (pallette) (*note if file defines less than 256 entries in palette, remaining colors are expected to be COLORQUAD(0,0,0,0)) type=2,1 - compressed 256 colors (palette) 1 byte - (number-1) pixels of color of second byte. (i.e. add 1 to 1st byte to obtain number of pixels of 2nd byte) type=2,2 - compressed 255 colors (last RGBQUAD in palette is unused) if 255 (0FFh) byte value in image data is used it means that following 2 bytes will be: 1st byte - (number-4) pixels of color of 2nd byte (i.e. add 4 to the byte to obtain number of pixels) type=2,3 - compressed 128 colors (only 1st 128 colors of palette are used). if byte in image data is >=128 then youngest 7bit means (number-3) pixels of color of following byte. (i.e. after obtaining number from youngest 7 bits add 3 to it) type=2,4 - compressed 254 colors (two last RGBQUADS in palette unused) if 255 (0FFh) then the meaning is like in type 2,2, if byte is 254 (0FEh) then 3 following bytes will be: WORD - (number-260) of color of following byte (i.e. add 260 to the WORD to obtain number of pixels). type=3,0 - no colors, no palette, each byte define transparency 0 - means opposite of background, 255 - transparent (background) type=3,1 - compressed 3 type analogue to 2,1 type=4,0 - 24bit per pixel //opaque images only type=4,1 - 24bit per pixel compressed (byte + 3 bytes RGB) 1st byte - (number-1) pixels of color of following 3 bytes (RGB); type=4,2 - 24bit per pixel semi-advanced compression (for details see separate file MBM-SAC.txt) type=5,0 - 32bit per pixel (COLORQUADs) type=5,1 - 32bit per pixel compressed (byte + COLORQUAD) 1st byte - (number-1) pixels of color of following COLORQUADs type=5,2 - 32bit per pixel compressed. For this type if transparency for a pixel equals 255 (0FFh) then values of r,g,b are always set to 0. If transparency byte is 255 then if next byte=0 then it's single pixel (COLORQUAD), if second byte>1 then this byte is a number of pixels of the following COLORQUAD, if second byte=1 then following 2 bytes are (WORD-256) describes number of pixels of following COLORQUAD. type=5,3 32bit per pixel semi-advanced compression analogous to 4,2 (see MBM-SAC.txt for details) //type>=6 reserved (for now incorrect value - unknown type); -------------------------------------------------------------------------------------------- components (red,green,blue) for semi-transparent pixels are evaluated using this equation: f.c = (t*b.c+(255-t)*p.c)/255; where: f - final color (f.c stands for final color component, respectively red, green, blue) t - transparency byte b - background color (b.c stands for background color component) p - picture color (p.c stands for picture color component) for type 3 (8-bit, no palette) pixel color components are evaluated this way: f.c = (t*b.c+(255-t)*(255-b.c))/255; For best quality all results should be computed on float point numbers and rounded. -------------------------------------------------------------------------------------------- *Note: This format is NOT meant to be extended by third parties. If you add support for it in your product, please keep up to the specifications. Designed by Grzegorz Wróbel Last revision: 9 October 2012 The actual copy of this file can be found at http://www.4neurons.com/other/mbm/MBM.TXT Sample images and demonstration program can be found at http://www.4neurons.com/other/mbm/mbm.html