From f503f1835fd47de323b19d8f3f1ea0fc542dd6f6 Mon Sep 17 00:00:00 2001 From: Anton Lydike Date: Fri, 20 May 2022 20:43:27 +0200 Subject: [PATCH] switched to unsigned int everywhere --- src/images.c | 10 +++++----- src/images.h | 12 ++++++------ src/multithreading.c | 2 +- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/images.c b/src/images.c index a02870e..4619419 100644 --- a/src/images.c +++ b/src/images.c @@ -4,7 +4,7 @@ #include "images.h" -int image_new(int width, int height, Image* img) { +int image_new(unsigned int width, unsigned int height, Image* img) { //Image img = malloc(sizeof(Image)); if (img == NULL) return 0; @@ -20,7 +20,7 @@ int image_new(int width, int height, Image* img) { // initialize bitmap... img->bitmap = malloc(height * sizeof(char*)); - for (int i = 0; i < height; i++) { + for (unsigned int i = 0; i < height; i++) { img->bitmap[i] = malloc(3 * width * sizeof(char)); } @@ -28,7 +28,7 @@ int image_new(int width, int height, Image* img) { return 1; } -int image_set_px(Image image, int x, int y, int r, int g, int b) { +int image_set_px(Image image, unsigned int x, unsigned int y, int r, int g, int b) { if (!image_check_coords(image, x, y)) return 0; image.bitmap[y][(3 * x) + 0] = r; @@ -37,7 +37,7 @@ int image_set_px(Image image, int x, int y, int r, int g, int b) { return 1; } -int image_set_px_c(Image image, int x, int y, Color color) { +int image_set_px_c(Image image, unsigned int x, unsigned int y, Color color) { if (!image_check_coords(image, x, y)) return 0; if (color.alpha == 0) return 1; @@ -55,7 +55,7 @@ int image_set_px_c(Image image, int x, int y, Color color) { return 1; } -int image_check_coords(Image image, int x, int y) { +int image_check_coords(Image image, unsigned int x, unsigned int y) { return x >= 0 && x < image.width && y >= 0 && y < image.height; } diff --git a/src/images.h b/src/images.h index dcd628f..c877b72 100644 --- a/src/images.h +++ b/src/images.h @@ -11,17 +11,17 @@ typedef struct _color { typedef struct _image { unsigned char** bitmap; - int width; - int height; + unsigned int width; + unsigned int height; } Image; // basic image manipulation (src/images.c) -int image_new(int width, int height, Image* image); +int image_new(unsigned int width, unsigned int height, Image* image); -int image_set_px(Image image, int x, int y, int r, int g, int b); -int image_set_px_c(Image image, int x, int y, Color color); +int image_set_px(Image image, unsigned int x, unsigned int y, int r, int g, int b); +int image_set_px_c(Image image, unsigned int x, unsigned int y, Color color); -int image_check_coords(Image image, int x, int y); +int image_check_coords(Image image, unsigned int x, unsigned int y); int image_destroy(Image image); diff --git a/src/multithreading.c b/src/multithreading.c index c5cca94..e7b1166 100644 --- a/src/multithreading.c +++ b/src/multithreading.c @@ -22,7 +22,7 @@ int image_new_shared(int width, int height, Image* img) { } void image_destroy_shared(Image img) { - for (int i = 0; i < img.height; i++) { + for (unsigned int i = 0; i < img.height; i++) { munmap(img.bitmap[i], 3 * img.width * sizeof(char)); } munmap(img.bitmap, img.height * sizeof(char*));