/* ======================================================================= */
/** "DotEncod.c" - DotCode (rev 2.23) Encoding Module 04/05/19 (jHe) **/
/* ======================================================================= */
/* Copyright (c) 2016-2019 AIM Technical Symbology Committee (AIM TSC). */
/* AIM TSC grants anyone free use of the code and assumes no liability. */
/* This software is based on contribution from Honeywell, and the original */
/* copyright notice is seen below. */
/* ======================================================================= */
/* This DotCode encoding source code is Copyrighted 2013 by Honeywell */
/* Imaging & Mobility, Skaneateles Falls, NY. However, it is intended for */
/* public use and may be distributed and used freely. This software is be- */
/* lieved to be error-free but Honeywell assumes no liability for its use. */
/* ======================================================================= */
// Rev 1.20 -- initial public release (6/20/08, released 8/5/08)
// Rev 1.21 -- fixed bugs in Macro header encoding & Symbol Separation (10/7/08)
// Rev 1.22 -- updated padding character(s) to value 106 as specified; also
// updated Macro(xx) expansion & FNC2 operations per changes to
// specification (10/26/08)
// Rev 2.00 -- fixed two bugs, in Score() and in call to AddPads() (search for "REV 2.00 FIX" in 5 places)
// Rev 2.10 -- fixed bugs in rsencode() to properly handle large symbols (nc >= GF) (marked by "LARGE FIX")
// Rev 2.20 -- subtract a penalty score for empty rows/columns from total code score for each mask, where
// the penalty is Sum(n * N), where N is the number of positions in a row/column, and n is
// the number of consecutive empty rows/columns (2/24/2016)
// commit to the first mask that scores above a threshold (2/24/2016)
// Rev 2.21 -- "fast" parameter of the encoder controls whether to use the bypass algo above (9/5/2017)
// Rev 2.22 -- reverse the mask trial order; fill in the last 6 dots if no mask passes the threshold
// Also tries to use the fill-in corner dots method after each regular mask for the fast
// bypass method (10/12/2017)
// Rev 2.23 -- Removed conditions for calling RowPenalty() and ColPenalty in ScoreArray(). Also
// changed some integral variable and function return types to long if they may not fit
// in a 16-bit integer (4/5/2019)
// Rev 2.24 -- Return same undifferentiated score for code with any unlit edge (4/29/2019)
// DotCodeEncode() normally works on an input character string with the
// following substitutions:
// "#0" stands for <NUL>
// "#1" stands for FNC1
// "#2" stands for FNC2 (& "#2" followed by 6 digits encodes an ECI)
// "#3" stands for FNC3, and
// "##" for the "#" character
// NOTES:
// "#" followed by anything else is invalid, & DotCodeEncode() returns -1.
// BUT... setting argument "literal" non-zero bypasses these "#-" translations,
// & all input message strings are valid but FNCx characters can't be encoded
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include <limits.h>
#include "DotEncod.h"
#define BOOL char
#define UCHAR unsigned char
#define TRUE 1
#define FALSE 0
#define GF 113 /* Size of the Galois field */
#define PM 3 /* Prime Modulus for the Galois field */
#define SCORE_UNLIT_EDGE -99999
/***** GLOBAL VARIABLES *****/
int wd[5000]; /* array of Codewords (data plus checks) in order */
int lg[GF], alg[GF]; /* arrays for log and antilog values */
int neras; /* the # of Erasures &... */
int ocp; /* the total # of Erasures plus Errors found */
int uec;
/* ======================================================================= */
/* ************************ R-S ENCODING ************************ */
/* ======================================================================= */
/*-------------------------------------------------------------------------*/
/* "rsencode(nd,nc)" adds "nc" R-S check words to "nd" data words in wd[] */
/*-------------------------------------------------------------------------*/
void rsencode (int nd, int nc)
{
int i, j, k, nw, start, step;
int root[GF], c[GF];
nw = nd+nc;
step = (nw+GF-2)/(GF-1);
for (start=0; start<step; start++) {
int ND = (nd-start+step-1)/step, NW = (nw-start+step-1)/step, NC = NW-ND;
/* First time through, begin by generating "NC+1" roots (antilogs): */
if (!start) { // LARGE FIX
root[0] = 1;
for (i=1; i<=(NC+1); i++) root[i] = (PM * root[i-1]) % GF;
}
/* Compute also the generator polynomial "c" of order "NC": */
for (i=1; i<=NC; i++) c[i] = 0;
c[0] = 1;
for (i=1; i<=NC; i++) {
for (j=NC; j>=1; j--) {
c[j] = (GF + c[j] - (root[i] * c[j-1]) % GF) % GF;
}
}
// Finally compute the corresponding checkword values into wd[], starting at wd[start] & stepping by step
for (i=ND; i<NW; i++) wd[start+i*step] = 0;
for (i=0; i<ND; i++) {
k = (wd[start+i*step] + wd[start+ND*step]) % GF;
for (j=0; j<NC-1; j++) {
wd[start+(ND+j)*step] = (GF - ((c[j+1] * k) % GF) + wd[start+(ND+j+1)*step]) % GF;
}
wd[start+(ND+NC-1)*step] = (GF - ((c[NC] * k) % GF)) % GF;
}
for (i=ND; i<NW; i++) wd[start+i*step] = (GF - wd[start+i*step]) % GF;
}
}
/* ======================================================================= */
/* ********************* MESSAGE ENCODING ********************** */
/* ======================================================================= */
/***** MORE GLOBAL VARIABLES *****/
UCHAR *cw;
char PastFirstDatum, InsideMacro; // some status flags
int Base103[6], bincnt; // accomodates Binary Mode compaction
#define FNC1 256
#define FNC2 257
#define FNC3 258
#define END 259
#define EOT 04
#define LF 10
#define CR 13
#define FS 28
#define GS 29
#define RS 30
#define US 31
#define TWIX(a,b,c) (((a)<=(c))&&((c)<=(b)))
#define DIGIT(c) TWIX('0','9',(c))
#define STORE(a) *(cw++) = (a)
#define STOREDATUM(a) { STORE(a); PastFirstDatum = 1; }
int nDigits (int *c)
{
int *last = c;
while (DIGIT(*last)) last++;
return (last-c);
}
void StoreC (int *c) //'0' equals 48
{
int v = (*c-'0') * 10 + (*(c+1)-'0');
STOREDATUM(v);
}
void BinShift (int c)
{
if (c < 160) {
STORE(110);
STOREDATUM(c-64);
}
else {
STORE(111);
STOREDATUM(c-160);
}
}
#define SHIFT(v,m,n) { STORE(v); backto = mode; mode = m; nshift = n; repeat = TRUE; }
#define LATCH(v,m) { STORE(v); mode = m; repeat = TRUE; }
#define CODE_SET_A 0
#define CODE_SET_B 1
#define CODE_SET_C 2
#define BINARY_MODE 3
#define FNCx(c) TWIX(FNC1,FNC3,c)
BOOL DatumA (int c)
{
return ((TWIX(0,95,c)||(FNCx(c)))? TRUE:FALSE);
}
BOOL DatumB (int c)
{
return ((TWIX(32,127,c)||((PastFirstDatum)&&((c==9)||TWIX(28,30,c)))||(FNCx(c)))? TRUE:FALSE);
}
BOOL CrLf (int *c)
{
return (((*c==CR)&&(*(c+1)==LF))? TRUE:FALSE);
}
BOOL DigitPair (int *c)
{
return (((DIGIT(*c))&&(DIGIT(*(c+1))))? TRUE:FALSE);
}
BOOL SeventeenTen (int *c)
{
return (((nDigits(c)>=10)&&(*c=='1')&&(*(c+1)=='7')&&(*(c+8)=='1')&&(*(c+9)=='0'))? TRUE:FALSE);
}
BOOL Binary (int c)
{
return ((TWIX(128,255,c))? TRUE:FALSE);
}
BOOL ECI (int *c, long *v)
{
if ((*c == FNC2)&&(nDigits(c+1) >= 6)) {
int n;
for (n=6,*v=0; n; n--) *v = *v * 10 + (*(++c)-'0');
return (TRUE);
}
return (FALSE);
}
int StoreFNC2 (int *c, int *nshift)
{
long j;
STORE(108);
if (ECI(c,&j)) {
if (j < 40) {
STORE(j);
if (*nshift) (*nshift)--;
}
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
采用C语言写的dotcode编码源代码,实现了多字符集的编码,使用灵活、方便,可调整码点大小、长宽比等参数。里面包含了main函数和保存为bmp图片的函数,可对生成的dotcode进行圆点、方形等形状的设置,也可设置各点的大小,功能强大,使用简单。
资源推荐
资源详情
资源评论
收起资源包目录
DotCodeEncode.rar (3个子文件)
DotEncod.h 3KB
DotEncod.c 38KB
main.c 12KB
共 3 条
- 1
资源评论
- 盘安技2021-12-18用户下载后在一定时间内未进行评价,系统默认好评。
- weixin_549620512021-10-15用户下载后在一定时间内未进行评价,系统默认好评。
- 况鹏2024-03-14内容与描述一致,超赞的资源,值得借鉴的内容很多,支持!
- hehailyc2021-10-21用户下载后在一定时间内未进行评价,系统默认好评。
- 2401_835539692024-03-21发现一个宝藏资源,赶紧冲冲冲!支持大佬~
尘雨若烟
- 粉丝: 4
- 资源: 8
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功