libdmtx 0.7.8.7
libdmtx is a software library that enables programs to read and write Data Matrix barcodes of the modern ECC200 variety.
Loading...
Searching...
No Matches
dmtxencodestream.c
Go to the documentation of this file.
1
17#include <assert.h>
18
19#include "dmtx.h"
20#include "dmtxstatic.h"
21
27{
28 DmtxEncodeStream stream;
29
30 stream.input = input;
31 stream.output = output;
32
34 stream.inputNext = 0;
35 stream.outputChainValueCount = 0;
36 stream.outputChainWordCount = 0;
37 stream.reason = NULL;
38 stream.sizeIdx = DmtxUndefined;
40
41 return stream;
42}
43
49{
50 DmtxPassFail passFail;
51
52 dst->currentScheme = src->currentScheme;
53 dst->inputNext = src->inputNext;
56 dst->reason = src->reason;
57 dst->sizeIdx = src->sizeIdx;
58 dst->status = src->status;
59 dst->input = src->input;
60 dst->fnc1 = src->fnc1;
61
62 dmtxByteListCopy(dst->output, src->output, &passFail);
63}
64
69static void streamMarkComplete(DmtxEncodeStream *stream, int sizeIdx)
70{
71 if (stream->status == DmtxStatusEncoding) {
72 stream->sizeIdx = sizeIdx;
73 stream->status = DmtxStatusComplete;
74 DmtxAssert(stream->reason == NULL);
75 }
76}
77
82static void streamMarkInvalid(DmtxEncodeStream *stream, int reasonIdx)
83{
84 stream->status = DmtxStatusInvalid;
85 stream->reason = dmtxErrorMessage[reasonIdx];
86}
87
92static void streamMarkFatal(DmtxEncodeStream *stream, int reasonIdx)
93{
94 stream->status = DmtxStatusFatal;
95 stream->reason = dmtxErrorMessage[reasonIdx];
96}
97
103{
104 DmtxPassFail passFail;
105
106 dmtxByteListPush(stream->output, value, &passFail);
107
108 if (passFail == DmtxPass) {
109 stream->outputChainWordCount++;
110 } else {
112 }
113}
114
120{
121 DmtxByte value;
122 DmtxPassFail passFail;
123
124 if (stream->outputChainWordCount > 0) {
125 value = dmtxByteListPop(stream->output, &passFail);
126 stream->outputChainWordCount--;
127 } else {
128 value = 0;
130 }
131
132 return value;
133}
134
139static void streamOutputSet(DmtxEncodeStream *stream, int index, DmtxByte value)
140{
141 if (index < 0 || index >= stream->output->length) {
143 } else {
144 stream->output->b[index] = value;
145 }
146}
147
153{
154 return (stream->inputNext < stream->input->length) ? DmtxTrue : DmtxFalse;
155}
156
162{
163 DmtxByte value = 0;
164
165 if (streamInputHasNext(stream)) {
166 value = stream->input->b[stream->inputNext];
167 } else {
169 }
170
171 return value;
172}
173
180{
181 DmtxByte value;
182
183 value = streamInputPeekNext(stream);
184
185 if (stream->status == DmtxStatusEncoding) {
186 stream->inputNext++; /* XXX is this what we really mean here? */
187 }
188
189 return value;
190}
191
198{
199 if (stream->inputNext > 0) {
200 stream->inputNext--;
201 } else {
203 }
204}
libdmtx - Data Matrix Encoding/Decoding Library Copyright 2008, 2009 Mike Laughton.
#define DmtxPassFail
Definition dmtx.h:42
#define DmtxTrue
Definition dmtx.h:47
void dmtxByteListPush(DmtxByteList *list, DmtxByte value, DmtxPassFail *passFail)
#define DmtxBoolean
Definition dmtx.h:46
#define DmtxPass
Definition dmtx.h:43
#define DmtxUndefined
Definition dmtx.h:40
@ DmtxSchemeAscii
Definition dmtx.h:90
DmtxByte dmtxByteListPop(DmtxByteList *list, DmtxPassFail *passFail)
void dmtxByteListCopy(DmtxByteList *dst, const DmtxByteList *src, DmtxPassFail *passFail)
#define DmtxFalse
Definition dmtx.h:48
unsigned char DmtxByte
Definition dmtx.h:293
@ DmtxStatusComplete
Definition dmtx.h:81
@ DmtxStatusEncoding
Definition dmtx.h:80
@ DmtxStatusInvalid
Definition dmtx.h:82
@ DmtxStatusFatal
Definition dmtx.h:83
static DmtxByte streamInputAdvanceNext(DmtxEncodeStream *stream)
used as each input cw is processed
static void streamOutputChainAppend(DmtxEncodeStream *stream, DmtxByte value)
push on newest/last append used for encoding each output cw
static void streamOutputSet(DmtxEncodeStream *stream, int index, DmtxByte value)
overwrite arbitrary element used for binary length changes
static DmtxEncodeStream streamInit(DmtxByteList *input, DmtxByteList *output)
static void streamCopy(DmtxEncodeStream *dst, DmtxEncodeStream *src)
static void streamMarkInvalid(DmtxEncodeStream *stream, int reasonIdx)
static DmtxByte streamInputPeekNext(DmtxEncodeStream *stream)
peek at first/oldest used for ascii double digit
static void streamInputAdvancePrev(DmtxEncodeStream *stream)
used as each input cw is processed
static DmtxByte streamOutputChainRemoveLast(DmtxEncodeStream *stream)
pop off newest/last used for edifact
static void streamMarkComplete(DmtxEncodeStream *stream, int sizeIdx)
static void streamMarkFatal(DmtxEncodeStream *stream, int reasonIdx)
static DmtxBoolean streamInputHasNext(DmtxEncodeStream *stream)
libdmtx - Data Matrix Encoding/Decoding Library Copyright 2008, 2009 Mike Laughton.
@ DmtxErrorEmptyList
Definition dmtxstatic.h:398
@ DmtxErrorOutOfBounds
Definition dmtxstatic.h:399
#define DmtxAssert(expr)
Definition dmtxstatic.h:96
static char * dmtxErrorMessage[]
Definition dmtxstatic.h:406
DmtxByte * b
Definition dmtx.h:305
DmtxByteList Use signed int for length fields instead of size_t to play nicely with RS arithmetic.
DmtxByteList * input
Definition dmtx.h:318
DmtxByteList * output
Definition dmtx.h:319
DmtxStatus status
Definition dmtx.h:317