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
dmtxdecode.c File Reference

libdmtx - Data Matrix Encoding/Decoding Library Copyright 2008, 2009 Mike Laughton. More...

#include <assert.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "dmtx.h"
#include "dmtxstatic.h"

Go to the source code of this file.

Functions

DmtxDecodedmtxDecodeCreate (DmtxImage *img, int scale)
 Initialize decode struct with default values.
 
DmtxPassFail dmtxDecodeDestroy (DmtxDecode **dec)
 Deinitialize decode struct.
 
DmtxPassFail dmtxDecodeSetProp (DmtxDecode *dec, int prop, int value)
 Set decoding behavior property.
 
int dmtxDecodeGetProp (DmtxDecode *dec, int prop)
 Get decoding behavior property.
 
unsigned char * dmtxDecodeGetCache (DmtxDecode *dec, int x, int y)
 Returns xxx.
 
DmtxPassFail dmtxDecodeGetPixelValue (DmtxDecode *dec, int x, int y, int channel, OUT int *value)
 获取图像像素
 
static void cacheFillQuad (DmtxDecode *dec, DmtxPixelLoc p0, DmtxPixelLoc p1, DmtxPixelLoc p2, DmtxPixelLoc p3)
 Fill the region covered by the quadrilateral given by (p0,p1,p2,p3) in the cache.
 
DmtxMessagedmtxDecodeMatrixRegion (DmtxDecode *dec, DmtxRegion *reg, int fix)
 解码拟合的二维码区域
 
DmtxMessagedmtxDecodePopulatedArray (int sizeIdx, INOUT DmtxMessage *msg, int fix)
 从DataMatrix数据区二进制矩阵解码,并将结果写入msg->output
 
DmtxMessagedmtxDecodeMosaicRegion (DmtxDecode *dec, DmtxRegion *reg, int fix)
 Convert fitted Data Mosaic region into a decoded message.
 
unsigned char * dmtxDecodeCreateDiagnostic (DmtxDecode *dec, int *totalBytes, int *headerBytes, int style)
 
static void tallyModuleJumps (DmtxDecode *dec, DmtxRegion *reg, INOUT int tally[][24], int xOrigin, int yOrigin, int mapWidth, int mapHeight, DmtxDirection dir)
 通过指定方向对判断bit为1的码元位置记录对应的值
 
static DmtxPassFail populateArrayFromMatrix (DmtxDecode *dec, DmtxRegion *reg, OUT DmtxMessage *msg)
 根据模块颜色填充数组以确定码字值。
 

Detailed Description

libdmtx - Data Matrix Encoding/Decoding Library Copyright 2008, 2009 Mike Laughton.

All rights reserved. Copyright 2009 Mackenzie Straight. All rights reserved. Copyright 2012-2016 Vadim A. Misbakh-Soloviov. All rights reserved. Copyright 2016 Tim Zaman. 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

Decode regions

Definition in file dmtxdecode.c.

Function Documentation

◆ cacheFillQuad()

static void cacheFillQuad ( DmtxDecode * dec,
DmtxPixelLoc p0,
DmtxPixelLoc p1,
DmtxPixelLoc p2,
DmtxPixelLoc p3 )
static

Fill the region covered by the quadrilateral given by (p0,p1,p2,p3) in the cache.

Definition at line 272 of file dmtxdecode.c.

◆ dmtxDecodeCreate()

DmtxDecode * dmtxDecodeCreate ( DmtxImage * img,
int scale )
extern

Initialize decode struct with default values.

Returns
Initialized DmtxDecode struct

Definition at line 32 of file dmtxdecode.c.

◆ dmtxDecodeCreateDiagnostic()

unsigned char * dmtxDecodeCreateDiagnostic ( DmtxDecode * dec,
int * totalBytes,
int * headerBytes,
int style )
extern

Definition at line 499 of file dmtxdecode.c.

◆ dmtxDecodeDestroy()

DmtxPassFail dmtxDecodeDestroy ( DmtxDecode ** dec)
extern

Deinitialize decode struct.

Parameters
dec
Returns
void

Definition at line 77 of file dmtxdecode.c.

◆ dmtxDecodeGetCache()

unsigned char * dmtxDecodeGetCache ( DmtxDecode * dec,
int x,
int y )
extern

Returns xxx.

Parameters
dec
xScaled x coordinate
yScaled y coordinate
Returns
Scaled pixel offset

Definition at line 211 of file dmtxdecode.c.

◆ dmtxDecodeGetPixelValue()

DmtxPassFail dmtxDecodeGetPixelValue ( DmtxDecode * dec,
int x,
int y,
int channel,
OUT int * value )
extern

获取图像像素

Definition at line 233 of file dmtxdecode.c.

◆ dmtxDecodeGetProp()

int dmtxDecodeGetProp ( DmtxDecode * dec,
int prop )
extern

Get decoding behavior property.

