mirror of
https://github.com/zint/zint
synced 2024-11-16 20:57:25 +13:00
Consolidate raster image rotation and colour sanity checks
This commit is contained in:
parent
71a30a9031
commit
e0402ba434
134
backend/bmp.c
134
backend/bmp.c
@ -43,8 +43,8 @@
|
|||||||
|
|
||||||
#define SSET "0123456789ABCDEF"
|
#define SSET "0123456789ABCDEF"
|
||||||
|
|
||||||
int bmp_pixel_plot(struct zint_symbol *symbol, int image_height, int image_width, char *pixelbuf, int rotate_angle) {
|
int bmp_pixel_plot(struct zint_symbol *symbol, char *pixelbuf) {
|
||||||
int i, row, column, errno;
|
int i, row, column;
|
||||||
int fgred, fggrn, fgblu, bgred, bggrn, bgblu;
|
int fgred, fggrn, fgblu, bgred, bggrn, bgblu;
|
||||||
int row_size;
|
int row_size;
|
||||||
unsigned int data_size;
|
unsigned int data_size;
|
||||||
@ -53,48 +53,12 @@ int bmp_pixel_plot(struct zint_symbol *symbol, int image_height, int image_width
|
|||||||
bitmap_file_header_t file_header;
|
bitmap_file_header_t file_header;
|
||||||
bitmap_info_header_t info_header;
|
bitmap_info_header_t info_header;
|
||||||
|
|
||||||
switch (rotate_angle) {
|
|
||||||
case 0:
|
|
||||||
case 180:
|
|
||||||
symbol->bitmap_width = image_width;
|
|
||||||
symbol->bitmap_height = image_height;
|
|
||||||
break;
|
|
||||||
case 90:
|
|
||||||
case 270:
|
|
||||||
symbol->bitmap_width = image_height;
|
|
||||||
symbol->bitmap_height = image_width;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (symbol->bitmap != NULL)
|
if (symbol->bitmap != NULL)
|
||||||
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);
|
symbol->bitmap = (char *) malloc(row_size * symbol->bitmap_height);
|
||||||
|
|
||||||
/* sort out colour options */
|
|
||||||
to_upper((unsigned char*) symbol->fgcolour);
|
|
||||||
to_upper((unsigned char*) symbol->bgcolour);
|
|
||||||
|
|
||||||
if (strlen(symbol->fgcolour) != 6) {
|
|
||||||
strcpy(symbol->errtxt, "Malformed foreground colour target");
|
|
||||||
return ZINT_ERROR_INVALID_OPTION;
|
|
||||||
}
|
|
||||||
if (strlen(symbol->bgcolour) != 6) {
|
|
||||||
strcpy(symbol->errtxt, "Malformed background colour target");
|
|
||||||
return ZINT_ERROR_INVALID_OPTION;
|
|
||||||
}
|
|
||||||
errno = is_sane(SSET, (unsigned char*) symbol->fgcolour, strlen(symbol->fgcolour));
|
|
||||||
if (errno == ZINT_ERROR_INVALID_DATA) {
|
|
||||||
strcpy(symbol->errtxt, "Malformed foreground colour target");
|
|
||||||
return ZINT_ERROR_INVALID_OPTION;
|
|
||||||
}
|
|
||||||
errno = is_sane(SSET, (unsigned char*) symbol->bgcolour, strlen(symbol->fgcolour));
|
|
||||||
if (errno == ZINT_ERROR_INVALID_DATA) {
|
|
||||||
strcpy(symbol->errtxt, "Malformed background colour target");
|
|
||||||
return ZINT_ERROR_INVALID_OPTION;
|
|
||||||
}
|
|
||||||
|
|
||||||
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]);
|
||||||
fgblu = (16 * ctoi(symbol->fgcolour[4])) + ctoi(symbol->fgcolour[5]);
|
fgblu = (16 * ctoi(symbol->fgcolour[4])) + ctoi(symbol->fgcolour[5]);
|
||||||
@ -104,87 +68,23 @@ int bmp_pixel_plot(struct zint_symbol *symbol, int image_height, int image_width
|
|||||||
|
|
||||||
/* Pixel Plotting */
|
/* Pixel Plotting */
|
||||||
i = 0;
|
i = 0;
|
||||||
switch (rotate_angle) {
|
for (row = 0; row < symbol->bitmap_height; row++) {
|
||||||
case 0: /* Plot the right way up */
|
for (column = 0; column < symbol->bitmap_width; column++) {
|
||||||
for (row = 0; row < image_height; row++) {
|
i = (3 * column) + (row * row_size);
|
||||||
for (column = 0; column < image_width; column++) {
|
switch (*(pixelbuf + (symbol->bitmap_width * (symbol->bitmap_height - row - 1)) + column)) {
|
||||||
i = (3 * column) + (row * row_size);
|
case '1':
|
||||||
switch (*(pixelbuf + (image_width * (image_height - row - 1)) + column)) {
|
symbol->bitmap[i] = fgblu;
|
||||||
case '1':
|
symbol->bitmap[i + 1] = fggrn;
|
||||||
symbol->bitmap[i] = fgblu;
|
symbol->bitmap[i + 2] = fgred;
|
||||||
symbol->bitmap[i + 1] = fggrn;
|
break;
|
||||||
symbol->bitmap[i + 2] = fgred;
|
default:
|
||||||
break;
|
symbol->bitmap[i] = bgblu;
|
||||||
default:
|
symbol->bitmap[i + 1] = bggrn;
|
||||||
symbol->bitmap[i] = bgblu;
|
symbol->bitmap[i + 2] = bgred;
|
||||||
symbol->bitmap[i + 1] = bggrn;
|
break;
|
||||||
symbol->bitmap[i + 2] = bgred;
|
|
||||||
break;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
}
|
||||||
case 90: /* Plot 90 degrees clockwise */
|
|
||||||
for (row = 0; row < image_width; row++) {
|
|
||||||
for (column = 0; column < image_height; column++) {
|
|
||||||
i = (3 * column) + (row * row_size);
|
|
||||||
switch (*(pixelbuf + (image_width * (image_height - column - 1)) + (image_width - row - 1))) {
|
|
||||||
case '1':
|
|
||||||
symbol->bitmap[i] = fgblu;
|
|
||||||
symbol->bitmap[i + 1] = fggrn;
|
|
||||||
symbol->bitmap[i + 2] = fgred;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
symbol->bitmap[i] = bgblu;
|
|
||||||
symbol->bitmap[i + 1] = bggrn;
|
|
||||||
symbol->bitmap[i + 2] = bgred;
|
|
||||||
break;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 180: /* Plot upside down */
|
|
||||||
for (row = 0; row < image_height; row++) {
|
|
||||||
for (column = 0; column < image_width; column++) {
|
|
||||||
i = (3 * column) + (row * row_size);
|
|
||||||
switch (*(pixelbuf + (image_width * row) + (image_width - column - 1))) {
|
|
||||||
case '1':
|
|
||||||
symbol->bitmap[i] = fgblu;
|
|
||||||
symbol->bitmap[i + 1] = fggrn;
|
|
||||||
symbol->bitmap[i + 2] = fgred;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
symbol->bitmap[i] = bgblu;
|
|
||||||
symbol->bitmap[i + 1] = bggrn;
|
|
||||||
symbol->bitmap[i + 2] = bgred;
|
|
||||||
break;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 270: /* Plot 90 degrees anti-clockwise */
|
|
||||||
for (row = 0; row < image_width; row++) {
|
|
||||||
for (column = 0; column < image_height; column++) {
|
|
||||||
i = (3 * column) + (row * row_size);
|
|
||||||
switch (*(pixelbuf + (image_width * column) + row)) {
|
|
||||||
case '1':
|
|
||||||
symbol->bitmap[i] = fgblu;
|
|
||||||
symbol->bitmap[i + 1] = fggrn;
|
|
||||||
symbol->bitmap[i + 2] = fgred;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
symbol->bitmap[i] = bgblu;
|
|
||||||
symbol->bitmap[i + 1] = bggrn;
|
|
||||||
symbol->bitmap[i + 2] = bgred;
|
|
||||||
break;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
data_size = symbol->bitmap_height * row_size;
|
data_size = symbol->bitmap_height * row_size;
|
||||||
|
105
backend/gif.c
105
backend/gif.c
@ -260,104 +260,21 @@ int gif_lzw(unsigned char *pOut, int OutLength, unsigned char *pIn, int InLen) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int gif_pixel_plot(struct zint_symbol *symbol, int image_height, int image_width, char *pixelbuf, int rotate_angle) {
|
int gif_pixel_plot(struct zint_symbol *symbol, char *pixelbuf) {
|
||||||
char outbuf[10];
|
char outbuf[10];
|
||||||
int errno;
|
|
||||||
int row, column;
|
|
||||||
FILE *gif_file;
|
FILE *gif_file;
|
||||||
unsigned short ImageWidth = image_width;
|
|
||||||
unsigned short ImageHeight = image_height;
|
|
||||||
unsigned short usTemp;
|
unsigned short usTemp;
|
||||||
int byte_out;
|
int byte_out;
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
char* rotated_bitmap;
|
|
||||||
char * lzwoutbuf;
|
char * lzwoutbuf;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef _MSC_VER
|
#ifndef _MSC_VER
|
||||||
char rotated_bitmap[image_height * image_width];
|
char lzwoutbuf[symbol->bitmap_height * symbol->bitmap_width];
|
||||||
char lzwoutbuf[image_height * image_width];
|
|
||||||
#else
|
#else
|
||||||
rotated_bitmap = (char *) _alloca((image_height * image_width) * sizeof (char));
|
|
||||||
lzwoutbuf = (char *) _alloca((image_height * image_width) * sizeof (char));
|
lzwoutbuf = (char *) _alloca((image_height * image_width) * sizeof (char));
|
||||||
#endif /* _MSC_VER */
|
#endif /* _MSC_VER */
|
||||||
|
|
||||||
switch (rotate_angle) {
|
|
||||||
case 0:
|
|
||||||
case 180:
|
|
||||||
symbol->bitmap_width = image_width;
|
|
||||||
symbol->bitmap_height = image_height;
|
|
||||||
break;
|
|
||||||
case 90:
|
|
||||||
case 270:
|
|
||||||
ImageWidth = image_height;
|
|
||||||
ImageHeight = image_width;
|
|
||||||
symbol->bitmap_width = image_height;
|
|
||||||
symbol->bitmap_height = image_width;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* sort out colour options */
|
|
||||||
to_upper((unsigned char*) symbol->fgcolour);
|
|
||||||
to_upper((unsigned char*) symbol->bgcolour);
|
|
||||||
|
|
||||||
if (strlen(symbol->fgcolour) != 6) {
|
|
||||||
strcpy(symbol->errtxt, "Malformed foreground colour target");
|
|
||||||
return ZINT_ERROR_INVALID_OPTION;
|
|
||||||
}
|
|
||||||
if (strlen(symbol->bgcolour) != 6) {
|
|
||||||
strcpy(symbol->errtxt, "Malformed background colour target");
|
|
||||||
return ZINT_ERROR_INVALID_OPTION;
|
|
||||||
}
|
|
||||||
errno = is_sane(SSET, (unsigned char*) symbol->fgcolour, strlen(symbol->fgcolour));
|
|
||||||
if (errno == ZINT_ERROR_INVALID_DATA) {
|
|
||||||
strcpy(symbol->errtxt, "Malformed foreground colour target");
|
|
||||||
return ZINT_ERROR_INVALID_OPTION;
|
|
||||||
}
|
|
||||||
errno = is_sane(SSET, (unsigned char*) symbol->bgcolour, strlen(symbol->fgcolour));
|
|
||||||
if (errno == ZINT_ERROR_INVALID_DATA) {
|
|
||||||
strcpy(symbol->errtxt, "Malformed background colour target");
|
|
||||||
return ZINT_ERROR_INVALID_OPTION;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Rotate image before plotting */
|
|
||||||
switch (rotate_angle) {
|
|
||||||
case 0: /* Plot the right way up */
|
|
||||||
for (row = 0; row < image_height; row++) {
|
|
||||||
for (column = 0; column < image_width; column++) {
|
|
||||||
rotated_bitmap[(row * image_width) + column] =
|
|
||||||
*(pixelbuf + (image_width * row) + column);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 90: /* Plot 90 degrees clockwise */
|
|
||||||
for (row = 0; row < image_width; row++) {
|
|
||||||
for (column = 0; column < image_height; column++) {
|
|
||||||
rotated_bitmap[(row * image_height) + column] =
|
|
||||||
*(pixelbuf + (image_width * (image_height - column - 1)) + row);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 180: /* Plot upside down */
|
|
||||||
for (row = 0; row < image_height; row++) {
|
|
||||||
for (column = 0; column < image_width; column++) {
|
|
||||||
rotated_bitmap[(row * image_width) + column] =
|
|
||||||
*(pixelbuf + (image_width * (image_height - row - 1)) + (image_width - column - 1));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 270: /* Plot 90 degrees anti-clockwise */
|
|
||||||
for (row = 0; row < image_width; row++) {
|
|
||||||
for (column = 0; column < image_height; column++) {
|
|
||||||
rotated_bitmap[(row * image_height) + column] =
|
|
||||||
*(pixelbuf + (image_width * column) + (image_width - row - 1));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* 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) {
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
@ -388,11 +305,11 @@ int gif_pixel_plot(struct zint_symbol *symbol, int image_height, int image_width
|
|||||||
fwrite(outbuf, 6, 1, gif_file);
|
fwrite(outbuf, 6, 1, gif_file);
|
||||||
/* Screen Descriptor (7) */
|
/* Screen Descriptor (7) */
|
||||||
/* Screen Width */
|
/* Screen Width */
|
||||||
usTemp = (unsigned short) ImageWidth;
|
usTemp = (unsigned short) symbol->bitmap_width;
|
||||||
outbuf[0] = (unsigned char) (0xff & usTemp);
|
outbuf[0] = (unsigned char) (0xff & usTemp);
|
||||||
outbuf[1] = (unsigned char) ((0xff00 & usTemp) / 0x100);
|
outbuf[1] = (unsigned char) ((0xff00 & usTemp) / 0x100);
|
||||||
/* Screen Height */
|
/* Screen Height */
|
||||||
usTemp = (unsigned short) ImageHeight;
|
usTemp = (unsigned short) symbol->bitmap_height;
|
||||||
outbuf[2] = (unsigned char) (0xff & usTemp);
|
outbuf[2] = (unsigned char) (0xff & usTemp);
|
||||||
outbuf[3] = (unsigned char) ((0xff00 & usTemp) / 0x100);
|
outbuf[3] = (unsigned char) ((0xff00 & usTemp) / 0x100);
|
||||||
/* write ImageBits-1 to the three least significant bits of byte 5 of
|
/* write ImageBits-1 to the three least significant bits of byte 5 of
|
||||||
@ -452,11 +369,11 @@ int gif_pixel_plot(struct zint_symbol *symbol, int image_height, int image_width
|
|||||||
outbuf[3] = 0x00;
|
outbuf[3] = 0x00;
|
||||||
outbuf[4] = 0x00;
|
outbuf[4] = 0x00;
|
||||||
/* Image Width (low byte first) */
|
/* Image Width (low byte first) */
|
||||||
outbuf[5] = (unsigned char) (0xff & ImageWidth);
|
outbuf[5] = (unsigned char) (0xff & symbol->bitmap_width);
|
||||||
outbuf[6] = (unsigned char) ((0xff00 & ImageWidth) / 0x100);
|
outbuf[6] = (unsigned char) ((0xff00 & symbol->bitmap_width) / 0x100);
|
||||||
/* Image Height */
|
/* Image Height */
|
||||||
outbuf[7] = (unsigned char) (0xff & ImageHeight);
|
outbuf[7] = (unsigned char) (0xff & symbol->bitmap_height);
|
||||||
outbuf[8] = (unsigned char) ((0xff00 & ImageHeight) / 0x100);
|
outbuf[8] = (unsigned char) ((0xff00 & symbol->bitmap_height) / 0x100);
|
||||||
|
|
||||||
/* Byte 10 contains the interlaced flag and
|
/* Byte 10 contains the interlaced flag and
|
||||||
* information on the local color table.
|
* information on the local color table.
|
||||||
@ -468,9 +385,9 @@ int gif_pixel_plot(struct zint_symbol *symbol, int image_height, int image_width
|
|||||||
/* call lzw encoding */
|
/* call lzw encoding */
|
||||||
byte_out = gif_lzw(
|
byte_out = gif_lzw(
|
||||||
(unsigned char *) lzwoutbuf,
|
(unsigned char *) lzwoutbuf,
|
||||||
image_height * image_width,
|
symbol->bitmap_height * symbol->bitmap_width,
|
||||||
(unsigned char *) rotated_bitmap,
|
(unsigned char *) pixelbuf,
|
||||||
image_height * image_width);
|
symbol->bitmap_height * symbol->bitmap_width);
|
||||||
if (byte_out <= 0) {
|
if (byte_out <= 0) {
|
||||||
fclose(gif_file);
|
fclose(gif_file);
|
||||||
return ZINT_ERROR_MEMORY;
|
return ZINT_ERROR_MEMORY;
|
||||||
|
@ -44,66 +44,22 @@
|
|||||||
|
|
||||||
#define SSET "0123456789ABCDEF"
|
#define SSET "0123456789ABCDEF"
|
||||||
|
|
||||||
int pcx_pixel_plot(struct zint_symbol *symbol, int image_height, int image_width, char *pixelbuf, int rotate_angle) {
|
int pcx_pixel_plot(struct zint_symbol *symbol, char *pixelbuf) {
|
||||||
int fgred, fggrn, fgblu, bgred, bggrn, bgblu;
|
int fgred, fggrn, fgblu, bgred, bggrn, bgblu;
|
||||||
int errno;
|
|
||||||
int row, column, i, colour;
|
int row, column, i, colour;
|
||||||
int run_count;
|
int run_count;
|
||||||
FILE *pcx_file;
|
FILE *pcx_file;
|
||||||
pcx_header_t header;
|
pcx_header_t header;
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
char* rotated_bitmap;
|
|
||||||
unsigned char* rle_row;
|
unsigned char* rle_row;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef _MSC_VER
|
|
||||||
char rotated_bitmap[image_height * image_width];
|
|
||||||
#else
|
|
||||||
rotated_bitmap = (char *) _alloca((image_height * image_width) * sizeof (char));
|
|
||||||
#endif /* _MSC_VER */
|
|
||||||
|
|
||||||
switch (rotate_angle) {
|
|
||||||
case 0:
|
|
||||||
case 180:
|
|
||||||
symbol->bitmap_width = image_width;
|
|
||||||
symbol->bitmap_height = image_height;
|
|
||||||
break;
|
|
||||||
case 90:
|
|
||||||
case 270:
|
|
||||||
symbol->bitmap_width = image_height;
|
|
||||||
symbol->bitmap_height = image_width;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifndef _MSC_VER
|
#ifndef _MSC_VER
|
||||||
unsigned char rle_row[symbol->bitmap_width];
|
unsigned char rle_row[symbol->bitmap_width];
|
||||||
#else
|
#else
|
||||||
rle_row = (unsigned char *) _alloca((symbol->bitmap_width * 6) * sizeof (unsigned char));
|
rle_row = (unsigned char *) _alloca((symbol->bitmap_width * 6) * sizeof (unsigned char));
|
||||||
#endif /* _MSC_VER */
|
#endif /* _MSC_VER */
|
||||||
|
|
||||||
/* sort out colour options */
|
|
||||||
to_upper((unsigned char*) symbol->fgcolour);
|
|
||||||
to_upper((unsigned char*) symbol->bgcolour);
|
|
||||||
|
|
||||||
if (strlen(symbol->fgcolour) != 6) {
|
|
||||||
strcpy(symbol->errtxt, "Malformed foreground colour target");
|
|
||||||
return ZINT_ERROR_INVALID_OPTION;
|
|
||||||
}
|
|
||||||
if (strlen(symbol->bgcolour) != 6) {
|
|
||||||
strcpy(symbol->errtxt, "Malformed background colour target");
|
|
||||||
return ZINT_ERROR_INVALID_OPTION;
|
|
||||||
}
|
|
||||||
errno = is_sane(SSET, (unsigned char*) symbol->fgcolour, strlen(symbol->fgcolour));
|
|
||||||
if (errno == ZINT_ERROR_INVALID_DATA) {
|
|
||||||
strcpy(symbol->errtxt, "Malformed foreground colour target");
|
|
||||||
return ZINT_ERROR_INVALID_OPTION;
|
|
||||||
}
|
|
||||||
errno = is_sane(SSET, (unsigned char*) symbol->bgcolour, strlen(symbol->fgcolour));
|
|
||||||
if (errno == ZINT_ERROR_INVALID_DATA) {
|
|
||||||
strcpy(symbol->errtxt, "Malformed background colour target");
|
|
||||||
return ZINT_ERROR_INVALID_OPTION;
|
|
||||||
}
|
|
||||||
|
|
||||||
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]);
|
||||||
fgblu = (16 * ctoi(symbol->fgcolour[4])) + ctoi(symbol->fgcolour[5]);
|
fgblu = (16 * ctoi(symbol->fgcolour[4])) + ctoi(symbol->fgcolour[5]);
|
||||||
@ -111,42 +67,6 @@ int pcx_pixel_plot(struct zint_symbol *symbol, int image_height, int image_width
|
|||||||
bggrn = (16 * ctoi(symbol->bgcolour[2])) + ctoi(symbol->bgcolour[3]);
|
bggrn = (16 * ctoi(symbol->bgcolour[2])) + ctoi(symbol->bgcolour[3]);
|
||||||
bgblu = (16 * ctoi(symbol->bgcolour[4])) + ctoi(symbol->bgcolour[5]);
|
bgblu = (16 * ctoi(symbol->bgcolour[4])) + ctoi(symbol->bgcolour[5]);
|
||||||
|
|
||||||
/* Rotate image before plotting */
|
|
||||||
switch (rotate_angle) {
|
|
||||||
case 0: /* Plot the right way up */
|
|
||||||
for (row = 0; row < image_height; row++) {
|
|
||||||
for (column = 0; column < image_width; column++) {
|
|
||||||
rotated_bitmap[(row * image_width) + column] =
|
|
||||||
*(pixelbuf + (image_width * row) + column);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 90: /* Plot 90 degrees clockwise */
|
|
||||||
for (row = 0; row < image_width; row++) {
|
|
||||||
for (column = 0; column < image_height; column++) {
|
|
||||||
rotated_bitmap[(row * image_height) + column] =
|
|
||||||
*(pixelbuf + (image_width * (image_height - column - 1)) + row);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 180: /* Plot upside down */
|
|
||||||
for (row = 0; row < image_height; row++) {
|
|
||||||
for (column = 0; column < image_width; column++) {
|
|
||||||
rotated_bitmap[(row * image_width) + column] =
|
|
||||||
*(pixelbuf + (image_width * (image_height - row - 1)) + (image_width - column - 1));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 270: /* Plot 90 degrees anti-clockwise */
|
|
||||||
for (row = 0; row < image_width; row++) {
|
|
||||||
for (column = 0; column < image_height; column++) {
|
|
||||||
rotated_bitmap[(row * image_height) + column] =
|
|
||||||
*(pixelbuf + (image_width * column) + (image_width - row - 1));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
header.manufacturer = 10; // ZSoft
|
header.manufacturer = 10; // ZSoft
|
||||||
header.version = 5; // Version 3.0
|
header.version = 5; // Version 3.0
|
||||||
@ -203,21 +123,21 @@ int pcx_pixel_plot(struct zint_symbol *symbol, int image_height, int image_width
|
|||||||
for (column = 0; column < symbol->bitmap_width; column++) {
|
for (column = 0; column < symbol->bitmap_width; column++) {
|
||||||
switch (colour) {
|
switch (colour) {
|
||||||
case 0:
|
case 0:
|
||||||
if (rotated_bitmap[(row * symbol->bitmap_width) + column] == '1') {
|
if (pixelbuf[(row * symbol->bitmap_width) + column] == '1') {
|
||||||
rle_row[column] = fgred;
|
rle_row[column] = fgred;
|
||||||
} else {
|
} else {
|
||||||
rle_row[column] = bgred;
|
rle_row[column] = bgred;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
if (rotated_bitmap[(row * symbol->bitmap_width) + column] == '1') {
|
if (pixelbuf[(row * symbol->bitmap_width) + column] == '1') {
|
||||||
rle_row[column] = fggrn;
|
rle_row[column] = fggrn;
|
||||||
} else {
|
} else {
|
||||||
rle_row[column] = bggrn;
|
rle_row[column] = bggrn;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
if (rotated_bitmap[(row * symbol->bitmap_width) + column] == '1') {
|
if (pixelbuf[(row * symbol->bitmap_width) + column] == '1') {
|
||||||
rle_row[column] = fgblu;
|
rle_row[column] = fgblu;
|
||||||
} else {
|
} else {
|
||||||
rle_row[column] = bgblu;
|
rle_row[column] = bgblu;
|
||||||
|
160
backend/png.c
160
backend/png.c
@ -70,58 +70,25 @@ static void writepng_error_handler(png_structp png_ptr, png_const_charp msg) {
|
|||||||
longjmp(graphic->jmpbuf, 1);
|
longjmp(graphic->jmpbuf, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int png_pixel_plot(struct zint_symbol *symbol, int image_height, int image_width, char *pixelbuf, int rotate_angle) {
|
int png_pixel_plot(struct zint_symbol *symbol, char *pixelbuf) {
|
||||||
struct mainprog_info_type wpng_info;
|
struct mainprog_info_type wpng_info;
|
||||||
struct mainprog_info_type *graphic;
|
struct mainprog_info_type *graphic;
|
||||||
png_structp png_ptr;
|
png_structp png_ptr;
|
||||||
png_infop info_ptr;
|
png_infop info_ptr;
|
||||||
unsigned char *image_data;
|
unsigned char *image_data;
|
||||||
int i, row, column, errno;
|
int i, row, column;
|
||||||
int fgred, fggrn, fgblu, bgred, bggrn, bgblu;
|
int fgred, fggrn, fgblu, bgred, bggrn, bgblu;
|
||||||
|
|
||||||
#ifndef _MSC_VER
|
#ifndef _MSC_VER
|
||||||
unsigned char outdata[image_width * 3];
|
unsigned char outdata[symbol->bitmap_width * 3];
|
||||||
#else
|
#else
|
||||||
unsigned char* outdata = (unsigned char*) _alloca(image_width * 3);
|
unsigned char* outdata = (unsigned char*) _alloca(symbol->bitmap_width * 3);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
graphic = &wpng_info;
|
graphic = &wpng_info;
|
||||||
|
|
||||||
switch (rotate_angle) {
|
graphic->width = symbol->bitmap_width;
|
||||||
case 0:
|
graphic->height = symbol->bitmap_height;
|
||||||
case 180:
|
|
||||||
graphic->width = image_width;
|
|
||||||
graphic->height = image_height;
|
|
||||||
break;
|
|
||||||
case 90:
|
|
||||||
case 270:
|
|
||||||
graphic->width = image_height;
|
|
||||||
graphic->height = image_width;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* sort out colour options */
|
|
||||||
to_upper((unsigned char*) symbol->fgcolour);
|
|
||||||
to_upper((unsigned char*) symbol->bgcolour);
|
|
||||||
|
|
||||||
if (strlen(symbol->fgcolour) != 6) {
|
|
||||||
strcpy(symbol->errtxt, "Malformed foreground colour target");
|
|
||||||
return ZINT_ERROR_INVALID_OPTION;
|
|
||||||
}
|
|
||||||
if (strlen(symbol->bgcolour) != 6) {
|
|
||||||
strcpy(symbol->errtxt, "Malformed background colour target");
|
|
||||||
return ZINT_ERROR_INVALID_OPTION;
|
|
||||||
}
|
|
||||||
errno = is_sane(SSET, (unsigned char*) symbol->fgcolour, strlen(symbol->fgcolour));
|
|
||||||
if (errno == ZINT_ERROR_INVALID_DATA) {
|
|
||||||
strcpy(symbol->errtxt, "Malformed foreground colour target");
|
|
||||||
return ZINT_ERROR_INVALID_OPTION;
|
|
||||||
}
|
|
||||||
errno = is_sane(SSET, (unsigned char*) symbol->bgcolour, strlen(symbol->bgcolour));
|
|
||||||
if (errno == ZINT_ERROR_INVALID_DATA) {
|
|
||||||
strcpy(symbol->errtxt, "Malformed background colour target");
|
|
||||||
return ZINT_ERROR_INVALID_OPTION;
|
|
||||||
}
|
|
||||||
|
|
||||||
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]);
|
||||||
@ -186,103 +153,26 @@ int png_pixel_plot(struct zint_symbol *symbol, int image_height, int image_width
|
|||||||
png_set_packing(png_ptr);
|
png_set_packing(png_ptr);
|
||||||
|
|
||||||
/* Pixel Plotting */
|
/* Pixel Plotting */
|
||||||
|
for (row = 0; row < symbol->bitmap_height; row++) {
|
||||||
|
for (column = 0; column < symbol->bitmap_width; column++) {
|
||||||
|
i = column * 3;
|
||||||
|
switch (*(pixelbuf + (symbol->bitmap_width * row) + column)) {
|
||||||
|
case '1':
|
||||||
|
outdata[i] = fgred;
|
||||||
|
outdata[i + 1] = fggrn;
|
||||||
|
outdata[i + 2] = fgblu;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
outdata[i] = bgred;
|
||||||
|
outdata[i + 1] = bggrn;
|
||||||
|
outdata[i + 2] = bgblu;
|
||||||
|
break;
|
||||||
|
|
||||||
switch (rotate_angle) {
|
|
||||||
case 0: /* Plot the right way up */
|
|
||||||
for (row = 0; row < image_height; row++) {
|
|
||||||
for (column = 0; column < image_width; column++) {
|
|
||||||
i = column * 3;
|
|
||||||
switch (*(pixelbuf + (image_width * row) + column)) {
|
|
||||||
case '1':
|
|
||||||
outdata[i] = fgred;
|
|
||||||
outdata[i + 1] = fggrn;
|
|
||||||
outdata[i + 2] = fgblu;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
outdata[i] = bgred;
|
|
||||||
outdata[i + 1] = bggrn;
|
|
||||||
outdata[i + 2] = bgblu;
|
|
||||||
break;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/* write row contents to file */
|
|
||||||
image_data = outdata;
|
|
||||||
png_write_row(png_ptr, image_data);
|
|
||||||
}
|
}
|
||||||
break;
|
}
|
||||||
case 90: /* Plot 90 degrees clockwise */
|
/* write row contents to file */
|
||||||
for (row = 0; row < image_width; row++) {
|
image_data = outdata;
|
||||||
for (column = 0; column < image_height; column++) {
|
png_write_row(png_ptr, image_data);
|
||||||
i = column * 3;
|
|
||||||
switch (*(pixelbuf + (image_width * (image_height - column - 1)) + row)) {
|
|
||||||
case '1':
|
|
||||||
outdata[i] = fgred;
|
|
||||||
outdata[i + 1] = fggrn;
|
|
||||||
outdata[i + 2] = fgblu;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
outdata[i] = bgred;
|
|
||||||
outdata[i + 1] = bggrn;
|
|
||||||
outdata[i + 2] = bgblu;
|
|
||||||
break;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* write row contents to file */
|
|
||||||
image_data = outdata;
|
|
||||||
png_write_row(png_ptr, image_data);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 180: /* Plot upside down */
|
|
||||||
for (row = 0; row < image_height; row++) {
|
|
||||||
for (column = 0; column < image_width; column++) {
|
|
||||||
i = column * 3;
|
|
||||||
switch (*(pixelbuf + (image_width * (image_height - row - 1)) + (image_width - column - 1))) {
|
|
||||||
case '1':
|
|
||||||
outdata[i] = fgred;
|
|
||||||
outdata[i + 1] = fggrn;
|
|
||||||
outdata[i + 2] = fgblu;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
outdata[i] = bgred;
|
|
||||||
outdata[i + 1] = bggrn;
|
|
||||||
outdata[i + 2] = bgblu;
|
|
||||||
break;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* write row contents to file */
|
|
||||||
image_data = outdata;
|
|
||||||
png_write_row(png_ptr, image_data);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 270: /* Plot 90 degrees anti-clockwise */
|
|
||||||
for (row = 0; row < image_width; row++) {
|
|
||||||
for (column = 0; column < image_height; column++) {
|
|
||||||
i = column * 3;
|
|
||||||
switch (*(pixelbuf + (image_width * column) + (image_width - row - 1))) {
|
|
||||||
case '1':
|
|
||||||
outdata[i] = fgred;
|
|
||||||
outdata[i + 1] = fggrn;
|
|
||||||
outdata[i + 2] = fgblu;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
outdata[i] = bgred;
|
|
||||||
outdata[i + 1] = bggrn;
|
|
||||||
outdata[i + 2] = bgblu;
|
|
||||||
break;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* write row contents to file */
|
|
||||||
image_data = outdata;
|
|
||||||
png_write_row(png_ptr, image_data);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* End the file */
|
/* End the file */
|
||||||
|
@ -47,31 +47,109 @@
|
|||||||
#include "font.h" /* Font for human readable text */
|
#include "font.h" /* Font for human readable text */
|
||||||
|
|
||||||
#ifndef NO_PNG
|
#ifndef NO_PNG
|
||||||
extern int png_pixel_plot(struct zint_symbol *symbol, int image_height, int image_width, char *pixelbuf, int rotate_angle);
|
extern int png_pixel_plot(struct zint_symbol *symbol, char *pixelbuf);
|
||||||
#endif /* NO_PNG */
|
#endif /* NO_PNG */
|
||||||
extern int bmp_pixel_plot(struct zint_symbol *symbol, int image_height, int image_width, char *pixelbuf, int rotate_angle);
|
extern int bmp_pixel_plot(struct zint_symbol *symbol, char *pixelbuf);
|
||||||
extern int pcx_pixel_plot(struct zint_symbol *symbol, int image_height, int image_width, char *pixelbuf, int rotate_angle);
|
extern int pcx_pixel_plot(struct zint_symbol *symbol, char *pixelbuf);
|
||||||
extern int gif_pixel_plot(struct zint_symbol *symbol, int image_height, int image_width, char *pixelbuf, int rotate_angle);
|
extern int gif_pixel_plot(struct zint_symbol *symbol, char *pixelbuf);
|
||||||
|
|
||||||
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;
|
||||||
|
#ifndef _MSC_VER
|
||||||
|
char rotated_pixbuf[image_height * image_width];
|
||||||
|
#else
|
||||||
|
char* rrotated_pixbuf = (char *) _alloca((image_height * image_width) * sizeof (char));
|
||||||
|
#endif /* _MSC_VER */
|
||||||
|
|
||||||
|
switch (rotate_angle) {
|
||||||
|
case 0:
|
||||||
|
case 180:
|
||||||
|
symbol->bitmap_width = image_width;
|
||||||
|
symbol->bitmap_height = image_height;
|
||||||
|
break;
|
||||||
|
case 90:
|
||||||
|
case 270:
|
||||||
|
symbol->bitmap_width = image_height;
|
||||||
|
symbol->bitmap_height = image_width;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* sort out colour options */
|
||||||
|
to_upper((unsigned char*) symbol->fgcolour);
|
||||||
|
to_upper((unsigned char*) symbol->bgcolour);
|
||||||
|
|
||||||
|
if (strlen(symbol->fgcolour) != 6) {
|
||||||
|
strcpy(symbol->errtxt, "Malformed foreground colour target");
|
||||||
|
return ZINT_ERROR_INVALID_OPTION;
|
||||||
|
}
|
||||||
|
if (strlen(symbol->bgcolour) != 6) {
|
||||||
|
strcpy(symbol->errtxt, "Malformed background colour target");
|
||||||
|
return ZINT_ERROR_INVALID_OPTION;
|
||||||
|
}
|
||||||
|
error_number = is_sane(SSET, (unsigned char*) symbol->fgcolour, strlen(symbol->fgcolour));
|
||||||
|
if (error_number == ZINT_ERROR_INVALID_DATA) {
|
||||||
|
strcpy(symbol->errtxt, "Malformed foreground colour target");
|
||||||
|
return ZINT_ERROR_INVALID_OPTION;
|
||||||
|
}
|
||||||
|
error_number = is_sane(SSET, (unsigned char*) symbol->bgcolour, strlen(symbol->fgcolour));
|
||||||
|
if (error_number == ZINT_ERROR_INVALID_DATA) {
|
||||||
|
strcpy(symbol->errtxt, "Malformed background colour target");
|
||||||
|
return ZINT_ERROR_INVALID_OPTION;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Rotate image before plotting */
|
||||||
|
switch (rotate_angle) {
|
||||||
|
case 0: /* Plot the right way up */
|
||||||
|
for (row = 0; row < image_height; row++) {
|
||||||
|
for (column = 0; column < image_width; column++) {
|
||||||
|
rotated_pixbuf[(row * image_width) + column] =
|
||||||
|
*(pixelbuf + (image_width * row) + column);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 90: /* Plot 90 degrees clockwise */
|
||||||
|
for (row = 0; row < image_width; row++) {
|
||||||
|
for (column = 0; column < image_height; column++) {
|
||||||
|
rotated_pixbuf[(row * image_height) + column] =
|
||||||
|
*(pixelbuf + (image_width * (image_height - column - 1)) + row);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 180: /* Plot upside down */
|
||||||
|
for (row = 0; row < image_height; row++) {
|
||||||
|
for (column = 0; column < image_width; column++) {
|
||||||
|
rotated_pixbuf[(row * image_width) + column] =
|
||||||
|
*(pixelbuf + (image_width * (image_height - row - 1)) + (image_width - column - 1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 270: /* Plot 90 degrees anti-clockwise */
|
||||||
|
for (row = 0; row < image_width; row++) {
|
||||||
|
for (column = 0; column < image_height; column++) {
|
||||||
|
rotated_pixbuf[(row * image_height) + column] =
|
||||||
|
*(pixelbuf + (image_width * column) + (image_width - row - 1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
switch (image_type) {
|
switch (image_type) {
|
||||||
case OUT_PNG_FILE:
|
case OUT_PNG_FILE:
|
||||||
#ifndef NO_PNG
|
#ifndef NO_PNG
|
||||||
error_number = png_pixel_plot(symbol, image_height, image_width, pixelbuf, rotate_angle);
|
error_number = png_pixel_plot(symbol, rotated_pixbuf);
|
||||||
#else
|
#else
|
||||||
return ZINT_ERROR_INVALID_OPTION;
|
return ZINT_ERROR_INVALID_OPTION;
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
case OUT_PCX_FILE:
|
case OUT_PCX_FILE:
|
||||||
error_number = pcx_pixel_plot(symbol, image_height, image_width, pixelbuf, rotate_angle);
|
error_number = pcx_pixel_plot(symbol, rotated_pixbuf);
|
||||||
break;
|
break;
|
||||||
case OUT_GIF_FILE:
|
case OUT_GIF_FILE:
|
||||||
error_number = gif_pixel_plot(symbol, image_height, image_width, pixelbuf, rotate_angle);
|
error_number = gif_pixel_plot(symbol, rotated_pixbuf);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
error_number = bmp_pixel_plot(symbol, image_height, image_width, pixelbuf, rotate_angle);
|
error_number = bmp_pixel_plot(symbol, rotated_pixbuf);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user