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.bmptypedef unsigned short WORD;typedef unsigned long DWORD;DWORD WIDTH     = BMPDATA[18] + BMPDATA[19] * 256; // Max width 65791DWORD HEIGHT    = BMPDATA[22] + BMPDATA[23] * 256; // Max height 65791DWORD h;FILE* fp = fopen(IMAGE_NAME, rb);fprintf(fp, P6\n%i %i\n%i\n, WIDTH, HEIGHT, 255);  // Copies PPM datafor(h = (HEIGHT-1)*((WIDTH*3) + WIDTH%4); h>=0; h -= (WIDTH*3) + (WIDTH%4)){    fwrite_ps(&BMPDATA[BMPDATA[10] + h], 1, WIDTH*3, fp);}// BMPDATA is your buffer containing a bmp image.
Circuit-Swap mechanism on going (BMP->PPM)
c;image;graphics
In fwrite_ps, the purpose of the switch seem to be to rotate the values of p as 2 -> 0 -> -2. Unless I'm overlooking something, it seems to me you could use i and some modulo and arithmetics for the same effect, like this:for(i = 0; i != count * size; i++){    // i = 0 => -2 * -1 = 2    // i = 1 => -2 *  0 = 0    // i = 2 => -2 *  1 = -2    p = -2 * (i % 3 - 1);    if( fputc( ((unsigned char*)ptr)[(i+p) - 0], stream ) != EOF ) { chr++; }    else                                                           { break; }}About using all-cap names not for macros...The reason why all-caps is not so good for pretty much anything is that it's typically used for macros. One day you might include a header file that defines a macro that conflicts with a variable name you defined and your build will fail spectacularly with bizarre errors.