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 fgalpha, bgalpha;
|
||||
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 */
|
||||
if (symbol->bitmap != NULL) {
|
||||
free(symbol->bitmap);
|
||||
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);
|
||||
if (symbol->bitmap == NULL) {
|
||||
strcpy(symbol->errtxt, "661: Insufficient memory for bitmap buffer");
|
||||
return ZINT_ERROR_MEMORY;
|
||||
}
|
||||
if (plot_alpha) {
|
||||
symbol->alphamap = (unsigned char *) malloc(symbol->bitmap_width * symbol->bitmap_height);
|
||||
if (symbol->alphamap == NULL) {
|
||||
strcpy(symbol->errtxt, "662: Insufficient memory for alphamap buffer");
|
||||
return ZINT_ERROR_MEMORY;
|
||||
}
|
||||
}
|
||||
|
||||
fgred = (16 * ctoi(symbol->fgcolour[0])) + ctoi(symbol->fgcolour[1]);
|
||||
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]);
|
||||
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 (column = 0; column < symbol->bitmap_width; column++) {
|
||||
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 + 1] = 255;
|
||||
symbol->bitmap[i + 2] = 255;
|
||||
symbol->alphamap[i / 3] = fgalpha;
|
||||
if (plot_alpha) symbol->alphamap[i / 3] = fgalpha;
|
||||
break;
|
||||
case 'C': // Cyan
|
||||
symbol->bitmap[i] = 0;
|
||||
symbol->bitmap[i + 1] = 255;
|
||||
symbol->bitmap[i + 2] = 255;
|
||||
symbol->alphamap[i / 3] = fgalpha;
|
||||
if (plot_alpha) symbol->alphamap[i / 3] = fgalpha;
|
||||
break;
|
||||
case 'B': // Blue
|
||||
symbol->bitmap[i] = 0;
|
||||
symbol->bitmap[i + 1] = 0;
|
||||
symbol->bitmap[i + 2] = 255;
|
||||
symbol->alphamap[i / 3] = fgalpha;
|
||||
if (plot_alpha) symbol->alphamap[i / 3] = fgalpha;
|
||||
break;
|
||||
case 'M': // Magenta
|
||||
symbol->bitmap[i] = 255;
|
||||
symbol->bitmap[i + 1] = 0;
|
||||
symbol->bitmap[i + 2] = 255;
|
||||
symbol->alphamap[i / 3] = fgalpha;
|
||||
if (plot_alpha) symbol->alphamap[i / 3] = fgalpha;
|
||||
break;
|
||||
case 'R': // Red
|
||||
symbol->bitmap[i] = 255;
|
||||
symbol->bitmap[i + 1] = 0;
|
||||
symbol->bitmap[i + 2] = 0;
|
||||
symbol->alphamap[i / 3] = fgalpha;
|
||||
if (plot_alpha) symbol->alphamap[i / 3] = fgalpha;
|
||||
break;
|
||||
case 'Y': // Yellow
|
||||
symbol->bitmap[i] = 255;
|
||||
symbol->bitmap[i + 1] = 255;
|
||||
symbol->bitmap[i + 2] = 0;
|
||||
symbol->alphamap[i / 3] = fgalpha;
|
||||
if (plot_alpha) symbol->alphamap[i / 3] = fgalpha;
|
||||
break;
|
||||
case 'G': // Green
|
||||
symbol->bitmap[i] = 0;
|
||||
symbol->bitmap[i + 1] = 255;
|
||||
symbol->bitmap[i + 2] = 0;
|
||||
symbol->alphamap[i / 3] = fgalpha;
|
||||
if (plot_alpha) symbol->alphamap[i / 3] = fgalpha;
|
||||
break;
|
||||
case 'K': // Black
|
||||
symbol->bitmap[i] = 0;
|
||||
symbol->bitmap[i + 1] = 0;
|
||||
symbol->bitmap[i + 2] = 0;
|
||||
symbol->alphamap[i / 3] = fgalpha;
|
||||
if (plot_alpha) symbol->alphamap[i / 3] = fgalpha;
|
||||
break;
|
||||
case DEFAULT_INK:
|
||||
symbol->bitmap[i] = fgred;
|
||||
symbol->bitmap[i + 1] = fggrn;
|
||||
symbol->bitmap[i + 2] = fgblu;
|
||||
symbol->alphamap[i / 3] = fgalpha;
|
||||
if (plot_alpha) symbol->alphamap[i / 3] = fgalpha;
|
||||
break;
|
||||
default: // DEFAULT_PAPER
|
||||
symbol->bitmap[i] = bgred;
|
||||
symbol->bitmap[i + 1] = bggrn;
|
||||
symbol->bitmap[i + 2] = bgblu;
|
||||
symbol->alphamap[i / 3] = bgalpha;
|
||||
if (plot_alpha) symbol->alphamap[i / 3] = bgalpha;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -903,6 +903,10 @@ bitmap_width | integer | Width of stored bitmap | (output only)
|
||||
| | image (in pixels). |
|
||||
bitmap_height | integer | Height of stored bitmap | (output only)
|
||||
| | 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)
|
||||
vector | pointer to | Pointer to vector header | (output only)
|
||||
| vector | containing pointers to |
|
||||
|
Loading…
Reference in New Issue
Block a user