Advertisement
Guest User

Untitled

a guest
Oct 12th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.81 KB | None | 0 0
  1. // read infile's BITMAPFILEHEADER
  2. BITMAPFILEHEADER bf;
  3. fread(&bf, sizeof(BITMAPFILEHEADER), 1, inptr);
  4.  
  5. // read infile's BITMAPINFOHEADER
  6. BITMAPINFOHEADER bi;
  7. fread(&bi, sizeof(BITMAPINFOHEADER), 1, inptr);
  8.  
  9. // ensure infile is (likely) a 24-bit uncompressed BMP 4.0
  10. if (bf.bfType != 0x4d42 || bf.bfOffBits != 54 || bi.biSize != 40 ||
  11. bi.biBitCount != 24 || bi.biCompression != 0)
  12. {
  13. fclose(outptr);
  14. fclose(inptr);
  15. fprintf(stderr, "Unsupported file format.n");
  16. return 4;
  17. }
  18.  
  19. int oldpadding = (4 - (bi.biWidth * sizeof(RGBTRIPLE)) % 4) % 4;
  20. printf("oldpadding: %in", oldpadding);
  21.  
  22. int oldWidth = bi.biWidth;
  23. int oldHeight = abs(bi.biHeight);
  24.  
  25. bi.biWidth = bi.biWidth * scale;
  26. bi.biHeight = bi.biHeight * scale;
  27.  
  28. // determine padding for scanlines
  29. int padding = (4 - (bi.biWidth * sizeof(RGBTRIPLE)) % 4) % 4;
  30. printf("padding: %in", padding);
  31.  
  32. bi.biSizeImage = ( ( (sizeof(RGBTRIPLE) * bi.biWidth) + padding) * abs(bi.biHeight) );
  33. bf.bfSize = sizeof( BITMAPFILEHEADER ) + sizeof( BITMAPINFOHEADER ) + bi.biSizeImage;
  34.  
  35. // write outfile's BITMAPFILEHEADER
  36. fwrite(&bf, sizeof(BITMAPFILEHEADER), 1, outptr);
  37.  
  38. // write outfile's BITMAPINFOHEADER
  39. fwrite(&bi, sizeof(BITMAPINFOHEADER), 1, outptr);
  40.  
  41.  
  42. // iterate over infile's scanlines
  43. for (int i = 0; i < oldHeight; i++)
  44. {
  45. int m = 0;
  46. int rgb = sizeof(RGBTRIPLE);
  47. RGBTRIPLE* pixel = malloc(rgb * bi.biWidth);
  48.  
  49. RGBTRIPLE black;
  50. black.rgbtBlue = 255;
  51. black.rgbtGreen = 255;
  52. black.rgbtRed = 255;
  53.  
  54. for (int clear = 0; clear < (rgb * bi.biWidth); clear++)
  55. {
  56. pixel[clear] = black;
  57. }
  58.  
  59.  
  60. // iterate over pixels in scanline
  61. for (int j = 0; j < oldWidth; j++)
  62. {
  63. // temporary storage
  64. RGBTRIPLE triple;
  65.  
  66. // read RGB triple from infile
  67. fread(&triple, sizeof(RGBTRIPLE), 1, inptr);
  68.  
  69. for (int l = 0; l < scale; l++)
  70. {
  71. // write RGB triple to outfile
  72. fwrite(&triple, sizeof(RGBTRIPLE), 1, outptr);
  73.  
  74. pixel[m] = triple;
  75. m++;
  76. //m++; m++;
  77. //m++; m++; m++;
  78. printf("%x %x %xn", pixel->rgbtBlue, pixel->rgbtGreen, pixel->rgbtRed);
  79. }
  80.  
  81. if (j == (oldWidth - 1) )
  82. {
  83. // skip over padding, if any
  84. fseek(inptr, oldpadding, SEEK_CUR);
  85.  
  86. for (int k = 0; k < padding; k++)
  87. {
  88. fputc(0x00, outptr);
  89. }
  90.  
  91. printf("%pn",pixel);
  92.  
  93. int b = scale - 1;
  94. while (b > 0)
  95. {
  96. fwrite(&pixel, rgb * bi.biWidth, 1, outptr);
  97. b--;
  98.  
  99. for (int k = 0; k < padding; k++)
  100. {
  101. fputc(0x00, outptr);
  102. }
  103. }
  104. free(pixel);
  105. }
  106. }
  107.  
  108. }
  109.  
  110.  
  111. // close infile
  112. fclose(inptr);
  113.  
  114. // close outfile
  115. fclose(outptr);
  116.  
  117. // success
  118. return 0;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement