GS1 Barcode Engine
Library for encoding GS1 barcodes and processing Application Identifier data
|
GS1 Barcode Engine
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
The GS1 Barcode Engine provides routines to generate GS1 barcode symbols, process GS1 Digital Link and GS1 AI syntax data provided in raw or human-friendly formats, and process the scan data received from barcode readers.
The symbologies supported by this library are:
The encoder implementations are intended for use with GS1 standards and applications and do not contain additional features that might be required for more general use.
Within the GS1 Application Identifier system, structured data is represented in different formats depending upon the context.
The data formats supported by this library are:
This following diagram shows how the library can be used for processing and transformation of GS1 data, indicating which formats are accepted as input, how barcode message data is generated and AI data extracted from the provided input data, and how the given data can be output in various formats.
Data transformation: Inputs, outputs and buffers |
---|
The barcode input data can either be received from a string buffer or read from a file. The barcode symbols be written to a BMP or TIFF file, or accessed by a buffer in either graphical format or as an array of strings.
This example use of the library shows how to write the generated barcode image directly to a file:
Another is to capture the graphical output into a buffer or extract the image as a set of strings that can be processed by the application:
Most of the setter and action functions of this library return a boolean indicating whether the function was successful and write an error message that can be accessed with gs1_encoder_getErrMsg() in the event of failure. The example code above should be extended to check the return status of each function when used in production code.
This library generates bitmaps of barcode symbols ready for users of the library to render using whatever display or printing technology is available in their environment.
This library does not attempt to interface directly with any specific technology because the number of scenarios is too numerous and the library is not being provided by GS1 AISBL as a turnkey end-user product. Furthermore, the intent is to maintain the portability of this library by avoiding build time and runtime dependancies on other libraries.
The library provides two image scaling models:
By default, this library creates output that has no regard for real world dimensions. The "PixMult" property is set to 1, which means that each symbol module (narrowest bar or smallest square) is represented by one pixel.
The user can set PixMult to any integer scale factor to increase the size of the barcode symbol. Note that a pixel is the "atom" of an digital image and as such there is no realisation of a partial pixel. This has the effect of increasing the output bitmap in quantums which ensures the stability of the relative module sizes in the image.
This scaling system is most useful when the barcode is intended to be presented on graphical systems where the precise pitch of the display medium is unknown or cannot be controlled, for example when rendering to multiple different smartphone displays in open applications.
In systems where the end device resolution is known with certainty the library allows the user to specify this resolution and to provide a target X-dimension size (including optional minimum and maximum permissible limits) in terms of real world dimensions such as mm or inches.
This has the effect of automatically selecting a "PixMult" (bitmap pixels per module) that would most closely achieve the specified X-dimension within the provided constraints, when printed at exactly one device dot per bitmap pixel on a device with the specified resolutions. The library will report what X-dimension, if any, has actually been achieved to satisfy the given constraints.
It is the user's responsiblity to report the device resolution accurately and to ensure that the integrity of the graphical output from this library is maintained all the way through to the finished result. Specifically, that each source pixel is represented uniquely by a single output device dot in order for the actual X-dimension of the printed image to be correct.
Typedefs | |
typedef struct gs1_encoder | gs1_encoder |
A gs1_encoder context. More... | |
Functions | |
GS1_ENCODERS_API char * | gs1_encoder_getVersion (void) |
Get the version string of the library. More... | |
GS1_ENCODERS_API size_t | gs1_encoder_instanceSize (void) |
Find the memory storage requirements for an instance of gs1_encoder. More... | |
GS1_ENCODERS_API int | gs1_encoder_getMaxFilenameLength (void) |
Get the maximum filename length that can be used for input and output. More... | |
GS1_ENCODERS_API int | gs1_encoder_getMaxDataStrLength (void) |
Get the maximum size of the input data buffer for barcode message content. More... | |
GS1_ENCODERS_API int | gs1_encoder_getMaxPixMult (void) |
Get the maximum X-dimension in pixels. More... | |
GS1_ENCODERS_API int | gs1_encoder_getMaxGS1_128LinearHeight (void) |
Get the maximum height of GS1-128 linear symbols in modules. More... | |
GS1_ENCODERS_API gs1_encoder * | gs1_encoder_init (void *mem) |
Initialise a new gs1_encoder context. More... | |
GS1_ENCODERS_API char * | gs1_encoder_getErrMsg (gs1_encoder *ctx) |
Read an error message generated by the library. More... | |
GS1_ENCODERS_API int | gs1_encoder_getSym (gs1_encoder *ctx) |
Get the current symbology type. More... | |
GS1_ENCODERS_API bool | gs1_encoder_setSym (gs1_encoder *ctx, int sym) |
Set the symbology type. More... | |
GS1_ENCODERS_API int | gs1_encoder_getPixMult (gs1_encoder *ctx) |
Get the current device dots per module. More... | |
GS1_ENCODERS_API bool | gs1_encoder_setPixMult (gs1_encoder *ctx, int pixMult) |
Set the device dots per module. More... | |
GS1_ENCODERS_API double | gs1_encoder_getDeviceResolution (gs1_encoder *ctx) |
Get the specified device resolution. More... | |
GS1_ENCODERS_API bool | gs1_encoder_setDeviceResolution (gs1_encoder *ctx, double resolution) |
Set the device resolution. More... | |
GS1_ENCODERS_API bool | gs1_encoder_setXdimension (gs1_encoder *ctx, double min, double target, double max) |
Set the constraints for the X-dimension width. More... | |
GS1_ENCODERS_API double | gs1_encoder_getMinXdimension (gs1_encoder *ctx) |
Get the current minimum permissible X-dimension. More... | |
GS1_ENCODERS_API double | gs1_encoder_getMaxXdimension (gs1_encoder *ctx) |
Get the current maximum permissible X-dimension. More... | |
GS1_ENCODERS_API double | gs1_encoder_getTargetXdimension (gs1_encoder *ctx) |
Get the current target X-dimension specified by the user. More... | |
GS1_ENCODERS_API double | gs1_encoder_getActualXdimension (gs1_encoder *ctx) |
Get the actual X-dimension that can be achieved on the device. More... | |
GS1_ENCODERS_API int | gs1_encoder_getXundercut (gs1_encoder *ctx) |
Get the current X undercut. More... | |
GS1_ENCODERS_API bool | gs1_encoder_setXundercut (gs1_encoder *ctx, int Xundercut) |
Set the X undercut. More... | |
GS1_ENCODERS_API int | gs1_encoder_getYundercut (gs1_encoder *ctx) |
Get the current Y undercut. More... | |
GS1_ENCODERS_API bool | gs1_encoder_setYundercut (gs1_encoder *ctx, int Yundercut) |
Set the Y undercut. More... | |
GS1_ENCODERS_API int | gs1_encoder_getSepHt (gs1_encoder *ctx) |
Get the current separator height between linear and 2D components. More... | |
GS1_ENCODERS_API bool | gs1_encoder_setSepHt (gs1_encoder *ctx, int sepHt) |
Set the separator height between linear and 2D components. More... | |
GS1_ENCODERS_API int | gs1_encoder_getDataBarExpandedSegmentsWidth (gs1_encoder *ctx) |
Get the current number of segments per row for GS1 DataBar Expanded Stacked symbols. More... | |
GS1_ENCODERS_API bool | gs1_encoder_setDataBarExpandedSegmentsWidth (gs1_encoder *ctx, int dataBarExpandedSegmentsWidth) |
Set the number of segments per row for GS1 DataBar Expanded Stacked symbols. More... | |
GS1_ENCODERS_API int | gs1_encoder_getGS1_128LinearHeight (gs1_encoder *ctx) |
Get the height of GS1-128 linear symbols in modules. More... | |
GS1_ENCODERS_API bool | gs1_encoder_setGS1_128LinearHeight (gs1_encoder *ctx, int gs1_128LinearHeight) |
Set the height of GS1-128 linear symbols in modules. More... | |
GS1_ENCODERS_API int | gs1_encoder_getDmRows (gs1_encoder *ctx) |
Get the current fixed number of rows for Data Matrix symbols. More... | |
GS1_ENCODERS_API bool | gs1_encoder_setDmRows (gs1_encoder *ctx, int rows) |
Set a fixed number of rows for Data Matrix symbols. More... | |
GS1_ENCODERS_API int | gs1_encoder_getDmColumns (gs1_encoder *ctx) |
Get the current fixed number of columns for Data Matrix symbols. More... | |
GS1_ENCODERS_API bool | gs1_encoder_setDmColumns (gs1_encoder *ctx, int columns) |
Set a fixed number of columns for Data Matrix symbols. More... | |
GS1_ENCODERS_API int | gs1_encoder_getQrVersion (gs1_encoder *ctx) |
Get the current fixed version number for QR Code symbols. More... | |
GS1_ENCODERS_API bool | gs1_encoder_setQrVersion (gs1_encoder *ctx, int version) |
Set a fixed version number for QR Code symbols. More... | |
GS1_ENCODERS_API int | gs1_encoder_getQrEClevel (gs1_encoder *ctx) |
Get the current error correction level for QR Code symbols. More... | |
GS1_ENCODERS_API bool | gs1_encoder_setQrEClevel (gs1_encoder *ctx, int ecLevel) |
Set the error correction level for QR Code symbols. More... | |
GS1_ENCODERS_API bool | gs1_encoder_getAddCheckDigit (gs1_encoder *ctx) |
Get the current status of the "add check digit" mode. More... | |
GS1_ENCODERS_API bool | gs1_encoder_setAddCheckDigit (gs1_encoder *ctx, bool addCheckDigit) |
Enable or disable "add check digit" mode for EAN/UPC and GS1 DataBar symbols. More... | |
GS1_ENCODERS_API bool | gs1_encoder_getPermitUnknownAIs (gs1_encoder *ctx) |
Get the current status of the "permit unknown AIs" mode. More... | |
GS1_ENCODERS_API bool | gs1_encoder_setPermitUnknownAIs (gs1_encoder *ctx, bool permitUnknownAIs) |
Enable or disable "permit unknown AIs" mode for parsing of bracketed AI element strings and Digital Link URIs. More... | |
GS1_ENCODERS_API bool | gs1_encoder_getFileInputFlag (gs1_encoder *ctx) |
Indicates whether barcode data input is currently taken from a buffer or a file. More... | |
GS1_ENCODERS_API bool | gs1_encoder_setFileInputFlag (gs1_encoder *ctx, bool fileInputFlag) |
Selects between a file and buffer for barcode data input. symbols. More... | |
GS1_ENCODERS_API char * | gs1_encoder_getDataStr (gs1_encoder *ctx) |
Reads the raw barcode data input buffer. More... | |
GS1_ENCODERS_API bool | gs1_encoder_setDataStr (gs1_encoder *ctx, const char *dataStr) |
Sets the raw data in the buffer that is to be directly encoded within a barcode symbol when buffer input is selected. More... | |
GS1_ENCODERS_API bool | gs1_encoder_setAIdataStr (gs1_encoder *ctx, const char *dataStr) |
Sets the data in the buffer that is used when buffer input is selected by parsing input provided in GS1 Application Identifier syntax into a raw data string. More... | |
GS1_ENCODERS_API char * | gs1_encoder_getAIdataStr (gs1_encoder *ctx) |
Return the barcode input data buffer in human-friendly AI syntax. More... | |
GS1_ENCODERS_API bool | gs1_encoder_setScanData (gs1_encoder *ctx, const char *scanData) |
Process scan data received from a barcode reader with reporting of AIM symbology identifiers enabled to extract the message data and perform syntax checks in the case of GS1 Digital Link and AI data input. More... | |
GS1_ENCODERS_API char * | gs1_encoder_getScanData (gs1_encoder *ctx) |
Returns the string that should be returned by scanners when reading a symbol that is an instance of the selected symbology and contains the input data. More... | |
GS1_ENCODERS_API int | gs1_encoder_getHRI (gs1_encoder *ctx, char ***hri) |
Update a given pointer towards an array of strings containing Human-Readable Interpretation ("HRI") text. More... | |
GS1_ENCODERS_API size_t | gs1_encoder_getHRIsize (gs1_encoder *ctx) |
Get the require HRI buffer size. More... | |
GS1_ENCODERS_API void | gs1_encoder_copyHRI (gs1_encoder *ctx, void *buf, size_t max) |
Copy the HRI to a user-provided buffer in the form of a "|"-separated string. More... | |
GS1_ENCODERS_API char * | gs1_encoder_getDataFile (gs1_encoder *ctx) |
Gets the filename for a file containing the barcode data when file input is selected. More... | |
GS1_ENCODERS_API bool | gs1_encoder_setDataFile (gs1_encoder *ctx, const char *dataFile) |
Sets the filename for a file from which barcode data is read when file input is selected. More... | |
GS1_ENCODERS_API int | gs1_encoder_getFormat (gs1_encoder *ctx) |
Get the current output format type. More... | |
GS1_ENCODERS_API bool | gs1_encoder_setFormat (gs1_encoder *ctx, int format) |
Set the output format for the barcode symbol. More... | |
GS1_ENCODERS_API char * | gs1_encoder_getOutFile (gs1_encoder *ctx) |
Get the current output filename. More... | |
GS1_ENCODERS_API bool | gs1_encoder_setOutFile (gs1_encoder *ctx, const char *outFile) |
Set the output file for the barcode symbol. More... | |
GS1_ENCODERS_API bool | gs1_encoder_encode (gs1_encoder *ctx) |
Generate a barcode symbol representing the given input data. More... | |
GS1_ENCODERS_API size_t | gs1_encoder_getBuffer (gs1_encoder *ctx, void **buffer) |
Get the output buffer. More... | |
GS1_ENCODERS_API size_t | gs1_encoder_getBufferSize (gs1_encoder *ctx) |
Get the required output buffer size. More... | |
GS1_ENCODERS_API size_t | gs1_encoder_copyOutputBuffer (gs1_encoder *ctx, void *buffer, size_t max) |
Copy the output buffer to a user-provided buffer. More... | |
GS1_ENCODERS_API int | gs1_encoder_getBufferWidth (gs1_encoder *ctx) |
Get the number of columns in the output buffer image. More... | |
GS1_ENCODERS_API int | gs1_encoder_getBufferHeight (gs1_encoder *ctx) |
Get the number of rows in the output buffer image. More... | |
GS1_ENCODERS_API size_t | gs1_encoder_getBufferStrings (gs1_encoder *ctx, char ***strings) |
Return the output buffer represented as an array of strings. More... | |
GS1_ENCODERS_API void | gs1_encoder_free (gs1_encoder *ctx) |
Destroy a gs1_encoder instance. More... | |
typedef struct gs1_encoder gs1_encoder |
A gs1_encoder context.
This is an opaque struct that represents an instance of the library.
This context maintains all state required for an instance. Any number of instances of the library can be created, each operating seperately and equivalently to the others.
This library does not introduce any global variables. All runtime state is maintained in instances of the gs1_encoder struct and this state should only be modified using the public API functions provided by this library, decorated with GS1_ENCODERS_API.
A context is created by calling gs1_encoder_init() and destroyed by calling gs1_encoder_free(), releasing all of the storage allocated by the library for that instance.
The Data Matrix symbols may only be generated with a specific number of columns.
enum gs1_encoder_dmRows |
The Data Matrix symbols may only be generated with a specific number of rows.
enum gs1_encoder_formats |
The QR Code symbology supports several error correction levels which allow differing amount of unreadable data to be reconstructed.
The QR Code symbology supports several versions that specify the size of the symbol.
All of the major GS1 barcode formats ("symbologies") are supported by this library.
GS1_ENCODERS_API void gs1_encoder_copyHRI | ( | gs1_encoder * | ctx, |
void * | buf, | ||
size_t | max | ||
) |
Copy the HRI to a user-provided buffer in the form of a "|"-separated string.
The buffer into which the output buffer is copied must be preallocated with at least the size returned by gs1_encoder_getHRIsize().
[in,out] | ctx | gs1_encoder context |
[out] | buf | a pointer to a buffer into which the formatted HRI text is copied |
[in] | max | the maximum number of bytes that may be copied into the provided buffer |
GS1_ENCODERS_API size_t gs1_encoder_copyOutputBuffer | ( | gs1_encoder * | ctx, |
void * | buffer, | ||
size_t | max | ||
) |
Copy the output buffer to a user-provided buffer.
The buffer into which the output buffer is copied must be preallocated with at least the size returned by gs1_encoder_getBufferSize().
[in,out] | ctx | gs1_encoder context |
[out] | buffer | a pointer to a buffer into which the output buffer is copied |
[in] | max | the maximum number of bytes that may be copied into the provided buffer |
GS1_ENCODERS_API bool gs1_encoder_encode | ( | gs1_encoder * | ctx | ) |
Generate a barcode symbol representing the given input data.
This will create a barcode image for the symbology specified by gs1_encoder_setSym() containing the data provided by gs1_encoder_setDataStr() or gs1_encoder_setAIdataStr().
If the input is valid for the selected symbology then the image output will be written to the output file specified by gs1_encoder_setOutFile(), or to the output buffer if the output filename is empty, in the format specified by gs1_encoder_setFormat().
ctx | gs1_encoder context. |
GS1_ENCODERS_API void gs1_encoder_free | ( | gs1_encoder * | ctx | ) |
Destroy a gs1_encoder instance.
This will release all library-managed storage associated with the instance.
[in,out] | ctx | gs1_encoder context to destroy |
GS1_ENCODERS_API double gs1_encoder_getActualXdimension | ( | gs1_encoder * | ctx | ) |
Get the actual X-dimension that can be achieved on the device.
This returns the actual X-dimension that can be achieved based on the device resolution specified by gs1_encoder_setDeviceResolution() and the current number of pixels per module.
It likely differs from the target X-dimension but is guaranteed not to exceed any minimum and maximum X-dimension specified using gs1_encoder_setXdimension().
[in,out] | ctx | gs1_encoder context |
GS1_ENCODERS_API bool gs1_encoder_getAddCheckDigit | ( | gs1_encoder * | ctx | ) |
Get the current status of the "add check digit" mode.
[in,out] | ctx | gs1_encoder context |
GS1_ENCODERS_API char* gs1_encoder_getAIdataStr | ( | gs1_encoder * | ctx | ) |
Return the barcode input data buffer in human-friendly AI syntax.
For example, if the input data buffer were to contain:
^011231231231233310ABC123|^99XYZ(TM) CORP
Then this function would return:
(01)12312312312333(10)ABC123|(99)XYZ\(TM) CORP
[in,out] | ctx | gs1_encoder context |
GS1_ENCODERS_API size_t gs1_encoder_getBuffer | ( | gs1_encoder * | ctx, |
void ** | buffer | ||
) |
Get the output buffer.
[in,out] | ctx | gs1_encoder context |
[out] | buffer | a pointer to the buffer |
GS1_ENCODERS_API int gs1_encoder_getBufferHeight | ( | gs1_encoder * | ctx | ) |
Get the number of rows in the output buffer image.
[in,out] | ctx | gs1_encoder context |
GS1_ENCODERS_API size_t gs1_encoder_getBufferSize | ( | gs1_encoder * | ctx | ) |
Get the required output buffer size.
[in,out] | ctx | gs1_encoder context |
GS1_ENCODERS_API size_t gs1_encoder_getBufferStrings | ( | gs1_encoder * | ctx, |
char *** | strings | ||
) |
Return the output buffer represented as an array of strings.
Example output:
[in,out] | ctx | gs1_encoder context |
[out] | strings | the value of the given pointer is rewritten to point to an array of strings |
GS1_ENCODERS_API int gs1_encoder_getBufferWidth | ( | gs1_encoder * | ctx | ) |
Get the number of columns in the output buffer image.
[in,out] | ctx | gs1_encoder context |
GS1_ENCODERS_API int gs1_encoder_getDataBarExpandedSegmentsWidth | ( | gs1_encoder * | ctx | ) |
Get the current number of segments per row for GS1 DataBar Expanded Stacked symbols.
[in,out] | ctx | gs1_encoder context |
GS1_ENCODERS_API char* gs1_encoder_getDataFile | ( | gs1_encoder * | ctx | ) |
Gets the filename for a file containing the barcode data when file input is selected.
[in,out] | ctx | gs1_encoder context |
GS1_ENCODERS_API char* gs1_encoder_getDataStr | ( | gs1_encoder * | ctx | ) |
Reads the raw barcode data input buffer.
[in,out] | ctx | gs1_encoder context |
GS1_ENCODERS_API double gs1_encoder_getDeviceResolution | ( | gs1_encoder * | ctx | ) |
Get the specified device resolution.
This is the value specified by the user using gs1_encoder_setDeviceResolution().
[in,out] | ctx | gs1_encoder context |
GS1_ENCODERS_API int gs1_encoder_getDmColumns | ( | gs1_encoder * | ctx | ) |
Get the current fixed number of columns for Data Matrix symbols.
[in,out] | ctx | gs1_encoder context |
GS1_ENCODERS_API int gs1_encoder_getDmRows | ( | gs1_encoder * | ctx | ) |
Get the current fixed number of rows for Data Matrix symbols.
[in,out] | ctx | gs1_encoder context |
GS1_ENCODERS_API char* gs1_encoder_getErrMsg | ( | gs1_encoder * | ctx | ) |
Read an error message generated by the library.
When any of the setter functions of this library or gs1_encoder_encode() returns false (indicating an error), a human-friendly error message is generated which can be read using this function.
[in,out] | ctx | gs1_encoder context |
GS1_ENCODERS_API bool gs1_encoder_getFileInputFlag | ( | gs1_encoder * | ctx | ) |
Indicates whether barcode data input is currently taken from a buffer or a file.
[in,out] | ctx | gs1_encoder context |
GS1_ENCODERS_API int gs1_encoder_getFormat | ( | gs1_encoder * | ctx | ) |
Get the current output format type.
[in,out] | ctx | gs1_encoder context |
GS1_ENCODERS_API int gs1_encoder_getGS1_128LinearHeight | ( | gs1_encoder * | ctx | ) |
Get the height of GS1-128 linear symbols in modules.
[in,out] | ctx | gs1_encoder context |
GS1_ENCODERS_API int gs1_encoder_getHRI | ( | gs1_encoder * | ctx, |
char *** | hri | ||
) |
Update a given pointer towards an array of strings containing Human-Readable Interpretation ("HRI") text.
For example, if the input data buffer were to contain:
^011231231231233310ABC123|^99XYZ(TM) CORP
Then this function would return the following array of null-terminated strings:
"(01) 12312312312333" "(10) ABC123" "--" "(99) XYZ(TM) CORP"
[in,out] | ctx | gs1_encoder context |
[out] | hri | Pointer to an array of HRI strings |
GS1_ENCODERS_API size_t gs1_encoder_getHRIsize | ( | gs1_encoder * | ctx | ) |
Get the require HRI buffer size.
[in,out] | ctx | gs1_encoder context |
GS1_ENCODERS_API int gs1_encoder_getMaxDataStrLength | ( | void | ) |
Get the maximum size of the input data buffer for barcode message content.
This is an implementation limit that may be lowered for systems with limited memory by rebuilding the library.
GS1_ENCODERS_API int gs1_encoder_getMaxFilenameLength | ( | void | ) |
Get the maximum filename length that can be used for input and output.
This is an implementation limit that may be lowered for systems with limited memory by rebuilding the library.
GS1_ENCODERS_API int gs1_encoder_getMaxGS1_128LinearHeight | ( | void | ) |
Get the maximum height of GS1-128 linear symbols in modules.
This is an implementation limit that may be lowered for systems with limited memory by rebuilding the library.
GS1_ENCODERS_API int gs1_encoder_getMaxPixMult | ( | void | ) |
Get the maximum X-dimension in pixels.
This is an implementation limit that may be lowered for systems with limited memory by rebuilding the library.
GS1_ENCODERS_API double gs1_encoder_getMaxXdimension | ( | gs1_encoder * | ctx | ) |
Get the current maximum permissible X-dimension.
This is the value specified by the user using gs1_encoder_setXdimension().
[in,out] | ctx | gs1_encoder context |
GS1_ENCODERS_API double gs1_encoder_getMinXdimension | ( | gs1_encoder * | ctx | ) |
Get the current minimum permissible X-dimension.
This is the value specified by the user using gs1_encoder_setXdimension().
[in,out] | ctx | gs1_encoder context |
GS1_ENCODERS_API char* gs1_encoder_getOutFile | ( | gs1_encoder * | ctx | ) |
Get the current output filename.
[in,out] | ctx | gs1_encoder context |
GS1_ENCODERS_API bool gs1_encoder_getPermitUnknownAIs | ( | gs1_encoder * | ctx | ) |
Get the current status of the "permit unknown AIs" mode.
[in,out] | ctx | gs1_encoder context |
GS1_ENCODERS_API int gs1_encoder_getPixMult | ( | gs1_encoder * | ctx | ) |
Get the current device dots per module.
[in,out] | ctx | gs1_encoder context |
GS1_ENCODERS_API int gs1_encoder_getQrEClevel | ( | gs1_encoder * | ctx | ) |
Get the current error correction level for QR Code symbols.
[in,out] | ctx | gs1_encoder context |
GS1_ENCODERS_API int gs1_encoder_getQrVersion | ( | gs1_encoder * | ctx | ) |
Get the current fixed version number for QR Code symbols.
[in,out] | ctx | gs1_encoder context |
GS1_ENCODERS_API char* gs1_encoder_getScanData | ( | gs1_encoder * | ctx | ) |
Returns the string that should be returned by scanners when reading a symbol that is an instance of the selected symbology and contains the input data.
Examples:
Symbology | Input data | Returned scan data |
---|---|---|
gs1_encoder_sEAN13 | 2112345678900 | ]E02112345678900 |
gs1_encoder_sUPCA | 416000336108 | ]E00416000336108 |
gs1_encoder_sEAN8 | 02345673 | ]E402345673 |
gs1_encoder_sEAN8 | 02345673|^99COMPOSITE^98XYZ | ]E402345673|]e099COMPOSITE{GS}98XYZ |
gs1_encoder_sGS1_128_CCA | ^011231231231233310ABC123^99TESTING | ]C1011231231231233310ABC123{GS}99TESTING |
gs1_encoder_sGS1_128_CCA | ^0112312312312333|^98COMPOSITE^97XYZ | ]e00112312312312333{GS}98COMPOSITE{GS}97XYZ |
gs1_encoder_sQR | https://example.org/01/12312312312333 | ]Q1https://example.org/01/12312312312333 |
gs1_encoder_sQR | ^01123123123123338200http://example.com | ]Q301123123123123338200http://example.com |
gs1_encoder_sDM | https://example.com/gtin/09506000134352/lot/A1 | ]d1https://example.com/gtin/09506000134352/lot/A1 |
gs1_encoder_sDM | ^011231231231233310ABC123^99TESTING | ]d2011231231231233310ABC123{GS}99TESTING |
The output will be prefixed with the appropriate AIM symbology identifier.
"{GS}" in the scan data output in the above table represents a literal GS character (ASCII 29) that is included in the returned data.
The literal "|" character included in the scan data output for EAN/UPC Composite symbols indicates the separation between the first and second messages that would be transmitted by a reader that is configured to return the composite component.
This example use of the library shows how to determine what data a scanner should provide when reading a certain symbol:
[in,out] | ctx | gs1_encoder context |
GS1_ENCODERS_API int gs1_encoder_getSepHt | ( | gs1_encoder * | ctx | ) |
Get the current separator height between linear and 2D components.
[in,out] | ctx | gs1_encoder context |
GS1_ENCODERS_API int gs1_encoder_getSym | ( | gs1_encoder * | ctx | ) |
Get the current symbology type.
[in,out] | ctx | gs1_encoder context |
GS1_ENCODERS_API double gs1_encoder_getTargetXdimension | ( | gs1_encoder * | ctx | ) |
Get the current target X-dimension specified by the user.
This is the value specified by the user using gs1_encoder_setXdimension(). It may differ from the actual X-dimension that has been achieved (based on the device resolution) which can be retrieved using gs1_encoder_getActualXdimension().
[in,out] | ctx | gs1_encoder context |
GS1_ENCODERS_API char* gs1_encoder_getVersion | ( | void | ) |
Get the version string of the library.
This is typically the build date.
The return data does not need to be free()ed.
GS1_ENCODERS_API int gs1_encoder_getXundercut | ( | gs1_encoder * | ctx | ) |
Get the current X undercut.
[in,out] | ctx | gs1_encoder context |
GS1_ENCODERS_API int gs1_encoder_getYundercut | ( | gs1_encoder * | ctx | ) |
Get the current Y undercut.
[in,out] | ctx | gs1_encoder context |
GS1_ENCODERS_API gs1_encoder* gs1_encoder_init | ( | void * | mem | ) |
Initialise a new gs1_encoder context.
If it expected that most users of the library will pass NULL to this function which causes the library will allocate its own storage.
If a pointer to a storage buffer is provided then this will be used instead, however this buffer must be sufficient for the needs of the instance as returned by gs1_encoder_instanceSize() and this buffer should not be reused or freed until gs1_encoder_free() is called.
[in,out] | mem | buffer to use for storage, or NULL for automatic allocation |
GS1_ENCODERS_API size_t gs1_encoder_instanceSize | ( | void | ) |
Find the memory storage requirements for an instance of gs1_encoder.
For embedded systems it may be desirable to provide a pre-allocated buffer to a new context for storage purposes, rather than to have the instance malloc() it's own storage. This may avoid problems such as heap fragmentation on systems with a poor memory allocator or a restricted working set size.
This function returns the minimum size required for such a buffer.
Example of a user of the library allocating its own heap storage:
Example of a user of the library using static storage allocated at compile time:
GS1_ENCODERS_API bool gs1_encoder_setAddCheckDigit | ( | gs1_encoder * | ctx, |
bool | addCheckDigit | ||
) |
Enable or disable "add check digit" mode for EAN/UPC and GS1 DataBar symbols.
[in,out] | ctx | gs1_encoder context |
[in] | addCheckDigit | enabled if true; disabled if false |
GS1_ENCODERS_API bool gs1_encoder_setAIdataStr | ( | gs1_encoder * | ctx, |
const char * | dataStr | ||
) |
Sets the data in the buffer that is used when buffer input is selected by parsing input provided in GS1 Application Identifier syntax into a raw data string.
The input is provided in human-friendly format without FNC1 characters which are inserted automatically, for example:
This syntax harmonises the format for the input accepted by all symbologies. For example the following input is acceptable for EAN-13, UPC-A, UPC-E, any variant of the GS1 DataBar family, GS1 QR Code and GS1 DataMatrix:
The input is immediately parsed and validated against certain rules for GS1 AIs, after which the resulting encoding for valid inputs is available via gs1_encoder_getDataStr(). If the input is invalid then this function will return false and an error message will be set that can be read using gs1_encoder_getErrMsg().
Any "(" characters in AI element values must be escaped as "\(" to avoid conflating them with the start of the next AI.
For symbologies that support a composite component (all except gs1_encoder_sDM and gs1_encoder_sQR), the data for the linear and 2D components can be separated by a "|" character, for example:
[in,out] | ctx | gs1_encoder context |
[in] | dataStr | the barcode input data in GS1 Application Identifier syntax |
GS1_ENCODERS_API bool gs1_encoder_setDataBarExpandedSegmentsWidth | ( | gs1_encoder * | ctx, |
int | dataBarExpandedSegmentsWidth | ||
) |
Set the number of segments per row for GS1 DataBar Expanded Stacked symbols.
The default number of segments per row (22) matches the maximum number of symbol character for GS1 DataBar Expanded, resulting in a non-stacked symbol.
[in,out] | ctx | gs1_encoder context |
[in] | dataBarExpandedSegmentsWidth | segments per row |
GS1_ENCODERS_API bool gs1_encoder_setDataFile | ( | gs1_encoder * | ctx, |
const char * | dataFile | ||
) |
Sets the filename for a file from which barcode data is read when file input is selected.
[in,out] | ctx | gs1_encoder context |
[in] | dataFile | the data input filename |
GS1_ENCODERS_API bool gs1_encoder_setDataStr | ( | gs1_encoder * | ctx, |
const char * | dataStr | ||
) |
Sets the raw data in the buffer that is to be directly encoded within a barcode symbol when buffer input is selected.
Each encoder accepts input in a format that is specific to the requirements of the symbology, as described below. Some accept "plain" data input such as a 13-character GTIN in the case of EAN-13. Some require AI syntax data such as the GS1 DataBar family. Others accept either an AI string or a GS1 Digital Link URI, such as QR Code and Data Matrix.
A "^" character at the start of the input indicates that the data is in GS1 Application Identifier syntax. In this case, all subsequent instances of the "^" character represent the FNC1 non-data characters that are used to separate fields that are not specified as being pre-defined length from subsequent fields.
Inputs beginning with "^" will be validated against certain data syntax rules for GS1 AIs. If the input is invalid then this function will return false and an error message will be set that can be read using gs1_encoder_getErrMsg().
It is strongly advised that GS1 data input is instead specified using gs1_encoder_setAIdataStr() which takes care of the AI encoding rules automatically, including insertion of FNC1 characters where required. This can be used for all symbologies that accept GS1 AI syntax data.
Inputs beginning with "http://" or "https://" will be parsed as a Digital Link URI during which the corresponding AI element string is extracted and validated.
The acceptable data input varies between symbologies:
In the interest of data harmony, the EAN/UPC symbologies will additionally accept a GTIN input, such as (01)00000002345673 for EAN-8.
EAN/UPC, GS1 DataBar and GS1-128 support a Composite Component. The Composite Component must be specified in AI syntax. It must be separated from the primary linear components with a "|" character and begin with an FNC1 in first position, for example:
The above specifies a linear component representing "(01)12345678901231" together with a composite component representing "(10)ABC123(11)210630".
Again, for GS1 data it is simpler and less error prone to specify the input in human-friendly GS1 AI syntax using gs1_encoder_setAIdataStr().
[in,out] | ctx | gs1_encoder context |
[in] | dataStr | containing the raw barcode data |
GS1_ENCODERS_API bool gs1_encoder_setDeviceResolution | ( | gs1_encoder * | ctx, |
double | resolution | ||
) |
Set the device resolution.
Specifies the resolution (device dots per unit) of the output device on which the barcode is to be rendered.
This function is expected to be used along with gs1_encoder_setXdimension() to automatically set the device dots per module that would produce an image that most-closely matches the specified real-world dimensions when rendered on the device.
Calling this function will clear any existing X-dimension constraints, and therefore must be called before gs1_encoder_setXdimension().
[in,out] | ctx | gs1_encoder context |
[in] | resolution | device dots per unit |
GS1_ENCODERS_API bool gs1_encoder_setDmColumns | ( | gs1_encoder * | ctx, |
int | columns | ||
) |
Set a fixed number of columns for Data Matrix symbols.
[in,out] | ctx | gs1_encoder context |
[in] | columns | number of fixed columns, or 0 for automatic |
GS1_ENCODERS_API bool gs1_encoder_setDmRows | ( | gs1_encoder * | ctx, |
int | rows | ||
) |
Set a fixed number of rows for Data Matrix symbols.
[in,out] | ctx | gs1_encoder context |
[in] | rows | number of fixed rows, or 0 for automatic |
GS1_ENCODERS_API bool gs1_encoder_setFileInputFlag | ( | gs1_encoder * | ctx, |
bool | fileInputFlag | ||
) |
Selects between a file and buffer for barcode data input. symbols.
[in,out] | ctx | gs1_encoder context |
[in] | fileInputFlag | file input if true; buffer input if false |
GS1_ENCODERS_API bool gs1_encoder_setFormat | ( | gs1_encoder * | ctx, |
int | format | ||
) |
Set the output format for the barcode symbol.
This allows the output format to be specified as any one of the known gs1_encoder_formats:
[in,out] | ctx | gs1_encoder context |
[in] | format | output format, one of gs1_encoder_formats |
GS1_ENCODERS_API bool gs1_encoder_setGS1_128LinearHeight | ( | gs1_encoder * | ctx, |
int | gs1_128LinearHeight | ||
) |
Set the height of GS1-128 linear symbols in modules.
[in,out] | ctx | gs1_encoder context |
[in] | gs1_128LinearHeight | height in modules |
GS1_ENCODERS_API bool gs1_encoder_setOutFile | ( | gs1_encoder * | ctx, |
const char * | outFile | ||
) |
Set the output file for the barcode symbol.
The output will be written to the specified file in the format specified by gs1_encoder_setFormat().
If the filename is provided as the empty string then the output data will be stored in the output buffer which can be read using gs1_encoder_getBuffer() and gs1_encoder_getBufferStrings().
[in,out] | ctx | gs1_encoder context |
[in] | outFile | the output filename, or "" for buffer output |
GS1_ENCODERS_API bool gs1_encoder_setPermitUnknownAIs | ( | gs1_encoder * | ctx, |
bool | permitUnknownAIs | ||
) |
Enable or disable "permit unknown AIs" mode for parsing of bracketed AI element strings and Digital Link URIs.
[in,out] | ctx | gs1_encoder context |
[in] | permitUnknownAIs | enabled if true; disabled if false |
GS1_ENCODERS_API bool gs1_encoder_setPixMult | ( | gs1_encoder * | ctx, |
int | pixMult | ||
) |
Set the device dots per module.
Directly specifies the number of device pixels that shall compose a module within a barcode symbol. A module is defined to be the most narrow element: The shortest width bar for a linear symbology or the smallest square for a 2D symbology.
Valid options range from 1 up to the limit returned by gs1_encoder_getMaxPixMult().
Calling this function will clear any X-dimension constraints set by gs1_encoder_setXdimension().
[in,out] | ctx | gs1_encoder context |
[in] | pixMult | device dots per module |
GS1_ENCODERS_API bool gs1_encoder_setQrEClevel | ( | gs1_encoder * | ctx, |
int | ecLevel | ||
) |
Set the error correction level for QR Code symbols.
This determines what proportion of a symbols data can be reliably reconstructed if it is damaged.
Default is gs1_encoder_qrEClevelM
[in,out] | ctx | gs1_encoder context |
[in] | ecLevel | error correction level, one of gs1_encoder_qrEClevel |
GS1_ENCODERS_API bool gs1_encoder_setQrVersion | ( | gs1_encoder * | ctx, |
int | version | ||
) |
Set a fixed version number for QR Code symbols.
Default is gs1_encoder_qrVersionAutomatic
[in,out] | ctx | gs1_encoder context |
[in] | version | fixed version number, one of gs1_encoder_qrVersion |
GS1_ENCODERS_API bool gs1_encoder_setScanData | ( | gs1_encoder * | ctx, |
const char * | scanData | ||
) |
Process scan data received from a barcode reader with reporting of AIM symbology identifiers enabled to extract the message data and perform syntax checks in the case of GS1 Digital Link and AI data input.
This function will process scan data (such as the output of a barcode reader) and process the received data, setting the data input buffer to the message received and setting the selected symbology to something that is able to carry the received data.
A literal "|" character may be included in the scan data to indicates the separation between the first and second messages that would be transmitted by a reader that is configured to return the composite component when reading EAN/UPC symbols.
This example use of the library processes a given scan data string, which is assumed to represent AI data in this instance, and then renders the AI data in human-friendly format.
[in,out] | ctx | gs1_encoder context |
[in] | scanData | the scan data input as read by a reader with AIM symbology identifiers enabled |
GS1_ENCODERS_API bool gs1_encoder_setSepHt | ( | gs1_encoder * | ctx, |
int | sepHt | ||
) |
Set the separator height between linear and 2D components.
[in,out] | ctx | gs1_encoder context |
[in] | sepHt | in pixels |
GS1_ENCODERS_API bool gs1_encoder_setSym | ( | gs1_encoder * | ctx, |
int | sym | ||
) |
Set the symbology type.
This allows the symbology to be specified as any one of the known gs1_encoder_symbologies other than gs1_encoder_sNONE or gs1_encoder_sNUMSYMS.
[in,out] | ctx | gs1_encoder context |
[in] | sym | symbology type |
GS1_ENCODERS_API bool gs1_encoder_setXdimension | ( | gs1_encoder * | ctx, |
double | min, | ||
double | target, | ||
double | max | ||
) |
Set the constraints for the X-dimension width.
This function will automatically set the number of device dots per module that is required to produce symbols whose X-dimension most-closely meets the provided target X-dimension on a device whose resolution has been previously specified with gs1_encoder_setDeviceResolution(), without exceeding the optional constraints.
The following real-world dimensions are accepted:
When the minimum and/or maximum X-dimension is specified the chosen device dots per module is guaranteed to not exceed these constraints. With low-resolution devices and tight X-dimension tollerances it may not be possible to achieve an X-dimension that falls within the given constraints since modules must be composed of some whole number of device dots. Put another way, barcode images must be scaled in quantums of device dots to prevent unstable module widths due to pixel-grazing.
For example, it is not possible to generate linear symbols intended for general distribution, where the permissible X-dimension is restricted to 0.495 - 0.660mm, on a device whose resolution is 3 dots/mm since 1 device dot is 0.333mm and 2 device dots is 0.667mm. (Note that it is however possible to achieve an acceptable X-dimension on an even lower resolution, 2 dots/mm device since 1 device dot is 0.500mm, which demonstrates that care should exercised when selecting devices for a particular application.)
If the required X-dimension constraints can be achieved then the selected device dots per module can be obtained with gs1_encoder_getPixMult() and the actual X-dimension achieved can be obtained with gs1_encoder_getActualXdimension().
If it is not possible to achieve the given X-dimension then the function will produce an error and the device dots per module will be set to undefined (0).
[in,out] | ctx | gs1_encoder context |
[in] | min | minimum permissible X-dimension, or 0 for undefined |
[in] | target | target X-dimension |
[in] | max | maximum permissible X-dimension, or 0 for undefined |
GS1_ENCODERS_API bool gs1_encoder_setXundercut | ( | gs1_encoder * | ctx, |
int | Xundercut | ||
) |
Set the X undercut.
Compensate for horizontal print growth by shaving this number of pixels from both sides of each module.
[in,out] | ctx | gs1_encoder context |
[in] | Xundercut | in pixels |
GS1_ENCODERS_API bool gs1_encoder_setYundercut | ( | gs1_encoder * | ctx, |
int | Yundercut | ||
) |
Set the Y undercut.
Compensate for vertical print growth by shaving this number of pixels from the top and bottom of each module.
[in,out] | ctx | gs1_encoder context |
[in] | Yundercut | in pixels |