Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Task 1 - Load a 512x512 image lena.raw
- // - Apply specified per-pixel transformation to each pixel
- // - Save as result.raw
- #include "stdafx.h"
- #include <fstream>
- #include <iostream>
- using namespace std;
- // Size of the framebuffer
- const unsigned int SIZE = 512;
- // A simple RGB struct will represent a pixel in the framebuffer
- struct Pixel {
- // TODO: Define correct data type for r, g, b channel
- uint8_t r, g, b;
- };
- int main()
- {
- // Initialize a framebuffer
- auto framebuffer = new Pixel[SIZE][SIZE];
- uint8_t treshholdMin = 20;
- uint8_t treshholdMax = 200;
- // TODO: Open file lena.raw (this is 512x512 RAW GRB format)
- FILE *fr = fopen("lena.raw", "r");
- // TODO: Read data to framebuffer and close the file
- fread(framebuffer, SIZE * SIZE * sizeof(Pixel), 1, fr);
- fclose(fr);
- // Traverse the framebuffer
- for (unsigned int y = 0; y < SIZE; y++) {
- for (unsigned int x = 0; x < SIZE; x++) {
- // TODO: Apply pixel operation
- }
- }
- // TODO: Open file result.raw
- cout << "Generating result.raw file ..." << endl;
- FILE *fw = fopen("result.raw", "w");
- // TODO: Write the framebuffer to the file and close it
- fwrite(framebuffer, SIZE * SIZE * sizeof(Pixel), 1, fw);
- fclose(fw);
- cout << "Done." << endl;
- delete[] framebuffer;
- return EXIT_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement