1
0
mirror of https://git.code.sf.net/p/zint/code synced 2026-01-01 09:17:03 +00:00

CODEONE/ULTRA overrun fixes; TELEPEN fixes; CODEONE/LOGMARS/VIN/CODABAR options; GUI updates; tests

This commit is contained in:
gitlost
2020-06-04 18:45:25 +01:00
parent 8131471573
commit 6242e02638
80 changed files with 6393 additions and 2179 deletions

View File

@@ -2,7 +2,7 @@
/*
libzint - the open source barcode library
Copyright (C) 2009-2017 Robin Stuart <rstuart114@gmail.com>
Copyright (C) 2009 - 2020 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
@@ -32,34 +32,37 @@
/* vim: set ts=4 sw=4 et : */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "common.h"
#include "bmp.h" /* Bitmap header structure */
#include <math.h>
#ifdef _MSC_VER
#include <io.h>
#include <fcntl.h>
#endif
#define SSET "0123456789ABCDEF"
INTERNAL int bmp_pixel_plot(struct zint_symbol *symbol, char *pixelbuf) {
int i, row, column;
int fgred, fggrn, fgblu, bgred, bggrn, bgblu;
unsigned int fgred, fggrn, fgblu, bgred, bggrn, bgblu;
int row_size;
unsigned int data_size;
unsigned int data_offset, data_size, file_size;
unsigned char *bitmap_file_start, *bmp_posn;
char *bitmap;
unsigned char *bitmap;
FILE *bmp_file;
bitmap_file_header_t file_header;
bitmap_info_header_t info_header;
if (symbol->bitmap != NULL)
free(symbol->bitmap);
row_size = 4 * ((24 * symbol->bitmap_width + 31) / 32);
data_size = symbol->bitmap_height * row_size;
data_offset = sizeof (bitmap_file_header_t) + sizeof (bitmap_info_header_t);
file_size = data_offset + data_size;
row_size = 4 * floor((24.0 * symbol->bitmap_width + 31) / 32);
bitmap = (char *) malloc(row_size * symbol->bitmap_height);
bitmap_file_start = malloc(file_size);
if (bitmap_file_start == NULL) {
strcpy(symbol->errtxt, "602: Out of memory");
return ZINT_ERROR_MEMORY;
}
memset(bitmap_file_start, 0, file_size); /* Not required but keeps padding bytes consistent */
bitmap = bitmap_file_start + data_offset;
fgred = (16 * ctoi(symbol->fgcolour[0])) + ctoi(symbol->fgcolour[1]);
fggrn = (16 * ctoi(symbol->fgcolour[2])) + ctoi(symbol->fgcolour[3]);
@@ -69,7 +72,6 @@ INTERNAL int bmp_pixel_plot(struct zint_symbol *symbol, char *pixelbuf) {
bgblu = (16 * ctoi(symbol->bgcolour[4])) + ctoi(symbol->bgcolour[5]);
/* Pixel Plotting */
i = 0;
for (row = 0; row < symbol->bitmap_height; row++) {
for (column = 0; column < symbol->bitmap_width; column++) {
i = (3 * column) + (row * row_size);
@@ -129,13 +131,12 @@ INTERNAL int bmp_pixel_plot(struct zint_symbol *symbol, char *pixelbuf) {
}
}
data_size = symbol->bitmap_height * row_size;
symbol->bitmap_byte_length = data_size;
file_header.header_field = 0x4d42; // "BM"
file_header.file_size = sizeof (bitmap_file_header_t) + sizeof (bitmap_info_header_t) + data_size;
file_header.file_size = file_size;
file_header.reserved = 0;
file_header.data_offset = sizeof (bitmap_file_header_t) + sizeof (bitmap_info_header_t);
file_header.data_offset = data_offset;
info_header.header_size = sizeof (bitmap_info_header_t);
info_header.width = symbol->bitmap_width;
@@ -149,15 +150,10 @@ INTERNAL int bmp_pixel_plot(struct zint_symbol *symbol, char *pixelbuf) {
info_header.colours = 0;
info_header.important_colours = 0;
bitmap_file_start = (unsigned char*) malloc(file_header.file_size);
memset(bitmap_file_start, 0xff, file_header.file_size);
bmp_posn = bitmap_file_start;
memcpy(bitmap_file_start, &file_header, sizeof (bitmap_file_header_t));
bmp_posn += sizeof (bitmap_file_header_t);
memcpy(bmp_posn, &info_header, sizeof (bitmap_info_header_t));
bmp_posn += sizeof (bitmap_info_header_t);
memcpy(bmp_posn, bitmap, data_size);
/* Open output file in binary mode */
if ((symbol->output_options & BARCODE_STDOUT) != 0) {
@@ -165,7 +161,6 @@ INTERNAL int bmp_pixel_plot(struct zint_symbol *symbol, char *pixelbuf) {
if (-1 == _setmode(_fileno(stdout), _O_BINARY)) {
strcpy(symbol->errtxt, "600: Can't open output file");
free(bitmap_file_start);
free(bitmap);
return ZINT_ERROR_FILE_ACCESS;
}
#endif
@@ -173,7 +168,6 @@ INTERNAL int bmp_pixel_plot(struct zint_symbol *symbol, char *pixelbuf) {
} else {
if (!(bmp_file = fopen(symbol->outfile, "wb"))) {
free(bitmap_file_start);
free(bitmap);
strcpy(symbol->errtxt, "601: Can't open output file");
return ZINT_ERROR_FILE_ACCESS;
}
@@ -183,6 +177,5 @@ INTERNAL int bmp_pixel_plot(struct zint_symbol *symbol, char *pixelbuf) {
fclose(bmp_file);
free(bitmap_file_start);
free(bitmap);
return 0;
}