diff --git a/backend/bmp.c b/backend/bmp.c index 72803ec4..aad8407a 100644 --- a/backend/bmp.c +++ b/backend/bmp.c @@ -43,8 +43,8 @@ #define SSET "0123456789ABCDEF" -int bmp_pixel_plot(struct zint_symbol *symbol, int image_height, int image_width, char *pixelbuf, int rotate_angle) { - int i, row, column, errno; +int bmp_pixel_plot(struct zint_symbol *symbol, char *pixelbuf) { + int i, row, column; int fgred, fggrn, fgblu, bgred, bggrn, bgblu; int row_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_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) free(symbol->bitmap); row_size = 4 * floor((24.0 * symbol->bitmap_width + 31) / 32); 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]); fggrn = (16 * ctoi(symbol->fgcolour[2])) + ctoi(symbol->fgcolour[3]); 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 */ i = 0; - 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 = (3 * column) + (row * row_size); - switch (*(pixelbuf + (image_width * (image_height - row - 1)) + column)) { - 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; + for (row = 0; row < symbol->bitmap_height; row++) { + for (column = 0; column < symbol->bitmap_width; column++) { + 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; + break; + default: + symbol->bitmap[i] = bgblu; + symbol->bitmap[i + 1] = bggrn; + 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; diff --git a/backend/gif.c b/backend/gif.c index c0741f2a..e9c05834 100644 --- a/backend/gif.c +++ b/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]; - int errno; - int row, column; FILE *gif_file; - unsigned short ImageWidth = image_width; - unsigned short ImageHeight = image_height; unsigned short usTemp; int byte_out; #ifdef _MSC_VER - char* rotated_bitmap; char * lzwoutbuf; #endif #ifndef _MSC_VER - char rotated_bitmap[image_height * image_width]; - char lzwoutbuf[image_height * image_width]; + char lzwoutbuf[symbol->bitmap_height * symbol->bitmap_width]; #else - rotated_bitmap = (char *) _alloca((image_height * image_width) * sizeof (char)); lzwoutbuf = (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: - 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 */ if ((symbol->output_options & BARCODE_STDOUT) != 0) { #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); /* Screen Descriptor (7) */ /* Screen Width */ - usTemp = (unsigned short) ImageWidth; + usTemp = (unsigned short) symbol->bitmap_width; outbuf[0] = (unsigned char) (0xff & usTemp); outbuf[1] = (unsigned char) ((0xff00 & usTemp) / 0x100); /* Screen Height */ - usTemp = (unsigned short) ImageHeight; + usTemp = (unsigned short) symbol->bitmap_height; outbuf[2] = (unsigned char) (0xff & usTemp); outbuf[3] = (unsigned char) ((0xff00 & usTemp) / 0x100); /* 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[4] = 0x00; /* Image Width (low byte first) */ - outbuf[5] = (unsigned char) (0xff & ImageWidth); - outbuf[6] = (unsigned char) ((0xff00 & ImageWidth) / 0x100); + outbuf[5] = (unsigned char) (0xff & symbol->bitmap_width); + outbuf[6] = (unsigned char) ((0xff00 & symbol->bitmap_width) / 0x100); /* Image Height */ - outbuf[7] = (unsigned char) (0xff & ImageHeight); - outbuf[8] = (unsigned char) ((0xff00 & ImageHeight) / 0x100); + outbuf[7] = (unsigned char) (0xff & symbol->bitmap_height); + outbuf[8] = (unsigned char) ((0xff00 & symbol->bitmap_height) / 0x100); /* Byte 10 contains the interlaced flag and * 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 */ byte_out = gif_lzw( (unsigned char *) lzwoutbuf, - image_height * image_width, - (unsigned char *) rotated_bitmap, - image_height * image_width); + symbol->bitmap_height * symbol->bitmap_width, + (unsigned char *) pixelbuf, + symbol->bitmap_height * symbol->bitmap_width); if (byte_out <= 0) { fclose(gif_file); return ZINT_ERROR_MEMORY; diff --git a/backend/pcx.c b/backend/pcx.c index 08b4e4ce..2537ebf3 100644 --- a/backend/pcx.c +++ b/backend/pcx.c @@ -44,66 +44,22 @@ #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 errno; int row, column, i, colour; int run_count; FILE *pcx_file; pcx_header_t header; #ifdef _MSC_VER - char* rotated_bitmap; unsigned char* rle_row; #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 unsigned char rle_row[symbol->bitmap_width]; #else rle_row = (unsigned char *) _alloca((symbol->bitmap_width * 6) * sizeof (unsigned char)); #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]); fggrn = (16 * ctoi(symbol->fgcolour[2])) + ctoi(symbol->fgcolour[3]); 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]); 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.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++) { switch (colour) { case 0: - if (rotated_bitmap[(row * symbol->bitmap_width) + column] == '1') { + if (pixelbuf[(row * symbol->bitmap_width) + column] == '1') { rle_row[column] = fgred; } else { rle_row[column] = bgred; } break; case 1: - if (rotated_bitmap[(row * symbol->bitmap_width) + column] == '1') { + if (pixelbuf[(row * symbol->bitmap_width) + column] == '1') { rle_row[column] = fggrn; } else { rle_row[column] = bggrn; } break; case 2: - if (rotated_bitmap[(row * symbol->bitmap_width) + column] == '1') { + if (pixelbuf[(row * symbol->bitmap_width) + column] == '1') { rle_row[column] = fgblu; } else { rle_row[column] = bgblu; diff --git a/backend/png.c b/backend/png.c index 3210baf4..ac00af31 100644 --- a/backend/png.c +++ b/backend/png.c @@ -70,58 +70,25 @@ static void writepng_error_handler(png_structp png_ptr, png_const_charp msg) { 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 *graphic; png_structp png_ptr; png_infop info_ptr; unsigned char *image_data; - int i, row, column, errno; + int i, row, column; int fgred, fggrn, fgblu, bgred, bggrn, bgblu; #ifndef _MSC_VER - unsigned char outdata[image_width * 3]; + unsigned char outdata[symbol->bitmap_width * 3]; #else - unsigned char* outdata = (unsigned char*) _alloca(image_width * 3); + unsigned char* outdata = (unsigned char*) _alloca(symbol->bitmap_width * 3); #endif graphic = &wpng_info; - - switch (rotate_angle) { - case 0: - 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; - } + + graphic->width = symbol->bitmap_width; + graphic->height = symbol->bitmap_height; fgred = (16 * ctoi(symbol->fgcolour[0])) + ctoi(symbol->fgcolour[1]); 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); /* 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 */ - for (row = 0; row < image_width; row++) { - for (column = 0; column < image_height; column++) { - 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; + } + /* write row contents to file */ + image_data = outdata; + png_write_row(png_ptr, image_data); } /* End the file */ diff --git a/backend/raster.c b/backend/raster.c index 2b259a0a..6bc0ed70 100644 --- a/backend/raster.c +++ b/backend/raster.c @@ -47,31 +47,109 @@ #include "font.h" /* Font for human readable text */ #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 */ -extern int bmp_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, int image_height, int image_width, char *pixelbuf, int rotate_angle); -extern int gif_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, char *pixelbuf); +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 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) { case OUT_PNG_FILE: #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 return ZINT_ERROR_INVALID_OPTION; #endif break; 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; 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; default: - error_number = bmp_pixel_plot(symbol, image_height, image_width, pixelbuf, rotate_angle); + error_number = bmp_pixel_plot(symbol, rotated_pixbuf); break; }