Click to See Complete Forum and Search --> : Problem in Displaying Image using DIBSection


asiffayyaz
November 13th, 2003, 06:54 AM
Assalam-O-Alaikum,
I am trying to do Image Scaling and then save the scaled Image into a DIBSection and then display it using SetDIBitstoDevice. I have loaded a file and created a DIBSection according to the specification of the Image. I then created another DIBSection with the Scaled Parameters. I am doing Image Scaling by picking the bit pointer of the first DIBSection and then putting it in the scaled DIBSection with some manipulation. Now here is the problem

I have loaded a 640 * 480 file and create a DIBSection according to it. I then created a DIBSection of parameters twice of these parameters i.e 1280*960. Now I have to Scaled the Image in both the directions. But when i copies the row of the first bitmap twice then it works fine for the horizontal direction but does not work for the verticle direction. When i do it in the vertyicle direction then whole Image get corrupted. I am not able to scale the Image in the verticle direction Can any one tell me where is the problem. Here is the code

void ResizeDDA(BYTE *normalBuffer, BYTE *scaledBuffer, int rows, int cols, int BPP, double zoom)
{
// unsigned char *aspline, *line;
int x, y;
int ddax, dday, izoom, i, j, k;
BYTE *pPrevBuffer;

/* Calculate the differential amount */
izoom = (int)(1.0/zoom * 1000);
/* Allocate a buffer for a scan line from original image, and a
** resized scan line */
/* Initialize the output Y value and vertial differential */
y = 0;
dday = 0;
/* Loop over rows in the original image */
for (i = 0; i < rows; i++) {
/* Get a scan line from the original image (8-bit values expected) */
/* Adjust the vertical accumulated differential, initialize the
** output X pixel and horizontal accumulated differential */
dday -= 1000;
x = 0;
ddax = 0;
pPrevBuffer = scaledBuffer;
/* Loop over pixels in the original image */
for (j = 0; j < cols; j++) {
/* Adjust the horizontal accumulated differential */
ddax -= 1000;
while (ddax < 0) {
/* Store values from original image scanline into the scaled
** buffer until accumulated differential crosses threshold */
memcpy(scaledBuffer,normalBuffer,BPP);
x++;
scaledBuffer += 3;
ddax += izoom;
}
normalBuffer += 3;
}



dday += izoom;
while (dday < 0)
{
// The 'outer loop' -- output resized scan lines until the
// vertical threshold is crossed
dday += izoom;

memcpy(scaledBuffer,scaledBuffer-(BPP*x),(BPP*x));
scaledBuffer+=BPP*x;
y++;
}

}

}


Also have no Idea then where the next row will start. Whether there is no concept of row and column boundary in this way or the other thing.
Please reply early as it is urgant.
I have also attached the code.