How to mirror an image?

Asked

Viewed 372 times

2

I’d like to know how to mirror an image. I got an algorithm, but it only reverses images with 60x60 resolution and bpp=1.

I have the following image model to test:

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, 0xFF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x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 
0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 
0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 
0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 
0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 
0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 
                };

Anyone have any idea where I should make a better fit on this algorithm? Suppose we have an image 10x10 pixels, with bpp=1. Would the line size be 10 bits? Do I have to invert these bits per line to get the desired result? Does anyone know how to do this?

Here’s the algorithm I have:

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);
}
  • I don’t know what you understand as pure C, but at least some graphical library you will have to use.

  • C pure, not C++. C low level. What I want is to print image on a thermal printer. The image is coming out backwards and upside down. I need an algorithm to adjust the image.

  • Important [Dit] posting what tried and making clear the difficulty found. Ready codes, tutorials and questions that depend on various different knowledge applied usually do not fit well in the site scope in a single question. If you have doubt in specific parts, you can post a [mcve] of the current problem step, and by solving, you can open separate questions about the next steps, each focused on a specific problem.

  • @Bacco I put more information regarding my doubt.

  • You may find a C++ algorithm that you can compile to perform the inversion. The Opencv is an open computer vision library and has very efficient implementations for this type of operation.

1 answer

1

Whereas your image is something like:

/* 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 };

To reverse it, you can swap the pixels contained at the beginning of the image with the pixels contained at the end of the image, see only:

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;
    }
}

Putting it all together:

#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;
}

Exit:

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

See working on Repl.it

  • Thank you, Lacobus, thank you. With 0 and 1 works well, but if I put values: 0xFF, 0x00, 0x0C..., which correspond to the image data, does not work very well, gets dirt on the image. And the width x height size does not work well either. The image header has the size, so I replace it with these values. There’s something missing, I need to know what it is.

  • I just used the format more primitive image I could imagine to exemplify. What is the format of the image you are working on? How many bits it has per pixel ?

  • Varies... It depends on the image I open to have printed. I took a small example, bpp is 2, a 2x2 image I took as an example...

  • I have to take the image data and turn it into bmp. So far so good. The only problem is that the image comes out mirrored, because the bmp format is reversed, so I have to invert the image.

  • @Biancanunes: What is the format of the source image ? You can post one as an example/sample ?

  • I edited my question. I put it up there.

  • Funny thing is that when I printed it on the printer, it was able to adjust it only in the aspect of being upside down. It doesn’t look like that anymore. However, it’s still mirrored. I tried to make an algorithm to uninvert, but I couldn’t.

  • I had a little help. , passed me this solution: int bytesPerRow = (width >> 3) + (width & 0x7 ? 1 : 0); //that part didn’t understand why to scroll 3 bits to the right and give a & logic with 7. int Row; for (Row = height - 1; Row >= 0; Row-) memcpy(&(bitmapStream[sizeof(header) + Row * bytesPerRow]), &rgb[(height - Row - 1) * bytesPerRow], bytesPerRow); //this I understood even less here...

Show 3 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.