libdmtx 0.7.8.8
libdmtx is a software library that enables programs to read and write Data Matrix barcodes of the modern ECC200 variety.
Loading...
Searching...
No Matches
dmtxencodescheme.c File Reference

libdmtx - Data Matrix Encoding/Decoding Library Copyright 2011 Mike Laughton. More...

#include <assert.h>
#include "dmtx.h"
#include "dmtxstatic.h"

Go to the source code of this file.

Macros

#define CHKSCHEME(s)
 In this file:
 
#define CHKERR
 
#define CHKSIZE
 

Functions

static int encodeSingleScheme (DmtxByteList *input, DmtxByteList *output, int sizeIdxRequest, DmtxScheme scheme, int fnc1)
 
static void encodeNextChunk (DmtxEncodeStream *stream, int scheme, int option, int sizeIdxRequest)
 This function distributes work to the equivalent scheme-specific implementation.
 
static void encodeChangeScheme (DmtxEncodeStream *stream, DmtxScheme targetScheme, int unlatchType)
 
static int getRemainingSymbolCapacity (int outputLength, int sizeIdx)
 

Detailed Description

libdmtx - Data Matrix Encoding/Decoding Library Copyright 2011 Mike Laughton.

All rights reserved. Copyright 2012-2016 Vadim A. Misbakh-Soloviov. All rights reserved.

See LICENSE file in the main project directory for full terms of use and distribution.

Contact: Vadim A. Misbakh-Soloviov dmtx@.nosp@m.mva..nosp@m.name Mike Laughton mike@.nosp@m.drag.nosp@m.onfly.nosp@m.logi.nosp@m.c.com

Logic for encoding in single scheme

Definition in file dmtxencodescheme.c.

Macro Definition Documentation

◆ CHKERR

#define CHKERR
Value:
{ \
if (stream->status != DmtxStatusEncoding) { \
return; \
} \
}
@ DmtxStatusEncoding
Definition dmtx.h:80

Definition at line 83 of file dmtxencodescheme.c.

◆ CHKSCHEME

#define CHKSCHEME ( s)
Value:
{ \
if (stream->currentScheme != (s)) { \
streamMarkFatal(stream, DmtxErrorUnexpectedScheme); \
return; \
} \
}
@ DmtxErrorUnexpectedScheme
Definition dmtxstatic.h:402

In this file:

A "word" refers to a full codeword byte to be appended to the encoded output.

A "value" refers to any scheme value being appended to the output stream, regardless of how many bytes are used to represent it. Examples:

ASCII: 1 value in 1 codeword ASCII (digits): 2 values in 1 codeword C40/Text/X12: 3 values in 2 codewords C40/Text/X12 (unlatch): 1 values in 1 codeword EDIFACT: 4 values in 3 codewords Base 256: 1 value in 1 codeword

  • Shifts count as values, so outputChainValueCount will reflect these.
  • Latches and unlatches are also counted as values, but always in the scheme being exited.
  • Base256 header bytes are not included as values.

A "chunk" refers to the minimum grouping of values in a schema that must be encoded together.

ASCII: 1 value (1 codeword) in 1 chunk ASCII (digits): 2 values (1 codeword) in 1 chunk (optional) C40/Text/X12: 3 values (2 codewords) in 1 chunk C40/Text/X12 (unlatch): 1 value (1 codeword) in 1 chunk EDIFACT: 1 value (1 codeword*) in 1 chunk Base 256: 1 value (1 codeword) in 1 chunk

  • EDIFACT writes 6 bits at a time, but progress is tracked to the next byte boundary. If unlatch value finishes mid-byte, the remaining bits before the next boundary are set to zero.

Each scheme implements 3 equivalent functions:

  • encodeNextChunk[Scheme]
  • AppendValue[Scheme]
  • CompleteIfDone[Scheme]

The function encodeNextChunk() (no Scheme in the name) knows which scheme- specific implementations to call based on the stream's current encodation scheme.

It's important that encodeNextChunk[Scheme] not call CompleteIfDone[Scheme] directly because some parts of the logic might want to encode a stream without allowing the padding and other extra logic that can occur when an end-of-symbol condition is triggered.

Definition at line 74 of file dmtxencodescheme.c.

◆ CHKSIZE

#define CHKSIZE
Value:
{ \
if (sizeIdx == DmtxUndefined) { \
streamMarkInvalid(stream, DmtxErrorUnknown); \
return; \
} \
}
#define DmtxUndefined
Definition dmtx.h:40
@ DmtxErrorUnknown
Definition dmtxstatic.h:394

Definition at line 91 of file dmtxencodescheme.c.

Function Documentation

◆ encodeChangeScheme()

static void encodeChangeScheme ( DmtxEncodeStream * stream,
DmtxScheme targetScheme,
int unlatchType )
static

Definition at line 196 of file dmtxencodescheme.c.

◆ encodeNextChunk()

static void encodeNextChunk ( DmtxEncodeStream * stream,
int scheme,
int option,
int sizeIdxRequest )
static

This function distributes work to the equivalent scheme-specific implementation.

Each of these functions will encode the next symbol input word, and in some cases this requires additional input words to be encoded as well.

Definition at line 137 of file dmtxencodescheme.c.

◆ encodeSingleScheme()

static int encodeSingleScheme ( DmtxByteList * input,
DmtxByteList * output,
int sizeIdxRequest,
DmtxScheme scheme,
int fnc1 )
static

Definition at line 103 of file dmtxencodescheme.c.

◆ getRemainingSymbolCapacity()

static int getRemainingSymbolCapacity ( int outputLength,
int sizeIdx )
static

Definition at line 270 of file dmtxencodescheme.c.