Adding New File Extensions .BLP and .M3

Questions and postings pertaining to the development of ImageMagick, feature enhancements, and ImageMagick internals. ImageMagick source code and algorithms are discussed here. Usage questions which are too arcane for the normal user list should also be posted here.
Post Reply
Atmosferic
Posts: 5
Joined: 2011-05-10T15:58:06-07:00
Authentication code: 8675308

Adding New File Extensions .BLP and .M3

Post by Atmosferic »

Hello there,

I have looked effortlessly and nothing came up. I would like to include support for two file extensions .BLP and .M3.
I have example files, one of each. What I am aiming to do is to be able to preview them in as attachments in vbulletin as if they were images.

Something like convert them from .BLP or .M3 to .PNG format. The image uploaded would be in .BLP or .M3 format but the image preview when viewing the images on the forums would be in .png format.

Please can someone help me out with this?

Image Attachments:
ConsoleTerran_00.m3
humanknight.blp
Image
Atmosferic
Posts: 5
Joined: 2011-05-10T15:58:06-07:00
Authentication code: 8675308

Re: Adding New File Extensions .BLP and .M3

Post by Atmosferic »

Bump.

A little help here, please.
Image
Atmosferic
Posts: 5
Joined: 2011-05-10T15:58:06-07:00
Authentication code: 8675308

Re: Adding New File Extensions .BLP and .M3

Post by Atmosferic »

Bump..

Assistance needed.
Image
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Adding New File Extensions .BLP and .M3

Post by magick »

To consider adding support for these image format, we need a pointer to the image format specification and 3-5 example images so we can verify our work.
Atmosferic
Posts: 5
Joined: 2011-05-10T15:58:06-07:00
Authentication code: 8675308

Re: Adding New File Extensions .BLP and .M3

Post by Atmosferic »

BLP Specifications can be found here: http://en.wikipedia.org/wiki/.BLP
BLP2 Format listed below. BLP1 format is found there as well.

Code: Select all

struct BLP2Header
{
    FourCC      ID; // Always 'BLP2'
    UInt32      Type;
    UInt8       Encoding;
    UInt8       AlphaDepth;
    UInt8       AlphaEncoding;
    UInt8       HasMips;
    UInt32      Width;
    UInt32      Height;+7
    UInt32      Offsets[16];
    UInt32      Lengths[16];
    ARGBColor8  Palette[256];
};

Type
    0: JPEG compression
    1: Uncompressed or DirectX compression

Encoding
    1: Uncompressed
    2: DirectX compression

AlphaDepth
    0: No alpha channel
    1: 1 bit alpha
    4: 4 bit alpha (DXT3 only)
    8: 8 bit alpha

AlphaEncoding
    0: DXT1 alpha (0 or 1 bit alpha)
    1: DXT2/3 alpha (4 bit alpha)
    7: DXT4/5 alpha (interpolated alpha)

HasMips
    0: No mip levels
    1: Mip levels present (the number of levels is determined by the image size)

Width, Height: Dimensions of the image in pixels (always a power of two)

Offsets[0]: Offset from the start of the file to the image data
Lengths[0]: Length in bytes of the image data
Palette: 4-byte BGRA color values for paletted textures (this field is present regardless of whether the texture actually uses palettes)

The documentation for the .m3 used in (starcraft 2) files are not yet completed so I cannot provide you it at the moment.

For a pack of .blp files here are some below:
Icon Sets:
http://www.hiveworkshop.com/forums/icon ... 1306125321
http://www.hiveworkshop.com/forums/icon ... 1306125321
Skin Wrap Sets:
http://www.hiveworkshop.com/forums/skin ... 1306125392
http://www.hiveworkshop.com/forums/skin ... 1306125399
Image
Atmosferic
Posts: 5
Joined: 2011-05-10T15:58:06-07:00
Authentication code: 8675308

Re: Adding New File Extensions .BLP and .M3

Post by Atmosferic »

I made a terrible typo. I did not mean .M3 (those are model files for sc2) but .DDS (texture bit maps used in sc2). Im still looking for those specifications but I found the full specifications for the BLP 1 and BLP2 as shown below:

BLP1 and BLP2 Specifications:

Code: Select all

//+-----------------------------------------------------------------------------
//| Info
//+-----------------------------------------------------------------------------
The BLP file format!
Compiled by Magnus Ostberg (aka Magos)
MagosX@GMail.com


//+-----------------------------------------------------------------------------
//| Data types
//+-----------------------------------------------------------------------------
CHAR   - 8bit character
BYTE   - 8bit unsigned integer
WORD   - 16bit unsigned integer
DWORD  - 32bit unsigned integer
FLOAT  - 32bit floating point number
COLOR  - 32bit color value of type RGBA, one byte per channel
X[n]   - An n-dimensional vector of type X


//+-----------------------------------------------------------------------------
//| Descriptions
//+-----------------------------------------------------------------------------
[X | Y];      - Exactly one of the structures X and Y are present.

X;            - A structure that must be present.

#X            - A flag value, more than one can be combined.


//+-----------------------------------------------------------------------------
//| Notes
//+-----------------------------------------------------------------------------
- A full mipmap chain must be present. The last mipmap must be 1x1 (no larger).
  If an image is 32x8 the mipmap chain must be 32x8, 16x4, 8x2, 4x1, 2x1, 1x1.
  Sizes not of powers of 2 seems to work fine too, the same rules for mipmaps
  still applies. Ex: 24x17, 12x8 (rounded down), 6x4, 3x2, 1x1 (rounded down).


//+-----------------------------------------------------------------------------
//| BLP structure
//+-----------------------------------------------------------------------------
struct Blp
{
  DWORD 'BLP1';
  DWORD Compression;                   //0 - Uses JPEG compression
                                       //1 - Uses palettes (uncompressed)
  DWORD Flags;                         //#8 - Uses alpha channel (?)
  DWORD Width;
  DWORD Height;
  DWORD PictureType;                   //3 - Uncompressed index list + alpha list
                                       //4 - Uncompressed index list + alpha list
                                       //5 - Uncompressed index list
  DWORD PictureSubType;                //1 - ???
  DWORD MipMapOffset[16];
  DWORD MipMapSize[16];

  [BlpJpeg | BlpUncompressed1 | BlpUncompressed2]
};


//+-----------------------------------------------------------------------------
//| BLP JPEG structure (Compression == 0)
//+-----------------------------------------------------------------------------
struct BlpJpeg
{
  DWORD JpegHeaderSize;

  BYTE[JpegHeaderSize] JpegHeader;

  struct MipMap[16]
  {
    BYTE[???] JpegData;
  };

  // Up to 16 mipmaps can be stored in a blp image. 2^16 = 65536, so there's
  // little risk it won't be enough. Each JPEG (JFIF to be more exact) image
  // is constructed by merging the header with the mipmap (all mipmaps uses
  // the same header. It seems like Warcraft 3 can handle JPEG header sizes
  // of 0 (in case you have trouble generating JPEG images using the same
  // header) however there are other fan tools that does not. Specifying a
  // low number like 4 will work too as the only shared data are the initial
  // JPEG markers.
  //
  // Each mipmap has a certain size and is located at  a certain offset as
  // specified in the main blp header. There can be (and sometimes are in
  // Blizzard's images) unused space between the JPEG header and the JPEG
  // data. Why this is I don't know!
  //
  // The JPEG header of Blizzard's images is usually 624 bytes long. This
  // may or may not be true for your own generated images depending on how
  // you generated them.
  //
  // The JPEG format is advanced so I won't go into detail here.
};


//+-----------------------------------------------------------------------------
//| BLP Uncompressed 1 structure (Compression == 1, PictureType == 3 or 4)
//+-----------------------------------------------------------------------------
struct BlpUncompressed1
{
  COLOR[256] Palette;

  struct MipMap[16]
  {
    BYTE IndexList[CurrentWidth * CurrentHeight];
    BYTE AlphaList[CurrentWidth * CurrentHeight];
  };

  // CurrentWidth/CurrentHeight is the width/height for the current mipmap.
  // Mipmap size/offset works the same as explained for JPEGs above.
  //
  // Each cell in the index list refers to a location in the palette where
  // the corresponding RGB value is (the palette is still RGBA, but A is not
  // used). The alpha list contains the alpha value for the pixel.
};


//+-----------------------------------------------------------------------------
//| BLP Uncompressed 2 structure (Compression == 1, PictureType == 5)
//+-----------------------------------------------------------------------------
struct BlpUncompressed2
{
  COLOR[256] Palette;

  struct MipMap[16]
  {
    BYTE IndexList[CurrentWidth * CurrentHeight];
  };

  // CurrentWidth/CurrentHeight is the width/height for the current mipmap.
  // Mipmap size/offset works the same as explained for JPEGs above.
  //
  // Each cell in the index list refers to a location in the palette where
  // the corresponding RGBA value is. The alpha value is inversed so the real
  // alpha is "255 - alpha".
};

Image
Post Reply