Revoke changes made to pixel buffering in API

This commit is contained in:
Robin Stuart 2016-10-02 10:45:47 +01:00
parent f8b56002c9
commit f145680739
4 changed files with 50 additions and 9 deletions

View File

@ -49,6 +49,7 @@ int bmp_pixel_plot(struct zint_symbol *symbol, char *pixelbuf) {
int row_size; int row_size;
unsigned int data_size; unsigned int data_size;
unsigned char *bitmap_file_start, *bmp_posn; unsigned char *bitmap_file_start, *bmp_posn;
char *bitmap;
FILE *bmp_file; FILE *bmp_file;
bitmap_file_header_t file_header; bitmap_file_header_t file_header;
bitmap_info_header_t info_header; bitmap_info_header_t info_header;
@ -57,7 +58,7 @@ int bmp_pixel_plot(struct zint_symbol *symbol, char *pixelbuf) {
free(symbol->bitmap); free(symbol->bitmap);
row_size = 4 * floor((24.0 * symbol->bitmap_width + 31) / 32); 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]); fgred = (16 * ctoi(symbol->fgcolour[0])) + ctoi(symbol->fgcolour[1]);
fggrn = (16 * ctoi(symbol->fgcolour[2])) + ctoi(symbol->fgcolour[3]); 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); i = (3 * column) + (row * row_size);
switch (*(pixelbuf + (symbol->bitmap_width * (symbol->bitmap_height - row - 1)) + column)) { switch (*(pixelbuf + (symbol->bitmap_width * (symbol->bitmap_height - row - 1)) + column)) {
case '1': case '1':
symbol->bitmap[i] = fgblu; bitmap[i] = fgblu;
symbol->bitmap[i + 1] = fggrn; bitmap[i + 1] = fggrn;
symbol->bitmap[i + 2] = fgred; bitmap[i + 2] = fgred;
break; break;
default: default:
symbol->bitmap[i] = bgblu; bitmap[i] = bgblu;
symbol->bitmap[i + 1] = bggrn; bitmap[i + 1] = bggrn;
symbol->bitmap[i + 2] = bgred; bitmap[i + 2] = bgred;
break; break;
} }
@ -115,7 +116,7 @@ int bmp_pixel_plot(struct zint_symbol *symbol, char *pixelbuf) {
bmp_posn += sizeof (bitmap_file_header_t); bmp_posn += sizeof (bitmap_file_header_t);
memcpy(bmp_posn, &info_header, sizeof (bitmap_info_header_t)); memcpy(bmp_posn, &info_header, sizeof (bitmap_info_header_t));
bmp_posn += 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 */ /* Open output file in binary mode */
if ((symbol->output_options & BARCODE_STDOUT) != 0) { if ((symbol->output_options & BARCODE_STDOUT) != 0) {
@ -137,5 +138,6 @@ int bmp_pixel_plot(struct zint_symbol *symbol, char *pixelbuf) {
fclose(bmp_file); fclose(bmp_file);
free(bitmap_file_start); free(bitmap_file_start);
free(bitmap);
return 0; return 0;
} }

View File

@ -1177,7 +1177,7 @@ int ZBarcode_Buffer(struct zint_symbol *symbol, int rotate_angle) {
return ZINT_ERROR_INVALID_OPTION; 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); error_tag(symbol->errtxt, error_number);
return error_number; return error_number;
} }

View File

@ -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 pcx_pixel_plot(struct zint_symbol *symbol, char *pixelbuf);
extern int gif_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 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 error_number;
int row, column; int row, column;
@ -135,6 +169,10 @@ int save_raster_image_to_file(struct zint_symbol *symbol, int image_height, int
} }
switch (image_type) { switch (image_type) {
case OUT_BUFFER:
buffer_plot(symbol, rotated_pixbuf);
error_number = 0;
break;
case OUT_PNG_FILE: case OUT_PNG_FILE:
#ifndef NO_PNG #ifndef NO_PNG
error_number = png_pixel_plot(symbol, rotated_pixbuf); error_number = png_pixel_plot(symbol, rotated_pixbuf);

View File

@ -229,6 +229,7 @@ extern "C" {
#define ZINT_ERROR_MEMORY 11 #define ZINT_ERROR_MEMORY 11
// Raster file types // Raster file types
#define OUT_BUFFER 0
#define OUT_PNG_FILE 100 #define OUT_PNG_FILE 100
#define OUT_BMP_FILE 120 #define OUT_BMP_FILE 120
#define OUT_GIF_FILE 140 #define OUT_GIF_FILE 140