diff --git a/backend/bmp.c b/backend/bmp.c index aad8407a..f816488d 100644 --- a/backend/bmp.c +++ b/backend/bmp.c @@ -49,6 +49,7 @@ int bmp_pixel_plot(struct zint_symbol *symbol, char *pixelbuf) { int row_size; unsigned int data_size; unsigned char *bitmap_file_start, *bmp_posn; + char *bitmap; FILE *bmp_file; bitmap_file_header_t file_header; bitmap_info_header_t info_header; @@ -57,7 +58,7 @@ int bmp_pixel_plot(struct zint_symbol *symbol, char *pixelbuf) { free(symbol->bitmap); row_size = 4 * floor((24.0 * symbol->bitmap_width + 31) / 32); - symbol->bitmap = (char *) malloc(row_size * symbol->bitmap_height); + bitmap = (char *) malloc(row_size * symbol->bitmap_height); fgred = (16 * ctoi(symbol->fgcolour[0])) + ctoi(symbol->fgcolour[1]); fggrn = (16 * ctoi(symbol->fgcolour[2])) + ctoi(symbol->fgcolour[3]); @@ -73,14 +74,14 @@ int bmp_pixel_plot(struct zint_symbol *symbol, char *pixelbuf) { i = (3 * column) + (row * row_size); switch (*(pixelbuf + (symbol->bitmap_width * (symbol->bitmap_height - row - 1)) + column)) { case '1': - symbol->bitmap[i] = fgblu; - symbol->bitmap[i + 1] = fggrn; - symbol->bitmap[i + 2] = fgred; + bitmap[i] = fgblu; + bitmap[i + 1] = fggrn; + bitmap[i + 2] = fgred; break; default: - symbol->bitmap[i] = bgblu; - symbol->bitmap[i + 1] = bggrn; - symbol->bitmap[i + 2] = bgred; + bitmap[i] = bgblu; + bitmap[i + 1] = bggrn; + bitmap[i + 2] = bgred; break; } @@ -115,7 +116,7 @@ int bmp_pixel_plot(struct zint_symbol *symbol, char *pixelbuf) { bmp_posn += sizeof (bitmap_file_header_t); memcpy(bmp_posn, &info_header, sizeof (bitmap_info_header_t)); bmp_posn += sizeof (bitmap_info_header_t); - memcpy(bmp_posn, symbol->bitmap, data_size); + memcpy(bmp_posn, bitmap, data_size); /* Open output file in binary mode */ if ((symbol->output_options & BARCODE_STDOUT) != 0) { @@ -137,5 +138,6 @@ int bmp_pixel_plot(struct zint_symbol *symbol, char *pixelbuf) { fclose(bmp_file); free(bitmap_file_start); + free(bitmap); return 0; } \ No newline at end of file diff --git a/backend/library.c b/backend/library.c index ac71cbca..cff6acdd 100644 --- a/backend/library.c +++ b/backend/library.c @@ -1177,7 +1177,7 @@ int ZBarcode_Buffer(struct zint_symbol *symbol, int rotate_angle) { return ZINT_ERROR_INVALID_OPTION; } - error_number = plot_raster(symbol, rotate_angle, OUT_BMP_FILE); + error_number = plot_raster(symbol, rotate_angle, OUT_BUFFER); error_tag(symbol->errtxt, error_number); return error_number; } diff --git a/backend/raster.c b/backend/raster.c index 6611fdec..6ed5d758 100644 --- a/backend/raster.c +++ b/backend/raster.c @@ -53,6 +53,40 @@ extern int bmp_pixel_plot(struct zint_symbol *symbol, char *pixelbuf); extern int pcx_pixel_plot(struct zint_symbol *symbol, char *pixelbuf); extern int gif_pixel_plot(struct zint_symbol *symbol, char *pixelbuf); +void buffer_plot(struct zint_symbol *symbol, char *pixelbuf) { + /* Place pixelbuffer into symbol */ + int fgred, fggrn, fgblu, bgred, bggrn, bgblu; + int row, column, i; + + symbol->bitmap = (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]); + fgblu = (16 * ctoi(symbol->fgcolour[4])) + ctoi(symbol->fgcolour[5]); + 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; + switch (*(pixelbuf + (symbol->bitmap_width * (symbol->bitmap_height - row - 1)) + column)) { + case '1': + symbol->bitmap[i] = fgred; + symbol->bitmap[i + 1] = fggrn; + symbol->bitmap[i + 2] = fgblu; + break; + default: + symbol->bitmap[i] = bgred; + symbol->bitmap[i + 1] = bggrn; + symbol->bitmap[i + 2] = bgblu; + break; + + } + } + } +} + int save_raster_image_to_file(struct zint_symbol *symbol, int image_height, int image_width, char *pixelbuf, int rotate_angle, int image_type) { int error_number; int row, column; @@ -135,6 +169,10 @@ int save_raster_image_to_file(struct zint_symbol *symbol, int image_height, int } switch (image_type) { + case OUT_BUFFER: + buffer_plot(symbol, rotated_pixbuf); + error_number = 0; + break; case OUT_PNG_FILE: #ifndef NO_PNG error_number = png_pixel_plot(symbol, rotated_pixbuf); diff --git a/backend/zint.h b/backend/zint.h index 3ad4c4d7..7573f48c 100644 --- a/backend/zint.h +++ b/backend/zint.h @@ -229,6 +229,7 @@ extern "C" { #define ZINT_ERROR_MEMORY 11 // Raster file types +#define OUT_BUFFER 0 #define OUT_PNG_FILE 100 #define OUT_BMP_FILE 120 #define OUT_GIF_FILE 140