I don't exactly understand the principle of recopy method used in resize pset4. Can someone explain me without giving the actual solution. Here is my code so far. After running the code I recive a distorted image.I don't understand also the fseek function. From my understanding of fseek it must turn the cursor back to the beginning of the file so it must pass through pixels I wrote and the padding right ?
// iterate over infile's scanlines
for (int i = 0, old_biHeight = abs(old_bi.biHeight); i < old_biHeight; i++)
{
for (int j = 0; j < n - 1; j++)
{
// iterate over pixels in scanline
for (int k = 0; k < old_bi.biWidth; k++)
{
// temporary storage
RGBTRIPLE triple;
// read RGB triple from infile
fread(&triple, sizeof(RGBTRIPLE), 1, inptr);
// write RGB triple to infile
for (int z = 0; z < n; z++)
{
fwrite(&triple, sizeof(RGBTRIPLE), 1, outptr);
}
//padding
for (int z = 0; z < old_padding; z++)
{
fputc(0x00, outptr);
}
//Send infile cursor back
fseek(inptr, bi.biWidth, SEEK_SET);
}
}
for (int k = 0; k < old_bi.biWidth; k++)
{
RGBTRIPLE triple;
// read RGB triple from infile
fread(&triple, sizeof(RGBTRIPLE), 1, inptr);
for (int z = 0; z < n; z++)
{
fwrite(&triple, sizeof(RGBTRIPLE), 1, outptr);
}
for (int y = 0; y < new_padding; y++)
{
fputc(0x00, outptr);
}
}
}
EDIT: please also tell me what's wrong in my code. The code now resizes images but the image is full of randomly colors. Is it a problem with padding ?
EDIT NEW CODE :
// iterate over infile's scanlines
for (int i = 0, old_biHeight = abs(old_bi.biHeight); i < old_biHeight; i++)
{
for (int j = 0; j < n - 1; j++)
{
// iterate over pixels in scanline
for (int k = 0; k < old_bi.biWidth; k++)
{
// temporary storage
RGBTRIPLE triple;
// read RGB triple from infile
fread(&triple, sizeof(RGBTRIPLE), 1, inptr);
// write RGB triple to infile
for (int z = 0; z < n; z++)
{
fwrite(&triple, sizeof(RGBTRIPLE), 1, outptr);
}
//padding
for (int z = 0; z < new_padding; z++)
{
fputc(0x00, outptr);
}
//Send infile cursor back
fseek(inptr, new_padding, SEEK_CUR);
}
}
for (int k = 0; k < old_bi.biWidth; k++)
{
RGBTRIPLE triple;
// read RGB triple from infile
fread(&triple, sizeof(RGBTRIPLE), 1, inptr);
for (int z = 0; z < n; z++)
{
fwrite(&triple, sizeof(RGBTRIPLE), 1, outptr);
}
for (int y = 0; y < new_padding; y++)
{
fputc(0x00, outptr);
}
}
}
// skip over padding, if any
fseek(inptr, old_padding, SEEK_CUR);