fix segfault

This commit is contained in:
Minecon724 2024-08-04 12:03:56 +02:00
parent a047deda99
commit ec1fefc32e
Signed by: Minecon724
GPG key ID: 3CCC4D267742C8E8
2 changed files with 15 additions and 8 deletions

View file

@ -1,18 +1,22 @@
CC = gcc
CFLAGS = -Wall -g -L. -lm -O3 -march=native
CFLAGS = -Wall -L. -lm -O3 -march=native
CDEBUGFLAGS = -Wall -L. -lm -g
SOURCE = main.c
TARGET = enhancer
# Default target
all: $(TARGET)
all: release
# Rule to build the executable
$(TARGET): $(SOURCE)
$(CC) $(CFLAGS) -o $@ $<
release: $(SOURCE)
$(CC) $(CFLAGS) -o $(TARGET) $<
debug: $(SOURCE)
$(CC) $(CDEBUGFLAGS) -o $(TARGET)_debug $<
# Rule to clean up object files and the executable
clean:
rm -f $(TARGET) *.o
rm -f $(TARGET) $(TARGET)_debug *.o
# Phony targets
.PHONY: all clean
.PHONY: all clean

7
main.c
View file

@ -76,6 +76,8 @@ void vibrancer(unsigned char *pixel) {
g = pixel[1],
b = pixel[2];
printf("%d %d %d\n", r, g, b);
// TODO remove unnecessary calculations
int min_rgb = min3(r, g, b);
int max_rgb = max3(r, g, b);
@ -99,7 +101,6 @@ void vibrancer(unsigned char *pixel) {
pixel[0] = clamp(r, 0, 255);
pixel[1] = clamp(g, 0, 255);
pixel[2] = clamp(b, 0, 255);
}
int main(int argc, char **argv) {
@ -118,7 +119,9 @@ int main(int argc, char **argv) {
int width, height, channels;
unsigned char *img = stbi_load(input, &width, &height, &channels, 3);
unsigned char *img = stbi_load(input, &width, &height, &channels, 0);
printf("Width: %d, Height: %d, Channels: %d\n", width, height, channels);
if (img == NULL) {
printf("Error loading image\n");