Assumptions: Data is unsigned char pointer to bitmap, Width and Height are dimensions, and Pitch is bytes between rows (often just Width). DONTBURN is number of edge pixels to skip. BURNFADE is speed to fade out buffer.
This is highly simplified, and doesn't include handy optimizations such as using 32-bit integer or 64-bit FPU reads to quickly skip over burning large chunks of the buffer that are all 0. That's left as an exercise for the performance programmer.
unsigned char *line; //Pointer to start of current line.
for(y = DONTBURN; y < Height - DONTBURN; y++)
line = Data + y * Pitch;
for(x = DONTBURN; x < Width - DONTBURN; x++)
pixel = ((line[x] + line[x - 1] + line[x + 1] +
line[x + Pitch]) >>2) - BURNFADE;
line[x] = (pixel < 0 ? 0 : pixel); //Don't write < 0.
[size="5"]April 13th Update:
Here are a couple of other interesting things that Particle Fire does to achieve its effects. The "sparklies" in the darker flame are produced by simply iterating over each line of the buffer, selecting one random X pixel along that line, testing it to see if it is darker than a certian threshold, and if it is, it brightening it by writing a slightly lighter color into the buffer. The wall of flame along the bottom or top is produced by simply setting pixels in the furthest top or bottom burnable line of the buffer each frame. Two algorithms are used, a mostly random one where each pixel can change up or down by a random amount each frame, and a more ordered 1-dimensional Perlin Noise functions that produces a much "smoother" flame.
[size="2"] Copyright 1998-1999 by Seumas McNally.
No reproduction may be made without the author's written consent.
Courtesy Of Longbow Digital Artists