- // determine padding for scanlines
- int padding = (4 - (bio.biWidth * sizeof(RGBTRIPLE)) % 4) % 4;
- int paddingnew = (4 - (bi.biWidth * sizeof(RGBTRIPLE)) % 4) % 4;
- // go over every line in the source file
- float oh = factor;
- for (int i = 0, biHeight = abs(bio.biHeight); i < biHeight; i++)
- {
- // this will print a line several times or skip it, depending on the factor
- for (; oh > 0; oh--)
- {
- // go over every pixel in the source file
- float ow = factor;
- for (int j = 0; j < bio.biWidth; j++)
- {
- // this will print a pixel several times or skip it, depending on the factor
- for (; ow > 0; ow--)
- {
- RGBTRIPLE triple;
- fread(&triple, sizeof(RGBTRIPLE), 1, inptr);
- fwrite(&triple, sizeof(RGBTRIPLE), 1, outptr);
- if (ow >= 1)
- {
- //reset input file cursor
- fseek (inptr, -sizeof(RGBTRIPLE), SEEK_CUR);
- }
- }
- // bring the remainder of ow + factor to the next pixel
- ow += factor;
- }
- // skip the old padding in input, print the new padding in output
- fseek(inptr, padding, SEEK_CUR);
- for (int k = 0; k < paddingnew; k++)
- {
- fputc(0x00, outptr);
- }
- if (oh >= 1)
- {
- //reset input file cursor
- fseek (inptr, -bio.biWidth, SEEK_CUR);
- }
- }
- // bring the remainder of oh + factor to the next line
- oh += factor;
- }
- // close infile
- fclose(inptr);
- // close outfile
- fclose(outptr);
- // success
- return 0;
- }