aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/bitmap.c16
-rw-r--r--src/bitmap.h2
-rw-r--r--src/main.c7
3 files changed, 22 insertions, 3 deletions
diff --git a/src/bitmap.c b/src/bitmap.c
index 6d72cb0..31256e8 100644
--- a/src/bitmap.c
+++ b/src/bitmap.c
@@ -6,6 +6,15 @@
#include "bitmap.h"
+static const int bitmap_errors_cnt = 5;
+static const char* bitmap_errors[] = {
+ "OK.",
+ "Error opening file.", // Use errno instead
+ "Invalid or corrupted file.",
+ "Unsupported bit depth.",
+ "Compression not supported."
+};
+
static struct bitmap_file_header bitmap_read_file_header(FILE *_file);
static struct bitmap_image bitmap_read_pixel_data(FILE *_file, struct bitmap_file_header _header);
@@ -265,3 +274,10 @@ static uint8_t bitmap_rgb_luminance(uint8_t R, uint8_t G, uint8_t B) {
return ret;
}
+
+char* bitmap_strerror( int _error ) {
+ if ( _error >= bitmap_errors_cnt || _error < 0)
+ return "Unknown Error.";
+
+ return (char*) bitmap_errors[_error];
+}
diff --git a/src/bitmap.h b/src/bitmap.h
index 48fd1ac..9f8e312 100644
--- a/src/bitmap.h
+++ b/src/bitmap.h
@@ -80,4 +80,6 @@ int bitmap_shrink ( struct bitmap_image *_input, struct bitmap_image *_output, u
int bitmap_fit_to_width ( struct bitmap_image *_input, struct bitmap_image *_output, unsigned int _width );
+char* bitmap_strerror( int _error );
+
#endif /* end of include guard: _BITMAP_H_ */
diff --git a/src/main.c b/src/main.c
index 325f8af..90bfcc0 100644
--- a/src/main.c
+++ b/src/main.c
@@ -51,9 +51,10 @@ int main(int argc, char *argv[])
uint8_t brightness_min = 0x00;
uint8_t brightness_max = 0xff;
- if ( bitmap_read(args.filename, &bitmap) ) {
- printf("Error reading file\n");
- return 1;
+ int ret = bitmap_read(args.filename, &bitmap);
+ if ( ret ) {
+ printf( "%s\n", bitmap_strerror(ret) );
+ return ret;
}
if(args.fit_width > 0) {