hey i don't know why but my code works perfect resizing the images but for some reason i don't understand the check50 command tells me it is not correct because it does not resize anything correctly could someone please help
/**
* copy.c
*
* Computer Science 50
* Problem Set 4
*
* rezises a BMP piece by piece, just because.
*/
#include <stdio.h>
#include <stdlib.h>
#include "bmp.h"
int main(int argc, char* argv[])
{
// ensure proper usage
if (argc != 4)
{
printf("Usage: ./resize numberoftimestoberesized infile outfile\n");
return 1;
}
// remember filenames and key to resize
int key = atoi(argv[1]);
char* infile = argv[2];
char* outfile = argv[3];
// open input file
FILE* inptr = fopen(infile, "r");
if (inptr == NULL)
{
printf("Could not open %s.\n", infile);
return 2;
}
// open output file
FILE* outptr = fopen(outfile, "w");
if (outptr == NULL)
{
fclose(inptr);
fprintf(stderr, "Could not create %s.\n", outfile);
return 3;
}
// read infile's BITMAPFILEHEADER
BITMAPFILEHEADER bf;
BITMAPFILEHEADER bfc;
fread(&bf, sizeof(BITMAPFILEHEADER), 1, inptr);
// read infile's BITMAPINFOHEADER
BITMAPINFOHEADER bi;
BITMAPINFOHEADER bic;
fread(&bi, sizeof(BITMAPINFOHEADER), 1, inptr);
// ensure infile is (likely) a 24-bit uncompressed BMP 4.0
if (bf.bfType != 0x4d42 || bf.bfOffBits != 54 || bi.biSize != 40 ||
bi.biBitCount != 24 || bi.biCompression != 0)
{
fclose(outptr);
fclose(inptr);
fprintf(stderr, "Unsupported file format.\n");
return 4;
}
//makes a copy of the header files
bfc = bf;
bic = bi;
bic.biWidth = bi.biWidth * key;
bic.biHeight = bi.biHeight * key;
// write outfile's BITMAPFILEHEADER
fwrite(&bfc, sizeof(BITMAPFILEHEADER), 1, outptr);
// write outfile's BITMAPINFOHEADER
fwrite(&bic, sizeof(BITMAPINFOHEADER), 1, outptr);
// Padddings
int padding = (4 - (bi.biWidth * sizeof(RGBTRIPLE)) %4) % 4;
int paddingc = (4 - (bic.biWidth * sizeof(RGBTRIPLE)) %4) % 4;
// New seize
bic.biSizeImage = (bic.biWidth * sizeof(RGBTRIPLE) + paddingc) * abs(bic.biHeight);
bfc.bfSize = bf.bfSize - bi.biSizeImage + bic.biSizeImage;
// iterate over infile's scanlines
for (int i = 0, biHeight = abs(bi.biHeight); i < biHeight; i++)
{
//to ultiply times the hight
for (int j = 0; j < key; j++)
{
// iterate over pixels in scanline
for(int b = 0; b < bi.biWidth; b++ )
{
RGBTRIPLE triple;
// read RGB triple from infile
fread(&triple, sizeof(RGBTRIPLE), 1, inptr);
// multiplies times the width
for(int y = 0; y < key; y++)
fwrite(&triple, sizeof(RGBTRIPLE), 1, outptr);
}
// skip over padding, if any
fseek(inptr, padding, SEEK_CUR);
// Add a new padding
for (int f = 0; f < paddingc; f++)
fputc(0x00, outptr);
// Back to the begining
//f (j < key - 1)
fseek(inptr, -bi.biWidth * sizeof(RGBTRIPLE), SEEK_CUR);
}
// Back to the begining
//if (j < key - 1)
fseek(inptr, bi.biWidth * sizeof(RGBTRIPLE), SEEK_CUR);
}
// close infile
fclose(inptr);
// close outfile
fclose(outptr);
return 0;
}