Advertisement
Guest User

Untitled

a guest
Sep 25th, 2017
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. // Task 1 - Load a 512x512 image lena.raw
  2. // - Apply specified per-pixel transformation to each pixel
  3. // - Save as result.raw
  4. #include "stdafx.h"
  5. #include <fstream>
  6. #include <iostream>
  7.  
  8. using namespace std;
  9.  
  10. // Size of the framebuffer
  11. const unsigned int SIZE = 512;
  12.  
  13. // A simple RGB struct will represent a pixel in the framebuffer
  14. struct Pixel {
  15. // TODO: Define correct data type for r, g, b channel
  16. uint8_t r, g, b;
  17. };
  18.  
  19. int main()
  20. {
  21. // Initialize a framebuffer
  22. auto framebuffer = new Pixel[SIZE][SIZE];
  23. uint8_t treshholdMin = 20;
  24. uint8_t treshholdMax = 200;
  25.  
  26. // TODO: Open file lena.raw (this is 512x512 RAW GRB format)
  27. FILE *fr = fopen("lena.raw", "r");
  28.  
  29. // TODO: Read data to framebuffer and close the file
  30. fread(framebuffer, SIZE * SIZE * sizeof(Pixel), 1, fr);
  31. fclose(fr);
  32.  
  33. // Traverse the framebuffer
  34. for (unsigned int y = 0; y < SIZE; y++) {
  35. for (unsigned int x = 0; x < SIZE; x++) {
  36. // TODO: Apply pixel operation
  37.  
  38.  
  39.  
  40. }
  41. }
  42.  
  43. // TODO: Open file result.raw
  44. cout << "Generating result.raw file ..." << endl;
  45. FILE *fw = fopen("result.raw", "w");
  46.  
  47. // TODO: Write the framebuffer to the file and close it
  48. fwrite(framebuffer, SIZE * SIZE * sizeof(Pixel), 1, fw);
  49. fclose(fw);
  50.  
  51. cout << "Done." << endl;
  52. delete[] framebuffer;
  53. return EXIT_SUCCESS;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement