gpt4 book ai didi

algorithm - QR 编码器/解码器支持 GS1?

转载 作者:塔克拉玛干 更新时间:2023-11-03 02:55:58 27 4
gpt4 key购买 nike

很少有 QR 编码器/解码器(明确)支持所谓的 GS1 编码。 Zint是异常(exception)之一(在 QR 下选择 GS-1 数据模式),但它的许可证阻止我使用它。主要来自 Tec-It 的商业报价很昂贵,尤其是因为我对它们支持的所有其他类型的条形码都不感兴趣。

有没有一种方法可以在不更改其源代码的情况下向任何 QR 编码器/解码器添加 GS1 支持?例如,我可以应用某种算法将文本 GTIN AI 数据转换为兼容的二进制文件吗?我觉得应该是可以的,因为毕竟还是QR。请注意,我不是数据编码专家——我只是在寻找一种无需花大价钱就能处理此标准的方法。到目前为止,我找到了postscriptbarcode它确实支持它,并且似乎使用了自己的 QR 引擎,但输出质量一般,而且我的 PostScript 技能太有限,无法弄清楚算法。

最佳答案

只要库支持FNC1特殊字符的解码,就可以用来读取GS1码。 FNC1 字符不是数据流中的一个字节,而是更多的格式符号。

规范指出,前导 FNC1 字符用于识别 GS1 条形码,应解码为 "]d2" (GS1 DataMatrix),"]C1" (GS1-128)、"]e0"(GS1 DataBar 全向)或 "]Q3"(GS1 QR 码)。任何其他 FNC1 字符都应解码为 ASCII GS 字符(字节值 29)。

根据库的不同,前导 FNC1 可能丢失,或解码为 GS(不重要),或者嵌入的 FNC1 字符可能丢失(重要)。嵌入的 FNC1 字符用于分隔可变长度字段。

您可以阅读完整的规范 here (PDF)。可以在7.9 使用 GS1 应用程序标识符从 GS1 符号系统处理数据(第 426 页)标题下找到用于解码数据的算法。

算法是这样的:

Peek at the first character.
If it is ']',
If string does not start with ']C1' or ']e0' or ']d2' or ']Q3',
Not a GS1 barcode.
Stop.
Consume the caracters.
Else if it is <GS>,
Consume character.
Else,
No symbology identifier, assume GS1.
While not end of input,
Read the first two digits.
If they are in the table of valid codes,
Look up the length of the AI-code.
Read the rest of the code.
Look up the length of the field.
If it is variable-length,
Read until the next <FNC1> or <GS>.
Else,
Read the rest if the field.
Peek at the next character.
If it is <FNC1> or <GS>, consume it.
Save the read field.
Else,
Error: Invalid AI

QR 码中的二进制数据被编码为 4 位 token ,并嵌入了数据。

0111 -> Start Extended Channel Interpretation (ECI) Mode (special encodings).
0001, 0010, 0100, 1000 -> start numeric, alphanumeric, raw 8-bit, kanji encoded data.
0011 -> structured append (combine two or more QR Codes to one data-stream).
0101 -> FNC1 initial position.
1001 -> FNC1 other positions.
0000 -> End of stream (can be omitted if not enough space).

编码规范之后是数据长度,然后是实际数据。数据位的含义取决于所使用的编码。在数据 block 之间,您可以压缩 FNC1 字符。

不幸的是,二维码规范 ( ISO/IEC 18004 ) 需要花钱 (210 法郎)。不过,您可能会在网上找到一些盗版版本。

要创建 GS1 QR 码,您需要能够在数据中指定 FNC1 字符。该库应该识别“]Q3”前缀和 GS 字符,或者允许您通过其他方法编写 FNC1 token 。

如果您有某种方式来编写 FNC1 字符,则可以按如下方式对 GS1 数据进行编码:

Write initial FNC1.
For each field,
Write the AI-code as decimal digits.
Write field data.
If the code is a variable-length field,
If not the last field,
Write FNC1 to terminate the field.

如果可能,您应该对字段进行排序,使可变长度字段排在最后。


正如 Terry Burton 在评论中指出的那样; GS1 QR Code 中的 FNC1 符号在字母数字数据中可以编码为 %,在字节模式中编码为 GS。要对实际百分比符号进行编码,请将其写为 %%

要对 (01) 04912345123459 (15) 970331 (30) 128 (10) ABC123 进行编码,首先将其组合成数据字符串 01049123451234591597033130128%10ABC123 (% 指标是编码后的 FNC1 符号)。这个字符串然后写成

0101 - Initial FNC1, GS1 mode indicator
0001 - QR numeric mode
0000011101 - Data length (29)
<data bits for "01049123451234591597033130128">
0010 - QR alphanumeric mode
000001001 - Data length (9)
<data bits for "%10ABC123">

(来自 ISO 18004:2006 规范的示例)

关于algorithm - QR 编码器/解码器支持 GS1?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13629555/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com