Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // read infile's BITMAPFILEHEADER
- BITMAPFILEHEADER bf;
- fread(&bf, sizeof(BITMAPFILEHEADER), 1, inptr);
- // read infile's BITMAPINFOHEADER
- BITMAPINFOHEADER bi;
- 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;
- }
- int oldpadding = (4 - (bi.biWidth * sizeof(RGBTRIPLE)) % 4) % 4;
- printf("oldpadding: %in", oldpadding);
- int oldWidth = bi.biWidth;
- int oldHeight = abs(bi.biHeight);
- bi.biWidth = bi.biWidth * scale;
- bi.biHeight = bi.biHeight * scale;
- // determine padding for scanlines
- int padding = (4 - (bi.biWidth * sizeof(RGBTRIPLE)) % 4) % 4;
- printf("padding: %in", padding);
- bi.biSizeImage = ( ( (sizeof(RGBTRIPLE) * bi.biWidth) + padding) * abs(bi.biHeight) );
- bf.bfSize = sizeof( BITMAPFILEHEADER ) + sizeof( BITMAPINFOHEADER ) + bi.biSizeImage;
- // write outfile's BITMAPFILEHEADER
- fwrite(&bf, sizeof(BITMAPFILEHEADER), 1, outptr);
- // write outfile's BITMAPINFOHEADER
- fwrite(&bi, sizeof(BITMAPINFOHEADER), 1, outptr);
- // iterate over infile's scanlines
- for (int i = 0; i < oldHeight; i++)
- {
- int m = 0;
- int rgb = sizeof(RGBTRIPLE);
- RGBTRIPLE* pixel = malloc(rgb * bi.biWidth);
- RGBTRIPLE black;
- black.rgbtBlue = 255;
- black.rgbtGreen = 255;
- black.rgbtRed = 255;
- for (int clear = 0; clear < (rgb * bi.biWidth); clear++)
- {
- pixel[clear] = black;
- }
- // iterate over pixels in scanline
- for (int j = 0; j < oldWidth; j++)
- {
- // temporary storage
- RGBTRIPLE triple;
- // read RGB triple from infile
- fread(&triple, sizeof(RGBTRIPLE), 1, inptr);
- for (int l = 0; l < scale; l++)
- {
- // write RGB triple to outfile
- fwrite(&triple, sizeof(RGBTRIPLE), 1, outptr);
- pixel[m] = triple;
- m++;
- //m++; m++;
- //m++; m++; m++;
- printf("%x %x %xn", pixel->rgbtBlue, pixel->rgbtGreen, pixel->rgbtRed);
- }
- if (j == (oldWidth - 1) )
- {
- // skip over padding, if any
- fseek(inptr, oldpadding, SEEK_CUR);
- for (int k = 0; k < padding; k++)
- {
- fputc(0x00, outptr);
- }
- printf("%pn",pixel);
- int b = scale - 1;
- while (b > 0)
- {
- fwrite(&pixel, rgb * bi.biWidth, 1, outptr);
- b--;
- for (int k = 0; k < padding; k++)
- {
- fputc(0x00, outptr);
- }
- }
- free(pixel);
- }
- }
- }
- // close infile
- fclose(inptr);
- // close outfile
- fclose(outptr);
- // success
- return 0;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement