forked from drahosp/ppgso
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathraw_gradient.cpp
More file actions
49 lines (39 loc) · 1.39 KB
/
raw_gradient.cpp
File metadata and controls
49 lines (39 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// This very simple example illustrates the concept of a framebuffer
// We do not really need any libraries or hardware to do computer graphics
// In this case the framebuffer is simply saved as a raw RGB and TGA image
#include <iostream>
#include <fstream>
// A header implementation of a TGAImage object
#include "tga.h"
// Size of the framebuffer
const unsigned int SIZE = 512;
// A simple RGB struct will represent a pixel in the framebuffer
// Note: unsigned char is range <0, 255>
// signed char is range <-128, 127>
struct Pixel {
unsigned char r,g,b;
};
int main() {
// Initialize a framebuffer
Pixel framebuffer[SIZE][SIZE];
// Example: Generate a simple gradient
for ( unsigned int x = 0; x < SIZE; ++x ) {
for ( unsigned int y = 0; y < SIZE; ++y ) {
framebuffer[x][y].r = x/2;
framebuffer[x][y].g = y/2;
framebuffer[x][y].b = 0;
}
}
// Task1: Load RAW image file here instead
// Task2: Apply a convolution filter to the loaded image
// Task3: Merge multiple images using alpha blending
// Task4: Draw lines and Bezier curves
// Save the raw image to a file
std::ofstream raw("result.rgb", std::ios::binary);
raw.write((char*)framebuffer, sizeof(framebuffer));
raw.close();
// Helper object to save the framebuffer as TGA image
TGAImage tga(SIZE, SIZE, 3, framebuffer);
tga.write_tga_file("result.tga", true);
return EXIT_SUCCESS;
}