mirror of
https://github.com/zint/zint
synced 2024-11-16 20:57:25 +13:00
Make alpha channel available in direct plotting
This commit is contained in:
parent
382a051cb5
commit
42e866c889
@ -64,22 +64,44 @@ static int buffer_plot(struct zint_symbol *symbol, char *pixelbuf) {
|
|||||||
int fgred, fggrn, fgblu, bgred, bggrn, bgblu;
|
int fgred, fggrn, fgblu, bgred, bggrn, bgblu;
|
||||||
int fgalpha, bgalpha;
|
int fgalpha, bgalpha;
|
||||||
int row, column, i;
|
int row, column, i;
|
||||||
|
int plot_alpha = 0;
|
||||||
|
|
||||||
|
if (strlen(symbol->fgcolour) > 6) {
|
||||||
|
fgalpha = (16 * ctoi(symbol->fgcolour[6])) + ctoi(symbol->fgcolour[7]);
|
||||||
|
plot_alpha = 1;
|
||||||
|
} else {
|
||||||
|
fgalpha = 0xff;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (strlen(symbol->bgcolour) > 6) {
|
||||||
|
bgalpha = (16 * ctoi(symbol->bgcolour[6])) + ctoi(symbol->bgcolour[7]);
|
||||||
|
plot_alpha = 1;
|
||||||
|
} else {
|
||||||
|
bgalpha = 0xff;
|
||||||
|
}
|
||||||
|
|
||||||
/* Free any previous bitmap */
|
/* Free any previous bitmap */
|
||||||
if (symbol->bitmap != NULL) {
|
if (symbol->bitmap != NULL) {
|
||||||
free(symbol->bitmap);
|
free(symbol->bitmap);
|
||||||
symbol->bitmap = NULL;
|
symbol->bitmap = NULL;
|
||||||
}
|
}
|
||||||
|
if (symbol->alphamap != NULL) {
|
||||||
|
free(symbol->alphamap);
|
||||||
|
symbol->alphamap = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
symbol->bitmap = (unsigned char *) malloc(symbol->bitmap_width * symbol->bitmap_height * 3);
|
symbol->bitmap = (unsigned char *) malloc(symbol->bitmap_width * symbol->bitmap_height * 3);
|
||||||
if (symbol->bitmap == NULL) {
|
if (symbol->bitmap == NULL) {
|
||||||
strcpy(symbol->errtxt, "661: Insufficient memory for bitmap buffer");
|
strcpy(symbol->errtxt, "661: Insufficient memory for bitmap buffer");
|
||||||
return ZINT_ERROR_MEMORY;
|
return ZINT_ERROR_MEMORY;
|
||||||
}
|
}
|
||||||
|
if (plot_alpha) {
|
||||||
symbol->alphamap = (unsigned char *) malloc(symbol->bitmap_width * symbol->bitmap_height);
|
symbol->alphamap = (unsigned char *) malloc(symbol->bitmap_width * symbol->bitmap_height);
|
||||||
if (symbol->alphamap == NULL) {
|
if (symbol->alphamap == NULL) {
|
||||||
strcpy(symbol->errtxt, "662: Insufficient memory for alphamap buffer");
|
strcpy(symbol->errtxt, "662: Insufficient memory for alphamap buffer");
|
||||||
return ZINT_ERROR_MEMORY;
|
return ZINT_ERROR_MEMORY;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
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]);
|
||||||
@ -88,18 +110,6 @@ static int buffer_plot(struct zint_symbol *symbol, char *pixelbuf) {
|
|||||||
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]);
|
||||||
|
|
||||||
if (strlen(symbol->fgcolour) > 6) {
|
|
||||||
fgalpha = (16 * ctoi(symbol->fgcolour[6])) + ctoi(symbol->fgcolour[7]);
|
|
||||||
} else {
|
|
||||||
fgalpha = 0xff;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (strlen(symbol->bgcolour) > 6) {
|
|
||||||
bgalpha = (16 * ctoi(symbol->bgcolour[6])) + ctoi(symbol->bgcolour[7]);
|
|
||||||
} else {
|
|
||||||
bgalpha = 0xff;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (row = 0; row < symbol->bitmap_height; row++) {
|
for (row = 0; row < symbol->bitmap_height; row++) {
|
||||||
for (column = 0; column < symbol->bitmap_width; column++) {
|
for (column = 0; column < symbol->bitmap_width; column++) {
|
||||||
i = ((row * symbol->bitmap_width) + column) * 3;
|
i = ((row * symbol->bitmap_width) + column) * 3;
|
||||||
@ -108,61 +118,61 @@ static int buffer_plot(struct zint_symbol *symbol, char *pixelbuf) {
|
|||||||
symbol->bitmap[i] = 255;
|
symbol->bitmap[i] = 255;
|
||||||
symbol->bitmap[i + 1] = 255;
|
symbol->bitmap[i + 1] = 255;
|
||||||
symbol->bitmap[i + 2] = 255;
|
symbol->bitmap[i + 2] = 255;
|
||||||
symbol->alphamap[i / 3] = fgalpha;
|
if (plot_alpha) symbol->alphamap[i / 3] = fgalpha;
|
||||||
break;
|
break;
|
||||||
case 'C': // Cyan
|
case 'C': // Cyan
|
||||||
symbol->bitmap[i] = 0;
|
symbol->bitmap[i] = 0;
|
||||||
symbol->bitmap[i + 1] = 255;
|
symbol->bitmap[i + 1] = 255;
|
||||||
symbol->bitmap[i + 2] = 255;
|
symbol->bitmap[i + 2] = 255;
|
||||||
symbol->alphamap[i / 3] = fgalpha;
|
if (plot_alpha) symbol->alphamap[i / 3] = fgalpha;
|
||||||
break;
|
break;
|
||||||
case 'B': // Blue
|
case 'B': // Blue
|
||||||
symbol->bitmap[i] = 0;
|
symbol->bitmap[i] = 0;
|
||||||
symbol->bitmap[i + 1] = 0;
|
symbol->bitmap[i + 1] = 0;
|
||||||
symbol->bitmap[i + 2] = 255;
|
symbol->bitmap[i + 2] = 255;
|
||||||
symbol->alphamap[i / 3] = fgalpha;
|
if (plot_alpha) symbol->alphamap[i / 3] = fgalpha;
|
||||||
break;
|
break;
|
||||||
case 'M': // Magenta
|
case 'M': // Magenta
|
||||||
symbol->bitmap[i] = 255;
|
symbol->bitmap[i] = 255;
|
||||||
symbol->bitmap[i + 1] = 0;
|
symbol->bitmap[i + 1] = 0;
|
||||||
symbol->bitmap[i + 2] = 255;
|
symbol->bitmap[i + 2] = 255;
|
||||||
symbol->alphamap[i / 3] = fgalpha;
|
if (plot_alpha) symbol->alphamap[i / 3] = fgalpha;
|
||||||
break;
|
break;
|
||||||
case 'R': // Red
|
case 'R': // Red
|
||||||
symbol->bitmap[i] = 255;
|
symbol->bitmap[i] = 255;
|
||||||
symbol->bitmap[i + 1] = 0;
|
symbol->bitmap[i + 1] = 0;
|
||||||
symbol->bitmap[i + 2] = 0;
|
symbol->bitmap[i + 2] = 0;
|
||||||
symbol->alphamap[i / 3] = fgalpha;
|
if (plot_alpha) symbol->alphamap[i / 3] = fgalpha;
|
||||||
break;
|
break;
|
||||||
case 'Y': // Yellow
|
case 'Y': // Yellow
|
||||||
symbol->bitmap[i] = 255;
|
symbol->bitmap[i] = 255;
|
||||||
symbol->bitmap[i + 1] = 255;
|
symbol->bitmap[i + 1] = 255;
|
||||||
symbol->bitmap[i + 2] = 0;
|
symbol->bitmap[i + 2] = 0;
|
||||||
symbol->alphamap[i / 3] = fgalpha;
|
if (plot_alpha) symbol->alphamap[i / 3] = fgalpha;
|
||||||
break;
|
break;
|
||||||
case 'G': // Green
|
case 'G': // Green
|
||||||
symbol->bitmap[i] = 0;
|
symbol->bitmap[i] = 0;
|
||||||
symbol->bitmap[i + 1] = 255;
|
symbol->bitmap[i + 1] = 255;
|
||||||
symbol->bitmap[i + 2] = 0;
|
symbol->bitmap[i + 2] = 0;
|
||||||
symbol->alphamap[i / 3] = fgalpha;
|
if (plot_alpha) symbol->alphamap[i / 3] = fgalpha;
|
||||||
break;
|
break;
|
||||||
case 'K': // Black
|
case 'K': // Black
|
||||||
symbol->bitmap[i] = 0;
|
symbol->bitmap[i] = 0;
|
||||||
symbol->bitmap[i + 1] = 0;
|
symbol->bitmap[i + 1] = 0;
|
||||||
symbol->bitmap[i + 2] = 0;
|
symbol->bitmap[i + 2] = 0;
|
||||||
symbol->alphamap[i / 3] = fgalpha;
|
if (plot_alpha) symbol->alphamap[i / 3] = fgalpha;
|
||||||
break;
|
break;
|
||||||
case DEFAULT_INK:
|
case DEFAULT_INK:
|
||||||
symbol->bitmap[i] = fgred;
|
symbol->bitmap[i] = fgred;
|
||||||
symbol->bitmap[i + 1] = fggrn;
|
symbol->bitmap[i + 1] = fggrn;
|
||||||
symbol->bitmap[i + 2] = fgblu;
|
symbol->bitmap[i + 2] = fgblu;
|
||||||
symbol->alphamap[i / 3] = fgalpha;
|
if (plot_alpha) symbol->alphamap[i / 3] = fgalpha;
|
||||||
break;
|
break;
|
||||||
default: // DEFAULT_PAPER
|
default: // DEFAULT_PAPER
|
||||||
symbol->bitmap[i] = bgred;
|
symbol->bitmap[i] = bgred;
|
||||||
symbol->bitmap[i + 1] = bggrn;
|
symbol->bitmap[i + 1] = bggrn;
|
||||||
symbol->bitmap[i + 2] = bgblu;
|
symbol->bitmap[i + 2] = bgblu;
|
||||||
symbol->alphamap[i / 3] = bgalpha;
|
if (plot_alpha) symbol->alphamap[i / 3] = bgalpha;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -903,6 +903,10 @@ bitmap_width | integer | Width of stored bitmap | (output only)
|
|||||||
| | image (in pixels). |
|
| | image (in pixels). |
|
||||||
bitmap_height | integer | Height of stored bitmap | (output only)
|
bitmap_height | integer | Height of stored bitmap | (output only)
|
||||||
| | image (in pixels). |
|
| | image (in pixels). |
|
||||||
|
alphamap | pointer to | Pointer to array | (output only)
|
||||||
|
| unsigned | representing alpha |
|
||||||
|
| character | channel (or NULL if no |
|
||||||
|
| array | alpha channel needed). |
|
||||||
bitmap_byte_length| integer | Size of BMP bitmap data. | (output only)
|
bitmap_byte_length| integer | Size of BMP bitmap data. | (output only)
|
||||||
vector | pointer to | Pointer to vector header | (output only)
|
vector | pointer to | Pointer to vector header | (output only)
|
||||||
| vector | containing pointers to |
|
| vector | containing pointers to |
|
||||||
|
Loading…
Reference in New Issue
Block a user