Question

All right guys, I'm working on a method to enlarge a bmp file, but i am a little confused on how to go about it. This is how I think the enlarge would go:

Let's say we have the bmp file:

0 1 2
3 4 5

a 3x2 2D array, so let's say we want to enlarge this image by a scale of 2, then the new image would look like this:

0 0 1 1 2 2
0 0 1 1 2 2
3 3 4 4 5 5
3 3 4 4 5 5

I am correct about this or does it work in a different way?
Thank you, I just need to understand how it works to be able to write down an algorithm.

Was it helpful?

Solution

I basically call this image resize method: "brute sizing" or "image scaling"

  1. size calculation:

    Original image size: 3 x 2 pixels (total of 6 pixels)

    if you scale the height by 2 and the width by 2

    Final image size: 6 x 4 pixels (total of 24 pixels)

  2. Implementation:

    here is an example:
    lets say: AA=3, AB=2, AC=6 and BA=6, BB=4, BC=24 and scaleX=2, scaleY=2


    int ptotal = AC; //or = AA * AB

    for (pcount = 0; pcount < ptotal; ++pcount)
    {
        img_x = (pcount%(AA))*scaleX;
        if ((pcount%(scaleX))==0)
            img_y += scaleY;
        set_rect_BMP(bmp,img_x,img_y,scaleX,scaleY,r,g,b);
    }

int set_rect_BMP(BMP* bmp, int x, int y, int w, int h, int r, int g, int b) {

    int i, j;
    for (i = y; i < h+y; ++i)
    {
        for (j = x; j < w+x; ++j)
        {
            BMP_SetPixelRGB( bmp, j, i, r, g, b );
            //BMP_SetPixelRGB( bmp, the x coord, the y coord, red, green, blue );
        }
    }
}

Diagram of the algorithm:

enter image description here


further explanation will be given if needed ;) see more on wikipedia here: http://en.wikipedia.org/wiki/Image_scaling

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top