0

I have checked my bitmap file and info headers. They are correct and match the staff.bmp file. However, my resize code for 4 produces this:

0000036: 00ff00 00ff00 00ff00 00ff00 00ff00 00ff00 00ff00 00ff00 00ff00 00ff00 00ff00 00ff00  
000005a: 00ff00 00ff00 00ff00 00ff00 00ff00 00ff00 00ff00 00ff00 00ff00 00ff00 00ff00 00ff00  
00000a2: 00ff00 00ff00 00ff00 00ff00 00ff00 00ff00 00ff00 00ff00 00ff00 00ff00 00ff00 00ff00  
00000c6: 00ff00 00ff00 00ff00 00ff00 00ff00 00ff00 00ff00 00ff00 00ff00 00ff00 00ff00 00ff00  
00000ea: 00ff00 00ff00 00ff00 00ff00 ffffff ffffff ffffff ffffff ffffff ffffff ffffff ffffff  
000010e: ffffff ffffff ffffff ffffff ffffff ffffff ffffff ffffff 00ff00 00ff00 00ff00 00ff00

0000132: 00ff00 00ff00 00ff00 00ff00 00ff00 00ff00 00ff00 00ff00 00ff00 00ff00 00ff00 00ff00  
0000156: 00ff00 00ff00 00ff00 00ff00 00ff00 00ff00 00ff00 00ff00 00ff00 00ff00 00ff00 00ff00  
000017a: 00ff00 00ff00 00ff00 00ff00 00ff00 00ff00 00ff00 00ff00 00ff00 00ff00 00ff00 00ff00  
000019e: 00ff00 00ff00 00ff00 00ff00 00ff00 00ff00 00ff00 00ff00 00ff00 00ff00 00ff00 00ff00  
00001c2: 00ff00 00ff00 00ff00 00ff00 00ff00 00ff00 00ff00 00ff00 00ff00 00ff00 00ff00 00ff00

My padding and new padding variables are correct when I inquire using GDB. Perhaps my pointer is not in the right spot when I read? Please help!!!!

// iterate over infile's scanlines
for (int i = 0, biHeight = abs(bi.biHeight); i < biHeight; i++)
{
    // iterate over pixels in scanline
    for (int j = 0; j < bi.biWidth; j++)
    {
        // temporary storage
        RGBTRIPLE triple;

        // read RGB triple from infile
        fread(&triple, sizeof(RGBTRIPLE), 1, inptr);

        // write enlarged scan lines "enlarge" times for vertical enlarge
        for (int v = 0; v < enlarge; v++)
        {

            // write RGB triple "enlarge" times for horizontal enlarge
            for (int h = 0; h < enlarge; h++)
            {
                // write RGB triple to outfile
                fwrite(&triple, sizeof(RGBTRIPLE), 1, outptr);
            }

        }
    }

    // skip over padding, if any
    fseek(inptr, padding, SEEK_CUR);

    // add padding if needed
    for (int k = 0; k < paddingNew; k++)
    {
       fputc(0x00, outptr);
    }

Thanks!!!

0

The problem is that you are trying to do both the horizontal and vertical scaling on each pixel, one at a time. You scale the pixel horizontally, then vertically, then move on to read the next pixel. Once you get to the end of a line of pixels from the input file, then you skip over the padding and start on the next line in the input file, along with adding the output padding to the output file. This doesn't work.

In order to scale in both dimensions, you need to scale each pixel horizontally to create a horizontal line of pixels in the output file, adding padding at the end, and then repeat that process enlarge times, remembering to reset the pointer on the input file to the beginning of the line you just finished.

Time to restructure your program. ;-)

If this answers your question, please click on the check to accept. Let's keep up on forum housekeeping. ;-)

1
  • Thank you very much. I reworked the program so that I was duplicating the enlarged line the required times before moving to the next line in the original file. I had a bit of a problem identifying the right formula for the pointer but finally prevailed. I am sure learning a lot. Thank you so much for your help.
    – RPickett50
    Oct 2 '15 at 23:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .