diff options
| author | Levent Kaya <42411502+lvntky@users.noreply.github.com> | 2024-11-28 01:01:46 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-11-28 01:01:46 +0300 |
| commit | 8b25ef20ab3ffa29238f8b4bb2c6c0b7ec886caa (patch) | |
| tree | 84f143235b5e1e6f1d9d06764ac35addd4b97f5e /examples/text.c | |
| parent | eff7f86c4b81e804b13c5606fcc73a6dbfa58677 (diff) | |
| parent | 528209831fc8f188df895acae83174bb81996c96 (diff) | |
Merge pull request #12 from dario-loi/master
Code quality and warning removal
Diffstat (limited to 'examples/text.c')
| -rw-r--r-- | examples/text.c | 47 |
1 files changed, 22 insertions, 25 deletions
diff --git a/examples/text.c b/examples/text.c index 9003e3c..ee1efc9 100644 --- a/examples/text.c +++ b/examples/text.c @@ -16,35 +16,35 @@ int save_framebuffer_as_ppm(fbgl_t *fb, const char *filename) } // Write PPM header (P6 format - binary RGB) - fprintf(fp, "P6\n%u %u\n255\n", fb->width, fb->height); + fprintf(fp, "P6\n%u %u\n255\n", fb->width, fb->height); - // Allocate buffer for pixel data - uint8_t* pixel_buffer = malloc(fb->width * fb->height * 3); - if (!pixel_buffer) { + // Allocate buffer for pixel data + uint8_t *pixel_buffer = malloc(fb->width * fb->height * 3); + if (!pixel_buffer) { perror("Memory allocation error"); fclose(fp); return -1; } // Convert framebuffer to RGB - for (int32_t y = 0; y < fb->height; y++) { - for (int32_t x = 0; x < fb->width; x++) { - uint32_t pixel = fb->pixels[y * fb->width + x]; - - // Extract RGB components (assuming 32-bit ARGB or RGB) - uint8_t r = (pixel >> 16) & 0xFF; - uint8_t g = (pixel >> 8) & 0xFF; - uint8_t b = pixel & 0xFF; - - // Store in buffer for PPM - pixel_buffer[(y * fb->width + x) * 3] = r; - pixel_buffer[(y * fb->width + x) * 3 + 1] = g; - pixel_buffer[(y * fb->width + x) * 3 + 2] = b; - } - } + for (int32_t y = 0; y < fb->height; y++) { + for (int32_t x = 0; x < fb->width; x++) { + uint32_t pixel = fb->pixels[y * fb->width + x]; + + // Extract RGB components (assuming 32-bit ARGB or RGB) + uint8_t r = (pixel >> 16) & 0xFF; + uint8_t g = (pixel >> 8) & 0xFF; + uint8_t b = pixel & 0xFF; + + // Store in buffer for PPM + pixel_buffer[(y * fb->width + x) * 3] = r; + pixel_buffer[(y * fb->width + x) * 3 + 1] = g; + pixel_buffer[(y * fb->width + x) * 3 + 2] = b; + } + } - // Write pixel data - fwrite(pixel_buffer, 1, fb->width * fb->height * 3, fp); + // Write pixel data + fwrite(pixel_buffer, 1, fb->width * fb->height * 3, fp); // Cleanup free(pixel_buffer); @@ -76,9 +76,6 @@ int main(int argc, char *argv[]) // Text to render const char *text = "Hello, fbgl!"; - // Calculate text width - size_t text_width = strlen(text) * 8; - // Calculate centered position int x = (fb.width - 8) / 2; int y = (fb.height - 16) / 2; @@ -96,7 +93,7 @@ int main(int argc, char *argv[]) // Wait for a bit to show the image size_t framerate = 30 * 30; for (size_t i = 0; i < framerate; i++) { - usleep(50000); + nanosleep((struct timespec[]){ { 0, (int)5e7 } }, NULL); } // Cleanup |
