diff options
author | Jonas Gunz <himself@jonasgunz.de> | 2020-09-02 17:29:51 +0200 |
---|---|---|
committer | Jonas Gunz <himself@jonasgunz.de> | 2020-09-02 17:29:51 +0200 |
commit | 96fe104e6b1c1452a8408bb46baa73d2b93bcf0e (patch) | |
tree | 88a883853fb100d54d35921c0d3e7c6b39a899ee /src | |
parent | f546868b1f4d0eae4dc3ecc26035829cf0f2f721 (diff) | |
download | AsciiMap-96fe104e6b1c1452a8408bb46baa73d2b93bcf0e.tar.gz |
bitmap_strerror: More verbose bitmap failures
Diffstat (limited to 'src')
-rw-r--r-- | src/bitmap.c | 16 | ||||
-rw-r--r-- | src/bitmap.h | 2 | ||||
-rw-r--r-- | src/main.c | 7 |
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_ */ @@ -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) { |