comparison ppm.c @ 2685:da2e06c42d16

Add a compile-time flag to use RGB565 instead of ABGR/ARGB
author Michael Pavone <pavone@retrodev.com>
date Sun, 30 Mar 2025 00:06:53 -0700
parents 5f65a16c23ff
children
comparison
equal deleted inserted replaced
2684:c649bcc18487 2685:da2e06c42d16
1 #include <stdint.h> 1 #include <stdint.h>
2 #include <stdio.h> 2 #include <stdio.h>
3 #include "pixel.h"
3 4
4 void save_ppm(FILE *f, uint32_t *buffer, uint32_t width, uint32_t height, uint32_t pitch) 5 void save_ppm(FILE *f, pixel_t *buffer, uint32_t width, uint32_t height, uint32_t pitch)
5 { 6 {
6 fprintf(f, "P6\n%d %d\n255\n", width, height); 7 fprintf(f, "P6\n%d %d\n255\n", width, height);
7 for(uint32_t y = 0; y < height; y++) 8 for(uint32_t y = 0; y < height; y++)
8 { 9 {
9 uint32_t *line = buffer; 10 pixel_t *line = buffer;
10 for (uint32_t x = 0; x < width; x++, line++) 11 for (uint32_t x = 0; x < width; x++, line++)
11 { 12 {
12 uint8_t buf[3] = { 13 uint8_t buf[3] = {
14 #ifdef USE_RGB565
15 (*line >> 8 & 0xF8) | (*line >> (8+5)), //red
16 (*line >> 3 & 0xFC) | (*line >> (3+5) & 0x3), //green
17 *line << 3 | (*line >> (5-3) & 0x3) //blue
18 #else
19 #ifdef USE_GLES
20 *line, //red
21 *line >> 8, //green
22 *line >> 16 //blue
23 #else
13 *line >> 16, //red 24 *line >> 16, //red
14 *line >> 8, //green 25 *line >> 8, //green
15 *line //blue 26 *line //blue
27 #endif
28 #endif
16 }; 29 };
17 fwrite(buf, 1, sizeof(buf), f); 30 fwrite(buf, 1, sizeof(buf), f);
18 } 31 }
19 buffer = buffer + pitch / sizeof(uint32_t); 32 buffer = buffer + pitch / sizeof(pixel_t);
20 } 33 }
21 } 34 }