Mercurial > hgrepos > Python2 > PyMuPDF
comparison mupdf-source/thirdparty/zint/backend/imail.c @ 2:b50eed0cc0ef upstream
ADD: MuPDF v1.26.7: the MuPDF source as downloaded by a default build of PyMuPDF 1.26.4.
The directory name has changed: no version number in the expanded directory now.
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Mon, 15 Sep 2025 11:43:07 +0200 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 1:1d09e1dec1d9 | 2:b50eed0cc0ef |
|---|---|
| 1 /* imail.c - Handles Intelligent Mail (aka OneCode) for USPS */ | |
| 2 /* | |
| 3 libzint - the open source barcode library | |
| 4 Copyright (C) 2008-2024 Robin Stuart <rstuart114@gmail.com> | |
| 5 | |
| 6 Redistribution and use in source and binary forms, with or without | |
| 7 modification, are permitted provided that the following conditions | |
| 8 are met: | |
| 9 | |
| 10 1. Redistributions of source code must retain the above copyright | |
| 11 notice, this list of conditions and the following disclaimer. | |
| 12 2. Redistributions in binary form must reproduce the above copyright | |
| 13 notice, this list of conditions and the following disclaimer in the | |
| 14 documentation and/or other materials provided with the distribution. | |
| 15 3. Neither the name of the project nor the names of its contributors | |
| 16 may be used to endorse or promote products derived from this software | |
| 17 without specific prior written permission. | |
| 18 | |
| 19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | |
| 20 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
| 21 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
| 22 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE | |
| 23 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
| 24 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
| 25 OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
| 26 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
| 27 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
| 28 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
| 29 SUCH DAMAGE. | |
| 30 */ | |
| 31 /* SPDX-License-Identifier: BSD-3-Clause */ | |
| 32 | |
| 33 /* The function "USPS_MSB_Math_CRC11GenerateFrameCheckSequence" | |
| 34 is Copyright (C) 2006 United States Postal Service */ | |
| 35 | |
| 36 #include "common.h" | |
| 37 #include "large.h" | |
| 38 | |
| 39 #define SODIUM_MNS_F (IS_NUM_F | IS_MNS_F) /* SODIUM "0123456789-" */ | |
| 40 | |
| 41 /* The following lookup tables were generated using the code in Appendix C */ | |
| 42 | |
| 43 /* Appendix D Table 1 - 5 of 13 characters */ | |
| 44 static const unsigned short AppxD_I[1287] = { | |
| 45 0x001F, 0x1F00, 0x002F, 0x1E80, 0x0037, 0x1D80, 0x003B, 0x1B80, 0x003D, 0x1780, | |
| 46 0x003E, 0x0F80, 0x004F, 0x1E40, 0x0057, 0x1D40, 0x005B, 0x1B40, 0x005D, 0x1740, | |
| 47 0x005E, 0x0F40, 0x0067, 0x1CC0, 0x006B, 0x1AC0, 0x006D, 0x16C0, 0x006E, 0x0EC0, | |
| 48 0x0073, 0x19C0, 0x0075, 0x15C0, 0x0076, 0x0DC0, 0x0079, 0x13C0, 0x007A, 0x0BC0, | |
| 49 0x007C, 0x07C0, 0x008F, 0x1E20, 0x0097, 0x1D20, 0x009B, 0x1B20, 0x009D, 0x1720, | |
| 50 0x009E, 0x0F20, 0x00A7, 0x1CA0, 0x00AB, 0x1AA0, 0x00AD, 0x16A0, 0x00AE, 0x0EA0, | |
| 51 0x00B3, 0x19A0, 0x00B5, 0x15A0, 0x00B6, 0x0DA0, 0x00B9, 0x13A0, 0x00BA, 0x0BA0, | |
| 52 0x00BC, 0x07A0, 0x00C7, 0x1C60, 0x00CB, 0x1A60, 0x00CD, 0x1660, 0x00CE, 0x0E60, | |
| 53 0x00D3, 0x1960, 0x00D5, 0x1560, 0x00D6, 0x0D60, 0x00D9, 0x1360, 0x00DA, 0x0B60, | |
| 54 0x00DC, 0x0760, 0x00E3, 0x18E0, 0x00E5, 0x14E0, 0x00E6, 0x0CE0, 0x00E9, 0x12E0, | |
| 55 0x00EA, 0x0AE0, 0x00EC, 0x06E0, 0x00F1, 0x11E0, 0x00F2, 0x09E0, 0x00F4, 0x05E0, | |
| 56 0x00F8, 0x03E0, 0x010F, 0x1E10, 0x0117, 0x1D10, 0x011B, 0x1B10, 0x011D, 0x1710, | |
| 57 0x011E, 0x0F10, 0x0127, 0x1C90, 0x012B, 0x1A90, 0x012D, 0x1690, 0x012E, 0x0E90, | |
| 58 0x0133, 0x1990, 0x0135, 0x1590, 0x0136, 0x0D90, 0x0139, 0x1390, 0x013A, 0x0B90, | |
| 59 0x013C, 0x0790, 0x0147, 0x1C50, 0x014B, 0x1A50, 0x014D, 0x1650, 0x014E, 0x0E50, | |
| 60 0x0153, 0x1950, 0x0155, 0x1550, 0x0156, 0x0D50, 0x0159, 0x1350, 0x015A, 0x0B50, | |
| 61 0x015C, 0x0750, 0x0163, 0x18D0, 0x0165, 0x14D0, 0x0166, 0x0CD0, 0x0169, 0x12D0, | |
| 62 0x016A, 0x0AD0, 0x016C, 0x06D0, 0x0171, 0x11D0, 0x0172, 0x09D0, 0x0174, 0x05D0, | |
| 63 0x0178, 0x03D0, 0x0187, 0x1C30, 0x018B, 0x1A30, 0x018D, 0x1630, 0x018E, 0x0E30, | |
| 64 0x0193, 0x1930, 0x0195, 0x1530, 0x0196, 0x0D30, 0x0199, 0x1330, 0x019A, 0x0B30, | |
| 65 0x019C, 0x0730, 0x01A3, 0x18B0, 0x01A5, 0x14B0, 0x01A6, 0x0CB0, 0x01A9, 0x12B0, | |
| 66 0x01AA, 0x0AB0, 0x01AC, 0x06B0, 0x01B1, 0x11B0, 0x01B2, 0x09B0, 0x01B4, 0x05B0, | |
| 67 0x01B8, 0x03B0, 0x01C3, 0x1870, 0x01C5, 0x1470, 0x01C6, 0x0C70, 0x01C9, 0x1270, | |
| 68 0x01CA, 0x0A70, 0x01CC, 0x0670, 0x01D1, 0x1170, 0x01D2, 0x0970, 0x01D4, 0x0570, | |
| 69 0x01D8, 0x0370, 0x01E1, 0x10F0, 0x01E2, 0x08F0, 0x01E4, 0x04F0, 0x01E8, 0x02F0, | |
| 70 0x020F, 0x1E08, 0x0217, 0x1D08, 0x021B, 0x1B08, 0x021D, 0x1708, 0x021E, 0x0F08, | |
| 71 0x0227, 0x1C88, 0x022B, 0x1A88, 0x022D, 0x1688, 0x022E, 0x0E88, 0x0233, 0x1988, | |
| 72 0x0235, 0x1588, 0x0236, 0x0D88, 0x0239, 0x1388, 0x023A, 0x0B88, 0x023C, 0x0788, | |
| 73 0x0247, 0x1C48, 0x024B, 0x1A48, 0x024D, 0x1648, 0x024E, 0x0E48, 0x0253, 0x1948, | |
| 74 0x0255, 0x1548, 0x0256, 0x0D48, 0x0259, 0x1348, 0x025A, 0x0B48, 0x025C, 0x0748, | |
| 75 0x0263, 0x18C8, 0x0265, 0x14C8, 0x0266, 0x0CC8, 0x0269, 0x12C8, 0x026A, 0x0AC8, | |
| 76 0x026C, 0x06C8, 0x0271, 0x11C8, 0x0272, 0x09C8, 0x0274, 0x05C8, 0x0278, 0x03C8, | |
| 77 0x0287, 0x1C28, 0x028B, 0x1A28, 0x028D, 0x1628, 0x028E, 0x0E28, 0x0293, 0x1928, | |
| 78 0x0295, 0x1528, 0x0296, 0x0D28, 0x0299, 0x1328, 0x029A, 0x0B28, 0x029C, 0x0728, | |
| 79 0x02A3, 0x18A8, 0x02A5, 0x14A8, 0x02A6, 0x0CA8, 0x02A9, 0x12A8, 0x02AA, 0x0AA8, | |
| 80 0x02AC, 0x06A8, 0x02B1, 0x11A8, 0x02B2, 0x09A8, 0x02B4, 0x05A8, 0x02B8, 0x03A8, | |
| 81 0x02C3, 0x1868, 0x02C5, 0x1468, 0x02C6, 0x0C68, 0x02C9, 0x1268, 0x02CA, 0x0A68, | |
| 82 0x02CC, 0x0668, 0x02D1, 0x1168, 0x02D2, 0x0968, 0x02D4, 0x0568, 0x02D8, 0x0368, | |
| 83 0x02E1, 0x10E8, 0x02E2, 0x08E8, 0x02E4, 0x04E8, 0x0307, 0x1C18, 0x030B, 0x1A18, | |
| 84 0x030D, 0x1618, 0x030E, 0x0E18, 0x0313, 0x1918, 0x0315, 0x1518, 0x0316, 0x0D18, | |
| 85 0x0319, 0x1318, 0x031A, 0x0B18, 0x031C, 0x0718, 0x0323, 0x1898, 0x0325, 0x1498, | |
| 86 0x0326, 0x0C98, 0x0329, 0x1298, 0x032A, 0x0A98, 0x032C, 0x0698, 0x0331, 0x1198, | |
| 87 0x0332, 0x0998, 0x0334, 0x0598, 0x0338, 0x0398, 0x0343, 0x1858, 0x0345, 0x1458, | |
| 88 0x0346, 0x0C58, 0x0349, 0x1258, 0x034A, 0x0A58, 0x034C, 0x0658, 0x0351, 0x1158, | |
| 89 0x0352, 0x0958, 0x0354, 0x0558, 0x0361, 0x10D8, 0x0362, 0x08D8, 0x0364, 0x04D8, | |
| 90 0x0383, 0x1838, 0x0385, 0x1438, 0x0386, 0x0C38, 0x0389, 0x1238, 0x038A, 0x0A38, | |
| 91 0x038C, 0x0638, 0x0391, 0x1138, 0x0392, 0x0938, 0x0394, 0x0538, 0x03A1, 0x10B8, | |
| 92 0x03A2, 0x08B8, 0x03A4, 0x04B8, 0x03C1, 0x1078, 0x03C2, 0x0878, 0x03C4, 0x0478, | |
| 93 0x040F, 0x1E04, 0x0417, 0x1D04, 0x041B, 0x1B04, 0x041D, 0x1704, 0x041E, 0x0F04, | |
| 94 0x0427, 0x1C84, 0x042B, 0x1A84, 0x042D, 0x1684, 0x042E, 0x0E84, 0x0433, 0x1984, | |
| 95 0x0435, 0x1584, 0x0436, 0x0D84, 0x0439, 0x1384, 0x043A, 0x0B84, 0x043C, 0x0784, | |
| 96 0x0447, 0x1C44, 0x044B, 0x1A44, 0x044D, 0x1644, 0x044E, 0x0E44, 0x0453, 0x1944, | |
| 97 0x0455, 0x1544, 0x0456, 0x0D44, 0x0459, 0x1344, 0x045A, 0x0B44, 0x045C, 0x0744, | |
| 98 0x0463, 0x18C4, 0x0465, 0x14C4, 0x0466, 0x0CC4, 0x0469, 0x12C4, 0x046A, 0x0AC4, | |
| 99 0x046C, 0x06C4, 0x0471, 0x11C4, 0x0472, 0x09C4, 0x0474, 0x05C4, 0x0487, 0x1C24, | |
| 100 0x048B, 0x1A24, 0x048D, 0x1624, 0x048E, 0x0E24, 0x0493, 0x1924, 0x0495, 0x1524, | |
| 101 0x0496, 0x0D24, 0x0499, 0x1324, 0x049A, 0x0B24, 0x049C, 0x0724, 0x04A3, 0x18A4, | |
| 102 0x04A5, 0x14A4, 0x04A6, 0x0CA4, 0x04A9, 0x12A4, 0x04AA, 0x0AA4, 0x04AC, 0x06A4, | |
| 103 0x04B1, 0x11A4, 0x04B2, 0x09A4, 0x04B4, 0x05A4, 0x04C3, 0x1864, 0x04C5, 0x1464, | |
| 104 0x04C6, 0x0C64, 0x04C9, 0x1264, 0x04CA, 0x0A64, 0x04CC, 0x0664, 0x04D1, 0x1164, | |
| 105 0x04D2, 0x0964, 0x04D4, 0x0564, 0x04E1, 0x10E4, 0x04E2, 0x08E4, 0x0507, 0x1C14, | |
| 106 0x050B, 0x1A14, 0x050D, 0x1614, 0x050E, 0x0E14, 0x0513, 0x1914, 0x0515, 0x1514, | |
| 107 0x0516, 0x0D14, 0x0519, 0x1314, 0x051A, 0x0B14, 0x051C, 0x0714, 0x0523, 0x1894, | |
| 108 0x0525, 0x1494, 0x0526, 0x0C94, 0x0529, 0x1294, 0x052A, 0x0A94, 0x052C, 0x0694, | |
| 109 0x0531, 0x1194, 0x0532, 0x0994, 0x0534, 0x0594, 0x0543, 0x1854, 0x0545, 0x1454, | |
| 110 0x0546, 0x0C54, 0x0549, 0x1254, 0x054A, 0x0A54, 0x054C, 0x0654, 0x0551, 0x1154, | |
| 111 0x0552, 0x0954, 0x0561, 0x10D4, 0x0562, 0x08D4, 0x0583, 0x1834, 0x0585, 0x1434, | |
| 112 0x0586, 0x0C34, 0x0589, 0x1234, 0x058A, 0x0A34, 0x058C, 0x0634, 0x0591, 0x1134, | |
| 113 0x0592, 0x0934, 0x05A1, 0x10B4, 0x05A2, 0x08B4, 0x05C1, 0x1074, 0x05C2, 0x0874, | |
| 114 0x0607, 0x1C0C, 0x060B, 0x1A0C, 0x060D, 0x160C, 0x060E, 0x0E0C, 0x0613, 0x190C, | |
| 115 0x0615, 0x150C, 0x0616, 0x0D0C, 0x0619, 0x130C, 0x061A, 0x0B0C, 0x061C, 0x070C, | |
| 116 0x0623, 0x188C, 0x0625, 0x148C, 0x0626, 0x0C8C, 0x0629, 0x128C, 0x062A, 0x0A8C, | |
| 117 0x062C, 0x068C, 0x0631, 0x118C, 0x0632, 0x098C, 0x0643, 0x184C, 0x0645, 0x144C, | |
| 118 0x0646, 0x0C4C, 0x0649, 0x124C, 0x064A, 0x0A4C, 0x0651, 0x114C, 0x0652, 0x094C, | |
| 119 0x0661, 0x10CC, 0x0662, 0x08CC, 0x0683, 0x182C, 0x0685, 0x142C, 0x0686, 0x0C2C, | |
| 120 0x0689, 0x122C, 0x068A, 0x0A2C, 0x0691, 0x112C, 0x0692, 0x092C, 0x06A1, 0x10AC, | |
| 121 0x06A2, 0x08AC, 0x06C1, 0x106C, 0x06C2, 0x086C, 0x0703, 0x181C, 0x0705, 0x141C, | |
| 122 0x0706, 0x0C1C, 0x0709, 0x121C, 0x070A, 0x0A1C, 0x0711, 0x111C, 0x0712, 0x091C, | |
| 123 0x0721, 0x109C, 0x0722, 0x089C, 0x0741, 0x105C, 0x0742, 0x085C, 0x0781, 0x103C, | |
| 124 0x0782, 0x083C, 0x080F, 0x1E02, 0x0817, 0x1D02, 0x081B, 0x1B02, 0x081D, 0x1702, | |
| 125 0x081E, 0x0F02, 0x0827, 0x1C82, 0x082B, 0x1A82, 0x082D, 0x1682, 0x082E, 0x0E82, | |
| 126 0x0833, 0x1982, 0x0835, 0x1582, 0x0836, 0x0D82, 0x0839, 0x1382, 0x083A, 0x0B82, | |
| 127 0x0847, 0x1C42, 0x084B, 0x1A42, 0x084D, 0x1642, 0x084E, 0x0E42, 0x0853, 0x1942, | |
| 128 0x0855, 0x1542, 0x0856, 0x0D42, 0x0859, 0x1342, 0x085A, 0x0B42, 0x0863, 0x18C2, | |
| 129 0x0865, 0x14C2, 0x0866, 0x0CC2, 0x0869, 0x12C2, 0x086A, 0x0AC2, 0x0871, 0x11C2, | |
| 130 0x0872, 0x09C2, 0x0887, 0x1C22, 0x088B, 0x1A22, 0x088D, 0x1622, 0x088E, 0x0E22, | |
| 131 0x0893, 0x1922, 0x0895, 0x1522, 0x0896, 0x0D22, 0x0899, 0x1322, 0x089A, 0x0B22, | |
| 132 0x08A3, 0x18A2, 0x08A5, 0x14A2, 0x08A6, 0x0CA2, 0x08A9, 0x12A2, 0x08AA, 0x0AA2, | |
| 133 0x08B1, 0x11A2, 0x08B2, 0x09A2, 0x08C3, 0x1862, 0x08C5, 0x1462, 0x08C6, 0x0C62, | |
| 134 0x08C9, 0x1262, 0x08CA, 0x0A62, 0x08D1, 0x1162, 0x08D2, 0x0962, 0x08E1, 0x10E2, | |
| 135 0x0907, 0x1C12, 0x090B, 0x1A12, 0x090D, 0x1612, 0x090E, 0x0E12, 0x0913, 0x1912, | |
| 136 0x0915, 0x1512, 0x0916, 0x0D12, 0x0919, 0x1312, 0x091A, 0x0B12, 0x0923, 0x1892, | |
| 137 0x0925, 0x1492, 0x0926, 0x0C92, 0x0929, 0x1292, 0x092A, 0x0A92, 0x0931, 0x1192, | |
| 138 0x0932, 0x0992, 0x0943, 0x1852, 0x0945, 0x1452, 0x0946, 0x0C52, 0x0949, 0x1252, | |
| 139 0x094A, 0x0A52, 0x0951, 0x1152, 0x0961, 0x10D2, 0x0983, 0x1832, 0x0985, 0x1432, | |
| 140 0x0986, 0x0C32, 0x0989, 0x1232, 0x098A, 0x0A32, 0x0991, 0x1132, 0x09A1, 0x10B2, | |
| 141 0x09C1, 0x1072, 0x0A07, 0x1C0A, 0x0A0B, 0x1A0A, 0x0A0D, 0x160A, 0x0A0E, 0x0E0A, | |
| 142 0x0A13, 0x190A, 0x0A15, 0x150A, 0x0A16, 0x0D0A, 0x0A19, 0x130A, 0x0A1A, 0x0B0A, | |
| 143 0x0A23, 0x188A, 0x0A25, 0x148A, 0x0A26, 0x0C8A, 0x0A29, 0x128A, 0x0A2A, 0x0A8A, | |
| 144 0x0A31, 0x118A, 0x0A43, 0x184A, 0x0A45, 0x144A, 0x0A46, 0x0C4A, 0x0A49, 0x124A, | |
| 145 0x0A51, 0x114A, 0x0A61, 0x10CA, 0x0A83, 0x182A, 0x0A85, 0x142A, 0x0A86, 0x0C2A, | |
| 146 0x0A89, 0x122A, 0x0A91, 0x112A, 0x0AA1, 0x10AA, 0x0AC1, 0x106A, 0x0B03, 0x181A, | |
| 147 0x0B05, 0x141A, 0x0B06, 0x0C1A, 0x0B09, 0x121A, 0x0B11, 0x111A, 0x0B21, 0x109A, | |
| 148 0x0B41, 0x105A, 0x0B81, 0x103A, 0x0C07, 0x1C06, 0x0C0B, 0x1A06, 0x0C0D, 0x1606, | |
| 149 0x0C0E, 0x0E06, 0x0C13, 0x1906, 0x0C15, 0x1506, 0x0C16, 0x0D06, 0x0C19, 0x1306, | |
| 150 0x0C23, 0x1886, 0x0C25, 0x1486, 0x0C26, 0x0C86, 0x0C29, 0x1286, 0x0C31, 0x1186, | |
| 151 0x0C43, 0x1846, 0x0C45, 0x1446, 0x0C49, 0x1246, 0x0C51, 0x1146, 0x0C61, 0x10C6, | |
| 152 0x0C83, 0x1826, 0x0C85, 0x1426, 0x0C89, 0x1226, 0x0C91, 0x1126, 0x0CA1, 0x10A6, | |
| 153 0x0CC1, 0x1066, 0x0D03, 0x1816, 0x0D05, 0x1416, 0x0D09, 0x1216, 0x0D11, 0x1116, | |
| 154 0x0D21, 0x1096, 0x0D41, 0x1056, 0x0D81, 0x1036, 0x0E03, 0x180E, 0x0E05, 0x140E, | |
| 155 0x0E09, 0x120E, 0x0E11, 0x110E, 0x0E21, 0x108E, 0x0E41, 0x104E, 0x0E81, 0x102E, | |
| 156 0x0F01, 0x101E, 0x100F, 0x1E01, 0x1017, 0x1D01, 0x101B, 0x1B01, 0x101D, 0x1701, | |
| 157 0x1027, 0x1C81, 0x102B, 0x1A81, 0x102D, 0x1681, 0x1033, 0x1981, 0x1035, 0x1581, | |
| 158 0x1039, 0x1381, 0x1047, 0x1C41, 0x104B, 0x1A41, 0x104D, 0x1641, 0x1053, 0x1941, | |
| 159 0x1055, 0x1541, 0x1059, 0x1341, 0x1063, 0x18C1, 0x1065, 0x14C1, 0x1069, 0x12C1, | |
| 160 0x1071, 0x11C1, 0x1087, 0x1C21, 0x108B, 0x1A21, 0x108D, 0x1621, 0x1093, 0x1921, | |
| 161 0x1095, 0x1521, 0x1099, 0x1321, 0x10A3, 0x18A1, 0x10A5, 0x14A1, 0x10A9, 0x12A1, | |
| 162 0x10B1, 0x11A1, 0x10C3, 0x1861, 0x10C5, 0x1461, 0x10C9, 0x1261, 0x10D1, 0x1161, | |
| 163 0x1107, 0x1C11, 0x110B, 0x1A11, 0x110D, 0x1611, 0x1113, 0x1911, 0x1115, 0x1511, | |
| 164 0x1119, 0x1311, 0x1123, 0x1891, 0x1125, 0x1491, 0x1129, 0x1291, 0x1131, 0x1191, | |
| 165 0x1143, 0x1851, 0x1145, 0x1451, 0x1149, 0x1251, 0x1183, 0x1831, 0x1185, 0x1431, | |
| 166 0x1189, 0x1231, 0x1207, 0x1C09, 0x120B, 0x1A09, 0x120D, 0x1609, 0x1213, 0x1909, | |
| 167 0x1215, 0x1509, 0x1219, 0x1309, 0x1223, 0x1889, 0x1225, 0x1489, 0x1229, 0x1289, | |
| 168 0x1243, 0x1849, 0x1245, 0x1449, 0x1283, 0x1829, 0x1285, 0x1429, 0x1303, 0x1819, | |
| 169 0x1305, 0x1419, 0x1407, 0x1C05, 0x140B, 0x1A05, 0x140D, 0x1605, 0x1413, 0x1905, | |
| 170 0x1415, 0x1505, 0x1423, 0x1885, 0x1425, 0x1485, 0x1443, 0x1845, 0x1483, 0x1825, | |
| 171 0x1503, 0x1815, 0x1603, 0x180D, 0x1807, 0x1C03, 0x180B, 0x1A03, 0x1813, 0x1903, | |
| 172 0x1823, 0x1883, 0x1843, 0x1445, 0x1249, 0x1151, 0x10E1, 0x0C46, 0x0A4A, 0x0952, | |
| 173 0x08E2, 0x064C, 0x0554, 0x04E4, 0x0358, 0x02E8, 0x01F0 | |
| 174 }; | |
| 175 | |
| 176 /* Appendix D Table II - 2 of 13 characters */ | |
| 177 static const unsigned short AppxD_II[78] = { | |
| 178 0x0003, 0x1800, 0x0005, 0x1400, 0x0006, 0x0C00, 0x0009, 0x1200, 0x000A, 0x0A00, | |
| 179 0x000C, 0x0600, 0x0011, 0x1100, 0x0012, 0x0900, 0x0014, 0x0500, 0x0018, 0x0300, | |
| 180 0x0021, 0x1080, 0x0022, 0x0880, 0x0024, 0x0480, 0x0028, 0x0280, 0x0030, 0x0180, | |
| 181 0x0041, 0x1040, 0x0042, 0x0840, 0x0044, 0x0440, 0x0048, 0x0240, 0x0050, 0x0140, | |
| 182 0x0060, 0x00C0, 0x0081, 0x1020, 0x0082, 0x0820, 0x0084, 0x0420, 0x0088, 0x0220, | |
| 183 0x0090, 0x0120, 0x0101, 0x1010, 0x0102, 0x0810, 0x0104, 0x0410, 0x0108, 0x0210, | |
| 184 0x0201, 0x1008, 0x0202, 0x0808, 0x0204, 0x0408, 0x0401, 0x1004, 0x0402, 0x0804, | |
| 185 0x0801, 0x1002, 0x1001, 0x0802, 0x0404, 0x0208, 0x0110, 0x00A0 | |
| 186 }; | |
| 187 | |
| 188 /* Appendix D Table IV - Bar-to-Character Mapping (reverse lookup) */ | |
| 189 static const unsigned char AppxD_IV[130] = { | |
| 190 67, 6, 78, 16, 86, 95, 34, 40, 45, 113, 117, 121, 62, 87, 18, 104, 41, 76, 57, 119, | |
| 191 115, 72, 97, 2, 127, 26, 105, 35, 122, 52, 114, 7, 24, 82, 68, 63, 94, 44, 77, 112, | |
| 192 70, 100, 39, 30, 107, 15, 125, 85, 10, 65, 54, 88, 20, 106, 46, 66, 8, 116, 29, 61, | |
| 193 99, 80, 90, 37, 123, 51, 25, 84, 129, 56, 4, 109, 96, 28, 36, 47, 11, 71, 33, 102, | |
| 194 21, 9, 17, 49, 124, 79, 64, 91, 42, 69, 53, 60, 14, 1, 27, 103, 126, 75, 89, 50, | |
| 195 120, 19, 32, 110, 92, 111, 130, 59, 31, 12, 81, 43, 55, 5, 74, 22, 101, 128, 58, 118, | |
| 196 48, 108, 38, 98, 93, 23, 83, 13, 73, 3 | |
| 197 }; | |
| 198 | |
| 199 /*************************************************************************** | |
| 200 ** USPS_MSB_Math_CRC11GenerateFrameCheckSequence | |
| 201 ** | |
| 202 ** Inputs: | |
| 203 ** ByteAttayPtr is the address of a 13 byte array holding 102 bits which | |
| 204 ** are right justified - ie: the leftmost 2 bits of the first byte do not | |
| 205 ** hold data and must be set to zero. | |
| 206 ** | |
| 207 ** Outputs: | |
| 208 ** return unsigned short - 11 bit Frame Check Sequence (right justified) | |
| 209 ***************************************************************************/ | |
| 210 static unsigned short USPS_MSB_Math_CRC11GenerateFrameCheckSequence(unsigned char *ByteArrayPtr) { | |
| 211 unsigned short GeneratorPolynomial = 0x0F35; | |
| 212 unsigned short FrameCheckSequence = 0x07FF; | |
| 213 unsigned short Data; | |
| 214 int ByteIndex, Bit; | |
| 215 | |
| 216 /* Do most significant byte skipping the 2 most significant bits */ | |
| 217 Data = *ByteArrayPtr << 5; | |
| 218 ByteArrayPtr++; | |
| 219 for (Bit = 2; Bit < 8; Bit++) { | |
| 220 if ((FrameCheckSequence ^ Data) & 0x400) | |
| 221 FrameCheckSequence = (FrameCheckSequence << 1) ^ GeneratorPolynomial; | |
| 222 else | |
| 223 FrameCheckSequence = (FrameCheckSequence << 1); | |
| 224 FrameCheckSequence &= 0x7FF; | |
| 225 Data <<= 1; | |
| 226 } | |
| 227 /* Do rest of the bytes */ | |
| 228 for (ByteIndex = 1; ByteIndex < 13; ByteIndex++) { | |
| 229 Data = *ByteArrayPtr << 3; | |
| 230 ByteArrayPtr++; | |
| 231 for (Bit = 0; Bit < 8; Bit++) { | |
| 232 if ((FrameCheckSequence ^ Data) & 0x0400) { | |
| 233 FrameCheckSequence = (FrameCheckSequence << 1) ^ GeneratorPolynomial; | |
| 234 } else { | |
| 235 FrameCheckSequence = (FrameCheckSequence << 1); | |
| 236 } | |
| 237 FrameCheckSequence &= 0x7FF; | |
| 238 Data <<= 1; | |
| 239 } | |
| 240 } | |
| 241 return FrameCheckSequence; | |
| 242 } | |
| 243 | |
| 244 INTERNAL int daft_set_height(struct zint_symbol *symbol, const float min_height, const float max_height); | |
| 245 | |
| 246 INTERNAL int usps_imail(struct zint_symbol *symbol, unsigned char source[], int length) { | |
| 247 char data_pattern[200]; | |
| 248 int error_number = 0; | |
| 249 int i, j, read; | |
| 250 char tracker[33] = {0}; /* Zero to prevent false warning from clang-tidy */ | |
| 251 char zip[33], temp[2]; | |
| 252 large_uint accum; | |
| 253 large_uint byte_array_reg; | |
| 254 unsigned char byte_array[13]; | |
| 255 unsigned short usps_crc; | |
| 256 unsigned int codeword[10]; | |
| 257 unsigned short characters[10]; | |
| 258 short bar_map[130]; | |
| 259 int zip_len, len; | |
| 260 | |
| 261 if (length > 32) { | |
| 262 return errtxtf(ZINT_ERROR_TOO_LONG, symbol, 450, "Input length %d too long (maximum 32)", length); | |
| 263 } | |
| 264 if ((i = not_sane(SODIUM_MNS_F, source, length))) { | |
| 265 return errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 451, | |
| 266 "Invalid character at position %d in input (digits and \"-\" only)", i); | |
| 267 } | |
| 268 | |
| 269 /* separate the tracking code from the routing code */ | |
| 270 | |
| 271 zip[0] = '\0'; | |
| 272 read = 0; | |
| 273 j = 0; | |
| 274 for (i = 0; i < length; i++) { | |
| 275 if (source[i] == '-') { | |
| 276 tracker[read] = '\0'; | |
| 277 j = 1; | |
| 278 read = 0; | |
| 279 } else { | |
| 280 if (j == 0) { | |
| 281 /* reading tracker */ | |
| 282 tracker[read] = source[i]; | |
| 283 read++; | |
| 284 } else { | |
| 285 /* reading zip code */ | |
| 286 zip[read] = source[i]; | |
| 287 read++; | |
| 288 } | |
| 289 } | |
| 290 } | |
| 291 if (j == 0) { | |
| 292 tracker[read] = '\0'; | |
| 293 } else { | |
| 294 zip[read] = '\0'; | |
| 295 } | |
| 296 | |
| 297 if (strlen(tracker) != 20) { | |
| 298 return errtxt(ZINT_ERROR_INVALID_DATA, symbol, 452, | |
| 299 "Invalid length for tracking code (20 characters required)"); | |
| 300 } | |
| 301 if (tracker[1] > '4') { | |
| 302 return errtxt(ZINT_ERROR_INVALID_DATA, symbol, 454, | |
| 303 "Barcode Identifier (second character) out of range (0 to 4)"); | |
| 304 } | |
| 305 | |
| 306 zip_len = (int) strlen(zip); | |
| 307 if (zip_len != 0 && zip_len != 5 && zip_len != 9 && zip_len != 11) { | |
| 308 return errtxt(ZINT_ERROR_INVALID_DATA, symbol, 453, | |
| 309 "Invalid length for ZIP code (5, 9 or 11 characters required)"); | |
| 310 } | |
| 311 | |
| 312 /* *** Step 1 - Conversion of Data Fields into Binary Data *** */ | |
| 313 | |
| 314 /* Routing code first */ | |
| 315 | |
| 316 large_load_str_u64(&accum, (unsigned char *) zip, zip_len); | |
| 317 | |
| 318 /* add weight to routing code */ | |
| 319 if (zip_len > 9) { | |
| 320 large_add_u64(&accum, 1000100001); | |
| 321 } else if (zip_len > 5) { | |
| 322 large_add_u64(&accum, 100001); | |
| 323 } else if (zip_len > 0) { | |
| 324 large_add_u64(&accum, 1); | |
| 325 } | |
| 326 | |
| 327 /* tracking code */ | |
| 328 | |
| 329 /* multiply by 10 */ | |
| 330 large_mul_u64(&accum, 10); | |
| 331 | |
| 332 /* add first digit of tracker */ | |
| 333 large_add_u64(&accum, ctoi(tracker[0])); | |
| 334 | |
| 335 /* multiply by 5 */ | |
| 336 large_mul_u64(&accum, 5); | |
| 337 | |
| 338 /* add second digit */ | |
| 339 large_add_u64(&accum, ctoi(tracker[1])); | |
| 340 | |
| 341 /* and then the rest */ | |
| 342 | |
| 343 for (read = 2; read < 20; read++) { | |
| 344 | |
| 345 large_mul_u64(&accum, 10); | |
| 346 large_add_u64(&accum, ctoi(tracker[read])); | |
| 347 } | |
| 348 | |
| 349 /* *** Step 2 - Generation of 11-bit CRC on Binary Data *** */ | |
| 350 | |
| 351 large_load(&byte_array_reg, &accum); | |
| 352 | |
| 353 large_unset_bit(&byte_array_reg, 102); | |
| 354 large_unset_bit(&byte_array_reg, 103); | |
| 355 | |
| 356 large_uchar_array(&byte_array_reg, byte_array, 13, 8 /*bits*/); | |
| 357 | |
| 358 usps_crc = USPS_MSB_Math_CRC11GenerateFrameCheckSequence(byte_array); | |
| 359 | |
| 360 /* *** Step 3 - Conversion from Binary Data to Codewords *** */ | |
| 361 | |
| 362 /* start with codeword J which is base 636 */ | |
| 363 codeword[9] = (unsigned int) large_div_u64(&accum, 636); | |
| 364 | |
| 365 /* then codewords I to B with base 1365 */ | |
| 366 | |
| 367 for (j = 8; j > 0; j--) { | |
| 368 codeword[j] = (unsigned int) large_div_u64(&accum, 1365); | |
| 369 } | |
| 370 | |
| 371 codeword[0] = (unsigned int) large_lo(&accum); | |
| 372 | |
| 373 /* *** Step 4 - Inserting Additional Information into Codewords *** */ | |
| 374 | |
| 375 codeword[9] = codeword[9] * 2; | |
| 376 | |
| 377 if (usps_crc >= 1024) { | |
| 378 codeword[0] += 659; | |
| 379 } | |
| 380 | |
| 381 /* *** Step 5 - Conversion from Codewords to Characters *** */ | |
| 382 | |
| 383 for (i = 0; i < 10; i++) { | |
| 384 if (codeword[i] < 1287) { | |
| 385 characters[i] = AppxD_I[codeword[i]]; | |
| 386 } else { | |
| 387 characters[i] = AppxD_II[codeword[i] - 1287]; | |
| 388 } | |
| 389 } | |
| 390 | |
| 391 for (i = 0; i < 10; i++) { | |
| 392 if (usps_crc & (1 << i)) { | |
| 393 characters[i] = 0x1FFF - characters[i]; | |
| 394 } | |
| 395 } | |
| 396 | |
| 397 /* *** Step 6 - Conversion from Characters to the Intelligent Mail Barcode *** */ | |
| 398 for (i = 0; i < 10; i++) { | |
| 399 for (j = 0; j < 13; j++) { | |
| 400 if (characters[i] & (1 << j)) { | |
| 401 bar_map[AppxD_IV[(13 * i) + j] - 1] = 1; | |
| 402 } else { | |
| 403 bar_map[AppxD_IV[(13 * i) + j] - 1] = 0; | |
| 404 } | |
| 405 } | |
| 406 } | |
| 407 | |
| 408 data_pattern[0] = '\0'; | |
| 409 temp[1] = '\0'; | |
| 410 for (i = 0; i < 65; i++) { | |
| 411 j = 0; | |
| 412 if (bar_map[i] == 0) | |
| 413 j += 1; | |
| 414 if (bar_map[i + 65] == 0) | |
| 415 j += 2; | |
| 416 temp[0] = itoc(j); | |
| 417 strcat(data_pattern, temp); | |
| 418 } | |
| 419 | |
| 420 /* Translate 4-state data pattern to symbol */ | |
| 421 read = 0; | |
| 422 for (i = 0, len = (int) strlen(data_pattern); i < len; i++) { | |
| 423 if ((data_pattern[i] == '1') || (data_pattern[i] == '0')) { | |
| 424 set_module(symbol, 0, read); | |
| 425 } | |
| 426 set_module(symbol, 1, read); | |
| 427 if ((data_pattern[i] == '2') || (data_pattern[i] == '0')) { | |
| 428 set_module(symbol, 2, read); | |
| 429 } | |
| 430 read += 2; | |
| 431 } | |
| 432 | |
| 433 if (symbol->output_options & COMPLIANT_HEIGHT) { | |
| 434 /* USPS-B-3200 Section 2.3.1 | |
| 435 Using bar pitch as X (1" / 43) ~ 0.023" based on 22 bars + 21 spaces per inch (bar width 0.015" - 0.025"), | |
| 436 height 0.125" - 0.165" | |
| 437 Tracker 0.048" (average of 0.039" - 0.057") | |
| 438 Ascender/descender 0.0965" (average of 0.082" - 0.111") less T = 0.0485" | |
| 439 */ | |
| 440 const float min_height = 4.875f; /* 0.125 * 39 */ | |
| 441 const float max_height = 7.75500011f; /* 0.165 * 47 */ | |
| 442 symbol->row_height[0] = 2.0855f; /* 0.0485 * 43 */ | |
| 443 symbol->row_height[1] = 2.06399989f; /* 0.048 * 43 */ | |
| 444 /* Note using max X for minimum and min X for maximum */ | |
| 445 error_number = daft_set_height(symbol, min_height, max_height); | |
| 446 } else { | |
| 447 symbol->row_height[0] = 3.0f; | |
| 448 symbol->row_height[1] = 2.0f; | |
| 449 (void) daft_set_height(symbol, 0.0f, 0.0f); | |
| 450 } | |
| 451 symbol->rows = 3; | |
| 452 symbol->width = read - 1; | |
| 453 return error_number; | |
| 454 } | |
| 455 | |
| 456 /* vim: set ts=4 sw=4 et : */ |
