I've been working on Resize for a few weeks now and just can't seem to get the vertical replication working. I have to apologise in advance, my code is a mess, has a number of replicated notes, and is probably not a particularly intuitive/effective design.
After several dead-ends, I decided to use a system that reads the relevant triples, duplicates them x times (x being the scale), adds padding, and reverts the infile back to the start of the row. It runs this process (x - 1) times. The program then runs similar code for the final replication of the row, adds the padding, but instead skips forward over the infile padding. Long story short, it doesn't work and creates appropriately-sized images with a few correct rows (not always) and large black bars.
The relevant portion of the code is below.
for (int i = 0, biHeight = abs(old_height); i < biHeight; i++)
{
for (int a = 0; a < (scale - 1); a++)
{
// iterate over pixels in scanline
for (int j = 0; j < old_width; j++)
{
// temporary storage
RGBTRIPLE triple;
// read RGB triple from infile
fread(&triple, sizeof(RGBTRIPLE), 1, inptr);
// write RGB triple to outfile
for (int b = 0; b < scale; b++)
{
fwrite(&triple, sizeof(RGBTRIPLE), 1, outptr);
}
}
// add output file padding, if any
for (int k = 0; k < new_padding; k++)
{
fputc(0x00, outptr);
}
fseek(inptr, -(old_width), SEEK_CUR);
}
// iterate over pixels in scanline
for (int j = 0; j < old_width; j++)
{
// temporary storage
RGBTRIPLE triple;
// read RGB triple from infile
fread(&triple, sizeof(RGBTRIPLE), 1, inptr);
// write RGB triple to outfile
for (int b = 0; b < scale; b++)
{
fwrite(&triple, sizeof(RGBTRIPLE), 1, outptr);
}
}
// skip over input file padding, if any
fseek(inptr, old_padding, SEEK_CUR);
for (int k = 0; k < new_padding; k++)
{
fputc(0x00, outptr);
}
}
If anyone could point out to my where I'm going wrong I would be extremely grateful!