aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar jonas <himself@jonasgunz.de> 2019-04-28 11:00:27 +0200
committerGravatar jonas <himself@jonasgunz.de> 2019-04-28 11:00:27 +0200
commit15dc2c219595a92ca121578b13047e23156ea3fa (patch)
tree7523a22aa094aaf79a72100c8f8a0d4a04f0bfe3
parentdd029dad99fd17770980ff87b909733e7594b829 (diff)
downloadAsciiMap-15dc2c219595a92ca121578b13047e23156ea3fa.tar.gz
Added DEBUG messages and debug make target
-rw-r--r--Makefile7
-rw-r--r--bitmap.c2
-rw-r--r--main.c21
3 files changed, 18 insertions, 12 deletions
diff --git a/Makefile b/Makefile
index 7f64ce5..be95545 100644
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,5 @@
CC = /usr/bin/gcc
-CFLAGS = -Wall -g
+CFLAGS = -Wall
LDFLAGS = -lm
OUTPUT = bitmap
BUILDDIR = build
@@ -12,7 +12,10 @@ build: $(OBJ)
mkdir -p $(BUILDDIR)
$(CC) $(CFLAGS) -o $(BUILDDIR)/$(OUTPUT) $(OBJ) $(LDFLAGS)
-debug: build
+debug: CFLAGS+= -g -D _DEBUG
+debug: build;
+
+gdb: debug
gdb $(BUILDDIR)/$(OUTPUT)
%.o: %.c
diff --git a/bitmap.c b/bitmap.c
index a99e335..bb88b46 100644
--- a/bitmap.c
+++ b/bitmap.c
@@ -22,7 +22,7 @@ struct bitmap_pixel_data bitmap_read(char *_file)
ret.R = ret.G = ret.B = NULL;
ret.error = 1;
- FILE *bitmap = fopen(_file,"r");
+ FILE *bitmap = fopen(_file,"rb");
if(!bitmap)
return ret;
diff --git a/main.c b/main.c
index f0803ca..2aaf11c 100644
--- a/main.c
+++ b/main.c
@@ -5,6 +5,12 @@
#include "bitmap.h"
+#ifdef _DEBUG
+#warning "Compiling with DEBUG"
+#define DEBUG_PRINTF(...) { printf(__VA_ARGS__); }
+#else
+#define DEBUG_PRINTF(...) { }
+#endif
#define _HEADER_SIZE 54 //Fileheader + infoheader
#define IDENTIFIER 0x424d //BM BitMap identifier
@@ -28,7 +34,6 @@
const char map[] = {' ', ' ', '.', ',', '`', '-', '~', '"', '*', ':', ';', '<', '!', '/', '?', '%', '&', '=', '$', '#'};
//const char map[] = {' ', '`', '.', ',', ':', ';', '\"', '+', '#', '@'};
-//Routine for flipping bytes
//Calculate average
char avg(int argc, char *argv);
@@ -68,7 +73,7 @@ int main(int argc, char *argv[])
size_x = bitmap.x / CHAR_SIZE_X;
size_y = bitmap.y / CHAR_SIZE_Y;
- printf("Creating ASCII File %u x %u\n", size_x, size_y);
+ DEBUG_PRINTF("Creating ASCII File %u x %u\n", size_x, size_y);
ascii_buff = malloc(sizeof(*ascii_buff) * size_x);
for (int i = 0; i < size_x; i++)
@@ -103,10 +108,10 @@ int main(int argc, char *argv[])
}
}
- printf("Brightness Values: Min: %u Max: %u\n", b_min, b_max);
+ DEBUG_PRINTF("Brightness Values: Min: %u Max: %u\n", b_min, b_max);
//Write Output
- printf("Opening %s for writing.\n", argv[2]);
+ DEBUG_PRINTF("Opening %s for writing.\n", argv[2]);
FILE *out = fopen(argv[2], "w");
if(!out)
@@ -121,16 +126,14 @@ int main(int argc, char *argv[])
{
fputc( calc_char(ascii_buff[x][y], b_min, b_max) , out);
}
- printf(".");
+ DEBUG_PRINTF(".");
fputc('\n', out);
}
- printf("\n");
+ DEBUG_PRINTF("\n");
- printf("Finished!\n");
+ DEBUG_PRINTF("Finished!\n");
//Cleanup
-
-
for(int i = 0; i < size_x; i++)
free (ascii_buff[i]);
free(ascii_buff);