switched to unsigned int everywhere

master
Anton Lydike 3 years ago
parent a71e319fb4
commit f503f1835f

@ -4,7 +4,7 @@
#include "images.h" #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)); //Image img = malloc(sizeof(Image));
if (img == NULL) return 0; if (img == NULL) return 0;
@ -20,7 +20,7 @@ int image_new(int width, int height, Image* img) {
// initialize bitmap... // initialize bitmap...
img->bitmap = malloc(height * sizeof(char*)); 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)); img->bitmap[i] = malloc(3 * width * sizeof(char));
} }
@ -28,7 +28,7 @@ int image_new(int width, int height, Image* img) {
return 1; 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; if (!image_check_coords(image, x, y)) return 0;
image.bitmap[y][(3 * x) + 0] = r; 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; 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 (!image_check_coords(image, x, y)) return 0;
if (color.alpha == 0) return 1; 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; 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 && return x >= 0 && x < image.width &&
y >= 0 && y < image.height; y >= 0 && y < image.height;
} }

@ -11,17 +11,17 @@ typedef struct _color {
typedef struct _image { typedef struct _image {
unsigned char** bitmap; unsigned char** bitmap;
int width; unsigned int width;
int height; unsigned int height;
} Image; } Image;
// basic image manipulation (src/images.c) // 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(Image image, unsigned int x, unsigned 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_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); int image_destroy(Image image);

@ -22,7 +22,7 @@ int image_new_shared(int width, int height, Image* img) {
} }
void image_destroy_shared(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[i], 3 * img.width * sizeof(char));
} }
munmap(img.bitmap, img.height * sizeof(char*)); munmap(img.bitmap, img.height * sizeof(char*));

Loading…
Cancel
Save