HANXIN: 0xFFE terminator; reedsol/AZTEC: stack-based; AZTEC/HANXIN/QR/GRIDMATRIX speedups; #209

This commit is contained in:
gitlost 2020-11-27 12:54:44 +00:00
parent ab379a233d
commit cd214addba
70 changed files with 5703 additions and 2907 deletions

View file

@ -52,20 +52,20 @@
* License along with the GNU LIBICONV Library; see the file COPYING.LIB.
* If not, see <https://www.gnu.org/licenses/>.
*/
#include <string.h>
#ifdef _MSC_VER
#include <malloc.h>
#endif
#include "common.h"
#include "sjis.h"
INTERNAL int utf_to_eci(const int eci, const unsigned char source[], unsigned char dest[], size_t *length); /* Convert Unicode to other encodings */
/* Convert Unicode to other encodings */
INTERNAL int utf_to_eci(const int eci, const unsigned char source[], unsigned char dest[], int *length);
/*
* JISX0201.1976-0 (libiconv-1.16/lib/jisx0201.h)
*/
static int jisx0201_wctomb(unsigned int* r, unsigned int wc) {
static int jisx0201_wctomb(unsigned int *r, unsigned int wc) {
if (wc < 0x0080 && !(wc == 0x005c || wc == 0x007e)) {
*r = wc;
return 1;
@ -1444,7 +1444,7 @@ static const Summary16 jisx0208_uni2indx_pageff[15] = {
{ 6877, 0x0000 }, { 6877, 0x0000 }, { 6877, 0x0028 },
};
static int jisx0208_wctomb(unsigned int* r, unsigned int wc) {
static int jisx0208_wctomb(unsigned int *r, unsigned int wc) {
const Summary16 *summary = NULL;
if (wc < 0x0100) {
summary = &jisx0208_uni2indx_page00[(wc>>4)];
@ -1484,7 +1484,7 @@ static int jisx0208_wctomb(unsigned int* r, unsigned int wc) {
*/
/* Returns 1 or 2 on success, 0 if no mapping */
INTERNAL int sjis_wctomb_zint(unsigned int* r, unsigned int wc) {
INTERNAL int sjis_wctomb_zint(unsigned int *r, unsigned int wc) {
int ret;
/* Try JIS X 0201-1976. */
@ -1494,7 +1494,8 @@ INTERNAL int sjis_wctomb_zint(unsigned int* r, unsigned int wc) {
}
/* Try JIS X 0208-1990. */
/* ZINT: Note leaving mapping of full-width reverse solidus U+FF3C to 0x815F (duplicate of patched U+005C) to avoid having to regen tables */
/* ZINT: Note leaving mapping of full-width reverse solidus U+FF3C to 0x815F (duplicate of patched U+005C) to avoid
* having to regen tables */
ret = jisx0208_wctomb(r, wc);
if (ret) {
return ret;
@ -1515,13 +1516,14 @@ INTERNAL int sjis_wctomb_zint(unsigned int* r, unsigned int wc) {
}
/* Convert UTF-8 string to Shift JIS and place in array of ints */
INTERNAL int sjis_utf8tomb(struct zint_symbol *symbol, const unsigned char source[], size_t* p_length, unsigned int* jisdata) {
INTERNAL int sjis_utf8tomb(struct zint_symbol *symbol, const unsigned char source[], int *p_length,
unsigned int *jisdata) {
int error_number;
unsigned int i, length;
#ifndef _MSC_VER
unsigned int utfdata[*p_length + 1];
#else
unsigned int* utfdata = (unsigned int*) _alloca((*p_length + 1) * sizeof(unsigned int));
unsigned int *utfdata = (unsigned int *) _alloca((*p_length + 1) * sizeof(unsigned int));
#endif
error_number = utf8_to_unicode(symbol, source, utfdata, p_length, 1 /*disallow_4byte*/);
@ -1540,12 +1542,13 @@ INTERNAL int sjis_utf8tomb(struct zint_symbol *symbol, const unsigned char sourc
}
/* Convert UTF-8 string to single byte ECI and place in array of ints */
INTERNAL int sjis_utf8tosb(int eci, const unsigned char source[], size_t* p_length, unsigned int* jisdata, int full_multibyte) {
INTERNAL int sjis_utf8tosb(int eci, const unsigned char source[], int *p_length, unsigned int *jisdata,
int full_multibyte) {
int error_number;
#ifndef _MSC_VER
unsigned char single_byte[*p_length + 1];
#else
unsigned char* single_byte = (unsigned char*) _alloca(*p_length + 1);
unsigned char *single_byte = (unsigned char *) _alloca(*p_length + 1);
#endif
error_number = utf_to_eci(eci, source, single_byte, p_length);
@ -1559,9 +1562,9 @@ INTERNAL int sjis_utf8tosb(int eci, const unsigned char source[], size_t* p_leng
return 0;
}
/* If `full_multibyte` set, copy byte input stream to array of ints, putting double-bytes that match QR Kanji mode in a single entry.
* If `full_multibyte` not set, do a straight copy */
INTERNAL void sjis_cpy(const unsigned char source[], size_t* p_length, unsigned int* jisdata, int full_multibyte) {
/* If `full_multibyte` set, copy byte input stream to array of ints, putting double-bytes that match QR Kanji mode in a
* single entry. If `full_multibyte` not set, do a straight copy */
INTERNAL void sjis_cpy(const unsigned char source[], int *p_length, unsigned int *jisdata, int full_multibyte) {
unsigned int i, j, jis, length;
unsigned char c;
@ -1571,7 +1574,8 @@ INTERNAL void sjis_cpy(const unsigned char source[], size_t* p_length, unsigned
if (((c >= 0x81 && c <= 0x9F) || (c >= 0xE0 && c <= 0xEB)) && length - i >= 2) {
jis = (c << 8) | source[i + 1];
if ((jis >= 0x8140 && jis <= 0x9FFC) || (jis >= 0xE040 && jis <= 0xEBBF)) {
/* This may or may not be valid Shift JIS, but don't care as long as it can be encoded in QR Kanji mode */
/* This may or may not be valid Shift JIS, but don't care as long as it can be encoded in
* QR Kanji mode */
jisdata[j] = jis;
i++;
} else {