From 52214c5a1cf765aab5e89a00c8a7ceaa3d324f2b Mon Sep 17 00:00:00 2001 From: Robin Stuart Date: Sun, 29 Mar 2020 13:42:33 +0100 Subject: [PATCH] Change bitmap signedness to allow conversion to other data types Buffered bitmap array should have been type unsigned char not type char Includes change to manual In response to (and hopefully fixing) #182 reported by Marcelo Antunes --- backend/raster.c | 4 ++-- backend/zint.h | 2 +- docs/manual.txt | 11 ++++++----- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/backend/raster.c b/backend/raster.c index 25fac7bb..80dca387 100644 --- a/backend/raster.c +++ b/backend/raster.c @@ -61,7 +61,7 @@ static void buffer_plot(struct zint_symbol *symbol, char *pixelbuf) { int fgred, fggrn, fgblu, bgred, bggrn, bgblu; int row, column, i; - symbol->bitmap = (char *) malloc(symbol->bitmap_width * symbol->bitmap_height * 3); + symbol->bitmap = (unsigned char *) malloc(symbol->bitmap_width * symbol->bitmap_height * 3); fgred = (16 * ctoi(symbol->fgcolour[0])) + ctoi(symbol->fgcolour[1]); fggrn = (16 * ctoi(symbol->fgcolour[2])) + ctoi(symbol->fgcolour[3]); @@ -69,7 +69,7 @@ static void buffer_plot(struct zint_symbol *symbol, char *pixelbuf) { bgred = (16 * ctoi(symbol->bgcolour[0])) + ctoi(symbol->bgcolour[1]); bggrn = (16 * ctoi(symbol->bgcolour[2])) + ctoi(symbol->bgcolour[3]); bgblu = (16 * ctoi(symbol->bgcolour[4])) + ctoi(symbol->bgcolour[5]); - + for (row = 0; row < symbol->bitmap_height; row++) { for (column = 0; column < symbol->bitmap_width; column++) { i = ((row * symbol->bitmap_width) + column) * 3; diff --git a/backend/zint.h b/backend/zint.h index 8686f318..c51c7c67 100644 --- a/backend/zint.h +++ b/backend/zint.h @@ -125,7 +125,7 @@ extern "C" { unsigned char encoded_data[200][143]; int row_height[200]; /* Largest symbol is 189 x 189 Han Xin */ char errtxt[100]; - char *bitmap; + unsigned char *bitmap; int bitmap_width; int bitmap_height; unsigned int bitmap_byte_length; diff --git a/docs/manual.txt b/docs/manual.txt index 0b821b45..c3c7dc51 100644 --- a/docs/manual.txt +++ b/docs/manual.txt @@ -749,13 +749,13 @@ the example below where render_pixel() is assumed to be a function for drawing a pixel on the screen implemented by the external application: int row, col, i = 0; -unsigned int red, blue, green; +int red, blue, green; for (row = 0; row < my_symbol->bitmap_height; row++) { for (column = 0; col < my_symbol->bitmap_width; column++) { - red = my_symbol->bitmap[i]; - green = my_symbol->bitmap[i + 1]; - blue = my_symbol->bitmap[i + 2]; + red = (int) my_symbol->bitmap[i]; + green = (int) my_symbol->bitmap[i + 1]; + blue = (int) my_symbol->bitmap[i + 2]; render_pixel(row, column, red, green, blue); i += 3; } @@ -826,7 +826,8 @@ row_height | array of | Representation of the | (output only) errtxt | character | Error message in the event | (output only) | string | that an error ocurred. | bitmap | pointer to | Pointer to stored bitmap | (output only) - | character | image. | + | unsigned | image. | + | character | | | array | | bitmap_width | integer | Width of stored bitmap | (output only) | | image (in pixels). |