I can get smiley.bmp and large.bmp to scale properly, but not small.bmp, where the former is 3x3 and the latter two are larger (exactly how much larger I don't know) -- so I assume my program only works on bitmaps larger than 3x3, and check50 tests with 1x1 and 2x2 images.
The four lines below are the ones I believe are causing trouble.
I don't know why nor how the o
loop works (if I remove it the program will forcefully scale vertically by a factor of two, but fine horizontally), k
represents one pixel, and m
duplicates the current pixel. Furthermore, there is must be a better way to do this than using three nested for loops?
for (int o = 0; o < n-1; o++) {
for (int k = 0; k < bi.biWidth; k++) {
for (int m = 0; m < n; m++) {
fwrite((scanline+k), sizeof(RGBTRIPLE), 1, outptr);
}
}
}
// 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);
// Append triple to scanline
scanline[j] = triple;
// write RGB triple to outfile n times
for (int k = 0; k < n; k++) {
fwrite(&triple, sizeof(RGBTRIPLE), 1, outptr);
}
}
// Write scanline to outfile n times, as well as duplicate pixels n times
for (int o = 0; o < n-1; o++) {
for (int k = 0; k < bi.biWidth; k++) {
for (int m = 0; m < n; m++) {
fwrite((scanline+k), sizeof(RGBTRIPLE), 1, outptr);
}
}
}
// skip over padding in the infile, if any
fseek(inptr, padding, SEEK_CUR);
// then add it back to the outfile (to demonstrate how)
for (int k = 0; k < padding; k++)
{
fputc(0x00, outptr);
}
}