Parameters
dec
prop
Returns
value

Definition at line 166 of file dmtxdecode.c.

◆ dmtxDecodeMatrixRegion()

DmtxMessage * dmtxDecodeMatrixRegion ( DmtxDecode * dec,
DmtxRegion * reg,
int fix )
extern

解码拟合的二维码区域

Definition at line 336 of file dmtxdecode.c.

◆ dmtxDecodeMosaicRegion()

DmtxMessage * dmtxDecodeMosaicRegion ( DmtxDecode * dec,
DmtxRegion * reg,
int fix )
extern

Convert fitted Data Mosaic region into a decoded message.

Parameters
dec
reg
fix
Returns
Decoded message

Consider performing a color cube fit here to identify exact RGB of all 6 "cube-like" corners based on pixels located within region. Then force each sample pixel to the "cube-like" corner based o which one is nearest "sqrt(dr^2+dg^2+db^2)" (except sqrt is unnecessary). colorPlane = reg->flowBegin.plane;

To find RGB values of primary colors, perform something like a histogram except instead of going from black to color N, go from (127,127,127) to color. Use color bins along with distance to identify value. An additional method will be required to get actual RGB instead of just a plane in 3D.

Definition at line 436 of file dmtxdecode.c.

◆ dmtxDecodePopulatedArray()

DmtxMessage * dmtxDecodePopulatedArray ( int sizeIdx,
INOUT DmtxMessage * msg,
int fix )

从DataMatrix数据区二进制矩阵解码,并将结果写入msg->output

Parameters
[in]sizeIdx数据矩阵的尺寸索引,对应不同的符号大小。
[in,out]msg已经填充模块状态的解码消息结构体实例。
[in]fix纠错级别指示符,指定解码时使用的错误纠正能力, 默认DmtxUndefined
Note
使用此函数时,应将msg变量重新赋值为该函数的返回值,因为当返回NULL时,表示msg已被释放,不应再被使用。 示例用法:msg = dmtxDecodePopulatedArray(sizeidx, msg, fix);

Definition at line 390 of file dmtxdecode.c.

◆ dmtxDecodeSetProp()

DmtxPassFail dmtxDecodeSetProp ( DmtxDecode * dec,
int prop,
int value )
extern

Set decoding behavior property.

Parameters
dec
prop
value
Returns
DmtxPass | DmtxFail

Definition at line 101 of file dmtxdecode.c.

◆ populateArrayFromMatrix()

static DmtxPassFail populateArrayFromMatrix ( DmtxDecode * dec,
DmtxRegion * reg,
OUT DmtxMessage * msg )
static

根据模块颜色填充数组以确定码字值。

此函数遍历数据矩阵的各个区域,统计每个模块的颜色跳变,以推断出每个模块是黑(代表1)还是白(代表0)。 这一过程对于解码数据矩阵中的信息至关重要。函数首先计算整个符号的区域数量、区域尺寸等关键属性, 然后根据模块颜色对比和累加的“跳跃”计数来确定每个模块的状态,最后更新消息数组以反映解码结果。

Parameters
[in]dec解码上下文,包含解码配置和辅助函数。
[in]reg当前处理的数据矩阵区域信息。
[out]msg根据图像更新array

从四个方向对图像满足跳变的点求和

对下面2x3的数据区域的计算流程: |XX | | XX XX|

首先 weightFactor = 2 * (2(高) + 3(宽) + 2) = 14

  1. 从下到上 2. 从右到左 3. 从上到下 4. 从左到右 |1x2 | |1x2 | |2x2 | |3x2 | | 2x2 2x2| | 2x2 3x2| | 1x2 1x2| | 2x2 1x2|

该方向上**判断为1**的码元位置记录值,记录的内容为 宽/高-码元位置坐标

对上面得到的4个矩阵求和可得: |14 | | 14 14|

Definition at line 705 of file dmtxdecode.c.

◆ tallyModuleJumps()

static void tallyModuleJumps ( DmtxDecode * dec,
DmtxRegion * reg,
INOUT int tally[][24],
int xOrigin,
int yOrigin,
int mapWidth,
int mapHeight,
DmtxDirection dir )
static

通过指定方向对判断bit为1的码元位置记录对应的值

此函数遍历数据矩阵区域中的模块,根据模块颜色跳变的阈值来累加计数器(tally), 以此推断模块的明暗状态(代表二进制值)。它支持向上、向下、向左、向右四个方向的遍历。

Parameters
[in]dec解码上下文,包含解码配置和辅助函数
[in]reg当前处理的数据矩阵区域信息
[in,out]tally二维数组,用于累加模块状态的计数
[in]xOrigin起始位置X坐标
[in]yOrigin起始位置Y坐标
[in]mapWidth单区块码元宽度
[in]mapHeight单区块码元高度
[in]dir遍历方向

Definition at line 596 of file dmtxdecode.c.