2

Gostaria de sabe como faço para espelhar uma imagem. Consegui um algoritmo, mas ele só inverte imagens com resolução 60x60 e bpp=1.

Tenho o seguinte modelo de imagem para testar:

unsigned char icon[] ={ 
    //HEADER
    0x42, 0x4D,             // 0-1   BM 
    0xF6, 0x07, 0x00, 0x00, // 2-5   uint32 filesize (not reliable) 
    0x00, 0x00, 0x00, 0x00, // 6-9   uint32 0
    0x76, 0x00, 0x00, 0x00, // 10-13 uint32 bitmapOffset

    0x28, 0x00, 0x00, 0x00, // 14-17 uint32 info size
    0x3C, 0x00, 0x00, 0x00, // 18-21 int32  width
    0x3C, 0x00, 0x00, 0x00, // 22-25 int32  height
    0x01, 0x00,             // 26-27 uint16 nplanes
    0x04, 0x00,             // 28-29 uint16 bits per pixel bpp bitCount 
    0x00, 0x00, 0x00, 0x00, // 30-33 uint32 compression flag
    0x00, 0x00, 0x00, 0x00, // 34-37 uint32 image size in bytes
    0xC4, 0x0E, 0x00, 0x00, // 38-41 int32  biXPelsPerMeter 
    0xC4, 0x0E, 0x00, 0x00, // 32-45 int32  biYPelsPerMeter
    0x00, 0x00, 0x00, 0x00, // 46-49 uint32 colors used
    0x00, 0x00, 0x00, 0x00, // 50-53 uint32 important color count
    //*********************************************
    //Dados da imagem:
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x80, 
0x00, 0x00, 0x00, 0x80, 0x80, 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x80, 
0x00, 0x00, 0x80, 0x80, 0x80, 0x00, 0xC0, 0xC0, 0xC0, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 
0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0xFF, 
0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,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temos uma imagem 10x10 pixels, com bpp=1. O tamanho da linha seria de 10 bits? Será que tenho que inverter esses bits por linha, para ter o resultado almejado? Alguém sabe como se faz isso?

Eis o algoritmo que tenho:

int getBytesPerRow(int bpp, int width)
{
    switch (bpp)
    {
    case 1: return (width >> 3) + ((width & 0x7) == 0 ? 0 : 1);
    case 4: return (width >> 1) + ((width & 0x1) == 0 ? 0 : 1);
    case 8: return width;
    case 24: return width * 3;
    default: return -1;
    }
}

void ImageMirror(uchar *bmpBytes, int width, int height, int lenght, int bpp)
{

    int32 bmpRowLength;
    int32 imgRowLength;
    int32 imgRow;

    struct ImageInfo imageInfo;

    imageInfo.width = width;
    imageInfo.height = height;
    imageInfo.bpp = bpp;

    // imRowLength is the number of bytes that represent each line
    // bmpRowLength is the length of line in pixels and should be rounded to the next 32 bits boundary
    imgRowLength = getBytesPerRow(imageInfo.bpp, imageInfo.width);
    bmpRowLength = (imgRowLength & 0xFFFC) + ((imgRowLength & 3) == 0 ? 0 : 4);

    imageInfo.imageLength = imgRowLength * imageInfo.height;

    imageInfo.imageBytes = wabaVm->Malloc(imageInfo.imageLength);

    // invert the image, so it's stored upside up
    for (imgRow = 0; imgRow < imageInfo.height; imgRow++)
    {
        // if row size is less than the number of pixels per row
        int index = imgRow * imgRowLength;
        uchar *bmpRow = &bmpBytes[(imageInfo.height - imgRow - 1) * bmpRowLength];
        uchar *imgRow = &imageInfo.imageBytes[index];
        memcpy(imgRow, bmpRow, imgRowLength);
    }
    memset(bmpBytes, 0, lenght);
    memcpy(bmpBytes, imageInfo.imageBytes, lenght);
    Free(imageInfo.imageBytes);
}
5
  • Não sei o que você entende como C puro, mas pelo menos alguma biblioteca gráfica você terá que utilizar.
    – anonimo
    16/03/2019 às 13:31
  • C puro, sem ser C++. C baixo nível. O que quero é para imprimir imagem em uma impressora térmica. A imagem está saindo invertida e de ponta cabeça. Preciso de um algoritmo que ajeite a imagem. 16/03/2019 às 15:34
  • Importante editar postando o que tentou e deixando bem clara a dificuldade encontrada. Códigos prontos, tutoriais e dúvidas que dependam de vários conhecimentos diferentes aplicados normalmente não se encaixam bem no escopo do site em uma única pergunta. Se tiver dúvida em partes específicas, pode postar um Exemplo Mínimo, Completo e Verificável da etapa atual do problema, e resolvendo, pode abrir perguntas em separado sobre os passos seguintes, cada uma focada em um problema específico.
    – Largato
    18/03/2019 às 16:23
  • @Bacco Coloquei mais informações em relação minha dúvida. 20/03/2019 às 19:35
  • Você talvez encontre um algoritmo em C++ que possa compilar para realizar a inversão. O OpenCV é uma biblioteca aberta de visão computacional e tem implementações bem eficientes para esse tipo de operação. 25/03/2019 às 0:47

3 Respostas 3

1

Considerando que sua imagem seja algo como:

/* Imagem 13x10 */
char image[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0,
                 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0,
                 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0,
                 0, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 0,
                 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0,
                 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0,
                 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0,
                 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0,
                 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };

Para inverte-la, você pode fazer a troca dos pixels contidos no começo da imagem com os pixels contidos no final da imagem, veja só:

void image_mirror( char * img, int width, int height )
{
     /* Pixel auxiliar */
    char aux = 0;

    /* Pixel canto superior esquerdo */
    char * a = img;

    /* Pixel canto inferior direito */
    char * b = &img[ ( height * width ) - 1 ];

    /* Troca os pixels do comeco com os pixels do final */
    for( ; a < b; a++, b-- )
    {
        aux = *a;
        *a = *b;
        *b = aux;
    }
}

Colocando tudo junto:

#include <stdio.h>


void image_show( char * img, int width, int height )
{
    int i = 0;
    int w = 0;
    int h = 0;

    for( h = 0; h < height; h++ )
    {
        for( w = 0; w < width; w++ )
            printf( "%s", img[i++] ?  "X " : "  " );
        printf( "\n" );
    }
}


void image_mirror( char * img, int width, int height )
{
    char aux = 0;    
    char * a = img;
    char * b = &img[ ( height * width ) - 1 ];

    for( ; a < b; a++, b-- )
    {
        aux = *a;
        *a = *b;
        *b = aux;
    }
}


int main( int argc,char ** argv )
{
    /* Imagem 13x10 */
    char image[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                     0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0,
                     0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0,
                     0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0,
                     0, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 0,
                     0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0,
                     0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0,
                     0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0,
                     0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0,
                     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };

    printf("Imagem Original:\n");
    image_show( image, 13, 10 );

    /* Inverte imagem de ponta a cabeca */
    image_mirror( image, 13, 10 );

    printf("Imagem Invertida:\n");
    image_show( image, 13, 10 );

    return 0;
}

Saída:

Imagem Original:

    X X           X
        X       X
      X X X X X X X
    X X   X X X   X X
  X X X X X X X X X X X
  X   X X X X X X X   X
  X   X           X   X
        X X   X X

Imagem Invertida:

        X X   X X
  X   X           X   X
  X   X X X X X X X   X
  X X X X X X X X X X X
    X X   X X X   X X
      X X X X X X X
        X       X
      X           X X

Veja funcionando no Repl.it

8
  • Obrigada Lacobus. Com 0 e 1 funciona bem, mas se eu colocar valores: 0xFF, 0x00, 0x0C..., que correspondem aos dados da imagem, não funciona muito bem, fica com sujeira na imagem. E o tamanho width x height também não funciona bem. No cabeçalho da imagem tem o tamanho, então substituo por esses valores. Tem algo faltando, preciso saber o que é. 18/03/2019 às 1:55
  • Apenas usei o formato de imagem mais primitivo que eu pude imaginar para exemplificar. Qual é o formato da imagem na qual você está trabalhando ? Quantos bits ela possui por pixel ?
    – Lacobus
    18/03/2019 às 2:42
  • Varia... Depende da imagem que eu for abrir pra mandar imprimir. Peguei um exemplo pequeno, o bpp é 2, uma imagem 2x2 peguei como exemplo... 18/03/2019 às 3:14
  • Eu tenho que pegar os dados da imagem e transformar em bmp. Até aí tudo bem. Só o problema é que sai espelhada a imagem, pois o formato bmp é invertido, por isso tenho que inverter a imagem. 18/03/2019 às 3:32
  • @BiancaNunes: Qual é o formato da imagem de origem ? Tem como postar uma como exemplo/amostra ?
    – Lacobus
    18/03/2019 às 14:25
0

"(...) como faço para espelhar uma imagem. (...) Será que tenho que inverter esses bits por linha, para ter o resultado almejado? (...)"

Se a intenção é espelhar uma imagem na horizontal com 1 bit por pixel (1bpp), a resposta à pergunta é sim. Da mesma forma que é necessário inverter a ordem byte por linha, também é necessário inverter a ordem pixel dentro de 1 byte.

O exemplo de "modelo de imagem para testar" da pergunta é uma imagem BMP com 4 bits por pixel (4bpp), neste caso é necessário inverter, não a ordem bit, mas a ordem nibble (4 bits).

Imagens BMP 1bpp, 4bpp e 8bpp:

Para fazer espelhos na horizontal no formato pixel 1bpp (1 pixel por bit, ou seja, 8 pixeis por byte) é necessário inverter a ordem bit. Por exemplo, inverter a ordem bit de um byte (8 pixeis):

mirrored_Pixels_Per_Byte = (b & 128) >> 7 | (b & 64) >> 5 | (b & 32) >> 3 | (b & 16) >> 1 | (b & 8) << 1 | (b & 4) << 3 | (b & 2) << 5 | (b & 1) << 7;

Para fazer espelhos na horizontal no formato pixel 4bpp (1 pixel por cada 4 bits, ou seja, 2 pixeis por byte) é necessário inverter a ordem nibble (4 bits). Por exemplo, inverter a ordem nibble de um byte (2 pixeis):

mirrored_Pixels_Per_Byte = (b & 15) << 4 | (b >> 4);

Para fazer espelhos na horizontal no formato pixel 8bpp (1 pixel por cada 8 bits, ou seja, 1 pixel por byte) basta copiar. Este é o formato mais simples, visto que um pixel é igual a um byte. Por exemplo:

mirrored_Pixel = b;

O problema é que para 1bpp (quando o valor "width" da imagem em pixeis não é um múltiplo de 8) e 4bpp (quando o valor "width" da imagem em pixeis não é um múltiplo de 2) nem tudo são pixeis dentro de um byte.

Por exemplo uma imagem 1bpp com 9 pixeis x 2 pixeis (width x height):

Como 9 bit-pixeis por linha ("width") não cabem em 2 bytes completos (16 bit), o último byte de cada linha de pixeis é composto por 1 bit-pixel + 7 bits de valor 0.

Estes 7 bits de valor 0 não são pixeis e devem ser mantidos no final de cada linha de pixeis. Se forem movidos para o início de cada linha serão interpretados erradamente como pixeis e verá uma linha adicional (vertical) com 7 pixeis de largura do lado esquerdo da imagem.

Isto é válido para eventuais bytes de preenchimento "padding for 4 byte alignment" especificados para o formato de imagem BMP.

Por exemplo como 2 bytes (8 bit-pixeis + 1 bit-pixel + 7 bits de valor 0) não são um múltiplo de 4 bytes, "padding for 4 byte alignment", cada linha da imagem, neste caso, será composta por 2 bytes + 2 bytes adicionais de preenchimento. Os valores byte de preenchimento para "padding for 4 byte alignment" podem ser 0 ou qualquer outro e o seu valor não é importante.

Este "padding for 4 byte alignment" é obrigatório e a sua ausência, quando uma linha de pixeis não for um múltiplo de 4 bytes, gera um erro na imagem.

#include <stdio.h>

unsigned char icon[] ={ // bitmap 4bpp
// BITMAP FILE HEADER
       66, 77, //   0-1 (2 bytes uint16) "BM"
 246, 7, 0, 0, //   2-5 (4 bytes uint32) File size in bytes. Exemplo de como transfromar 4 bytes LE em um número: ( ( 246 ) << 0) | ( ( 7 ) << 8) | ( ( 0 ) << 16) | ( ( 0 ) << 24) = 2038
         0, 0, //   6-7 (2 bytes uint16) Reserved
         0, 0, //   8-9 (2 bytes uint16) Reserved
 118, 0, 0, 0, // 10-13 (4 bytes uint32) Offset where the image data (pixel array) can be found
// DIB HEADER
  40, 0, 0, 0, // 14-17 (4 bytes uint32) Size of DIB header in bytes
  60, 0, 0, 0, // 18-21 (4 bytes  int32) Image Width in pixels
  60, 0, 0, 0, // 22-25 (4 bytes  int32) Image Height in pixels
         1, 0, // 26-27 (2 bytes uint16) Number of color planes (must be 1)
         4, 0, // 28-29 (2 bytes uint16) Number of bits per pixel (bpp) (must be 1, 2, 4, 8, 16, 24 or 32). Exemplo de como transfromar 2 bytes LE em um número: ( ( 4 ) << 0) | ( ( 0 ) << 8) = 4
   0, 0, 0, 0, // 30-33 (4 bytes uint32) Value of compression method (can be 0, 1, 2, 3, 4, 5 or 6) (0 == compression none BI_RGB)
   0, 0, 0, 0, // 34-37 (4 bytes uint32) Size of image data (pixel array); a dummy 0 can be given for BI_RGB bitmaps
196, 14, 0, 0, // 38-41 (4 bytes uint32) Horizontal resolution of the image (pixels per meter)
196, 14, 0, 0, // 42-45 (4 bytes uint32) Vertical resolution of the image (pixels per meter)
  16, 0, 0, 0, // 46-49 (4 bytes uint32) Number of colors in the color palette
  16, 0, 0, 0, // 50-53 (4 bytes uint32) Number of important colors used, or 0 when every color is important; generally ignored
// COLOR PALETTE (color array)
  0,   0,   0, 255, // RGB (BGR LE)
  0,   0, 128, 255, // The number of entries is equal to the maximum size possible for the color palette (ncolors = 1 << bpp; or pow(2, bpp);)
  0, 128,   0, 255, // O valor da 4ª coluna deve ser ignorado e intrepretado como padding.
  0, 128, 128, 255, // O valor da 4ª coluna pode, ou deveria, ser 0.
128,   0,   0, 255, // Quando DIB header size == 12 só existem 3 colunas.
128,   0, 128, 255,
128, 128,   0, 255,
128, 128, 128, 255,
192, 192, 192, 255,
  0,  0,  255, 255,
  0, 255,   0, 255,
  0, 255, 255, 255,
255,   0,   0, 255,
255,   0, 255, 255,
255, 255,   0, 255,
255, 255, 255, 255,
// IMAGE DATA (pixel array)
/** Row of pixels (scan-line) ---> (60 pixeis * 4bpp / 8 = 30 bytes)                                                                               */
/** Para 4bpp cada byte contem 2 pixeis                                                                                                            */
/** 4bpp (1 pixel por cada 4 bits ---> 2 pixeis por byte) (2 nibbles por byte)                                                                     */
/** Row of pixels tem que ser um múltiplo de 8 bits. Exemplo: ((59 pixeis * 4bpp) + 8 - 1 - ((59 pixeis * 4bpp) + 8 - 1) % 8) / 8 = 30 bytes       */
/** Se o valor Width não for múltiplo de 2 o último byte de Row of pixels é composto por 1 nibble-pixel + 1 nibble de valor 0(extra padding nibble)*/
/** Para 4bpp cada nibble-pixel representa um índice referente a uma cor contida na palete de cores                                                */
/** Para extrair 2 nibbles (2 índices) de 1 byte: left_nibble = byte >> 4; right_nibble = byte & 15                                                */
/** Para inverter a ordem nibble de 1 byte (espelhar 1 byte composto por 2 nibbles): (byte & 15) << 4 | (byte >> 4)                                */
/** Para transformar 2 nibbles em 1 byte: (left__nibble << 4) | right_nibble                                                                       */
/** Se o valor Height da imagem for positivo os pixeis são armazenados a partir do canto inferior direito (1º pixel) para o canto superior esquerdo*/
/** Se o valor Height da imagem for negativo os pixeis da imagem são armazenados do canto superior esquerdo para o canto inferior direito          */
/** O valor Height negativo é válido para bitmaps sem compressão e DIB header size > 12                                                            */
/** Para converter um número negativo para 4 bytes LE, por exemplo -60:                                                                            */
/** nB1 = ( -60 ) >> 0 & 255; nB2 = ( -60 ) >> 8 & 255; nB3 = ( -60 ) >> 16 & 255; nB4 = ( -60 ) >> 24 & 255;                                      */
/**/255,/*<--- os últimos 2 pixeis da imagem*/ 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, /**/0, 0,/** Padding for 4 byte alignment (scan-line boundary padding), could be a value other than zero. */
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, /**/0, 0,/** Se "Row of Pixels" (scan-line) não for um múltiplo de 4 bytes "Total Row Size" (stride) será (RowOfPixelsize + 4 - 1 - (RowOfPixelsize + 4 - 1) % 4) */
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, /**/0, 0,/** Exemplo: 30 bytes + 4 - 1 - (30 bytes + 4 - 1) % 4 = 32 bytes */
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 131, 153, 153,  51,  59, 184, 143, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 248, 153, 153, 153, 153,  51, 187, 179,  59, 143, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0,
255, 255, 255, 255, 255, 255, 255, 255, 255, 248, 153, 153, 153, 153,  51, 139, 187, 179, 187,  59, 143, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0,
255, 255, 255, 255, 255, 255, 255, 255, 255, 153, 153, 153, 143, 255, 255, 255, 255, 248, 179,  59,  59, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0,
255, 255, 255, 255, 255, 255, 255, 255, 137, 153, 151, 255, 255, 255, 255, 255, 255, 255, 255, 139,  59,  56, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0,
255, 255, 255, 255, 255, 255, 255, 248, 153, 147, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 179, 179, 143, 255, 255, 255, 255, 255, 255, 255, 0, 0,
255, 255, 255, 255, 255, 255, 255, 121, 153, 143, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 248,  59,  56, 255, 255, 255, 255, 255, 255, 255, 0, 0,
255, 255, 255, 255, 255, 255, 248, 153, 152, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 251, 179, 143, 255, 255, 255, 255, 255, 255, 0, 0,
255, 255, 255, 255, 255, 255, 137, 153, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 187,  56, 255, 255, 255, 255, 255, 255, 0, 0,
255, 255, 255, 255, 255, 255, 153, 152, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 243, 179, 255, 255, 255, 255, 255, 255, 0, 0,
255, 255, 255, 255, 255, 249, 153, 143, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 248,  59, 191, 255, 255, 255, 255, 255, 0, 0,
255, 255, 255, 255, 255, 137, 147, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 131,  56, 255, 255, 255, 255, 255, 0, 0,
255, 255, 255, 255, 255, 153, 159, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 251, 187, 255, 255, 255, 255, 255, 0, 0,
255, 255, 255, 255, 248, 153, 143, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 248,  51, 143, 255, 255, 255, 255, 0, 0,
255, 255, 255, 255, 249, 153, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 179, 191, 255, 255, 255, 255, 0, 0,
255, 255, 255, 255, 137, 152, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 131,  56, 255, 255, 255, 255, 0, 0,
255, 255, 255, 255, 153, 159, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 251,  59, 255, 255, 255, 255, 0, 0,
255, 255, 255, 255, 136, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 136, 255, 255, 255, 255, 0, 0,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0,
255, 255, 119, 143, 255, 255, 119, 143, 255, 248, 119, 255, 119, 119, 127, 255, 248, 119, 119, 143, 248, 119, 255, 255, 247, 120, 247, 120, 255, 255, 0, 0,
255, 255,  64, 127, 255, 255,  68, 111, 255, 244,  68, 244,  68,  68,  68, 143, 128,  68,  68,  70, 248,   0, 127, 255, 132,   7, 244,   6, 255, 255, 0, 0,
255, 255,  68, 127, 255, 255, 116,  79, 255, 244,  71, 246,  70, 102,  68,  79, 132,  70, 100,  68, 127,  68, 111, 255, 116,  72, 246,  70, 255, 255, 0, 0,
255, 255,  68, 127, 255, 255, 132,  70, 102, 100,  72, 255, 255, 255, 100,  15, 248, 255, 248,  68, 111, 116,  70, 103, 100,  79, 246,  70, 255, 255, 0, 0,
255, 255,  68, 127, 255, 255, 244,  68,  68,  68,  79, 255, 255, 255, 116,  15, 255, 255, 255,  68, 111, 132,  68,  68,  68, 111, 246,  70, 255, 255, 0, 0,
255, 255,  68,  68,  70, 143, 246,  68, 119,  68, 127, 255, 248, 118,  68,  79, 255, 248, 118,  68, 111, 244,  70, 119,  68, 143, 246,  70, 255, 255, 0, 0,
255, 255,  68,  68,  68,  72, 247,  68, 255,  68, 143, 255, 100,  68,  68, 127, 248, 100,  68,  68, 143, 246,  70, 247,  68, 255, 246,  70, 255, 255, 0, 0,
255, 255,  68, 103, 116,  68, 255,  68, 136,  68, 255, 246,  68,  68, 104, 255, 244,  68,  68, 104, 255, 247,  68, 246,  70, 255, 246,  70, 255, 255, 0, 0,
255, 255,  68, 127, 246,  68, 255,  68, 119,  70, 255, 244,  68, 143, 255, 255, 132,  70, 255, 255, 255, 255,  68, 132,  71, 255, 246,  70, 255, 255, 0, 0,
255, 255,  68, 127, 246,  68, 255, 116, 100,  71, 255, 244,  70, 255, 255, 255, 116,  72, 255, 255, 255, 255,  68, 116,  72, 255, 246,  70, 255, 255, 0, 0,
255, 255,  68, 103, 116,  68, 255, 132,  68,  72, 255, 244,  68, 119, 118, 143, 132,  68, 119, 118, 255, 255, 116,  68,  79, 255, 246,  70, 255, 255, 0, 0,
255, 255,  68,  68,  68,  72, 255, 244,  68,  79, 255, 247,  68,  68,  64, 111, 246,  68,  68,  64, 143, 255, 132,  68, 127, 255, 244,  70, 255, 255, 0, 0,
255, 255, 102, 102, 102, 143, 255, 247, 102, 127, 255, 255, 134,  68, 102, 143, 255, 118,  68, 103, 255, 255, 246, 100, 143, 255, 246, 103, 255, 255, 0, 0,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 143, 255, 255, 0, 0,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 247,   6, 143, 255, 0, 0,
255, 255, 255, 255, 187, 191, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 246, 102, 255, 100,   8, 255, 0, 0,
255, 255, 255, 255, 139, 184, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 134, 104, 255, 247,  79, 255, 0, 0,
255, 255, 255, 255, 251, 187, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 230, 111, 255, 255, 255, 255, 0, 0,
255, 255, 255, 255, 248, 187, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 248, 102, 127, 255, 255, 255, 255, 0, 0,
255, 255, 255, 255, 255, 187, 191, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 246, 102, 143, 255, 255, 255, 255, 0, 0,
255, 255, 255, 255, 255, 139, 184, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 134, 103, 255, 255, 255, 255, 255, 0, 0,
255, 255, 255, 255, 255, 251, 187, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 102, 111, 255, 255, 255, 255, 255, 0, 0,
255, 255, 255, 255, 255, 255, 187, 191, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 246, 102, 143, 255, 255, 255, 255, 255, 0, 0,
255, 255, 255, 255, 255, 255, 139, 187, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 102, 103, 255, 255, 255, 255, 255, 255, 0, 0,
255, 255, 255, 255, 255, 255, 251, 187, 191, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 246, 102, 111, 255, 255, 255, 255, 255, 255, 0, 0,
255, 255, 255, 255, 255, 255, 255, 187, 187, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 248, 102, 102, 255, 255, 255, 255, 255, 255, 255, 0, 0,
255, 255, 255, 255, 255, 255, 255, 251, 187, 184, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 134, 102, 111, 255, 255, 255, 255, 255, 255, 255, 0, 0,
255, 255, 255, 255, 255, 255, 255, 255, 187, 187, 184, 255, 255, 255, 255, 255, 255, 255, 255, 134, 102, 102, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0,
255, 255, 255, 255, 255, 255, 255, 255, 248, 187, 187, 184, 255, 255, 255, 255, 255, 255, 134, 102, 102, 143, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0,
255, 255, 255, 255, 255, 255, 255, 255, 255, 251, 187, 187, 187, 136, 136, 136, 135, 102, 102, 102, 239, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 251, 187, 187, 187, 187, 102, 102, 102, 102, 104, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 248, 187, 187, 187, 102, 102, 110, 143, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 248, 136, 136, 136, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, /**/255,/*<--- os primeiros 2 pixeis da imagem*/ 0, 0,
};
0

"(...) como faço para espelhar uma imagem. (...) Será que tenho que inverter esses bits por linha, para ter o resultado almejado? (...)"

Continuação...

// continuação...
struct BMInfos {
    int isBM;
    int bpp;
    int Width;
    int absHeight;
    int StartOfImageDataOffset;
    int ImageDataSize;
    int TotalRowSize;
    int PixelRowSize;
    int PadSize;
    int isCompressed;
} inf;

void SetInfos() {
    inf.isBM = (icon[0] == 'B' && icon[1] == 'M');
    inf.StartOfImageDataOffset = (icon[10] << 0) | (icon[11] << 8) | (icon[12] << 16) | (icon[13] << 24);
    int dibSize = (icon[14] << 0) | (icon[15] << 8) | (icon[16] << 16) | (icon[17] << 24);
    inf.Width = (dibSize == 12) ? (icon[18] << 0) | (icon[19] << 8) : (icon[18] << 0) | (icon[19] << 8) | (icon[20] << 16) | (icon[21] << 24);
    int Height = (dibSize == 12) ? (icon[20] << 0) | (icon[21] << 8) : (icon[22] << 0) | (icon[23] << 8) | (icon[24] << 16) | (icon[25] << 24);
    inf.absHeight = (Height + (Height >> 31)) ^ (Height >> 31); /** O valor de "Height" pode ser negativo ou positivo. */
    inf.bpp = (dibSize == 12) ? (icon[24] << 0) | (icon[25] << 8) : (icon[28] << 0) | (icon[29] << 8);
    int Compression = (dibSize != 12) ? (icon[30] << 0) | (icon[31] << 8) | (icon[32] << 16) | (icon[33] << 24) : 0;
    inf.isCompressed  = (!(Compression == 0 || (Compression == 3 && (inf.bpp == 16 || inf.bpp == 32))));
    inf.ImageDataSize = ((((inf.Width * inf.bpp) + 31) & ~31) >> 3) * inf.absHeight;
    inf.PixelRowSize  = ((((inf.Width * inf.bpp) +  7) &  ~7) /  8); /** Tem que ser um múltiplo de 8 bits. (scan-ine)*/
    inf.TotalRowSize  = ((((inf.Width * inf.bpp) + 31) & ~31) >> 3); /** Tem que ser um múltiplo de 4 bytes. (stride)*/
    inf.PadSize = inf.TotalRowSize - inf.PixelRowSize; /** Os valores byte de prenchimento de linha para TotalRowSize "padding for 4 byte alignment" podem ser zero(s) ou qualquer outro valor. */
    int extraPaddingBitLevel = ((inf.PixelRowSize * 8) - (inf.Width * inf.bpp)) / inf.bpp; /** n bits|nibbles de prenchimento (nível bit) para PixelRowSize, "padding for 8 bit alignment". */

    printf( "\nBits per pixel: %d bpp", inf.bpp );
    printf( "\nImage width: %d pixels", inf.Width );
    printf( "\nImage height: %d pixels", inf.absHeight );
    printf( "\nStart of image data offset: %d", inf.StartOfImageDataOffset );
    printf( "\nImage data size: %d bytes", inf.ImageDataSize );
    printf( "\nTotal row size: %d bytes", inf.TotalRowSize );
    printf( "\nPixel row size: %d bytes", inf.PixelRowSize );
    printf( "\nPadding size: %d bytes", inf.PadSize );
    printf( "\nExtra padding, bit level: %d %s", extraPaddingBitLevel, inf.bpp == 1 ? "bits" : inf.bpp == 4 ? "nibbles" : "" );
    printf( "\nCompression value: %d", Compression );
    printf( "\nIs compressed: %s\n", inf.isCompressed ? "true" : "false" );
}

void Mirror() { // Espelhar um bitmap na horizontal
    int s = inf.StartOfImageDataOffset;
    int e = inf.StartOfImageDataOffset + (inf.ImageDataSize - 1) - inf.PadSize;

    if (inf.bpp == 1) {
        /** 1bpp (8 pixels por byte ---> 1 pixel por cada bit) (2 cores indexadas RGB (BGR LE)) */
        char auxT[inf.ImageDataSize * 8];
        int extraPaddingBits = ((inf.PixelRowSize * 8) - (inf.Width * inf.bpp)) / inf.bpp; /** Extra "padding", nível bit. Se existir, ... */
        /** ... por exemplo quando o valor "Width" da imagem não é um múltiplo de 8 os últimos bit-pixeis de cada linha de pixeis não cabem em 1 byte completo sendo este último byte constituído por n bit-pixeis + n bits de valor 0. */

        /** Converte todas as sequências byte em bit-pixeis (índices) invertendo a sua ordem por linha mas mantendo os bits de preenchimento no final de cada linha. Todos os bits serão armazenados temporariamente em auxT. */
        int k = 0;
        while (s <= e) {
            int i = 0;
            int j = inf.PixelRowSize;
            while (j--) {
                int l = (extraPaddingBits != 0 && i == 0) ? extraPaddingBits : 0; /** Mantêm os bits de preenchimento (nível bit) no final da linha de pixeis, se existirem. */
                while (l < 8) {
                    auxT[k + i] = icon[s + j] >> l & 1;
                    i++;
                    l++;
                }
            }
            s += inf.TotalRowSize;
            k += inf.TotalRowSize * 8;
        }
        /** Converte os bits para bytes e armazena-os nos dados da imagem */
        s = 0;
        e = sizeof(auxT) - 1;
        k = inf.StartOfImageDataOffset;
        while (s <= e) {
            char bit7 = auxT[s + 0];
            char bit6 = auxT[s + 1];
            char bit5 = auxT[s + 2];
            char bit4 = auxT[s + 3];
            char bit3 = auxT[s + 4];
            char bit2 = auxT[s + 5];
            char bit1 = auxT[s + 6];
            char bit0 = auxT[s + 7];
            icon[k] = (bit7 << 7) | (bit6 << 6) | (bit5 << 5) | (bit4 << 4) | (bit3 << 3) | (bit2 << 2) | (bit1 << 1) | (bit0 << 0);
            s += 8;
            k++;
        }
    }

    if (inf.bpp == 4) {
        /** 4bpp (2 pixeis por byte ---> 1 pixel por cada 4 bits) (2 nibbles por byte) (16 cores indexadas RGB (BGR LE)) */
        char auxT[inf.ImageDataSize * 2];
        int extraPaddingNibble = ((inf.PixelRowSize * 8) - (inf.Width * inf.bpp)) / inf.bpp; /** Extra "padding", nível bit. Se existir, ... */
        /** ... por exemplo quando o valor "Width" da imagem não é um múltiplo de 2 o último nibble-pixel de cada linha de pixeis não cabe em 1 byte completo sendo este último byte constituído por 1 nibble-pixel + 1 nibble de valor 0. */

        /** Converte todas as sequências byte em nibble-pixeis (índices) invertendo a sua ordem por linha mas mantendo os nibbles de preenchimento no final de cada linha. Todos os nibbles serão armazenados temporariamente em auxT. */
        int k = 0;
        while (s <= e) {
            int i = 0;
            int j = inf.PixelRowSize;
            while (j--) {
                if (!(extraPaddingNibble != 0 && i == 0)) auxT[k + i++] = icon[s + j] & 15; /** Mantêm o nibble de preenchimento (nível bit) no final da linha de pixeis, se existir. */
                auxT[k + i++] = icon[s + j] >> 4;
            }
            s += inf.TotalRowSize;
            k += inf.TotalRowSize * 2;
        }
        /** Converte as sequências nibble para byte e armazena todos os bytes nos dados da imagem */
        s = 0;
        e = sizeof(auxT) - 1;
        k = inf.StartOfImageDataOffset;
        while (s <= e) {
            icon[k] = (auxT[s + 0] << 4) | auxT[s + 1];
            s += 2;
            k++;
        }
    }

    if (inf.bpp >= 8) {
        /** 8bpp (1 pixel por byte ---> 1 pixel por cada 8bits) (256 cores indexadas RGB (BGR LE)) */
        /** 16bpp RGB ou ARGB (BGR ou BGRA LE) (1 pixel por cada 2 bytes ----> 1 pixel por cada 16 bits) (até 65536 cores únicas não indexadas) */
        /** 24bpp RGB (BGR LE) (1 pixel por cada 3 bytes ----> 1 pixel por cada 24 bits) (até 16777216 cores únicas não indexadas) */
        /** 32bpp ARGB (BGRA LE) (1 pixel por cada 4 bytes ----> 1 pixel por cada 32 bits) (até 4294967296 cores únicas não indexadas) */

        /** A partir de 8bpp todas as sequências índice (8bpp), RBG (16 e 24bpp) ou ARGB (16 e 32bpp) cabem em bytes completos. */
        /** A regra "padding for 4 byte alignment" continua a ser válida para 8, 16 e 24bpp. */
        /** 32bpp contêm naturalmente sequências de 4 bytes (1 B + 1 G + 1 R + 1 byte para o canal Alpha = 4 bytes). 32bpp nunca terá "paddings". */
        char b0, b1, b2, b3;
        int l, r, u, v, w;
        while (s <= e) {
            l = 0;
            r = inf.PixelRowSize - 1;
            while (l <= r) {
                                                   u = 0, w = 0;
                               if (inf.bpp >=  8) b0 = icon[s + l + u++];
                               if (inf.bpp >= 16) b1 = icon[s + l + u++];
                               if (inf.bpp >= 24) b2 = icon[s + l + u++];
                               if (inf.bpp >= 32) b3 = icon[s + l + u++];
                                                   v = u;
                if (inf.bpp >=  8) icon[s + l + w++] = icon[s + r - --u];
                if (inf.bpp >= 16) icon[s + l + w++] = icon[s + r - --u];
                if (inf.bpp >= 24) icon[s + l + w++] = icon[s + r - --u];
                if (inf.bpp >= 32) icon[s + l + w++] = icon[s + r - --u];
                if (inf.bpp >=  8) icon[s + r - --w] = b0;
                if (inf.bpp >= 16) icon[s + r - --w] = b1;
                if (inf.bpp >= 24) icon[s + r - --w] = b2;
                if (inf.bpp >= 32) icon[s + r - --w] = b3;
                l += v;
                r -= v;
            }
            s += inf.TotalRowSize;
        }
    }
}

void Flip() { // Espelhar um bitmap verticalmente
    int s = inf.StartOfImageDataOffset;
    int e = inf.StartOfImageDataOffset + inf.ImageDataSize;
    while (s < e) {
        int u = inf.TotalRowSize;
            while (u--) {
                                       char b0 = icon[s + u];
                                   icon[s + u] = icon[e - inf.TotalRowSize + u];
                icon[e - inf.TotalRowSize + u] = b0;
            }
        s += inf.TotalRowSize;
        e -= inf.TotalRowSize;
    }
}

void DIBFlip() { // Espelhar um bitmap verticalmente invertendo o sinal do valor "Height"
    int dibSize = (icon[14] << 0) | (icon[15] << 8) | (icon[16] << 16) | (icon[17] << 24);
    if (dibSize == 12) return; /** DIB Filp incompativel com OS/2 1.x BITMAPCOREHEADER (dibSize == 12) */
    int Height  = (icon[22] << 0) | (icon[23] << 8) | (icon[24] << 16) | (icon[25] << 24);
    int dib_flip = -(Height); /** Inverte o sinal do valor Height da imagem. */
    icon[22] = dib_flip >>  0 & 255;
    icon[23] = dib_flip >>  8 & 255;
    icon[24] = dib_flip >> 16 & 255;
    icon[25] = dib_flip >> 24 & 255;
}

void MirrorFlip() { // Espelhar um bitmap na horizontal e na vertical ao mesmo tempo
    int s = inf.StartOfImageDataOffset;
    int e = inf.StartOfImageDataOffset + (inf.ImageDataSize - 1) - inf.PadSize;

    /*
    if (inf.bpp == 1) { // Implementação mais simples, mas não funciona corretamente se o "Width" da imagem não for múltiplo de 8.
        // 1bpp (8 pixels por byte ---> 1 pixel por cada bit) (até 2 cores indexadas RGB (BGR LE))
        while (s <= e) {
            char b0 = icon[s];
            char b1 = icon[e];
               icon[s] = (b1 & 128) >> 7 | (b1 & 64) >> 5 | (b1 & 32) >> 3 | (b1 & 16) >> 1 | (b1 & 8) << 1 | (b1 & 4) << 3 | (b1 & 2) << 5 | (b1 & 1) << 7;
               icon[e] = (b0 & 128) >> 7 | (b0 & 64) >> 5 | (b0 & 32) >> 3 | (b0 & 16) >> 1 | (b0 & 8) << 1 | (b0 & 4) << 3 | (b0 & 2) << 5 | (b0 & 1) << 7;
            s++;
            e--;
        }
    }
    */

    if (inf.bpp == 1) {
        /** 1bpp (8 pixels por byte ---> 1 pixel por cada bit) (2 cores indexadas RGB (BGR LE)) */
        char auxT[inf.ImageDataSize * 8];
        int extraPaddingBits = ((inf.PixelRowSize * 8) - (inf.Width * inf.bpp)) / inf.bpp; /** Extra "padding", nível bit. */
        /** Converte todas as sequências byte em bit-pixeis (índices) invertendo totalmente a sua ordem mas mantendo os bits de preenchimento no final de cada linha. Todos os bits serão armazenados temporariamente em auxT. */
        int k = 0;
        while (s <= e) {
            int j = (extraPaddingBits != 0 && k == 0) ? extraPaddingBits : 0; /** Mantêm os bits de preenchimento (nível bit) no final da linha de pixeis, se existirem. */
            while (j < 8) {
                auxT[k] = icon[e] >> j & 1;
                j++;
                k++;
            }
            e--;
        }
        /** Converte os bits para bytes e armazena-os nos dados da imagem */
        /** Durante o processo de conversão eventuais bytes de preenchimento, "padding for 4 byte alignment", poderão adquirir novos valores diferentes dos seus valores originais. Estes, possíveis, novos valores não são importantes. */
        s = 0;
        e = sizeof(auxT) - 1;
        k = inf.StartOfImageDataOffset;
        while (s <= e) {
            char bit7 = auxT[s + 0];
            char bit6 = auxT[s + 1];
            char bit5 = auxT[s + 2];
            char bit4 = auxT[s + 3];
            char bit3 = auxT[s + 4];
            char bit2 = auxT[s + 5];
            char bit1 = auxT[s + 6];
            char bit0 = auxT[s + 7];
            icon[k] = (bit7 << 7) | (bit6 << 6) | (bit5 << 5) | (bit4 << 4) | (bit3 << 3) | (bit2 << 2) | (bit1 << 1) | (bit0 << 0);
            s += 8;
            k++;
        }
    }

    /*
    if (inf.bpp == 4) { // Implementação mais simples, mas não funciona corretamente se o "Width" da imagem não for múltiplo de 2.
        // 4bpp (2 pixeis por byte ---> 1 pixel por cada 4 bits) (2 nibbles por byte) (até 16 cores indexadas RGB (BGR LE))
        while (s <= e) {
            char b0 = icon[s];
               icon[s] = (icon[e] & 15) << 4 | (icon[e] >> 4);
               icon[e] = (     b0 & 15) << 4 | (     b0 >> 4);
            s++;
            e--;
        }
    }
    */

    if (inf.bpp == 4) {
        /** 4bpp (2 pixeis por byte ---> 1 pixel por cada 4 bits) (2 nibbles por byte) (16 cores indexadas RGB (BGR LE)) */
        char auxT[inf.ImageDataSize * 2];
        int extraPaddingNibble = ((inf.PixelRowSize * 8) - (inf.Width * inf.bpp)) / inf.bpp; /** Extra "padding", nível bit. */
        /** Converte todas as sequências byte em nibble-pixeis (índices) invertendo totalmente a sua ordem mas mantendo os nibbles de preenchimento no final de cada linha. Todos os nibbles serão armazenados temporariamente em auxT. */
        int k = 0;
        while (s <= e) {
            if (!(extraPaddingNibble != 0 && k == 0)) auxT[k++] = icon[e] & 15; /** Mantêm o nibble de preenchimento (nível bit) no final da linha de pixeis, se existir. */
            auxT[k++] = icon[e] >> 4;
            e--;
        }
        /** Converte as sequências nibble para byte e armazena todos os bytes nos dados da imagem */
        /** Durante o processo de conversão eventuais bytes de preenchimento, "padding for 4 byte alignment", poderão adquirir novos valores diferentes dos seus valores originais. Estes, possíveis, novos valores não são importantes. */
        s = 0;
        e = sizeof(auxT) - 1;
        k = inf.StartOfImageDataOffset;
        while (s <= e) {
            icon[k] = (auxT[s + 0] << 4) | auxT[s + 1];
            s += 2;
            k++;
        }
    }

    if (inf.bpp >= 8) {
        /** 8bpp (1 pixel por byte ---> 1 pixel por cada 8bits) (256 cores indexadas RGB (BGR LE)) */
        /** 16bpp RGB ou ARGB (BGR ou BGRA LE) (1 pixel por cada 2 bytes ----> 1 pixel por cada 16 bits) (até 65536 cores únicas não indexadas) */
        /** 24bpp RGB (BGR LE) (1 pixel por cada 3 bytes ----> 1 pixel por cada 24 bits) (até 16777216 cores únicas não indexadas) */
        /** 32bpp ARGB (BGRA LE) (1 pixel por cada 4 bytes ----> 1 pixel por cada 32 bits) (até 4294967296 cores únicas não indexadas) */

        /** A partir de 8bpp todas as sequências índice (8bpp), RBG (16 e 24bpp) ou ARGB (16 e 32bpp) cabem em bytes completos. */
        /** A regra "padding for 4 byte alignment" continua a ser válida para 8, 16 e 24bpp. */
        /** Os eventuais bytes de preenchimento, "padding for 4 byte alignment", são facilmente mantidos no final de cada linha bastando para isso criar um desfasamento no valor "end" do laço while ou for: e = inf.StartOfImageDataOffset + (inf.ImageDataSize - 1) - inf.PadSize;. */
        int u, v, w;
        char b0, b1, b2, b3;
        while (s <= e) {
                                           u = 0, w = 0;
                       if (inf.bpp >=  8) b0 = icon[s + u++];
                       if (inf.bpp >= 16) b1 = icon[s + u++];
                       if (inf.bpp >= 24) b2 = icon[s + u++];
                       if (inf.bpp == 32) b3 = icon[s + u++];
                                           v = u;
            if (inf.bpp >=  8) icon[s + w++] = icon[e - --u];
            if (inf.bpp >= 16) icon[s + w++] = icon[e - --u];
            if (inf.bpp >= 24) icon[s + w++] = icon[e - --u];
            if (inf.bpp == 32) icon[s + w++] = icon[e - --u];
            if (inf.bpp >=  8) icon[e - --w] = b0;
            if (inf.bpp >= 16) icon[e - --w] = b1;
            if (inf.bpp >= 24) icon[e - --w] = b2;
            if (inf.bpp == 32) icon[e - --w] = b3;
            s +=  v;
            e -=  v;
        }
    }
}

void SaveFile(char fname[]) {
    FILE *fout = fopen(fname, "wb");
    fwrite(icon, sizeof(icon), 1, fout);
    fclose(fout);
}

void Choice() {
    printf( "\nPress: 1 to Mirror | 2 to Mirror-Flip | 3 to Flip | 4 to DIB-Flip | 5 to Exit.\n" );
    char r;
    gets(&r);
    switch (r) {
        case '1':
            Mirror();
            SaveFile("Mirror.bmp");
            break;
        case '2':
            /*
            Mirror();
            Flip();
            SaveFile();
            */
            MirrorFlip();
            SaveFile("Mirror-Flip.bmp");
            break;
        case '3':
            Flip();
            SaveFile("Flip.bmp");
            break;
        case '4':
            DIBFlip();
            SaveFile("DIB-Flip.bmp");
            break;
        case '5':
            return;
        default:
            Choice();
    }

    printf("Continue... [y,n]?\n");
    gets(&r);
    switch (r) {
        case 'y':
            Choice();
            break;
        default:
            return;
    }
}

int main() {
    SetInfos();
    if (!inf.isBM) return -1; // O arquivo está danificado ou não é suportado.
    if (inf.Width < 0) return -1; // Tem que ser positivo (mandatório).
    if (inf.isCompressed) return -1; // Não suporta compressão.
    if (inf.bpp == 2) return -1; // Não suporta 2bpp.
    Choice();
    return 0;
}

Você deve fazer log-in para responder a esta pergunta.

Esta não é a resposta que você está procurando? Pesquise outras perguntas com a tag .