Circuit-Swap mechanism on going (BMP->PPM) Reffering other "Stack Exchange" Sources, I've been told that the only way of swapping BGR to RGB involves buffering. While this isn't true, I could just perofrm a quick C-SA algorithm on fseek or bmp buffer byte offsets. I wrote a fast implementation of fwrite, that swaps the first byte with the 3rd. I do believe that this operation is not slower then the regular one.

size_t fwrite_ps ( const void * ptr, size_t size, size_t count, FILE * stream )
{
    size_t i, chr = 0;
    char p;
    signed pc = 0;

    for(i = 0; i != count * size; i++)
    {
        switch(pc)
        {
            case 1  :   p = 0;          break;
            case 2  :   p = (-2);       break;
            default :   p = 2; pc = 0;  break;
        }

        if( fputc( ((unsigned char*)ptr)[(i+p) - 0], stream ) != EOF ) { chr++; pc++; }
        else                                                           { break; }
    }
    return chr / size;
}


I like my style of codding. For me, it is pretty readable even after years. If it is not as readable for others, it might be because they are most likely used to other, more common styles.

I would like to enhance the utility of this, so i will also provide a really fast way of copying pixels in the proper order. Except functional and fast, it also simplifies varieties of different standarts. It will not copy padding and it involves only one loop.

#define IMAGE_NAME "sample.bmp"

typedef unsigned short WORD;
typedef unsigned long DWORD;

DWORD WIDTH     = BMPDATA[18] + BMPDATA[19] * 256; // Max width 65791
DWORD HEIGHT    = BMPDATA[22] + BMPDATA[23] * 256; // Max height 65791
DWORD h;
FILE* fp = fopen(IMAGE_NAME, "rb");

fprintf(fp, "P6\n%i %i\n%i\n", WIDTH, HEIGHT, 255);  // Copies PPM data

for(h = (HEIGHT-1)*((WIDTH*3) + WIDTH%4); h&gt;=0; h -= (WIDTH*3) + (WIDTH%4))
{
    fwrite_ps(&amp;BMPDATA[BMPDATA[10] + h], 1, WIDTH*3, fp);
}
// BMPDATA is your buffer containing a bmp image.
Magic numbers

What is the significance of 18, 19, 22 and 23? They must be defined in terms of bitmap file header and bitmap info header
Correctness


According to a spec, bitmap width and bitmap height are 4 byte integers. The code accounts only for 2 bytes.
The code completely ignores colour depth.
The code is unable to deal with palette-based bitmaps.
The code completely ignores possible DIB compression.

Style


All-uppercase words are usually reserved for macros. Normal variable's identifiers should be in snake_case or camelCase.
What is the purpose of typedefing DWORD?
You should at least make your snippet into a function. Otherwise it is completely useless.