Advertisement
czlowiekzgon

bmp

Dec 8th, 2019
336
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. void ReadBMP(string filename)
  2. {
  3. FILE* fileOpen = fopen(filename.c_str(), "rb");
  4.  
  5. if (fileOpen == NULL)
  6. throw "Argument Exception";
  7.  
  8. fread(info, sizeof(unsigned char), 54, fileOpen); // read the 54-byte header
  9.  
  10. width = *(int*)&info[18];
  11. height = *(int*)&info[22];
  12.  
  13. int max_value, temp_value;
  14. for (int i = 1; i < width; i++)
  15. {
  16. temp_value = GCD(i, width);
  17. if (temp_value > max_value)
  18. max_value = temp_value;
  19. }
  20.  
  21. int row_padded = (width * 3 + 3) & (~3);
  22. unsigned char* data = new unsigned char[row_padded];
  23. unsigned char tempPixel;
  24.  
  25. img.width = width;
  26. img.height = height;
  27. img.pixels = new int[height * width * 3];
  28.  
  29. cpuImage.width = width;
  30. cpuImage.height = height;
  31. cpuImage.pixels = new int[height * width * 3];
  32.  
  33. gpuImage.width = width;
  34. gpuImage.height = height;
  35. gpuImage.pixels = new int[height * width * 3];
  36.  
  37. N = width * height * 3;
  38.  
  39. for (int i = 0; i < height; i++)
  40. {
  41. fread(data, sizeof(unsigned char), row_padded, fileOpen);
  42. for (int j = 0; j < width * 3; j += 3)
  43. {
  44. tempPixel = data[j];
  45. data[j] = data[j + 2];
  46. data[j + 2] = tempPixel;
  47. img.pixels[i * width * 3 + (j / 3) * 3 + 0] = (int)data[j];
  48. img.pixels[i * width * 3 + (j / 3) * 3 + 1] = (int)data[j + 1];
  49. img.pixels[i * width * 3 + (j / 3) * 3 + 2] = (int)data[j + 2];
  50.  
  51. }
  52. }
  53.  
  54. fclose(fileOpen);
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement