Patch

From ZDoom Wiki

Jump to: navigation, search

A patch is simply a collection of pixels stored in the graphic format native to Doom. All graphics in Doom with the exception of flats are patches. This includes all sprites, wall patches and all the other random graphics such as TITLEPIC and M_DOOM (which are the titlepic and Doom logo, respectively). Patches are useful because they take up a fairly small amount of disk space since they don't store any palette information (that's all stored in the PLAYPAL and COLORMAP lumps) and they can have transparency (though contrary to an enormous popular belief, transparency is not based on a specific index and certainly not on the color cyan, which isn't even in the Doom palette).

Specification

Getting more in depth, patches have three sections to them. The first is an 8 byte header with the following sections. As usual for Doom data, all integers are stored little-endian.



Bytes Data Type Description
0-1 Unsigned Short Width
2-3 Unsigned Short Height
4-5 Signed Short X Offset
6-7 Signed Short Y Offset


Next is a group of long integers (4 bytes) which are pointers to each column of the image. The number of pointers is equal to the width of the image. A column is a vertical arrangement of single pixels. Due to transparency, columns don't always have the same size which is why the offsets are necessary.

At the beginning of each column, there is another 3 byte header which is as follows:



Byte Description
1 Y Position to begin drawing this span
2 Number of pixels in this span
3 Garbage byte; Unused


After the header, each non-transparent pixel is a value from 0-255 which corresponds to a color in the PLAYPAL lump. If the column has a transparent area, then there is another header type entry which tells where to start and stop drawing the next position in the column. Each column ends with the last two bytes set to values 0 and 255. A column that has 255 for the first byte in the header is a completely empty column.

Large Graphics

ZDoom and Boom allow for textures larger than 255 pixel tall, unlike vanilla Doom. The extra picture data always starts with FE (254) as the Y start position and 01 as the Y stop position so that one pixel is drawn where the column was last drawn. Afterwards, there is another set of Y Start and Y Stop bytes which is of variable length just like a normal column. This pattern is continued if the texture is large enough. For example, a 258 pixel tall texture would have one column of extra data and a 516 pixel tall texture would have two columns of extra data. If the column starts beyond the 255th pixel, the column start and stop bytes will be FE 00 followed by 00 00 then and this pattern continues depending on how far down the column starts.

Retrieved from "http://zdoom.org/wiki/Patch"
Personal tools