Phase 1 - Output Something
First thing is to get an image rendered. I selected TARGA since it seems like an easy format and supports uncompressed, raw binary. Pixel content is just a gradient from black to full blue-green in a whopping 32 x 32 resolution.
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
int main() {
FILE* outputFile = fopen("output.tga", "wb");
uint8_t* pixels = (uint8_t*)malloc(32 * 32 * 3);
uint8_t* p = pixels;
uint8_t blue = 0;
for(int i = 0; i < 32; ++i) {
uint8_t green = 0;
for(int j = 0; j < 32; ++j) {
*p = blue & 0xFF; p++;
*p = green & 0xFF; p++;
*p = 0x0; p++;
green += 7;
}
blue += 7;
}
uint8_t tgaHeader[18] = {0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
tgaHeader[12] = 32 & 0xFF;
tgaHeader[13] = (32 >> 8) & 0xFF;
tgaHeader[14] = (32) & 0xFF;
tgaHeader[15] = (32 >> 8) & 0xFF;
tgaHeader[16] = 24;
fwrite(tgaHeader, sizeof(uint8_t), 18, outputFile);
fwrite(pixels, sizeof(uint8_t), 32 * 32 * 3, outputFile);
fclose(outputFile);
free(pixels);
return 0;
}
That's it. We now have a program that outputs an image file:
See the phase 1 source code in github
Written on March 5, 2015