diff --git a/backend/code1.c b/backend/code1.c index 57072c81..da47fa11 100644 --- a/backend/code1.c +++ b/backend/code1.c @@ -1366,7 +1366,6 @@ int code_one(struct zint_symbol *symbol, unsigned char source[], int length) { } binary_load(elreg, (char *) source, length); - hex_dump(elreg); for (i = 0; i < 15; i++) { data[i] = 0; diff --git a/backend/imail.c b/backend/imail.c index 2d458cf4..ede7fc88 100644 --- a/backend/imail.c +++ b/backend/imail.c @@ -2,20 +2,20 @@ /* libzint - the open source barcode library - Copyright (C) 2008 Robin Stuart + Copyright (C) 2008-2016 Robin Stuart Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - 1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. + documentation and/or other materials provided with the distribution. 3. Neither the name of the project nor the names of its contributors may be used to endorse or promote products derived from this software - without specific prior written permission. + without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE @@ -26,24 +26,24 @@ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ + */ /* The function "USPS_MSB_Math_CRC11GenerateFrameCheckSequence" is Copyright (C) 2006 United States Postal Service */ static const short int BCD[40] = { - 0, 0, 0, 0, - 1, 0, 0, 0, - 0, 1, 0, 0, - 1, 1, 0, 0, - 0, 0, 1, 0, - 1, 0, 1, 0, - 0, 1, 1, 0, - 1, 1, 1, 0, - 0, 0, 0, 1, - 1, 0, 0, 1 + 0, 0, 0, 0, + 1, 0, 0, 0, + 0, 1, 0, 0, + 1, 1, 0, 0, + 0, 0, 1, 0, + 1, 0, 1, 0, + 0, 1, 1, 0, + 1, 1, 1, 0, + 0, 0, 0, 1, + 1, 0, 0, 1 }; #include @@ -55,657 +55,624 @@ static const short int BCD[40] = { #define SODIUM "0123456789-" /* The following lookup tables were generated using the code in Appendix C */ - -static const unsigned short AppxD_I[1287] = { /* Appendix D Table 1 - 5 of 13 characters */ - 0x001F, 0x1F00, 0x002F, 0x1E80, 0x0037, 0x1D80, 0x003B, 0x1B80, 0x003D, 0x1780, - 0x003E, 0x0F80, 0x004F, 0x1E40, 0x0057, 0x1D40, 0x005B, 0x1B40, 0x005D, 0x1740, - 0x005E, 0x0F40, 0x0067, 0x1CC0, 0x006B, 0x1AC0, 0x006D, 0x16C0, 0x006E, 0x0EC0, - 0x0073, 0x19C0, 0x0075, 0x15C0, 0x0076, 0x0DC0, 0x0079, 0x13C0, 0x007A, 0x0BC0, - 0x007C, 0x07C0, 0x008F, 0x1E20, 0x0097, 0x1D20, 0x009B, 0x1B20, 0x009D, 0x1720, - 0x009E, 0x0F20, 0x00A7, 0x1CA0, 0x00AB, 0x1AA0, 0x00AD, 0x16A0, 0x00AE, 0x0EA0, - 0x00B3, 0x19A0, 0x00B5, 0x15A0, 0x00B6, 0x0DA0, 0x00B9, 0x13A0, 0x00BA, 0x0BA0, - 0x00BC, 0x07A0, 0x00C7, 0x1C60, 0x00CB, 0x1A60, 0x00CD, 0x1660, 0x00CE, 0x0E60, - 0x00D3, 0x1960, 0x00D5, 0x1560, 0x00D6, 0x0D60, 0x00D9, 0x1360, 0x00DA, 0x0B60, - 0x00DC, 0x0760, 0x00E3, 0x18E0, 0x00E5, 0x14E0, 0x00E6, 0x0CE0, 0x00E9, 0x12E0, - 0x00EA, 0x0AE0, 0x00EC, 0x06E0, 0x00F1, 0x11E0, 0x00F2, 0x09E0, 0x00F4, 0x05E0, - 0x00F8, 0x03E0, 0x010F, 0x1E10, 0x0117, 0x1D10, 0x011B, 0x1B10, 0x011D, 0x1710, - 0x011E, 0x0F10, 0x0127, 0x1C90, 0x012B, 0x1A90, 0x012D, 0x1690, 0x012E, 0x0E90, - 0x0133, 0x1990, 0x0135, 0x1590, 0x0136, 0x0D90, 0x0139, 0x1390, 0x013A, 0x0B90, - 0x013C, 0x0790, 0x0147, 0x1C50, 0x014B, 0x1A50, 0x014D, 0x1650, 0x014E, 0x0E50, - 0x0153, 0x1950, 0x0155, 0x1550, 0x0156, 0x0D50, 0x0159, 0x1350, 0x015A, 0x0B50, - 0x015C, 0x0750, 0x0163, 0x18D0, 0x0165, 0x14D0, 0x0166, 0x0CD0, 0x0169, 0x12D0, - 0x016A, 0x0AD0, 0x016C, 0x06D0, 0x0171, 0x11D0, 0x0172, 0x09D0, 0x0174, 0x05D0, - 0x0178, 0x03D0, 0x0187, 0x1C30, 0x018B, 0x1A30, 0x018D, 0x1630, 0x018E, 0x0E30, - 0x0193, 0x1930, 0x0195, 0x1530, 0x0196, 0x0D30, 0x0199, 0x1330, 0x019A, 0x0B30, - 0x019C, 0x0730, 0x01A3, 0x18B0, 0x01A5, 0x14B0, 0x01A6, 0x0CB0, 0x01A9, 0x12B0, - 0x01AA, 0x0AB0, 0x01AC, 0x06B0, 0x01B1, 0x11B0, 0x01B2, 0x09B0, 0x01B4, 0x05B0, - 0x01B8, 0x03B0, 0x01C3, 0x1870, 0x01C5, 0x1470, 0x01C6, 0x0C70, 0x01C9, 0x1270, - 0x01CA, 0x0A70, 0x01CC, 0x0670, 0x01D1, 0x1170, 0x01D2, 0x0970, 0x01D4, 0x0570, - 0x01D8, 0x0370, 0x01E1, 0x10F0, 0x01E2, 0x08F0, 0x01E4, 0x04F0, 0x01E8, 0x02F0, - 0x020F, 0x1E08, 0x0217, 0x1D08, 0x021B, 0x1B08, 0x021D, 0x1708, 0x021E, 0x0F08, - 0x0227, 0x1C88, 0x022B, 0x1A88, 0x022D, 0x1688, 0x022E, 0x0E88, 0x0233, 0x1988, - 0x0235, 0x1588, 0x0236, 0x0D88, 0x0239, 0x1388, 0x023A, 0x0B88, 0x023C, 0x0788, - 0x0247, 0x1C48, 0x024B, 0x1A48, 0x024D, 0x1648, 0x024E, 0x0E48, 0x0253, 0x1948, - 0x0255, 0x1548, 0x0256, 0x0D48, 0x0259, 0x1348, 0x025A, 0x0B48, 0x025C, 0x0748, - 0x0263, 0x18C8, 0x0265, 0x14C8, 0x0266, 0x0CC8, 0x0269, 0x12C8, 0x026A, 0x0AC8, - 0x026C, 0x06C8, 0x0271, 0x11C8, 0x0272, 0x09C8, 0x0274, 0x05C8, 0x0278, 0x03C8, - 0x0287, 0x1C28, 0x028B, 0x1A28, 0x028D, 0x1628, 0x028E, 0x0E28, 0x0293, 0x1928, - 0x0295, 0x1528, 0x0296, 0x0D28, 0x0299, 0x1328, 0x029A, 0x0B28, 0x029C, 0x0728, - 0x02A3, 0x18A8, 0x02A5, 0x14A8, 0x02A6, 0x0CA8, 0x02A9, 0x12A8, 0x02AA, 0x0AA8, - 0x02AC, 0x06A8, 0x02B1, 0x11A8, 0x02B2, 0x09A8, 0x02B4, 0x05A8, 0x02B8, 0x03A8, - 0x02C3, 0x1868, 0x02C5, 0x1468, 0x02C6, 0x0C68, 0x02C9, 0x1268, 0x02CA, 0x0A68, - 0x02CC, 0x0668, 0x02D1, 0x1168, 0x02D2, 0x0968, 0x02D4, 0x0568, 0x02D8, 0x0368, - 0x02E1, 0x10E8, 0x02E2, 0x08E8, 0x02E4, 0x04E8, 0x0307, 0x1C18, 0x030B, 0x1A18, - 0x030D, 0x1618, 0x030E, 0x0E18, 0x0313, 0x1918, 0x0315, 0x1518, 0x0316, 0x0D18, - 0x0319, 0x1318, 0x031A, 0x0B18, 0x031C, 0x0718, 0x0323, 0x1898, 0x0325, 0x1498, - 0x0326, 0x0C98, 0x0329, 0x1298, 0x032A, 0x0A98, 0x032C, 0x0698, 0x0331, 0x1198, - 0x0332, 0x0998, 0x0334, 0x0598, 0x0338, 0x0398, 0x0343, 0x1858, 0x0345, 0x1458, - 0x0346, 0x0C58, 0x0349, 0x1258, 0x034A, 0x0A58, 0x034C, 0x0658, 0x0351, 0x1158, - 0x0352, 0x0958, 0x0354, 0x0558, 0x0361, 0x10D8, 0x0362, 0x08D8, 0x0364, 0x04D8, - 0x0383, 0x1838, 0x0385, 0x1438, 0x0386, 0x0C38, 0x0389, 0x1238, 0x038A, 0x0A38, - 0x038C, 0x0638, 0x0391, 0x1138, 0x0392, 0x0938, 0x0394, 0x0538, 0x03A1, 0x10B8, - 0x03A2, 0x08B8, 0x03A4, 0x04B8, 0x03C1, 0x1078, 0x03C2, 0x0878, 0x03C4, 0x0478, - 0x040F, 0x1E04, 0x0417, 0x1D04, 0x041B, 0x1B04, 0x041D, 0x1704, 0x041E, 0x0F04, - 0x0427, 0x1C84, 0x042B, 0x1A84, 0x042D, 0x1684, 0x042E, 0x0E84, 0x0433, 0x1984, - 0x0435, 0x1584, 0x0436, 0x0D84, 0x0439, 0x1384, 0x043A, 0x0B84, 0x043C, 0x0784, - 0x0447, 0x1C44, 0x044B, 0x1A44, 0x044D, 0x1644, 0x044E, 0x0E44, 0x0453, 0x1944, - 0x0455, 0x1544, 0x0456, 0x0D44, 0x0459, 0x1344, 0x045A, 0x0B44, 0x045C, 0x0744, - 0x0463, 0x18C4, 0x0465, 0x14C4, 0x0466, 0x0CC4, 0x0469, 0x12C4, 0x046A, 0x0AC4, - 0x046C, 0x06C4, 0x0471, 0x11C4, 0x0472, 0x09C4, 0x0474, 0x05C4, 0x0487, 0x1C24, - 0x048B, 0x1A24, 0x048D, 0x1624, 0x048E, 0x0E24, 0x0493, 0x1924, 0x0495, 0x1524, - 0x0496, 0x0D24, 0x0499, 0x1324, 0x049A, 0x0B24, 0x049C, 0x0724, 0x04A3, 0x18A4, - 0x04A5, 0x14A4, 0x04A6, 0x0CA4, 0x04A9, 0x12A4, 0x04AA, 0x0AA4, 0x04AC, 0x06A4, - 0x04B1, 0x11A4, 0x04B2, 0x09A4, 0x04B4, 0x05A4, 0x04C3, 0x1864, 0x04C5, 0x1464, - 0x04C6, 0x0C64, 0x04C9, 0x1264, 0x04CA, 0x0A64, 0x04CC, 0x0664, 0x04D1, 0x1164, - 0x04D2, 0x0964, 0x04D4, 0x0564, 0x04E1, 0x10E4, 0x04E2, 0x08E4, 0x0507, 0x1C14, - 0x050B, 0x1A14, 0x050D, 0x1614, 0x050E, 0x0E14, 0x0513, 0x1914, 0x0515, 0x1514, - 0x0516, 0x0D14, 0x0519, 0x1314, 0x051A, 0x0B14, 0x051C, 0x0714, 0x0523, 0x1894, - 0x0525, 0x1494, 0x0526, 0x0C94, 0x0529, 0x1294, 0x052A, 0x0A94, 0x052C, 0x0694, - 0x0531, 0x1194, 0x0532, 0x0994, 0x0534, 0x0594, 0x0543, 0x1854, 0x0545, 0x1454, - 0x0546, 0x0C54, 0x0549, 0x1254, 0x054A, 0x0A54, 0x054C, 0x0654, 0x0551, 0x1154, - 0x0552, 0x0954, 0x0561, 0x10D4, 0x0562, 0x08D4, 0x0583, 0x1834, 0x0585, 0x1434, - 0x0586, 0x0C34, 0x0589, 0x1234, 0x058A, 0x0A34, 0x058C, 0x0634, 0x0591, 0x1134, - 0x0592, 0x0934, 0x05A1, 0x10B4, 0x05A2, 0x08B4, 0x05C1, 0x1074, 0x05C2, 0x0874, - 0x0607, 0x1C0C, 0x060B, 0x1A0C, 0x060D, 0x160C, 0x060E, 0x0E0C, 0x0613, 0x190C, - 0x0615, 0x150C, 0x0616, 0x0D0C, 0x0619, 0x130C, 0x061A, 0x0B0C, 0x061C, 0x070C, - 0x0623, 0x188C, 0x0625, 0x148C, 0x0626, 0x0C8C, 0x0629, 0x128C, 0x062A, 0x0A8C, - 0x062C, 0x068C, 0x0631, 0x118C, 0x0632, 0x098C, 0x0643, 0x184C, 0x0645, 0x144C, - 0x0646, 0x0C4C, 0x0649, 0x124C, 0x064A, 0x0A4C, 0x0651, 0x114C, 0x0652, 0x094C, - 0x0661, 0x10CC, 0x0662, 0x08CC, 0x0683, 0x182C, 0x0685, 0x142C, 0x0686, 0x0C2C, - 0x0689, 0x122C, 0x068A, 0x0A2C, 0x0691, 0x112C, 0x0692, 0x092C, 0x06A1, 0x10AC, - 0x06A2, 0x08AC, 0x06C1, 0x106C, 0x06C2, 0x086C, 0x0703, 0x181C, 0x0705, 0x141C, - 0x0706, 0x0C1C, 0x0709, 0x121C, 0x070A, 0x0A1C, 0x0711, 0x111C, 0x0712, 0x091C, - 0x0721, 0x109C, 0x0722, 0x089C, 0x0741, 0x105C, 0x0742, 0x085C, 0x0781, 0x103C, - 0x0782, 0x083C, 0x080F, 0x1E02, 0x0817, 0x1D02, 0x081B, 0x1B02, 0x081D, 0x1702, - 0x081E, 0x0F02, 0x0827, 0x1C82, 0x082B, 0x1A82, 0x082D, 0x1682, 0x082E, 0x0E82, - 0x0833, 0x1982, 0x0835, 0x1582, 0x0836, 0x0D82, 0x0839, 0x1382, 0x083A, 0x0B82, - 0x0847, 0x1C42, 0x084B, 0x1A42, 0x084D, 0x1642, 0x084E, 0x0E42, 0x0853, 0x1942, - 0x0855, 0x1542, 0x0856, 0x0D42, 0x0859, 0x1342, 0x085A, 0x0B42, 0x0863, 0x18C2, - 0x0865, 0x14C2, 0x0866, 0x0CC2, 0x0869, 0x12C2, 0x086A, 0x0AC2, 0x0871, 0x11C2, - 0x0872, 0x09C2, 0x0887, 0x1C22, 0x088B, 0x1A22, 0x088D, 0x1622, 0x088E, 0x0E22, - 0x0893, 0x1922, 0x0895, 0x1522, 0x0896, 0x0D22, 0x0899, 0x1322, 0x089A, 0x0B22, - 0x08A3, 0x18A2, 0x08A5, 0x14A2, 0x08A6, 0x0CA2, 0x08A9, 0x12A2, 0x08AA, 0x0AA2, - 0x08B1, 0x11A2, 0x08B2, 0x09A2, 0x08C3, 0x1862, 0x08C5, 0x1462, 0x08C6, 0x0C62, - 0x08C9, 0x1262, 0x08CA, 0x0A62, 0x08D1, 0x1162, 0x08D2, 0x0962, 0x08E1, 0x10E2, - 0x0907, 0x1C12, 0x090B, 0x1A12, 0x090D, 0x1612, 0x090E, 0x0E12, 0x0913, 0x1912, - 0x0915, 0x1512, 0x0916, 0x0D12, 0x0919, 0x1312, 0x091A, 0x0B12, 0x0923, 0x1892, - 0x0925, 0x1492, 0x0926, 0x0C92, 0x0929, 0x1292, 0x092A, 0x0A92, 0x0931, 0x1192, - 0x0932, 0x0992, 0x0943, 0x1852, 0x0945, 0x1452, 0x0946, 0x0C52, 0x0949, 0x1252, - 0x094A, 0x0A52, 0x0951, 0x1152, 0x0961, 0x10D2, 0x0983, 0x1832, 0x0985, 0x1432, - 0x0986, 0x0C32, 0x0989, 0x1232, 0x098A, 0x0A32, 0x0991, 0x1132, 0x09A1, 0x10B2, - 0x09C1, 0x1072, 0x0A07, 0x1C0A, 0x0A0B, 0x1A0A, 0x0A0D, 0x160A, 0x0A0E, 0x0E0A, - 0x0A13, 0x190A, 0x0A15, 0x150A, 0x0A16, 0x0D0A, 0x0A19, 0x130A, 0x0A1A, 0x0B0A, - 0x0A23, 0x188A, 0x0A25, 0x148A, 0x0A26, 0x0C8A, 0x0A29, 0x128A, 0x0A2A, 0x0A8A, - 0x0A31, 0x118A, 0x0A43, 0x184A, 0x0A45, 0x144A, 0x0A46, 0x0C4A, 0x0A49, 0x124A, - 0x0A51, 0x114A, 0x0A61, 0x10CA, 0x0A83, 0x182A, 0x0A85, 0x142A, 0x0A86, 0x0C2A, - 0x0A89, 0x122A, 0x0A91, 0x112A, 0x0AA1, 0x10AA, 0x0AC1, 0x106A, 0x0B03, 0x181A, - 0x0B05, 0x141A, 0x0B06, 0x0C1A, 0x0B09, 0x121A, 0x0B11, 0x111A, 0x0B21, 0x109A, - 0x0B41, 0x105A, 0x0B81, 0x103A, 0x0C07, 0x1C06, 0x0C0B, 0x1A06, 0x0C0D, 0x1606, - 0x0C0E, 0x0E06, 0x0C13, 0x1906, 0x0C15, 0x1506, 0x0C16, 0x0D06, 0x0C19, 0x1306, - 0x0C23, 0x1886, 0x0C25, 0x1486, 0x0C26, 0x0C86, 0x0C29, 0x1286, 0x0C31, 0x1186, - 0x0C43, 0x1846, 0x0C45, 0x1446, 0x0C49, 0x1246, 0x0C51, 0x1146, 0x0C61, 0x10C6, - 0x0C83, 0x1826, 0x0C85, 0x1426, 0x0C89, 0x1226, 0x0C91, 0x1126, 0x0CA1, 0x10A6, - 0x0CC1, 0x1066, 0x0D03, 0x1816, 0x0D05, 0x1416, 0x0D09, 0x1216, 0x0D11, 0x1116, - 0x0D21, 0x1096, 0x0D41, 0x1056, 0x0D81, 0x1036, 0x0E03, 0x180E, 0x0E05, 0x140E, - 0x0E09, 0x120E, 0x0E11, 0x110E, 0x0E21, 0x108E, 0x0E41, 0x104E, 0x0E81, 0x102E, - 0x0F01, 0x101E, 0x100F, 0x1E01, 0x1017, 0x1D01, 0x101B, 0x1B01, 0x101D, 0x1701, - 0x1027, 0x1C81, 0x102B, 0x1A81, 0x102D, 0x1681, 0x1033, 0x1981, 0x1035, 0x1581, - 0x1039, 0x1381, 0x1047, 0x1C41, 0x104B, 0x1A41, 0x104D, 0x1641, 0x1053, 0x1941, - 0x1055, 0x1541, 0x1059, 0x1341, 0x1063, 0x18C1, 0x1065, 0x14C1, 0x1069, 0x12C1, - 0x1071, 0x11C1, 0x1087, 0x1C21, 0x108B, 0x1A21, 0x108D, 0x1621, 0x1093, 0x1921, - 0x1095, 0x1521, 0x1099, 0x1321, 0x10A3, 0x18A1, 0x10A5, 0x14A1, 0x10A9, 0x12A1, - 0x10B1, 0x11A1, 0x10C3, 0x1861, 0x10C5, 0x1461, 0x10C9, 0x1261, 0x10D1, 0x1161, - 0x1107, 0x1C11, 0x110B, 0x1A11, 0x110D, 0x1611, 0x1113, 0x1911, 0x1115, 0x1511, - 0x1119, 0x1311, 0x1123, 0x1891, 0x1125, 0x1491, 0x1129, 0x1291, 0x1131, 0x1191, - 0x1143, 0x1851, 0x1145, 0x1451, 0x1149, 0x1251, 0x1183, 0x1831, 0x1185, 0x1431, - 0x1189, 0x1231, 0x1207, 0x1C09, 0x120B, 0x1A09, 0x120D, 0x1609, 0x1213, 0x1909, - 0x1215, 0x1509, 0x1219, 0x1309, 0x1223, 0x1889, 0x1225, 0x1489, 0x1229, 0x1289, - 0x1243, 0x1849, 0x1245, 0x1449, 0x1283, 0x1829, 0x1285, 0x1429, 0x1303, 0x1819, - 0x1305, 0x1419, 0x1407, 0x1C05, 0x140B, 0x1A05, 0x140D, 0x1605, 0x1413, 0x1905, - 0x1415, 0x1505, 0x1423, 0x1885, 0x1425, 0x1485, 0x1443, 0x1845, 0x1483, 0x1825, - 0x1503, 0x1815, 0x1603, 0x180D, 0x1807, 0x1C03, 0x180B, 0x1A03, 0x1813, 0x1903, - 0x1823, 0x1883, 0x1843, 0x1445, 0x1249, 0x1151, 0x10E1, 0x0C46, 0x0A4A, 0x0952, - 0x08E2, 0x064C, 0x0554, 0x04E4, 0x0358, 0x02E8, 0x01F0 }; -static const unsigned short AppxD_II[78] = { /* Appendix D Table II - 2 of 13 characters */ - 0x0003, 0x1800, 0x0005, 0x1400, 0x0006, 0x0C00, 0x0009, 0x1200, 0x000A, 0x0A00, - 0x000C, 0x0600, 0x0011, 0x1100, 0x0012, 0x0900, 0x0014, 0x0500, 0x0018, 0x0300, - 0x0021, 0x1080, 0x0022, 0x0880, 0x0024, 0x0480, 0x0028, 0x0280, 0x0030, 0x0180, - 0x0041, 0x1040, 0x0042, 0x0840, 0x0044, 0x0440, 0x0048, 0x0240, 0x0050, 0x0140, - 0x0060, 0x00C0, 0x0081, 0x1020, 0x0082, 0x0820, 0x0084, 0x0420, 0x0088, 0x0220, - 0x0090, 0x0120, 0x0101, 0x1010, 0x0102, 0x0810, 0x0104, 0x0410, 0x0108, 0x0210, - 0x0201, 0x1008, 0x0202, 0x0808, 0x0204, 0x0408, 0x0401, 0x1004, 0x0402, 0x0804, - 0x0801, 0x1002, 0x1001, 0x0802, 0x0404, 0x0208, 0x0110, 0x00A0 }; +static const unsigned short AppxD_I[1287] = { + /* Appendix D Table 1 - 5 of 13 characters */ + 0x001F, 0x1F00, 0x002F, 0x1E80, 0x0037, 0x1D80, 0x003B, 0x1B80, 0x003D, 0x1780, + 0x003E, 0x0F80, 0x004F, 0x1E40, 0x0057, 0x1D40, 0x005B, 0x1B40, 0x005D, 0x1740, + 0x005E, 0x0F40, 0x0067, 0x1CC0, 0x006B, 0x1AC0, 0x006D, 0x16C0, 0x006E, 0x0EC0, + 0x0073, 0x19C0, 0x0075, 0x15C0, 0x0076, 0x0DC0, 0x0079, 0x13C0, 0x007A, 0x0BC0, + 0x007C, 0x07C0, 0x008F, 0x1E20, 0x0097, 0x1D20, 0x009B, 0x1B20, 0x009D, 0x1720, + 0x009E, 0x0F20, 0x00A7, 0x1CA0, 0x00AB, 0x1AA0, 0x00AD, 0x16A0, 0x00AE, 0x0EA0, + 0x00B3, 0x19A0, 0x00B5, 0x15A0, 0x00B6, 0x0DA0, 0x00B9, 0x13A0, 0x00BA, 0x0BA0, + 0x00BC, 0x07A0, 0x00C7, 0x1C60, 0x00CB, 0x1A60, 0x00CD, 0x1660, 0x00CE, 0x0E60, + 0x00D3, 0x1960, 0x00D5, 0x1560, 0x00D6, 0x0D60, 0x00D9, 0x1360, 0x00DA, 0x0B60, + 0x00DC, 0x0760, 0x00E3, 0x18E0, 0x00E5, 0x14E0, 0x00E6, 0x0CE0, 0x00E9, 0x12E0, + 0x00EA, 0x0AE0, 0x00EC, 0x06E0, 0x00F1, 0x11E0, 0x00F2, 0x09E0, 0x00F4, 0x05E0, + 0x00F8, 0x03E0, 0x010F, 0x1E10, 0x0117, 0x1D10, 0x011B, 0x1B10, 0x011D, 0x1710, + 0x011E, 0x0F10, 0x0127, 0x1C90, 0x012B, 0x1A90, 0x012D, 0x1690, 0x012E, 0x0E90, + 0x0133, 0x1990, 0x0135, 0x1590, 0x0136, 0x0D90, 0x0139, 0x1390, 0x013A, 0x0B90, + 0x013C, 0x0790, 0x0147, 0x1C50, 0x014B, 0x1A50, 0x014D, 0x1650, 0x014E, 0x0E50, + 0x0153, 0x1950, 0x0155, 0x1550, 0x0156, 0x0D50, 0x0159, 0x1350, 0x015A, 0x0B50, + 0x015C, 0x0750, 0x0163, 0x18D0, 0x0165, 0x14D0, 0x0166, 0x0CD0, 0x0169, 0x12D0, + 0x016A, 0x0AD0, 0x016C, 0x06D0, 0x0171, 0x11D0, 0x0172, 0x09D0, 0x0174, 0x05D0, + 0x0178, 0x03D0, 0x0187, 0x1C30, 0x018B, 0x1A30, 0x018D, 0x1630, 0x018E, 0x0E30, + 0x0193, 0x1930, 0x0195, 0x1530, 0x0196, 0x0D30, 0x0199, 0x1330, 0x019A, 0x0B30, + 0x019C, 0x0730, 0x01A3, 0x18B0, 0x01A5, 0x14B0, 0x01A6, 0x0CB0, 0x01A9, 0x12B0, + 0x01AA, 0x0AB0, 0x01AC, 0x06B0, 0x01B1, 0x11B0, 0x01B2, 0x09B0, 0x01B4, 0x05B0, + 0x01B8, 0x03B0, 0x01C3, 0x1870, 0x01C5, 0x1470, 0x01C6, 0x0C70, 0x01C9, 0x1270, + 0x01CA, 0x0A70, 0x01CC, 0x0670, 0x01D1, 0x1170, 0x01D2, 0x0970, 0x01D4, 0x0570, + 0x01D8, 0x0370, 0x01E1, 0x10F0, 0x01E2, 0x08F0, 0x01E4, 0x04F0, 0x01E8, 0x02F0, + 0x020F, 0x1E08, 0x0217, 0x1D08, 0x021B, 0x1B08, 0x021D, 0x1708, 0x021E, 0x0F08, + 0x0227, 0x1C88, 0x022B, 0x1A88, 0x022D, 0x1688, 0x022E, 0x0E88, 0x0233, 0x1988, + 0x0235, 0x1588, 0x0236, 0x0D88, 0x0239, 0x1388, 0x023A, 0x0B88, 0x023C, 0x0788, + 0x0247, 0x1C48, 0x024B, 0x1A48, 0x024D, 0x1648, 0x024E, 0x0E48, 0x0253, 0x1948, + 0x0255, 0x1548, 0x0256, 0x0D48, 0x0259, 0x1348, 0x025A, 0x0B48, 0x025C, 0x0748, + 0x0263, 0x18C8, 0x0265, 0x14C8, 0x0266, 0x0CC8, 0x0269, 0x12C8, 0x026A, 0x0AC8, + 0x026C, 0x06C8, 0x0271, 0x11C8, 0x0272, 0x09C8, 0x0274, 0x05C8, 0x0278, 0x03C8, + 0x0287, 0x1C28, 0x028B, 0x1A28, 0x028D, 0x1628, 0x028E, 0x0E28, 0x0293, 0x1928, + 0x0295, 0x1528, 0x0296, 0x0D28, 0x0299, 0x1328, 0x029A, 0x0B28, 0x029C, 0x0728, + 0x02A3, 0x18A8, 0x02A5, 0x14A8, 0x02A6, 0x0CA8, 0x02A9, 0x12A8, 0x02AA, 0x0AA8, + 0x02AC, 0x06A8, 0x02B1, 0x11A8, 0x02B2, 0x09A8, 0x02B4, 0x05A8, 0x02B8, 0x03A8, + 0x02C3, 0x1868, 0x02C5, 0x1468, 0x02C6, 0x0C68, 0x02C9, 0x1268, 0x02CA, 0x0A68, + 0x02CC, 0x0668, 0x02D1, 0x1168, 0x02D2, 0x0968, 0x02D4, 0x0568, 0x02D8, 0x0368, + 0x02E1, 0x10E8, 0x02E2, 0x08E8, 0x02E4, 0x04E8, 0x0307, 0x1C18, 0x030B, 0x1A18, + 0x030D, 0x1618, 0x030E, 0x0E18, 0x0313, 0x1918, 0x0315, 0x1518, 0x0316, 0x0D18, + 0x0319, 0x1318, 0x031A, 0x0B18, 0x031C, 0x0718, 0x0323, 0x1898, 0x0325, 0x1498, + 0x0326, 0x0C98, 0x0329, 0x1298, 0x032A, 0x0A98, 0x032C, 0x0698, 0x0331, 0x1198, + 0x0332, 0x0998, 0x0334, 0x0598, 0x0338, 0x0398, 0x0343, 0x1858, 0x0345, 0x1458, + 0x0346, 0x0C58, 0x0349, 0x1258, 0x034A, 0x0A58, 0x034C, 0x0658, 0x0351, 0x1158, + 0x0352, 0x0958, 0x0354, 0x0558, 0x0361, 0x10D8, 0x0362, 0x08D8, 0x0364, 0x04D8, + 0x0383, 0x1838, 0x0385, 0x1438, 0x0386, 0x0C38, 0x0389, 0x1238, 0x038A, 0x0A38, + 0x038C, 0x0638, 0x0391, 0x1138, 0x0392, 0x0938, 0x0394, 0x0538, 0x03A1, 0x10B8, + 0x03A2, 0x08B8, 0x03A4, 0x04B8, 0x03C1, 0x1078, 0x03C2, 0x0878, 0x03C4, 0x0478, + 0x040F, 0x1E04, 0x0417, 0x1D04, 0x041B, 0x1B04, 0x041D, 0x1704, 0x041E, 0x0F04, + 0x0427, 0x1C84, 0x042B, 0x1A84, 0x042D, 0x1684, 0x042E, 0x0E84, 0x0433, 0x1984, + 0x0435, 0x1584, 0x0436, 0x0D84, 0x0439, 0x1384, 0x043A, 0x0B84, 0x043C, 0x0784, + 0x0447, 0x1C44, 0x044B, 0x1A44, 0x044D, 0x1644, 0x044E, 0x0E44, 0x0453, 0x1944, + 0x0455, 0x1544, 0x0456, 0x0D44, 0x0459, 0x1344, 0x045A, 0x0B44, 0x045C, 0x0744, + 0x0463, 0x18C4, 0x0465, 0x14C4, 0x0466, 0x0CC4, 0x0469, 0x12C4, 0x046A, 0x0AC4, + 0x046C, 0x06C4, 0x0471, 0x11C4, 0x0472, 0x09C4, 0x0474, 0x05C4, 0x0487, 0x1C24, + 0x048B, 0x1A24, 0x048D, 0x1624, 0x048E, 0x0E24, 0x0493, 0x1924, 0x0495, 0x1524, + 0x0496, 0x0D24, 0x0499, 0x1324, 0x049A, 0x0B24, 0x049C, 0x0724, 0x04A3, 0x18A4, + 0x04A5, 0x14A4, 0x04A6, 0x0CA4, 0x04A9, 0x12A4, 0x04AA, 0x0AA4, 0x04AC, 0x06A4, + 0x04B1, 0x11A4, 0x04B2, 0x09A4, 0x04B4, 0x05A4, 0x04C3, 0x1864, 0x04C5, 0x1464, + 0x04C6, 0x0C64, 0x04C9, 0x1264, 0x04CA, 0x0A64, 0x04CC, 0x0664, 0x04D1, 0x1164, + 0x04D2, 0x0964, 0x04D4, 0x0564, 0x04E1, 0x10E4, 0x04E2, 0x08E4, 0x0507, 0x1C14, + 0x050B, 0x1A14, 0x050D, 0x1614, 0x050E, 0x0E14, 0x0513, 0x1914, 0x0515, 0x1514, + 0x0516, 0x0D14, 0x0519, 0x1314, 0x051A, 0x0B14, 0x051C, 0x0714, 0x0523, 0x1894, + 0x0525, 0x1494, 0x0526, 0x0C94, 0x0529, 0x1294, 0x052A, 0x0A94, 0x052C, 0x0694, + 0x0531, 0x1194, 0x0532, 0x0994, 0x0534, 0x0594, 0x0543, 0x1854, 0x0545, 0x1454, + 0x0546, 0x0C54, 0x0549, 0x1254, 0x054A, 0x0A54, 0x054C, 0x0654, 0x0551, 0x1154, + 0x0552, 0x0954, 0x0561, 0x10D4, 0x0562, 0x08D4, 0x0583, 0x1834, 0x0585, 0x1434, + 0x0586, 0x0C34, 0x0589, 0x1234, 0x058A, 0x0A34, 0x058C, 0x0634, 0x0591, 0x1134, + 0x0592, 0x0934, 0x05A1, 0x10B4, 0x05A2, 0x08B4, 0x05C1, 0x1074, 0x05C2, 0x0874, + 0x0607, 0x1C0C, 0x060B, 0x1A0C, 0x060D, 0x160C, 0x060E, 0x0E0C, 0x0613, 0x190C, + 0x0615, 0x150C, 0x0616, 0x0D0C, 0x0619, 0x130C, 0x061A, 0x0B0C, 0x061C, 0x070C, + 0x0623, 0x188C, 0x0625, 0x148C, 0x0626, 0x0C8C, 0x0629, 0x128C, 0x062A, 0x0A8C, + 0x062C, 0x068C, 0x0631, 0x118C, 0x0632, 0x098C, 0x0643, 0x184C, 0x0645, 0x144C, + 0x0646, 0x0C4C, 0x0649, 0x124C, 0x064A, 0x0A4C, 0x0651, 0x114C, 0x0652, 0x094C, + 0x0661, 0x10CC, 0x0662, 0x08CC, 0x0683, 0x182C, 0x0685, 0x142C, 0x0686, 0x0C2C, + 0x0689, 0x122C, 0x068A, 0x0A2C, 0x0691, 0x112C, 0x0692, 0x092C, 0x06A1, 0x10AC, + 0x06A2, 0x08AC, 0x06C1, 0x106C, 0x06C2, 0x086C, 0x0703, 0x181C, 0x0705, 0x141C, + 0x0706, 0x0C1C, 0x0709, 0x121C, 0x070A, 0x0A1C, 0x0711, 0x111C, 0x0712, 0x091C, + 0x0721, 0x109C, 0x0722, 0x089C, 0x0741, 0x105C, 0x0742, 0x085C, 0x0781, 0x103C, + 0x0782, 0x083C, 0x080F, 0x1E02, 0x0817, 0x1D02, 0x081B, 0x1B02, 0x081D, 0x1702, + 0x081E, 0x0F02, 0x0827, 0x1C82, 0x082B, 0x1A82, 0x082D, 0x1682, 0x082E, 0x0E82, + 0x0833, 0x1982, 0x0835, 0x1582, 0x0836, 0x0D82, 0x0839, 0x1382, 0x083A, 0x0B82, + 0x0847, 0x1C42, 0x084B, 0x1A42, 0x084D, 0x1642, 0x084E, 0x0E42, 0x0853, 0x1942, + 0x0855, 0x1542, 0x0856, 0x0D42, 0x0859, 0x1342, 0x085A, 0x0B42, 0x0863, 0x18C2, + 0x0865, 0x14C2, 0x0866, 0x0CC2, 0x0869, 0x12C2, 0x086A, 0x0AC2, 0x0871, 0x11C2, + 0x0872, 0x09C2, 0x0887, 0x1C22, 0x088B, 0x1A22, 0x088D, 0x1622, 0x088E, 0x0E22, + 0x0893, 0x1922, 0x0895, 0x1522, 0x0896, 0x0D22, 0x0899, 0x1322, 0x089A, 0x0B22, + 0x08A3, 0x18A2, 0x08A5, 0x14A2, 0x08A6, 0x0CA2, 0x08A9, 0x12A2, 0x08AA, 0x0AA2, + 0x08B1, 0x11A2, 0x08B2, 0x09A2, 0x08C3, 0x1862, 0x08C5, 0x1462, 0x08C6, 0x0C62, + 0x08C9, 0x1262, 0x08CA, 0x0A62, 0x08D1, 0x1162, 0x08D2, 0x0962, 0x08E1, 0x10E2, + 0x0907, 0x1C12, 0x090B, 0x1A12, 0x090D, 0x1612, 0x090E, 0x0E12, 0x0913, 0x1912, + 0x0915, 0x1512, 0x0916, 0x0D12, 0x0919, 0x1312, 0x091A, 0x0B12, 0x0923, 0x1892, + 0x0925, 0x1492, 0x0926, 0x0C92, 0x0929, 0x1292, 0x092A, 0x0A92, 0x0931, 0x1192, + 0x0932, 0x0992, 0x0943, 0x1852, 0x0945, 0x1452, 0x0946, 0x0C52, 0x0949, 0x1252, + 0x094A, 0x0A52, 0x0951, 0x1152, 0x0961, 0x10D2, 0x0983, 0x1832, 0x0985, 0x1432, + 0x0986, 0x0C32, 0x0989, 0x1232, 0x098A, 0x0A32, 0x0991, 0x1132, 0x09A1, 0x10B2, + 0x09C1, 0x1072, 0x0A07, 0x1C0A, 0x0A0B, 0x1A0A, 0x0A0D, 0x160A, 0x0A0E, 0x0E0A, + 0x0A13, 0x190A, 0x0A15, 0x150A, 0x0A16, 0x0D0A, 0x0A19, 0x130A, 0x0A1A, 0x0B0A, + 0x0A23, 0x188A, 0x0A25, 0x148A, 0x0A26, 0x0C8A, 0x0A29, 0x128A, 0x0A2A, 0x0A8A, + 0x0A31, 0x118A, 0x0A43, 0x184A, 0x0A45, 0x144A, 0x0A46, 0x0C4A, 0x0A49, 0x124A, + 0x0A51, 0x114A, 0x0A61, 0x10CA, 0x0A83, 0x182A, 0x0A85, 0x142A, 0x0A86, 0x0C2A, + 0x0A89, 0x122A, 0x0A91, 0x112A, 0x0AA1, 0x10AA, 0x0AC1, 0x106A, 0x0B03, 0x181A, + 0x0B05, 0x141A, 0x0B06, 0x0C1A, 0x0B09, 0x121A, 0x0B11, 0x111A, 0x0B21, 0x109A, + 0x0B41, 0x105A, 0x0B81, 0x103A, 0x0C07, 0x1C06, 0x0C0B, 0x1A06, 0x0C0D, 0x1606, + 0x0C0E, 0x0E06, 0x0C13, 0x1906, 0x0C15, 0x1506, 0x0C16, 0x0D06, 0x0C19, 0x1306, + 0x0C23, 0x1886, 0x0C25, 0x1486, 0x0C26, 0x0C86, 0x0C29, 0x1286, 0x0C31, 0x1186, + 0x0C43, 0x1846, 0x0C45, 0x1446, 0x0C49, 0x1246, 0x0C51, 0x1146, 0x0C61, 0x10C6, + 0x0C83, 0x1826, 0x0C85, 0x1426, 0x0C89, 0x1226, 0x0C91, 0x1126, 0x0CA1, 0x10A6, + 0x0CC1, 0x1066, 0x0D03, 0x1816, 0x0D05, 0x1416, 0x0D09, 0x1216, 0x0D11, 0x1116, + 0x0D21, 0x1096, 0x0D41, 0x1056, 0x0D81, 0x1036, 0x0E03, 0x180E, 0x0E05, 0x140E, + 0x0E09, 0x120E, 0x0E11, 0x110E, 0x0E21, 0x108E, 0x0E41, 0x104E, 0x0E81, 0x102E, + 0x0F01, 0x101E, 0x100F, 0x1E01, 0x1017, 0x1D01, 0x101B, 0x1B01, 0x101D, 0x1701, + 0x1027, 0x1C81, 0x102B, 0x1A81, 0x102D, 0x1681, 0x1033, 0x1981, 0x1035, 0x1581, + 0x1039, 0x1381, 0x1047, 0x1C41, 0x104B, 0x1A41, 0x104D, 0x1641, 0x1053, 0x1941, + 0x1055, 0x1541, 0x1059, 0x1341, 0x1063, 0x18C1, 0x1065, 0x14C1, 0x1069, 0x12C1, + 0x1071, 0x11C1, 0x1087, 0x1C21, 0x108B, 0x1A21, 0x108D, 0x1621, 0x1093, 0x1921, + 0x1095, 0x1521, 0x1099, 0x1321, 0x10A3, 0x18A1, 0x10A5, 0x14A1, 0x10A9, 0x12A1, + 0x10B1, 0x11A1, 0x10C3, 0x1861, 0x10C5, 0x1461, 0x10C9, 0x1261, 0x10D1, 0x1161, + 0x1107, 0x1C11, 0x110B, 0x1A11, 0x110D, 0x1611, 0x1113, 0x1911, 0x1115, 0x1511, + 0x1119, 0x1311, 0x1123, 0x1891, 0x1125, 0x1491, 0x1129, 0x1291, 0x1131, 0x1191, + 0x1143, 0x1851, 0x1145, 0x1451, 0x1149, 0x1251, 0x1183, 0x1831, 0x1185, 0x1431, + 0x1189, 0x1231, 0x1207, 0x1C09, 0x120B, 0x1A09, 0x120D, 0x1609, 0x1213, 0x1909, + 0x1215, 0x1509, 0x1219, 0x1309, 0x1223, 0x1889, 0x1225, 0x1489, 0x1229, 0x1289, + 0x1243, 0x1849, 0x1245, 0x1449, 0x1283, 0x1829, 0x1285, 0x1429, 0x1303, 0x1819, + 0x1305, 0x1419, 0x1407, 0x1C05, 0x140B, 0x1A05, 0x140D, 0x1605, 0x1413, 0x1905, + 0x1415, 0x1505, 0x1423, 0x1885, 0x1425, 0x1485, 0x1443, 0x1845, 0x1483, 0x1825, + 0x1503, 0x1815, 0x1603, 0x180D, 0x1807, 0x1C03, 0x180B, 0x1A03, 0x1813, 0x1903, + 0x1823, 0x1883, 0x1843, 0x1445, 0x1249, 0x1151, 0x10E1, 0x0C46, 0x0A4A, 0x0952, + 0x08E2, 0x064C, 0x0554, 0x04E4, 0x0358, 0x02E8, 0x01F0 +}; -static const int AppxD_IV[130] = { /* Appendix D Table IV - Bar-to-Character Mapping (reverse lookup) */ - 67, 6, 78, 16, 86, 95, 34, 40, 45, 113, 117, 121, 62, 87, 18, 104, 41, 76, 57, 119, 115, 72, 97, - 2, 127, 26, 105, 35, 122, 52, 114, 7, 24, 82, 68, 63, 94, 44, 77, 112, 70, 100, 39, 30, 107, - 15, 125, 85, 10, 65, 54, 88, 20, 106, 46, 66, 8, 116, 29, 61, 99, 80, 90, 37, 123, 51, 25, 84, - 129, 56, 4, 109, 96, 28, 36, 47, 11, 71, 33, 102, 21, 9, 17, 49, 124, 79, 64, 91, 42, 69, 53, - 60, 14, 1, 27, 103, 126, 75, 89, 50, 120, 19, 32, 110, 92, 111, 130, 59, 31, 12, 81, 43, 55, - 5, 74, 22, 101, 128, 58, 118, 48, 108, 38, 98, 93, 23, 83, 13, 73, 3 }; +static const unsigned short AppxD_II[78] = { + /* Appendix D Table II - 2 of 13 characters */ + 0x0003, 0x1800, 0x0005, 0x1400, 0x0006, 0x0C00, 0x0009, 0x1200, 0x000A, 0x0A00, + 0x000C, 0x0600, 0x0011, 0x1100, 0x0012, 0x0900, 0x0014, 0x0500, 0x0018, 0x0300, + 0x0021, 0x1080, 0x0022, 0x0880, 0x0024, 0x0480, 0x0028, 0x0280, 0x0030, 0x0180, + 0x0041, 0x1040, 0x0042, 0x0840, 0x0044, 0x0440, 0x0048, 0x0240, 0x0050, 0x0140, + 0x0060, 0x00C0, 0x0081, 0x1020, 0x0082, 0x0820, 0x0084, 0x0420, 0x0088, 0x0220, + 0x0090, 0x0120, 0x0101, 0x1010, 0x0102, 0x0810, 0x0104, 0x0410, 0x0108, 0x0210, + 0x0201, 0x1008, 0x0202, 0x0808, 0x0204, 0x0408, 0x0401, 0x1004, 0x0402, 0x0804, + 0x0801, 0x1002, 0x1001, 0x0802, 0x0404, 0x0208, 0x0110, 0x00A0 +}; + +static const int AppxD_IV[130] = { + /* Appendix D Table IV - Bar-to-Character Mapping (reverse lookup) */ + 67, 6, 78, 16, 86, 95, 34, 40, 45, 113, 117, 121, 62, 87, 18, 104, 41, 76, 57, 119, 115, 72, 97, + 2, 127, 26, 105, 35, 122, 52, 114, 7, 24, 82, 68, 63, 94, 44, 77, 112, 70, 100, 39, 30, 107, + 15, 125, 85, 10, 65, 54, 88, 20, 106, 46, 66, 8, 116, 29, 61, 99, 80, 90, 37, 123, 51, 25, 84, + 129, 56, 4, 109, 96, 28, 36, 47, 11, 71, 33, 102, 21, 9, 17, 49, 124, 79, 64, 91, 42, 69, 53, + 60, 14, 1, 27, 103, 126, 75, 89, 50, 120, 19, 32, 110, 92, 111, 130, 59, 31, 12, 81, 43, 55, + 5, 74, 22, 101, 128, 58, 118, 48, 108, 38, 98, 93, 23, 83, 13, 73, 3 +}; /*************************************************************************** - ** USPS_MSB_Math_CRC11GenerateFrameCheckSequence - ** - ** Inputs: - ** ByteAttayPtr is the address of a 13 byte array holding 102 bytes which - ** are right justified - ie: the leftmost 2 bits of the first byte do not - ** hold data and must be set to zero. - ** - ** Outputs: - ** return unsigned short - 11 bit Frame Check Sequence (right justified) -***************************************************************************/ -extern unsigned short - USPS_MSB_Math_CRC11GenerateFrameCheckSequence( unsigned char *ByteArrayPtr ) + ** USPS_MSB_Math_CRC11GenerateFrameCheckSequence + ** + ** Inputs: + ** ByteAttayPtr is the address of a 13 byte array holding 102 bytes which + ** are right justified - ie: the leftmost 2 bits of the first byte do not + ** hold data and must be set to zero. + ** + ** Outputs: + ** return unsigned short - 11 bit Frame Check Sequence (right justified) + ***************************************************************************/ +extern unsigned short USPS_MSB_Math_CRC11GenerateFrameCheckSequence(unsigned char *ByteArrayPtr) { + unsigned short GeneratorPolynomial = 0x0F35; + unsigned short FrameCheckSequence = 0x07FF; + unsigned short Data; + int ByteIndex, Bit; -{ - unsigned short GeneratorPolynomial = 0x0F35; - unsigned short FrameCheckSequence = 0x07FF; - unsigned short Data; - int ByteIndex, Bit; - - /* Do most significant byte skipping the 2 most significant bits */ - Data = *ByteArrayPtr << 5; - ByteArrayPtr++; - for ( Bit = 2; Bit < 8; Bit++ ) - { - if ( (FrameCheckSequence ^ Data) & 0x400 ) - FrameCheckSequence = (FrameCheckSequence << 1) ^ GeneratorPolynomial; - else - FrameCheckSequence = (FrameCheckSequence << 1); - FrameCheckSequence &= 0x7FF; - Data <<= 1; - } - /* Do rest of the bytes */ - for ( ByteIndex = 1; ByteIndex < 13; ByteIndex++ ) - { - Data = *ByteArrayPtr << 3; - ByteArrayPtr++; - for ( Bit = 0; Bit < 8; Bit++ ) - { - if ( (FrameCheckSequence ^ Data) & 0x0400 ) { - FrameCheckSequence = (FrameCheckSequence << 1) ^ GeneratorPolynomial; - } else { - FrameCheckSequence = (FrameCheckSequence << 1); - } - FrameCheckSequence &= 0x7FF; - Data <<= 1; - } - } - return FrameCheckSequence; + /* Do most significant byte skipping the 2 most significant bits */ + Data = *ByteArrayPtr << 5; + ByteArrayPtr++; + for (Bit = 2; Bit < 8; Bit++) { + if ((FrameCheckSequence ^ Data) & 0x400) + FrameCheckSequence = (FrameCheckSequence << 1) ^ GeneratorPolynomial; + else + FrameCheckSequence = (FrameCheckSequence << 1); + FrameCheckSequence &= 0x7FF; + Data <<= 1; + } + /* Do rest of the bytes */ + for (ByteIndex = 1; ByteIndex < 13; ByteIndex++) { + Data = *ByteArrayPtr << 3; + ByteArrayPtr++; + for (Bit = 0; Bit < 8; Bit++) { + if ((FrameCheckSequence ^ Data) & 0x0400) { + FrameCheckSequence = (FrameCheckSequence << 1) ^ GeneratorPolynomial; + } else { + FrameCheckSequence = (FrameCheckSequence << 1); + } + FrameCheckSequence &= 0x7FF; + Data <<= 1; + } + } + return FrameCheckSequence; } -void breakup(short int fcs_bit[], unsigned short usps_crc) -{ - int i; +void breakup(short int fcs_bit[], unsigned short usps_crc) { + int i; - for(i = 0; i < 13; i++) { - fcs_bit[i] = 0; - } + for (i = 0; i < 13; i++) { + fcs_bit[i] = 0; + } - if(usps_crc >= 4096) { - fcs_bit[12] = 1; - usps_crc -= 4096; - } - if(usps_crc >= 2048) { - fcs_bit[11] = 1; - usps_crc -= 2048; - } - if(usps_crc >= 1024) { - fcs_bit[10] = 1; - usps_crc -= 1024; - } - if(usps_crc >= 512) { - fcs_bit[9] = 1; - usps_crc -= 512; - } - if(usps_crc >= 256) { - fcs_bit[8] = 1; - usps_crc -= 256; - } - if(usps_crc >= 128) { - fcs_bit[7] = 1; - usps_crc -= 128; - } - if(usps_crc >= 64) { - fcs_bit[6] = 1; - usps_crc -= 64; - } - if(usps_crc >= 32) { - fcs_bit[5] = 1; - usps_crc -= 32; - } - if(usps_crc >= 16) { - fcs_bit[4] = 1; - usps_crc -= 16; - } - if(usps_crc >= 8) { - fcs_bit[3] = 1; - usps_crc -= 8; - } - if(usps_crc >= 4) { - fcs_bit[2] = 1; - usps_crc -= 4; - } - if(usps_crc >= 2) { - fcs_bit[1] = 1; - usps_crc -= 2; - } - if(usps_crc == 1) { - fcs_bit[0] = 1; - } + if (usps_crc >= 4096) { + fcs_bit[12] = 1; + usps_crc -= 4096; + } + if (usps_crc >= 2048) { + fcs_bit[11] = 1; + usps_crc -= 2048; + } + if (usps_crc >= 1024) { + fcs_bit[10] = 1; + usps_crc -= 1024; + } + if (usps_crc >= 512) { + fcs_bit[9] = 1; + usps_crc -= 512; + } + if (usps_crc >= 256) { + fcs_bit[8] = 1; + usps_crc -= 256; + } + if (usps_crc >= 128) { + fcs_bit[7] = 1; + usps_crc -= 128; + } + if (usps_crc >= 64) { + fcs_bit[6] = 1; + usps_crc -= 64; + } + if (usps_crc >= 32) { + fcs_bit[5] = 1; + usps_crc -= 32; + } + if (usps_crc >= 16) { + fcs_bit[4] = 1; + usps_crc -= 16; + } + if (usps_crc >= 8) { + fcs_bit[3] = 1; + usps_crc -= 8; + } + if (usps_crc >= 4) { + fcs_bit[2] = 1; + usps_crc -= 4; + } + if (usps_crc >= 2) { + fcs_bit[1] = 1; + usps_crc -= 2; + } + if (usps_crc == 1) { + fcs_bit[0] = 1; + } } -int imail(struct zint_symbol *symbol, unsigned char source[], int length) -{ - char data_pattern[200]; - int error_number; - int i, j, read; - char zip[35], tracker[35], zip_adder[11], temp[2]; - short int accum[112], x_reg[112], y_reg[112]; - unsigned char byte_array[13]; - unsigned short usps_crc; - int codeword[10]; - unsigned short characters[10]; - short int bit_pattern[13], bar_map[130]; - - error_number = 0; - - if(length > 32) { - strcpy(symbol->errtxt, "Input too long"); - return ZINT_ERROR_TOO_LONG; - } - error_number = is_sane(SODIUM, source, length); - if(error_number == ZINT_ERROR_INVALID_DATA) { - strcpy(symbol->errtxt, "Invalid characters in data"); - return error_number; - } - - strcpy(zip, ""); - strcpy(tracker, ""); - - /* separate the tracking code from the routing code */ - - read = 0; - j = 0; - for(i = 0; i < length; i++) { - if(source[i] == '-') { - tracker[read] = '\0'; - j = 1; - read = 0; - } else { - if(j == 0) { - /* reading tracker */ - tracker[read] = source[i]; - read++; - } else { - /* reading zip code */ - zip[read] = source[i]; - read++; - } - } - } - if(j == 0) { - tracker[read] = '\0'; - } else { - zip[read] = '\0'; - } - - if(strlen(tracker) != 20) { - strcpy(symbol->errtxt, "Invalid length tracking code"); - return ZINT_ERROR_INVALID_DATA; - } - if(strlen(zip) > 11) { - strcpy(symbol->errtxt, "Invalid ZIP code"); - return ZINT_ERROR_INVALID_DATA; - } - - /* *** Step 1 - Conversion of Data Fields into Binary Data *** */ - - /* Routing code first */ - - for(i = 0; i < 112; i++) { - accum[i] = 0; - } - - for(read = 0; read < strlen(zip); read++) { - - for(i = 0; i < 112; i++) { - x_reg[i] = accum[i]; - } - - for(i = 0; i < 9; i++) { - binary_add(accum, x_reg); - } - - x_reg[0] = BCD[ctoi(zip[read]) * 4]; - x_reg[1] = BCD[(ctoi(zip[read]) * 4) + 1]; - x_reg[2] = BCD[(ctoi(zip[read]) * 4) + 2]; - x_reg[3] = BCD[(ctoi(zip[read]) * 4) + 3]; - for(i = 4; i < 112; i++) { - x_reg[i] = 0; - } - - binary_add(accum, x_reg); - } - - /* add weight to routing code */ - - for(i = 0; i < 112; i++) { - x_reg[i] = accum[i]; - } - - if(strlen(zip) > 9) { - strcpy(zip_adder, "1000100001"); - } else { - if(strlen(zip) > 5) { - strcpy(zip_adder, "100001"); - } else { - if(strlen(zip) > 0) { - strcpy(zip_adder, "1"); - } else { - strcpy(zip_adder, "0"); - } - } - } - - for(i = 0; i < 112; i++) { - accum[i] = 0; - } - - for(read = 0; read < strlen(zip_adder); read++) { - - for(i = 0; i < 112; i++) { - y_reg[i] = accum[i]; - } - - for(i = 0; i < 9; i++) { - binary_add(accum, y_reg); - } - - y_reg[0] = BCD[ctoi(zip_adder[read]) * 4]; - y_reg[1] = BCD[(ctoi(zip_adder[read]) * 4) + 1]; - y_reg[2] = BCD[(ctoi(zip_adder[read]) * 4) + 2]; - y_reg[3] = BCD[(ctoi(zip_adder[read]) * 4) + 3]; - for(i = 4; i < 112; i++) { - y_reg[i] = 0; - } - - binary_add(accum, y_reg); - } - - binary_add(accum, x_reg); - - /* tracking code */ - - /* multiply by 10 */ - for(i = 0; i < 112; i++) { - y_reg[i] = accum[i]; - } - - for(i = 0; i < 9; i++) { - binary_add(accum, y_reg); - } - - /* add first digit of tracker */ - y_reg[0] = BCD[ctoi(tracker[0]) * 4]; - y_reg[1] = BCD[(ctoi(tracker[0]) * 4) + 1]; - y_reg[2] = BCD[(ctoi(tracker[0]) * 4) + 2]; - y_reg[3] = BCD[(ctoi(tracker[0]) * 4) + 3]; - for(i = 4; i < 112; i++) { - y_reg[i] = 0; - } - - binary_add(accum, y_reg); - - /* multiply by 5 */ - for(i = 0; i < 112; i++) { - y_reg[i] = accum[i]; - } - - for(i = 0; i < 4; i++) { - binary_add(accum, y_reg); - } - - /* add second digit */ - y_reg[0] = BCD[ctoi(tracker[1]) * 4]; - y_reg[1] = BCD[(ctoi(tracker[1]) * 4) + 1]; - y_reg[2] = BCD[(ctoi(tracker[1]) * 4) + 2]; - y_reg[3] = BCD[(ctoi(tracker[1]) * 4) + 3]; - for(i = 4; i < 112; i++) { - y_reg[i] = 0; - } - - binary_add(accum, y_reg); - - /* and then the rest */ - - for(read = 2; read < strlen(tracker); read++) { - - for(i = 0; i < 112; i++) { - y_reg[i] = accum[i]; - } - - for(i = 0; i < 9; i++) { - binary_add(accum, y_reg); - } - - y_reg[0] = BCD[ctoi(tracker[read]) * 4]; - y_reg[1] = BCD[(ctoi(tracker[read]) * 4) + 1]; - y_reg[2] = BCD[(ctoi(tracker[read]) * 4) + 2]; - y_reg[3] = BCD[(ctoi(tracker[read]) * 4) + 3]; - for(i = 4; i < 112; i++) { - y_reg[i] = 0; - } - - binary_add(accum, y_reg); - } - - /* printf("Binary data 1: "); - hex_dump(accum); */ - - /* *** Step 2 - Generation of 11-bit CRC on Binary Data *** */ - - accum[103] = 0; - accum[102] = 0; - - memset(byte_array, 0, 13); - for(j = 0; j < 13; j++) { - i = 96 - (8 * j); - byte_array[j] = 0; - byte_array[j] += accum[i]; - byte_array[j] += 2 * accum[i + 1]; - byte_array[j] += 4 * accum[i + 2]; - byte_array[j] += 8 * accum[i + 3]; - byte_array[j] += 16 * accum[i + 4]; - byte_array[j] += 32 * accum[i + 5]; - byte_array[j] += 64 * accum[i + 6]; - byte_array[j] += 128 * accum[i + 7]; - } - - usps_crc = USPS_MSB_Math_CRC11GenerateFrameCheckSequence(byte_array); - /* printf("FCS 2: %4.4X\n", usps_crc); */ - - /* *** Step 3 - Conversion from Binary Data to Codewords *** */ - - /* start with codeword J which is base 636 */ - for(i = 0; i < 112; i++) { - x_reg[i] = 0; - y_reg[i] = 0; - } - - x_reg[101] = 1; - x_reg[98] = 1; - x_reg[97] = 1; - x_reg[96] = 1; - x_reg[95] = 1; - x_reg[94] = 1; - - for(i = 92; i >= 0; i--) { - y_reg[i] = islarger(accum, x_reg); - if(y_reg[i] == 1) { - binary_subtract(accum, x_reg); - } - shiftdown(x_reg); - } - - codeword[9] = (accum[9] * 512) + (accum[8] * 256) + (accum[7] * 128) + (accum[6] * 64) + - (accum[5] * 32) + (accum[4] * 16) + (accum[3] * 8) + (accum[2] * 4) + - (accum[1] * 2) + accum[0]; - - /* then codewords I to B with base 1365 */ - - for(j = 8; j > 0; j--) { - for(i = 0; i < 112; i++) { - accum[i] = y_reg[i]; - y_reg[i] = 0; - x_reg[i] = 0; - } - x_reg[101] = 1; - x_reg[99] = 1; - x_reg[97] = 1; - x_reg[95] = 1; - x_reg[93] = 1; - x_reg[91] = 1; - for(i = 91; i >= 0; i--) { - y_reg[i] = islarger(accum, x_reg); - if(y_reg[i] == 1) { - binary_subtract(accum, x_reg); - } - shiftdown(x_reg); - } - - codeword[j] = (accum[10] * 1024) + (accum[9] * 512) + (accum[8] * 256) + - (accum[7] * 128) + (accum[6] * 64) + (accum[5] * 32) + - (accum[4] * 16) + (accum[3] * 8) + (accum[2] * 4) + - (accum[1] * 2) + accum[0]; - } - - codeword[0] = (y_reg[10] * 1024) + (y_reg[9] * 512) + (y_reg[8] * 256) + - (y_reg[7] * 128) + (y_reg[6] * 64) + (y_reg[5] * 32) + - (y_reg[4] * 16) + (y_reg[3] * 8) + (y_reg[2] * 4) + - (y_reg[1] * 2) + y_reg[0]; - - for(i = 0; i < 8; i++) { - if(codeword[i] == 1365) { - codeword[i] = 0; - codeword[i + 1]++; - } - } - - /* printf("Codewords 3: "); - for(i = 0; i < 10; i++) { - printf("%d ", codeword[i]); - } - printf("\n"); */ - - /* *** Step 4 - Inserting Additional Information into Codewords *** */ - - codeword[9] = codeword[9] * 2; - - if(usps_crc >= 1024) { - codeword[0] += 659; - } - - /* printf("Codewords 4b: "); - for(i = 0; i < 10; i++) { - printf("%d ", codeword[i]); - } - printf("\n"); */ - - /* *** Step 5 - Conversion from Codewords to Characters *** */ - - for(i = 0; i < 10; i++) { - if(codeword[i] < 1287) { - characters[i] = AppxD_I[codeword[i]]; - } else { - characters[i] = AppxD_II[codeword[i] - 1287]; - } - } - - /* printf("Characters 5a: "); - for(i = 0; i < 10; i++) { - printf("%4.4X ", characters[i]); - } - printf("\n"); */ - - breakup(bit_pattern, usps_crc); - - for(i = 0; i < 10; i++) { - if(bit_pattern[i] == 1) { - characters[i] = 0x1FFF - characters[i]; - } - } - - /* printf("Characters 5b: "); - for(i = 0; i < 10; i++) { - printf("%4.4X ", characters[i]); - } - printf("\n"); */ - - /* *** Step 6 - Conversion from Characters to the Intelligent Mail Barcode *** */ - - for(i = 0; i < 10; i++) { - breakup(bit_pattern, characters[i]); - for(j = 0; j < 13; j++) { - bar_map[AppxD_IV[(13 * i) + j] - 1] = bit_pattern[j]; - } - } - - strcpy(data_pattern, ""); - temp[1] = '\0'; - for(i = 0; i < 65; i++) { - j = 0; - if(bar_map[i] == 0) - j += 1; - if(bar_map[i + 65] == 0) - j += 2; - temp[0] = itoc(j); - concat(data_pattern, temp); - } - - /* Translate 4-state data pattern to symbol */ - read = 0; - for(i = 0; i < strlen(data_pattern); i++) - { - if((data_pattern[i] == '1') || (data_pattern[i] == '0')) - { - set_module(symbol, 0, read); - } - set_module(symbol, 1, read); - if((data_pattern[i] == '2') || (data_pattern[i] == '0')) - { - set_module(symbol, 2, read); - } - read += 2; - } - - symbol->row_height[0] = 3; - symbol->row_height[1] = 2; - symbol->row_height[2] = 3; - - symbol->rows = 3; - symbol->width = read - 1; - return error_number; +int imail(struct zint_symbol *symbol, unsigned char source[], int length) { + char data_pattern[200]; + int error_number; + int i, j, read; + char zip[35], tracker[35], zip_adder[11], temp[2]; + short int accum[112], x_reg[112], y_reg[112]; + unsigned char byte_array[13]; + unsigned short usps_crc; + int codeword[10]; + unsigned short characters[10]; + short int bit_pattern[13], bar_map[130]; + + error_number = 0; + + if (length > 32) { + strcpy(symbol->errtxt, "Input too long"); + return ZINT_ERROR_TOO_LONG; + } + error_number = is_sane(SODIUM, source, length); + if (error_number == ZINT_ERROR_INVALID_DATA) { + strcpy(symbol->errtxt, "Invalid characters in data"); + return error_number; + } + + strcpy(zip, ""); + strcpy(tracker, ""); + + /* separate the tracking code from the routing code */ + + read = 0; + j = 0; + for (i = 0; i < length; i++) { + if (source[i] == '-') { + tracker[read] = '\0'; + j = 1; + read = 0; + } else { + if (j == 0) { + /* reading tracker */ + tracker[read] = source[i]; + read++; + } else { + /* reading zip code */ + zip[read] = source[i]; + read++; + } + } + } + if (j == 0) { + tracker[read] = '\0'; + } else { + zip[read] = '\0'; + } + + if (strlen(tracker) != 20) { + strcpy(symbol->errtxt, "Invalid length tracking code"); + return ZINT_ERROR_INVALID_DATA; + } + if (strlen(zip) > 11) { + strcpy(symbol->errtxt, "Invalid ZIP code"); + return ZINT_ERROR_INVALID_DATA; + } + + /* *** Step 1 - Conversion of Data Fields into Binary Data *** */ + + /* Routing code first */ + + for (i = 0; i < 112; i++) { + accum[i] = 0; + } + + for (read = 0; read < strlen(zip); read++) { + + for (i = 0; i < 112; i++) { + x_reg[i] = accum[i]; + } + + for (i = 0; i < 9; i++) { + binary_add(accum, x_reg); + } + + x_reg[0] = BCD[ctoi(zip[read]) * 4]; + x_reg[1] = BCD[(ctoi(zip[read]) * 4) + 1]; + x_reg[2] = BCD[(ctoi(zip[read]) * 4) + 2]; + x_reg[3] = BCD[(ctoi(zip[read]) * 4) + 3]; + for (i = 4; i < 112; i++) { + x_reg[i] = 0; + } + + binary_add(accum, x_reg); + } + + /* add weight to routing code */ + + for (i = 0; i < 112; i++) { + x_reg[i] = accum[i]; + } + + if (strlen(zip) > 9) { + strcpy(zip_adder, "1000100001"); + } else { + if (strlen(zip) > 5) { + strcpy(zip_adder, "100001"); + } else { + if (strlen(zip) > 0) { + strcpy(zip_adder, "1"); + } else { + strcpy(zip_adder, "0"); + } + } + } + + for (i = 0; i < 112; i++) { + accum[i] = 0; + } + + for (read = 0; read < strlen(zip_adder); read++) { + + for (i = 0; i < 112; i++) { + y_reg[i] = accum[i]; + } + + for (i = 0; i < 9; i++) { + binary_add(accum, y_reg); + } + + y_reg[0] = BCD[ctoi(zip_adder[read]) * 4]; + y_reg[1] = BCD[(ctoi(zip_adder[read]) * 4) + 1]; + y_reg[2] = BCD[(ctoi(zip_adder[read]) * 4) + 2]; + y_reg[3] = BCD[(ctoi(zip_adder[read]) * 4) + 3]; + for (i = 4; i < 112; i++) { + y_reg[i] = 0; + } + + binary_add(accum, y_reg); + } + + binary_add(accum, x_reg); + + /* tracking code */ + + /* multiply by 10 */ + for (i = 0; i < 112; i++) { + y_reg[i] = accum[i]; + } + + for (i = 0; i < 9; i++) { + binary_add(accum, y_reg); + } + + /* add first digit of tracker */ + y_reg[0] = BCD[ctoi(tracker[0]) * 4]; + y_reg[1] = BCD[(ctoi(tracker[0]) * 4) + 1]; + y_reg[2] = BCD[(ctoi(tracker[0]) * 4) + 2]; + y_reg[3] = BCD[(ctoi(tracker[0]) * 4) + 3]; + for (i = 4; i < 112; i++) { + y_reg[i] = 0; + } + + binary_add(accum, y_reg); + + /* multiply by 5 */ + for (i = 0; i < 112; i++) { + y_reg[i] = accum[i]; + } + + for (i = 0; i < 4; i++) { + binary_add(accum, y_reg); + } + + /* add second digit */ + y_reg[0] = BCD[ctoi(tracker[1]) * 4]; + y_reg[1] = BCD[(ctoi(tracker[1]) * 4) + 1]; + y_reg[2] = BCD[(ctoi(tracker[1]) * 4) + 2]; + y_reg[3] = BCD[(ctoi(tracker[1]) * 4) + 3]; + for (i = 4; i < 112; i++) { + y_reg[i] = 0; + } + + binary_add(accum, y_reg); + + /* and then the rest */ + + for (read = 2; read < strlen(tracker); read++) { + + for (i = 0; i < 112; i++) { + y_reg[i] = accum[i]; + } + + for (i = 0; i < 9; i++) { + binary_add(accum, y_reg); + } + + y_reg[0] = BCD[ctoi(tracker[read]) * 4]; + y_reg[1] = BCD[(ctoi(tracker[read]) * 4) + 1]; + y_reg[2] = BCD[(ctoi(tracker[read]) * 4) + 2]; + y_reg[3] = BCD[(ctoi(tracker[read]) * 4) + 3]; + for (i = 4; i < 112; i++) { + y_reg[i] = 0; + } + + binary_add(accum, y_reg); + } + + /* *** Step 2 - Generation of 11-bit CRC on Binary Data *** */ + + accum[103] = 0; + accum[102] = 0; + + memset(byte_array, 0, 13); + for (j = 0; j < 13; j++) { + i = 96 - (8 * j); + byte_array[j] = 0; + byte_array[j] += accum[i]; + byte_array[j] += 2 * accum[i + 1]; + byte_array[j] += 4 * accum[i + 2]; + byte_array[j] += 8 * accum[i + 3]; + byte_array[j] += 16 * accum[i + 4]; + byte_array[j] += 32 * accum[i + 5]; + byte_array[j] += 64 * accum[i + 6]; + byte_array[j] += 128 * accum[i + 7]; + } + + usps_crc = USPS_MSB_Math_CRC11GenerateFrameCheckSequence(byte_array); + + /* *** Step 3 - Conversion from Binary Data to Codewords *** */ + + /* start with codeword J which is base 636 */ + for (i = 0; i < 112; i++) { + x_reg[i] = 0; + y_reg[i] = 0; + } + + x_reg[101] = 1; + x_reg[98] = 1; + x_reg[97] = 1; + x_reg[96] = 1; + x_reg[95] = 1; + x_reg[94] = 1; + + for (i = 92; i >= 0; i--) { + y_reg[i] = islarger(accum, x_reg); + if (y_reg[i] == 1) { + binary_subtract(accum, x_reg); + } + shiftdown(x_reg); + } + + codeword[9] = (accum[9] * 512) + (accum[8] * 256) + (accum[7] * 128) + (accum[6] * 64) + + (accum[5] * 32) + (accum[4] * 16) + (accum[3] * 8) + (accum[2] * 4) + + (accum[1] * 2) + accum[0]; + + /* then codewords I to B with base 1365 */ + + for (j = 8; j > 0; j--) { + for (i = 0; i < 112; i++) { + accum[i] = y_reg[i]; + y_reg[i] = 0; + x_reg[i] = 0; + } + x_reg[101] = 1; + x_reg[99] = 1; + x_reg[97] = 1; + x_reg[95] = 1; + x_reg[93] = 1; + x_reg[91] = 1; + for (i = 91; i >= 0; i--) { + y_reg[i] = islarger(accum, x_reg); + if (y_reg[i] == 1) { + binary_subtract(accum, x_reg); + } + shiftdown(x_reg); + } + + codeword[j] = (accum[10] * 1024) + (accum[9] * 512) + (accum[8] * 256) + + (accum[7] * 128) + (accum[6] * 64) + (accum[5] * 32) + + (accum[4] * 16) + (accum[3] * 8) + (accum[2] * 4) + + (accum[1] * 2) + accum[0]; + } + + codeword[0] = (y_reg[10] * 1024) + (y_reg[9] * 512) + (y_reg[8] * 256) + + (y_reg[7] * 128) + (y_reg[6] * 64) + (y_reg[5] * 32) + + (y_reg[4] * 16) + (y_reg[3] * 8) + (y_reg[2] * 4) + + (y_reg[1] * 2) + y_reg[0]; + + for (i = 0; i < 8; i++) { + if (codeword[i] == 1365) { + codeword[i] = 0; + codeword[i + 1]++; + } + } + + /* *** Step 4 - Inserting Additional Information into Codewords *** */ + + codeword[9] = codeword[9] * 2; + + if (usps_crc >= 1024) { + codeword[0] += 659; + } + + /* *** Step 5 - Conversion from Codewords to Characters *** */ + + for (i = 0; i < 10; i++) { + if (codeword[i] < 1287) { + characters[i] = AppxD_I[codeword[i]]; + } else { + characters[i] = AppxD_II[codeword[i] - 1287]; + } + } + + breakup(bit_pattern, usps_crc); + + for (i = 0; i < 10; i++) { + if (bit_pattern[i] == 1) { + characters[i] = 0x1FFF - characters[i]; + } + } + + /* *** Step 6 - Conversion from Characters to the Intelligent Mail Barcode *** */ + + for (i = 0; i < 10; i++) { + breakup(bit_pattern, characters[i]); + for (j = 0; j < 13; j++) { + bar_map[AppxD_IV[(13 * i) + j] - 1] = bit_pattern[j]; + } + } + + strcpy(data_pattern, ""); + temp[1] = '\0'; + for (i = 0; i < 65; i++) { + j = 0; + if (bar_map[i] == 0) + j += 1; + if (bar_map[i + 65] == 0) + j += 2; + temp[0] = itoc(j); + concat(data_pattern, temp); + } + + /* Translate 4-state data pattern to symbol */ + read = 0; + for (i = 0; i < strlen(data_pattern); i++) { + if ((data_pattern[i] == '1') || (data_pattern[i] == '0')) { + set_module(symbol, 0, read); + } + set_module(symbol, 1, read); + if ((data_pattern[i] == '2') || (data_pattern[i] == '0')) { + set_module(symbol, 2, read); + } + read += 2; + } + + symbol->row_height[0] = 3; + symbol->row_height[1] = 2; + symbol->row_height[2] = 3; + + symbol->rows = 3; + symbol->width = read - 1; + return error_number; } diff --git a/backend/large.c b/backend/large.c index 347b7a24..025eb84f 100644 --- a/backend/large.c +++ b/backend/large.c @@ -2,7 +2,7 @@ /* libzint - the open source barcode library - Copyright (C) 2008 Robin Stuart + Copyright (C) 2008-2016 Robin Stuart Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions @@ -28,7 +28,7 @@ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ + */ #include #include @@ -36,203 +36,168 @@ #include "large.h" static const short int BCD[40] = { - 0, 0, 0, 0, - 1, 0, 0, 0, - 0, 1, 0, 0, - 1, 1, 0, 0, - 0, 0, 1, 0, - 1, 0, 1, 0, - 0, 1, 1, 0, - 1, 1, 1, 0, - 0, 0, 0, 1, - 1, 0, 0, 1 }; + 0, 0, 0, 0, + 1, 0, 0, 0, + 0, 1, 0, 0, + 1, 1, 0, 0, + 0, 0, 1, 0, + 1, 0, 1, 0, + 0, 1, 1, 0, + 1, 1, 1, 0, + 0, 0, 0, 1, + 1, 0, 0, 1 +}; -void binary_add(short int accumulator[], short int input_buffer[]) -{ /* Binary addition */ - int i, carry, done; - carry = 0; +void binary_add(short int accumulator[], short int input_buffer[]) { /* Binary addition */ + int i, carry, done; + carry = 0; - for(i = 0; i < 112; i++) { - done = 0; - if(((input_buffer[i] == 0) && (accumulator[i] == 0)) && ((carry == 0) && (done == 0))) { - accumulator[i] = 0; - carry = 0; - done = 1; - } - if(((input_buffer[i] == 0) && (accumulator[i] == 0)) && ((carry == 1) && (done == 0))) { - accumulator[i] = 1; - carry = 0; - done = 1; - } - if(((input_buffer[i] == 0) && (accumulator[i] == 1)) && ((carry == 0) && (done == 0))) { - accumulator[i] = 1; - carry = 0; - done = 1; - } - if(((input_buffer[i] == 0) && (accumulator[i] == 1)) && ((carry == 1) && (done == 0))) { - accumulator[i] = 0; - carry = 1; - done = 1; - } - if(((input_buffer[i] == 1) && (accumulator[i] == 0)) && ((carry == 0) && (done == 0))) { - accumulator[i] = 1; - carry = 0; - done = 1; - } - if(((input_buffer[i] == 1) && (accumulator[i] == 0)) && ((carry == 1) && (done == 0))) { - accumulator[i] = 0; - carry = 1; - done = 1; - } - if(((input_buffer[i] == 1) && (accumulator[i] == 1)) && ((carry == 0) && (done == 0))) { - accumulator[i] = 0; - carry = 1; - done = 1; - } - if(((input_buffer[i] == 1) && (accumulator[i] == 1)) && ((carry == 1) && (done == 0))) { - accumulator[i] = 1; - carry = 1; - done = 1; - } - } + for (i = 0; i < 112; i++) { + done = 0; + if (((input_buffer[i] == 0) && (accumulator[i] == 0)) + && ((carry == 0) && (done == 0))) { + accumulator[i] = 0; + carry = 0; + done = 1; + } + if (((input_buffer[i] == 0) && (accumulator[i] == 0)) + && ((carry == 1) && (done == 0))) { + accumulator[i] = 1; + carry = 0; + done = 1; + } + if (((input_buffer[i] == 0) && (accumulator[i] == 1)) + && ((carry == 0) && (done == 0))) { + accumulator[i] = 1; + carry = 0; + done = 1; + } + if (((input_buffer[i] == 0) && (accumulator[i] == 1)) + && ((carry == 1) && (done == 0))) { + accumulator[i] = 0; + carry = 1; + done = 1; + } + if (((input_buffer[i] == 1) && (accumulator[i] == 0)) + && ((carry == 0) && (done == 0))) { + accumulator[i] = 1; + carry = 0; + done = 1; + } + if (((input_buffer[i] == 1) && (accumulator[i] == 0)) + && ((carry == 1) && (done == 0))) { + accumulator[i] = 0; + carry = 1; + done = 1; + } + if (((input_buffer[i] == 1) && (accumulator[i] == 1)) + && ((carry == 0) && (done == 0))) { + accumulator[i] = 0; + carry = 1; + done = 1; + } + if (((input_buffer[i] == 1) && (accumulator[i] == 1)) + && ((carry == 1) && (done == 0))) { + accumulator[i] = 1; + carry = 1; + done = 1; + } + } } -void binary_subtract(short int accumulator[], short int input_buffer[]) -{ /* 2's compliment subtraction */ - /* take input_buffer from accumulator and put answer in accumulator */ - int i; - short int sub_buffer[112]; +void binary_subtract(short int accumulator[], short int input_buffer[]) { + /* 2's compliment subtraction */ + /* take input_buffer from accumulator and put answer in accumulator */ + int i; + short int sub_buffer[112]; - for(i = 0; i < 112; i++) { - if(input_buffer[i] == 0) { - sub_buffer[i] = 1; - } else { - sub_buffer[i] = 0; - } - } - binary_add(accumulator, sub_buffer); + for (i = 0; i < 112; i++) { + if (input_buffer[i] == 0) { + sub_buffer[i] = 1; + } else { + sub_buffer[i] = 0; + } + } + binary_add(accumulator, sub_buffer); - sub_buffer[0] = 1; + sub_buffer[0] = 1; - for(i = 1; i < 112; i++) { - sub_buffer[i] = 0; - } - binary_add(accumulator, sub_buffer); + for (i = 1; i < 112; i++) { + sub_buffer[i] = 0; + } + binary_add(accumulator, sub_buffer); } -void shiftdown(short int buffer[]) -{ - int i; +void shiftdown(short int buffer[]) { + int i; - buffer[102] = 0; - buffer[103] = 0; + buffer[102] = 0; + buffer[103] = 0; - for(i = 0; i < 102; i++) { - buffer[i] = buffer[i + 1]; - } + for (i = 0; i < 102; i++) { + buffer[i] = buffer[i + 1]; + } } -void shiftup(short int buffer[]) -{ - int i; +void shiftup(short int buffer[]) { + int i; - for(i = 102; i > 0; i--) { - buffer[i] = buffer[i - 1]; - } + for (i = 102; i > 0; i--) { + buffer[i] = buffer[i - 1]; + } - buffer[0] = 0; + buffer[0] = 0; } -short int islarger(short int accum[], short int reg[]) -{ - /* Returns 1 if accum[] is larger than reg[], else 0 */ - int i, latch, larger; - latch = 0; - i = 103; - larger = 0; +short int islarger(short int accum[], short int reg[]) { + /* Returns 1 if accum[] is larger than reg[], else 0 */ + int i, latch, larger; + latch = 0; + i = 103; + larger = 0; - do { - if((accum[i] == 1) && (reg[i] == 0)) { - latch = 1; - larger = 1; - } - if((accum[i] == 0) && (reg[i] == 1)) { - latch = 1; - } - i--; - } while ((latch == 0) && (i >= -1)); + do { + if ((accum[i] == 1) && (reg[i] == 0)) { + latch = 1; + larger = 1; + } + if ((accum[i] == 0) && (reg[i] == 1)) { + latch = 1; + } + i--; + } while ((latch == 0) && (i >= -1)); - return larger; + return larger; } -void binary_load(short int reg[], char data[], const unsigned int src_len) -{ - int read, i; - short int temp[112] = { 0 }; +void binary_load(short int reg[], char data[], const unsigned int src_len) { + int read, i; + short int temp[112] = {0}; - for(i = 0; i < 112; i++) { - reg[i] = 0; - } + for (i = 0; i < 112; i++) { + reg[i] = 0; + } - for(read = 0; read < src_len; read++) { + for (read = 0; read < src_len; read++) { - for(i = 0; i < 112; i++) { - temp[i] = reg[i]; - } + for (i = 0; i < 112; i++) { + temp[i] = reg[i]; + } - for(i = 0; i < 9; i++) { - binary_add(reg, temp); - } + for (i = 0; i < 9; i++) { + binary_add(reg, temp); + } - temp[0] = BCD[ctoi(data[read]) * 4]; - temp[1] = BCD[(ctoi(data[read]) * 4) + 1]; - temp[2] = BCD[(ctoi(data[read]) * 4) + 2]; - temp[3] = BCD[(ctoi(data[read]) * 4) + 3]; - for(i = 4; i < 112; i++) { - temp[i] = 0; - } + temp[0] = BCD[ctoi(data[read]) * 4]; + temp[1] = BCD[(ctoi(data[read]) * 4) + 1]; + temp[2] = BCD[(ctoi(data[read]) * 4) + 2]; + temp[3] = BCD[(ctoi(data[read]) * 4) + 3]; + for (i = 4; i < 112; i++) { + temp[i] = 0; + } - binary_add(reg, temp); - } + binary_add(reg, temp); + } } -void hex_dump(short int input_buffer[]) -{ - int i, digit, byte_space; - - byte_space = 1; - for(i = 100; i >= 0; i-=4) { - digit = 0; - digit += 1 * input_buffer[i]; - digit += 2 * input_buffer[i + 1]; - digit += 4 * input_buffer[i + 2]; - digit += 8 * input_buffer[i + 3]; - - switch(digit) { - case 0: printf("0"); break; - case 1: printf("1"); break; - case 2: printf("2"); break; - case 3: printf("3"); break; - case 4: printf("4"); break; - case 5: printf("5"); break; - case 6: printf("6"); break; - case 7: printf("7"); break; - case 8: printf("8"); break; - case 9: printf("9"); break; - case 10: printf("A"); break; - case 11: printf("B"); break; - case 12: printf("C"); break; - case 13: printf("D"); break; - case 14: printf("E"); break; - case 15: printf("F"); break; - } - if(byte_space == 1) { - byte_space = 0; - } else { - byte_space = 1; - printf(" "); - } - } - printf("\n"); -} diff --git a/backend/large.h b/backend/large.h index 73177fd6..28759524 100644 --- a/backend/large.h +++ b/backend/large.h @@ -2,7 +2,7 @@ /* libzint - the open source barcode library - Copyright (C) 2008 Robin Stuart + Copyright (C) 2008-2016 Robin Stuart Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions @@ -42,7 +42,6 @@ extern void binary_subtract(short int accumulator[], short int input_buffer[]); extern void shiftdown(short int buffer[]); extern void shiftup(short int buffer[]); extern short int islarger(short int accum[], short int reg[]); -extern void hex_dump(short int input_buffer[]); #ifdef __cplusplus } diff --git a/backend/library.c b/backend/library.c index 9d94a5cd..1566aa6c 100755 --- a/backend/library.c +++ b/backend/library.c @@ -1,7 +1,7 @@ /* library.c - external functions of libzint libzint - the open source barcode library - Copyright (C) 2009 Robin Stuart + Copyright (C) 2009-2016 Robin Stuart Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions @@ -27,7 +27,7 @@ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ + */ #include #include @@ -41,94 +41,90 @@ #define TECHNETIUM "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%" -struct zint_symbol *ZBarcode_Create() -{ - struct zint_symbol *symbol; - int i; +struct zint_symbol *ZBarcode_Create() { + struct zint_symbol *symbol; + int i; - symbol = (struct zint_symbol*)malloc(sizeof(*symbol)); - if (!symbol) return NULL; + symbol = (struct zint_symbol*) malloc(sizeof (*symbol)); + if (!symbol) return NULL; - memset(symbol, 0, sizeof(*symbol)); - symbol->symbology = BARCODE_CODE128; - symbol->height = 0; - symbol->whitespace_width = 0; - symbol->border_width = 0; - symbol->output_options = 0; - symbol->rows = 0; - symbol->width = 0; - strcpy(symbol->fgcolour, "000000"); - strcpy(symbol->bgcolour, "ffffff"); - strcpy(symbol->outfile, ""); - symbol->scale = 1.0; - symbol->option_1 = -1; - symbol->option_2 = 0; - symbol->option_3 = 928; // PDF_MAX - symbol->show_hrt = 1; // Show human readable text - symbol->input_mode = DATA_MODE; - strcpy(symbol->primary, ""); - memset(&(symbol->encoded_data[0][0]),0,sizeof(symbol->encoded_data)); - for(i = 0; i < 178; i++) { - symbol->row_height[i] = 0; + memset(symbol, 0, sizeof (*symbol)); + symbol->symbology = BARCODE_CODE128; + symbol->height = 0; + symbol->whitespace_width = 0; + symbol->border_width = 0; + symbol->output_options = 0; + symbol->rows = 0; + symbol->width = 0; + strcpy(symbol->fgcolour, "000000"); + strcpy(symbol->bgcolour, "ffffff"); + strcpy(symbol->outfile, ""); + symbol->scale = 1.0; + symbol->option_1 = -1; + symbol->option_2 = 0; + symbol->option_3 = 928; // PDF_MAX + symbol->show_hrt = 1; // Show human readable text + symbol->input_mode = DATA_MODE; + strcpy(symbol->primary, ""); + memset(&(symbol->encoded_data[0][0]), 0, sizeof (symbol->encoded_data)); + for (i = 0; i < 178; i++) { + symbol->row_height[i] = 0; + } + symbol->bitmap = NULL; + symbol->bitmap_width = 0; + symbol->bitmap_height = 0; + return symbol; +} + +void ZBarcode_Clear(struct zint_symbol *symbol) { + int i, j; + + for (i = 0; i < symbol->rows; i++) { + for (j = 0; j < symbol->width; j++) { + unset_module(symbol, i, j); } - symbol->bitmap = NULL; - symbol->bitmap_width = 0; - symbol->bitmap_height = 0; - return symbol; + } + symbol->rows = 0; + symbol->width = 0; + memset(symbol->text, 0, 128); + symbol->errtxt[0] = '\0'; + if (symbol->bitmap != NULL) { + free(symbol->bitmap); + symbol->bitmap = NULL; + } + symbol->bitmap_width = 0; + symbol->bitmap_height = 0; } -void ZBarcode_Clear(struct zint_symbol *symbol) -{ - int i, j; +void ZBarcode_Delete(struct zint_symbol *symbol) { + if (symbol->bitmap != NULL) + free(symbol->bitmap); - for(i = 0; i < symbol->rows; i++) { - for(j = 0; j < symbol->width; j++) { - unset_module(symbol, i, j); - } - } - symbol->rows = 0; - symbol->width = 0; - memset(symbol->text,0,128); - symbol->errtxt[0] = '\0'; - if (symbol->bitmap != NULL) - { - free(symbol->bitmap); - symbol->bitmap = NULL; - } - symbol->bitmap_width = 0; - symbol->bitmap_height = 0; -} + // If there is a rendered version, ensure its memory is released + if (symbol->rendered != NULL) { + struct zint_render_line *line, *l; + struct zint_render_string *string, *s; -void ZBarcode_Delete(struct zint_symbol *symbol) -{ - if (symbol->bitmap != NULL) - free(symbol->bitmap); + // Free lines + line = symbol->rendered->lines; + while (line) { + l = line; + line = line->next; + free(l); + } + // Free Strings + string = symbol->rendered->strings; + while (string) { + s = string; + string = string->next; + free(s->text); + free(s); + } - // If there is a rendered version, ensure its memory is released - if (symbol->rendered != NULL) { - struct zint_render_line *line, *l; - struct zint_render_string *string, *s; - - // Free lines - line = symbol->rendered->lines; - while(line) { - l = line; - line = line->next; - free(l); - } - // Free Strings - string = symbol->rendered->strings; - while (string) { - s = string; - string = string->next; - free(s->text); - free(s); - } - - // Free Render - free(symbol->rendered); - } - free(symbol); + // Free Render + free(symbol->rendered); + } + free(symbol); } extern int eanx(struct zint_symbol *symbol, unsigned char source[], int length); /* EAN system barcodes */ @@ -196,736 +192,901 @@ extern int bmp_handle(struct zint_symbol *symbol, int rotate_angle); extern int ps_plot(struct zint_symbol *symbol); extern int svg_plot(struct zint_symbol *symbol); -void error_tag(char error_string[], int error_number) -{ - char error_buffer[100]; +void error_tag(char error_string[], int error_number) { + char error_buffer[100]; - if(error_number != 0) { - strcpy(error_buffer, error_string); + if (error_number != 0) { + strcpy(error_buffer, error_string); - if(error_number > 4) { - strcpy(error_string, "error: "); - } else { - strcpy(error_string, "warning: "); - } + if (error_number > 4) { + strcpy(error_string, "error: "); + } else { + strcpy(error_string, "warning: "); + } - concat(error_string, error_buffer); - } + concat(error_string, error_buffer); + } } -int dump_plot(struct zint_symbol *symbol) -{ - /* Output a hexadecimal representation of the rendered symbol */ - FILE *f; - int i, r; - int byt; - char hex[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', - '9', 'A', 'B', 'C', 'D', 'E', 'F'}; - int space = 0; +/* Output a hexadecimal representation of the rendered symbol */ +int dump_plot(struct zint_symbol *symbol) { + FILE *f; + int i, r; + int byt; + char hex[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', + '9', 'A', 'B', 'C', 'D', 'E', 'F'}; + int space = 0; - if(symbol->output_options & BARCODE_STDOUT) { - f = stdout; - } else { - f = fopen(symbol->outfile, "w"); - if(!f) { - strcpy(symbol->errtxt, "Could not open output file"); - return ZINT_ERROR_FILE_ACCESS; - } - } + if (symbol->output_options & BARCODE_STDOUT) { + f = stdout; + } else { + f = fopen(symbol->outfile, "w"); + if (!f) { + strcpy(symbol->errtxt, "Could not open output file"); + return ZINT_ERROR_FILE_ACCESS; + } + } - for (r = 0; r < symbol->rows; r++) { + for (r = 0; r < symbol->rows; r++) { + byt = 0; + for (i = 0; i < symbol->width; i++) { + byt = byt << 1; + if (module_is_set(symbol, r, i)) { + byt += 1; + } + if (((i + 1) % 4) == 0) { + fputc(hex[byt], f); + space++; byt = 0; - for (i = 0; i < symbol->width; i++) { - byt = byt << 1; - if (module_is_set(symbol, r, i)) { - byt += 1; - } - if (((i + 1) % 4) == 0) { - fputc(hex[byt], f); - space++; - byt = 0; - } - if (space == 2) { - fputc(' ', f); - space = 0; - } - } - - if ((symbol->width % 4) != 0) { - byt = byt << (4 - (symbol->width % 4)); - fputc(hex[byt], f); - } - fputs("\n", f); + } + if (space == 2) { + fputc(' ', f); space = 0; - } + } + } - if(symbol->output_options & BARCODE_STDOUT) { - fflush(f); - } else { - fclose(f); - } + if ((symbol->width % 4) != 0) { + byt = byt << (4 - (symbol->width % 4)); + fputc(hex[byt], f); + } + fputs("\n", f); + space = 0; + } - return 0; + if (symbol->output_options & BARCODE_STDOUT) { + fflush(f); + } else { + fclose(f); + } + + return 0; } -int hibc(struct zint_symbol *symbol, unsigned char source[], int length) -{ - int counter, error_number, i; - char to_process[40], temp[2], check_digit; +/* Process health industry bar code data */ +int hibc(struct zint_symbol *symbol, unsigned char source[], int length) { + int counter, error_number, i; + char to_process[40], temp[2], check_digit; - if(length > 36) { - strcpy(symbol->errtxt, "Data too long for HIBC LIC"); - return ZINT_ERROR_TOO_LONG; - } - to_upper(source); - error_number = is_sane(TECHNETIUM , source, length); - if(error_number == ZINT_ERROR_INVALID_DATA) { - strcpy(symbol->errtxt, "Invalid characters in data"); - return error_number; - } + if (length > 36) { + strcpy(symbol->errtxt, "Data too long for HIBC LIC"); + return ZINT_ERROR_TOO_LONG; + } + to_upper(source); + error_number = is_sane(TECHNETIUM, source, length); + if (error_number == ZINT_ERROR_INVALID_DATA) { + strcpy(symbol->errtxt, "Invalid characters in data"); + return error_number; + } - strcpy(to_process, "+"); - counter = 41; - for(i = 0; i < length; i++) { - counter += posn(TECHNETIUM, source[i]); - } - counter = counter % 43; + strcpy(to_process, "+"); + counter = 41; + for (i = 0; i < length; i++) { + counter += posn(TECHNETIUM, source[i]); + } + counter = counter % 43; - if(counter < 10) { - check_digit = itoc(counter); - } else { - if(counter < 36) { - check_digit = (counter - 10) + 'A'; - } else { - switch(counter) { - case 36: check_digit = '-'; break; - case 37: check_digit = '.'; break; - case 38: check_digit = ' '; break; - case 39: check_digit = '$'; break; - case 40: check_digit = '/'; break; - case 41: check_digit = '+'; break; - case 42: check_digit = '%'; break; - default: check_digit = ' '; break; /* Keep compiler happy */ - } - } - } + if (counter < 10) { + check_digit = itoc(counter); + } else { + if (counter < 36) { + check_digit = (counter - 10) + 'A'; + } else { + switch (counter) { + case 36: check_digit = '-'; + break; + case 37: check_digit = '.'; + break; + case 38: check_digit = ' '; + break; + case 39: check_digit = '$'; + break; + case 40: check_digit = '/'; + break; + case 41: check_digit = '+'; + break; + case 42: check_digit = '%'; + break; + default: check_digit = ' '; + break; /* Keep compiler happy */ + } + } + } - temp[0] = check_digit; - temp[1] = '\0'; + temp[0] = check_digit; + temp[1] = '\0'; - concat(to_process, (char *)source); - concat(to_process, temp); - length = strlen(to_process); + concat(to_process, (char *) source); + concat(to_process, temp); + length = strlen(to_process); - switch(symbol->symbology) { - case BARCODE_HIBC_128: - error_number = code_128(symbol, (unsigned char *)to_process, length); - ustrcpy(symbol->text, (unsigned char*)"*"); - uconcat(symbol->text, (unsigned char*)to_process); - uconcat(symbol->text, (unsigned char*)"*"); - break; - case BARCODE_HIBC_39: - symbol->option_2 = 0; - error_number = c39(symbol, (unsigned char *)to_process, length); - ustrcpy(symbol->text, (unsigned char*)"*"); - uconcat(symbol->text, (unsigned char*)to_process); - uconcat(symbol->text, (unsigned char*)"*"); - break; - case BARCODE_HIBC_DM: - error_number = dmatrix(symbol, (unsigned char *)to_process, length); - break; - case BARCODE_HIBC_QR: - error_number = qr_code(symbol, (unsigned char *)to_process, length); - break; - case BARCODE_HIBC_PDF: - error_number = pdf417enc(symbol, (unsigned char *)to_process, length); - break; - case BARCODE_HIBC_MICPDF: - error_number = micro_pdf417(symbol, (unsigned char *)to_process, length); - break; - case BARCODE_HIBC_AZTEC: - error_number = aztec(symbol, (unsigned char *)to_process, length); - break; - } + switch (symbol->symbology) { + case BARCODE_HIBC_128: + error_number = code_128(symbol, (unsigned char *) to_process, length); + ustrcpy(symbol->text, (unsigned char*) "*"); + uconcat(symbol->text, (unsigned char*) to_process); + uconcat(symbol->text, (unsigned char*) "*"); + break; + case BARCODE_HIBC_39: + symbol->option_2 = 0; + error_number = c39(symbol, (unsigned char *) to_process, length); + ustrcpy(symbol->text, (unsigned char*) "*"); + uconcat(symbol->text, (unsigned char*) to_process); + uconcat(symbol->text, (unsigned char*) "*"); + break; + case BARCODE_HIBC_DM: + error_number = dmatrix(symbol, (unsigned char *) to_process, length); + break; + case BARCODE_HIBC_QR: + error_number = qr_code(symbol, (unsigned char *) to_process, length); + break; + case BARCODE_HIBC_PDF: + error_number = pdf417enc(symbol, (unsigned char *) to_process, length); + break; + case BARCODE_HIBC_MICPDF: + error_number = micro_pdf417(symbol, (unsigned char *) to_process, length); + break; + case BARCODE_HIBC_AZTEC: + error_number = aztec(symbol, (unsigned char *) to_process, length); + break; + } - return error_number; + return error_number; } -int gs1_compliant(int symbology) -{ - /* Returns 1 if symbology supports GS1 data */ +int gs1_compliant(int symbology) { + /* Returns 1 if symbology supports GS1 data */ - int result = 0; + int result = 0; - switch(symbology) { - case BARCODE_EAN128: - case BARCODE_RSS_EXP: - case BARCODE_RSS_EXPSTACK: - case BARCODE_EANX_CC: - case BARCODE_EAN128_CC: - case BARCODE_RSS14_CC: - case BARCODE_RSS_LTD_CC: - case BARCODE_RSS_EXP_CC: - case BARCODE_UPCA_CC: - case BARCODE_UPCE_CC: - case BARCODE_RSS14STACK_CC: - case BARCODE_RSS14_OMNI_CC: - case BARCODE_RSS_EXPSTACK_CC: - case BARCODE_CODE16K: - case BARCODE_AZTEC: - case BARCODE_DATAMATRIX: - case BARCODE_CODEONE: - case BARCODE_CODE49: - case BARCODE_QRCODE: - result = 1; - break; - } + switch (symbology) { + case BARCODE_EAN128: + case BARCODE_RSS_EXP: + case BARCODE_RSS_EXPSTACK: + case BARCODE_EANX_CC: + case BARCODE_EAN128_CC: + case BARCODE_RSS14_CC: + case BARCODE_RSS_LTD_CC: + case BARCODE_RSS_EXP_CC: + case BARCODE_UPCA_CC: + case BARCODE_UPCE_CC: + case BARCODE_RSS14STACK_CC: + case BARCODE_RSS14_OMNI_CC: + case BARCODE_RSS_EXPSTACK_CC: + case BARCODE_CODE16K: + case BARCODE_AZTEC: + case BARCODE_DATAMATRIX: + case BARCODE_CODEONE: + case BARCODE_CODE49: + case BARCODE_QRCODE: + result = 1; + break; + } - return result; + return result; } -int ZBarcode_ValidID(int symbol_id) -{ - /* Checks whether a symbology is supported */ +int ZBarcode_ValidID(int symbol_id) { + /* Checks whether a symbology is supported */ - int result = 0; + int result = 0; - switch(symbol_id) { - case BARCODE_CODE11: - case BARCODE_C25MATRIX: - case BARCODE_C25INTER: - case BARCODE_C25IATA: - case BARCODE_C25LOGIC: - case BARCODE_C25IND: - case BARCODE_CODE39: - case BARCODE_EXCODE39: - case BARCODE_EANX: - case BARCODE_EAN128: - case BARCODE_CODABAR: - case BARCODE_CODE128: - case BARCODE_DPLEIT: - case BARCODE_DPIDENT: - case BARCODE_CODE16K: - case BARCODE_CODE49: - case BARCODE_CODE93: - case BARCODE_FLAT: - case BARCODE_RSS14: - case BARCODE_RSS_LTD: - case BARCODE_RSS_EXP: - case BARCODE_TELEPEN: - case BARCODE_UPCA: - case BARCODE_UPCE: - case BARCODE_POSTNET: - case BARCODE_MSI_PLESSEY: - case BARCODE_FIM: - case BARCODE_LOGMARS: - case BARCODE_PHARMA: - case BARCODE_PZN: - case BARCODE_PHARMA_TWO: - case BARCODE_PDF417: - case BARCODE_PDF417TRUNC: - case BARCODE_MAXICODE: - case BARCODE_QRCODE: - case BARCODE_CODE128B: - case BARCODE_AUSPOST: - case BARCODE_AUSREPLY: - case BARCODE_AUSROUTE: - case BARCODE_AUSREDIRECT: - case BARCODE_ISBNX: - case BARCODE_RM4SCC: - case BARCODE_DATAMATRIX: - case BARCODE_EAN14: - case BARCODE_NVE18: - case BARCODE_JAPANPOST: - case BARCODE_KOREAPOST: - case BARCODE_RSS14STACK: - case BARCODE_RSS14STACK_OMNI: - case BARCODE_RSS_EXPSTACK: - case BARCODE_PLANET: - case BARCODE_MICROPDF417: - case BARCODE_ONECODE: - case BARCODE_PLESSEY: - case BARCODE_TELEPEN_NUM: - case BARCODE_ITF14: - case BARCODE_KIX: - case BARCODE_AZTEC: - case BARCODE_DAFT: - case BARCODE_MICROQR: - case BARCODE_HIBC_128: - case BARCODE_HIBC_39: - case BARCODE_HIBC_DM: - case BARCODE_HIBC_QR: - case BARCODE_HIBC_PDF: - case BARCODE_HIBC_MICPDF: - case BARCODE_HIBC_AZTEC: - case BARCODE_AZRUNE: - case BARCODE_CODE32: - case BARCODE_EANX_CC: - case BARCODE_EAN128_CC: - case BARCODE_RSS14_CC: - case BARCODE_RSS_LTD_CC: - case BARCODE_RSS_EXP_CC: - case BARCODE_UPCA_CC: - case BARCODE_UPCE_CC: - case BARCODE_RSS14STACK_CC: - case BARCODE_RSS14_OMNI_CC: - case BARCODE_RSS_EXPSTACK_CC: - case BARCODE_CHANNEL: - case BARCODE_CODEONE: - case BARCODE_GRIDMATRIX: - result = 1; - break; - } + switch (symbol_id) { + case BARCODE_CODE11: + case BARCODE_C25MATRIX: + case BARCODE_C25INTER: + case BARCODE_C25IATA: + case BARCODE_C25LOGIC: + case BARCODE_C25IND: + case BARCODE_CODE39: + case BARCODE_EXCODE39: + case BARCODE_EANX: + case BARCODE_EAN128: + case BARCODE_CODABAR: + case BARCODE_CODE128: + case BARCODE_DPLEIT: + case BARCODE_DPIDENT: + case BARCODE_CODE16K: + case BARCODE_CODE49: + case BARCODE_CODE93: + case BARCODE_FLAT: + case BARCODE_RSS14: + case BARCODE_RSS_LTD: + case BARCODE_RSS_EXP: + case BARCODE_TELEPEN: + case BARCODE_UPCA: + case BARCODE_UPCE: + case BARCODE_POSTNET: + case BARCODE_MSI_PLESSEY: + case BARCODE_FIM: + case BARCODE_LOGMARS: + case BARCODE_PHARMA: + case BARCODE_PZN: + case BARCODE_PHARMA_TWO: + case BARCODE_PDF417: + case BARCODE_PDF417TRUNC: + case BARCODE_MAXICODE: + case BARCODE_QRCODE: + case BARCODE_CODE128B: + case BARCODE_AUSPOST: + case BARCODE_AUSREPLY: + case BARCODE_AUSROUTE: + case BARCODE_AUSREDIRECT: + case BARCODE_ISBNX: + case BARCODE_RM4SCC: + case BARCODE_DATAMATRIX: + case BARCODE_EAN14: + case BARCODE_NVE18: + case BARCODE_JAPANPOST: + case BARCODE_KOREAPOST: + case BARCODE_RSS14STACK: + case BARCODE_RSS14STACK_OMNI: + case BARCODE_RSS_EXPSTACK: + case BARCODE_PLANET: + case BARCODE_MICROPDF417: + case BARCODE_ONECODE: + case BARCODE_PLESSEY: + case BARCODE_TELEPEN_NUM: + case BARCODE_ITF14: + case BARCODE_KIX: + case BARCODE_AZTEC: + case BARCODE_DAFT: + case BARCODE_MICROQR: + case BARCODE_HIBC_128: + case BARCODE_HIBC_39: + case BARCODE_HIBC_DM: + case BARCODE_HIBC_QR: + case BARCODE_HIBC_PDF: + case BARCODE_HIBC_MICPDF: + case BARCODE_HIBC_AZTEC: + case BARCODE_AZRUNE: + case BARCODE_CODE32: + case BARCODE_EANX_CC: + case BARCODE_EAN128_CC: + case BARCODE_RSS14_CC: + case BARCODE_RSS_LTD_CC: + case BARCODE_RSS_EXP_CC: + case BARCODE_UPCA_CC: + case BARCODE_UPCE_CC: + case BARCODE_RSS14STACK_CC: + case BARCODE_RSS14_OMNI_CC: + case BARCODE_RSS_EXPSTACK_CC: + case BARCODE_CHANNEL: + case BARCODE_CODEONE: + case BARCODE_GRIDMATRIX: + result = 1; + break; + } - return result; + return result; } -int extended_charset(struct zint_symbol *symbol, unsigned char *source, int length) -{ - int error_number = 0; +int extended_charset(struct zint_symbol *symbol, unsigned char *source, int length) { + int error_number = 0; - /* These are the "elite" standards which can support multiple character sets */ - switch(symbol->symbology) { - case BARCODE_QRCODE: error_number = qr_code(symbol, source, length); break; - case BARCODE_MICROQR: error_number = microqr(symbol, source, length); break; - case BARCODE_GRIDMATRIX: error_number = grid_matrix(symbol, source, length); break; - } + /* These are the "elite" standards which can support multiple character sets */ + switch (symbol->symbology) { + case BARCODE_QRCODE: error_number = qr_code(symbol, source, length); + break; + case BARCODE_MICROQR: error_number = microqr(symbol, source, length); + break; + case BARCODE_GRIDMATRIX: error_number = grid_matrix(symbol, source, length); + break; + } - return error_number; + return error_number; } -int reduced_charset(struct zint_symbol *symbol, unsigned char *source, int length) -{ - /* These are the "norm" standards which only support Latin-1 at most */ - int error_number = 0; - +int reduced_charset(struct zint_symbol *symbol, unsigned char *source, int length) { + /* These are the "norm" standards which only support Latin-1 at most */ + int error_number = 0; + #ifndef _MSC_VER - unsigned char preprocessed[length + 1]; + unsigned char preprocessed[length + 1]; #else - unsigned char* preprocessed = (unsigned char*)_alloca(length + 1); + unsigned char* preprocessed = (unsigned char*) _alloca(length + 1); #endif - - if(symbol->symbology == BARCODE_CODE16K) { - symbol->whitespace_width = 16; - symbol->border_width = 2; - symbol->output_options = BARCODE_BIND; - } - if(symbol->symbology == BARCODE_ITF14) { - symbol->whitespace_width = 20; - symbol->border_width = 8; - symbol->output_options = BARCODE_BOX; - } + if (symbol->symbology == BARCODE_CODE16K) { + symbol->whitespace_width = 16; + symbol->border_width = 2; + symbol->output_options = BARCODE_BIND; + } - switch(symbol->input_mode) { - case DATA_MODE: - case GS1_MODE: - memcpy(preprocessed, source, length); - preprocessed[length] = '\0'; - break; - case UNICODE_MODE: - error_number = latin1_process(symbol, source, preprocessed, &length); - if(error_number != 0) { return error_number; } - break; - } + if (symbol->symbology == BARCODE_ITF14) { + symbol->whitespace_width = 20; + symbol->border_width = 8; + symbol->output_options = BARCODE_BOX; + } - switch(symbol->symbology) { - case BARCODE_C25MATRIX: error_number = matrix_two_of_five(symbol, preprocessed, length); break; - case BARCODE_C25IND: error_number = industrial_two_of_five(symbol, preprocessed, length); break; - case BARCODE_C25INTER: error_number = interleaved_two_of_five(symbol, preprocessed, length); break; - case BARCODE_C25IATA: error_number = iata_two_of_five(symbol, preprocessed, length); break; - case BARCODE_C25LOGIC: error_number = logic_two_of_five(symbol, preprocessed, length); break; - case BARCODE_DPLEIT: error_number = dpleit(symbol, preprocessed, length); break; - case BARCODE_DPIDENT: error_number = dpident(symbol, preprocessed, length); break; - case BARCODE_UPCA: error_number = eanx(symbol, preprocessed, length); break; - case BARCODE_UPCE: error_number = eanx(symbol, preprocessed, length); break; - case BARCODE_EANX: error_number = eanx(symbol, preprocessed, length); break; - case BARCODE_EAN128: error_number = ean_128(symbol, preprocessed, length); break; - case BARCODE_CODE39: error_number = c39(symbol, preprocessed, length); break; - case BARCODE_PZN: error_number = pharmazentral(symbol, preprocessed, length); break; - case BARCODE_EXCODE39: error_number = ec39(symbol, preprocessed, length); break; - case BARCODE_CODABAR: error_number = codabar(symbol, preprocessed, length); break; - case BARCODE_CODE93: error_number = c93(symbol, preprocessed, length); break; - case BARCODE_LOGMARS: error_number = c39(symbol, preprocessed, length); break; - case BARCODE_CODE128: error_number = code_128(symbol, preprocessed, length); break; - case BARCODE_CODE128B: error_number = code_128(symbol, preprocessed, length); break; - case BARCODE_NVE18: error_number = nve_18(symbol, preprocessed, length); break; - case BARCODE_CODE11: error_number = code_11(symbol, preprocessed, length); break; - case BARCODE_MSI_PLESSEY: error_number = msi_handle(symbol, preprocessed, length); break; - case BARCODE_TELEPEN: error_number = telepen(symbol, preprocessed, length); break; - case BARCODE_TELEPEN_NUM: error_number = telepen_num(symbol, preprocessed, length); break; - case BARCODE_PHARMA: error_number = pharma_one(symbol, preprocessed, length); break; - case BARCODE_PLESSEY: error_number = plessey(symbol, preprocessed, length); break; - case BARCODE_ITF14: error_number = itf14(symbol, preprocessed, length); break; - case BARCODE_FLAT: error_number = flattermarken(symbol, preprocessed, length); break; - case BARCODE_FIM: error_number = fim(symbol, preprocessed, length); break; - case BARCODE_POSTNET: error_number = post_plot(symbol, preprocessed, length); break; - case BARCODE_PLANET: error_number = planet_plot(symbol, preprocessed, length); break; - case BARCODE_RM4SCC: error_number = royal_plot(symbol, preprocessed, length); break; - case BARCODE_AUSPOST: error_number = australia_post(symbol, preprocessed, length); break; - case BARCODE_AUSREPLY: error_number = australia_post(symbol, preprocessed, length); break; - case BARCODE_AUSROUTE: error_number = australia_post(symbol, preprocessed, length); break; - case BARCODE_AUSREDIRECT: error_number = australia_post(symbol, preprocessed, length); break; - case BARCODE_CODE16K: error_number = code16k(symbol, preprocessed, length); break; - case BARCODE_PHARMA_TWO: error_number = pharma_two(symbol, preprocessed, length); break; - case BARCODE_ONECODE: error_number = imail(symbol, preprocessed, length); break; - case BARCODE_ISBNX: error_number = eanx(symbol, preprocessed, length); break; - case BARCODE_RSS14: error_number = rss14(symbol, preprocessed, length); break; - case BARCODE_RSS14STACK: error_number = rss14(symbol, preprocessed, length); break; - case BARCODE_RSS14STACK_OMNI: error_number = rss14(symbol, preprocessed, length); break; - case BARCODE_RSS_LTD: error_number = rsslimited(symbol, preprocessed, length); break; - case BARCODE_RSS_EXP: error_number = rssexpanded(symbol, preprocessed, length); break; - case BARCODE_RSS_EXPSTACK: error_number = rssexpanded(symbol, preprocessed, length); break; - case BARCODE_EANX_CC: error_number = composite(symbol, preprocessed, length); break; - case BARCODE_EAN128_CC: error_number = composite(symbol, preprocessed, length); break; - case BARCODE_RSS14_CC: error_number = composite(symbol, preprocessed, length); break; - case BARCODE_RSS_LTD_CC: error_number = composite(symbol, preprocessed, length); break; - case BARCODE_RSS_EXP_CC: error_number = composite(symbol, preprocessed, length); break; - case BARCODE_UPCA_CC: error_number = composite(symbol, preprocessed, length); break; - case BARCODE_UPCE_CC: error_number = composite(symbol, preprocessed, length); break; - case BARCODE_RSS14STACK_CC: error_number = composite(symbol, preprocessed, length); break; - case BARCODE_RSS14_OMNI_CC: error_number = composite(symbol, preprocessed, length); break; - case BARCODE_RSS_EXPSTACK_CC: error_number = composite(symbol, preprocessed, length); break; - case BARCODE_KIX: error_number = kix_code(symbol, preprocessed, length); break; - case BARCODE_CODE32: error_number = code32(symbol, preprocessed, length); break; - case BARCODE_DAFT: error_number = daft_code(symbol, preprocessed, length); break; - case BARCODE_EAN14: error_number = ean_14(symbol, preprocessed, length); break; - case BARCODE_AZRUNE: error_number = aztec_runes(symbol, preprocessed, length); break; - case BARCODE_KOREAPOST: error_number = korea_post(symbol, preprocessed, length); break; - case BARCODE_HIBC_128: error_number = hibc(symbol, preprocessed, length); break; - case BARCODE_HIBC_39: error_number = hibc(symbol, preprocessed, length); break; - case BARCODE_HIBC_DM: error_number = hibc(symbol, preprocessed, length); break; - case BARCODE_HIBC_QR: error_number = hibc(symbol, preprocessed, length); break; - case BARCODE_HIBC_PDF: error_number = hibc(symbol, preprocessed, length); break; - case BARCODE_HIBC_MICPDF: error_number = hibc(symbol, preprocessed, length); break; - case BARCODE_HIBC_AZTEC: error_number = hibc(symbol, preprocessed, length); break; - case BARCODE_JAPANPOST: error_number = japan_post(symbol, preprocessed, length); break; - case BARCODE_CODE49: error_number = code_49(symbol, preprocessed, length); break; - case BARCODE_CHANNEL: error_number = channel_code(symbol, preprocessed, length); break; - case BARCODE_CODEONE: error_number = code_one(symbol, preprocessed, length); break; - case BARCODE_DATAMATRIX: error_number = dmatrix(symbol, preprocessed, length); break; - case BARCODE_PDF417: error_number = pdf417enc(symbol, preprocessed, length); break; - case BARCODE_PDF417TRUNC: error_number = pdf417enc(symbol, preprocessed, length); break; - case BARCODE_MICROPDF417: error_number = micro_pdf417(symbol, preprocessed, length); break; - case BARCODE_MAXICODE: error_number = maxicode(symbol, preprocessed, length); break; - case BARCODE_AZTEC: error_number = aztec(symbol, preprocessed, length); break; - } + switch (symbol->input_mode) { + case DATA_MODE: + case GS1_MODE: + memcpy(preprocessed, source, length); + preprocessed[length] = '\0'; + break; + case UNICODE_MODE: + error_number = latin1_process(symbol, source, preprocessed, &length); + if (error_number != 0) { + return error_number; + } + break; + } - return error_number; + switch (symbol->symbology) { + case BARCODE_C25MATRIX: error_number = matrix_two_of_five(symbol, preprocessed, length); + break; + case BARCODE_C25IND: error_number = industrial_two_of_five(symbol, preprocessed, length); + break; + case BARCODE_C25INTER: error_number = interleaved_two_of_five(symbol, preprocessed, length); + break; + case BARCODE_C25IATA: error_number = iata_two_of_five(symbol, preprocessed, length); + break; + case BARCODE_C25LOGIC: error_number = logic_two_of_five(symbol, preprocessed, length); + break; + case BARCODE_DPLEIT: error_number = dpleit(symbol, preprocessed, length); + break; + case BARCODE_DPIDENT: error_number = dpident(symbol, preprocessed, length); + break; + case BARCODE_UPCA: error_number = eanx(symbol, preprocessed, length); + break; + case BARCODE_UPCE: error_number = eanx(symbol, preprocessed, length); + break; + case BARCODE_EANX: error_number = eanx(symbol, preprocessed, length); + break; + case BARCODE_EAN128: error_number = ean_128(symbol, preprocessed, length); + break; + case BARCODE_CODE39: error_number = c39(symbol, preprocessed, length); + break; + case BARCODE_PZN: error_number = pharmazentral(symbol, preprocessed, length); + break; + case BARCODE_EXCODE39: error_number = ec39(symbol, preprocessed, length); + break; + case BARCODE_CODABAR: error_number = codabar(symbol, preprocessed, length); + break; + case BARCODE_CODE93: error_number = c93(symbol, preprocessed, length); + break; + case BARCODE_LOGMARS: error_number = c39(symbol, preprocessed, length); + break; + case BARCODE_CODE128: error_number = code_128(symbol, preprocessed, length); + break; + case BARCODE_CODE128B: error_number = code_128(symbol, preprocessed, length); + break; + case BARCODE_NVE18: error_number = nve_18(symbol, preprocessed, length); + break; + case BARCODE_CODE11: error_number = code_11(symbol, preprocessed, length); + break; + case BARCODE_MSI_PLESSEY: error_number = msi_handle(symbol, preprocessed, length); + break; + case BARCODE_TELEPEN: error_number = telepen(symbol, preprocessed, length); + break; + case BARCODE_TELEPEN_NUM: error_number = telepen_num(symbol, preprocessed, length); + break; + case BARCODE_PHARMA: error_number = pharma_one(symbol, preprocessed, length); + break; + case BARCODE_PLESSEY: error_number = plessey(symbol, preprocessed, length); + break; + case BARCODE_ITF14: error_number = itf14(symbol, preprocessed, length); + break; + case BARCODE_FLAT: error_number = flattermarken(symbol, preprocessed, length); + break; + case BARCODE_FIM: error_number = fim(symbol, preprocessed, length); + break; + case BARCODE_POSTNET: error_number = post_plot(symbol, preprocessed, length); + break; + case BARCODE_PLANET: error_number = planet_plot(symbol, preprocessed, length); + break; + case BARCODE_RM4SCC: error_number = royal_plot(symbol, preprocessed, length); + break; + case BARCODE_AUSPOST: error_number = australia_post(symbol, preprocessed, length); + break; + case BARCODE_AUSREPLY: error_number = australia_post(symbol, preprocessed, length); + break; + case BARCODE_AUSROUTE: error_number = australia_post(symbol, preprocessed, length); + break; + case BARCODE_AUSREDIRECT: error_number = australia_post(symbol, preprocessed, length); + break; + case BARCODE_CODE16K: error_number = code16k(symbol, preprocessed, length); + break; + case BARCODE_PHARMA_TWO: error_number = pharma_two(symbol, preprocessed, length); + break; + case BARCODE_ONECODE: error_number = imail(symbol, preprocessed, length); + break; + case BARCODE_ISBNX: error_number = eanx(symbol, preprocessed, length); + break; + case BARCODE_RSS14: error_number = rss14(symbol, preprocessed, length); + break; + case BARCODE_RSS14STACK: error_number = rss14(symbol, preprocessed, length); + break; + case BARCODE_RSS14STACK_OMNI: error_number = rss14(symbol, preprocessed, length); + break; + case BARCODE_RSS_LTD: error_number = rsslimited(symbol, preprocessed, length); + break; + case BARCODE_RSS_EXP: error_number = rssexpanded(symbol, preprocessed, length); + break; + case BARCODE_RSS_EXPSTACK: error_number = rssexpanded(symbol, preprocessed, length); + break; + case BARCODE_EANX_CC: error_number = composite(symbol, preprocessed, length); + break; + case BARCODE_EAN128_CC: error_number = composite(symbol, preprocessed, length); + break; + case BARCODE_RSS14_CC: error_number = composite(symbol, preprocessed, length); + break; + case BARCODE_RSS_LTD_CC: error_number = composite(symbol, preprocessed, length); + break; + case BARCODE_RSS_EXP_CC: error_number = composite(symbol, preprocessed, length); + break; + case BARCODE_UPCA_CC: error_number = composite(symbol, preprocessed, length); + break; + case BARCODE_UPCE_CC: error_number = composite(symbol, preprocessed, length); + break; + case BARCODE_RSS14STACK_CC: error_number = composite(symbol, preprocessed, length); + break; + case BARCODE_RSS14_OMNI_CC: error_number = composite(symbol, preprocessed, length); + break; + case BARCODE_RSS_EXPSTACK_CC: error_number = composite(symbol, preprocessed, length); + break; + case BARCODE_KIX: error_number = kix_code(symbol, preprocessed, length); + break; + case BARCODE_CODE32: error_number = code32(symbol, preprocessed, length); + break; + case BARCODE_DAFT: error_number = daft_code(symbol, preprocessed, length); + break; + case BARCODE_EAN14: error_number = ean_14(symbol, preprocessed, length); + break; + case BARCODE_AZRUNE: error_number = aztec_runes(symbol, preprocessed, length); + break; + case BARCODE_KOREAPOST: error_number = korea_post(symbol, preprocessed, length); + break; + case BARCODE_HIBC_128: error_number = hibc(symbol, preprocessed, length); + break; + case BARCODE_HIBC_39: error_number = hibc(symbol, preprocessed, length); + break; + case BARCODE_HIBC_DM: error_number = hibc(symbol, preprocessed, length); + break; + case BARCODE_HIBC_QR: error_number = hibc(symbol, preprocessed, length); + break; + case BARCODE_HIBC_PDF: error_number = hibc(symbol, preprocessed, length); + break; + case BARCODE_HIBC_MICPDF: error_number = hibc(symbol, preprocessed, length); + break; + case BARCODE_HIBC_AZTEC: error_number = hibc(symbol, preprocessed, length); + break; + case BARCODE_JAPANPOST: error_number = japan_post(symbol, preprocessed, length); + break; + case BARCODE_CODE49: error_number = code_49(symbol, preprocessed, length); + break; + case BARCODE_CHANNEL: error_number = channel_code(symbol, preprocessed, length); + break; + case BARCODE_CODEONE: error_number = code_one(symbol, preprocessed, length); + break; + case BARCODE_DATAMATRIX: error_number = dmatrix(symbol, preprocessed, length); + break; + case BARCODE_PDF417: error_number = pdf417enc(symbol, preprocessed, length); + break; + case BARCODE_PDF417TRUNC: error_number = pdf417enc(symbol, preprocessed, length); + break; + case BARCODE_MICROPDF417: error_number = micro_pdf417(symbol, preprocessed, length); + break; + case BARCODE_MAXICODE: error_number = maxicode(symbol, preprocessed, length); + break; + case BARCODE_AZTEC: error_number = aztec(symbol, preprocessed, length); + break; + } + + return error_number; } -int ZBarcode_Encode(struct zint_symbol *symbol, unsigned char *source, int length) -{ - int error_number, error_buffer, i; +int ZBarcode_Encode(struct zint_symbol *symbol, unsigned char *source, int length) { + int error_number, error_buffer, i; #ifdef _MSC_VER - unsigned char* local_source; + unsigned char* local_source; #endif - error_number = 0; + error_number = 0; - if(length == 0) { - length = ustrlen(source); - } - if(length == 0) { - strcpy(symbol->errtxt, "No input data"); - error_tag(symbol->errtxt, ZINT_ERROR_INVALID_DATA); - return ZINT_ERROR_INVALID_DATA; - } + if (length == 0) { + length = ustrlen(source); + } + if (length == 0) { + strcpy(symbol->errtxt, "No input data"); + error_tag(symbol->errtxt, ZINT_ERROR_INVALID_DATA); + return ZINT_ERROR_INVALID_DATA; + } - if(strcmp(symbol->outfile, "") == 0) { - strcpy(symbol->outfile, "out.png"); - } + if (strcmp(symbol->outfile, "") == 0) { + strcpy(symbol->outfile, "out.png"); + } #ifndef _MSC_VER - unsigned char local_source[length + 1]; + unsigned char local_source[length + 1]; #else - local_source = (unsigned char*)_alloca(length + 1); + local_source = (unsigned char*) _alloca(length + 1); #endif - - /* First check the symbology field */ - if(symbol->symbology < 1) { strcpy(symbol->errtxt, "Symbology out of range, using Code 128"); symbol->symbology = BARCODE_CODE128; error_number = ZINT_WARN_INVALID_OPTION; } - /* symbol->symbologys 1 to 86 are defined by tbarcode */ - if(symbol->symbology == 5) { symbol->symbology = BARCODE_C25MATRIX; } - if((symbol->symbology >= 10) && (symbol->symbology <= 12)) { symbol->symbology = BARCODE_EANX; } - if((symbol->symbology == 14) || (symbol->symbology == 15)) { symbol->symbology = BARCODE_EANX; } - if(symbol->symbology == 17) { symbol->symbology = BARCODE_UPCA; } - if(symbol->symbology == 19) { strcpy(symbol->errtxt, "Codabar 18 not supported, using Codabar"); symbol->symbology = BARCODE_CODABAR; error_number = ZINT_WARN_INVALID_OPTION; } - if(symbol->symbology == 26) { symbol->symbology = BARCODE_UPCA; } - if(symbol->symbology == 27) { strcpy(symbol->errtxt, "UPCD1 not supported"); error_number = ZINT_ERROR_INVALID_OPTION; } - if(symbol->symbology == 33) { symbol->symbology = BARCODE_EAN128; } - if((symbol->symbology == 35) || (symbol->symbology == 36)) { symbol->symbology = BARCODE_UPCA; } - if((symbol->symbology == 38) || (symbol->symbology == 39)) { symbol->symbology = BARCODE_UPCE; } - if((symbol->symbology >= 41) && (symbol->symbology <= 45)) { symbol->symbology = BARCODE_POSTNET; } - if(symbol->symbology == 46) { symbol->symbology = BARCODE_PLESSEY; } - if(symbol->symbology == 48) { symbol->symbology = BARCODE_NVE18; } - if(symbol->symbology == 54) { strcpy(symbol->errtxt, "General Parcel Code not supported, using Code 128"); symbol->symbology = BARCODE_CODE128; error_number = ZINT_WARN_INVALID_OPTION; } - if((symbol->symbology == 59) || (symbol->symbology == 61)) { symbol->symbology = BARCODE_CODE128; } - if(symbol->symbology == 62) { symbol->symbology = BARCODE_CODE93; } - if((symbol->symbology == 64) || (symbol->symbology == 65)) { symbol->symbology = BARCODE_AUSPOST; } - if(symbol->symbology == 73) { strcpy(symbol->errtxt, "Codablock E not supported"); error_number = ZINT_ERROR_INVALID_OPTION; } - if(symbol->symbology == 78) { symbol->symbology = BARCODE_RSS14; } - if(symbol->symbology == 83) { symbol->symbology = BARCODE_PLANET; } - if(symbol->symbology == 88) { symbol->symbology = BARCODE_EAN128; } - if(symbol->symbology == 91) { strcpy(symbol->errtxt, "Symbology out of range, using Code 128"); symbol->symbology = BARCODE_CODE128; error_number = ZINT_WARN_INVALID_OPTION; } - if((symbol->symbology >= 94) && (symbol->symbology <= 96)) { strcpy(symbol->errtxt, "Symbology out of range, using Code 128"); symbol->symbology = BARCODE_CODE128; error_number = ZINT_WARN_INVALID_OPTION; } - if(symbol->symbology == 100) { symbol->symbology = BARCODE_HIBC_128; } - if(symbol->symbology == 101) { symbol->symbology = BARCODE_HIBC_39; } - if(symbol->symbology == 103) { symbol->symbology = BARCODE_HIBC_DM; } - if(symbol->symbology == 105) { symbol->symbology = BARCODE_HIBC_QR; } - if(symbol->symbology == 107) { symbol->symbology = BARCODE_HIBC_PDF; } - if(symbol->symbology == 109) { symbol->symbology = BARCODE_HIBC_MICPDF; } - if(symbol->symbology == 111) { symbol->symbology = BARCODE_HIBC_BLOCKF; } - if((symbol->symbology >= 113) && (symbol->symbology <= 127)) { strcpy(symbol->errtxt, "Symbology out of range, using Code 128"); symbol->symbology = BARCODE_CODE128; error_number = ZINT_WARN_INVALID_OPTION; } - /* Everything from 128 up is Zint-specific */ - if(symbol->symbology >= 143) { strcpy(symbol->errtxt, "Symbology out of range, using Code 128"); symbol->symbology = BARCODE_CODE128; error_number = ZINT_WARN_INVALID_OPTION; } - if((symbol->symbology == BARCODE_CODABLOCKF) || (symbol->symbology == BARCODE_HIBC_BLOCKF)) { strcpy(symbol->errtxt, "Codablock F not supported"); error_number = ZINT_ERROR_INVALID_OPTION; } - - if(error_number > 4) { - error_tag(symbol->errtxt, error_number); - return error_number; - } else { - error_buffer = error_number; - } + /* First check the symbology field */ + if (symbol->symbology < 1) { + strcpy(symbol->errtxt, "Symbology out of range, using Code 128"); + symbol->symbology = BARCODE_CODE128; + error_number = ZINT_WARN_INVALID_OPTION; + } - if((symbol->input_mode < 0) || (symbol->input_mode > 2)) { symbol->input_mode = DATA_MODE; } + /* symbol->symbologys 1 to 86 are defined by tbarcode */ + if (symbol->symbology == 5) { + symbol->symbology = BARCODE_C25MATRIX; + } + if ((symbol->symbology >= 10) && (symbol->symbology <= 12)) { + symbol->symbology = BARCODE_EANX; + } + if ((symbol->symbology == 14) || (symbol->symbology == 15)) { + symbol->symbology = BARCODE_EANX; + } + if (symbol->symbology == 17) { + symbol->symbology = BARCODE_UPCA; + } + if (symbol->symbology == 19) { + strcpy(symbol->errtxt, "Codabar 18 not supported, using Codabar"); + symbol->symbology = BARCODE_CODABAR; + error_number = ZINT_WARN_INVALID_OPTION; + } + if (symbol->symbology == 26) { + symbol->symbology = BARCODE_UPCA; + } + if (symbol->symbology == 27) { + strcpy(symbol->errtxt, "UPCD1 not supported"); + error_number = ZINT_ERROR_INVALID_OPTION; + } + if (symbol->symbology == 33) { + symbol->symbology = BARCODE_EAN128; + } + if ((symbol->symbology == 35) || (symbol->symbology == 36)) { + symbol->symbology = BARCODE_UPCA; + } + if ((symbol->symbology == 38) || (symbol->symbology == 39)) { + symbol->symbology = BARCODE_UPCE; + } + if ((symbol->symbology >= 41) && (symbol->symbology <= 45)) { + symbol->symbology = BARCODE_POSTNET; + } + if (symbol->symbology == 46) { + symbol->symbology = BARCODE_PLESSEY; + } + if (symbol->symbology == 48) { + symbol->symbology = BARCODE_NVE18; + } + if (symbol->symbology == 54) { + strcpy(symbol->errtxt, "General Parcel Code not supported, using Code 128"); + symbol->symbology = BARCODE_CODE128; + error_number = ZINT_WARN_INVALID_OPTION; + } + if ((symbol->symbology == 59) || (symbol->symbology == 61)) { + symbol->symbology = BARCODE_CODE128; + } + if (symbol->symbology == 62) { + symbol->symbology = BARCODE_CODE93; + } + if ((symbol->symbology == 64) || (symbol->symbology == 65)) { + symbol->symbology = BARCODE_AUSPOST; + } + if (symbol->symbology == 73) { + strcpy(symbol->errtxt, "Codablock E not supported"); + error_number = ZINT_ERROR_INVALID_OPTION; + } + if (symbol->symbology == 78) { + symbol->symbology = BARCODE_RSS14; + } + if (symbol->symbology == 83) { + symbol->symbology = BARCODE_PLANET; + } + if (symbol->symbology == 88) { + symbol->symbology = BARCODE_EAN128; + } + if (symbol->symbology == 91) { + strcpy(symbol->errtxt, "Symbology out of range, using Code 128"); + symbol->symbology = BARCODE_CODE128; + error_number = ZINT_WARN_INVALID_OPTION; + } + if ((symbol->symbology >= 94) && (symbol->symbology <= 96)) { + strcpy(symbol->errtxt, "Symbology out of range, using Code 128"); + symbol->symbology = BARCODE_CODE128; + error_number = ZINT_WARN_INVALID_OPTION; + } + if (symbol->symbology == 100) { + symbol->symbology = BARCODE_HIBC_128; + } + if (symbol->symbology == 101) { + symbol->symbology = BARCODE_HIBC_39; + } + if (symbol->symbology == 103) { + symbol->symbology = BARCODE_HIBC_DM; + } + if (symbol->symbology == 105) { + symbol->symbology = BARCODE_HIBC_QR; + } + if (symbol->symbology == 107) { + symbol->symbology = BARCODE_HIBC_PDF; + } + if (symbol->symbology == 109) { + symbol->symbology = BARCODE_HIBC_MICPDF; + } + if (symbol->symbology == 111) { + symbol->symbology = BARCODE_HIBC_BLOCKF; + } + if ((symbol->symbology >= 113) && (symbol->symbology <= 127)) { + strcpy(symbol->errtxt, "Symbology out of range, using Code 128"); + symbol->symbology = BARCODE_CODE128; + error_number = ZINT_WARN_INVALID_OPTION; + } + /* Everything from 128 up is Zint-specific */ + if (symbol->symbology >= 143) { + strcpy(symbol->errtxt, "Symbology out of range, using Code 128"); + symbol->symbology = BARCODE_CODE128; + error_number = ZINT_WARN_INVALID_OPTION; + } + if ((symbol->symbology == BARCODE_CODABLOCKF) || (symbol->symbology == BARCODE_HIBC_BLOCKF)) { + strcpy(symbol->errtxt, "Codablock F not supported"); + error_number = ZINT_ERROR_INVALID_OPTION; + } - if(symbol->input_mode == GS1_MODE) { - for(i = 0; i < length; i++) { - if(source[i] == '\0') { - strcpy(symbol->errtxt, "NULL characters not permitted in GS1 mode"); - return ZINT_ERROR_INVALID_DATA; - } - } - if(gs1_compliant(symbol->symbology) == 1) { - error_number = ugs1_verify(symbol, source, length, local_source); - if(error_number != 0) { return error_number; } - length = ustrlen(local_source); - } else { - strcpy(symbol->errtxt, "Selected symbology does not support GS1 mode"); - return ZINT_ERROR_INVALID_OPTION; - } - } else { - memcpy(local_source, source, length); - local_source[length] = '\0'; - } + if (error_number > 4) { + error_tag(symbol->errtxt, error_number); + return error_number; + } else { + error_buffer = error_number; + } - switch(symbol->symbology) { - case BARCODE_QRCODE: - case BARCODE_MICROQR: - case BARCODE_GRIDMATRIX: - error_number = extended_charset(symbol, local_source, length); - break; - default: - error_number = reduced_charset(symbol, local_source, length); - break; - } + if ((symbol->input_mode < 0) || (symbol->input_mode > 2)) { + symbol->input_mode = DATA_MODE; + } - if((symbol->symbology == BARCODE_CODE128) || (symbol->symbology == BARCODE_CODE128B)) { - for(i = 0; i < length; i++) { - if(local_source[i] == '\0') { - symbol->text[i] = ' '; - } else { - symbol->text[i] = local_source[i]; - } - } - } + if (symbol->input_mode == GS1_MODE) { + for (i = 0; i < length; i++) { + if (source[i] == '\0') { + strcpy(symbol->errtxt, "NULL characters not permitted in GS1 mode"); + return ZINT_ERROR_INVALID_DATA; + } + } + if (gs1_compliant(symbol->symbology) == 1) { + error_number = ugs1_verify(symbol, source, length, local_source); + if (error_number != 0) { + return error_number; + } + length = ustrlen(local_source); + } else { + strcpy(symbol->errtxt, "Selected symbology does not support GS1 mode"); + return ZINT_ERROR_INVALID_OPTION; + } + } else { + memcpy(local_source, source, length); + local_source[length] = '\0'; + } - if(error_number == 0) { - error_number = error_buffer; - } - error_tag(symbol->errtxt, error_number); - /*printf("%s\n",symbol->text);*/ - return error_number; + switch (symbol->symbology) { + case BARCODE_QRCODE: + case BARCODE_MICROQR: + case BARCODE_GRIDMATRIX: + error_number = extended_charset(symbol, local_source, length); + break; + default: + error_number = reduced_charset(symbol, local_source, length); + break; + } + + if ((symbol->symbology == BARCODE_CODE128) || (symbol->symbology == BARCODE_CODE128B)) { + for (i = 0; i < length; i++) { + if (local_source[i] == '\0') { + symbol->text[i] = ' '; + } else { + symbol->text[i] = local_source[i]; + } + } + } + + if (error_number == 0) { + error_number = error_buffer; + } + error_tag(symbol->errtxt, error_number); + return error_number; } -int ZBarcode_Print(struct zint_symbol *symbol, int rotate_angle) -{ - int error_number; - char output[4]; +int ZBarcode_Print(struct zint_symbol *symbol, int rotate_angle) { + int error_number; + char output[4]; - switch(rotate_angle) { - case 0: - case 90: - case 180: - case 270: - break; - default: - strcpy(symbol->errtxt, "Invalid rotation angle"); - return ZINT_ERROR_INVALID_OPTION; - } + switch (rotate_angle) { + case 0: + case 90: + case 180: + case 270: + break; + default: + strcpy(symbol->errtxt, "Invalid rotation angle"); + return ZINT_ERROR_INVALID_OPTION; + } - if(strlen(symbol->outfile) > 3) { - output[0] = symbol->outfile[strlen(symbol->outfile) - 3]; - output[1] = symbol->outfile[strlen(symbol->outfile) - 2]; - output[2] = symbol->outfile[strlen(symbol->outfile) - 1]; - output[3] = '\0'; - to_upper((unsigned char*)output); + if (strlen(symbol->outfile) > 3) { + output[0] = symbol->outfile[strlen(symbol->outfile) - 3]; + output[1] = symbol->outfile[strlen(symbol->outfile) - 2]; + output[2] = symbol->outfile[strlen(symbol->outfile) - 1]; + output[3] = '\0'; + to_upper((unsigned char*) output); #ifndef NO_PNG - if(!(strcmp(output, "PNG"))) { - if(symbol->scale < 1.0) { symbol->text[0] = '\0'; } - error_number = png_handle(symbol, rotate_angle); - } else + if (!(strcmp(output, "PNG"))) { + if (symbol->scale < 1.0) { + symbol->text[0] = '\0'; + } + error_number = png_handle(symbol, rotate_angle); + } else #endif - if(!(strcmp(output, "TXT"))) { - error_number = dump_plot(symbol); - } else - if(!(strcmp(output, "EPS"))) { - error_number = ps_plot(symbol); - } else - if(!(strcmp(output, "SVG"))) { - error_number = svg_plot(symbol); - } else - { - strcpy(symbol->errtxt, "Unknown output format"); - error_tag(symbol->errtxt, ZINT_ERROR_INVALID_OPTION); - return ZINT_ERROR_INVALID_OPTION; - } - } else { - strcpy(symbol->errtxt, "Unknown output format"); - error_tag(symbol->errtxt, ZINT_ERROR_INVALID_OPTION); - return ZINT_ERROR_INVALID_OPTION; - } + if (!(strcmp(output, "TXT"))) { + error_number = dump_plot(symbol); + } else + if (!(strcmp(output, "EPS"))) { + error_number = ps_plot(symbol); + } else + if (!(strcmp(output, "SVG"))) { + error_number = svg_plot(symbol); + } else { + strcpy(symbol->errtxt, "Unknown output format"); + error_tag(symbol->errtxt, ZINT_ERROR_INVALID_OPTION); + return ZINT_ERROR_INVALID_OPTION; + } + } else { + strcpy(symbol->errtxt, "Unknown output format"); + error_tag(symbol->errtxt, ZINT_ERROR_INVALID_OPTION); + return ZINT_ERROR_INVALID_OPTION; + } - error_tag(symbol->errtxt, error_number); - return error_number; + error_tag(symbol->errtxt, error_number); + return error_number; } -int ZBarcode_Buffer(struct zint_symbol *symbol, int rotate_angle) -{ - int error_number; +int ZBarcode_Buffer(struct zint_symbol *symbol, int rotate_angle) { + int error_number; - switch(rotate_angle) { - case 0: - case 90: - case 180: - case 270: - break; - default: - strcpy(symbol->errtxt, "Invalid rotation angle"); - return ZINT_ERROR_INVALID_OPTION; - } + switch (rotate_angle) { + case 0: + case 90: + case 180: + case 270: + break; + default: + strcpy(symbol->errtxt, "Invalid rotation angle"); + return ZINT_ERROR_INVALID_OPTION; + } - error_number = bmp_handle(symbol, rotate_angle); - error_tag(symbol->errtxt, error_number); - return error_number; + error_number = bmp_handle(symbol, rotate_angle); + error_tag(symbol->errtxt, error_number); + return error_number; } -int ZBarcode_Encode_and_Print(struct zint_symbol *symbol, unsigned char *input, int length, int rotate_angle) -{ - int error_number; +int ZBarcode_Encode_and_Print(struct zint_symbol *symbol, unsigned char *input, int length, int rotate_angle) { + int error_number; - error_number = 0; + error_number = 0; - error_number = ZBarcode_Encode(symbol, input, length); - if(error_number != 0) { - return error_number; - } + error_number = ZBarcode_Encode(symbol, input, length); + if (error_number != 0) { + return error_number; + } - error_number = ZBarcode_Print(symbol, rotate_angle); - return error_number; + error_number = ZBarcode_Print(symbol, rotate_angle); + return error_number; } -int ZBarcode_Encode_and_Buffer(struct zint_symbol *symbol, unsigned char *input, int length, int rotate_angle) -{ - int error_number; +int ZBarcode_Encode_and_Buffer(struct zint_symbol *symbol, unsigned char *input, int length, int rotate_angle) { + int error_number; - error_number = 0; + error_number = 0; - error_number = ZBarcode_Encode(symbol, input, length); - if(error_number != 0) { - return error_number; - } + error_number = ZBarcode_Encode(symbol, input, length); + if (error_number != 0) { + return error_number; + } - error_number = ZBarcode_Buffer(symbol, rotate_angle); - return error_number; + error_number = ZBarcode_Buffer(symbol, rotate_angle); + return error_number; } -int ZBarcode_Encode_File(struct zint_symbol *symbol, char *filename) -{ - FILE *file; - unsigned char *buffer; - unsigned long fileLen; - unsigned int nRead = 0, n = 0; - int ret; +int ZBarcode_Encode_File(struct zint_symbol *symbol, char *filename) { + FILE *file; + unsigned char *buffer; + unsigned long fileLen; + unsigned int nRead = 0, n = 0; + int ret; - if (!strcmp(filename, "-")) { - file = stdin; - fileLen = 7100; - } else { - file = fopen(filename, "rb"); - if (!file) { - strcpy(symbol->errtxt, "Unable to read input file"); - return ZINT_ERROR_INVALID_DATA; - } + if (!strcmp(filename, "-")) { + file = stdin; + fileLen = 7100; + } else { + file = fopen(filename, "rb"); + if (!file) { + strcpy(symbol->errtxt, "Unable to read input file"); + return ZINT_ERROR_INVALID_DATA; + } - /* Get file length */ - fseek(file, 0, SEEK_END); - fileLen = ftell(file); - fseek(file, 0, SEEK_SET); + /* Get file length */ + fseek(file, 0, SEEK_END); + fileLen = ftell(file); + fseek(file, 0, SEEK_SET); - if(fileLen > 7100) { - /* The largest amount of data that can be encoded is 7089 numeric digits in QR Code */ - strcpy(symbol->errtxt, "Input file too long"); - fclose(file); - return ZINT_ERROR_INVALID_DATA; - } - } + if (fileLen > 7100) { + /* The largest amount of data that can be encoded is 7089 numeric digits in QR Code */ + strcpy(symbol->errtxt, "Input file too long"); + fclose(file); + return ZINT_ERROR_INVALID_DATA; + } + } - /* Allocate memory */ - buffer = (unsigned char *)malloc(fileLen * sizeof(unsigned char)); - if(!buffer) { - strcpy(symbol->errtxt, "Internal memory error"); + /* Allocate memory */ + buffer = (unsigned char *) malloc(fileLen * sizeof (unsigned char)); + if (!buffer) { + strcpy(symbol->errtxt, "Internal memory error"); if (strcmp(filename, "-")) - fclose(file); - return ZINT_ERROR_MEMORY; - } + fclose(file); + return ZINT_ERROR_MEMORY; + } - /* Read file contents into buffer */ + /* Read file contents into buffer */ - do - { - n = fread(buffer + nRead, 1, fileLen - nRead, file); - if (ferror(file)) - { - strcpy(symbol->errtxt, strerror(errno)); - nRead = 0; - return ZINT_ERROR_INVALID_DATA; - } - nRead += n; - } while (!feof(file) && (0 < n) && (nRead < fileLen)); + do { + n = fread(buffer + nRead, 1, fileLen - nRead, file); + if (ferror(file)) { + strcpy(symbol->errtxt, strerror(errno)); + nRead = 0; + return ZINT_ERROR_INVALID_DATA; + } + nRead += n; + } while (!feof(file) && (0 < n) && (nRead < fileLen)); - fclose(file); - ret = ZBarcode_Encode(symbol, buffer, nRead); - free(buffer); - return ret; + fclose(file); + ret = ZBarcode_Encode(symbol, buffer, nRead); + free(buffer); + return ret; } -int ZBarcode_Encode_File_and_Print(struct zint_symbol *symbol, char *filename, int rotate_angle) -{ - int error_number; +int ZBarcode_Encode_File_and_Print(struct zint_symbol *symbol, char *filename, int rotate_angle) { + int error_number; - error_number = 0; + error_number = 0; - error_number = ZBarcode_Encode_File(symbol, filename); - if(error_number != 0) { - return error_number; - } + error_number = ZBarcode_Encode_File(symbol, filename); + if (error_number != 0) { + return error_number; + } - return ZBarcode_Print(symbol, rotate_angle); + return ZBarcode_Print(symbol, rotate_angle); } -int ZBarcode_Encode_File_and_Buffer(struct zint_symbol *symbol, char *filename, int rotate_angle) -{ - int error_number; +int ZBarcode_Encode_File_and_Buffer(struct zint_symbol *symbol, char *filename, int rotate_angle) { + int error_number; - error_number = 0; + error_number = 0; - error_number = ZBarcode_Encode_File(symbol, filename); - if(error_number != 0) { - return error_number; - } + error_number = ZBarcode_Encode_File(symbol, filename); + if (error_number != 0) { + return error_number; + } - return ZBarcode_Buffer(symbol, rotate_angle); + return ZBarcode_Buffer(symbol, rotate_angle); } /* @@ -938,8 +1099,7 @@ int ZBarcode_Encode_File_and_Buffer(struct zint_symbol *symbol, char *filename, * dimensions. The symbol->scale and symbol->height values are totally ignored in this case. * */ -int ZBarcode_Render(struct zint_symbol *symbol, float width, float height) -{ - // Send the request to the render_plot method - return render_plot(symbol, width, height); +int ZBarcode_Render(struct zint_symbol *symbol, float width, float height) { + // Send the request to the render_plot method + return render_plot(symbol, width, height); } diff --git a/backend/maxicode.c b/backend/maxicode.c index a60d03e2..8b66d6a1 100644 --- a/backend/maxicode.c +++ b/backend/maxicode.c @@ -2,20 +2,20 @@ /* libzint - the open source barcode library - Copyright (C) 2010 Robin Stuart + Copyright (C) 2010-2016 Robin Stuart Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - 1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. + documentation and/or other materials provided with the distribution. 3. Neither the name of the project nor the names of its contributors may be used to endorse or promote products derived from this software - without specific prior written permission. + without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE @@ -26,9 +26,9 @@ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ + */ /* Includes corrections thanks to Monica Swanson @ Source Technologies */ @@ -38,679 +38,681 @@ #include #include #ifdef __APPLE__ -#include +#include #else -#include +#include #endif int maxi_codeword[144]; -void maxi_do_primary_check( ) -{ - /* Handles error correction of primary message */ - unsigned char data[15]; - unsigned char results[15]; - int j; - int datalen = 10; - int ecclen = 10; +/* Handles error correction of primary message */ +void maxi_do_primary_check() { + unsigned char data[15]; + unsigned char results[15]; + int j; + int datalen = 10; + int ecclen = 10; - rs_init_gf(0x43); - rs_init_code(ecclen, 1); + rs_init_gf(0x43); + rs_init_code(ecclen, 1); - for(j = 0; j < datalen; j += 1) - data[j] = maxi_codeword[j]; + for (j = 0; j < datalen; j += 1) + data[j] = maxi_codeword[j]; - rs_encode(datalen, data, results); + rs_encode(datalen, data, results); - for ( j = 0; j < ecclen; j += 1) - maxi_codeword[ datalen + j] = results[ecclen - 1 - j]; - rs_free(); + for (j = 0; j < ecclen; j += 1) + maxi_codeword[ datalen + j] = results[ecclen - 1 - j]; + rs_free(); } -void maxi_do_secondary_chk_odd( int ecclen ) -{ - /* Handles error correction of odd characters in secondary */ - unsigned char data[100]; - unsigned char results[30]; - int j; - int datalen = 68; +/* Handles error correction of odd characters in secondary */ +void maxi_do_secondary_chk_odd(int ecclen) { + unsigned char data[100]; + unsigned char results[30]; + int j; + int datalen = 68; - rs_init_gf(0x43); - rs_init_code(ecclen, 1); + rs_init_gf(0x43); + rs_init_code(ecclen, 1); - if (ecclen == 20) - datalen = 84; + if (ecclen == 20) + datalen = 84; - for(j = 0; j < datalen; j += 1) - if (j & 1) // odd - data[(j-1)/2] = maxi_codeword[j + 20]; + for (j = 0; j < datalen; j += 1) + if (j & 1) // odd + data[(j - 1) / 2] = maxi_codeword[j + 20]; - rs_encode(datalen/2, data, results); + rs_encode(datalen / 2, data, results); - for ( j = 0; j < (ecclen); j += 1) - maxi_codeword[ datalen + (2 *j) + 1 + 20 ] = results[ecclen - 1 - j]; - rs_free(); + for (j = 0; j < (ecclen); j += 1) + maxi_codeword[ datalen + (2 * j) + 1 + 20 ] = results[ecclen - 1 - j]; + rs_free(); } -void maxi_do_secondary_chk_even(int ecclen ) -{ - /* Handles error correction of even characters in secondary */ - unsigned char data[100]; - unsigned char results[30]; - int j; - int datalen = 68; +/* Handles error correction of even characters in secondary */ +void maxi_do_secondary_chk_even(int ecclen) { + unsigned char data[100]; + unsigned char results[30]; + int j; + int datalen = 68; - if (ecclen == 20) - datalen = 84; + if (ecclen == 20) + datalen = 84; - rs_init_gf(0x43); - rs_init_code(ecclen, 1); + rs_init_gf(0x43); + rs_init_code(ecclen, 1); - for(j = 0; j < datalen + 1; j += 1) - if (!(j & 1)) // even - data[j/2] = maxi_codeword[j + 20]; + for (j = 0; j < datalen + 1; j += 1) + if (!(j & 1)) // even + data[j / 2] = maxi_codeword[j + 20]; - rs_encode(datalen/2, data, results); + rs_encode(datalen / 2, data, results); - for ( j = 0; j < (ecclen); j += 1) - maxi_codeword[ datalen + (2 *j) + 20] = results[ecclen - 1 - j]; - rs_free(); + for (j = 0; j < (ecclen); j += 1) + maxi_codeword[ datalen + (2 * j) + 20] = results[ecclen - 1 - j]; + rs_free(); } -void maxi_bump(int set[], int character[], int bump_posn) -{ - /* Moves everything up so that a shift or latch can be inserted */ - int i; +/* Moves everything up so that a shift or latch can be inserted */ +void maxi_bump(int set[], int character[], int bump_posn) { + int i; - for(i = 143; i > bump_posn; i--) { - set[i] = set[i - 1]; - character[i] = character[i - 1]; - } + for (i = 143; i > bump_posn; i--) { + set[i] = set[i - 1]; + character[i] = character[i - 1]; + } } -int maxi_text_process(int mode, unsigned char source[], int length) -{ - /* Format text according to Appendix A */ +/* Format text according to Appendix A */ +int maxi_text_process(int mode, unsigned char source[], int length) { + /* This code doesn't make use of [Lock in C], [Lock in D] + and [Lock in E] and so is not always the most efficient at + compressing data, but should suffice for most applications */ - /* This code doesn't make use of [Lock in C], [Lock in D] - and [Lock in E] and so is not always the most efficient at - compressing data, but should suffice for most applications */ + int set[144], character[144], i, j, done, count, current_set; - int set[144], character[144], i, j, done, count, current_set; + if (length > 138) { + return ZINT_ERROR_TOO_LONG; + } - if(length > 138) { - return ZINT_ERROR_TOO_LONG; - } + for (i = 0; i < 144; i++) { + set[i] = -1; + character[i] = 0; + } - for(i = 0; i < 144; i++) { - set[i] = -1; - character[i] = 0; - } + for (i = 0; i < length; i++) { + /* Look up characters in table from Appendix A - this gives + value and code set for most characters */ + set[i] = maxiCodeSet[source[i]]; + character[i] = maxiSymbolChar[source[i]]; + } - for (i = 0; i < length; i++) { - /* Look up characters in table from Appendix A - this gives - value and code set for most characters */ - set[i] = maxiCodeSet[source[i]]; - character[i] = maxiSymbolChar[source[i]]; - } + /* If a character can be represented in more than one code set, + pick which version to use */ + if (set[0] == 0) { + if (character[0] == 13) { + character[0] = 0; + } + set[0] = 1; + } - /* If a character can be represented in more than one code set, - pick which version to use */ - if(set[0] == 0) { - if(character[0] == 13) { - character[0] = 0; - } - set[0] = 1; - } + for (i = 1; i < length; i++) { + if (set[i] == 0) { + done = 0; + /* Special character */ + if (character[i] == 13) { + /* Carriage Return */ + if (set[i - 1] == 5) { + character[i] = 13; + set[i] = 5; + } else { + if ((i != length - 1) && (set[i + 1] == 5)) { + character[i] = 13; + set[i] = 5; + } else { + character[i] = 0; + set[i] = 1; + } + } + done = 1; + } - for(i = 1; i < length; i++) { - if(set[i] == 0) { - done = 0; - /* Special character */ - if(character[i] == 13) { - /* Carriage Return */ - if(set[i - 1] == 5) { - character[i] = 13; - set[i] = 5; - } else { - if((i != length - 1) && (set[i + 1] == 5)) { - character[i] = 13; - set[i] = 5; - } else { - character[i] = 0; - set[i] = 1; - } - } - done = 1; - } + if ((character[i] == 28) && (done == 0)) { + /* FS */ + if (set[i - 1] == 5) { + character[i] = 32; + set[i] = 5; + } else { + set[i] = set[i - 1]; + } + done = 1; + } - if((character[i] == 28) && (done == 0)) { - /* FS */ - if(set[i - 1] == 5) { - character[i] = 32; - set[i] = 5; - } else { - set[i] = set[i - 1]; - } - done = 1; - } + if ((character[i] == 29) && (done == 0)) { + /* GS */ + if (set[i - 1] == 5) { + character[i] = 33; + set[i] = 5; + } else { + set[i] = set[i - 1]; + } + done = 1; + } - if((character[i] == 29) && (done == 0)) { - /* GS */ - if(set[i - 1] == 5) { - character[i] = 33; - set[i] = 5; - } else { - set[i] = set[i - 1]; - } - done = 1; - } + if ((character[i] == 30) && (done == 0)) { + /* RS */ + if (set[i - 1] == 5) { + character[i] = 34; + set[i] = 5; + } else { + set[i] = set[i - 1]; + } + done = 1; + } - if((character[i] == 30) && (done == 0)) { - /* RS */ - if(set[i - 1] == 5) { - character[i] = 34; - set[i] = 5; - } else { - set[i] = set[i - 1]; - } - done = 1; - } + if ((character[i] == 32) && (done == 0)) { + /* Space */ + if (set[i - 1] == 1) { + character[i] = 32; + set[i] = 1; + } + if (set[i - 1] == 2) { + character[i] = 47; + set[i] = 2; + } + if (set[i - 1] >= 3) { + if (i != length - 1) { + if (set[i + 1] == 1) { + character[i] = 32; + set[i] = 1; + } + if (set[i + 1] == 2) { + character[i] = 47; + set[i] = 2; + } + if (set[i + 1] >= 3) { + character[i] = 59; + set[i] = set[i - 1]; + } + } else { + character[i] = 59; + set[i] = set[i - 1]; + } + } + done = 1; + } - if((character[i] == 32) && (done == 0)) { - /* Space */ - if(set[i - 1] == 1) { - character[i] = 32; - set[i] = 1; - } - if(set[i - 1] == 2) { - character[i] = 47; - set[i] = 2; - } - if(set[i - 1] >= 3) { - if(i != length - 1) { - if(set[i + 1] == 1) { - character[i] = 32; - set[i] = 1; - } - if(set[i + 1] == 2) { - character[i] = 47; - set[i] = 2; - } - if(set[i + 1] >= 3) { - character[i] = 59; - set[i] = set[i - 1]; - } - } else { - character[i] = 59; - set[i] = set[i - 1]; - } - } - done = 1; - } + if ((character[i] == 44) && (done == 0)) { + /* Comma */ + if (set[i - 1] == 2) { + character[i] = 48; + set[i] = 2; + } else { + if ((i != length - 1) && (set[i + 1] == 2)) { + character[i] = 48; + set[i] = 2; + } else { + set[i] = 1; + } + } + done = 1; + } - if((character[i] == 44) && (done == 0)) { - /* Comma */ - if(set[i - 1] == 2) { - character[i] = 48; - set[i] = 2; - } else { - if((i != length - 1) && (set[i + 1] == 2)) { - character[i] = 48; - set[i] = 2; - } else { - set[i] = 1; - } - } - done = 1; - } + if ((character[i] == 46) && (done == 0)) { + /* Full Stop */ + if (set[i - 1] == 2) { + character[i] = 49; + set[i] = 2; + } else { + if ((i != length - 1) && (set[i + 1] == 2)) { + character[i] = 49; + set[i] = 2; + } else { + set[i] = 1; + } + } + done = 1; + } - if((character[i] == 46) && (done == 0)) { - /* Full Stop */ - if(set[i - 1] == 2) { - character[i] = 49; - set[i] = 2; - } else { - if((i != length - 1) && (set[i + 1] == 2)) { - character[i] = 49; - set[i] = 2; - } else { - set[i] = 1; - } - } - done = 1; - } + if ((character[i] == 47) && (done == 0)) { + /* Slash */ + if (set[i - 1] == 2) { + character[i] = 50; + set[i] = 2; + } else { + if ((i != length - 1) && (set[i + 1] == 2)) { + character[i] = 50; + set[i] = 2; + } else { + set[i] = 1; + } + } + done = 1; + } - if((character[i] == 47) && (done == 0)) { - /* Slash */ - if(set[i - 1] == 2) { - character[i] = 50; - set[i] = 2; - } else { - if((i != length - 1) && (set[i + 1] == 2)) { - character[i] = 50; - set[i] = 2; - } else { - set[i] = 1; - } - } - done = 1; - } + if ((character[i] == 58) && (done == 0)) { + /* Colon */ + if (set[i - 1] == 2) { + character[i] = 51; + set[i] = 2; + } else { + if ((i != length - 1) && (set[i + 1] == 2)) { + character[i] = 51; + set[i] = 2; + } else { + set[i] = 1; + } + } + done = 1; + } + } + } - if((character[i] == 58) && (done == 0)) { - /* Colon */ - if(set[i - 1] == 2) { - character[i] = 51; - set[i] = 2; - } else { - if((i != length - 1) && (set[i + 1] == 2)) { - character[i] = 51; - set[i] = 2; - } else { - set[i] = 1; - } - } - done = 1; - } - } - } + for (i = length; i < 144; i++) { + /* Add the padding */ + if (set[length - 1] == 2) { + set[i] = 2; + } else { + set[i] = 1; + } + character[i] = 33; + } - for(i = length; i < 144; i++) { - /* Add the padding */ - if(set[length - 1] == 2) { - set[i] = 2; - } else { - set[i] = 1; - } - character[i] = 33; - } + /* Find candidates for number compression */ + if ((mode == 2) || (mode == 3)) { + j = 0; + } else { + j = 9; + } + /* Number compression not allowed in primary message */ + count = 0; + for (i = j; i < 143; i++) { + if ((set[i] == 1) && ((character[i] >= 48) && (character[i] <= 57))) { + /* Character is a number */ + count++; + } else { + count = 0; + } + if (count == 9) { + /* Nine digits in a row can be compressed */ + set[i] = 6; + set[i - 1] = 6; + set[i - 2] = 6; + set[i - 3] = 6; + set[i - 4] = 6; + set[i - 5] = 6; + set[i - 6] = 6; + set[i - 7] = 6; + set[i - 8] = 6; + count = 0; + } + } - /* Find candidates for number compression */ - if((mode == 2) || (mode ==3)) { j = 0; } else { j = 9; } - /* Number compression not allowed in primary message */ - count = 0; - for(i = j; i < 143; i++) { - if((set[i] == 1) && ((character[i] >= 48) && (character[i] <= 57))) { - /* Character is a number */ - count++; - } else { - count = 0; - } - if(count == 9) { - /* Nine digits in a row can be compressed */ - set[i] = 6; - set[i - 1] = 6; - set[i - 2] = 6; - set[i - 3] = 6; - set[i - 4] = 6; - set[i - 5] = 6; - set[i - 6] = 6; - set[i - 7] = 6; - set[i - 8] = 6; - count = 0; - } - } + /* Add shift and latch characters */ + current_set = 1; + i = 0; + do { - /* Add shift and latch characters */ - current_set = 1; - i = 0; - do { + if ((set[i] != current_set) && (set[i] != 6)) { + switch (set[i]) { + case 1: + if (set[i + 1] == 1) { + if (set[i + 2] == 1) { + if (set[i + 3] == 1) { + /* Latch A */ + maxi_bump(set, character, i); + character[i] = 63; + current_set = 1; + length++; + } else { + /* 3 Shift A */ + maxi_bump(set, character, i); + character[i] = 57; + length++; + i += 2; + } + } else { + /* 2 Shift A */ + maxi_bump(set, character, i); + character[i] = 56; + length++; + i++; + } + } else { + /* Shift A */ + maxi_bump(set, character, i); + character[i] = 59; + length++; + } + break; + case 2: + if (set[i + 1] == 2) { + /* Latch B */ + maxi_bump(set, character, i); + character[i] = 63; + current_set = 2; + length++; + } else { + /* Shift B */ + maxi_bump(set, character, i); + character[i] = 59; + length++; + } + break; + case 3: + /* Shift C */ + maxi_bump(set, character, i); + character[i] = 60; + length++; + break; + case 4: + /* Shift D */ + maxi_bump(set, character, i); + character[i] = 61; + length++; + break; + case 5: + /* Shift E */ + maxi_bump(set, character, i); + character[i] = 62; + length++; + break; + } + i++; + } + i++; + } while (i < 145); - if((set[i] != current_set) && (set[i] != 6)) { - switch(set[i]) { - case 1: - if(set[i + 1] == 1) { - if(set[i + 2] == 1) { - if(set[i + 3] == 1) { - /* Latch A */ - maxi_bump(set, character, i); - character[i] = 63; - current_set = 1; - length++; - } else { - /* 3 Shift A */ - maxi_bump(set, character, i); - character[i] = 57; - length++; - i += 2; - } - } else { - /* 2 Shift A */ - maxi_bump(set, character, i); - character[i] = 56; - length++; - i++; - } - } else { - /* Shift A */ - maxi_bump(set, character, i); - character[i] = 59; - length++; - } - break; - case 2: - if(set[i + 1] == 2) { - /* Latch B */ - maxi_bump(set, character, i); - character[i] = 63; - current_set = 2; - length++; - } else { - /* Shift B */ - maxi_bump(set, character, i); - character[i] = 59; - length++; - } - break; - case 3: - /* Shift C */ - maxi_bump(set, character, i); - character[i] = 60; - length++; - break; - case 4: - /* Shift D */ - maxi_bump(set, character, i); - character[i] = 61; - length++; - break; - case 5: - /* Shift E */ - maxi_bump(set, character, i); - character[i] = 62; - length++; - break; - } - i++; - } - i++; - } while(i < 145); + /* Number compression has not been forgotten! - It's handled below */ + i = 0; + do { + if (set[i] == 6) { + /* Number compression */ + char substring[11]; + int value; - /* Number compression has not been forgotten! - It's handled below */ - i = 0; - do { - if (set[i] == 6) { - /* Number compression */ - char substring[11]; - int value; + for (j = 0; j < 9; j++) { + substring[j] = character[i + j]; + } + substring[9] = '\0'; + value = atoi(substring); - for(j = 0; j < 9; j++) { - substring[j] = character[i + j]; - } - substring[9] = '\0'; - value = atoi(substring); + character[i] = 31; /* NS */ + character[i + 1] = (value & 0x3f000000) >> 24; + character[i + 2] = (value & 0xfc0000) >> 18; + character[i + 3] = (value & 0x3f000) >> 12; + character[i + 4] = (value & 0xfc0) >> 6; + character[i + 5] = (value & 0x3f); - character[i] = 31; /* NS */ - character[i + 1] = (value & 0x3f000000) >> 24; - character[i + 2] = (value & 0xfc0000) >> 18; - character[i + 3] = (value & 0x3f000) >> 12; - character[i + 4] = (value & 0xfc0) >> 6; - character[i + 5] = (value & 0x3f); + i += 6; + for (j = i; j < 140; j++) { + set[j] = set[j + 3]; + character[j] = character[j + 3]; + } + length -= 3; + } else { + i++; + } + } while (i <= 143); - i += 6; - for(j = i; j < 140; j++) { - set[j] = set[j + 3]; - character[j] = character[j + 3]; - } - length -= 3; - } else { - i++; - } - } while (i <= 143); + if (((mode == 2) || (mode == 3)) && (length > 84)) { + return ZINT_ERROR_TOO_LONG; + } - if(((mode ==2) || (mode == 3)) && (length > 84)) { - return ZINT_ERROR_TOO_LONG; - } + if (((mode == 4) || (mode == 6)) && (length > 93)) { + return ZINT_ERROR_TOO_LONG; + } - if(((mode == 4) || (mode == 6)) && (length > 93)) { - return ZINT_ERROR_TOO_LONG; - } - - if((mode == 5) && (length > 77)) { - return ZINT_ERROR_TOO_LONG; - } + if ((mode == 5) && (length > 77)) { + return ZINT_ERROR_TOO_LONG; + } - /* Copy the encoded text into the codeword array */ - if((mode == 2) || (mode == 3)) { - for(i = 0; i < 84; i++) { /* secondary only */ - maxi_codeword[i + 20] = character[i]; - } - } + /* Copy the encoded text into the codeword array */ + if ((mode == 2) || (mode == 3)) { + for (i = 0; i < 84; i++) { /* secondary only */ + maxi_codeword[i + 20] = character[i]; + } + } - if((mode == 4) || (mode == 6)) { - for(i = 0; i < 9; i++) { /* primary */ - maxi_codeword[i + 1] = character[i]; - } - for(i = 0; i < 84; i++) { /* secondary */ - maxi_codeword[i + 20] = character[i + 9]; - } - } + if ((mode == 4) || (mode == 6)) { + for (i = 0; i < 9; i++) { /* primary */ + maxi_codeword[i + 1] = character[i]; + } + for (i = 0; i < 84; i++) { /* secondary */ + maxi_codeword[i + 20] = character[i + 9]; + } + } - if(mode == 5) { - for(i = 0; i < 9; i++) { /* primary */ - maxi_codeword[i + 1] = character[i]; - } - for(i = 0; i < 68; i++) { /* secondary */ - maxi_codeword[i + 20] = character[i + 9]; - } - } + if (mode == 5) { + for (i = 0; i < 9; i++) { /* primary */ + maxi_codeword[i + 1] = character[i]; + } + for (i = 0; i < 68; i++) { /* secondary */ + maxi_codeword[i + 20] = character[i + 9]; + } + } - return 0; + return 0; } -void maxi_do_primary_2(char postcode[], int country, int service) -{ - /* Format structured primary for Mode 2 */ - int postcode_length, postcode_num, i; +/* Format structured primary for Mode 2 */ +void maxi_do_primary_2(char postcode[], int country, int service) { + int postcode_length, postcode_num, i; - for(i = 0; i < 10; i++) { - if((postcode[i] < '0') || (postcode[i] > '9')) { - postcode[i] = '\0'; - } - } + for (i = 0; i < 10; i++) { + if ((postcode[i] < '0') || (postcode[i] > '9')) { + postcode[i] = '\0'; + } + } - postcode_length = strlen(postcode); - postcode_num = atoi(postcode); + postcode_length = strlen(postcode); + postcode_num = atoi(postcode); - maxi_codeword[0] = ((postcode_num & 0x03) << 4) | 2; - maxi_codeword[1] = ((postcode_num & 0xfc) >> 2); - maxi_codeword[2] = ((postcode_num & 0x3f00) >> 8); - maxi_codeword[3] = ((postcode_num & 0xfc000) >> 14); - maxi_codeword[4] = ((postcode_num & 0x3f00000) >> 20); - maxi_codeword[5] = ((postcode_num & 0x3c000000) >> 26) | ((postcode_length & 0x3) << 4); - maxi_codeword[6] = ((postcode_length & 0x3c) >> 2) | ((country & 0x3) << 4); - maxi_codeword[7] = (country & 0xfc) >> 2; - maxi_codeword[8] = ((country & 0x300) >> 8) | ((service & 0xf) << 2); - maxi_codeword[9] = ((service & 0x3f0) >> 4); + maxi_codeword[0] = ((postcode_num & 0x03) << 4) | 2; + maxi_codeword[1] = ((postcode_num & 0xfc) >> 2); + maxi_codeword[2] = ((postcode_num & 0x3f00) >> 8); + maxi_codeword[3] = ((postcode_num & 0xfc000) >> 14); + maxi_codeword[4] = ((postcode_num & 0x3f00000) >> 20); + maxi_codeword[5] = ((postcode_num & 0x3c000000) >> 26) | ((postcode_length & 0x3) << 4); + maxi_codeword[6] = ((postcode_length & 0x3c) >> 2) | ((country & 0x3) << 4); + maxi_codeword[7] = (country & 0xfc) >> 2; + maxi_codeword[8] = ((country & 0x300) >> 8) | ((service & 0xf) << 2); + maxi_codeword[9] = ((service & 0x3f0) >> 4); } -void maxi_do_primary_3(char postcode[], int country, int service) -{ - /* Format structured primary for Mode 3 */ - int i, h; +/* Format structured primary for Mode 3 */ +void maxi_do_primary_3(char postcode[], int country, int service) { + int i, h; - h = strlen(postcode); - to_upper((unsigned char*)postcode); - for(i = 0; i < h; i++) { - if((postcode[i] >= 'A') && (postcode[i] <= 'Z')) { - /* (Capital) letters shifted to Code Set A values */ - postcode[i] -= 64; - } - if(((postcode[i] == 27) || (postcode[i] == 31)) || ((postcode[i] == 33) || (postcode[i] >= 59))) { - /* Not a valid postcode character */ - postcode[i] = ' '; - } - /* Input characters lower than 27 (NUL - SUB) in postcode are - interpreted as capital letters in Code Set A (e.g. LF becomes 'J') */ - } + h = strlen(postcode); + to_upper((unsigned char*) postcode); + for (i = 0; i < h; i++) { + if ((postcode[i] >= 'A') && (postcode[i] <= 'Z')) { + /* (Capital) letters shifted to Code Set A values */ + postcode[i] -= 64; + } + if (((postcode[i] == 27) || (postcode[i] == 31)) || ((postcode[i] == 33) || (postcode[i] >= 59))) { + /* Not a valid postcode character */ + postcode[i] = ' '; + } + /* Input characters lower than 27 (NUL - SUB) in postcode are + interpreted as capital letters in Code Set A (e.g. LF becomes 'J') */ + } - maxi_codeword[0] = ((postcode[5] & 0x03) << 4) | 3; - maxi_codeword[1] = ((postcode[4] & 0x03) << 4) | ((postcode[5] & 0x3c) >> 2); - maxi_codeword[2] = ((postcode[3] & 0x03) << 4) | ((postcode[4] & 0x3c) >> 2); - maxi_codeword[3] = ((postcode[2] & 0x03) << 4) | ((postcode[3] & 0x3c) >> 2); - maxi_codeword[4] = ((postcode[1] & 0x03) << 4) | ((postcode[2] & 0x3c) >> 2); - maxi_codeword[5] = ((postcode[0] & 0x03) << 4) | ((postcode[1] & 0x3c) >> 2); - maxi_codeword[6] = ((postcode[0] & 0x3c) >> 2) | ((country & 0x3) << 4); - maxi_codeword[7] = (country & 0xfc) >> 2; - maxi_codeword[8] = ((country & 0x300) >> 8) | ((service & 0xf) << 2); - maxi_codeword[9] = ((service & 0x3f0) >> 4); + maxi_codeword[0] = ((postcode[5] & 0x03) << 4) | 3; + maxi_codeword[1] = ((postcode[4] & 0x03) << 4) | ((postcode[5] & 0x3c) >> 2); + maxi_codeword[2] = ((postcode[3] & 0x03) << 4) | ((postcode[4] & 0x3c) >> 2); + maxi_codeword[3] = ((postcode[2] & 0x03) << 4) | ((postcode[3] & 0x3c) >> 2); + maxi_codeword[4] = ((postcode[1] & 0x03) << 4) | ((postcode[2] & 0x3c) >> 2); + maxi_codeword[5] = ((postcode[0] & 0x03) << 4) | ((postcode[1] & 0x3c) >> 2); + maxi_codeword[6] = ((postcode[0] & 0x3c) >> 2) | ((country & 0x3) << 4); + maxi_codeword[7] = (country & 0xfc) >> 2; + maxi_codeword[8] = ((country & 0x300) >> 8) | ((service & 0xf) << 2); + maxi_codeword[9] = ((service & 0x3f0) >> 4); } -int maxicode(struct zint_symbol *symbol, unsigned char source[], int length) -{ - int i, j, block, bit, mode, countrycode = 0, service = 0, lp = 0; - int bit_pattern[7], internal_error = 0, eclen, error_number; - char postcode[12], countrystr[4], servicestr[4]; +int maxicode(struct zint_symbol *symbol, unsigned char source[], int length) { + int i, j, block, bit, mode, countrycode = 0, service = 0, lp = 0; + int bit_pattern[7], internal_error = 0, eclen, error_number; + char postcode[12], countrystr[4], servicestr[4]; #ifndef _MSC_VER - unsigned char local_source[length + 1]; + unsigned char local_source[length + 1]; #else - unsigned char* local_source = (unsigned char*)_alloca(length + 1); + unsigned char* local_source = (unsigned char*) _alloca(length + 1); #endif - mode = symbol->option_1; - strcpy(postcode, ""); - strcpy(countrystr, ""); - strcpy(servicestr, ""); + mode = symbol->option_1; + strcpy(postcode, ""); + strcpy(countrystr, ""); + strcpy(servicestr, ""); - /* The following to be replaced by ECI handling */ - switch(symbol->input_mode) { - case DATA_MODE: - case GS1_MODE: - memcpy(local_source, source, length); - local_source[length] = '\0'; - break; - case UNICODE_MODE: - error_number = latin1_process(symbol, source, local_source, &length); - if(error_number != 0) { return error_number; } - break; - } - memset(maxi_codeword, 0, sizeof(maxi_codeword)); + /* The following to be replaced by ECI handling */ + switch (symbol->input_mode) { + case DATA_MODE: + case GS1_MODE: + memcpy(local_source, source, length); + local_source[length] = '\0'; + break; + case UNICODE_MODE: + error_number = latin1_process(symbol, source, local_source, &length); + if (error_number != 0) { + return error_number; + } + break; + } + memset(maxi_codeword, 0, sizeof (maxi_codeword)); - if(mode == -1) { /* If mode is unspecified */ - lp = strlen(symbol->primary); - if(lp == 0) { - mode = 4; - } else { - mode = 2; - for(i = 0; i < 10 && i < lp; i++) { - if((symbol->primary[i] < 48) || (symbol->primary[i] > 57)) { - mode = 3; - break; - } - } - } - } + if (mode == -1) { /* If mode is unspecified */ + lp = strlen(symbol->primary); + if (lp == 0) { + mode = 4; + } else { + mode = 2; + for (i = 0; i < 10 && i < lp; i++) { + if ((symbol->primary[i] < 48) || (symbol->primary[i] > 57)) { + mode = 3; + break; + } + } + } + } - if((mode < 2) || (mode > 6)) { /* Only codes 2 to 6 supported */ - strcpy(symbol->errtxt, "Invalid Maxicode Mode"); - return ZINT_ERROR_INVALID_OPTION; - } + if ((mode < 2) || (mode > 6)) { /* Only codes 2 to 6 supported */ + strcpy(symbol->errtxt, "Invalid Maxicode Mode"); + return ZINT_ERROR_INVALID_OPTION; + } - if((mode == 2) || (mode == 3)) { /* Modes 2 and 3 need data in symbol->primary */ - if(lp == 0){ /* Mode set manually means lp doesn't get set */ - lp = strlen( symbol->primary ); - } - if(lp != 15) { - strcpy(symbol->errtxt, "Invalid Primary String"); - return ZINT_ERROR_INVALID_DATA; - } + if ((mode == 2) || (mode == 3)) { /* Modes 2 and 3 need data in symbol->primary */ + if (lp == 0) { /* Mode set manually means lp doesn't get set */ + lp = strlen(symbol->primary); + } + if (lp != 15) { + strcpy(symbol->errtxt, "Invalid Primary String"); + return ZINT_ERROR_INVALID_DATA; + } - for(i = 9; i < 15; i++) { /* check that country code and service are numeric */ - if((symbol->primary[i] < '0') || (symbol->primary[i] > '9')) { - strcpy(symbol->errtxt, "Invalid Primary String"); - return ZINT_ERROR_INVALID_DATA; - } - } + for (i = 9; i < 15; i++) { /* check that country code and service are numeric */ + if ((symbol->primary[i] < '0') || (symbol->primary[i] > '9')) { + strcpy(symbol->errtxt, "Invalid Primary String"); + return ZINT_ERROR_INVALID_DATA; + } + } - memcpy(postcode, symbol->primary, 9); - postcode[9] = '\0'; + memcpy(postcode, symbol->primary, 9); + postcode[9] = '\0'; - if(mode == 2) { - for(i = 0; i < 10; i++) { - if(postcode[i] == ' ') { - postcode[i] = '\0'; - } - } - } - else if(mode == 3) { postcode[6] = '\0'; } + if (mode == 2) { + for (i = 0; i < 10; i++) { + if (postcode[i] == ' ') { + postcode[i] = '\0'; + } + } + } else if (mode == 3) { + postcode[6] = '\0'; + } - countrystr[0] = symbol->primary[9]; - countrystr[1] = symbol->primary[10]; - countrystr[2] = symbol->primary[11]; - countrystr[3] = '\0'; + countrystr[0] = symbol->primary[9]; + countrystr[1] = symbol->primary[10]; + countrystr[2] = symbol->primary[11]; + countrystr[3] = '\0'; - servicestr[0] = symbol->primary[12]; - servicestr[1] = symbol->primary[13]; - servicestr[2] = symbol->primary[14]; - servicestr[3] = '\0'; + servicestr[0] = symbol->primary[12]; + servicestr[1] = symbol->primary[13]; + servicestr[2] = symbol->primary[14]; + servicestr[3] = '\0'; - countrycode = atoi(countrystr); - service = atoi(servicestr); + countrycode = atoi(countrystr); + service = atoi(servicestr); - if(mode == 2) { maxi_do_primary_2(postcode, countrycode, service); } - if(mode == 3) { maxi_do_primary_3(postcode, countrycode, service); } - } else { - maxi_codeword[0] = mode; - } + if (mode == 2) { + maxi_do_primary_2(postcode, countrycode, service); + } + if (mode == 3) { + maxi_do_primary_3(postcode, countrycode, service); + } + } else { + maxi_codeword[0] = mode; + } - i = maxi_text_process(mode, local_source, length); - if(i == ZINT_ERROR_TOO_LONG ) { - strcpy(symbol->errtxt, "Input data too long"); - return i; - } + i = maxi_text_process(mode, local_source, length); + if (i == ZINT_ERROR_TOO_LONG) { + strcpy(symbol->errtxt, "Input data too long"); + return i; + } - /* All the data is sorted - now do error correction */ - maxi_do_primary_check(); /* always EEC */ + /* All the data is sorted - now do error correction */ + maxi_do_primary_check(); /* always EEC */ - if ( mode == 5 ) - eclen = 56; // 68 data codewords , 56 error corrections - else - eclen = 40; // 84 data codewords, 40 error corrections + if (mode == 5) + eclen = 56; // 68 data codewords , 56 error corrections + else + eclen = 40; // 84 data codewords, 40 error corrections - maxi_do_secondary_chk_even(eclen/2); // do error correction of even - maxi_do_secondary_chk_odd(eclen/2); // do error correction of odd + maxi_do_secondary_chk_even(eclen / 2); // do error correction of even + maxi_do_secondary_chk_odd(eclen / 2); // do error correction of odd - /* Copy data into symbol grid */ - for(i = 0; i < 33; i++) { - for(j = 0; j < 30; j++) { - block = (MaxiGrid[(i * 30) + j] + 5) / 6; - bit = (MaxiGrid[(i * 30) + j] + 5) % 6; + /* Copy data into symbol grid */ + for (i = 0; i < 33; i++) { + for (j = 0; j < 30; j++) { + block = (MaxiGrid[(i * 30) + j] + 5) / 6; + bit = (MaxiGrid[(i * 30) + j] + 5) % 6; - if(block != 0) { + if (block != 0) { - bit_pattern[0] = (maxi_codeword[block - 1] & 0x20) >> 5; - bit_pattern[1] = (maxi_codeword[block - 1] & 0x10) >> 4; - bit_pattern[2] = (maxi_codeword[block - 1] & 0x8) >> 3; - bit_pattern[3] = (maxi_codeword[block - 1] & 0x4) >> 2; - bit_pattern[4] = (maxi_codeword[block - 1] & 0x2) >> 1; - bit_pattern[5] = (maxi_codeword[block - 1] & 0x1); + bit_pattern[0] = (maxi_codeword[block - 1] & 0x20) >> 5; + bit_pattern[1] = (maxi_codeword[block - 1] & 0x10) >> 4; + bit_pattern[2] = (maxi_codeword[block - 1] & 0x8) >> 3; + bit_pattern[3] = (maxi_codeword[block - 1] & 0x4) >> 2; + bit_pattern[4] = (maxi_codeword[block - 1] & 0x2) >> 1; + bit_pattern[5] = (maxi_codeword[block - 1] & 0x1); - if(bit_pattern[bit] != 0) { - set_module(symbol, i, j); - } - } - } - } + if (bit_pattern[bit] != 0) { + set_module(symbol, i, j); + } + } + } + } - /* Add orientation markings */ - set_module(symbol, 0, 28); // Top right filler - set_module(symbol, 0, 29); - set_module(symbol, 9, 10); // Top left marker - set_module(symbol, 9, 11); - set_module(symbol, 10, 11); - set_module(symbol, 15, 7); // Left hand marker - set_module(symbol, 16, 8); - set_module(symbol, 16, 20); // Right hand marker - set_module(symbol, 17, 20); - set_module(symbol, 22, 10); // Bottom left marker - set_module(symbol, 23, 10); - set_module(symbol, 22, 17); // Bottom right marker - set_module(symbol, 23, 17); + /* Add orientation markings */ + set_module(symbol, 0, 28); // Top right filler + set_module(symbol, 0, 29); + set_module(symbol, 9, 10); // Top left marker + set_module(symbol, 9, 11); + set_module(symbol, 10, 11); + set_module(symbol, 15, 7); // Left hand marker + set_module(symbol, 16, 8); + set_module(symbol, 16, 20); // Right hand marker + set_module(symbol, 17, 20); + set_module(symbol, 22, 10); // Bottom left marker + set_module(symbol, 23, 10); + set_module(symbol, 22, 17); // Bottom right marker + set_module(symbol, 23, 17); - symbol->width = 30; - symbol->rows = 33; + symbol->width = 30; + symbol->rows = 33; - return internal_error; + return internal_error; } diff --git a/backend/maxicode.h b/backend/maxicode.h index 60bc1fcf..72b5c185 100644 --- a/backend/maxicode.h +++ b/backend/maxicode.h @@ -2,20 +2,20 @@ /* libzint - the open source barcode library - Copyright (C) 2008 Robin Stuart + Copyright (C) 2008-2016 Robin Stuart Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - 1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. + documentation and/or other materials provided with the distribution. 3. Neither the name of the project nor the names of its contributors may be used to endorse or promote products derived from this software - without specific prior written permission. + without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE @@ -26,76 +26,79 @@ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ + */ -static const int MaxiGrid[] = { /* ISO/IEC 16023 Figure 5 - MaxiCode Module Sequence */ /* 30 x 33 data grid */ - 122, 121, 128, 127, 134, 133, 140, 139, 146, 145, 152, 151, 158, 157, 164, 163, 170, 169, 176, 175, 182, 181, 188, 187, 194, 193, 200, 199, 0, 0, - 124, 123, 130, 129, 136, 135, 142, 141, 148, 147, 154, 153, 160, 159, 166, 165, 172, 171, 178, 177, 184, 183, 190, 189, 196, 195, 202, 201, 817, 0, - 126, 125, 132, 131, 138, 137, 144, 143, 150, 149, 156, 155, 162, 161, 168, 167, 174, 173, 180, 179, 186, 185, 192, 191, 198, 197, 204, 203, 819, 818, - 284, 283, 278, 277, 272, 271, 266, 265, 260, 259, 254, 253, 248, 247, 242, 241, 236, 235, 230, 229, 224, 223, 218, 217, 212, 211, 206, 205, 820, 0, - 286, 285, 280, 279, 274, 273, 268, 267, 262, 261, 256, 255, 250, 249, 244, 243, 238, 237, 232, 231, 226, 225, 220, 219, 214, 213, 208, 207, 822, 821, - 288, 287, 282, 281, 276, 275, 270, 269, 264, 263, 258, 257, 252, 251, 246, 245, 240, 239, 234, 233, 228, 227, 222, 221, 216, 215, 210, 209, 823, 0, - 290, 289, 296, 295, 302, 301, 308, 307, 314, 313, 320, 319, 326, 325, 332, 331, 338, 337, 344, 343, 350, 349, 356, 355, 362, 361, 368, 367, 825, 824, - 292, 291, 298, 297, 304, 303, 310, 309, 316, 315, 322, 321, 328, 327, 334, 333, 340, 339, 346, 345, 352, 351, 358, 357, 364, 363, 370, 369, 826, 0, - 294, 293, 300, 299, 306, 305, 312, 311, 318, 317, 324, 323, 330, 329, 336, 335, 342, 341, 348, 347, 354, 353, 360, 359, 366, 365, 372, 371, 828, 827, - 410, 409, 404, 403, 398, 397, 392, 391, 80, 79, 0, 0, 14, 13, 38, 37, 3, 0, 45, 44, 110, 109, 386, 385, 380, 379, 374, 373, 829, 0, - 412, 411, 406, 405, 400, 399, 394, 393, 82, 81, 41, 0, 16, 15, 40, 39, 4, 0, 0, 46, 112, 111, 388, 387, 382, 381, 376, 375, 831, 830, - 414, 413, 408, 407, 402, 401, 396, 395, 84, 83, 42, 0, 0, 0, 0, 0, 6, 5, 48, 47, 114, 113, 390, 389, 384, 383, 378, 377, 832, 0, - 416, 415, 422, 421, 428, 427, 104, 103, 56, 55, 17, 0, 0, 0, 0, 0, 0, 0, 21, 20, 86, 85, 434, 433, 440, 439, 446, 445, 834, 833, - 418, 417, 424, 423, 430, 429, 106, 105, 58, 57, 0, 0, 0, 0, 0, 0, 0, 0, 23, 22, 88, 87, 436, 435, 442, 441, 448, 447, 835, 0, - 420, 419, 426, 425, 432, 431, 108, 107, 60, 59, 0, 0, 0, 0, 0, 0, 0, 0, 0, 24, 90, 89, 438, 437, 444, 443, 450, 449, 837, 836, - 482, 481, 476, 475, 470, 469, 49, 0, 31, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 54, 53, 464, 463, 458, 457, 452, 451, 838, 0, - 484, 483, 478, 477, 472, 471, 50, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 466, 465, 460, 459, 454, 453, 840, 839, - 486, 485, 480, 479, 474, 473, 52, 51, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 43, 468, 467, 462, 461, 456, 455, 841, 0, - 488, 487, 494, 493, 500, 499, 98, 97, 62, 61, 0, 0, 0, 0, 0, 0, 0, 0, 0, 27, 92, 91, 506, 505, 512, 511, 518, 517, 843, 842, - 490, 489, 496, 495, 502, 501, 100, 99, 64, 63, 0, 0, 0, 0, 0, 0, 0, 0, 29, 28, 94, 93, 508, 507, 514, 513, 520, 519, 844, 0, - 492, 491, 498, 497, 504, 503, 102, 101, 66, 65, 18, 0, 0, 0, 0, 0, 0, 0, 19, 30, 96, 95, 510, 509, 516, 515, 522, 521, 846, 845, - 560, 559, 554, 553, 548, 547, 542, 541, 74, 73, 33, 0, 0, 0, 0, 0, 0, 11, 68, 67, 116, 115, 536, 535, 530, 529, 524, 523, 847, 0, - 562, 561, 556, 555, 550, 549, 544, 543, 76, 75, 0, 0, 8, 7, 36, 35, 12, 0, 70, 69, 118, 117, 538, 537, 532, 531, 526, 525, 849, 848, - 564, 563, 558, 557, 552, 551, 546, 545, 78, 77, 0, 34, 10, 9, 26, 25, 0, 0, 72, 71, 120, 119, 540, 539, 534, 533, 528, 527, 850, 0, - 566, 565, 572, 571, 578, 577, 584, 583, 590, 589, 596, 595, 602, 601, 608, 607, 614, 613, 620, 619, 626, 625, 632, 631, 638, 637, 644, 643, 852, 851, - 568, 567, 574, 573, 580, 579, 586, 585, 592, 591, 598, 597, 604, 603, 610, 609, 616, 615, 622, 621, 628, 627, 634, 633, 640, 639, 646, 645, 853, 0, - 570, 569, 576, 575, 582, 581, 588, 587, 594, 593, 600, 599, 606, 605, 612, 611, 618, 617, 624, 623, 630, 629, 636, 635, 642, 641, 648, 647, 855, 854, - 728, 727, 722, 721, 716, 715, 710, 709, 704, 703, 698, 697, 692, 691, 686, 685, 680, 679, 674, 673, 668, 667, 662, 661, 656, 655, 650, 649, 856, 0, - 730, 729, 724, 723, 718, 717, 712, 711, 706, 705, 700, 699, 694, 693, 688, 687, 682, 681, 676, 675, 670, 669, 664, 663, 658, 657, 652, 651, 858, 857, - 732, 731, 726, 725, 720, 719, 714, 713, 708, 707, 702, 701, 696, 695, 690, 689, 684, 683, 678, 677, 672, 671, 666, 665, 660, 659, 654, 653, 859, 0, - 734, 733, 740, 739, 746, 745, 752, 751, 758, 757, 764, 763, 770, 769, 776, 775, 782, 781, 788, 787, 794, 793, 800, 799, 806, 805, 812, 811, 861, 860, - 736, 735, 742, 741, 748, 747, 754, 753, 760, 759, 766, 765, 772, 771, 778, 777, 784, 783, 790, 789, 796, 795, 802, 801, 808, 807, 814, 813, 862, 0, - 738, 737, 744, 743, 750, 749, 756, 755, 762, 761, 768, 767, 774, 773, 780, 779, 786, 785, 792, 791, 798, 797, 804, 803, 810, 809, 816, 815, 864, 863 +static const int MaxiGrid[] = { + /* ISO/IEC 16023 Figure 5 - MaxiCode Module Sequence */ /* 30 x 33 data grid */ + 122, 121, 128, 127, 134, 133, 140, 139, 146, 145, 152, 151, 158, 157, 164, 163, 170, 169, 176, 175, 182, 181, 188, 187, 194, 193, 200, 199, 0, 0, + 124, 123, 130, 129, 136, 135, 142, 141, 148, 147, 154, 153, 160, 159, 166, 165, 172, 171, 178, 177, 184, 183, 190, 189, 196, 195, 202, 201, 817, 0, + 126, 125, 132, 131, 138, 137, 144, 143, 150, 149, 156, 155, 162, 161, 168, 167, 174, 173, 180, 179, 186, 185, 192, 191, 198, 197, 204, 203, 819, 818, + 284, 283, 278, 277, 272, 271, 266, 265, 260, 259, 254, 253, 248, 247, 242, 241, 236, 235, 230, 229, 224, 223, 218, 217, 212, 211, 206, 205, 820, 0, + 286, 285, 280, 279, 274, 273, 268, 267, 262, 261, 256, 255, 250, 249, 244, 243, 238, 237, 232, 231, 226, 225, 220, 219, 214, 213, 208, 207, 822, 821, + 288, 287, 282, 281, 276, 275, 270, 269, 264, 263, 258, 257, 252, 251, 246, 245, 240, 239, 234, 233, 228, 227, 222, 221, 216, 215, 210, 209, 823, 0, + 290, 289, 296, 295, 302, 301, 308, 307, 314, 313, 320, 319, 326, 325, 332, 331, 338, 337, 344, 343, 350, 349, 356, 355, 362, 361, 368, 367, 825, 824, + 292, 291, 298, 297, 304, 303, 310, 309, 316, 315, 322, 321, 328, 327, 334, 333, 340, 339, 346, 345, 352, 351, 358, 357, 364, 363, 370, 369, 826, 0, + 294, 293, 300, 299, 306, 305, 312, 311, 318, 317, 324, 323, 330, 329, 336, 335, 342, 341, 348, 347, 354, 353, 360, 359, 366, 365, 372, 371, 828, 827, + 410, 409, 404, 403, 398, 397, 392, 391, 80, 79, 0, 0, 14, 13, 38, 37, 3, 0, 45, 44, 110, 109, 386, 385, 380, 379, 374, 373, 829, 0, + 412, 411, 406, 405, 400, 399, 394, 393, 82, 81, 41, 0, 16, 15, 40, 39, 4, 0, 0, 46, 112, 111, 388, 387, 382, 381, 376, 375, 831, 830, + 414, 413, 408, 407, 402, 401, 396, 395, 84, 83, 42, 0, 0, 0, 0, 0, 6, 5, 48, 47, 114, 113, 390, 389, 384, 383, 378, 377, 832, 0, + 416, 415, 422, 421, 428, 427, 104, 103, 56, 55, 17, 0, 0, 0, 0, 0, 0, 0, 21, 20, 86, 85, 434, 433, 440, 439, 446, 445, 834, 833, + 418, 417, 424, 423, 430, 429, 106, 105, 58, 57, 0, 0, 0, 0, 0, 0, 0, 0, 23, 22, 88, 87, 436, 435, 442, 441, 448, 447, 835, 0, + 420, 419, 426, 425, 432, 431, 108, 107, 60, 59, 0, 0, 0, 0, 0, 0, 0, 0, 0, 24, 90, 89, 438, 437, 444, 443, 450, 449, 837, 836, + 482, 481, 476, 475, 470, 469, 49, 0, 31, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 54, 53, 464, 463, 458, 457, 452, 451, 838, 0, + 484, 483, 478, 477, 472, 471, 50, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 466, 465, 460, 459, 454, 453, 840, 839, + 486, 485, 480, 479, 474, 473, 52, 51, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 43, 468, 467, 462, 461, 456, 455, 841, 0, + 488, 487, 494, 493, 500, 499, 98, 97, 62, 61, 0, 0, 0, 0, 0, 0, 0, 0, 0, 27, 92, 91, 506, 505, 512, 511, 518, 517, 843, 842, + 490, 489, 496, 495, 502, 501, 100, 99, 64, 63, 0, 0, 0, 0, 0, 0, 0, 0, 29, 28, 94, 93, 508, 507, 514, 513, 520, 519, 844, 0, + 492, 491, 498, 497, 504, 503, 102, 101, 66, 65, 18, 0, 0, 0, 0, 0, 0, 0, 19, 30, 96, 95, 510, 509, 516, 515, 522, 521, 846, 845, + 560, 559, 554, 553, 548, 547, 542, 541, 74, 73, 33, 0, 0, 0, 0, 0, 0, 11, 68, 67, 116, 115, 536, 535, 530, 529, 524, 523, 847, 0, + 562, 561, 556, 555, 550, 549, 544, 543, 76, 75, 0, 0, 8, 7, 36, 35, 12, 0, 70, 69, 118, 117, 538, 537, 532, 531, 526, 525, 849, 848, + 564, 563, 558, 557, 552, 551, 546, 545, 78, 77, 0, 34, 10, 9, 26, 25, 0, 0, 72, 71, 120, 119, 540, 539, 534, 533, 528, 527, 850, 0, + 566, 565, 572, 571, 578, 577, 584, 583, 590, 589, 596, 595, 602, 601, 608, 607, 614, 613, 620, 619, 626, 625, 632, 631, 638, 637, 644, 643, 852, 851, + 568, 567, 574, 573, 580, 579, 586, 585, 592, 591, 598, 597, 604, 603, 610, 609, 616, 615, 622, 621, 628, 627, 634, 633, 640, 639, 646, 645, 853, 0, + 570, 569, 576, 575, 582, 581, 588, 587, 594, 593, 600, 599, 606, 605, 612, 611, 618, 617, 624, 623, 630, 629, 636, 635, 642, 641, 648, 647, 855, 854, + 728, 727, 722, 721, 716, 715, 710, 709, 704, 703, 698, 697, 692, 691, 686, 685, 680, 679, 674, 673, 668, 667, 662, 661, 656, 655, 650, 649, 856, 0, + 730, 729, 724, 723, 718, 717, 712, 711, 706, 705, 700, 699, 694, 693, 688, 687, 682, 681, 676, 675, 670, 669, 664, 663, 658, 657, 652, 651, 858, 857, + 732, 731, 726, 725, 720, 719, 714, 713, 708, 707, 702, 701, 696, 695, 690, 689, 684, 683, 678, 677, 672, 671, 666, 665, 660, 659, 654, 653, 859, 0, + 734, 733, 740, 739, 746, 745, 752, 751, 758, 757, 764, 763, 770, 769, 776, 775, 782, 781, 788, 787, 794, 793, 800, 799, 806, 805, 812, 811, 861, 860, + 736, 735, 742, 741, 748, 747, 754, 753, 760, 759, 766, 765, 772, 771, 778, 777, 784, 783, 790, 789, 796, 795, 802, 801, 808, 807, 814, 813, 862, 0, + 738, 737, 744, 743, 750, 749, 756, 755, 762, 761, 768, 767, 774, 773, 780, 779, 786, 785, 792, 791, 798, 797, 804, 803, 810, 809, 816, 815, 864, 863 }; -static const int maxiCodeSet[256] = { /* from Appendix A - ASCII character to Code Set (e.g. 2 = Set B) */ - /* set 0 refers to special characters that fit into more than one set (e.g. GS) */ - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 0, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 0, 0, 0, 5, 0, 2, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 2, - 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, - 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 4, 5, 5, 5, 5, 5, 5, 4, 5, 3, 4, 3, 5, 5, 4, 4, 3, 3, 3, - 4, 3, 5, 4, 4, 3, 3, 4, 3, 3, 3, 4, 3, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, - 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4 +static const int maxiCodeSet[256] = { + /* from Appendix A - ASCII character to Code Set (e.g. 2 = Set B) */ + /* set 0 refers to special characters that fit into more than one set (e.g. GS) */ + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 0, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 0, 0, 0, 5, 0, 2, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 2, + 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, + 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 4, 5, 5, 5, 5, 5, 5, 4, 5, 3, 4, 3, 5, 5, 4, 4, 3, 3, 3, + 4, 3, 5, 4, 4, 3, 3, 4, 3, 3, 3, 4, 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, + 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4 }; -static const int maxiSymbolChar[256] = { /* from Appendix A - ASCII character to symbol value */ - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, - 20, 21, 22, 23, 24, 25, 26, 30, 28, 29, 30, 35, 32, 53, 34, 35, 36, 37, 38, 39, - 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 37, - 38, 39, 40, 41, 52, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, - 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 42, 43, 44, 45, 46, 0, 1, 2, 3, - 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, - 24, 25, 26, 32, 54, 34, 35, 36, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 47, 48, - 49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 36, - 37, 37, 38, 39, 40, 41, 42, 43, 38, 44, 37, 39, 38, 45, 46, 40, 41, 39, 40, 41, - 42, 42, 47, 43, 44, 43, 44, 45, 45, 46, 47, 46, 0, 1, 2, 3, 4, 5, 6, 7, - 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 32, - 33, 34, 35, 36, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, - 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 32, 33, 34, 35, 36 +static const int maxiSymbolChar[256] = { + /* from Appendix A - ASCII character to symbol value */ + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, + 20, 21, 22, 23, 24, 25, 26, 30, 28, 29, 30, 35, 32, 53, 34, 35, 36, 37, 38, 39, + 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 37, + 38, 39, 40, 41, 52, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, + 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 42, 43, 44, 45, 46, 0, 1, 2, 3, + 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, + 24, 25, 26, 32, 54, 34, 35, 36, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 47, 48, + 49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 36, + 37, 37, 38, 39, 40, 41, 42, 43, 38, 44, 37, 39, 38, 45, 46, 40, 41, 39, 40, 41, + 42, 42, 47, 43, 44, 43, 44, 45, 45, 46, 47, 46, 0, 1, 2, 3, 4, 5, 6, 7, + 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 32, + 33, 34, 35, 36, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, + 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 32, 33, 34, 35, 36 }; diff --git a/backend/maxipng.h b/backend/maxipng.h index 09c75671..7888e212 100644 --- a/backend/maxipng.h +++ b/backend/maxipng.h @@ -2,7 +2,7 @@ /* libzint - the open source barcode library - Copyright (C) 2008 Robin Stuart + Copyright (C) 2008-2016 Robin Stuart Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions @@ -28,7 +28,7 @@ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ + */ /* This file contains the pixel-by-pixel representation of maxicode glyphs at a resolution of 12 pixels per millimeter. hexagon[] is taken directly @@ -37,113 +37,113 @@ #define SSET "0123456789ABCDEF" static const int hexagon[120] = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, - 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, - 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, - 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, - 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, - 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, + 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, + 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, + 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, + 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, + 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; static const unsigned int bullseye_compressed[] = { - 0,0,0,0,0,255,248,0,0,0,0,0, - 0,0,0,0,31,255,255,192,0,0,0,0, - 0,0,0,1,255,255,255,252,0,0,0,0, - 0,0,0,7,255,255,255,255,0,0,0,0, - 0,0,0,31,255,255,255,255,192,0,0,0, - 0,0,0,127,255,255,255,255,240,0,0,0, - 0,0,1,255,255,255,255,255,252,0,0,0, - 0,0,7,255,255,255,255,255,255,0,0,0, - 0,0,15,255,255,0,7,255,255,128,0,0, - 0,0,63,255,240,0,0,127,255,224,0,0, - 0,0,127,255,128,0,0,15,255,240,0,0, - 0,0,255,252,0,0,0,1,255,248,0,0, - 0,1,255,240,0,0,0,0,127,252,0,0, - 0,3,255,224,0,0,0,0,63,254,0,0, - 0,7,255,128,0,0,0,0,15,255,0,0, - 0,15,255,0,0,0,0,0,7,255,128,0, - 0,31,252,0,0,127,240,0,1,255,192,0, - 0,63,248,0,7,255,255,0,0,255,224,0, - 0,127,240,0,63,255,255,224,0,127,240,0, - 0,127,224,0,255,255,255,248,0,63,240,0, - 0,255,192,1,255,255,255,252,0,31,248,0, - 1,255,128,7,255,255,255,255,0,15,252,0, - 1,255,0,15,255,255,255,255,128,7,252,0, - 3,255,0,63,255,255,255,255,224,7,254,0, - 3,254,0,127,255,192,31,255,240,3,254,0, - 7,252,0,255,252,0,1,255,248,1,255,0, - 7,252,1,255,240,0,0,127,252,1,255,0, - 15,248,1,255,192,0,0,31,252,0,255,128, - 15,240,3,255,128,0,0,15,254,0,127,128, - 31,240,7,255,0,0,0,7,255,0,127,192, - 31,224,7,254,0,0,0,3,255,0,63,192, - 63,224,15,252,0,0,0,1,255,128,63,224, - 63,224,31,248,0,63,192,0,255,192,63,224, - 63,192,31,240,0,255,240,0,127,192,31,224, - 63,192,63,224,3,255,252,0,63,224,31,224, - 127,192,63,224,7,255,254,0,63,224,31,240, - 127,128,63,192,15,255,255,0,31,224,15,240, - 127,128,127,192,31,255,255,128,31,240,15,240, - 127,128,127,128,63,255,255,192,15,240,15,240, - 127,128,127,128,63,255,255,192,15,240,15,240, - 255,0,127,128,127,240,255,224,15,240,7,240, - 255,0,255,128,127,192,63,224,15,248,7,240, - 255,0,255,0,255,128,31,240,7,248,7,240, - 255,0,255,0,255,128,31,240,7,248,7,240, - 255,0,255,0,255,0,15,240,7,248,7,240, - 255,0,255,0,255,0,15,240,7,248,7,240, - 255,0,255,0,255,0,15,240,7,248,7,240, - 255,0,255,0,255,0,15,240,7,248,7,240, - 255,0,255,0,255,128,31,240,7,248,7,240, - 255,0,255,0,255,128,31,240,7,248,7,240, - 255,0,255,0,127,192,63,224,7,248,7,240, - 255,0,255,128,127,240,255,224,15,248,7,240, - 255,0,127,128,63,255,255,192,15,240,7,240, - 127,128,127,128,63,255,255,192,15,240,15,240, - 127,128,127,128,31,255,255,128,15,240,15,240, - 127,128,127,192,15,255,255,0,31,240,15,240, - 127,128,63,192,7,255,254,0,31,224,15,240, - 127,192,63,224,3,255,252,0,63,224,31,240, - 63,192,63,224,0,255,240,0,63,224,31,224, - 63,192,31,240,0,63,192,0,127,192,31,224, - 63,224,31,248,0,0,0,0,255,192,63,224, - 63,224,15,252,0,0,0,1,255,128,63,224, - 31,224,7,254,0,0,0,3,255,0,63,192, - 31,240,7,255,0,0,0,7,255,0,127,192, - 15,240,3,255,128,0,0,15,254,0,127,128, - 15,248,1,255,192,0,0,31,252,0,255,128, - 7,252,1,255,240,0,0,127,252,1,255,0, - 7,252,0,255,252,0,1,255,248,1,255,0, - 3,254,0,127,255,192,31,255,240,3,254,0, - 3,255,0,63,255,255,255,255,224,7,254,0, - 1,255,0,15,255,255,255,255,128,7,252,0, - 1,255,128,7,255,255,255,255,0,15,252,0, - 0,255,192,1,255,255,255,252,0,31,248,0, - 0,127,224,0,255,255,255,248,0,63,240,0, - 0,127,240,0,63,255,255,224,0,127,240,0, - 0,63,248,0,7,255,255,0,0,255,224,0, - 0,31,252,0,0,127,240,0,1,255,192,0, - 0,15,255,0,0,0,0,0,7,255,128,0, - 0,7,255,128,0,0,0,0,15,255,0,0, - 0,3,255,224,0,0,0,0,63,254,0,0, - 0,1,255,240,0,0,0,0,127,252,0,0, - 0,0,255,252,0,0,0,1,255,248,0,0, - 0,0,127,255,128,0,0,15,255,240,0,0, - 0,0,63,255,240,0,0,127,255,224,0,0, - 0,0,15,255,255,0,7,255,255,128,0,0, - 0,0,7,255,255,255,255,255,255,0,0,0, - 0,0,1,255,255,255,255,255,252,0,0,0, - 0,0,0,127,255,255,255,255,240,0,0,0, - 0,0,0,31,255,255,255,255,192,0,0,0, - 0,0,0,7,255,255,255,255,0,0,0,0, - 0,0,0,1,255,255,255,252,0,0,0,0, - 0,0,0,0,31,255,255,192,0,0,0,0, - 0,0,0,0,0,255,248,0,0,0,0,0 + 0, 0, 0, 0, 0, 255, 248, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 31, 255, 255, 192, 0, 0, 0, 0, + 0, 0, 0, 1, 255, 255, 255, 252, 0, 0, 0, 0, + 0, 0, 0, 7, 255, 255, 255, 255, 0, 0, 0, 0, + 0, 0, 0, 31, 255, 255, 255, 255, 192, 0, 0, 0, + 0, 0, 0, 127, 255, 255, 255, 255, 240, 0, 0, 0, + 0, 0, 1, 255, 255, 255, 255, 255, 252, 0, 0, 0, + 0, 0, 7, 255, 255, 255, 255, 255, 255, 0, 0, 0, + 0, 0, 15, 255, 255, 0, 7, 255, 255, 128, 0, 0, + 0, 0, 63, 255, 240, 0, 0, 127, 255, 224, 0, 0, + 0, 0, 127, 255, 128, 0, 0, 15, 255, 240, 0, 0, + 0, 0, 255, 252, 0, 0, 0, 1, 255, 248, 0, 0, + 0, 1, 255, 240, 0, 0, 0, 0, 127, 252, 0, 0, + 0, 3, 255, 224, 0, 0, 0, 0, 63, 254, 0, 0, + 0, 7, 255, 128, 0, 0, 0, 0, 15, 255, 0, 0, + 0, 15, 255, 0, 0, 0, 0, 0, 7, 255, 128, 0, + 0, 31, 252, 0, 0, 127, 240, 0, 1, 255, 192, 0, + 0, 63, 248, 0, 7, 255, 255, 0, 0, 255, 224, 0, + 0, 127, 240, 0, 63, 255, 255, 224, 0, 127, 240, 0, + 0, 127, 224, 0, 255, 255, 255, 248, 0, 63, 240, 0, + 0, 255, 192, 1, 255, 255, 255, 252, 0, 31, 248, 0, + 1, 255, 128, 7, 255, 255, 255, 255, 0, 15, 252, 0, + 1, 255, 0, 15, 255, 255, 255, 255, 128, 7, 252, 0, + 3, 255, 0, 63, 255, 255, 255, 255, 224, 7, 254, 0, + 3, 254, 0, 127, 255, 192, 31, 255, 240, 3, 254, 0, + 7, 252, 0, 255, 252, 0, 1, 255, 248, 1, 255, 0, + 7, 252, 1, 255, 240, 0, 0, 127, 252, 1, 255, 0, + 15, 248, 1, 255, 192, 0, 0, 31, 252, 0, 255, 128, + 15, 240, 3, 255, 128, 0, 0, 15, 254, 0, 127, 128, + 31, 240, 7, 255, 0, 0, 0, 7, 255, 0, 127, 192, + 31, 224, 7, 254, 0, 0, 0, 3, 255, 0, 63, 192, + 63, 224, 15, 252, 0, 0, 0, 1, 255, 128, 63, 224, + 63, 224, 31, 248, 0, 63, 192, 0, 255, 192, 63, 224, + 63, 192, 31, 240, 0, 255, 240, 0, 127, 192, 31, 224, + 63, 192, 63, 224, 3, 255, 252, 0, 63, 224, 31, 224, + 127, 192, 63, 224, 7, 255, 254, 0, 63, 224, 31, 240, + 127, 128, 63, 192, 15, 255, 255, 0, 31, 224, 15, 240, + 127, 128, 127, 192, 31, 255, 255, 128, 31, 240, 15, 240, + 127, 128, 127, 128, 63, 255, 255, 192, 15, 240, 15, 240, + 127, 128, 127, 128, 63, 255, 255, 192, 15, 240, 15, 240, + 255, 0, 127, 128, 127, 240, 255, 224, 15, 240, 7, 240, + 255, 0, 255, 128, 127, 192, 63, 224, 15, 248, 7, 240, + 255, 0, 255, 0, 255, 128, 31, 240, 7, 248, 7, 240, + 255, 0, 255, 0, 255, 128, 31, 240, 7, 248, 7, 240, + 255, 0, 255, 0, 255, 0, 15, 240, 7, 248, 7, 240, + 255, 0, 255, 0, 255, 0, 15, 240, 7, 248, 7, 240, + 255, 0, 255, 0, 255, 0, 15, 240, 7, 248, 7, 240, + 255, 0, 255, 0, 255, 0, 15, 240, 7, 248, 7, 240, + 255, 0, 255, 0, 255, 128, 31, 240, 7, 248, 7, 240, + 255, 0, 255, 0, 255, 128, 31, 240, 7, 248, 7, 240, + 255, 0, 255, 0, 127, 192, 63, 224, 7, 248, 7, 240, + 255, 0, 255, 128, 127, 240, 255, 224, 15, 248, 7, 240, + 255, 0, 127, 128, 63, 255, 255, 192, 15, 240, 7, 240, + 127, 128, 127, 128, 63, 255, 255, 192, 15, 240, 15, 240, + 127, 128, 127, 128, 31, 255, 255, 128, 15, 240, 15, 240, + 127, 128, 127, 192, 15, 255, 255, 0, 31, 240, 15, 240, + 127, 128, 63, 192, 7, 255, 254, 0, 31, 224, 15, 240, + 127, 192, 63, 224, 3, 255, 252, 0, 63, 224, 31, 240, + 63, 192, 63, 224, 0, 255, 240, 0, 63, 224, 31, 224, + 63, 192, 31, 240, 0, 63, 192, 0, 127, 192, 31, 224, + 63, 224, 31, 248, 0, 0, 0, 0, 255, 192, 63, 224, + 63, 224, 15, 252, 0, 0, 0, 1, 255, 128, 63, 224, + 31, 224, 7, 254, 0, 0, 0, 3, 255, 0, 63, 192, + 31, 240, 7, 255, 0, 0, 0, 7, 255, 0, 127, 192, + 15, 240, 3, 255, 128, 0, 0, 15, 254, 0, 127, 128, + 15, 248, 1, 255, 192, 0, 0, 31, 252, 0, 255, 128, + 7, 252, 1, 255, 240, 0, 0, 127, 252, 1, 255, 0, + 7, 252, 0, 255, 252, 0, 1, 255, 248, 1, 255, 0, + 3, 254, 0, 127, 255, 192, 31, 255, 240, 3, 254, 0, + 3, 255, 0, 63, 255, 255, 255, 255, 224, 7, 254, 0, + 1, 255, 0, 15, 255, 255, 255, 255, 128, 7, 252, 0, + 1, 255, 128, 7, 255, 255, 255, 255, 0, 15, 252, 0, + 0, 255, 192, 1, 255, 255, 255, 252, 0, 31, 248, 0, + 0, 127, 224, 0, 255, 255, 255, 248, 0, 63, 240, 0, + 0, 127, 240, 0, 63, 255, 255, 224, 0, 127, 240, 0, + 0, 63, 248, 0, 7, 255, 255, 0, 0, 255, 224, 0, + 0, 31, 252, 0, 0, 127, 240, 0, 1, 255, 192, 0, + 0, 15, 255, 0, 0, 0, 0, 0, 7, 255, 128, 0, + 0, 7, 255, 128, 0, 0, 0, 0, 15, 255, 0, 0, + 0, 3, 255, 224, 0, 0, 0, 0, 63, 254, 0, 0, + 0, 1, 255, 240, 0, 0, 0, 0, 127, 252, 0, 0, + 0, 0, 255, 252, 0, 0, 0, 1, 255, 248, 0, 0, + 0, 0, 127, 255, 128, 0, 0, 15, 255, 240, 0, 0, + 0, 0, 63, 255, 240, 0, 0, 127, 255, 224, 0, 0, + 0, 0, 15, 255, 255, 0, 7, 255, 255, 128, 0, 0, + 0, 0, 7, 255, 255, 255, 255, 255, 255, 0, 0, 0, + 0, 0, 1, 255, 255, 255, 255, 255, 252, 0, 0, 0, + 0, 0, 0, 127, 255, 255, 255, 255, 240, 0, 0, 0, + 0, 0, 0, 31, 255, 255, 255, 255, 192, 0, 0, 0, + 0, 0, 0, 7, 255, 255, 255, 255, 0, 0, 0, 0, + 0, 0, 0, 1, 255, 255, 255, 252, 0, 0, 0, 0, + 0, 0, 0, 0, 31, 255, 255, 192, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 255, 248, 0, 0, 0, 0, 0 }; diff --git a/backend/medical.c b/backend/medical.c index 77c10798..1f7a2a37 100644 --- a/backend/medical.c +++ b/backend/medical.c @@ -2,7 +2,7 @@ /* libzint - the open source barcode library - Copyright (C) 2008 Robin Stuart + Copyright (C) 2008-2016 Robin Stuart Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions @@ -28,7 +28,7 @@ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ + */ #include #include @@ -40,280 +40,270 @@ extern int c39(struct zint_symbol *symbol, unsigned char source[], int length); #define CALCIUM "0123456789-$:/.+ABCD" -static const char *CodaTable[20] = {"11111221", "11112211", "11121121", "22111111", "11211211", "21111211", - "12111121", "12112111", "12211111", "21121111", "11122111", "11221111", "21112121", "21211121", - "21212111", "11212121", "11221211", "12121121", "11121221", "11122211"}; +static const char *CodaTable[20] = { + "11111221", "11112211", "11121121", "22111111", "11211211", "21111211", + "12111121", "12112111", "12211111", "21121111", "11122111", "11221111", "21112121", "21211121", + "21212111", "11212121", "11221211", "12121121", "11121221", "11122211" +}; -int pharma_one(struct zint_symbol *symbol, unsigned char source[], int length) -{ - /* "Pharmacode can represent only a single integer from 3 to 131070. Unlike other - commonly used one-dimensional barcode schemes, pharmacode does not store the data in a - form corresponding to the human-readable digits; the number is encoded in binary, rather - than decimal. Pharmacode is read from right to left: with n as the bar position starting - at 0 on the right, each narrow bar adds 2n to the value and each wide bar adds 2(2^n). - The minimum barcode is 2 bars and the maximum 16, so the smallest number that could - be encoded is 3 (2 narrow bars) and the biggest is 131070 (16 wide bars)." - - http://en.wikipedia.org/wiki/Pharmacode */ +int pharma_one(struct zint_symbol *symbol, unsigned char source[], int length) { + /* "Pharmacode can represent only a single integer from 3 to 131070. Unlike other + commonly used one-dimensional barcode schemes, pharmacode does not store the data in a + form corresponding to the human-readable digits; the number is encoded in binary, rather + than decimal. Pharmacode is read from right to left: with n as the bar position starting + at 0 on the right, each narrow bar adds 2n to the value and each wide bar adds 2(2^n). + The minimum barcode is 2 bars and the maximum 16, so the smallest number that could + be encoded is 3 (2 narrow bars) and the biggest is 131070 (16 wide bars)." + - http://en.wikipedia.org/wiki/Pharmacode */ - /* This code uses the One Track Pharamacode calculating algorithm as recommended by - the specification at http://www.laetus.com/laetus.php?request=file&id=69 */ + /* This code uses the One Track Pharamacode calculating algorithm as recommended by + the specification at http://www.laetus.com/laetus.php?request=file&id=69 */ - unsigned long int tester; - int counter, error_number, h; - char inter[18] = { 0 }; /* 131070 -> 17 bits */ - char dest[64]; /* 17 * 2 + 1 */ + unsigned long int tester; + int counter, error_number, h; + char inter[18] = {0}; /* 131070 -> 17 bits */ + char dest[64]; /* 17 * 2 + 1 */ - error_number = 0; + error_number = 0; - if(length > 6) { - strcpy(symbol->errtxt, "Input too long"); - return ZINT_ERROR_TOO_LONG; - } - error_number = is_sane(NEON, source, length); - if(error_number == ZINT_ERROR_INVALID_DATA) { - strcpy(symbol->errtxt, "Invalid characters in data"); - return error_number; - } + if (length > 6) { + strcpy(symbol->errtxt, "Input too long"); + return ZINT_ERROR_TOO_LONG; + } + error_number = is_sane(NEON, source, length); + if (error_number == ZINT_ERROR_INVALID_DATA) { + strcpy(symbol->errtxt, "Invalid characters in data"); + return error_number; + } - tester = atoi((char*)source); + tester = atoi((char*) source); - if((tester < 3) || (tester > 131070)) { - strcpy(symbol->errtxt, "Data out of range"); - return ZINT_ERROR_INVALID_DATA; - } + if ((tester < 3) || (tester > 131070)) { + strcpy(symbol->errtxt, "Data out of range"); + return ZINT_ERROR_INVALID_DATA; + } - do - { - if(!(tester & 1)) { - concat(inter, "W"); - tester = (tester - 2) / 2; - } else { - concat(inter, "N"); - tester = (tester - 1) / 2; - } - } - while(tester != 0); + do { + if (!(tester & 1)) { + concat(inter, "W"); + tester = (tester - 2) / 2; + } else { + concat(inter, "N"); + tester = (tester - 1) / 2; + } + } while (tester != 0); - h = strlen(inter) - 1; - *dest = '\0'; - for(counter = h; counter >= 0; counter--) { - if(inter[counter] == 'W') { - concat(dest, "32"); - } else { - concat(dest, "12"); - } - } + h = strlen(inter) - 1; + *dest = '\0'; + for (counter = h; counter >= 0; counter--) { + if (inter[counter] == 'W') { + concat(dest, "32"); + } else { + concat(dest, "12"); + } + } - expand(symbol, dest); + expand(symbol, dest); - return error_number; + return error_number; } -int pharma_two_calc(struct zint_symbol *symbol, unsigned char source[], char dest[]) -{ - /* This code uses the Two Track Pharamacode defined in the document at - http://www.laetus.com/laetus.php?request=file&id=69 and using a modified - algorithm from the One Track system. This standard accepts integet values - from 4 to 64570080. */ +int pharma_two_calc(struct zint_symbol *symbol, unsigned char source[], char dest[]) { + /* This code uses the Two Track Pharamacode defined in the document at + http://www.laetus.com/laetus.php?request=file&id=69 and using a modified + algorithm from the One Track system. This standard accepts integet values + from 4 to 64570080. */ - unsigned long int tester; - int counter, h; - char inter[17]; - int error_number; + unsigned long int tester; + int counter, h; + char inter[17]; + int error_number; - tester = atoi((char*)source); + tester = atoi((char*) source); - if((tester < 4) || (tester > 64570080)) - { - strcpy(symbol->errtxt, "Data out of range"); - return ZINT_ERROR_INVALID_DATA; - } - error_number = 0; - strcpy(inter, ""); - do - { - switch(tester%3) { - case 0: - concat(inter, "3"); - tester = (tester - 3) / 3; - break; - case 1: - concat(inter, "1"); - tester = (tester - 1) / 3; - break; - case 2: - concat(inter, "2"); - tester = (tester - 2) / 3; - break; - } - } - while(tester != 0); + if ((tester < 4) || (tester > 64570080)) { + strcpy(symbol->errtxt, "Data out of range"); + return ZINT_ERROR_INVALID_DATA; + } + error_number = 0; + strcpy(inter, ""); + do { + switch (tester % 3) { + case 0: + concat(inter, "3"); + tester = (tester - 3) / 3; + break; + case 1: + concat(inter, "1"); + tester = (tester - 1) / 3; + break; + case 2: + concat(inter, "2"); + tester = (tester - 2) / 3; + break; + } + } while (tester != 0); - h = strlen(inter) - 1; - for(counter = h; counter >= 0; counter--) - { - dest[h - counter] = inter[counter]; - } - dest[h + 1] = '\0'; + h = strlen(inter) - 1; + for (counter = h; counter >= 0; counter--) { + dest[h - counter] = inter[counter]; + } + dest[h + 1] = '\0'; - return error_number; + return error_number; } -int pharma_two(struct zint_symbol *symbol, unsigned char source[], int length) -{ - /* Draws the patterns for two track pharmacode */ - char height_pattern[200]; - unsigned int loopey, h; - int writer; - int error_number = 0; - strcpy(height_pattern, ""); +int pharma_two(struct zint_symbol *symbol, unsigned char source[], int length) { + /* Draws the patterns for two track pharmacode */ + char height_pattern[200]; + unsigned int loopey, h; + int writer; + int error_number = 0; + strcpy(height_pattern, ""); - if(length > 8) { - strcpy(symbol->errtxt, "Input too long"); - return ZINT_ERROR_TOO_LONG; - } - error_number = is_sane(NEON, source, length); - if(error_number == ZINT_ERROR_INVALID_DATA) { - strcpy(symbol->errtxt, "Invalid characters in data"); - return error_number; - } - error_number = pharma_two_calc(symbol, source, height_pattern); - if(error_number != 0) { - return error_number; - } + if (length > 8) { + strcpy(symbol->errtxt, "Input too long"); + return ZINT_ERROR_TOO_LONG; + } + error_number = is_sane(NEON, source, length); + if (error_number == ZINT_ERROR_INVALID_DATA) { + strcpy(symbol->errtxt, "Invalid characters in data"); + return error_number; + } + error_number = pharma_two_calc(symbol, source, height_pattern); + if (error_number != 0) { + return error_number; + } - writer = 0; - h = strlen(height_pattern); - for(loopey = 0; loopey < h; loopey++) - { - if((height_pattern[loopey] == '2') || (height_pattern[loopey] == '3')) - { - set_module(symbol, 0, writer); - } - if((height_pattern[loopey] == '1') || (height_pattern[loopey] == '3')) - { - set_module(symbol, 1, writer); - } - writer += 2; - } - symbol->rows = 2; - symbol->width = writer - 1; + writer = 0; + h = strlen(height_pattern); + for (loopey = 0; loopey < h; loopey++) { + if ((height_pattern[loopey] == '2') || (height_pattern[loopey] == '3')) { + set_module(symbol, 0, writer); + } + if ((height_pattern[loopey] == '1') || (height_pattern[loopey] == '3')) { + set_module(symbol, 1, writer); + } + writer += 2; + } + symbol->rows = 2; + symbol->width = writer - 1; - return error_number; + return error_number; } -int codabar(struct zint_symbol *symbol, unsigned char source[], int length) -{ /* The Codabar system consisting of simple substitution */ +/* The Codabar system consisting of simple substitution */ +int codabar(struct zint_symbol *symbol, unsigned char source[], int length) { - int i, error_number; - char dest[512]; + int i, error_number; + char dest[512]; - error_number = 0; - strcpy(dest, ""); + error_number = 0; + strcpy(dest, ""); - if(length > 60) { /* No stack smashing please */ - strcpy(symbol->errtxt, "Input too long"); - return ZINT_ERROR_TOO_LONG; - } - to_upper(source); - error_number = is_sane(CALCIUM, source, length); - if(error_number == ZINT_ERROR_INVALID_DATA) { - strcpy(symbol->errtxt, "Invalid characters in data"); - return error_number; - } - /* Codabar must begin and end with the characters A, B, C or D */ - if((source[0] != 'A') && (source[0] != 'B') && (source[0] != 'C') && (source[0] != 'D')) - { - strcpy(symbol->errtxt, "Invalid characters in data"); - return ZINT_ERROR_INVALID_DATA; - } + if (length > 60) { /* No stack smashing please */ + strcpy(symbol->errtxt, "Input too long"); + return ZINT_ERROR_TOO_LONG; + } + to_upper(source); + error_number = is_sane(CALCIUM, source, length); + if (error_number == ZINT_ERROR_INVALID_DATA) { + strcpy(symbol->errtxt, "Invalid characters in data"); + return error_number; + } + /* Codabar must begin and end with the characters A, B, C or D */ + if ((source[0] != 'A') && (source[0] != 'B') && (source[0] != 'C') + && (source[0] != 'D')) { + strcpy(symbol->errtxt, "Invalid characters in data"); + return ZINT_ERROR_INVALID_DATA; + } - if((source[length - 1] != 'A') && (source[length - 1] != 'B') && - (source[length - 1] != 'C') && (source[length - 1] != 'D')) - { - strcpy(symbol->errtxt, "Invalid characters in data"); - return ZINT_ERROR_INVALID_DATA; - } + if ((source[length - 1] != 'A') && (source[length - 1] != 'B') && + (source[length - 1] != 'C') && (source[length - 1] != 'D')) { + strcpy(symbol->errtxt, "Invalid characters in data"); + return ZINT_ERROR_INVALID_DATA; + } - for(i = 0; i < length; i++) - { - lookup(CALCIUM, CodaTable, source[i], dest); - } + for (i = 0; i < length; i++) { + lookup(CALCIUM, CodaTable, source[i], dest); + } - expand(symbol, dest); - ustrcpy(symbol->text, source); - return error_number; + expand(symbol, dest); + ustrcpy(symbol->text, source); + return error_number; } -int code32(struct zint_symbol *symbol, unsigned char source[], int length) -{ /* Italian Pharmacode */ - int i, zeroes, error_number, checksum, checkpart, checkdigit; - char localstr[10], risultante[7]; - long int pharmacode, remainder, devisor; - int codeword[6]; - char tabella[34]; +/* Italian Pharmacode */ +int code32(struct zint_symbol *symbol, unsigned char source[], int length) { + int i, zeroes, error_number, checksum, checkpart, checkdigit; + char localstr[10], risultante[7]; + long int pharmacode, remainder, devisor; + int codeword[6]; + char tabella[34]; - /* Validate the input */ - if(length > 8) { - strcpy(symbol->errtxt, "Input too long"); - return ZINT_ERROR_TOO_LONG; - } - error_number = is_sane(NEON, source, length); - if(error_number == ZINT_ERROR_INVALID_DATA) { - strcpy(symbol->errtxt, "Invalid characters in data"); - return error_number; - } + /* Validate the input */ + if (length > 8) { + strcpy(symbol->errtxt, "Input too long"); + return ZINT_ERROR_TOO_LONG; + } + error_number = is_sane(NEON, source, length); + if (error_number == ZINT_ERROR_INVALID_DATA) { + strcpy(symbol->errtxt, "Invalid characters in data"); + return error_number; + } - /* Add leading zeros as required */ - zeroes = 8 - length; - memset(localstr, '0', zeroes); - strcpy(localstr + zeroes, (char*)source); + /* Add leading zeros as required */ + zeroes = 8 - length; + memset(localstr, '0', zeroes); + strcpy(localstr + zeroes, (char*) source); - /* Calculate the check digit */ - checksum = 0; - checkpart = 0; - for(i = 0; i < 4; i++) { - checkpart = ctoi(localstr[i * 2]); - checksum += checkpart; - checkpart = 2 * (ctoi(localstr[(i * 2) + 1])); - if(checkpart >= 10) { - checksum += (checkpart - 10) + 1; - } else { - checksum += checkpart; - } - } + /* Calculate the check digit */ + checksum = 0; + checkpart = 0; + for (i = 0; i < 4; i++) { + checkpart = ctoi(localstr[i * 2]); + checksum += checkpart; + checkpart = 2 * (ctoi(localstr[(i * 2) + 1])); + if (checkpart >= 10) { + checksum += (checkpart - 10) + 1; + } else { + checksum += checkpart; + } + } - /* Add check digit to data string */ - checkdigit = checksum % 10; - localstr[8] = itoc(checkdigit); - localstr[9] = '\0'; + /* Add check digit to data string */ + checkdigit = checksum % 10; + localstr[8] = itoc(checkdigit); + localstr[9] = '\0'; - /* Convert string into an integer value */ - pharmacode = atoi(localstr); + /* Convert string into an integer value */ + pharmacode = atoi(localstr); - /* Convert from decimal to base-32 */ - devisor = 33554432; - for(i = 5; i >= 0; i--) { - codeword[i] = pharmacode / devisor; - remainder = pharmacode % devisor; - pharmacode = remainder; - devisor /= 32; - } + /* Convert from decimal to base-32 */ + devisor = 33554432; + for (i = 5; i >= 0; i--) { + codeword[i] = pharmacode / devisor; + remainder = pharmacode % devisor; + pharmacode = remainder; + devisor /= 32; + } - /* Look up values in 'Tabella di conversione' */ - strcpy(tabella, "0123456789BCDFGHJKLMNPQRSTUVWXYZ"); - for(i = 5; i >= 0; i--) { - risultante[5 - i] = tabella[codeword[i]]; - } - risultante[6] = '\0'; - /* Plot the barcode using Code 39 */ - error_number = c39(symbol, (unsigned char*)risultante, strlen(risultante)); - if(error_number != 0) { return error_number; } + /* Look up values in 'Tabella di conversione' */ + strcpy(tabella, "0123456789BCDFGHJKLMNPQRSTUVWXYZ"); + for (i = 5; i >= 0; i--) { + risultante[5 - i] = tabella[codeword[i]]; + } + risultante[6] = '\0'; + /* Plot the barcode using Code 39 */ + error_number = c39(symbol, (unsigned char*) risultante, strlen(risultante)); + if (error_number != 0) { + return error_number; + } - /* Override the normal text output with the Pharmacode number */ - ustrcpy(symbol->text, (unsigned char*)"A"); - uconcat(symbol->text, (unsigned char*)localstr); + /* Override the normal text output with the Pharmacode number */ + ustrcpy(symbol->text, (unsigned char*) "A"); + uconcat(symbol->text, (unsigned char*) localstr); - return error_number; + return error_number; } diff --git a/backend/pdf417.c b/backend/pdf417.c index 20f49b0e..f76d7c0b 100644 --- a/backend/pdf417.c +++ b/backend/pdf417.c @@ -1,7 +1,7 @@ /* pdf417.c - Handles PDF417 stacked symbology */ /* Zint - A barcode generating program using libpng - Copyright (C) 2008 Robin Stuart + Copyright (C) 2008-2016 Robin Stuart Portions Copyright (C) 2004 Grandzebu Bug Fixes thanks to KL Chin @@ -9,14 +9,14 @@ modification, are permitted provided that the following conditions are met: - 1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. + documentation and/or other materials provided with the distribution. 3. Neither the name of the project nor the names of its contributors may be used to endorse or promote products derived from this software - without specific prior written permission. + without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE @@ -27,9 +27,9 @@ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ + */ /* This code is adapted from "Code barre PDF 417 / PDF 417 barcode" v2.5.0 which is Copyright (C) 2004 (Grandzebu). @@ -41,8 +41,6 @@ symbol->option_2 is used to adjust the width of the resulting symbol (i.e. the number of codeword columns not including row start and end data) */ -/* @(#) $Id: pdf417.c,v 1.21 2010/01/28 17:55:59 hooper114 Exp $ */ - #include #include #include @@ -50,1049 +48,1236 @@ #ifndef _MSC_VER #include #else -#include +#include #include "ms_stdint.h" -#endif +#endif #include "pdf417.h" #include "common.h" #include "large.h" -/* +/* Three figure numbers in comments give the location of command equivalents in the original Visual Basic source code file pdf417.frm this code retains some original (French) procedure and variable names to ease conversion */ /* text mode processing tables */ -static const int asciix[95] = { 7, 8, 8, 4, 12, 4, 4, 8, 8, 8, 12, 4, 12, 12, 12, 12, 4, 4, 4, 4, 4, 4, 4, 4, - 4, 4, 12, 8, 8, 4, 8, 8, 8, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 8, 8, 8, 4, 8, 8, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 8, 8, 8, 8 }; +static const int asciix[95] = { + 7, 8, 8, 4, 12, 4, 4, 8, 8, 8, 12, 4, 12, 12, 12, 12, 4, 4, 4, 4, 4, 4, 4, 4, + 4, 4, 12, 8, 8, 4, 8, 8, 8, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 8, 8, 8, 4, 8, 8, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 8, 8, 8, 8 +}; -static const int asciiy[95] = { 26, 10, 20, 15, 18, 21, 10, 28, 23, 24, 22, 20, 13, 16, 17, 19, 0, 1, 2, 3, - 4, 5, 6, 7, 8, 9, 14, 0, 1, 23, 2, 25, 3, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, - 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 4, 5, 6, 24, 7, 8, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, - 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 21, 27, 9 }; +static const int asciiy[95] = { + 26, 10, 20, 15, 18, 21, 10, 28, 23, 24, 22, 20, 13, 16, 17, 19, 0, 1, 2, 3, + 4, 5, 6, 7, 8, 9, 14, 0, 1, 23, 2, 25, 3, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, + 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 4, 5, 6, 24, 7, 8, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, + 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 21, 27, 9 +}; /* Automatic sizing table */ -static const int MicroAutosize[56] = -{ 4, 6, 7, 8, 10, 12, 13, 14, 16, 18, 19, 20, 24, 29, 30, 33, 34, 37, 39, 46, 54, 58, 70, 72, 82, 90, 108, 126, - 1, 14, 2, 7, 3, 25, 8, 16, 5, 17, 9, 6, 10, 11, 28, 12, 19, 13, 29, 20, 30, 21, 22, 31, 23, 32, 33, 34 +static const int MicroAutosize[56] ={ + 4, 6, 7, 8, 10, 12, 13, 14, 16, 18, 19, 20, 24, 29, 30, 33, 34, 37, 39, 46, 54, 58, 70, 72, 82, 90, 108, 126, + 1, 14, 2, 7, 3, 25, 8, 16, 5, 17, 9, 6, 10, 11, 28, 12, 19, 13, 29, 20, 30, 21, 22, 31, 23, 32, 33, 34 }; -int liste[2][1000]; /* global - okay, so I got _almost_ everything local! */ +int liste[2][1000]; /* global */ /* 866 */ -int quelmode(char codeascii) -{ - int mode = BYT; - if ((codeascii == '\t') || (codeascii == '\n') || (codeascii == '\r') || ((codeascii >= ' ') && (codeascii <= '~'))) { mode = TEX; } - else if((codeascii >= '0') && (codeascii <= '9')) { mode = NUM; } - /* 876 */ +int quelmode(char codeascii) { + int mode = BYT; + if ((codeascii == '\t') || (codeascii == '\n') || (codeascii == '\r') || ((codeascii >= ' ') && (codeascii <= '~'))) { + mode = TEX; + } else if ((codeascii >= '0') && (codeascii <= '9')) { + mode = NUM; + } + /* 876 */ - return mode; + return mode; } /* 844 */ -void regroupe(int *indexliste) -{ - int i, j; +void regroupe(int *indexliste) { + int i, j; - /* bring together same type blocks */ - if(*(indexliste) > 1) { - i = 1; - while(i < *(indexliste)) { - if(liste[1][i - 1] == liste[1][i]) { - /* bring together */ - liste[0][i - 1] = liste[0][i - 1] + liste[0][i]; - j = i + 1; + /* bring together same type blocks */ + if (*(indexliste) > 1) { + i = 1; + while (i < *(indexliste)) { + if (liste[1][i - 1] == liste[1][i]) { + /* bring together */ + liste[0][i - 1] = liste[0][i - 1] + liste[0][i]; + j = i + 1; - /* decreace the list */ - while(j < *(indexliste)) { - liste[0][j - 1] = liste[0][j]; - liste[1][j - 1] = liste[1][j]; - j++; - } - *(indexliste) = *(indexliste) - 1; - i--; - } - i++; - } - } - /* 865 */ + /* decreace the list */ + while (j < *(indexliste)) { + liste[0][j - 1] = liste[0][j]; + liste[1][j - 1] = liste[1][j]; + j++; + } + *(indexliste) = *(indexliste) - 1; + i--; + } + i++; + } + } + /* 865 */ } /* 478 */ -void pdfsmooth(int *indexliste) -{ - int i, crnt, last, next, length; +void pdfsmooth(int *indexliste) { + int i, crnt, last, next, length; - for(i = 0; i < *(indexliste); i++) { - crnt = liste[1][i]; - length = liste[0][i]; - if(i != 0) { last = liste[1][i - 1]; } else { last = FALSE; } - if(i != *(indexliste) - 1) { next = liste[1][i + 1]; } else { next = FALSE; } + for (i = 0; i < *(indexliste); i++) { + crnt = liste[1][i]; + length = liste[0][i]; + if (i != 0) { + last = liste[1][i - 1]; + } else { + last = FALSE; + } + if (i != *(indexliste) - 1) { + next = liste[1][i + 1]; + } else { + next = FALSE; + } - if(crnt == NUM) { - if(i == 0) { /* first block */ - if(*(indexliste) > 1) { /* and there are others */ - if((next == TEX) && (length < 8)) { liste[1][i] = TEX;} - if((next == BYT) && (length == 1)) { liste[1][i] = BYT; } - } - } else { - if(i == *(indexliste) - 1) { /* last block */ - if((last == TEX) && (length < 7)) { liste[1][i] = TEX; } - if((last == BYT) && (length == 1)) { liste[1][i] = BYT; } - } else { /* not first or last block */ - if(((last == BYT) && (next == BYT)) && (length < 4)) { liste[1][i] = BYT; } - if(((last == BYT) && (next == TEX)) && (length < 4)) { liste[1][i] = TEX; } - if(((last == TEX) && (next == BYT)) && (length < 5)) { liste[1][i] = TEX; } - if(((last == TEX) && (next == TEX)) && (length < 8)) { liste[1][i] = TEX; } - } - } - } - } - regroupe(indexliste); - /* 520 */ - for(i = 0; i < *(indexliste); i++) { - crnt = liste[1][i]; - length = liste[0][i]; - if(i != 0) { last = liste[1][i - 1]; } else { last = FALSE; } - if(i != *(indexliste) - 1) { next = liste[1][i + 1]; } else { next = FALSE; } + if (crnt == NUM) { + if (i == 0) { + /* first block */ + if (*(indexliste) > 1) { + /* and there are others */ + if ((next == TEX) && (length < 8)) { + liste[1][i] = TEX; + } + if ((next == BYT) && (length == 1)) { + liste[1][i] = BYT; + } + } + } else { + if (i == *(indexliste) - 1) { + /* last block */ + if ((last == TEX) && (length < 7)) { + liste[1][i] = TEX; + } + if ((last == BYT) && (length == 1)) { + liste[1][i] = BYT; + } + } else { + /* not first or last block */ + if (((last == BYT) && (next == BYT)) && (length < 4)) { + liste[1][i] = BYT; + } + if (((last == BYT) && (next == TEX)) && (length < 4)) { + liste[1][i] = TEX; + } + if (((last == TEX) && (next == BYT)) && (length < 5)) { + liste[1][i] = TEX; + } + if (((last == TEX) && (next == TEX)) && (length < 8)) { + liste[1][i] = TEX; + } + } + } + } + } + regroupe(indexliste); + /* 520 */ + for (i = 0; i < *(indexliste); i++) { + crnt = liste[1][i]; + length = liste[0][i]; + if (i != 0) { + last = liste[1][i - 1]; + } else { + last = FALSE; + } + if (i != *(indexliste) - 1) { + next = liste[1][i + 1]; + } else { + next = FALSE; + } - if((crnt == TEX) && (i > 0)) { /* not the first */ - if(i == *(indexliste) - 1) { /* the last one */ - if((last == BYT) && (length == 1)) { liste[1][i] = BYT; } - } else { /* not the last one */ - if(((last == BYT) && (next == BYT)) && (length < 5)) { liste[1][i] = BYT; } - if((((last == BYT) && (next != BYT)) || ((last != BYT) && (next == BYT))) && (length < 3)) { - liste[1][i] = BYT; - } - } - } - } - /* 540 */ - regroupe(indexliste); + if ((crnt == TEX) && (i > 0)) { + /* not the first */ + if (i == *(indexliste) - 1) { + /* the last one */ + if ((last == BYT) && (length == 1)) { + liste[1][i] = BYT; + } + } else { + /* not the last one */ + if (((last == BYT) && (next == BYT)) && (length < 5)) { + liste[1][i] = BYT; + } + if ((((last == BYT) && (next != BYT)) || ((last != BYT) + && (next == BYT))) && (length < 3)) { + liste[1][i] = BYT; + } + } + } + } + /* 540 */ + regroupe(indexliste); } /* 547 */ -void textprocess(int *chainemc, int *mclength, char chaine[], int start, int length, int block) -{ - int j, indexlistet, curtable, listet[2][5000], chainet[5000], wnet; - char codeascii; +void textprocess(int *chainemc, int *mclength, char chaine[], int start, int length, int block) { + int j, indexlistet, curtable, listet[2][5000], chainet[5000], wnet; + char codeascii; - codeascii = 0; - wnet = 0; + codeascii = 0; + wnet = 0; - for(j = 0; j < 1000; j++) { - listet[0][j] = 0; - } - /* listet will contain the table numbers and the value of each characters */ - for(indexlistet = 0; indexlistet < length; indexlistet++) { - codeascii = chaine[start + indexlistet]; - switch(codeascii) { - case '\t': listet[0][indexlistet] = 12; listet[1][indexlistet] = 12; break; - case '\n': listet[0][indexlistet] = 8; listet[1][indexlistet] = 15; break; - case 13: listet[0][indexlistet] = 12; listet[1][indexlistet] = 11; break; - default: listet[0][indexlistet] = asciix[codeascii - 32]; - listet[1][indexlistet] = asciiy[codeascii - 32]; break; - } - } + for (j = 0; j < 1000; j++) { + listet[0][j] = 0; + } + /* listet will contain the table numbers and the value of each characters */ + for (indexlistet = 0; indexlistet < length; indexlistet++) { + codeascii = chaine[start + indexlistet]; + switch (codeascii) { + case '\t': listet[0][indexlistet] = 12; + listet[1][indexlistet] = 12; + break; + case '\n': listet[0][indexlistet] = 8; + listet[1][indexlistet] = 15; + break; + case 13: listet[0][indexlistet] = 12; + listet[1][indexlistet] = 11; + break; + default: listet[0][indexlistet] = asciix[codeascii - 32]; + listet[1][indexlistet] = asciiy[codeascii - 32]; + break; + } + } - /* 570 */ - curtable = 1; /* default table */ - for(j = 0; j < length; j++) { - if(listet[0][j] & curtable) { /* The character is in the current table */ - chainet[wnet] = listet[1][j]; - wnet++; - } else { /* Obliged to change table */ - int flag = FALSE; /* True if we change table for only one character */ - if (j == (length - 1)) { - flag = TRUE; - } else { - if(!(listet[0][j] & listet[0][j + 1])) { flag = TRUE; } - } + /* 570 */ + curtable = 1; /* default table */ + for (j = 0; j < length; j++) { + if (listet[0][j] & curtable) { + /* The character is in the current table */ + chainet[wnet] = listet[1][j]; + wnet++; + } else { + /* Obliged to change table */ + int flag = FALSE; /* True if we change table for only one character */ + if (j == (length - 1)) { + flag = TRUE; + } else { + if (!(listet[0][j] & listet[0][j + 1])) { + flag = TRUE; + } + } - if (flag) { /* we change only one character - look for temporary switch */ - if((listet[0][j] & 1) && (curtable == 2)) { /* T_UPP */ - chainet[wnet] = 27; - chainet[wnet + 1] = listet[1][j]; - wnet += 2; - } - if(listet[0][j] & 8) { /* T_PUN */ - chainet[wnet] = 29; - chainet[wnet + 1] = listet[1][j]; - wnet += 2; - } - if(!(((listet[0][j] & 1) && (curtable == 2)) || (listet[0][j] & 8))) { - /* No temporary switch available */ - flag = FALSE; - } - } + if (flag) { + /* we change only one character - look for temporary switch */ + if ((listet[0][j] & 1) && (curtable == 2)) { /* T_UPP */ + chainet[wnet] = 27; + chainet[wnet + 1] = listet[1][j]; + wnet += 2; + } + if (listet[0][j] & 8) { /* T_PUN */ + chainet[wnet] = 29; + chainet[wnet + 1] = listet[1][j]; + wnet += 2; + } + if (!(((listet[0][j] & 1) && (curtable == 2)) || (listet[0][j] & 8))) { + /* No temporary switch available */ + flag = FALSE; + } + } - /* 599 */ - if (!(flag)) { - int newtable; + /* 599 */ + if (!(flag)) { + int newtable; - if(j == (length - 1)) { - newtable = listet[0][j]; - } else { - if(!(listet[0][j] & listet[0][j + 1])) { - newtable = listet[0][j]; - } else { - newtable = listet[0][j] & listet[0][j + 1]; - } - } + if (j == (length - 1)) { + newtable = listet[0][j]; + } else { + if (!(listet[0][j] & listet[0][j + 1])) { + newtable = listet[0][j]; + } else { + newtable = listet[0][j] & listet[0][j + 1]; + } + } - /* Maintain the first if several tables are possible */ - switch (newtable) { - case 3: - case 5: - case 7: - case 9: - case 11: - case 13: - case 15: - newtable = 1; break; - case 6: - case 10: - case 14: - newtable = 2; break; - case 12: - newtable = 4; break; - } + /* Maintain the first if several tables are possible */ + switch (newtable) { + case 3: + case 5: + case 7: + case 9: + case 11: + case 13: + case 15: + newtable = 1; + break; + case 6: + case 10: + case 14: + newtable = 2; + break; + case 12: + newtable = 4; + break; + } - /* 619 - select the switch */ - switch (curtable) { - case 1: - switch (newtable) { - case 2: chainet[wnet] = 27; wnet++; break; - case 4: chainet[wnet] = 28; wnet++; break; - case 8: chainet[wnet] = 28; wnet++; chainet[wnet] = 25; wnet++; break; - } break; - case 2: - switch (newtable) { - case 1: chainet[wnet] = 28; wnet++; chainet[wnet] = 28; wnet++; break; - case 4: chainet[wnet] = 28; wnet++; break; - case 8: chainet[wnet] = 28; wnet++; chainet[wnet] = 25; wnet++; break; - } break; - case 4: - switch (newtable) { - case 1: chainet[wnet] = 28; wnet++; break; - case 2: chainet[wnet] = 27; wnet++; break; - case 8: chainet[wnet] = 25; wnet++; break; - } break; - case 8: - switch (newtable) { - case 1: chainet[wnet] = 29; wnet++; break; - case 2: chainet[wnet] = 29; wnet++; chainet[wnet] = 27; wnet++; break; - case 4: chainet[wnet] = 29; wnet++; chainet[wnet] = 28; wnet++; break; - } break; - } - curtable = newtable; - /* 659 - at last we add the character */ - chainet[wnet] = listet[1][j]; - wnet++; - } - } - } + /* 619 - select the switch */ + switch (curtable) { + case 1: + switch (newtable) { + case 2: chainet[wnet] = 27; + wnet++; + break; + case 4: chainet[wnet] = 28; + wnet++; + break; + case 8: chainet[wnet] = 28; + wnet++; + chainet[wnet] = 25; + wnet++; + break; + } + break; + case 2: + switch (newtable) { + case 1: chainet[wnet] = 28; + wnet++; + chainet[wnet] = 28; + wnet++; + break; + case 4: chainet[wnet] = 28; + wnet++; + break; + case 8: chainet[wnet] = 28; + wnet++; + chainet[wnet] = 25; + wnet++; + break; + } + break; + case 4: + switch (newtable) { + case 1: chainet[wnet] = 28; + wnet++; + break; + case 2: chainet[wnet] = 27; + wnet++; + break; + case 8: chainet[wnet] = 25; + wnet++; + break; + } + break; + case 8: + switch (newtable) { + case 1: chainet[wnet] = 29; + wnet++; + break; + case 2: chainet[wnet] = 29; + wnet++; + chainet[wnet] = 27; + wnet++; + break; + case 4: chainet[wnet] = 29; + wnet++; + chainet[wnet] = 28; + wnet++; + break; + } + break; + } + curtable = newtable; + /* 659 - at last we add the character */ + chainet[wnet] = listet[1][j]; + wnet++; + } + } + } - /* 663 */ - if (wnet & 1) { - chainet[wnet] = 29; - wnet++; - } - /* Now translate the string chainet into codewords */ - chainemc[*(mclength)] = 900; - *(mclength) = *(mclength) + 1; + /* 663 */ + if (wnet & 1) { + chainet[wnet] = 29; + wnet++; + } + /* Now translate the string chainet into codewords */ + chainemc[*(mclength)] = 900; + *(mclength) = *(mclength) + 1; - for(j = 0; j < wnet; j+= 2) { - int cw_number; + for (j = 0; j < wnet; j += 2) { + int cw_number; - cw_number = (30 * chainet[j]) + chainet[j + 1]; - chainemc[*(mclength)] = cw_number; - *(mclength) = *(mclength) + 1; + cw_number = (30 * chainet[j]) + chainet[j + 1]; + chainemc[*(mclength)] = cw_number; + *(mclength) = *(mclength) + 1; - } + } } /* 671 */ -void byteprocess(int *chainemc, int *mclength, unsigned char chaine[], int start, int length, int block) -{ - int debug = 0; - int len = 0; - unsigned int chunkLen = 0; +void byteprocess(int *chainemc, int *mclength, unsigned char chaine[], int start, int length, int block) { + int debug = 0; + int len = 0; + unsigned int chunkLen = 0; #if defined(_MSC_VER) && _MSC_VER == 1200 - uint64_t mantisa = 0; - uint64_t total = 0; + uint64_t mantisa = 0; + uint64_t total = 0; #else - uint64_t mantisa = 0ULL; - uint64_t total = 0ULL; + uint64_t mantisa = 0ULL; + uint64_t total = 0ULL; #endif - if(debug) printf("\nEntering byte mode at position %d\n", start); + if (debug) printf("\nEntering byte mode at position %d\n", start); - if(length == 1) { - chainemc[(*mclength)++] = 913; - chainemc[(*mclength)++] = chaine[start]; - if(debug) { printf("913 %d\n", chainemc[*mclength - 1]); } - } else { - /* select the switch for multiple of 6 bytes */ - if (length % 6 == 0) { - chainemc[(*mclength)++] = 924; - if(debug) printf("924 "); - } else { - chainemc[(*mclength)++] = 901; - if(debug) printf("901 "); - } + if (length == 1) { + chainemc[(*mclength)++] = 913; + chainemc[(*mclength)++] = chaine[start]; + if (debug) { + printf("913 %d\n", chainemc[*mclength - 1]); + } + } else { + /* select the switch for multiple of 6 bytes */ + if (length % 6 == 0) { + chainemc[(*mclength)++] = 924; + if (debug) printf("924 "); + } else { + chainemc[(*mclength)++] = 901; + if (debug) printf("901 "); + } - while (len < length) - { - chunkLen = length - len; - if (6 <= chunkLen) /* Take groups of 6 */ - { - chunkLen = 6; - len += chunkLen; + while (len < length) { + chunkLen = length - len; + if (6 <= chunkLen) /* Take groups of 6 */ { + chunkLen = 6; + len += chunkLen; #if defined(_MSC_VER) && _MSC_VER == 1200 - total = 0; + total = 0; #else - total = 0ULL; + total = 0ULL; #endif - while (chunkLen--) - { - mantisa = chaine[start++]; + while (chunkLen--) { + mantisa = chaine[start++]; #if defined(_MSC_VER) && _MSC_VER == 1200 - total |= mantisa << (uint64_t)(chunkLen * 8); + total |= mantisa << (uint64_t) (chunkLen * 8); #else - total |= mantisa << (uint64_t)(chunkLen * 8ULL); + total |= mantisa << (uint64_t) (chunkLen * 8ULL); #endif - } + } - chunkLen = 5; + chunkLen = 5; - while (chunkLen--) - { + while (chunkLen--) { #if defined(_MSC_VER) && _MSC_VER == 1200 - chainemc[*mclength + chunkLen] = (int)(total % 900); - total /= 900; + chainemc[*mclength + chunkLen] = (int) (total % 900); + total /= 900; #else - chainemc[*mclength + chunkLen] = (int)(total % 900ULL); - total /= 900ULL; + chainemc[*mclength + chunkLen] = (int) (total % 900ULL); + total /= 900ULL; #endif - } - *mclength += 5; - } - else /* If it remain a group of less than 6 bytes */ - { - len += chunkLen; - while (chunkLen--) - { - chainemc[(*mclength)++] = chaine[start++]; - } - } - } - } + } + *mclength += 5; + } else /* If it remain a group of less than 6 bytes */ { + len += chunkLen; + while (chunkLen--) { + chainemc[(*mclength)++] = chaine[start++]; + } + } + } + } } /* 712 */ -void numbprocess(int *chainemc, int *mclength, char chaine[], int start, int length, int block) -{ - int j, loop, longueur, dummy[100], dumlength, diviseur, nombre; - char chainemod[50], chainemult[100], temp; +void numbprocess(int *chainemc, int *mclength, char chaine[], int start, int length, int block) { + int j, loop, longueur, dummy[100], dumlength, diviseur, nombre; + char chainemod[50], chainemult[100], temp; - strcpy(chainemod, ""); - for(loop = 0; loop <= 50; loop++) { - dummy[loop] = 0; - } + strcpy(chainemod, ""); + for (loop = 0; loop <= 50; loop++) { + dummy[loop] = 0; + } - chainemc[*(mclength)] = 902; - *(mclength) = *(mclength) + 1; + chainemc[*(mclength)] = 902; + *(mclength) = *(mclength) + 1; - j = 0; - while(j < length) { - dumlength = 0; - strcpy(chainemod, ""); - longueur = length - j; - if(longueur > 44) { longueur = 44; } - concat(chainemod, "1"); - for(loop = 1; loop <= longueur; loop++) { - chainemod[loop] = chaine[start + loop + j - 1]; - } - chainemod[longueur + 1] = '\0'; - do { - diviseur = 900; + j = 0; + while (j < length) { + dumlength = 0; + strcpy(chainemod, ""); + longueur = length - j; + if (longueur > 44) { + longueur = 44; + } + concat(chainemod, "1"); + for (loop = 1; loop <= longueur; loop++) { + chainemod[loop] = chaine[start + loop + j - 1]; + } + chainemod[longueur + 1] = '\0'; + do { + diviseur = 900; - /* 877 - gosub Modulo */ - strcpy(chainemult, ""); - nombre = 0; - while(strlen(chainemod) != 0) { - nombre *= 10; - nombre += ctoi(chainemod[0]); - for(loop = 0; loop < strlen(chainemod); loop++) { - chainemod[loop] = chainemod[loop + 1]; - } - if (nombre < diviseur) { - if (strlen(chainemult) != 0) { concat(chainemult, "0"); } - } else { - temp = (nombre / diviseur) + '0'; - chainemult[strlen(chainemult) + 1] = '\0'; - chainemult[strlen(chainemult)] = temp; - } - nombre = nombre % diviseur; - } - diviseur = nombre; - /* return to 723 */ + /* 877 - gosub Modulo */ + strcpy(chainemult, ""); + nombre = 0; + while (strlen(chainemod) != 0) { + nombre *= 10; + nombre += ctoi(chainemod[0]); + for (loop = 0; loop < strlen(chainemod); loop++) { + chainemod[loop] = chainemod[loop + 1]; + } + if (nombre < diviseur) { + if (strlen(chainemult) != 0) { + concat(chainemult, "0"); + } + } else { + temp = (nombre / diviseur) + '0'; + chainemult[strlen(chainemult) + 1] = '\0'; + chainemult[strlen(chainemult)] = temp; + } + nombre = nombre % diviseur; + } + diviseur = nombre; + /* return to 723 */ - for(loop = dumlength; loop > 0; loop--) { - dummy[loop] = dummy[loop - 1]; - } - dummy[0] = diviseur; - dumlength++; - strcpy(chainemod, chainemult); - } while(strlen(chainemult) != 0); - for(loop = 0; loop < dumlength; loop++) { - chainemc[*(mclength)] = dummy[loop]; - *(mclength) = *(mclength) + 1; - } - j += longueur; - } + for (loop = dumlength; loop > 0; loop--) { + dummy[loop] = dummy[loop - 1]; + } + dummy[0] = diviseur; + dumlength++; + strcpy(chainemod, chainemult); + } while (strlen(chainemult) != 0); + for (loop = 0; loop < dumlength; loop++) { + chainemc[*(mclength)] = dummy[loop]; + *(mclength) = *(mclength) + 1; + } + j += longueur; + } } /* 366 */ -int pdf417(struct zint_symbol *symbol, unsigned char chaine[], int length) -{ - int i, k, j, indexchaine, indexliste, mode, longueur, loop, mccorrection[520], offset; - int total, chainemc[2700], mclength, c1, c2, c3, dummy[35], codeerr; - char codebarre[140], pattern[580]; - int debug = 0; +int pdf417(struct zint_symbol *symbol, unsigned char chaine[], int length) { + int i, k, j, indexchaine, indexliste, mode, longueur, loop, mccorrection[520], offset; + int total, chainemc[2700], mclength, c1, c2, c3, dummy[35], codeerr; + char codebarre[140], pattern[580]; + int debug = 0; - codeerr = 0; + codeerr = 0; - /* 456 */ - indexliste = 0; - indexchaine = 0; + /* 456 */ + indexliste = 0; + indexchaine = 0; - mode = quelmode(chaine[indexchaine]); + mode = quelmode(chaine[indexchaine]); - for(i = 0; i < 1000; i++) { - liste[0][i] = 0; - } + for (i = 0; i < 1000; i++) { + liste[0][i] = 0; + } - /* 463 */ - do { - liste[1][indexliste] = mode; - while ((liste[1][indexliste] == mode) && (indexchaine < length)) { - liste[0][indexliste]++; - indexchaine++; - mode = quelmode(chaine[indexchaine]); - } - indexliste++; - } while (indexchaine < length); + /* 463 */ + do { + liste[1][indexliste] = mode; + while ((liste[1][indexliste] == mode) && (indexchaine < length)) { + liste[0][indexliste]++; + indexchaine++; + mode = quelmode(chaine[indexchaine]); + } + indexliste++; + } while (indexchaine < length); - /* 474 */ - pdfsmooth(&indexliste); + /* 474 */ + pdfsmooth(&indexliste); - if(debug) { - printf("Initial block pattern:\n"); - for(i = 0; i < indexliste; i++) { - printf("Len: %d Type: ", liste[0][i]); - switch(liste[1][i]) { - case TEX: printf("Text\n"); break; - case BYT: printf("Byte\n"); break; - case NUM: printf("Number\n"); break; - default: printf("ERROR\n"); break; - } - } - } + if (debug) { + printf("Initial block pattern:\n"); + for (i = 0; i < indexliste; i++) { + printf("Len: %d Type: ", liste[0][i]); + switch (liste[1][i]) { + case TEX: printf("Text\n"); + break; + case BYT: printf("Byte\n"); + break; + case NUM: printf("Number\n"); + break; + default: printf("ERROR\n"); + break; + } + } + } - /* 541 - now compress the data */ - indexchaine = 0; - mclength = 0; - if(symbol->output_options & READER_INIT) { - chainemc[mclength] = 921; /* Reader Initialisation */ - mclength++; - } - for(i = 0; i < indexliste; i++) { - switch(liste[1][i]) { - case TEX: /* 547 - text mode */ - textprocess(chainemc, &mclength, (char*)chaine, indexchaine, liste[0][i], i); - break; - case BYT: /* 670 - octet stream mode */ - byteprocess(chainemc, &mclength, chaine, indexchaine, liste[0][i], i); - break; - case NUM: /* 712 - numeric mode */ - numbprocess(chainemc, &mclength, (char*)chaine, indexchaine, liste[0][i], i); - break; - } - indexchaine = indexchaine + liste[0][i]; - } + /* 541 - now compress the data */ + indexchaine = 0; + mclength = 0; + if (symbol->output_options & READER_INIT) { + chainemc[mclength] = 921; /* Reader Initialisation */ + mclength++; + } + for (i = 0; i < indexliste; i++) { + switch (liste[1][i]) { + case TEX: /* 547 - text mode */ + textprocess(chainemc, &mclength, (char*) chaine, indexchaine, liste[0][i], i); + break; + case BYT: /* 670 - octet stream mode */ + byteprocess(chainemc, &mclength, chaine, indexchaine, liste[0][i], i); + break; + case NUM: /* 712 - numeric mode */ + numbprocess(chainemc, &mclength, (char*) chaine, indexchaine, liste[0][i], i); + break; + } + indexchaine = indexchaine + liste[0][i]; + } - if(debug) { - printf("\nCompressed data stream:\n"); - for(i = 0; i < mclength; i++) { - printf("%d ", chainemc[i]); - } - printf("\n\n"); - } + if (debug) { + printf("\nCompressed data stream:\n"); + for (i = 0; i < mclength; i++) { + printf("%d ", chainemc[i]); + } + printf("\n\n"); + } - /* 752 - Now take care of the number of CWs per row */ - if (symbol->option_1 < 0) { - symbol->option_1 = 6; - if(mclength <= 863) { symbol->option_1 = 5; } - if(mclength <= 320) { symbol->option_1 = 4; } - if(mclength <= 160) { symbol->option_1 = 3; } - if(mclength <= 40) { symbol->option_1 = 2; } - } - k = 1; - for(loop = 1; loop <= (symbol->option_1 + 1); loop++) - { - k *= 2; - } - longueur = mclength; - if(symbol->option_2 > 30) { symbol->option_2 = 30; } - if(symbol->option_2 < 1) { - symbol->option_2 = 0.5 + sqrt((longueur + k) / 3.0); - } - if(((longueur + k) / symbol->option_2) > 90) { - /* stop the symbol from becoming too high */ - symbol->option_2 = symbol->option_2 + 1; - } + /* 752 - Now take care of the number of CWs per row */ + if (symbol->option_1 < 0) { + symbol->option_1 = 6; + if (mclength <= 863) { + symbol->option_1 = 5; + } + if (mclength <= 320) { + symbol->option_1 = 4; + } + if (mclength <= 160) { + symbol->option_1 = 3; + } + if (mclength <= 40) { + symbol->option_1 = 2; + } + } + k = 1; + for (loop = 1; loop <= (symbol->option_1 + 1); loop++) { + k *= 2; + } + longueur = mclength; + if (symbol->option_2 > 30) { + symbol->option_2 = 30; + } + if (symbol->option_2 < 1) { + symbol->option_2 = 0.5 + sqrt((longueur + k) / 3.0); + } + if (((longueur + k) / symbol->option_2) > 90) { + /* stop the symbol from becoming too high */ + symbol->option_2 = symbol->option_2 + 1; + } - if(longueur + k > 928) { - /* Enforce maximum codeword limit */ - return 2; - } + if (longueur + k > 928) { + /* Enforce maximum codeword limit */ + return 2; + } - if(((longueur + k) / symbol->option_2) > 90) { - return 4; - } + if (((longueur + k) / symbol->option_2) > 90) { + return 4; + } - /* 781 - Padding calculation */ - longueur = mclength + 1 + k; - i = 0; - if ((longueur / symbol->option_2) < 3) { - i = (symbol->option_2 * 3) - longueur; /* A bar code must have at least three rows */ - } else { - if((longueur % symbol->option_2) > 0) { i = symbol->option_2 - (longueur % symbol->option_2); } - } - /* We add the padding */ - while (i > 0) { - chainemc[mclength] = 900; - mclength++; - i--; - } - /* we add the length descriptor */ - for(i = mclength; i > 0; i--) { - chainemc[i] = chainemc[i - 1]; - } - chainemc[0] = mclength + 1; - mclength++; + /* 781 - Padding calculation */ + longueur = mclength + 1 + k; + i = 0; + if ((longueur / symbol->option_2) < 3) { + i = (symbol->option_2 * 3) - longueur; /* A bar code must have at least three rows */ + } else { + if ((longueur % symbol->option_2) > 0) { + i = symbol->option_2 - (longueur % symbol->option_2); + } + } + /* We add the padding */ + while (i > 0) { + chainemc[mclength] = 900; + mclength++; + i--; + } + /* we add the length descriptor */ + for (i = mclength; i > 0; i--) { + chainemc[i] = chainemc[i - 1]; + } + chainemc[0] = mclength + 1; + mclength++; - /* 796 - we now take care of the Reed Solomon codes */ - switch(symbol->option_1) { - case 1: offset = 2; break; - case 2: offset = 6; break; - case 3: offset = 14; break; - case 4: offset = 30; break; - case 5: offset = 62; break; - case 6: offset = 126; break; - case 7: offset = 254; break; - case 8: offset = 510; break; - default: offset = 0; break; - } + /* 796 - we now take care of the Reed Solomon codes */ + switch (symbol->option_1) { + case 1: offset = 2; + break; + case 2: offset = 6; + break; + case 3: offset = 14; + break; + case 4: offset = 30; + break; + case 5: offset = 62; + break; + case 6: offset = 126; + break; + case 7: offset = 254; + break; + case 8: offset = 510; + break; + default: offset = 0; + break; + } - longueur = mclength; - for(loop = 0; loop < 520; loop++) { - mccorrection[loop] = 0; - } - total = 0; - for(i = 0; i < longueur; i++) { - total = (chainemc[i] + mccorrection[k - 1]) % 929; - for(j = k - 1; j > 0; j--) { - mccorrection[j] = (mccorrection[j - 1] + 929 - (total * coefrs[offset + j]) % 929) % 929; - } - mccorrection[0] = (929 - (total * coefrs[offset + j]) % 929) % 929; - } + longueur = mclength; + for (loop = 0; loop < 520; loop++) { + mccorrection[loop] = 0; + } + total = 0; + for (i = 0; i < longueur; i++) { + total = (chainemc[i] + mccorrection[k - 1]) % 929; + for (j = k - 1; j > 0; j--) { + mccorrection[j] = (mccorrection[j - 1] + 929 - (total * coefrs[offset + j]) % 929) % 929; + } + mccorrection[0] = (929 - (total * coefrs[offset + j]) % 929) % 929; + } - /* we add these codes to the string */ - for(i = k - 1; i >= 0; i--) { - chainemc[mclength++] = mccorrection[i] ? 929 - mccorrection[i] : 0; - } + /* we add these codes to the string */ + for (i = k - 1; i >= 0; i--) { + chainemc[mclength++] = mccorrection[i] ? 929 - mccorrection[i] : 0; + } - /* 818 - The CW string is finished */ - c1 = (mclength / symbol->option_2 - 1) / 3; - c2 = symbol->option_1 * 3 + (mclength / symbol->option_2 - 1) % 3; - c3 = symbol->option_2 - 1; + /* 818 - The CW string is finished */ + c1 = (mclength / symbol->option_2 - 1) / 3; + c2 = symbol->option_1 * 3 + (mclength / symbol->option_2 - 1) % 3; + c3 = symbol->option_2 - 1; - /* we now encode each row */ - for(i = 0; i <= (mclength / symbol->option_2) - 1; i++) { - for(j = 0; j < symbol->option_2 ; j++) { - dummy[j + 1] = chainemc[i * symbol->option_2 + j]; - } - k = (i / 3) * 30; - switch(i % 3) { - /* follows this pattern from US Patent 5,243,655: - Row 0: L0 (row #, # of rows) R0 (row #, # of columns) - Row 1: L1 (row #, security level) R1 (row #, # of rows) - Row 2: L2 (row #, # of columns) R2 (row #, security level) - Row 3: L3 (row #, # of rows) R3 (row #, # of columns) - etc. */ - case 0: - dummy[0] = k + c1; - dummy[symbol->option_2 + 1] = k + c3; - break; - case 1: - dummy[0] = k + c2; - dummy[symbol->option_2 + 1] = k + c1; - break; - case 2: - dummy[0] = k + c3; - dummy[symbol->option_2 + 1] = k + c2; - break; - } - strcpy(codebarre, "+*"); /* Start with a start char and a separator */ - if(symbol->symbology == BARCODE_PDF417TRUNC) { - /* truncated - so same as before except knock off the last 5 chars */ - for(j = 0; j <= symbol->option_2; j++) { - switch(i % 3) { - case 1: offset = 929; break; - case 2: offset = 1858; break; - default: offset = 0; break; - } - concat(codebarre, codagemc[offset + dummy[j]]); - concat(codebarre, "*"); - } - } else { - /* normal PDF417 symbol */ - for(j = 0; j <= symbol->option_2 + 1; j++) { - switch(i % 3) { - case 1: offset = 929; /* cluster(3) */ break; - case 2: offset = 1858; /* cluster(6) */ break; - default: offset = 0; /* cluster(0) */ break; - } - concat(codebarre, codagemc[offset + dummy[j]]); - concat(codebarre, "*"); - } - concat(codebarre, "-"); - } + /* we now encode each row */ + for (i = 0; i <= (mclength / symbol->option_2) - 1; i++) { + for (j = 0; j < symbol->option_2; j++) { + dummy[j + 1] = chainemc[i * symbol->option_2 + j]; + } + k = (i / 3) * 30; + switch (i % 3) { + case 0: + dummy[0] = k + c1; + dummy[symbol->option_2 + 1] = k + c3; + break; + case 1: + dummy[0] = k + c2; + dummy[symbol->option_2 + 1] = k + c1; + break; + case 2: + dummy[0] = k + c3; + dummy[symbol->option_2 + 1] = k + c2; + break; + } + strcpy(codebarre, "+*"); /* Start with a start char and a separator */ + if (symbol->symbology == BARCODE_PDF417TRUNC) { + /* truncated - so same as before except knock off the last 5 chars */ + for (j = 0; j <= symbol->option_2; j++) { + switch (i % 3) { + case 1: offset = 929; + break; + case 2: offset = 1858; + break; + default: offset = 0; + break; + } + concat(codebarre, codagemc[offset + dummy[j]]); + concat(codebarre, "*"); + } + } else { + /* normal PDF417 symbol */ + for (j = 0; j <= symbol->option_2 + 1; j++) { + switch (i % 3) { + case 1: offset = 929; + /* cluster(3) */ break; + case 2: offset = 1858; + /* cluster(6) */ break; + default: offset = 0; + /* cluster(0) */ break; + } + concat(codebarre, codagemc[offset + dummy[j]]); + concat(codebarre, "*"); + } + concat(codebarre, "-"); + } - strcpy(pattern, ""); - for(loop = 0; loop < strlen(codebarre); loop++) { - lookup(BRSET, PDFttf, codebarre[loop], pattern); - } - for(loop = 0; loop < strlen(pattern); loop++) { - if(pattern[loop] == '1') { set_module(symbol, i, loop); } - } - if(symbol->height == 0) { - symbol->row_height[i] = 3; - } - } - symbol->rows = (mclength / symbol->option_2); - symbol->width = strlen(pattern); + strcpy(pattern, ""); + for (loop = 0; loop < strlen(codebarre); loop++) { + lookup(BRSET, PDFttf, codebarre[loop], pattern); + } + for (loop = 0; loop < strlen(pattern); loop++) { + if (pattern[loop] == '1') { + set_module(symbol, i, loop); + } + } + if (symbol->height == 0) { + symbol->row_height[i] = 3; + } + } + symbol->rows = (mclength / symbol->option_2); + symbol->width = strlen(pattern); - /* 843 */ - return codeerr; + /* 843 */ + return codeerr; } /* 345 */ -int pdf417enc(struct zint_symbol *symbol, unsigned char source[], int length) -{ - int codeerr, error_number; +int pdf417enc(struct zint_symbol *symbol, unsigned char source[], int length) { + int codeerr, error_number; - error_number = 0; + error_number = 0; - if((symbol->option_1 < -1) || (symbol->option_1 > 8)) { - strcpy(symbol->errtxt, "Security value out of range"); - symbol->option_1 = -1; - error_number = ZINT_WARN_INVALID_OPTION; - } - if((symbol->option_2 < 0) || (symbol->option_2 > 30)) { - strcpy(symbol->errtxt, "Number of columns out of range"); - symbol->option_2 = 0; - error_number = ZINT_WARN_INVALID_OPTION; - } + if ((symbol->option_1 < -1) || (symbol->option_1 > 8)) { + strcpy(symbol->errtxt, "Security value out of range"); + symbol->option_1 = -1; + error_number = ZINT_WARN_INVALID_OPTION; + } + if ((symbol->option_2 < 0) || (symbol->option_2 > 30)) { + strcpy(symbol->errtxt, "Number of columns out of range"); + symbol->option_2 = 0; + error_number = ZINT_WARN_INVALID_OPTION; + } - /* 349 */ - codeerr = pdf417(symbol, source, length); + /* 349 */ + codeerr = pdf417(symbol, source, length); - /* 352 */ - if(codeerr != 0) { - switch(codeerr) { - case 1: - strcpy(symbol->errtxt, "No such file or file unreadable"); - error_number = ZINT_ERROR_INVALID_OPTION; - break; - case 2: - strcpy(symbol->errtxt, "Input string too long"); - error_number = ZINT_ERROR_TOO_LONG; - break; - case 3: - strcpy(symbol->errtxt, "Number of codewords per row too small"); - error_number = ZINT_WARN_INVALID_OPTION; - break; - case 4: - strcpy(symbol->errtxt, "Data too long for specified number of columns"); - error_number = ZINT_ERROR_TOO_LONG; - break; - default: - strcpy(symbol->errtxt, "Something strange happened"); - error_number = ZINT_ERROR_ENCODING_PROBLEM; - break; - } - } + /* 352 */ + if (codeerr != 0) { + switch (codeerr) { + case 1: + strcpy(symbol->errtxt, "No such file or file unreadable"); + error_number = ZINT_ERROR_INVALID_OPTION; + break; + case 2: + strcpy(symbol->errtxt, "Input string too long"); + error_number = ZINT_ERROR_TOO_LONG; + break; + case 3: + strcpy(symbol->errtxt, "Number of codewords per row too small"); + error_number = ZINT_WARN_INVALID_OPTION; + break; + case 4: + strcpy(symbol->errtxt, "Data too long for specified number of columns"); + error_number = ZINT_ERROR_TOO_LONG; + break; + default: + strcpy(symbol->errtxt, "Something strange happened"); + error_number = ZINT_ERROR_ENCODING_PROBLEM; + break; + } + } - /* 364 */ - return error_number; + /* 364 */ + return error_number; } +/* like PDF417 only much smaller! */ +int micro_pdf417(struct zint_symbol *symbol, unsigned char chaine[], int length) { + int i, k, j, indexchaine, indexliste, mode, longueur, mccorrection[50], offset; + int total, chainemc[2700], mclength, dummy[5], codeerr; + char codebarre[100], pattern[580]; + int variant, LeftRAPStart, CentreRAPStart, RightRAPStart, StartCluster; + int LeftRAP, CentreRAP, RightRAP, Cluster, writer, flip, loop; + int debug = 0; -int micro_pdf417(struct zint_symbol *symbol, unsigned char chaine[], int length) -{ /* like PDF417 only much smaller! */ + /* Encoding starts out the same as PDF417, so use the same code */ + codeerr = 0; - int i, k, j, indexchaine, indexliste, mode, longueur, mccorrection[50], offset; - int total, chainemc[2700], mclength, dummy[5], codeerr; - char codebarre[100], pattern[580]; - int variant, LeftRAPStart, CentreRAPStart, RightRAPStart, StartCluster; - int LeftRAP, CentreRAP, RightRAP, Cluster, writer, flip, loop; - int debug = 0; + /* 456 */ + indexliste = 0; + indexchaine = 0; - /* Encoding starts out the same as PDF417, so use the same code */ - codeerr = 0; + mode = quelmode(chaine[indexchaine]); - /* 456 */ - indexliste = 0; - indexchaine = 0; + for (i = 0; i < 1000; i++) { + liste[0][i] = 0; + } - mode = quelmode(chaine[indexchaine]); + /* 463 */ + do { + liste[1][indexliste] = mode; + while ((liste[1][indexliste] == mode) && (indexchaine < length)) { + liste[0][indexliste]++; + indexchaine++; + mode = quelmode(chaine[indexchaine]); + } + indexliste++; + } while (indexchaine < length); - for(i = 0; i < 1000; i++) { - liste[0][i] = 0; - } + /* 474 */ + pdfsmooth(&indexliste); - /* 463 */ - do { - liste[1][indexliste] = mode; - while ((liste[1][indexliste] == mode) && (indexchaine < length)) { - liste[0][indexliste]++; - indexchaine++; - mode = quelmode(chaine[indexchaine]); - } - indexliste++; - } while (indexchaine < length); + if (debug) { + printf("Initial mapping:\n"); + for (i = 0; i < indexliste; i++) { + printf("len: %d type: ", liste[0][i]); + switch (liste[1][i]) { + case TEX: printf("TEXT\n"); + break; + case BYT: printf("BYTE\n"); + break; + case NUM: printf("NUMBER\n"); + break; + default: printf("*ERROR*\n"); + break; + } + } + } - /* 474 */ - pdfsmooth(&indexliste); + /* 541 - now compress the data */ + indexchaine = 0; + mclength = 0; + if (symbol->output_options & READER_INIT) { + chainemc[mclength] = 921; /* Reader Initialisation */ + mclength++; + } + for (i = 0; i < indexliste; i++) { + switch (liste[1][i]) { + case TEX: /* 547 - text mode */ + textprocess(chainemc, &mclength, (char*) chaine, indexchaine, liste[0][i], i); + break; + case BYT: /* 670 - octet stream mode */ + byteprocess(chainemc, &mclength, chaine, indexchaine, liste[0][i], i); + break; + case NUM: /* 712 - numeric mode */ + numbprocess(chainemc, &mclength, (char*) chaine, indexchaine, liste[0][i], i); + break; + } + indexchaine = indexchaine + liste[0][i]; + } - if(debug) { - printf("Initial mapping:\n"); - for(i = 0; i < indexliste; i++) { - printf("len: %d type: ", liste[0][i]); - switch(liste[1][i]) { - case TEX: printf("TEXT\n"); break; - case BYT: printf("BYTE\n"); break; - case NUM: printf("NUMBER\n"); break; - default: printf("*ERROR*\n"); break; - } - } - } + /* This is where it all changes! */ - /* 541 - now compress the data */ - indexchaine = 0; - mclength = 0; - if(symbol->output_options & READER_INIT) { - chainemc[mclength] = 921; /* Reader Initialisation */ - mclength++; - } - for(i = 0; i < indexliste; i++) { - switch(liste[1][i]) { - case TEX: /* 547 - text mode */ - textprocess(chainemc, &mclength, (char*)chaine, indexchaine, liste[0][i], i); - break; - case BYT: /* 670 - octet stream mode */ - byteprocess(chainemc, &mclength, chaine, indexchaine, liste[0][i], i); - break; - case NUM: /* 712 - numeric mode */ - numbprocess(chainemc, &mclength, (char*)chaine, indexchaine, liste[0][i], i); - break; - } - indexchaine = indexchaine + liste[0][i]; - } + if (mclength > 126) { + strcpy(symbol->errtxt, "Input data too long"); + return ZINT_ERROR_TOO_LONG; + } + if (symbol->option_2 > 4) { + strcpy(symbol->errtxt, "Specified width out of range"); + symbol->option_2 = 0; + codeerr = ZINT_WARN_INVALID_OPTION; + } - /* This is where it all changes! */ + if (debug) { + printf("\nEncoded Data Stream:\n"); + for (i = 0; i < mclength; i++) { + printf("0x%02X ", chainemc[i]); + } + printf("\n"); + } - if(mclength > 126) { - strcpy(symbol->errtxt, "Input data too long"); - return ZINT_ERROR_TOO_LONG; - } - if(symbol->option_2 > 4) { - strcpy(symbol->errtxt, "Specified width out of range"); - symbol->option_2 = 0; - codeerr = ZINT_WARN_INVALID_OPTION; - } + /* Now figure out which variant of the symbol to use and load values accordingly */ - if(debug) { - printf("\nEncoded Data Stream:\n"); - for(i = 0; i < mclength; i++) { - printf("0x%02X ", chainemc[i]); - } - printf("\n"); - } + variant = 0; - /* Now figure out which variant of the symbol to use and load values accordingly */ + if ((symbol->option_2 == 1) && (mclength > 20)) { + /* the user specified 1 column but the data doesn't fit - go to automatic */ + symbol->option_2 = 0; + strcpy(symbol->errtxt, "Specified symbol size too small for data"); + codeerr = ZINT_WARN_INVALID_OPTION; + } - variant = 0; + if ((symbol->option_2 == 2) && (mclength > 37)) { + /* the user specified 2 columns but the data doesn't fit - go to automatic */ + symbol->option_2 = 0; + strcpy(symbol->errtxt, "Specified symbol size too small for data"); + codeerr = ZINT_WARN_INVALID_OPTION; + } - if((symbol->option_2 == 1) && (mclength > 20)) { - /* the user specified 1 column but the data doesn't fit - go to automatic */ - symbol->option_2 = 0; - strcpy(symbol->errtxt, "Specified symbol size too small for data"); - codeerr = ZINT_WARN_INVALID_OPTION; - } + if ((symbol->option_2 == 3) && (mclength > 82)) { + /* the user specified 3 columns but the data doesn't fit - go to automatic */ + symbol->option_2 = 0; + strcpy(symbol->errtxt, "Specified symbol size too small for data"); + codeerr = ZINT_WARN_INVALID_OPTION; + } - if((symbol->option_2 == 2) && (mclength > 37)) { - /* the user specified 2 columns but the data doesn't fit - go to automatic */ - symbol->option_2 = 0; - strcpy(symbol->errtxt, "Specified symbol size too small for data"); - codeerr = ZINT_WARN_INVALID_OPTION; - } + if (symbol->option_2 == 1) { + /* the user specified 1 column and the data does fit */ + variant = 6; + if (mclength <= 16) { + variant = 5; + } + if (mclength <= 12) { + variant = 4; + } + if (mclength <= 10) { + variant = 3; + } + if (mclength <= 7) { + variant = 2; + } + if (mclength <= 4) { + variant = 1; + } + } - if((symbol->option_2 == 3) && (mclength > 82)) { - /* the user specified 3 columns but the data doesn't fit - go to automatic */ - symbol->option_2 = 0; - strcpy(symbol->errtxt, "Specified symbol size too small for data"); - codeerr = ZINT_WARN_INVALID_OPTION; - } + if (symbol->option_2 == 2) { + /* the user specified 2 columns and the data does fit */ + variant = 13; + if (mclength <= 33) { + variant = 12; + } + if (mclength <= 29) { + variant = 11; + } + if (mclength <= 24) { + variant = 10; + } + if (mclength <= 19) { + variant = 9; + } + if (mclength <= 13) { + variant = 8; + } + if (mclength <= 8) { + variant = 7; + } + } - if(symbol->option_2 == 1) { - /* the user specified 1 column and the data does fit */ - variant = 6; - if(mclength <= 16) { variant = 5; } - if(mclength <= 12) { variant = 4; } - if(mclength <= 10) { variant = 3; } - if(mclength <= 7) { variant = 2; } - if(mclength <= 4) { variant = 1; } - } + if (symbol->option_2 == 3) { + /* the user specified 3 columns and the data does fit */ + variant = 23; + if (mclength <= 70) { + variant = 22; + } + if (mclength <= 58) { + variant = 21; + } + if (mclength <= 46) { + variant = 20; + } + if (mclength <= 34) { + variant = 19; + } + if (mclength <= 24) { + variant = 18; + } + if (mclength <= 18) { + variant = 17; + } + if (mclength <= 14) { + variant = 16; + } + if (mclength <= 10) { + variant = 15; + } + if (mclength <= 6) { + variant = 14; + } + } - if(symbol->option_2 == 2) { - /* the user specified 2 columns and the data does fit */ - variant = 13; - if(mclength <= 33) { variant = 12; } - if(mclength <= 29) { variant = 11; } - if(mclength <= 24) { variant = 10; } - if(mclength <= 19) { variant = 9; } - if(mclength <= 13) { variant = 8; } - if(mclength <= 8) { variant = 7; } - } + if (symbol->option_2 == 4) { + /* the user specified 4 columns and the data does fit */ + variant = 34; + if (mclength <= 108) { + variant = 33; + } + if (mclength <= 90) { + variant = 32; + } + if (mclength <= 72) { + variant = 31; + } + if (mclength <= 54) { + variant = 30; + } + if (mclength <= 39) { + variant = 29; + } + if (mclength <= 30) { + variant = 28; + } + if (mclength <= 24) { + variant = 27; + } + if (mclength <= 18) { + variant = 26; + } + if (mclength <= 12) { + variant = 25; + } + if (mclength <= 8) { + variant = 24; + } + } - if(symbol->option_2 == 3) { - /* the user specified 3 columns and the data does fit */ - variant = 23; - if(mclength <= 70) { variant = 22; } - if(mclength <= 58) { variant = 21; } - if(mclength <= 46) { variant = 20; } - if(mclength <= 34) { variant = 19; } - if(mclength <= 24) { variant = 18; } - if(mclength <= 18) { variant = 17; } - if(mclength <= 14) { variant = 16; } - if(mclength <= 10) { variant = 15; } - if(mclength <= 6) { variant = 14; } - } + if (variant == 0) { + /* Zint can choose automatically from all available variations */ + for (i = 27; i >= 0; i--) { - if(symbol->option_2 == 4) { - /* the user specified 4 columns and the data does fit */ - variant = 34; - if(mclength <= 108) { variant = 33; } - if(mclength <= 90) { variant = 32; } - if(mclength <= 72) { variant = 31; } - if(mclength <= 54) { variant = 30; } - if(mclength <= 39) { variant = 29; } - if(mclength <= 30) { variant = 28; } - if(mclength <= 24) { variant = 27; } - if(mclength <= 18) { variant = 26; } - if(mclength <= 12) { variant = 25; } - if(mclength <= 8) { variant = 24; } - } + if (MicroAutosize[i] >= mclength) { + variant = MicroAutosize[i + 28]; + } + } + } - if(variant == 0) { - /* Zint can choose automatically from all available variations */ - for(i = 27; i >= 0; i--) { + /* Now we have the variant we can load the data */ + variant--; + symbol->option_2 = MicroVariants[variant]; /* columns */ + symbol->rows = MicroVariants[variant + 34]; /* rows */ + k = MicroVariants[variant + 68]; /* number of EC CWs */ + longueur = (symbol->option_2 * symbol->rows) - k; /* number of non-EC CWs */ + i = longueur - mclength; /* amount of padding required */ + offset = MicroVariants[variant + 102]; /* coefficient offset */ - if(MicroAutosize[i] >= mclength) { - variant = MicroAutosize[i + 28]; - } - } - } + if (debug) { + printf("\nChoose symbol size:\n"); + printf("%d columns x %d rows\n", symbol->option_2, symbol->rows); + printf("%d data codewords (including %d pads), %d ecc codewords\n", longueur, i, k); + printf("\n"); + } - /* Now we have the variant we can load the data */ - variant --; - symbol->option_2 = MicroVariants[variant]; /* columns */ - symbol->rows = MicroVariants[variant + 34]; /* rows */ - k = MicroVariants[variant + 68]; /* number of EC CWs */ - longueur = (symbol->option_2 * symbol->rows) - k; /* number of non-EC CWs */ - i = longueur - mclength; /* amount of padding required */ - offset = MicroVariants[variant + 102]; /* coefficient offset */ + /* We add the padding */ + while (i > 0) { + chainemc[mclength] = 900; + mclength++; + i--; + } - if(debug) { - printf("\nChoose symbol size:\n"); - printf("%d columns x %d rows\n", symbol->option_2, symbol->rows); - printf("%d data codewords (including %d pads), %d ecc codewords\n", longueur, i, k); - printf("\n"); - } + /* Reed-Solomon error correction */ + longueur = mclength; + for (loop = 0; loop < 50; loop++) { + mccorrection[loop] = 0; + } + total = 0; + for (i = 0; i < longueur; i++) { + total = (chainemc[i] + mccorrection[k - 1]) % 929; + for (j = k - 1; j >= 0; j--) { + if (j == 0) { + mccorrection[j] = (929 - (total * Microcoeffs[offset + j]) % 929) % 929; + } else { + mccorrection[j] = (mccorrection[j - 1] + 929 - (total * Microcoeffs[offset + j]) % 929) % 929; + } + } + } - /* We add the padding */ - while (i > 0) { - chainemc[mclength] = 900; - mclength++; - i--; - } + for (j = 0; j < k; j++) { + if (mccorrection[j] != 0) { + mccorrection[j] = 929 - mccorrection[j]; + } + } + /* we add these codes to the string */ + for (i = k - 1; i >= 0; i--) { + chainemc[mclength] = mccorrection[i]; + mclength++; + } - /* Reed-Solomon error correction */ - longueur = mclength; - for(loop = 0; loop < 50; loop++) { - mccorrection[loop] = 0; - } - total = 0; - for(i = 0; i < longueur; i++) { - total = (chainemc[i] + mccorrection[k - 1]) % 929; - for(j = k - 1; j >= 0; j--) { - if(j == 0) { - mccorrection[j] = (929 - (total * Microcoeffs[offset + j]) % 929) % 929; - } else { - mccorrection[j] = (mccorrection[j - 1] + 929 - (total * Microcoeffs[offset + j]) % 929) % 929; - } - } - } + if (debug) { + printf("Encoded Data Stream with ECC:\n"); + for (i = 0; i < mclength; i++) { + printf("0x%02X ", chainemc[i]); + } + printf("\n"); + } - for(j = 0; j < k; j++) { - if(mccorrection[j] != 0) { mccorrection[j] = 929 - mccorrection[j]; } - } - /* we add these codes to the string */ - for(i = k - 1; i >= 0; i--) { - chainemc[mclength] = mccorrection[i]; - mclength++; - } + /* Now get the RAP (Row Address Pattern) start values */ + LeftRAPStart = RAPTable[variant]; + CentreRAPStart = RAPTable[variant + 34]; + RightRAPStart = RAPTable[variant + 68]; + StartCluster = RAPTable[variant + 102] / 3; - if(debug) { - printf("Encoded Data Stream with ECC:\n"); - for(i = 0; i < mclength; i++) { - printf("0x%02X ", chainemc[i]); - } - printf("\n"); - } + /* That's all values loaded, get on with the encoding */ - /* Now get the RAP (Row Address Pattern) start values */ - LeftRAPStart = RAPTable[variant]; - CentreRAPStart = RAPTable[variant + 34]; - RightRAPStart = RAPTable[variant + 68]; - StartCluster = RAPTable[variant + 102] / 3; + LeftRAP = LeftRAPStart; + CentreRAP = CentreRAPStart; + RightRAP = RightRAPStart; + Cluster = StartCluster; + /* Cluster can be 0, 1 or 2 for Cluster(0), Cluster(3) and Cluster(6) */ - /* That's all values loaded, get on with the encoding */ + if (debug) printf("\nInternal row representation:\n"); + for (i = 0; i < symbol->rows; i++) { + if (debug) printf("row %d: ", i); + strcpy(codebarre, ""); + offset = 929 * Cluster; + for (j = 0; j < 5; j++) { + dummy[j] = 0; + } + for (j = 0; j < symbol->option_2; j++) { + dummy[j + 1] = chainemc[i * symbol->option_2 + j]; + if (debug) printf("[%d] ", dummy[j + 1]); + } - LeftRAP = LeftRAPStart; - CentreRAP = CentreRAPStart; - RightRAP = RightRAPStart; - Cluster = StartCluster; /* Cluster can be 0, 1 or 2 for Cluster(0), Cluster(3) and Cluster(6) */ + /* Copy the data into codebarre */ + concat(codebarre, RAPLR[LeftRAP]); + concat(codebarre, "1"); + concat(codebarre, codagemc[offset + dummy[1]]); + concat(codebarre, "1"); + if (symbol->option_2 == 3) { + concat(codebarre, RAPC[CentreRAP]); + } + if (symbol->option_2 >= 2) { + concat(codebarre, "1"); + concat(codebarre, codagemc[offset + dummy[2]]); + concat(codebarre, "1"); + } + if (symbol->option_2 == 4) { + concat(codebarre, RAPC[CentreRAP]); + } + if (symbol->option_2 >= 3) { + concat(codebarre, "1"); + concat(codebarre, codagemc[offset + dummy[3]]); + concat(codebarre, "1"); + } + if (symbol->option_2 == 4) { + concat(codebarre, "1"); + concat(codebarre, codagemc[offset + dummy[4]]); + concat(codebarre, "1"); + } + concat(codebarre, RAPLR[RightRAP]); + concat(codebarre, "1"); /* stop */ + if (debug) printf("%s\n", codebarre); - if(debug) printf("\nInternal row representation:\n"); - for(i = 0; i < symbol->rows; i++) { - if(debug) printf("row %d: ", i); - strcpy(codebarre, ""); - offset = 929 * Cluster; - for(j = 0; j < 5; j++) { - dummy[j] = 0; - } - for(j = 0; j < symbol->option_2 ; j++) { - dummy[j + 1] = chainemc[i * symbol->option_2 + j]; - if(debug) printf("[%d] ", dummy[j + 1]); - } + /* Now codebarre is a mixture of letters and numbers */ - /* Copy the data into codebarre */ - concat(codebarre, RAPLR[LeftRAP]); - concat(codebarre, "1"); - concat(codebarre, codagemc[offset + dummy[1]]); - concat(codebarre, "1"); - if(symbol->option_2 == 3) { - concat(codebarre, RAPC[CentreRAP]); - } - if(symbol->option_2 >= 2) { - concat(codebarre, "1"); - concat(codebarre, codagemc[offset + dummy[2]]); - concat(codebarre, "1"); - } - if(symbol->option_2 == 4) { - concat(codebarre, RAPC[CentreRAP]); - } - if(symbol->option_2 >= 3) { - concat(codebarre, "1"); - concat(codebarre, codagemc[offset + dummy[3]]); - concat(codebarre, "1"); - } - if(symbol->option_2 == 4) { - concat(codebarre, "1"); - concat(codebarre, codagemc[offset + dummy[4]]); - concat(codebarre, "1"); - } - concat(codebarre, RAPLR[RightRAP]); - concat(codebarre, "1"); /* stop */ - if(debug) printf("%s\n", codebarre); + writer = 0; + flip = 1; + strcpy(pattern, ""); + for (loop = 0; loop < strlen(codebarre); loop++) { + if ((codebarre[loop] >= '0') && (codebarre[loop] <= '9')) { + for (k = 0; k < ctoi(codebarre[loop]); k++) { + if (flip == 0) { + pattern[writer] = '0'; + } else { + pattern[writer] = '1'; + } + writer++; + } + pattern[writer] = '\0'; + if (flip == 0) { + flip = 1; + } else { + flip = 0; + } + } else { + lookup(BRSET, PDFttf, codebarre[loop], pattern); + writer += 5; + } + } + symbol->width = writer; - /* Now codebarre is a mixture of letters and numbers */ + /* so now pattern[] holds the string of '1's and '0's. - copy this to the symbol */ + for (loop = 0; loop < strlen(pattern); loop++) { + if (pattern[loop] == '1') { + set_module(symbol, i, loop); + } + } + symbol->row_height[i] = 2; - writer = 0; - flip = 1; - strcpy(pattern, ""); - for(loop = 0; loop < strlen(codebarre); loop++) { - if((codebarre[loop] >= '0') && (codebarre[loop] <= '9')) { - for(k = 0; k < ctoi(codebarre[loop]); k++) { - if(flip == 0) { - pattern[writer] = '0'; - } else { - pattern[writer] = '1'; - } - writer++; - } - pattern[writer] = '\0'; - if(flip == 0) { - flip = 1; - } else { - flip = 0; - } - } else { - lookup(BRSET, PDFttf, codebarre[loop], pattern); - writer += 5; - } - } - symbol->width = writer; + /* Set up RAPs and Cluster for next row */ + LeftRAP++; + CentreRAP++; + RightRAP++; + Cluster++; - /* so now pattern[] holds the string of '1's and '0's. - copy this to the symbol */ - for(loop = 0; loop < strlen(pattern); loop++) { - if(pattern[loop] == '1') { set_module(symbol, i, loop); } - } - symbol->row_height[i] = 2; + if (LeftRAP == 53) { + LeftRAP = 1; + } + if (CentreRAP == 53) { + CentreRAP = 1; + } + if (RightRAP == 53) { + RightRAP = 1; + } + if (Cluster == 3) { + Cluster = 0; + } + } - /* Set up RAPs and Cluster for next row */ - LeftRAP++; - CentreRAP++; - RightRAP++; - Cluster++; - - if(LeftRAP == 53) { - LeftRAP = 1; - } - if(CentreRAP == 53) { - CentreRAP = 1; - } - if(RightRAP == 53) { - RightRAP = 1; - } - if(Cluster == 3) { - Cluster = 0; - } - } - - return codeerr; + return codeerr; } - diff --git a/backend/pdf417.h b/backend/pdf417.h index fea6e0b4..6ad11843 100644 --- a/backend/pdf417.h +++ b/backend/pdf417.h @@ -2,21 +2,21 @@ /* libzint - the open source barcode library - Copyright (C) 2008 Robin Stuart + Copyright (C) 2008-2016 Robin Stuart Portions Copyright (C) 2004 Grandzebu Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - 1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. + documentation and/or other materials provided with the distribution. 3. Neither the name of the project nor the names of its contributors may be used to endorse or promote products derived from this software - without specific prior written permission. + without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE @@ -27,9 +27,9 @@ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ + */ /* this file contains the character table, the pre-calculated coefficients and the codeword patterns taken from lines 416 to 454 of pdf417.frm */ @@ -44,406 +44,417 @@ /* PDF417 error correction coefficients from Grand Zebu */ static const int coefrs[1022] = { - /* k = 2 */ - 27, 917, - - /* k = 4 */ - 522, 568, 723, 809, - - /* k = 8 */ - 237, 308, 436, 284, 646, 653, 428, 379, - - /* k = 16 */ - 274, 562, 232, 755, 599, 524, 801, 132, 295, 116, 442, 428, 295, 42, 176, 65, - - /* k = 32 */ - 361, 575, 922, 525, 176, 586, 640, 321, 536, 742, 677, 742, 687, 284, 193, 517, - 273, 494, 263, 147, 593, 800, 571, 320, 803, 133, 231, 390, 685, 330, 63, 410, - - /* k = 64 */ - 539, 422, 6, 93, 862, 771, 453, 106, 610, 287, 107, 505, 733, 877, 381, 612, - 723, 476, 462, 172, 430, 609, 858, 822, 543, 376, 511, 400, 672, 762, 283, 184, - 440, 35, 519, 31, 460, 594, 225, 535, 517, 352, 605, 158, 651, 201, 488, 502, - 648, 733, 717, 83, 404, 97, 280, 771, 840, 629, 4, 381, 843, 623, 264, 543, - - /* k = 128 */ - 521, 310, 864, 547, 858, 580, 296, 379, 53, 779, 897, 444, 400, 925, 749, 415, - 822, 93, 217, 208, 928, 244, 583, 620, 246, 148, 447, 631, 292, 908, 490, 704, - 516, 258, 457, 907, 594, 723, 674, 292, 272, 96, 684, 432, 686, 606, 860, 569, - 193, 219, 129, 186, 236, 287, 192, 775, 278, 173, 40, 379, 712, 463, 646, 776, - 171, 491, 297, 763, 156, 732, 95, 270, 447, 90, 507, 48, 228, 821, 808, 898, - 784, 663, 627, 378, 382, 262, 380, 602, 754, 336, 89, 614, 87, 432, 670, 616, - 157, 374, 242, 726, 600, 269, 375, 898, 845, 454, 354, 130, 814, 587, 804, 34, - 211, 330, 539, 297, 827, 865, 37, 517, 834, 315, 550, 86, 801, 4, 108, 539, - - /* k = 256 */ - 524, 894, 75, 766, 882, 857, 74, 204, 82, 586, 708, 250, 905, 786, 138, 720, - 858, 194, 311, 913, 275, 190, 375, 850, 438, 733, 194, 280, 201, 280, 828, 757, - 710, 814, 919, 89, 68, 569, 11, 204, 796, 605, 540, 913, 801, 700, 799, 137, - 439, 418, 592, 668, 353, 859, 370, 694, 325, 240, 216, 257, 284, 549, 209, 884, - 315, 70, 329, 793, 490, 274, 877, 162, 749, 812, 684, 461, 334, 376, 849, 521, - 307, 291, 803, 712, 19, 358, 399, 908, 103, 511, 51, 8, 517, 225, 289, 470, - 637, 731, 66, 255, 917, 269, 463, 830, 730, 433, 848, 585, 136, 538, 906, 90, - 2, 290, 743, 199, 655, 903, 329, 49, 802, 580, 355, 588, 188, 462, 10, 134, - 628, 320, 479, 130, 739, 71, 263, 318, 374, 601, 192, 605, 142, 673, 687, 234, - 722, 384, 177, 752, 607, 640, 455, 193, 689, 707, 805, 641, 48, 60, 732, 621, - 895, 544, 261, 852, 655, 309, 697, 755, 756, 60, 231, 773, 434, 421, 726, 528, - 503, 118, 49, 795, 32, 144, 500, 238, 836, 394, 280, 566, 319, 9, 647, 550, - 73, 914, 342, 126, 32, 681, 331, 792, 620, 60, 609, 441, 180, 791, 893, 754, - 605, 383, 228, 749, 760, 213, 54, 297, 134, 54, 834, 299, 922, 191, 910, 532, - 609, 829, 189, 20, 167, 29, 872, 449, 83, 402, 41, 656, 505, 579, 481, 173, - 404, 251, 688, 95, 497, 555, 642, 543, 307, 159, 924, 558, 648, 55, 497, 10, - - /* k = 512 */ - 352, 77, 373, 504, 35, 599, 428, 207, 409, 574, 118, 498, 285, 380, 350, 492, - 197, 265, 920, 155, 914, 299, 229, 643, 294, 871, 306, 88, 87, 193, 352, 781, - 846, 75, 327, 520, 435, 543, 203, 666, 249, 346, 781, 621, 640, 268, 794, 534, - 539, 781, 408, 390, 644, 102, 476, 499, 290, 632, 545, 37, 858, 916, 552, 41, - 542, 289, 122, 272, 383, 800, 485, 98, 752, 472, 761, 107, 784, 860, 658, 741, - 290, 204, 681, 407, 855, 85, 99, 62, 482, 180, 20, 297, 451, 593, 913, 142, - 808, 684, 287, 536, 561, 76, 653, 899, 729, 567, 744, 390, 513, 192, 516, 258, - 240, 518, 794, 395, 768, 848, 51, 610, 384, 168, 190, 826, 328, 596, 786, 303, - 570, 381, 415, 641, 156, 237, 151, 429, 531, 207, 676, 710, 89, 168, 304, 402, - 40, 708, 575, 162, 864, 229, 65, 861, 841, 512, 164, 477, 221, 92, 358, 785, - 288, 357, 850, 836, 827, 736, 707, 94, 8, 494, 114, 521, 2, 499, 851, 543, - 152, 729, 771, 95, 248, 361, 578, 323, 856, 797, 289, 51, 684, 466, 533, 820, - 669, 45, 902, 452, 167, 342, 244, 173, 35, 463, 651, 51, 699, 591, 452, 578, - 37, 124, 298, 332, 552, 43, 427, 119, 662, 777, 475, 850, 764, 364, 578, 911, - 283, 711, 472, 420, 245, 288, 594, 394, 511, 327, 589, 777, 699, 688, 43, 408, - 842, 383, 721, 521, 560, 644, 714, 559, 62, 145, 873, 663, 713, 159, 672, 729, - 624, 59, 193, 417, 158, 209, 563, 564, 343, 693, 109, 608, 563, 365, 181, 772, - 677, 310, 248, 353, 708, 410, 579, 870, 617, 841, 632, 860, 289, 536, 35, 777, - 618, 586, 424, 833, 77, 597, 346, 269, 757, 632, 695, 751, 331, 247, 184, 45, - 787, 680, 18, 66, 407, 369, 54, 492, 228, 613, 830, 922, 437, 519, 644, 905, - 789, 420, 305, 441, 207, 300, 892, 827, 141, 537, 381, 662, 513, 56, 252, 341, - 242, 797, 838, 837, 720, 224, 307, 631, 61, 87, 560, 310, 756, 665, 397, 808, - 851, 309, 473, 795, 378, 31, 647, 915, 459, 806, 590, 731, 425, 216, 548, 249, - 321, 881, 699, 535, 673, 782, 210, 815, 905, 303, 843, 922, 281, 73, 469, 791, - 660, 162, 498, 308, 155, 422, 907, 817, 187, 62, 16, 425, 535, 336, 286, 437, - 375, 273, 610, 296, 183, 923, 116, 667, 751, 353, 62, 366, 691, 379, 687, 842, - 37, 357, 720, 742, 330, 5, 39, 923, 311, 424, 242, 749, 321, 54, 669, 316, - 342, 299, 534, 105, 667, 488, 640, 672, 576, 540, 316, 486, 721, 610, 46, 656, - 447, 171, 616, 464, 190, 531, 297, 321, 762, 752, 533, 175, 134, 14, 381, 433, - 717, 45, 111, 20, 596, 284, 736, 138, 646, 411, 877, 669, 141, 919, 45, 780, - 407, 164, 332, 899, 165, 726, 600, 325, 498, 655, 357, 752, 768, 223, 849, 647, - 63, 310, 863, 251, 366, 304, 282, 738, 675, 410, 389, 244, 31, 121, 303, 263 }; - + /* k = 2 */ + 27, 917, -static const char *codagemc[2787] = { "urA", "xfs", "ypy", "unk", "xdw", "yoz", "pDA", "uls", "pBk", "eBA", - "pAs", "eAk", "prA", "uvs", "xhy", "pnk", "utw", "xgz", "fDA", "pls", "fBk", "frA", "pvs", - "uxy", "fnk", "ptw", "uwz", "fls", "psy", "fvs", "pxy", "ftw", "pwz", "fxy", "yrx", "ufk", - "xFw", "ymz", "onA", "uds", "xEy", "olk", "ucw", "dBA", "oks", "uci", "dAk", "okg", "dAc", - "ovk", "uhw", "xaz", "dnA", "ots", "ugy", "dlk", "osw", "ugj", "dks", "osi", "dvk", "oxw", - "uiz", "dts", "owy", "dsw", "owj", "dxw", "oyz", "dwy", "dwj", "ofA", "uFs", "xCy", "odk", - "uEw", "xCj", "clA", "ocs", "uEi", "ckk", "ocg", "ckc", "ckE", "cvA", "ohs", "uay", "ctk", - "ogw", "uaj", "css", "ogi", "csg", "csa", "cxs", "oiy", "cww", "oij", "cwi", "cyy", "oFk", - "uCw", "xBj", "cdA", "oEs", "uCi", "cck", "oEg", "uCb", "ccc", "oEa", "ccE", "oED", "chk", - "oaw", "uDj", "cgs", "oai", "cgg", "oab", "cga", "cgD", "obj", "cib", "cFA", "oCs", "uBi", - "cEk", "oCg", "uBb", "cEc", "oCa", "cEE", "oCD", "cEC", "cas", "cag", "caa", "cCk", "uAr", - "oBa", "oBD", "cCB", "tfk", "wpw", "yez", "mnA", "tds", "woy", "mlk", "tcw", "woj", "FBA", - "mks", "FAk", "mvk", "thw", "wqz", "FnA", "mts", "tgy", "Flk", "msw", "Fks", "Fkg", "Fvk", - "mxw", "tiz", "Fts", "mwy", "Fsw", "Fsi", "Fxw", "myz", "Fwy", "Fyz", "vfA", "xps", "yuy", - "vdk", "xow", "yuj", "qlA", "vcs", "xoi", "qkk", "vcg", "xob", "qkc", "vca", "mfA", "tFs", - "wmy", "qvA", "mdk", "tEw", "wmj", "qtk", "vgw", "xqj", "hlA", "Ekk", "mcg", "tEb", "hkk", - "qsg", "hkc", "EvA", "mhs", "tay", "hvA", "Etk", "mgw", "taj", "htk", "qww", "vij", "hss", - "Esg", "hsg", "Exs", "miy", "hxs", "Eww", "mij", "hww", "qyj", "hwi", "Eyy", "hyy", "Eyj", - "hyj", "vFk", "xmw", "ytj", "qdA", "vEs", "xmi", "qck", "vEg", "xmb", "qcc", "vEa", "qcE", - "qcC", "mFk", "tCw", "wlj", "qhk", "mEs", "tCi", "gtA", "Eck", "vai", "tCb", "gsk", "Ecc", - "mEa", "gsc", "qga", "mED", "EcC", "Ehk", "maw", "tDj", "gxk", "Egs", "mai", "gws", "qii", - "mab", "gwg", "Ega", "EgD", "Eiw", "mbj", "gyw", "Eii", "gyi", "Eib", "gyb", "gzj", "qFA", - "vCs", "xli", "qEk", "vCg", "xlb", "qEc", "vCa", "qEE", "vCD", "qEC", "qEB", "EFA", "mCs", - "tBi", "ghA", "EEk", "mCg", "tBb", "ggk", "qag", "vDb", "ggc", "EEE", "mCD", "ggE", "qaD", - "ggC", "Eas", "mDi", "gis", "Eag", "mDb", "gig", "qbb", "gia", "EaD", "giD", "gji", "gjb", - "qCk", "vBg", "xkr", "qCc", "vBa", "qCE", "vBD", "qCC", "qCB", "ECk", "mBg", "tAr", "gak", - "ECc", "mBa", "gac", "qDa", "mBD", "gaE", "ECC", "gaC", "ECB", "EDg", "gbg", "gba", "gbD", - "vAq", "vAn", "qBB", "mAq", "EBE", "gDE", "gDC", "gDB", "lfA", "sps", "wey", "ldk", "sow", - "ClA", "lcs", "soi", "Ckk", "lcg", "Ckc", "CkE", "CvA", "lhs", "sqy", "Ctk", "lgw", "sqj", - "Css", "lgi", "Csg", "Csa", "Cxs", "liy", "Cww", "lij", "Cwi", "Cyy", "Cyj", "tpk", "wuw", - "yhj", "ndA", "tos", "wui", "nck", "tog", "wub", "ncc", "toa", "ncE", "toD", "lFk", "smw", - "wdj", "nhk", "lEs", "smi", "atA", "Cck", "tqi", "smb", "ask", "ngg", "lEa", "asc", "CcE", - "asE", "Chk", "law", "snj", "axk", "Cgs", "trj", "aws", "nii", "lab", "awg", "Cga", "awa", - "Ciw", "lbj", "ayw", "Cii", "ayi", "Cib", "Cjj", "azj", "vpA", "xus", "yxi", "vok", "xug", - "yxb", "voc", "xua", "voE", "xuD", "voC", "nFA", "tms", "wti", "rhA", "nEk", "xvi", "wtb", - "rgk", "vqg", "xvb", "rgc", "nEE", "tmD", "rgE", "vqD", "nEB", "CFA", "lCs", "sli", "ahA", - "CEk", "lCg", "slb", "ixA", "agk", "nag", "tnb", "iwk", "rig", "vrb", "lCD", "iwc", "agE", - "naD", "iwE", "CEB", "Cas", "lDi", "ais", "Cag", "lDb", "iys", "aig", "nbb", "iyg", "rjb", - "CaD", "aiD", "Cbi", "aji", "Cbb", "izi", "ajb", "vmk", "xtg", "ywr", "vmc", "xta", "vmE", - "xtD", "vmC", "vmB", "nCk", "tlg", "wsr", "rak", "nCc", "xtr", "rac", "vna", "tlD", "raE", - "nCC", "raC", "nCB", "raB", "CCk", "lBg", "skr", "aak", "CCc", "lBa", "iik", "aac", "nDa", - "lBD", "iic", "rba", "CCC", "iiE", "aaC", "CCB", "aaB", "CDg", "lBr", "abg", "CDa", "ijg", - "aba", "CDD", "ija", "abD", "CDr", "ijr", "vlc", "xsq", "vlE", "xsn", "vlC", "vlB", "nBc", - "tkq", "rDc", "nBE", "tkn", "rDE", "vln", "rDC", "nBB", "rDB", "CBc", "lAq", "aDc", "CBE", - "lAn", "ibc", "aDE", "nBn", "ibE", "rDn", "CBB", "ibC", "aDB", "ibB", "aDq", "ibq", "ibn", - "xsf", "vkl", "tkf", "nAm", "nAl", "CAo", "aBo", "iDo", "CAl", "aBl", "kpk", "BdA", "kos", - "Bck", "kog", "seb", "Bcc", "koa", "BcE", "koD", "Bhk", "kqw", "sfj", "Bgs", "kqi", "Bgg", - "kqb", "Bga", "BgD", "Biw", "krj", "Bii", "Bib", "Bjj", "lpA", "sus", "whi", "lok", "sug", - "loc", "sua", "loE", "suD", "loC", "BFA", "kms", "sdi", "DhA", "BEk", "svi", "sdb", "Dgk", - "lqg", "svb", "Dgc", "BEE", "kmD", "DgE", "lqD", "BEB", "Bas", "kni", "Dis", "Bag", "knb", - "Dig", "lrb", "Dia", "BaD", "Bbi", "Dji", "Bbb", "Djb", "tuk", "wxg", "yir", "tuc", "wxa", - "tuE", "wxD", "tuC", "tuB", "lmk", "stg", "nqk", "lmc", "sta", "nqc", "tva", "stD", "nqE", - "lmC", "nqC", "lmB", "nqB", "BCk", "klg", "Dak", "BCc", "str", "bik", "Dac", "lna", "klD", - "bic", "nra", "BCC", "biE", "DaC", "BCB", "DaB", "BDg", "klr", "Dbg", "BDa", "bjg", "Dba", - "BDD", "bja", "DbD", "BDr", "Dbr", "bjr", "xxc", "yyq", "xxE", "yyn", "xxC", "xxB", "ttc", - "wwq", "vvc", "xxq", "wwn", "vvE", "xxn", "vvC", "ttB", "vvB", "llc", "ssq", "nnc", "llE", - "ssn", "rrc", "nnE", "ttn", "rrE", "vvn", "llB", "rrC", "nnB", "rrB", "BBc", "kkq", "DDc", - "BBE", "kkn", "bbc", "DDE", "lln", "jjc", "bbE", "nnn", "BBB", "jjE", "rrn", "DDB", "jjC", - "BBq", "DDq", "BBn", "bbq", "DDn", "jjq", "bbn", "jjn", "xwo", "yyf", "xwm", "xwl", "tso", - "wwf", "vto", "xwv", "vtm", "tsl", "vtl", "lko", "ssf", "nlo", "lkm", "rno", "nlm", "lkl", - "rnm", "nll", "rnl", "BAo", "kkf", "DBo", "lkv", "bDo", "DBm", "BAl", "jbo", "bDm", "DBl", - "jbm", "bDl", "jbl", "DBv", "jbv", "xwd", "vsu", "vst", "nku", "rlu", "rlt", "DAu", "bBu", - "jDu", "jDt", "ApA", "Aok", "keg", "Aoc", "AoE", "AoC", "Aqs", "Aqg", "Aqa", "AqD", "Ari", - "Arb", "kuk", "kuc", "sha", "kuE", "shD", "kuC", "kuB", "Amk", "kdg", "Bqk", "kvg", "kda", - "Bqc", "kva", "BqE", "kvD", "BqC", "AmB", "BqB", "Ang", "kdr", "Brg", "kvr", "Bra", "AnD", - "BrD", "Anr", "Brr", "sxc", "sxE", "sxC", "sxB", "ktc", "lvc", "sxq", "sgn", "lvE", "sxn", - "lvC", "ktB", "lvB", "Alc", "Bnc", "AlE", "kcn", "Drc", "BnE", "AlC", "DrE", "BnC", "AlB", - "DrC", "BnB", "Alq", "Bnq", "Aln", "Drq", "Bnn", "Drn", "wyo", "wym", "wyl", "swo", "txo", - "wyv", "txm", "swl", "txl", "kso", "sgf", "lto", "swv", "nvo", "ltm", "ksl", "nvm", "ltl", - "nvl", "Ako", "kcf", "Blo", "ksv", "Dno", "Blm", "Akl", "bro", "Dnm", "Bll", "brm", "Dnl", - "Akv", "Blv", "Dnv", "brv", "yze", "yzd", "wye", "xyu", "wyd", "xyt", "swe", "twu", "swd", - "vxu", "twt", "vxt", "kse", "lsu", "ksd", "ntu", "lst", "rvu", "ypk", "zew", "xdA", "yos", - "zei", "xck", "yog", "zeb", "xcc", "yoa", "xcE", "yoD", "xcC", "xhk", "yqw", "zfj", "utA", - "xgs", "yqi", "usk", "xgg", "yqb", "usc", "xga", "usE", "xgD", "usC", "uxk", "xiw", "yrj", - "ptA", "uws", "xii", "psk", "uwg", "xib", "psc", "uwa", "psE", "uwD", "psC", "pxk", "uyw", - "xjj", "ftA", "pws", "uyi", "fsk", "pwg", "uyb", "fsc", "pwa", "fsE", "pwD", "fxk", "pyw", - "uzj", "fws", "pyi", "fwg", "pyb", "fwa", "fyw", "pzj", "fyi", "fyb", "xFA", "yms", "zdi", - "xEk", "ymg", "zdb", "xEc", "yma", "xEE", "ymD", "xEC", "xEB", "uhA", "xas", "yni", "ugk", - "xag", "ynb", "ugc", "xaa", "ugE", "xaD", "ugC", "ugB", "oxA", "uis", "xbi", "owk", "uig", - "xbb", "owc", "uia", "owE", "uiD", "owC", "owB", "dxA", "oys", "uji", "dwk", "oyg", "ujb", - "dwc", "oya", "dwE", "oyD", "dwC", "dys", "ozi", "dyg", "ozb", "dya", "dyD", "dzi", "dzb", - "xCk", "ylg", "zcr", "xCc", "yla", "xCE", "ylD", "xCC", "xCB", "uak", "xDg", "ylr", "uac", - "xDa", "uaE", "xDD", "uaC", "uaB", "oik", "ubg", "xDr", "oic", "uba", "oiE", "ubD", "oiC", - "oiB", "cyk", "ojg", "ubr", "cyc", "oja", "cyE", "ojD", "cyC", "cyB", "czg", "ojr", "cza", - "czD", "czr", "xBc", "ykq", "xBE", "ykn", "xBC", "xBB", "uDc", "xBq", "uDE", "xBn", "uDC", - "uDB", "obc", "uDq", "obE", "uDn", "obC", "obB", "cjc", "obq", "cjE", "obn", "cjC", "cjB", - "cjq", "cjn", "xAo", "ykf", "xAm", "xAl", "uBo", "xAv", "uBm", "uBl", "oDo", "uBv", "oDm", - "oDl", "cbo", "oDv", "cbm", "cbl", "xAe", "xAd", "uAu", "uAt", "oBu", "oBt", "wpA", "yes", - "zFi", "wok", "yeg", "zFb", "woc", "yea", "woE", "yeD", "woC", "woB", "thA", "wqs", "yfi", - "tgk", "wqg", "yfb", "tgc", "wqa", "tgE", "wqD", "tgC", "tgB", "mxA", "tis", "wri", "mwk", - "tig", "wrb", "mwc", "tia", "mwE", "tiD", "mwC", "mwB", "FxA", "mys", "tji", "Fwk", "myg", - "tjb", "Fwc", "mya", "FwE", "myD", "FwC", "Fys", "mzi", "Fyg", "mzb", "Fya", "FyD", "Fzi", - "Fzb", "yuk", "zhg", "hjs", "yuc", "zha", "hbw", "yuE", "zhD", "hDy", "yuC", "yuB", "wmk", - "ydg", "zEr", "xqk", "wmc", "zhr", "xqc", "yva", "ydD", "xqE", "wmC", "xqC", "wmB", "xqB", - "tak", "wng", "ydr", "vik", "tac", "wna", "vic", "xra", "wnD", "viE", "taC", "viC", "taB", - "viB", "mik", "tbg", "wnr", "qyk", "mic", "tba", "qyc", "vja", "tbD", "qyE", "miC", "qyC", - "miB", "qyB", "Eyk", "mjg", "tbr", "hyk", "Eyc", "mja", "hyc", "qza", "mjD", "hyE", "EyC", - "hyC", "EyB", "Ezg", "mjr", "hzg", "Eza", "hza", "EzD", "hzD", "Ezr", "ytc", "zgq", "grw", - "ytE", "zgn", "gny", "ytC", "glz", "ytB", "wlc", "ycq", "xnc", "wlE", "ycn", "xnE", "ytn", - "xnC", "wlB", "xnB", "tDc", "wlq", "vbc", "tDE", "wln", "vbE", "xnn", "vbC", "tDB", "vbB", - "mbc", "tDq", "qjc", "mbE", "tDn", "qjE", "vbn", "qjC", "mbB", "qjB", "Ejc", "mbq", "gzc", - "EjE", "mbn", "gzE", "qjn", "gzC", "EjB", "gzB", "Ejq", "gzq", "Ejn", "gzn", "yso", "zgf", - "gfy", "ysm", "gdz", "ysl", "wko", "ycf", "xlo", "ysv", "xlm", "wkl", "xll", "tBo", "wkv", - "vDo", "tBm", "vDm", "tBl", "vDl", "mDo", "tBv", "qbo", "vDv", "qbm", "mDl", "qbl", "Ebo", - "mDv", "gjo", "Ebm", "gjm", "Ebl", "gjl", "Ebv", "gjv", "yse", "gFz", "ysd", "wke", "xku", - "wkd", "xkt", "tAu", "vBu", "tAt", "vBt", "mBu", "qDu", "mBt", "qDt", "EDu", "gbu", "EDt", - "gbt", "ysF", "wkF", "xkh", "tAh", "vAx", "mAx", "qBx", "wek", "yFg", "zCr", "wec", "yFa", - "weE", "yFD", "weC", "weB", "sqk", "wfg", "yFr", "sqc", "wfa", "sqE", "wfD", "sqC", "sqB", - "lik", "srg", "wfr", "lic", "sra", "liE", "srD", "liC", "liB", "Cyk", "ljg", "srr", "Cyc", - "lja", "CyE", "ljD", "CyC", "CyB", "Czg", "ljr", "Cza", "CzD", "Czr", "yhc", "zaq", "arw", - "yhE", "zan", "any", "yhC", "alz", "yhB", "wdc", "yEq", "wvc", "wdE", "yEn", "wvE", "yhn", - "wvC", "wdB", "wvB", "snc", "wdq", "trc", "snE", "wdn", "trE", "wvn", "trC", "snB", "trB", - "lbc", "snq", "njc", "lbE", "snn", "njE", "trn", "njC", "lbB", "njB", "Cjc", "lbq", "azc", - "CjE", "lbn", "azE", "njn", "azC", "CjB", "azB", "Cjq", "azq", "Cjn", "azn", "zio", "irs", - "rfy", "zim", "inw", "rdz", "zil", "ily", "ikz", "ygo", "zaf", "afy", "yxo", "ziv", "ivy", - "adz", "yxm", "ygl", "itz", "yxl", "wco", "yEf", "wto", "wcm", "xvo", "yxv", "wcl", "xvm", - "wtl", "xvl", "slo", "wcv", "tno", "slm", "vro", "tnm", "sll", "vrm", "tnl", "vrl", "lDo", - "slv", "nbo", "lDm", "rjo", "nbm", "lDl", "rjm", "nbl", "rjl", "Cbo", "lDv", "ajo", "Cbm", - "izo", "ajm", "Cbl", "izm", "ajl", "izl", "Cbv", "ajv", "zie", "ifw", "rFz", "zid", "idy", - "icz", "yge", "aFz", "ywu", "ygd", "ihz", "ywt", "wce", "wsu", "wcd", "xtu", "wst", "xtt", - "sku", "tlu", "skt", "vnu", "tlt", "vnt", "lBu", "nDu", "lBt", "rbu", "nDt", "rbt", "CDu", - "abu", "CDt", "iju", "abt", "ijt", "ziF", "iFy", "iEz", "ygF", "ywh", "wcF", "wsh", "xsx", - "skh", "tkx", "vlx", "lAx", "nBx", "rDx", "CBx", "aDx", "ibx", "iCz", "wFc", "yCq", "wFE", - "yCn", "wFC", "wFB", "sfc", "wFq", "sfE", "wFn", "sfC", "sfB", "krc", "sfq", "krE", "sfn", - "krC", "krB", "Bjc", "krq", "BjE", "krn", "BjC", "BjB", "Bjq", "Bjn", "yao", "zDf", "Dfy", - "yam", "Ddz", "yal", "wEo", "yCf", "who", "wEm", "whm", "wEl", "whl", "sdo", "wEv", "svo", - "sdm", "svm", "sdl", "svl", "kno", "sdv", "lro", "knm", "lrm", "knl", "lrl", "Bbo", "knv", - "Djo", "Bbm", "Djm", "Bbl", "Djl", "Bbv", "Djv", "zbe", "bfw", "npz", "zbd", "bdy", "bcz", - "yae", "DFz", "yiu", "yad", "bhz", "yit", "wEe", "wgu", "wEd", "wxu", "wgt", "wxt", "scu", - "stu", "sct", "tvu", "stt", "tvt", "klu", "lnu", "klt", "nru", "lnt", "nrt", "BDu", "Dbu", - "BDt", "bju", "Dbt", "bjt", "jfs", "rpy", "jdw", "roz", "jcy", "jcj", "zbF", "bFy", "zjh", - "jhy", "bEz", "jgz", "yaF", "yih", "yyx", "wEF", "wgh", "wwx", "xxx", "sch", "ssx", "ttx", - "vvx", "kkx", "llx", "nnx", "rrx", "BBx", "DDx", "bbx", "jFw", "rmz", "jEy", "jEj", "bCz", - "jaz", "jCy", "jCj", "jBj", "wCo", "wCm", "wCl", "sFo", "wCv", "sFm", "sFl", "kfo", "sFv", - "kfm", "kfl", "Aro", "kfv", "Arm", "Arl", "Arv", "yDe", "Bpz", "yDd", "wCe", "wau", "wCd", - "wat", "sEu", "shu", "sEt", "sht", "kdu", "kvu", "kdt", "kvt", "Anu", "Bru", "Ant", "Brt", - "zDp", "Dpy", "Doz", "yDF", "ybh", "wCF", "wah", "wix", "sEh", "sgx", "sxx", "kcx", "ktx", - "lvx", "Alx", "Bnx", "Drx", "bpw", "nuz", "boy", "boj", "Dmz", "bqz", "jps", "ruy", "jow", - "ruj", "joi", "job", "bmy", "jqy", "bmj", "jqj", "jmw", "rtj", "jmi", "jmb", "blj", "jnj", - "jli", "jlb", "jkr", "sCu", "sCt", "kFu", "kFt", "Afu", "Aft", "wDh", "sCh", "sax", "kEx", - "khx", "Adx", "Avx", "Buz", "Duy", "Duj", "buw", "nxj", "bui", "bub", "Dtj", "bvj", "jus", - "rxi", "jug", "rxb", "jua", "juD", "bti", "jvi", "btb", "jvb", "jtg", "rwr", "jta", "jtD", - "bsr", "jtr", "jsq", "jsn", "Bxj", "Dxi", "Dxb", "bxg", "nyr", "bxa", "bxD", "Dwr", "bxr", - "bwq", "bwn", "pjk", "urw", "ejA", "pbs", "uny", "ebk", "pDw", "ulz", "eDs", "pBy", "eBw", - "zfc", "fjk", "prw", "zfE", "fbs", "pny", "zfC", "fDw", "plz", "zfB", "fBy", "yrc", "zfq", - "frw", "yrE", "zfn", "fny", "yrC", "flz", "yrB", "xjc", "yrq", "xjE", "yrn", "xjC", "xjB", - "uzc", "xjq", "uzE", "xjn", "uzC", "uzB", "pzc", "uzq", "pzE", "uzn", "pzC", "djA", "ors", - "ufy", "dbk", "onw", "udz", "dDs", "oly", "dBw", "okz", "dAy", "zdo", "drs", "ovy", "zdm", - "dnw", "otz", "zdl", "dly", "dkz", "yno", "zdv", "dvy", "ynm", "dtz", "ynl", "xbo", "ynv", - "xbm", "xbl", "ujo", "xbv", "ujm", "ujl", "ozo", "ujv", "ozm", "ozl", "crk", "ofw", "uFz", - "cns", "ody", "clw", "ocz", "cky", "ckj", "zcu", "cvw", "ohz", "zct", "cty", "csz", "ylu", - "cxz", "ylt", "xDu", "xDt", "ubu", "ubt", "oju", "ojt", "cfs", "oFy", "cdw", "oEz", "ccy", - "ccj", "zch", "chy", "cgz", "ykx", "xBx", "uDx", "cFw", "oCz", "cEy", "cEj", "caz", "cCy", - "cCj", "FjA", "mrs", "tfy", "Fbk", "mnw", "tdz", "FDs", "mly", "FBw", "mkz", "FAy", "zFo", - "Frs", "mvy", "zFm", "Fnw", "mtz", "zFl", "Fly", "Fkz", "yfo", "zFv", "Fvy", "yfm", "Ftz", - "yfl", "wro", "yfv", "wrm", "wrl", "tjo", "wrv", "tjm", "tjl", "mzo", "tjv", "mzm", "mzl", - "qrk", "vfw", "xpz", "hbA", "qns", "vdy", "hDk", "qlw", "vcz", "hBs", "qky", "hAw", "qkj", - "hAi", "Erk", "mfw", "tFz", "hrk", "Ens", "mdy", "hns", "qty", "mcz", "hlw", "Eky", "hky", - "Ekj", "hkj", "zEu", "Evw", "mhz", "zhu", "zEt", "hvw", "Ety", "zht", "hty", "Esz", "hsz", - "ydu", "Exz", "yvu", "ydt", "hxz", "yvt", "wnu", "xru", "wnt", "xrt", "tbu", "vju", "tbt", - "vjt", "mju", "mjt", "grA", "qfs", "vFy", "gnk", "qdw", "vEz", "gls", "qcy", "gkw", "qcj", - "gki", "gkb", "Efs", "mFy", "gvs", "Edw", "mEz", "gtw", "qgz", "gsy", "Ecj", "gsj", "zEh", - "Ehy", "zgx", "gxy", "Egz", "gwz", "ycx", "ytx", "wlx", "xnx", "tDx", "vbx", "mbx", "gfk", - "qFw", "vCz", "gds", "qEy", "gcw", "qEj", "gci", "gcb", "EFw", "mCz", "ghw", "EEy", "ggy", - "EEj", "ggj", "Eaz", "giz", "gFs", "qCy", "gEw", "qCj", "gEi", "gEb", "ECy", "gay", "ECj", - "gaj", "gCw", "qBj", "gCi", "gCb", "EBj", "gDj", "gBi", "gBb", "Crk", "lfw", "spz", "Cns", - "ldy", "Clw", "lcz", "Cky", "Ckj", "zCu", "Cvw", "lhz", "zCt", "Cty", "Csz", "yFu", "Cxz", - "yFt", "wfu", "wft", "sru", "srt", "lju", "ljt", "arA", "nfs", "tpy", "ank", "ndw", "toz", - "als", "ncy", "akw", "ncj", "aki", "akb", "Cfs", "lFy", "avs", "Cdw", "lEz", "atw", "ngz", - "asy", "Ccj", "asj", "zCh", "Chy", "zax", "axy", "Cgz", "awz", "yEx", "yhx", "wdx", "wvx", - "snx", "trx", "lbx", "rfk", "vpw", "xuz", "inA", "rds", "voy", "ilk", "rcw", "voj", "iks", - "rci", "ikg", "rcb", "ika", "afk", "nFw", "tmz", "ivk", "ads", "nEy", "its", "rgy", "nEj", - "isw", "aci", "isi", "acb", "isb", "CFw", "lCz", "ahw", "CEy", "ixw", "agy", "CEj", "iwy", - "agj", "iwj", "Caz", "aiz", "iyz", "ifA", "rFs", "vmy", "idk", "rEw", "vmj", "ics", "rEi", - "icg", "rEb", "ica", "icD", "aFs", "nCy", "ihs", "aEw", "nCj", "igw", "raj", "igi", "aEb", - "igb", "CCy", "aay", "CCj", "iiy", "aaj", "iij", "iFk", "rCw", "vlj", "iEs", "rCi", "iEg", - "rCb", "iEa", "iED", "aCw", "nBj", "iaw", "aCi", "iai", "aCb", "iab", "CBj", "aDj", "ibj", - "iCs", "rBi", "iCg", "rBb", "iCa", "iCD", "aBi", "iDi", "aBb", "iDb", "iBg", "rAr", "iBa", - "iBD", "aAr", "iBr", "iAq", "iAn", "Bfs", "kpy", "Bdw", "koz", "Bcy", "Bcj", "Bhy", "Bgz", - "yCx", "wFx", "sfx", "krx", "Dfk", "lpw", "suz", "Dds", "loy", "Dcw", "loj", "Dci", "Dcb", - "BFw", "kmz", "Dhw", "BEy", "Dgy", "BEj", "Dgj", "Baz", "Diz", "bfA", "nps", "tuy", "bdk", - "now", "tuj", "bcs", "noi", "bcg", "nob", "bca", "bcD", "DFs", "lmy", "bhs", "DEw", "lmj", - "bgw", "DEi", "bgi", "DEb", "bgb", "BCy", "Day", "BCj", "biy", "Daj", "bij", "rpk", "vuw", - "xxj", "jdA", "ros", "vui", "jck", "rog", "vub", "jcc", "roa", "jcE", "roD", "jcC", "bFk", - "nmw", "ttj", "jhk", "bEs", "nmi", "jgs", "rqi", "nmb", "jgg", "bEa", "jga", "bED", "jgD", - "DCw", "llj", "baw", "DCi", "jiw", "bai", "DCb", "jii", "bab", "jib", "BBj", "DDj", "bbj", - "jjj", "jFA", "rms", "vti", "jEk", "rmg", "vtb", "jEc", "rma", "jEE", "rmD", "jEC", "jEB", - "bCs", "nli", "jas", "bCg", "nlb", "jag", "rnb", "jaa", "bCD", "jaD", "DBi", "bDi", "DBb", - "jbi", "bDb", "jbb", "jCk", "rlg", "vsr", "jCc", "rla", "jCE", "rlD", "jCC", "jCB", "bBg", - "nkr", "jDg", "bBa", "jDa", "bBD", "jDD", "DAr", "bBr", "jDr", "jBc", "rkq", "jBE", "rkn", - "jBC", "jBB", "bAq", "jBq", "bAn", "jBn", "jAo", "rkf", "jAm", "jAl", "bAf", "jAv", "Apw", - "kez", "Aoy", "Aoj", "Aqz", "Bps", "kuy", "Bow", "kuj", "Boi", "Bob", "Amy", "Bqy", "Amj", - "Bqj", "Dpk", "luw", "sxj", "Dos", "lui", "Dog", "lub", "Doa", "DoD", "Bmw", "ktj", "Dqw", - "Bmi", "Dqi", "Bmb", "Dqb", "Alj", "Bnj", "Drj", "bpA", "nus", "txi", "bok", "nug", "txb", - "boc", "nua", "boE", "nuD", "boC", "boB", "Dms", "lti", "bqs", "Dmg", "ltb", "bqg", "nvb", - "bqa", "DmD", "bqD", "Bli", "Dni", "Blb", "bri", "Dnb", "brb", "ruk", "vxg", "xyr", "ruc", - "vxa", "ruE", "vxD", "ruC", "ruB", "bmk", "ntg", "twr", "jqk", "bmc", "nta", "jqc", "rva", - "ntD", "jqE", "bmC", "jqC", "bmB", "jqB", "Dlg", "lsr", "bng", "Dla", "jrg", "bna", "DlD", - "jra", "bnD", "jrD", "Bkr", "Dlr", "bnr", "jrr", "rtc", "vwq", "rtE", "vwn", "rtC", "rtB", - "blc", "nsq", "jnc", "blE", "nsn", "jnE", "rtn", "jnC", "blB", "jnB", "Dkq", "blq", "Dkn", - "jnq", "bln", "jnn", "rso", "vwf", "rsm", "rsl", "bko", "nsf", "jlo", "bkm", "jlm", "bkl", - "jll", "Dkf", "bkv", "jlv", "rse", "rsd", "bke", "jku", "bkd", "jkt", "Aey", "Aej", "Auw", - "khj", "Aui", "Aub", "Adj", "Avj", "Bus", "kxi", "Bug", "kxb", "Bua", "BuD", "Ati", "Bvi", - "Atb", "Bvb", "Duk", "lxg", "syr", "Duc", "lxa", "DuE", "lxD", "DuC", "DuB", "Btg", "kwr", - "Dvg", "lxr", "Dva", "BtD", "DvD", "Asr", "Btr", "Dvr", "nxc", "tyq", "nxE", "tyn", "nxC", - "nxB", "Dtc", "lwq", "bvc", "nxq", "lwn", "bvE", "DtC", "bvC", "DtB", "bvB", "Bsq", "Dtq", - "Bsn", "bvq", "Dtn", "bvn", "vyo", "xzf", "vym", "vyl", "nwo", "tyf", "rxo", "nwm", "rxm", - "nwl", "rxl", "Dso", "lwf", "bto", "Dsm", "jvo", "btm", "Dsl", "jvm", "btl", "jvl", "Bsf", - "Dsv", "btv", "jvv", "vye", "vyd", "nwe", "rwu", "nwd", "rwt", "Dse", "bsu", "Dsd", "jtu", - "bst", "jtt", "vyF", "nwF", "rwh", "DsF", "bsh", "jsx", "Ahi", "Ahb", "Axg", "kir", "Axa", - "AxD", "Agr", "Axr", "Bxc", "kyq", "BxE", "kyn", "BxC", "BxB", "Awq", "Bxq", "Awn", "Bxn", - "lyo", "szf", "lym", "lyl", "Bwo", "kyf", "Dxo", "lyv", "Dxm", "Bwl", "Dxl", "Awf", "Bwv", - "Dxv", "tze", "tzd", "lye", "nyu", "lyd", "nyt", "Bwe", "Dwu", "Bwd", "bxu", "Dwt", "bxt", - "tzF", "lyF", "nyh", "BwF", "Dwh", "bwx", "Aiq", "Ain", "Ayo", "kjf", "Aym", "Ayl", "Aif", - "Ayv", "kze", "kzd", "Aye", "Byu", "Ayd", "Byt", "szp" }; - -/* converts values into bar patterns - replacing Grand Zebu's true type font */ -static const char *PDFttf[35] = { "00000", "00001", "00010", "00011", "00100", "00101", "00110", "00111", - "01000", "01001", "01010", "01011", "01100", "01101", "01110", "01111", "10000", "10001", - "10010", "10011", "10100", "10101", "10110", "10111", "11000", "11001", "11010", - "11011", "11100", "11101", "11110", "11111", "01", "1111111101010100", "11111101000101001"}; + /* k = 4 */ + 522, 568, 723, 809, + + /* k = 8 */ + 237, 308, 436, 284, 646, 653, 428, 379, + + /* k = 16 */ + 274, 562, 232, 755, 599, 524, 801, 132, 295, 116, 442, 428, 295, 42, 176, 65, + + /* k = 32 */ + 361, 575, 922, 525, 176, 586, 640, 321, 536, 742, 677, 742, 687, 284, 193, 517, + 273, 494, 263, 147, 593, 800, 571, 320, 803, 133, 231, 390, 685, 330, 63, 410, + + /* k = 64 */ + 539, 422, 6, 93, 862, 771, 453, 106, 610, 287, 107, 505, 733, 877, 381, 612, + 723, 476, 462, 172, 430, 609, 858, 822, 543, 376, 511, 400, 672, 762, 283, 184, + 440, 35, 519, 31, 460, 594, 225, 535, 517, 352, 605, 158, 651, 201, 488, 502, + 648, 733, 717, 83, 404, 97, 280, 771, 840, 629, 4, 381, 843, 623, 264, 543, + + /* k = 128 */ + 521, 310, 864, 547, 858, 580, 296, 379, 53, 779, 897, 444, 400, 925, 749, 415, + 822, 93, 217, 208, 928, 244, 583, 620, 246, 148, 447, 631, 292, 908, 490, 704, + 516, 258, 457, 907, 594, 723, 674, 292, 272, 96, 684, 432, 686, 606, 860, 569, + 193, 219, 129, 186, 236, 287, 192, 775, 278, 173, 40, 379, 712, 463, 646, 776, + 171, 491, 297, 763, 156, 732, 95, 270, 447, 90, 507, 48, 228, 821, 808, 898, + 784, 663, 627, 378, 382, 262, 380, 602, 754, 336, 89, 614, 87, 432, 670, 616, + 157, 374, 242, 726, 600, 269, 375, 898, 845, 454, 354, 130, 814, 587, 804, 34, + 211, 330, 539, 297, 827, 865, 37, 517, 834, 315, 550, 86, 801, 4, 108, 539, + + /* k = 256 */ + 524, 894, 75, 766, 882, 857, 74, 204, 82, 586, 708, 250, 905, 786, 138, 720, + 858, 194, 311, 913, 275, 190, 375, 850, 438, 733, 194, 280, 201, 280, 828, 757, + 710, 814, 919, 89, 68, 569, 11, 204, 796, 605, 540, 913, 801, 700, 799, 137, + 439, 418, 592, 668, 353, 859, 370, 694, 325, 240, 216, 257, 284, 549, 209, 884, + 315, 70, 329, 793, 490, 274, 877, 162, 749, 812, 684, 461, 334, 376, 849, 521, + 307, 291, 803, 712, 19, 358, 399, 908, 103, 511, 51, 8, 517, 225, 289, 470, + 637, 731, 66, 255, 917, 269, 463, 830, 730, 433, 848, 585, 136, 538, 906, 90, + 2, 290, 743, 199, 655, 903, 329, 49, 802, 580, 355, 588, 188, 462, 10, 134, + 628, 320, 479, 130, 739, 71, 263, 318, 374, 601, 192, 605, 142, 673, 687, 234, + 722, 384, 177, 752, 607, 640, 455, 193, 689, 707, 805, 641, 48, 60, 732, 621, + 895, 544, 261, 852, 655, 309, 697, 755, 756, 60, 231, 773, 434, 421, 726, 528, + 503, 118, 49, 795, 32, 144, 500, 238, 836, 394, 280, 566, 319, 9, 647, 550, + 73, 914, 342, 126, 32, 681, 331, 792, 620, 60, 609, 441, 180, 791, 893, 754, + 605, 383, 228, 749, 760, 213, 54, 297, 134, 54, 834, 299, 922, 191, 910, 532, + 609, 829, 189, 20, 167, 29, 872, 449, 83, 402, 41, 656, 505, 579, 481, 173, + 404, 251, 688, 95, 497, 555, 642, 543, 307, 159, 924, 558, 648, 55, 497, 10, + + /* k = 512 */ + 352, 77, 373, 504, 35, 599, 428, 207, 409, 574, 118, 498, 285, 380, 350, 492, + 197, 265, 920, 155, 914, 299, 229, 643, 294, 871, 306, 88, 87, 193, 352, 781, + 846, 75, 327, 520, 435, 543, 203, 666, 249, 346, 781, 621, 640, 268, 794, 534, + 539, 781, 408, 390, 644, 102, 476, 499, 290, 632, 545, 37, 858, 916, 552, 41, + 542, 289, 122, 272, 383, 800, 485, 98, 752, 472, 761, 107, 784, 860, 658, 741, + 290, 204, 681, 407, 855, 85, 99, 62, 482, 180, 20, 297, 451, 593, 913, 142, + 808, 684, 287, 536, 561, 76, 653, 899, 729, 567, 744, 390, 513, 192, 516, 258, + 240, 518, 794, 395, 768, 848, 51, 610, 384, 168, 190, 826, 328, 596, 786, 303, + 570, 381, 415, 641, 156, 237, 151, 429, 531, 207, 676, 710, 89, 168, 304, 402, + 40, 708, 575, 162, 864, 229, 65, 861, 841, 512, 164, 477, 221, 92, 358, 785, + 288, 357, 850, 836, 827, 736, 707, 94, 8, 494, 114, 521, 2, 499, 851, 543, + 152, 729, 771, 95, 248, 361, 578, 323, 856, 797, 289, 51, 684, 466, 533, 820, + 669, 45, 902, 452, 167, 342, 244, 173, 35, 463, 651, 51, 699, 591, 452, 578, + 37, 124, 298, 332, 552, 43, 427, 119, 662, 777, 475, 850, 764, 364, 578, 911, + 283, 711, 472, 420, 245, 288, 594, 394, 511, 327, 589, 777, 699, 688, 43, 408, + 842, 383, 721, 521, 560, 644, 714, 559, 62, 145, 873, 663, 713, 159, 672, 729, + 624, 59, 193, 417, 158, 209, 563, 564, 343, 693, 109, 608, 563, 365, 181, 772, + 677, 310, 248, 353, 708, 410, 579, 870, 617, 841, 632, 860, 289, 536, 35, 777, + 618, 586, 424, 833, 77, 597, 346, 269, 757, 632, 695, 751, 331, 247, 184, 45, + 787, 680, 18, 66, 407, 369, 54, 492, 228, 613, 830, 922, 437, 519, 644, 905, + 789, 420, 305, 441, 207, 300, 892, 827, 141, 537, 381, 662, 513, 56, 252, 341, + 242, 797, 838, 837, 720, 224, 307, 631, 61, 87, 560, 310, 756, 665, 397, 808, + 851, 309, 473, 795, 378, 31, 647, 915, 459, 806, 590, 731, 425, 216, 548, 249, + 321, 881, 699, 535, 673, 782, 210, 815, 905, 303, 843, 922, 281, 73, 469, 791, + 660, 162, 498, 308, 155, 422, 907, 817, 187, 62, 16, 425, 535, 336, 286, 437, + 375, 273, 610, 296, 183, 923, 116, 667, 751, 353, 62, 366, 691, 379, 687, 842, + 37, 357, 720, 742, 330, 5, 39, 923, 311, 424, 242, 749, 321, 54, 669, 316, + 342, 299, 534, 105, 667, 488, 640, 672, 576, 540, 316, 486, 721, 610, 46, 656, + 447, 171, 616, 464, 190, 531, 297, 321, 762, 752, 533, 175, 134, 14, 381, 433, + 717, 45, 111, 20, 596, 284, 736, 138, 646, 411, 877, 669, 141, 919, 45, 780, + 407, 164, 332, 899, 165, 726, 600, 325, 498, 655, 357, 752, 768, 223, 849, 647, + 63, 310, 863, 251, 366, 304, 282, 738, 675, 410, 389, 244, 31, 121, 303, 263 +}; + + +static const char *codagemc[2787] = { + "urA", "xfs", "ypy", "unk", "xdw", "yoz", "pDA", "uls", "pBk", "eBA", + "pAs", "eAk", "prA", "uvs", "xhy", "pnk", "utw", "xgz", "fDA", "pls", "fBk", "frA", "pvs", + "uxy", "fnk", "ptw", "uwz", "fls", "psy", "fvs", "pxy", "ftw", "pwz", "fxy", "yrx", "ufk", + "xFw", "ymz", "onA", "uds", "xEy", "olk", "ucw", "dBA", "oks", "uci", "dAk", "okg", "dAc", + "ovk", "uhw", "xaz", "dnA", "ots", "ugy", "dlk", "osw", "ugj", "dks", "osi", "dvk", "oxw", + "uiz", "dts", "owy", "dsw", "owj", "dxw", "oyz", "dwy", "dwj", "ofA", "uFs", "xCy", "odk", + "uEw", "xCj", "clA", "ocs", "uEi", "ckk", "ocg", "ckc", "ckE", "cvA", "ohs", "uay", "ctk", + "ogw", "uaj", "css", "ogi", "csg", "csa", "cxs", "oiy", "cww", "oij", "cwi", "cyy", "oFk", + "uCw", "xBj", "cdA", "oEs", "uCi", "cck", "oEg", "uCb", "ccc", "oEa", "ccE", "oED", "chk", + "oaw", "uDj", "cgs", "oai", "cgg", "oab", "cga", "cgD", "obj", "cib", "cFA", "oCs", "uBi", + "cEk", "oCg", "uBb", "cEc", "oCa", "cEE", "oCD", "cEC", "cas", "cag", "caa", "cCk", "uAr", + "oBa", "oBD", "cCB", "tfk", "wpw", "yez", "mnA", "tds", "woy", "mlk", "tcw", "woj", "FBA", + "mks", "FAk", "mvk", "thw", "wqz", "FnA", "mts", "tgy", "Flk", "msw", "Fks", "Fkg", "Fvk", + "mxw", "tiz", "Fts", "mwy", "Fsw", "Fsi", "Fxw", "myz", "Fwy", "Fyz", "vfA", "xps", "yuy", + "vdk", "xow", "yuj", "qlA", "vcs", "xoi", "qkk", "vcg", "xob", "qkc", "vca", "mfA", "tFs", + "wmy", "qvA", "mdk", "tEw", "wmj", "qtk", "vgw", "xqj", "hlA", "Ekk", "mcg", "tEb", "hkk", + "qsg", "hkc", "EvA", "mhs", "tay", "hvA", "Etk", "mgw", "taj", "htk", "qww", "vij", "hss", + "Esg", "hsg", "Exs", "miy", "hxs", "Eww", "mij", "hww", "qyj", "hwi", "Eyy", "hyy", "Eyj", + "hyj", "vFk", "xmw", "ytj", "qdA", "vEs", "xmi", "qck", "vEg", "xmb", "qcc", "vEa", "qcE", + "qcC", "mFk", "tCw", "wlj", "qhk", "mEs", "tCi", "gtA", "Eck", "vai", "tCb", "gsk", "Ecc", + "mEa", "gsc", "qga", "mED", "EcC", "Ehk", "maw", "tDj", "gxk", "Egs", "mai", "gws", "qii", + "mab", "gwg", "Ega", "EgD", "Eiw", "mbj", "gyw", "Eii", "gyi", "Eib", "gyb", "gzj", "qFA", + "vCs", "xli", "qEk", "vCg", "xlb", "qEc", "vCa", "qEE", "vCD", "qEC", "qEB", "EFA", "mCs", + "tBi", "ghA", "EEk", "mCg", "tBb", "ggk", "qag", "vDb", "ggc", "EEE", "mCD", "ggE", "qaD", + "ggC", "Eas", "mDi", "gis", "Eag", "mDb", "gig", "qbb", "gia", "EaD", "giD", "gji", "gjb", + "qCk", "vBg", "xkr", "qCc", "vBa", "qCE", "vBD", "qCC", "qCB", "ECk", "mBg", "tAr", "gak", + "ECc", "mBa", "gac", "qDa", "mBD", "gaE", "ECC", "gaC", "ECB", "EDg", "gbg", "gba", "gbD", + "vAq", "vAn", "qBB", "mAq", "EBE", "gDE", "gDC", "gDB", "lfA", "sps", "wey", "ldk", "sow", + "ClA", "lcs", "soi", "Ckk", "lcg", "Ckc", "CkE", "CvA", "lhs", "sqy", "Ctk", "lgw", "sqj", + "Css", "lgi", "Csg", "Csa", "Cxs", "liy", "Cww", "lij", "Cwi", "Cyy", "Cyj", "tpk", "wuw", + "yhj", "ndA", "tos", "wui", "nck", "tog", "wub", "ncc", "toa", "ncE", "toD", "lFk", "smw", + "wdj", "nhk", "lEs", "smi", "atA", "Cck", "tqi", "smb", "ask", "ngg", "lEa", "asc", "CcE", + "asE", "Chk", "law", "snj", "axk", "Cgs", "trj", "aws", "nii", "lab", "awg", "Cga", "awa", + "Ciw", "lbj", "ayw", "Cii", "ayi", "Cib", "Cjj", "azj", "vpA", "xus", "yxi", "vok", "xug", + "yxb", "voc", "xua", "voE", "xuD", "voC", "nFA", "tms", "wti", "rhA", "nEk", "xvi", "wtb", + "rgk", "vqg", "xvb", "rgc", "nEE", "tmD", "rgE", "vqD", "nEB", "CFA", "lCs", "sli", "ahA", + "CEk", "lCg", "slb", "ixA", "agk", "nag", "tnb", "iwk", "rig", "vrb", "lCD", "iwc", "agE", + "naD", "iwE", "CEB", "Cas", "lDi", "ais", "Cag", "lDb", "iys", "aig", "nbb", "iyg", "rjb", + "CaD", "aiD", "Cbi", "aji", "Cbb", "izi", "ajb", "vmk", "xtg", "ywr", "vmc", "xta", "vmE", + "xtD", "vmC", "vmB", "nCk", "tlg", "wsr", "rak", "nCc", "xtr", "rac", "vna", "tlD", "raE", + "nCC", "raC", "nCB", "raB", "CCk", "lBg", "skr", "aak", "CCc", "lBa", "iik", "aac", "nDa", + "lBD", "iic", "rba", "CCC", "iiE", "aaC", "CCB", "aaB", "CDg", "lBr", "abg", "CDa", "ijg", + "aba", "CDD", "ija", "abD", "CDr", "ijr", "vlc", "xsq", "vlE", "xsn", "vlC", "vlB", "nBc", + "tkq", "rDc", "nBE", "tkn", "rDE", "vln", "rDC", "nBB", "rDB", "CBc", "lAq", "aDc", "CBE", + "lAn", "ibc", "aDE", "nBn", "ibE", "rDn", "CBB", "ibC", "aDB", "ibB", "aDq", "ibq", "ibn", + "xsf", "vkl", "tkf", "nAm", "nAl", "CAo", "aBo", "iDo", "CAl", "aBl", "kpk", "BdA", "kos", + "Bck", "kog", "seb", "Bcc", "koa", "BcE", "koD", "Bhk", "kqw", "sfj", "Bgs", "kqi", "Bgg", + "kqb", "Bga", "BgD", "Biw", "krj", "Bii", "Bib", "Bjj", "lpA", "sus", "whi", "lok", "sug", + "loc", "sua", "loE", "suD", "loC", "BFA", "kms", "sdi", "DhA", "BEk", "svi", "sdb", "Dgk", + "lqg", "svb", "Dgc", "BEE", "kmD", "DgE", "lqD", "BEB", "Bas", "kni", "Dis", "Bag", "knb", + "Dig", "lrb", "Dia", "BaD", "Bbi", "Dji", "Bbb", "Djb", "tuk", "wxg", "yir", "tuc", "wxa", + "tuE", "wxD", "tuC", "tuB", "lmk", "stg", "nqk", "lmc", "sta", "nqc", "tva", "stD", "nqE", + "lmC", "nqC", "lmB", "nqB", "BCk", "klg", "Dak", "BCc", "str", "bik", "Dac", "lna", "klD", + "bic", "nra", "BCC", "biE", "DaC", "BCB", "DaB", "BDg", "klr", "Dbg", "BDa", "bjg", "Dba", + "BDD", "bja", "DbD", "BDr", "Dbr", "bjr", "xxc", "yyq", "xxE", "yyn", "xxC", "xxB", "ttc", + "wwq", "vvc", "xxq", "wwn", "vvE", "xxn", "vvC", "ttB", "vvB", "llc", "ssq", "nnc", "llE", + "ssn", "rrc", "nnE", "ttn", "rrE", "vvn", "llB", "rrC", "nnB", "rrB", "BBc", "kkq", "DDc", + "BBE", "kkn", "bbc", "DDE", "lln", "jjc", "bbE", "nnn", "BBB", "jjE", "rrn", "DDB", "jjC", + "BBq", "DDq", "BBn", "bbq", "DDn", "jjq", "bbn", "jjn", "xwo", "yyf", "xwm", "xwl", "tso", + "wwf", "vto", "xwv", "vtm", "tsl", "vtl", "lko", "ssf", "nlo", "lkm", "rno", "nlm", "lkl", + "rnm", "nll", "rnl", "BAo", "kkf", "DBo", "lkv", "bDo", "DBm", "BAl", "jbo", "bDm", "DBl", + "jbm", "bDl", "jbl", "DBv", "jbv", "xwd", "vsu", "vst", "nku", "rlu", "rlt", "DAu", "bBu", + "jDu", "jDt", "ApA", "Aok", "keg", "Aoc", "AoE", "AoC", "Aqs", "Aqg", "Aqa", "AqD", "Ari", + "Arb", "kuk", "kuc", "sha", "kuE", "shD", "kuC", "kuB", "Amk", "kdg", "Bqk", "kvg", "kda", + "Bqc", "kva", "BqE", "kvD", "BqC", "AmB", "BqB", "Ang", "kdr", "Brg", "kvr", "Bra", "AnD", + "BrD", "Anr", "Brr", "sxc", "sxE", "sxC", "sxB", "ktc", "lvc", "sxq", "sgn", "lvE", "sxn", + "lvC", "ktB", "lvB", "Alc", "Bnc", "AlE", "kcn", "Drc", "BnE", "AlC", "DrE", "BnC", "AlB", + "DrC", "BnB", "Alq", "Bnq", "Aln", "Drq", "Bnn", "Drn", "wyo", "wym", "wyl", "swo", "txo", + "wyv", "txm", "swl", "txl", "kso", "sgf", "lto", "swv", "nvo", "ltm", "ksl", "nvm", "ltl", + "nvl", "Ako", "kcf", "Blo", "ksv", "Dno", "Blm", "Akl", "bro", "Dnm", "Bll", "brm", "Dnl", + "Akv", "Blv", "Dnv", "brv", "yze", "yzd", "wye", "xyu", "wyd", "xyt", "swe", "twu", "swd", + "vxu", "twt", "vxt", "kse", "lsu", "ksd", "ntu", "lst", "rvu", "ypk", "zew", "xdA", "yos", + "zei", "xck", "yog", "zeb", "xcc", "yoa", "xcE", "yoD", "xcC", "xhk", "yqw", "zfj", "utA", + "xgs", "yqi", "usk", "xgg", "yqb", "usc", "xga", "usE", "xgD", "usC", "uxk", "xiw", "yrj", + "ptA", "uws", "xii", "psk", "uwg", "xib", "psc", "uwa", "psE", "uwD", "psC", "pxk", "uyw", + "xjj", "ftA", "pws", "uyi", "fsk", "pwg", "uyb", "fsc", "pwa", "fsE", "pwD", "fxk", "pyw", + "uzj", "fws", "pyi", "fwg", "pyb", "fwa", "fyw", "pzj", "fyi", "fyb", "xFA", "yms", "zdi", + "xEk", "ymg", "zdb", "xEc", "yma", "xEE", "ymD", "xEC", "xEB", "uhA", "xas", "yni", "ugk", + "xag", "ynb", "ugc", "xaa", "ugE", "xaD", "ugC", "ugB", "oxA", "uis", "xbi", "owk", "uig", + "xbb", "owc", "uia", "owE", "uiD", "owC", "owB", "dxA", "oys", "uji", "dwk", "oyg", "ujb", + "dwc", "oya", "dwE", "oyD", "dwC", "dys", "ozi", "dyg", "ozb", "dya", "dyD", "dzi", "dzb", + "xCk", "ylg", "zcr", "xCc", "yla", "xCE", "ylD", "xCC", "xCB", "uak", "xDg", "ylr", "uac", + "xDa", "uaE", "xDD", "uaC", "uaB", "oik", "ubg", "xDr", "oic", "uba", "oiE", "ubD", "oiC", + "oiB", "cyk", "ojg", "ubr", "cyc", "oja", "cyE", "ojD", "cyC", "cyB", "czg", "ojr", "cza", + "czD", "czr", "xBc", "ykq", "xBE", "ykn", "xBC", "xBB", "uDc", "xBq", "uDE", "xBn", "uDC", + "uDB", "obc", "uDq", "obE", "uDn", "obC", "obB", "cjc", "obq", "cjE", "obn", "cjC", "cjB", + "cjq", "cjn", "xAo", "ykf", "xAm", "xAl", "uBo", "xAv", "uBm", "uBl", "oDo", "uBv", "oDm", + "oDl", "cbo", "oDv", "cbm", "cbl", "xAe", "xAd", "uAu", "uAt", "oBu", "oBt", "wpA", "yes", + "zFi", "wok", "yeg", "zFb", "woc", "yea", "woE", "yeD", "woC", "woB", "thA", "wqs", "yfi", + "tgk", "wqg", "yfb", "tgc", "wqa", "tgE", "wqD", "tgC", "tgB", "mxA", "tis", "wri", "mwk", + "tig", "wrb", "mwc", "tia", "mwE", "tiD", "mwC", "mwB", "FxA", "mys", "tji", "Fwk", "myg", + "tjb", "Fwc", "mya", "FwE", "myD", "FwC", "Fys", "mzi", "Fyg", "mzb", "Fya", "FyD", "Fzi", + "Fzb", "yuk", "zhg", "hjs", "yuc", "zha", "hbw", "yuE", "zhD", "hDy", "yuC", "yuB", "wmk", + "ydg", "zEr", "xqk", "wmc", "zhr", "xqc", "yva", "ydD", "xqE", "wmC", "xqC", "wmB", "xqB", + "tak", "wng", "ydr", "vik", "tac", "wna", "vic", "xra", "wnD", "viE", "taC", "viC", "taB", + "viB", "mik", "tbg", "wnr", "qyk", "mic", "tba", "qyc", "vja", "tbD", "qyE", "miC", "qyC", + "miB", "qyB", "Eyk", "mjg", "tbr", "hyk", "Eyc", "mja", "hyc", "qza", "mjD", "hyE", "EyC", + "hyC", "EyB", "Ezg", "mjr", "hzg", "Eza", "hza", "EzD", "hzD", "Ezr", "ytc", "zgq", "grw", + "ytE", "zgn", "gny", "ytC", "glz", "ytB", "wlc", "ycq", "xnc", "wlE", "ycn", "xnE", "ytn", + "xnC", "wlB", "xnB", "tDc", "wlq", "vbc", "tDE", "wln", "vbE", "xnn", "vbC", "tDB", "vbB", + "mbc", "tDq", "qjc", "mbE", "tDn", "qjE", "vbn", "qjC", "mbB", "qjB", "Ejc", "mbq", "gzc", + "EjE", "mbn", "gzE", "qjn", "gzC", "EjB", "gzB", "Ejq", "gzq", "Ejn", "gzn", "yso", "zgf", + "gfy", "ysm", "gdz", "ysl", "wko", "ycf", "xlo", "ysv", "xlm", "wkl", "xll", "tBo", "wkv", + "vDo", "tBm", "vDm", "tBl", "vDl", "mDo", "tBv", "qbo", "vDv", "qbm", "mDl", "qbl", "Ebo", + "mDv", "gjo", "Ebm", "gjm", "Ebl", "gjl", "Ebv", "gjv", "yse", "gFz", "ysd", "wke", "xku", + "wkd", "xkt", "tAu", "vBu", "tAt", "vBt", "mBu", "qDu", "mBt", "qDt", "EDu", "gbu", "EDt", + "gbt", "ysF", "wkF", "xkh", "tAh", "vAx", "mAx", "qBx", "wek", "yFg", "zCr", "wec", "yFa", + "weE", "yFD", "weC", "weB", "sqk", "wfg", "yFr", "sqc", "wfa", "sqE", "wfD", "sqC", "sqB", + "lik", "srg", "wfr", "lic", "sra", "liE", "srD", "liC", "liB", "Cyk", "ljg", "srr", "Cyc", + "lja", "CyE", "ljD", "CyC", "CyB", "Czg", "ljr", "Cza", "CzD", "Czr", "yhc", "zaq", "arw", + "yhE", "zan", "any", "yhC", "alz", "yhB", "wdc", "yEq", "wvc", "wdE", "yEn", "wvE", "yhn", + "wvC", "wdB", "wvB", "snc", "wdq", "trc", "snE", "wdn", "trE", "wvn", "trC", "snB", "trB", + "lbc", "snq", "njc", "lbE", "snn", "njE", "trn", "njC", "lbB", "njB", "Cjc", "lbq", "azc", + "CjE", "lbn", "azE", "njn", "azC", "CjB", "azB", "Cjq", "azq", "Cjn", "azn", "zio", "irs", + "rfy", "zim", "inw", "rdz", "zil", "ily", "ikz", "ygo", "zaf", "afy", "yxo", "ziv", "ivy", + "adz", "yxm", "ygl", "itz", "yxl", "wco", "yEf", "wto", "wcm", "xvo", "yxv", "wcl", "xvm", + "wtl", "xvl", "slo", "wcv", "tno", "slm", "vro", "tnm", "sll", "vrm", "tnl", "vrl", "lDo", + "slv", "nbo", "lDm", "rjo", "nbm", "lDl", "rjm", "nbl", "rjl", "Cbo", "lDv", "ajo", "Cbm", + "izo", "ajm", "Cbl", "izm", "ajl", "izl", "Cbv", "ajv", "zie", "ifw", "rFz", "zid", "idy", + "icz", "yge", "aFz", "ywu", "ygd", "ihz", "ywt", "wce", "wsu", "wcd", "xtu", "wst", "xtt", + "sku", "tlu", "skt", "vnu", "tlt", "vnt", "lBu", "nDu", "lBt", "rbu", "nDt", "rbt", "CDu", + "abu", "CDt", "iju", "abt", "ijt", "ziF", "iFy", "iEz", "ygF", "ywh", "wcF", "wsh", "xsx", + "skh", "tkx", "vlx", "lAx", "nBx", "rDx", "CBx", "aDx", "ibx", "iCz", "wFc", "yCq", "wFE", + "yCn", "wFC", "wFB", "sfc", "wFq", "sfE", "wFn", "sfC", "sfB", "krc", "sfq", "krE", "sfn", + "krC", "krB", "Bjc", "krq", "BjE", "krn", "BjC", "BjB", "Bjq", "Bjn", "yao", "zDf", "Dfy", + "yam", "Ddz", "yal", "wEo", "yCf", "who", "wEm", "whm", "wEl", "whl", "sdo", "wEv", "svo", + "sdm", "svm", "sdl", "svl", "kno", "sdv", "lro", "knm", "lrm", "knl", "lrl", "Bbo", "knv", + "Djo", "Bbm", "Djm", "Bbl", "Djl", "Bbv", "Djv", "zbe", "bfw", "npz", "zbd", "bdy", "bcz", + "yae", "DFz", "yiu", "yad", "bhz", "yit", "wEe", "wgu", "wEd", "wxu", "wgt", "wxt", "scu", + "stu", "sct", "tvu", "stt", "tvt", "klu", "lnu", "klt", "nru", "lnt", "nrt", "BDu", "Dbu", + "BDt", "bju", "Dbt", "bjt", "jfs", "rpy", "jdw", "roz", "jcy", "jcj", "zbF", "bFy", "zjh", + "jhy", "bEz", "jgz", "yaF", "yih", "yyx", "wEF", "wgh", "wwx", "xxx", "sch", "ssx", "ttx", + "vvx", "kkx", "llx", "nnx", "rrx", "BBx", "DDx", "bbx", "jFw", "rmz", "jEy", "jEj", "bCz", + "jaz", "jCy", "jCj", "jBj", "wCo", "wCm", "wCl", "sFo", "wCv", "sFm", "sFl", "kfo", "sFv", + "kfm", "kfl", "Aro", "kfv", "Arm", "Arl", "Arv", "yDe", "Bpz", "yDd", "wCe", "wau", "wCd", + "wat", "sEu", "shu", "sEt", "sht", "kdu", "kvu", "kdt", "kvt", "Anu", "Bru", "Ant", "Brt", + "zDp", "Dpy", "Doz", "yDF", "ybh", "wCF", "wah", "wix", "sEh", "sgx", "sxx", "kcx", "ktx", + "lvx", "Alx", "Bnx", "Drx", "bpw", "nuz", "boy", "boj", "Dmz", "bqz", "jps", "ruy", "jow", + "ruj", "joi", "job", "bmy", "jqy", "bmj", "jqj", "jmw", "rtj", "jmi", "jmb", "blj", "jnj", + "jli", "jlb", "jkr", "sCu", "sCt", "kFu", "kFt", "Afu", "Aft", "wDh", "sCh", "sax", "kEx", + "khx", "Adx", "Avx", "Buz", "Duy", "Duj", "buw", "nxj", "bui", "bub", "Dtj", "bvj", "jus", + "rxi", "jug", "rxb", "jua", "juD", "bti", "jvi", "btb", "jvb", "jtg", "rwr", "jta", "jtD", + "bsr", "jtr", "jsq", "jsn", "Bxj", "Dxi", "Dxb", "bxg", "nyr", "bxa", "bxD", "Dwr", "bxr", + "bwq", "bwn", "pjk", "urw", "ejA", "pbs", "uny", "ebk", "pDw", "ulz", "eDs", "pBy", "eBw", + "zfc", "fjk", "prw", "zfE", "fbs", "pny", "zfC", "fDw", "plz", "zfB", "fBy", "yrc", "zfq", + "frw", "yrE", "zfn", "fny", "yrC", "flz", "yrB", "xjc", "yrq", "xjE", "yrn", "xjC", "xjB", + "uzc", "xjq", "uzE", "xjn", "uzC", "uzB", "pzc", "uzq", "pzE", "uzn", "pzC", "djA", "ors", + "ufy", "dbk", "onw", "udz", "dDs", "oly", "dBw", "okz", "dAy", "zdo", "drs", "ovy", "zdm", + "dnw", "otz", "zdl", "dly", "dkz", "yno", "zdv", "dvy", "ynm", "dtz", "ynl", "xbo", "ynv", + "xbm", "xbl", "ujo", "xbv", "ujm", "ujl", "ozo", "ujv", "ozm", "ozl", "crk", "ofw", "uFz", + "cns", "ody", "clw", "ocz", "cky", "ckj", "zcu", "cvw", "ohz", "zct", "cty", "csz", "ylu", + "cxz", "ylt", "xDu", "xDt", "ubu", "ubt", "oju", "ojt", "cfs", "oFy", "cdw", "oEz", "ccy", + "ccj", "zch", "chy", "cgz", "ykx", "xBx", "uDx", "cFw", "oCz", "cEy", "cEj", "caz", "cCy", + "cCj", "FjA", "mrs", "tfy", "Fbk", "mnw", "tdz", "FDs", "mly", "FBw", "mkz", "FAy", "zFo", + "Frs", "mvy", "zFm", "Fnw", "mtz", "zFl", "Fly", "Fkz", "yfo", "zFv", "Fvy", "yfm", "Ftz", + "yfl", "wro", "yfv", "wrm", "wrl", "tjo", "wrv", "tjm", "tjl", "mzo", "tjv", "mzm", "mzl", + "qrk", "vfw", "xpz", "hbA", "qns", "vdy", "hDk", "qlw", "vcz", "hBs", "qky", "hAw", "qkj", + "hAi", "Erk", "mfw", "tFz", "hrk", "Ens", "mdy", "hns", "qty", "mcz", "hlw", "Eky", "hky", + "Ekj", "hkj", "zEu", "Evw", "mhz", "zhu", "zEt", "hvw", "Ety", "zht", "hty", "Esz", "hsz", + "ydu", "Exz", "yvu", "ydt", "hxz", "yvt", "wnu", "xru", "wnt", "xrt", "tbu", "vju", "tbt", + "vjt", "mju", "mjt", "grA", "qfs", "vFy", "gnk", "qdw", "vEz", "gls", "qcy", "gkw", "qcj", + "gki", "gkb", "Efs", "mFy", "gvs", "Edw", "mEz", "gtw", "qgz", "gsy", "Ecj", "gsj", "zEh", + "Ehy", "zgx", "gxy", "Egz", "gwz", "ycx", "ytx", "wlx", "xnx", "tDx", "vbx", "mbx", "gfk", + "qFw", "vCz", "gds", "qEy", "gcw", "qEj", "gci", "gcb", "EFw", "mCz", "ghw", "EEy", "ggy", + "EEj", "ggj", "Eaz", "giz", "gFs", "qCy", "gEw", "qCj", "gEi", "gEb", "ECy", "gay", "ECj", + "gaj", "gCw", "qBj", "gCi", "gCb", "EBj", "gDj", "gBi", "gBb", "Crk", "lfw", "spz", "Cns", + "ldy", "Clw", "lcz", "Cky", "Ckj", "zCu", "Cvw", "lhz", "zCt", "Cty", "Csz", "yFu", "Cxz", + "yFt", "wfu", "wft", "sru", "srt", "lju", "ljt", "arA", "nfs", "tpy", "ank", "ndw", "toz", + "als", "ncy", "akw", "ncj", "aki", "akb", "Cfs", "lFy", "avs", "Cdw", "lEz", "atw", "ngz", + "asy", "Ccj", "asj", "zCh", "Chy", "zax", "axy", "Cgz", "awz", "yEx", "yhx", "wdx", "wvx", + "snx", "trx", "lbx", "rfk", "vpw", "xuz", "inA", "rds", "voy", "ilk", "rcw", "voj", "iks", + "rci", "ikg", "rcb", "ika", "afk", "nFw", "tmz", "ivk", "ads", "nEy", "its", "rgy", "nEj", + "isw", "aci", "isi", "acb", "isb", "CFw", "lCz", "ahw", "CEy", "ixw", "agy", "CEj", "iwy", + "agj", "iwj", "Caz", "aiz", "iyz", "ifA", "rFs", "vmy", "idk", "rEw", "vmj", "ics", "rEi", + "icg", "rEb", "ica", "icD", "aFs", "nCy", "ihs", "aEw", "nCj", "igw", "raj", "igi", "aEb", + "igb", "CCy", "aay", "CCj", "iiy", "aaj", "iij", "iFk", "rCw", "vlj", "iEs", "rCi", "iEg", + "rCb", "iEa", "iED", "aCw", "nBj", "iaw", "aCi", "iai", "aCb", "iab", "CBj", "aDj", "ibj", + "iCs", "rBi", "iCg", "rBb", "iCa", "iCD", "aBi", "iDi", "aBb", "iDb", "iBg", "rAr", "iBa", + "iBD", "aAr", "iBr", "iAq", "iAn", "Bfs", "kpy", "Bdw", "koz", "Bcy", "Bcj", "Bhy", "Bgz", + "yCx", "wFx", "sfx", "krx", "Dfk", "lpw", "suz", "Dds", "loy", "Dcw", "loj", "Dci", "Dcb", + "BFw", "kmz", "Dhw", "BEy", "Dgy", "BEj", "Dgj", "Baz", "Diz", "bfA", "nps", "tuy", "bdk", + "now", "tuj", "bcs", "noi", "bcg", "nob", "bca", "bcD", "DFs", "lmy", "bhs", "DEw", "lmj", + "bgw", "DEi", "bgi", "DEb", "bgb", "BCy", "Day", "BCj", "biy", "Daj", "bij", "rpk", "vuw", + "xxj", "jdA", "ros", "vui", "jck", "rog", "vub", "jcc", "roa", "jcE", "roD", "jcC", "bFk", + "nmw", "ttj", "jhk", "bEs", "nmi", "jgs", "rqi", "nmb", "jgg", "bEa", "jga", "bED", "jgD", + "DCw", "llj", "baw", "DCi", "jiw", "bai", "DCb", "jii", "bab", "jib", "BBj", "DDj", "bbj", + "jjj", "jFA", "rms", "vti", "jEk", "rmg", "vtb", "jEc", "rma", "jEE", "rmD", "jEC", "jEB", + "bCs", "nli", "jas", "bCg", "nlb", "jag", "rnb", "jaa", "bCD", "jaD", "DBi", "bDi", "DBb", + "jbi", "bDb", "jbb", "jCk", "rlg", "vsr", "jCc", "rla", "jCE", "rlD", "jCC", "jCB", "bBg", + "nkr", "jDg", "bBa", "jDa", "bBD", "jDD", "DAr", "bBr", "jDr", "jBc", "rkq", "jBE", "rkn", + "jBC", "jBB", "bAq", "jBq", "bAn", "jBn", "jAo", "rkf", "jAm", "jAl", "bAf", "jAv", "Apw", + "kez", "Aoy", "Aoj", "Aqz", "Bps", "kuy", "Bow", "kuj", "Boi", "Bob", "Amy", "Bqy", "Amj", + "Bqj", "Dpk", "luw", "sxj", "Dos", "lui", "Dog", "lub", "Doa", "DoD", "Bmw", "ktj", "Dqw", + "Bmi", "Dqi", "Bmb", "Dqb", "Alj", "Bnj", "Drj", "bpA", "nus", "txi", "bok", "nug", "txb", + "boc", "nua", "boE", "nuD", "boC", "boB", "Dms", "lti", "bqs", "Dmg", "ltb", "bqg", "nvb", + "bqa", "DmD", "bqD", "Bli", "Dni", "Blb", "bri", "Dnb", "brb", "ruk", "vxg", "xyr", "ruc", + "vxa", "ruE", "vxD", "ruC", "ruB", "bmk", "ntg", "twr", "jqk", "bmc", "nta", "jqc", "rva", + "ntD", "jqE", "bmC", "jqC", "bmB", "jqB", "Dlg", "lsr", "bng", "Dla", "jrg", "bna", "DlD", + "jra", "bnD", "jrD", "Bkr", "Dlr", "bnr", "jrr", "rtc", "vwq", "rtE", "vwn", "rtC", "rtB", + "blc", "nsq", "jnc", "blE", "nsn", "jnE", "rtn", "jnC", "blB", "jnB", "Dkq", "blq", "Dkn", + "jnq", "bln", "jnn", "rso", "vwf", "rsm", "rsl", "bko", "nsf", "jlo", "bkm", "jlm", "bkl", + "jll", "Dkf", "bkv", "jlv", "rse", "rsd", "bke", "jku", "bkd", "jkt", "Aey", "Aej", "Auw", + "khj", "Aui", "Aub", "Adj", "Avj", "Bus", "kxi", "Bug", "kxb", "Bua", "BuD", "Ati", "Bvi", + "Atb", "Bvb", "Duk", "lxg", "syr", "Duc", "lxa", "DuE", "lxD", "DuC", "DuB", "Btg", "kwr", + "Dvg", "lxr", "Dva", "BtD", "DvD", "Asr", "Btr", "Dvr", "nxc", "tyq", "nxE", "tyn", "nxC", + "nxB", "Dtc", "lwq", "bvc", "nxq", "lwn", "bvE", "DtC", "bvC", "DtB", "bvB", "Bsq", "Dtq", + "Bsn", "bvq", "Dtn", "bvn", "vyo", "xzf", "vym", "vyl", "nwo", "tyf", "rxo", "nwm", "rxm", + "nwl", "rxl", "Dso", "lwf", "bto", "Dsm", "jvo", "btm", "Dsl", "jvm", "btl", "jvl", "Bsf", + "Dsv", "btv", "jvv", "vye", "vyd", "nwe", "rwu", "nwd", "rwt", "Dse", "bsu", "Dsd", "jtu", + "bst", "jtt", "vyF", "nwF", "rwh", "DsF", "bsh", "jsx", "Ahi", "Ahb", "Axg", "kir", "Axa", + "AxD", "Agr", "Axr", "Bxc", "kyq", "BxE", "kyn", "BxC", "BxB", "Awq", "Bxq", "Awn", "Bxn", + "lyo", "szf", "lym", "lyl", "Bwo", "kyf", "Dxo", "lyv", "Dxm", "Bwl", "Dxl", "Awf", "Bwv", + "Dxv", "tze", "tzd", "lye", "nyu", "lyd", "nyt", "Bwe", "Dwu", "Bwd", "bxu", "Dwt", "bxt", + "tzF", "lyF", "nyh", "BwF", "Dwh", "bwx", "Aiq", "Ain", "Ayo", "kjf", "Aym", "Ayl", "Aif", + "Ayv", "kze", "kzd", "Aye", "Byu", "Ayd", "Byt", "szp" +}; + +static const char *PDFttf[35] = { + /* converts values into bar patterns - replacing Grand Zebu's true type font */ + "00000", "00001", "00010", "00011", "00100", "00101", "00110", "00111", + "01000", "01001", "01010", "01011", "01100", "01101", "01110", "01111", "10000", "10001", + "10010", "10011", "10100", "10101", "10110", "10111", "11000", "11001", "11010", + "11011", "11100", "11101", "11110", "11111", "01", "1111111101010100", "11111101000101001"}; /* MicroPDF417 coefficients from ISO/IEC 24728:2006 Annex F */ static const int Microcoeffs[344] = { - /* k = 7 */ - 76, 925, 537, 597, 784, 691, 437, - - /* k = 8 */ - 237, 308, 436, 284, 646, 653, 428, 379, - - /* k = 9 */ - 567, 527, 622, 257, 289, 362, 501, 441, 205, - - /* k = 10 */ - 377, 457, 64, 244, 826, 841, 818, 691, 266, 612, - - /* k = 11 */ - 462, 45, 565, 708, 825, 213, 15, 68, 327, 602, 904, - - /* k = 12 */ - 597, 864, 757, 201, 646, 684, 347, 127, 388, 7, 69, 851, - - /* k = 13 */ - 764, 713, 342, 384, 606, 583, 322, 592, 678, 204, 184, 394, 692, - - /* k = 14 */ - 669, 677, 154, 187, 241, 286, 274, 354, 478, 915, 691, 833, 105, 215, - - /* k = 15 */ - 460, 829, 476, 109, 904, 664, 230, 5, 80, 74, 550, 575, 147, 868, 642, - - /* k = 16 */ - 274, 562, 232, 755, 599, 524, 801, 132, 295, 116, 442, 428, 295, 42, 176, 65, - - /* k = 18 */ - 279, 577, 315, 624, 37, 855, 275, 739, 120, 297, 312, 202, 560, 321, 233, 756, - 760, 573, - - /* k = 21 */ - 108, 519, 781, 534, 129, 425, 681, 553, 422, 716, 763, 693, 624, 610, 310, 691, - 347, 165, 193, 259, 568, - - /* k = 26 */ - 443, 284, 887, 544, 788, 93, 477, 760, 331, 608, 269, 121, 159, 830, 446, 893, - 699, 245, 441, 454, 325, 858, 131, 847, 764, 169, - - /* k = 32 */ - 361, 575, 922, 525, 176, 586, 640, 321, 536, 742, 677, 742, 687, 284, 193, 517, - 273, 494, 263, 147, 593, 800, 571, 320, 803, 133, 231, 390, 685, 330, 63, 410, - - /* k = 38 */ - 234, 228, 438, 848, 133, 703, 529, 721, 788, 322, 280, 159, 738, 586, 388, 684, - 445, 680, 245, 595, 614, 233, 812, 32, 284, 658, 745, 229, 95, 689, 920, 771, - 554, 289, 231, 125, 117, 518, - - /* k = 44 */ - 476, 36, 659, 848, 678, 64, 764, 840, 157, 915, 470, 876, 109, 25, 632, 405, - 417, 436, 714, 60, 376, 97, 413, 706, 446, 21, 3, 773, 569, 267, 272, 213, - 31, 560, 231, 758, 103, 271, 572, 436, 339, 730, 82, 285, - - /* k = 50 */ - 923, 797, 576, 875, 156, 706, 63, 81, 257, 874, 411, 416, 778, 50, 205, 303, - 188, 535, 909, 155, 637, 230, 534, 96, 575, 102, 264, 233, 919, 593, 865, 26, - 579, 623, 766, 146, 10, 739, 246, 127, 71, 244, 211, 477, 920, 876, 427, 820, - 718, 435 }; + /* k = 7 */ + 76, 925, 537, 597, 784, 691, 437, + + /* k = 8 */ + 237, 308, 436, 284, 646, 653, 428, 379, + + /* k = 9 */ + 567, 527, 622, 257, 289, 362, 501, 441, 205, + + /* k = 10 */ + 377, 457, 64, 244, 826, 841, 818, 691, 266, 612, + + /* k = 11 */ + 462, 45, 565, 708, 825, 213, 15, 68, 327, 602, 904, + + /* k = 12 */ + 597, 864, 757, 201, 646, 684, 347, 127, 388, 7, 69, 851, + + /* k = 13 */ + 764, 713, 342, 384, 606, 583, 322, 592, 678, 204, 184, 394, 692, + + /* k = 14 */ + 669, 677, 154, 187, 241, 286, 274, 354, 478, 915, 691, 833, 105, 215, + + /* k = 15 */ + 460, 829, 476, 109, 904, 664, 230, 5, 80, 74, 550, 575, 147, 868, 642, + + /* k = 16 */ + 274, 562, 232, 755, 599, 524, 801, 132, 295, 116, 442, 428, 295, 42, 176, 65, + + /* k = 18 */ + 279, 577, 315, 624, 37, 855, 275, 739, 120, 297, 312, 202, 560, 321, 233, 756, + 760, 573, + + /* k = 21 */ + 108, 519, 781, 534, 129, 425, 681, 553, 422, 716, 763, 693, 624, 610, 310, 691, + 347, 165, 193, 259, 568, + + /* k = 26 */ + 443, 284, 887, 544, 788, 93, 477, 760, 331, 608, 269, 121, 159, 830, 446, 893, + 699, 245, 441, 454, 325, 858, 131, 847, 764, 169, + + /* k = 32 */ + 361, 575, 922, 525, 176, 586, 640, 321, 536, 742, 677, 742, 687, 284, 193, 517, + 273, 494, 263, 147, 593, 800, 571, 320, 803, 133, 231, 390, 685, 330, 63, 410, + + /* k = 38 */ + 234, 228, 438, 848, 133, 703, 529, 721, 788, 322, 280, 159, 738, 586, 388, 684, + 445, 680, 245, 595, 614, 233, 812, 32, 284, 658, 745, 229, 95, 689, 920, 771, + 554, 289, 231, 125, 117, 518, + + /* k = 44 */ + 476, 36, 659, 848, 678, 64, 764, 840, 157, 915, 470, 876, 109, 25, 632, 405, + 417, 436, 714, 60, 376, 97, 413, 706, 446, 21, 3, 773, 569, 267, 272, 213, + 31, 560, 231, 758, 103, 271, 572, 436, 339, 730, 82, 285, + + /* k = 50 */ + 923, 797, 576, 875, 156, 706, 63, 81, 257, 874, 411, 416, 778, 50, 205, 303, + 188, 535, 909, 155, 637, 230, 534, 96, 575, 102, 264, 233, 919, 593, 865, 26, + 579, 623, 766, 146, 10, 739, 246, 127, 71, 244, 211, 477, 920, 876, 427, 820, + 718, 435 +}; /* rows, columns, error codewords, k-offset of valid MicroPDF417 sizes from ISO/IEC 24728:2006 */ -static const int MicroVariants[170] = -{ 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, - 11, 14, 17, 20, 24, 28, 8, 11, 14, 17, 20, 23, 26, 6, 8, 10, 12, 15, 20, 26, 32, 38, 44, 4, 6, 8, 10, 12, 15, 20, 26, 32, 38, 44, - 7, 7, 7, 8, 8, 8, 8, 9, 9, 10, 11, 13, 15, 12, 14, 16, 18, 21, 26, 32, 38, 44, 50, 8, 12, 14, 16, 18, 21, 26, 32, 38, 44, 50, - 0, 0, 0, 7, 7, 7, 7, 15, 15, 24, 34, 57, 84, 45, 70, 99, 115, 133, 154, 180, 212, 250, 294, 7, 45, 70, 99, 115, 133, 154, 180, 212, 250, 294 }; +static const int MicroVariants[170] ={ + 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, + 11, 14, 17, 20, 24, 28, 8, 11, 14, 17, 20, 23, 26, 6, 8, 10, 12, 15, 20, 26, 32, 38, 44, 4, 6, 8, 10, 12, 15, 20, 26, 32, 38, 44, + 7, 7, 7, 8, 8, 8, 8, 9, 9, 10, 11, 13, 15, 12, 14, 16, 18, 21, 26, 32, 38, 44, 50, 8, 12, 14, 16, 18, 21, 26, 32, 38, 44, 50, + 0, 0, 0, 7, 7, 7, 7, 15, 15, 24, 34, 57, 84, 45, 70, 99, 115, 133, 154, 180, 212, 250, 294, 7, 45, 70, 99, 115, 133, 154, 180, 212, 250, 294 +}; /* rows, columns, error codewords, k-offset */ /* following is Left RAP, Centre RAP, Right RAP and Start Cluster from ISO/IEC 24728:2006 tables 10, 11 and 12 */ -static const int RAPTable[136] = -{ 1, 8, 36, 19, 9, 25, 1, 1, 8, 36, 19, 9, 27, 1, 7, 15, 25, 37, 1, 1, 21, 15, 1, 47, 1, 7, 15, 25, 37, 1, 1, 21, 15, 1, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 7, 15, 25, 37, 17, 9, 29, 31, 25, 19, 1, 7, 15, 25, 37, 17, 9, 29, 31, 25, - 9, 8, 36, 19, 17, 33, 1, 9, 8, 36, 19, 17, 35, 1, 7, 15, 25, 37, 33, 17, 37, 47, 49, 43, 1, 7, 15, 25, 37, 33, 17, 37, 47, 49, - 0, 3, 6, 0, 6, 0, 0, 0, 3, 6, 0, 6, 6, 0, 0, 6, 0, 0, 0, 0, 6, 6, 0, 3, 0, 0, 6, 0, 0, 0, 0, 6, 6, 0 }; +static const int RAPTable[136] ={ + 1, 8, 36, 19, 9, 25, 1, 1, 8, 36, 19, 9, 27, 1, 7, 15, 25, 37, 1, 1, 21, 15, 1, 47, 1, 7, 15, 25, 37, 1, 1, 21, 15, 1, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 7, 15, 25, 37, 17, 9, 29, 31, 25, 19, 1, 7, 15, 25, 37, 17, 9, 29, 31, 25, + 9, 8, 36, 19, 17, 33, 1, 9, 8, 36, 19, 17, 35, 1, 7, 15, 25, 37, 33, 17, 37, 47, 49, 43, 1, 7, 15, 25, 37, 33, 17, 37, 47, 49, + 0, 3, 6, 0, 6, 0, 0, 0, 3, 6, 0, 6, 6, 0, 0, 6, 0, 0, 0, 0, 6, 6, 0, 3, 0, 0, 6, 0, 0, 0, 0, 6, 6, 0 +}; /* Left and Right Row Address Pattern from Table 2 */ -static const char *RAPLR[53] = {"", "221311", "311311", "312211", "222211", "213211", "214111", "223111", - "313111", "322111", "412111", "421111", "331111", "241111", "232111", "231211", "321211", - "411211", "411121", "411112", "321112", "312112", "311212", "311221", "311131", "311122", - "311113", "221113", "221122", "221131", "221221", "222121", "312121", "321121", "231121", - "231112", "222112", "213112", "212212", "212221", "212131", "212122", "212113", "211213", - "211123", "211132", "211141", "211231", "211222", "211312", "211321", "211411", "212311" }; +static const char *RAPLR[53] = { + "", "221311", "311311", "312211", "222211", "213211", "214111", "223111", + "313111", "322111", "412111", "421111", "331111", "241111", "232111", "231211", "321211", + "411211", "411121", "411112", "321112", "312112", "311212", "311221", "311131", "311122", + "311113", "221113", "221122", "221131", "221221", "222121", "312121", "321121", "231121", + "231112", "222112", "213112", "212212", "212221", "212131", "212122", "212113", "211213", + "211123", "211132", "211141", "211231", "211222", "211312", "211321", "211411", "212311" +}; /* Centre Row Address Pattern from Table 2 */ -static const char *RAPC[53] = {"", "112231", "121231", "122131", "131131", "131221", "132121", "141121", - "141211", "142111", "133111", "132211", "131311", "122311", "123211", "124111", "115111", - "114211", "114121", "123121", "123112", "122212", "122221", "121321", "121411", "112411", - "113311", "113221", "113212", "113122", "122122", "131122", "131113", "122113", "113113", - "112213", "112222", "112312", "112321", "111421", "111331", "111322", "111232", "111223", - "111133", "111124", "111214", "112114", "121114", "121123", "121132", "112132", "112141" }; +static const char *RAPC[53] = { + "", "112231", "121231", "122131", "131131", "131221", "132121", "141121", + "141211", "142111", "133111", "132211", "131311", "122311", "123211", "124111", "115111", + "114211", "114121", "123121", "123112", "122212", "122221", "121321", "121411", "112411", + "113311", "113221", "113212", "113122", "122122", "131122", "131113", "122113", "113113", + "112213", "112222", "112312", "112321", "111421", "111331", "111322", "111232", "111223", + "111133", "111124", "111214", "112114", "121114", "121123", "121132", "112132", "112141" +}; void byteprocess(int *chainemc, int *mclength, unsigned char chaine[], int start, int length, int block); \ No newline at end of file diff --git a/backend/plessey.c b/backend/plessey.c index f62b7a0d..1082207f 100644 --- a/backend/plessey.c +++ b/backend/plessey.c @@ -2,7 +2,7 @@ /* libzint - the open source barcode library - Copyright (C) 2008 Robin Stuart + Copyright (C) 2008-2016 Robin Stuart Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions @@ -28,7 +28,7 @@ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ + */ #include #include @@ -37,472 +37,457 @@ #define SSET "0123456789ABCDEF" -static const char *PlessTable[16] = {"13131313", "31131313", "13311313", "31311313", "13133113", "31133113", - "13313113", "31313113", "13131331", "31131331", "13311331", "31311331", "13133131", - "31133131", "13313131", "31313131"}; +static const char *PlessTable[16] = { + "13131313", "31131313", "13311313", "31311313", "13133113", "31133113", + "13313113", "31313113", "13131331", "31131331", "13311331", "31311331", "13133131", + "31133131", "13313131", "31313131" +}; -static const char *MSITable[10] = {"12121212", "12121221", "12122112", "12122121", "12211212", "12211221", - "12212112", "12212121", "21121212", "21121221"}; +static const char *MSITable[10] = { + "12121212", "12121221", "12122112", "12122121", "12211212", "12211221", + "12212112", "12212121", "21121212", "21121221" +}; +/* Not MSI/Plessey but the older Plessey standard */ +int plessey(struct zint_symbol *symbol, unsigned char source[], int length) { -int plessey(struct zint_symbol *symbol, unsigned char source[], int length) -{ /* Not MSI/Plessey but the older Plessey standard */ + unsigned int i, check; + unsigned char *checkptr; + static const char grid[9] = {1, 1, 1, 1, 0, 1, 0, 0, 1}; + char dest[1024]; /* 8 + 65 * 8 + 8 * 2 + 9 + 1 ~ 1024 */ + int error_number; - unsigned int i, check; - unsigned char *checkptr; - static const char grid[9] = {1,1,1,1,0,1,0,0,1}; - char dest[1024]; /* 8 + 65 * 8 + 8 * 2 + 9 + 1 ~ 1024 */ - int error_number; + error_number = 0; - error_number = 0; + if (length > 65) { + strcpy(symbol->errtxt, "Input too long"); + return ZINT_ERROR_TOO_LONG; + } + error_number = is_sane(SSET, source, length); + if (error_number == ZINT_ERROR_INVALID_DATA) { + strcpy(symbol->errtxt, "Invalid characters in data"); + return error_number; + } + checkptr = (unsigned char *) calloc(1, length * 4 + 8); - if(length > 65) { - strcpy(symbol->errtxt, "Input too long"); - return ZINT_ERROR_TOO_LONG; - } - error_number = is_sane(SSET, source, length); - if(error_number == ZINT_ERROR_INVALID_DATA) { - strcpy(symbol->errtxt, "Invalid characters in data"); - return error_number; - } - checkptr = (unsigned char *)calloc (1, length * 4 + 8); + /* Start character */ + strcpy(dest, "31311331"); - /* Start character */ - strcpy(dest, "31311331"); + /* Data area */ + for (i = 0; i < length; i++) { + check = posn(SSET, source[i]); + lookup(SSET, PlessTable, source[i], dest); + checkptr[4 * i] = check & 1; + checkptr[4 * i + 1] = (check >> 1) & 1; + checkptr[4 * i + 2] = (check >> 2) & 1; + checkptr[4 * i + 3] = (check >> 3) & 1; + } - /* Data area */ - for(i = 0; i < length; i++) - { - check = posn(SSET, source[i]); - lookup(SSET, PlessTable, source[i], dest); - checkptr[4*i] = check & 1; - checkptr[4*i+1] = (check >> 1) & 1; - checkptr[4*i+2] = (check >> 2) & 1; - checkptr[4*i+3] = (check >> 3) & 1; - } + /* CRC check digit code adapted from code by Leonid A. Broukhis + used in GNU Barcode */ - /* CRC check digit code adapted from code by Leonid A. Broukhis - used in GNU Barcode */ + for (i = 0; i < (4 * length); i++) { + int j; + if (checkptr[i]) + for (j = 0; j < 9; j++) + checkptr[i + j] ^= grid[j]; + } - for (i = 0; i < (4 * length); i++) { - int j; - if (checkptr[i]) - for (j = 0; j < 9; j++) - checkptr[i+j] ^= grid[j]; - } + for (i = 0; i < 8; i++) { + switch (checkptr[length * 4 + i]) { + case 0: concat(dest, "13"); + break; + case 1: concat(dest, "31"); + break; + } + } - for (i = 0; i < 8; i++) { - switch(checkptr[length * 4 + i]) - { - case 0: concat(dest, "13"); break; - case 1: concat(dest, "31"); break; - } - } + /* Stop character */ + concat(dest, "331311313"); - /* Stop character */ - concat(dest, "331311313"); - - expand(symbol, dest); - ustrcpy(symbol->text, source); - free(checkptr); - return error_number; + expand(symbol, dest); + ustrcpy(symbol->text, source); + free(checkptr); + return error_number; } -int msi_plessey(struct zint_symbol *symbol, unsigned char source[], int length) -{ /* Plain MSI Plessey - does not calculate any check character */ +/* Plain MSI Plessey - does not calculate any check character */ +int msi_plessey(struct zint_symbol *symbol, unsigned char source[], int length) { - unsigned int i; - char dest[512]; /* 2 + 55 * 8 + 3 + 1 ~ 512 */ + unsigned int i; + char dest[512]; /* 2 + 55 * 8 + 3 + 1 ~ 512 */ - if(length > 55) { - strcpy(symbol->errtxt, "Input too long"); - return ZINT_ERROR_TOO_LONG; - } + if (length > 55) { + strcpy(symbol->errtxt, "Input too long"); + return ZINT_ERROR_TOO_LONG; + } - /* start character */ - strcpy(dest, "21"); + /* start character */ + strcpy(dest, "21"); - for(i = 0; i < length; i++) - { - lookup(NEON, MSITable, source[i], dest); - } + for (i = 0; i < length; i++) { + lookup(NEON, MSITable, source[i], dest); + } - /* Stop character */ - concat (dest, "121"); + /* Stop character */ + concat(dest, "121"); - expand(symbol, dest); - ustrcpy(symbol->text, source); - return 0; + expand(symbol, dest); + ustrcpy(symbol->text, source); + return 0; } -int msi_plessey_mod10(struct zint_symbol *symbol, unsigned char source[], int length) -{ /* MSI Plessey with Modulo 10 check digit - algorithm from Barcode Island - http://www.barcodeisland.com/ */ +/* MSI Plessey with Modulo 10 check digit - algorithm from Barcode Island + * http://www.barcodeisland.com/ */ +int msi_plessey_mod10(struct zint_symbol *symbol, unsigned char source[], int length) { + - unsigned long i, wright, dau, pedwar, pump, n; - char un[200], tri[32]; - int error_number, h; - char dest[1000]; + unsigned long i, wright, dau, pedwar, pump, n; + char un[200], tri[32]; + int error_number, h; + char dest[1000]; - error_number = 0; + error_number = 0; - if(length > 18) { - strcpy(symbol->errtxt, "Input too long"); - return ZINT_ERROR_TOO_LONG; - } + if (length > 18) { + strcpy(symbol->errtxt, "Input too long"); + return ZINT_ERROR_TOO_LONG; + } - /* start character */ - strcpy(dest, "21"); + /* start character */ + strcpy(dest, "21"); - /* draw data section */ - for(i = 0; i < length; i++) - { - lookup(NEON, MSITable, source[i], dest); - } + /* draw data section */ + for (i = 0; i < length; i++) { + lookup(NEON, MSITable, source[i], dest); + } - /* calculate check digit */ - wright = 0; - n = !(length & 1); - for(i = n; i < length; i += 2) - { - un[wright++] = source[i]; - } - un[wright] = '\0'; + /* calculate check digit */ + wright = 0; + n = !(length & 1); + for (i = n; i < length; i += 2) { + un[wright++] = source[i]; + } + un[wright] = '\0'; - dau = strtoul(un, NULL, 10); - dau *= 2; + dau = strtoul(un, NULL, 10); + dau *= 2; - sprintf(tri, "%ld", dau); + sprintf(tri, "%ld", dau); - pedwar = 0; - h = strlen(tri); - for(i = 0; i < h; i++) - { - pedwar += ctoi(tri[i]); - } + pedwar = 0; + h = strlen(tri); + for (i = 0; i < h; i++) { + pedwar += ctoi(tri[i]); + } - n = length & 1; - for(i = n; i < length; i+=2) - { - pedwar += ctoi(source[i]); - } + n = length & 1; + for (i = n; i < length; i += 2) { + pedwar += ctoi(source[i]); + } - pump = (10 - pedwar % 10); - if(pump == 10) - { - pump = 0; - } + pump = (10 - pedwar % 10); + if (pump == 10) { + pump = 0; + } - /* draw check digit */ - lookup(NEON, MSITable, itoc(pump), dest); + /* draw check digit */ + lookup(NEON, MSITable, itoc(pump), dest); - /* Stop character */ - concat (dest, "121"); - expand(symbol, dest); + /* Stop character */ + concat(dest, "121"); + expand(symbol, dest); - ustrcpy(symbol->text, source); - symbol->text[length] = itoc(pump); - symbol->text[length + 1] = '\0'; - return error_number; + ustrcpy(symbol->text, source); + symbol->text[length] = itoc(pump); + symbol->text[length + 1] = '\0'; + return error_number; } -int msi_plessey_mod1010(struct zint_symbol *symbol, unsigned char source[], const unsigned int src_len) -{ /* MSI Plessey with two Modulo 10 check digits - algorithm from - Barcode Island http://www.barcodeisland.com/ */ +/* MSI Plessey with two Modulo 10 check digits - algorithm from + * Barcode Island http://www.barcodeisland.com/ */ +int msi_plessey_mod1010(struct zint_symbol *symbol, unsigned char source[], const unsigned int src_len) { + - unsigned long i, n, wright, dau, pedwar, pump, chwech; - char un[16], tri[32]; - int error_number, h; - char dest[1000]; + unsigned long i, n, wright, dau, pedwar, pump, chwech; + char un[16], tri[32]; + int error_number, h; + char dest[1000]; - error_number = 0; + error_number = 0; - if(src_len > 18) { /* No Entry Stack Smashers! limit because of str->number conversion*/ - strcpy(symbol->errtxt, "Input too long"); - return ZINT_ERROR_TOO_LONG; - } + if (src_len > 18) { + /* No Entry Stack Smashers! limit because of str->number conversion*/ + strcpy(symbol->errtxt, "Input too long"); + return ZINT_ERROR_TOO_LONG; + } - /* start character */ - strcpy(dest, "21"); + /* start character */ + strcpy(dest, "21"); - /* draw data section */ - for(i = 0; i < src_len; i++) - { - lookup(NEON, MSITable, source[i], dest); - } + /* draw data section */ + for (i = 0; i < src_len; i++) { + lookup(NEON, MSITable, source[i], dest); + } - /* calculate first check digit */ - wright = 0; + /* calculate first check digit */ + wright = 0; - n = !(src_len & 1); - for(i = n; i < src_len; i += 2) - { - un[wright++] = source[i]; - } - un[wright] = '\0'; + n = !(src_len & 1); + for (i = n; i < src_len; i += 2) { + un[wright++] = source[i]; + } + un[wright] = '\0'; - dau = strtoul(un, NULL, 10); - dau *= 2; + dau = strtoul(un, NULL, 10); + dau *= 2; - sprintf(tri, "%ld", dau); + sprintf(tri, "%ld", dau); - pedwar = 0; - h = strlen(tri); - for(i = 0; i < h; i++) - { - pedwar += ctoi(tri[i]); - } + pedwar = 0; + h = strlen(tri); + for (i = 0; i < h; i++) { + pedwar += ctoi(tri[i]); + } - n = src_len & 1; - for(i = n; i < src_len; i += 2) - { - pedwar += ctoi(source[i]); - } + n = src_len & 1; + for (i = n; i < src_len; i += 2) { + pedwar += ctoi(source[i]); + } - pump = 10 - pedwar % 10; - if(pump == 10) - { - pump = 0; - } + pump = 10 - pedwar % 10; + if (pump == 10) { + pump = 0; + } - /* calculate second check digit */ - wright = 0; - n = src_len & 1; - for(i = n; i < src_len; i += 2) - { - un[wright++] = source[i]; - } - un[wright++] = itoc(pump); - un[wright] = '\0'; + /* calculate second check digit */ + wright = 0; + n = src_len & 1; + for (i = n; i < src_len; i += 2) { + un[wright++] = source[i]; + } + un[wright++] = itoc(pump); + un[wright] = '\0'; - dau = strtoul(un, NULL, 10); - dau *= 2; + dau = strtoul(un, NULL, 10); + dau *= 2; - sprintf(tri, "%ld", dau); + sprintf(tri, "%ld", dau); - pedwar = 0; - h = strlen(tri); - for(i = 0; i < h; i++) - { - pedwar += ctoi(tri[i]); - } + pedwar = 0; + h = strlen(tri); + for (i = 0; i < h; i++) { + pedwar += ctoi(tri[i]); + } - i = !(src_len & 1); - for(; i < src_len; i += 2) - { - pedwar += ctoi(source[i]); - } + i = !(src_len & 1); + for (; i < src_len; i += 2) { + pedwar += ctoi(source[i]); + } - chwech = 10 - pedwar % 10; - if(chwech == 10) - { - chwech = 0; - } + chwech = 10 - pedwar % 10; + if (chwech == 10) { + chwech = 0; + } - /* Draw check digits */ - lookup(NEON, MSITable, itoc(pump), dest); - lookup(NEON, MSITable, itoc(chwech), dest); + /* Draw check digits */ + lookup(NEON, MSITable, itoc(pump), dest); + lookup(NEON, MSITable, itoc(chwech), dest); - /* Stop character */ - concat (dest, "121"); + /* Stop character */ + concat(dest, "121"); - expand(symbol, dest); + expand(symbol, dest); - ustrcpy(symbol->text, source); - symbol->text[src_len] = itoc(pump); - symbol->text[src_len + 1] = itoc(chwech); - symbol->text[src_len + 2] = '\0'; + ustrcpy(symbol->text, source); + symbol->text[src_len] = itoc(pump); + symbol->text[src_len + 1] = itoc(chwech); + symbol->text[src_len + 2] = '\0'; - return error_number; + return error_number; } +/* Calculate a Modulo 11 check digit using the system discussed on Wikipedia - + see http://en.wikipedia.org/wiki/Talk:MSI_Barcode */ +int msi_plessey_mod11(struct zint_symbol *symbol, unsigned char source[], const unsigned int src_len) { + /* uses the IBM weight system */ + int i, weight, x, check; + int error_number; + char dest[1000]; -int msi_plessey_mod11(struct zint_symbol *symbol, unsigned char source[], const unsigned int src_len) -{ - /* Calculate a Modulo 11 check digit using the system discussed on Wikipedia - - see http://en.wikipedia.org/wiki/Talk:MSI_Barcode */ - /* uses the IBM weight system */ + error_number = 0; - int i, weight, x, check; - int error_number; - char dest[1000]; + if (src_len > 55) { + strcpy(symbol->errtxt, "Input too long"); + return ZINT_ERROR_TOO_LONG; + } - error_number = 0; + /* start character */ + strcpy(dest, "21"); - if(src_len > 55) { - strcpy(symbol->errtxt, "Input too long"); - return ZINT_ERROR_TOO_LONG; - } + /* draw data section */ + for (i = 0; i < src_len; i++) { + lookup(NEON, MSITable, source[i], dest); + } - /* start character */ - strcpy(dest, "21"); + /* calculate check digit */ + x = 0; + weight = 2; + for (i = src_len - 1; i >= 0; i--) { + x += weight * ctoi(source[i]); + weight++; + if (weight > 7) { + weight = 2; + } + } - /* draw data section */ - for(i = 0; i < src_len; i++) - { - lookup(NEON, MSITable, source[i], dest); - } + check = (11 - (x % 11)) % 11; + if (check == 10) { + lookup(NEON, MSITable, '1', dest); + lookup(NEON, MSITable, '0', dest); + } else { + lookup(NEON, MSITable, itoc(check), dest); + } - /* calculate check digit */ - x = 0; - weight = 2; - for(i = src_len - 1; i >= 0; i--) { - x += weight * ctoi(source[i]); - weight++; - if(weight > 7) { - weight = 2; - } - } + /* stop character */ + concat(dest, "121"); - check = (11 - (x % 11)) % 11; - if(check == 10) { - lookup(NEON, MSITable, '1', dest); - lookup(NEON, MSITable, '0', dest); - } else { - lookup(NEON, MSITable, itoc(check), dest); - } + expand(symbol, dest); - /* stop character */ - concat (dest, "121"); + ustrcpy(symbol->text, source); + if (check == 10) { + concat((char*) symbol->text, "10"); + } else { + symbol->text[src_len] = itoc(check); + symbol->text[src_len + 1] = '\0'; + } - expand(symbol, dest); - - ustrcpy(symbol->text, source); - if(check == 10) { - concat((char* )symbol->text, "10"); - } else { - symbol->text[src_len] = itoc(check); - symbol->text[src_len + 1] = '\0'; - } - - return error_number; + return error_number; } -int msi_plessey_mod1110(struct zint_symbol *symbol, unsigned char source[], const unsigned int src_len) -{ - /* Combining the Barcode Island and Wikipedia code */ - /* Verified against http://www.bokai.com/BarcodeJSP/applet/BarcodeSampleApplet.htm */ - /* Weighted using the IBM system */ +/* Combining the Barcode Island and Wikipedia code + * Verified against http://www.bokai.com/BarcodeJSP/applet/BarcodeSampleApplet.htm */ +int msi_plessey_mod1110(struct zint_symbol *symbol, unsigned char source[], const unsigned int src_len) { + /* Weighted using the IBM system */ + unsigned long i, weight, x, check, wright, dau, pedwar, pump, h; + long si; + char un[16], tri[16]; + int error_number; + char dest[1000]; + unsigned char temp[32]; + unsigned int temp_len; - unsigned long i, weight, x, check, wright, dau, pedwar, pump, h; - long si; - char un[16], tri[16]; - int error_number; - char dest[1000]; - unsigned char temp[32]; - unsigned int temp_len; + error_number = 0; - error_number = 0; + if (src_len > 18) { + strcpy(symbol->errtxt, "Input too long"); + return ZINT_ERROR_TOO_LONG; + } - if(src_len > 18) { - strcpy(symbol->errtxt, "Input too long"); - return ZINT_ERROR_TOO_LONG; - } + /* start character */ + strcpy(dest, "21"); - /* start character */ - strcpy(dest, "21"); + /* draw data section */ + for (i = 0; i < src_len; i++) { + lookup(NEON, MSITable, source[i], dest); + } - /* draw data section */ - for(i = 0; i < src_len; i++) - { - lookup(NEON, MSITable, source[i], dest); - } + /* calculate first (mod 11) digit */ + x = 0; + weight = 2; + for (si = src_len - 1; si >= 0; si--) { + x += weight * ctoi(source[si]); + weight++; + if (weight > 7) { + weight = 2; + } + } - /* calculate first (mod 11) digit */ - x = 0; - weight = 2; - for(si = src_len - 1; si >= 0; si--) { - x += weight * ctoi(source[si]); - weight++; - if(weight > 7) { - weight = 2; - } - } + check = (11 - (x % 11)) % 11; + ustrcpy(temp, source); + temp_len = src_len; + if (check == 10) { + lookup(NEON, MSITable, '1', dest); + lookup(NEON, MSITable, '0', dest); + uconcat(temp, (unsigned char *) "10"); + temp_len += 2; + } else { + lookup(NEON, MSITable, itoc(check), dest); + temp[temp_len++] = itoc(check); + temp[temp_len] = '\0'; + } - check = (11 - (x % 11)) % 11; - ustrcpy(temp, source); - temp_len = src_len; - if(check == 10) { - lookup(NEON, MSITable, '1', dest); - lookup(NEON, MSITable, '0', dest); - uconcat(temp, (unsigned char *)"10"); - temp_len += 2; - } else { - lookup(NEON, MSITable, itoc(check), dest); - temp[temp_len++] = itoc(check); - temp[temp_len] = '\0'; - } + /* calculate second (mod 10) check digit */ + wright = 0; + i = !(temp_len & 1); + for (; i < temp_len; i += 2) { + un[wright++] = temp[i]; + } + un[wright] = '\0'; - /* calculate second (mod 10) check digit */ - wright = 0; - i = !(temp_len & 1); - for(; i < temp_len; i += 2) - { - un[wright++] = temp[i]; - } - un[wright] = '\0'; + dau = strtoul(un, NULL, 10); + dau *= 2; - dau = strtoul(un, NULL, 10); - dau *= 2; + sprintf(tri, "%ld", dau); - sprintf(tri, "%ld", dau); + pedwar = 0; + h = strlen(tri); + for (i = 0; i < h; i++) { + pedwar += ctoi(tri[i]); + } - pedwar = 0; - h = strlen(tri); - for(i = 0; i < h; i++) - { - pedwar += ctoi(tri[i]); - } + i = temp_len & 1; + for (; i < temp_len; i += 2) { + pedwar += ctoi(temp[i]); + } - i = temp_len & 1; - for(; i < temp_len; i+=2) - { - pedwar += ctoi(temp[i]); - } + pump = 10 - pedwar % 10; + if (pump == 10) { + pump = 0; + } - pump = 10 - pedwar % 10; - if(pump == 10) - { - pump = 0; - } + /* draw check digit */ + lookup(NEON, MSITable, itoc(pump), dest); - /* draw check digit */ - lookup(NEON, MSITable, itoc(pump), dest); + /* stop character */ + concat(dest, "121"); + expand(symbol, dest); - /* stop character */ - concat (dest, "121"); - expand(symbol, dest); - - temp[temp_len++] = itoc(pump); - temp[temp_len] = '\0'; + temp[temp_len++] = itoc(pump); + temp[temp_len] = '\0'; - ustrcpy(symbol->text, temp); - return error_number; + ustrcpy(symbol->text, temp); + return error_number; } int msi_handle(struct zint_symbol *symbol, unsigned char source[], int length) { - int error_number; + int error_number; - error_number = is_sane(NEON, source, length); - if(error_number != 0) { - strcpy(symbol->errtxt, "Invalid characters in input data"); - return ZINT_ERROR_INVALID_DATA; - } + error_number = is_sane(NEON, source, length); + if (error_number != 0) { + strcpy(symbol->errtxt, "Invalid characters in input data"); + return ZINT_ERROR_INVALID_DATA; + } - if((symbol->option_2 < 0) || (symbol->option_2 > 4)) { - symbol->option_2 = 0; - } + if ((symbol->option_2 < 0) || (symbol->option_2 > 4)) { + symbol->option_2 = 0; + } - switch(symbol->option_2) { - case 0: error_number = msi_plessey(symbol, source, length); break; - case 1: error_number = msi_plessey_mod10(symbol, source, length); break; - case 2: error_number = msi_plessey_mod1010(symbol, source, length); break; - case 3: error_number = msi_plessey_mod11(symbol, source, length); break; - case 4: error_number = msi_plessey_mod1110(symbol, source, length); break; - } + switch (symbol->option_2) { + case 0: error_number = msi_plessey(symbol, source, length); + break; + case 1: error_number = msi_plessey_mod10(symbol, source, length); + break; + case 2: error_number = msi_plessey_mod1010(symbol, source, length); + break; + case 3: error_number = msi_plessey_mod11(symbol, source, length); + break; + case 4: error_number = msi_plessey_mod1110(symbol, source, length); + break; + } - return error_number; + return error_number; } diff --git a/backend/png.c b/backend/png.c index cf2b7984..593745a7 100644 --- a/backend/png.c +++ b/backend/png.c @@ -2,7 +2,7 @@ /* libzint - the open source barcode library - Copyright (C) 2009 Robin Stuart + Copyright (C) 2009-2016 Robin Stuart Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions @@ -28,7 +28,7 @@ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ + */ #include #ifdef _MSC_VER @@ -58,6 +58,7 @@ #define BMP_DATA 200 #ifndef NO_PNG + struct mainprog_info_type { long width; long height; @@ -65,1101 +66,1079 @@ struct mainprog_info_type { jmp_buf jmpbuf; }; -static void writepng_error_handler(png_structp png_ptr, png_const_charp msg) -{ - struct mainprog_info_type *graphic; +static void writepng_error_handler(png_structp png_ptr, png_const_charp msg) { + struct mainprog_info_type *graphic; fprintf(stderr, "writepng libpng error: %s\n", msg); fflush(stderr); - graphic = (struct mainprog_info_type*)png_get_error_ptr(png_ptr); - if (graphic == NULL) { /* we are completely hosed now */ + graphic = (struct mainprog_info_type*) png_get_error_ptr(png_ptr); + if (graphic == NULL) { + /* we are completely hosed now */ fprintf(stderr, - "writepng severe error: jmpbuf not recoverable; terminating.\n"); + "writepng severe error: jmpbuf not recoverable; terminating.\n"); fflush(stderr); return; } longjmp(graphic->jmpbuf, 1); } -int png_pixel_plot(struct zint_symbol *symbol, int image_height, int image_width, char *pixelbuf, int rotate_angle) -{ - struct mainprog_info_type wpng_info; - struct mainprog_info_type *graphic; - png_structp png_ptr; - png_infop info_ptr; - unsigned char *image_data; - int i, row, column, errno; - int fgred, fggrn, fgblu, bgred, bggrn, bgblu; - +int png_pixel_plot(struct zint_symbol *symbol, int image_height, int image_width, char *pixelbuf, int rotate_angle) { + struct mainprog_info_type wpng_info; + struct mainprog_info_type *graphic; + png_structp png_ptr; + png_infop info_ptr; + unsigned char *image_data; + int i, row, column, errno; + int fgred, fggrn, fgblu, bgred, bggrn, bgblu; + #ifndef _MSC_VER - unsigned char outdata[image_width * 3]; + unsigned char outdata[image_width * 3]; #else - unsigned char* outdata = (unsigned char*)_alloca(image_width * 3); + unsigned char* outdata = (unsigned char*) _alloca(image_width * 3); #endif - graphic = &wpng_info; + graphic = &wpng_info; - switch(rotate_angle) { - case 0: - case 180: - graphic->width = image_width; - graphic->height = image_height; - break; - case 90: - case 270: - graphic->width = image_height; - graphic->height = image_width; - break; - } + switch (rotate_angle) { + case 0: + case 180: + graphic->width = image_width; + graphic->height = image_height; + break; + case 90: + case 270: + graphic->width = image_height; + graphic->height = image_width; + break; + } - /* sort out colour options */ - to_upper((unsigned char*)symbol->fgcolour); - to_upper((unsigned char*)symbol->bgcolour); + /* sort out colour options */ + to_upper((unsigned char*) symbol->fgcolour); + to_upper((unsigned char*) symbol->bgcolour); - if(strlen(symbol->fgcolour) != 6) { - strcpy(symbol->errtxt, "Malformed foreground colour target"); - return ZINT_ERROR_INVALID_OPTION; - } - if(strlen(symbol->bgcolour) != 6) { - strcpy(symbol->errtxt, "Malformed background colour target"); - return ZINT_ERROR_INVALID_OPTION; - } - errno = is_sane(SSET, (unsigned char*)symbol->fgcolour, strlen(symbol->fgcolour)); - if (errno == ZINT_ERROR_INVALID_DATA) { - strcpy(symbol->errtxt, "Malformed foreground colour target"); - return ZINT_ERROR_INVALID_OPTION; - } - errno = is_sane(SSET, (unsigned char*)symbol->bgcolour, strlen(symbol->bgcolour)); - if (errno == ZINT_ERROR_INVALID_DATA) { - strcpy(symbol->errtxt, "Malformed background colour target"); - return ZINT_ERROR_INVALID_OPTION; - } + if (strlen(symbol->fgcolour) != 6) { + strcpy(symbol->errtxt, "Malformed foreground colour target"); + return ZINT_ERROR_INVALID_OPTION; + } + if (strlen(symbol->bgcolour) != 6) { + strcpy(symbol->errtxt, "Malformed background colour target"); + return ZINT_ERROR_INVALID_OPTION; + } + errno = is_sane(SSET, (unsigned char*) symbol->fgcolour, strlen(symbol->fgcolour)); + if (errno == ZINT_ERROR_INVALID_DATA) { + strcpy(symbol->errtxt, "Malformed foreground colour target"); + return ZINT_ERROR_INVALID_OPTION; + } + errno = is_sane(SSET, (unsigned char*) symbol->bgcolour, strlen(symbol->bgcolour)); + if (errno == ZINT_ERROR_INVALID_DATA) { + strcpy(symbol->errtxt, "Malformed background colour target"); + return ZINT_ERROR_INVALID_OPTION; + } - fgred = (16 * ctoi(symbol->fgcolour[0])) + ctoi(symbol->fgcolour[1]); - fggrn = (16 * ctoi(symbol->fgcolour[2])) + ctoi(symbol->fgcolour[3]); - fgblu = (16 * ctoi(symbol->fgcolour[4])) + ctoi(symbol->fgcolour[5]); - bgred = (16 * ctoi(symbol->bgcolour[0])) + ctoi(symbol->bgcolour[1]); - bggrn = (16 * ctoi(symbol->bgcolour[2])) + ctoi(symbol->bgcolour[3]); - bgblu = (16 * ctoi(symbol->bgcolour[4])) + ctoi(symbol->bgcolour[5]); + fgred = (16 * ctoi(symbol->fgcolour[0])) + ctoi(symbol->fgcolour[1]); + fggrn = (16 * ctoi(symbol->fgcolour[2])) + ctoi(symbol->fgcolour[3]); + fgblu = (16 * ctoi(symbol->fgcolour[4])) + ctoi(symbol->fgcolour[5]); + bgred = (16 * ctoi(symbol->bgcolour[0])) + ctoi(symbol->bgcolour[1]); + bggrn = (16 * ctoi(symbol->bgcolour[2])) + ctoi(symbol->bgcolour[3]); + bgblu = (16 * ctoi(symbol->bgcolour[4])) + ctoi(symbol->bgcolour[5]); - /* Open output file in binary mode */ - if((symbol->output_options & BARCODE_STDOUT) != 0) { + /* Open output file in binary mode */ + if ((symbol->output_options & BARCODE_STDOUT) != 0) { #ifdef _MSC_VER - if (-1 == _setmode(_fileno(stdout), _O_BINARY)) { - strcpy(symbol->errtxt, "Can't open output file"); - return ZINT_ERROR_FILE_ACCESS; - } + if (-1 == _setmode(_fileno(stdout), _O_BINARY)) { + strcpy(symbol->errtxt, "Can't open output file"); + return ZINT_ERROR_FILE_ACCESS; + } #endif - graphic->outfile = stdout; - } else { - if (!(graphic->outfile = fopen(symbol->outfile, "wb"))) { - strcpy(symbol->errtxt, "Can't open output file"); - return ZINT_ERROR_FILE_ACCESS; - } - } + graphic->outfile = stdout; + } else { + if (!(graphic->outfile = fopen(symbol->outfile, "wb"))) { + strcpy(symbol->errtxt, "Can't open output file"); + return ZINT_ERROR_FILE_ACCESS; + } + } - /* Set up error handling routine as proc() above */ - png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, graphic, writepng_error_handler, NULL); - if (!png_ptr) { - strcpy(symbol->errtxt, "Out of memory"); - return ZINT_ERROR_MEMORY; - } + /* Set up error handling routine as proc() above */ + png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, graphic, writepng_error_handler, NULL); + if (!png_ptr) { + strcpy(symbol->errtxt, "Out of memory"); + return ZINT_ERROR_MEMORY; + } - info_ptr = png_create_info_struct(png_ptr); - if (!info_ptr) { - png_destroy_write_struct(&png_ptr, NULL); - strcpy(symbol->errtxt, "Out of memory"); - return ZINT_ERROR_MEMORY; - } + info_ptr = png_create_info_struct(png_ptr); + if (!info_ptr) { + png_destroy_write_struct(&png_ptr, NULL); + strcpy(symbol->errtxt, "Out of memory"); + return ZINT_ERROR_MEMORY; + } - /* catch jumping here */ - if (setjmp(graphic->jmpbuf)) { - png_destroy_write_struct(&png_ptr, &info_ptr); - strcpy(symbol->errtxt, "libpng error occurred"); - return ZINT_ERROR_MEMORY; - } + /* catch jumping here */ + if (setjmp(graphic->jmpbuf)) { + png_destroy_write_struct(&png_ptr, &info_ptr); + strcpy(symbol->errtxt, "libpng error occurred"); + return ZINT_ERROR_MEMORY; + } - /* open output file with libpng */ - png_init_io(png_ptr, graphic->outfile); + /* open output file with libpng */ + png_init_io(png_ptr, graphic->outfile); - /* set compression */ - png_set_compression_level(png_ptr,9); + /* set compression */ + png_set_compression_level(png_ptr, 9); - /* set Header block */ - png_set_IHDR(png_ptr, info_ptr, graphic->width, graphic->height, - 8, PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE, - PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); + /* set Header block */ + png_set_IHDR(png_ptr, info_ptr, graphic->width, graphic->height, + 8, PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE, + PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); - /* write all chunks up to (but not including) first IDAT */ - png_write_info(png_ptr, info_ptr); + /* write all chunks up to (but not including) first IDAT */ + png_write_info(png_ptr, info_ptr); - /* set up the transformations: for now, just pack low-bit-depth pixels - into bytes (one, two or four pixels per byte) */ - png_set_packing(png_ptr); + /* set up the transformations: for now, just pack low-bit-depth pixels + into bytes (one, two or four pixels per byte) */ + png_set_packing(png_ptr); - /* Pixel Plotting */ + /* Pixel Plotting */ - switch(rotate_angle) { - case 0: /* Plot the right way up */ - for(row = 0; row < image_height; row++) { - for(column = 0; column < image_width; column++) { - i = column * 3; - switch(*(pixelbuf + (image_width * row) + column)) - { - case '1': - outdata[i] = fgred; - outdata[i + 1] = fggrn; - outdata[i + 2] = fgblu; - break; - default: - outdata[i] = bgred; - outdata[i + 1] = bggrn; - outdata[i + 2] = bgblu; - break; + switch (rotate_angle) { + case 0: /* Plot the right way up */ + for (row = 0; row < image_height; row++) { + for (column = 0; column < image_width; column++) { + i = column * 3; + switch (*(pixelbuf + (image_width * row) + column)) { + case '1': + outdata[i] = fgred; + outdata[i + 1] = fggrn; + outdata[i + 2] = fgblu; + break; + default: + outdata[i] = bgred; + outdata[i + 1] = bggrn; + outdata[i + 2] = bgblu; + break; - } - } - /* write row contents to file */ - image_data = outdata; - png_write_row(png_ptr, image_data); - } - break; - case 90: /* Plot 90 degrees clockwise */ - for(row = 0; row < image_width; row++) { - for(column = 0; column < image_height; column++) { - i = column * 3; - switch(*(pixelbuf + (image_width * (image_height - column - 1)) + row)) - { - case '1': - outdata[i] = fgred; - outdata[i + 1] = fggrn; - outdata[i + 2] = fgblu; - break; - default: - outdata[i] = bgred; - outdata[i + 1] = bggrn; - outdata[i + 2] = bgblu; - break; + } + } + /* write row contents to file */ + image_data = outdata; + png_write_row(png_ptr, image_data); + } + break; + case 90: /* Plot 90 degrees clockwise */ + for (row = 0; row < image_width; row++) { + for (column = 0; column < image_height; column++) { + i = column * 3; + switch (*(pixelbuf + (image_width * (image_height - column - 1)) + row)) { + case '1': + outdata[i] = fgred; + outdata[i + 1] = fggrn; + outdata[i + 2] = fgblu; + break; + default: + outdata[i] = bgred; + outdata[i + 1] = bggrn; + outdata[i + 2] = bgblu; + break; - } - } + } + } - /* write row contents to file */ - image_data = outdata; - png_write_row(png_ptr, image_data); - } - break; - case 180: /* Plot upside down */ - for(row = 0; row < image_height; row++) { - for(column = 0; column < image_width; column++) { - i = column * 3; - switch(*(pixelbuf + (image_width * (image_height - row - 1)) + (image_width - column - 1))) - { - case '1': - outdata[i] = fgred; - outdata[i + 1] = fggrn; - outdata[i + 2] = fgblu; - break; - default: - outdata[i] = bgred; - outdata[i + 1] = bggrn; - outdata[i + 2] = bgblu; - break; + /* write row contents to file */ + image_data = outdata; + png_write_row(png_ptr, image_data); + } + break; + case 180: /* Plot upside down */ + for (row = 0; row < image_height; row++) { + for (column = 0; column < image_width; column++) { + i = column * 3; + switch (*(pixelbuf + (image_width * (image_height - row - 1)) + (image_width - column - 1))) { + case '1': + outdata[i] = fgred; + outdata[i + 1] = fggrn; + outdata[i + 2] = fgblu; + break; + default: + outdata[i] = bgred; + outdata[i + 1] = bggrn; + outdata[i + 2] = bgblu; + break; - } - } + } + } - /* write row contents to file */ - image_data = outdata; - png_write_row(png_ptr, image_data); - } - break; - case 270: /* Plot 90 degrees anti-clockwise */ - for(row = 0; row < image_width; row++) { - for(column = 0; column < image_height; column++) { - i = column * 3; - switch(*(pixelbuf + (image_width * column) + (image_width - row - 1))) - { - case '1': - outdata[i] = fgred; - outdata[i + 1] = fggrn; - outdata[i + 2] = fgblu; - break; - default: - outdata[i] = bgred; - outdata[i + 1] = bggrn; - outdata[i + 2] = bgblu; - break; + /* write row contents to file */ + image_data = outdata; + png_write_row(png_ptr, image_data); + } + break; + case 270: /* Plot 90 degrees anti-clockwise */ + for (row = 0; row < image_width; row++) { + for (column = 0; column < image_height; column++) { + i = column * 3; + switch (*(pixelbuf + (image_width * column) + (image_width - row - 1))) { + case '1': + outdata[i] = fgred; + outdata[i + 1] = fggrn; + outdata[i + 2] = fgblu; + break; + default: + outdata[i] = bgred; + outdata[i + 1] = bggrn; + outdata[i + 2] = bgblu; + break; - } - } + } + } - /* write row contents to file */ - image_data = outdata; - png_write_row(png_ptr, image_data); - } - break; - } + /* write row contents to file */ + image_data = outdata; + png_write_row(png_ptr, image_data); + } + break; + } - /* End the file */ - png_write_end(png_ptr, NULL); + /* End the file */ + png_write_end(png_ptr, NULL); - /* make sure we have disengaged */ - if (png_ptr && info_ptr) png_destroy_write_struct(&png_ptr, &info_ptr); - if(symbol->output_options & BARCODE_STDOUT) { - fflush(wpng_info.outfile); - } else { - fclose(wpng_info.outfile); - } - return 0; + /* make sure we have disengaged */ + if (png_ptr && info_ptr) png_destroy_write_struct(&png_ptr, &info_ptr); + if (symbol->output_options & BARCODE_STDOUT) { + fflush(wpng_info.outfile); + } else { + fclose(wpng_info.outfile); + } + return 0; } #endif /* NO_PNG */ -int bmp_pixel_plot(struct zint_symbol *symbol, int image_height, int image_width, char *pixelbuf, int rotate_angle) -{ - int i, row, column, errno; - int fgred, fggrn, fgblu, bgred, bggrn, bgblu; +int bmp_pixel_plot(struct zint_symbol *symbol, int image_height, int image_width, char *pixelbuf, int rotate_angle) { + int i, row, column, errno; + int fgred, fggrn, fgblu, bgred, bggrn, bgblu; - switch(rotate_angle) { - case 0: - case 180: - symbol->bitmap_width = image_width; - symbol->bitmap_height = image_height; - break; - case 90: - case 270: - symbol->bitmap_width = image_height; - symbol->bitmap_height = image_width; - break; - } + switch (rotate_angle) { + case 0: + case 180: + symbol->bitmap_width = image_width; + symbol->bitmap_height = image_height; + break; + case 90: + case 270: + symbol->bitmap_width = image_height; + symbol->bitmap_height = image_width; + break; + } - if (symbol->bitmap != NULL) - free(symbol->bitmap); + if (symbol->bitmap != NULL) + free(symbol->bitmap); symbol->bitmap = (char *) malloc(image_width * image_height * 3); - /* sort out colour options */ - to_upper((unsigned char*)symbol->fgcolour); - to_upper((unsigned char*)symbol->bgcolour); + /* sort out colour options */ + to_upper((unsigned char*) symbol->fgcolour); + to_upper((unsigned char*) symbol->bgcolour); - if(strlen(symbol->fgcolour) != 6) { - strcpy(symbol->errtxt, "Malformed foreground colour target"); - return ZINT_ERROR_INVALID_OPTION; - } - if(strlen(symbol->bgcolour) != 6) { - strcpy(symbol->errtxt, "Malformed background colour target"); - return ZINT_ERROR_INVALID_OPTION; - } - errno = is_sane(SSET, (unsigned char*)symbol->fgcolour, strlen(symbol->fgcolour)); - if (errno == ZINT_ERROR_INVALID_DATA) { - strcpy(symbol->errtxt, "Malformed foreground colour target"); - return ZINT_ERROR_INVALID_OPTION; - } - errno = is_sane(SSET, (unsigned char*)symbol->bgcolour, strlen(symbol->fgcolour)); - if (errno == ZINT_ERROR_INVALID_DATA) { - strcpy(symbol->errtxt, "Malformed background colour target"); - return ZINT_ERROR_INVALID_OPTION; - } + if (strlen(symbol->fgcolour) != 6) { + strcpy(symbol->errtxt, "Malformed foreground colour target"); + return ZINT_ERROR_INVALID_OPTION; + } + if (strlen(symbol->bgcolour) != 6) { + strcpy(symbol->errtxt, "Malformed background colour target"); + return ZINT_ERROR_INVALID_OPTION; + } + errno = is_sane(SSET, (unsigned char*) symbol->fgcolour, strlen(symbol->fgcolour)); + if (errno == ZINT_ERROR_INVALID_DATA) { + strcpy(symbol->errtxt, "Malformed foreground colour target"); + return ZINT_ERROR_INVALID_OPTION; + } + errno = is_sane(SSET, (unsigned char*) symbol->bgcolour, strlen(symbol->fgcolour)); + if (errno == ZINT_ERROR_INVALID_DATA) { + strcpy(symbol->errtxt, "Malformed background colour target"); + return ZINT_ERROR_INVALID_OPTION; + } - fgred = (16 * ctoi(symbol->fgcolour[0])) + ctoi(symbol->fgcolour[1]); - fggrn = (16 * ctoi(symbol->fgcolour[2])) + ctoi(symbol->fgcolour[3]); - fgblu = (16 * ctoi(symbol->fgcolour[4])) + ctoi(symbol->fgcolour[5]); - bgred = (16 * ctoi(symbol->bgcolour[0])) + ctoi(symbol->bgcolour[1]); - bggrn = (16 * ctoi(symbol->bgcolour[2])) + ctoi(symbol->bgcolour[3]); - bgblu = (16 * ctoi(symbol->bgcolour[4])) + ctoi(symbol->bgcolour[5]); + fgred = (16 * ctoi(symbol->fgcolour[0])) + ctoi(symbol->fgcolour[1]); + fggrn = (16 * ctoi(symbol->fgcolour[2])) + ctoi(symbol->fgcolour[3]); + fgblu = (16 * ctoi(symbol->fgcolour[4])) + ctoi(symbol->fgcolour[5]); + bgred = (16 * ctoi(symbol->bgcolour[0])) + ctoi(symbol->bgcolour[1]); + bggrn = (16 * ctoi(symbol->bgcolour[2])) + ctoi(symbol->bgcolour[3]); + bgblu = (16 * ctoi(symbol->bgcolour[4])) + ctoi(symbol->bgcolour[5]); - /* Pixel Plotting */ - i = 0; - switch(rotate_angle) { - case 0: /* Plot the right way up */ - for(row = 0; row < image_height; row++) { - for(column = 0; column < image_width; column++) { - switch(*(pixelbuf + (image_width * row) + column)) - { - case '1': - symbol->bitmap[i++] = fgred; - symbol->bitmap[i++] = fggrn; - symbol->bitmap[i++] = fgblu; - break; - default: - symbol->bitmap[i++] = bgred; - symbol->bitmap[i++] = bggrn; - symbol->bitmap[i++] = bgblu; - break; + /* Pixel Plotting */ + i = 0; + switch (rotate_angle) { + case 0: /* Plot the right way up */ + for (row = 0; row < image_height; row++) { + for (column = 0; column < image_width; column++) { + switch (*(pixelbuf + (image_width * row) + column)) { + case '1': + symbol->bitmap[i++] = fgred; + symbol->bitmap[i++] = fggrn; + symbol->bitmap[i++] = fgblu; + break; + default: + symbol->bitmap[i++] = bgred; + symbol->bitmap[i++] = bggrn; + symbol->bitmap[i++] = bgblu; + break; - } - } - } - break; - case 90: /* Plot 90 degrees clockwise */ - for(row = 0; row < image_width; row++) { - for(column = 0; column < image_height; column++) { - switch(*(pixelbuf + (image_width * (image_height - column - 1)) + row)) - { - case '1': - symbol->bitmap[i++] = fgred; - symbol->bitmap[i++] = fggrn; - symbol->bitmap[i++] = fgblu; - break; - default: - symbol->bitmap[i++] = bgred; - symbol->bitmap[i++] = bggrn; - symbol->bitmap[i++] = bgblu; - break; + } + } + } + break; + case 90: /* Plot 90 degrees clockwise */ + for (row = 0; row < image_width; row++) { + for (column = 0; column < image_height; column++) { + switch (*(pixelbuf + (image_width * (image_height - column - 1)) + row)) { + case '1': + symbol->bitmap[i++] = fgred; + symbol->bitmap[i++] = fggrn; + symbol->bitmap[i++] = fgblu; + break; + default: + symbol->bitmap[i++] = bgred; + symbol->bitmap[i++] = bggrn; + symbol->bitmap[i++] = bgblu; + break; - } - } - } - break; - case 180: /* Plot upside down */ - for(row = 0; row < image_height; row++) { - for(column = 0; column < image_width; column++) { - switch(*(pixelbuf + (image_width * (image_height - row - 1)) + (image_width - column - 1))) - { - case '1': - symbol->bitmap[i++] = fgred; - symbol->bitmap[i++] = fggrn; - symbol->bitmap[i++] = fgblu; - break; - default: - symbol->bitmap[i++] = bgred; - symbol->bitmap[i++] = bggrn; - symbol->bitmap[i++] = bgblu; - break; + } + } + } + break; + case 180: /* Plot upside down */ + for (row = 0; row < image_height; row++) { + for (column = 0; column < image_width; column++) { + switch (*(pixelbuf + (image_width * (image_height - row - 1)) + (image_width - column - 1))) { + case '1': + symbol->bitmap[i++] = fgred; + symbol->bitmap[i++] = fggrn; + symbol->bitmap[i++] = fgblu; + break; + default: + symbol->bitmap[i++] = bgred; + symbol->bitmap[i++] = bggrn; + symbol->bitmap[i++] = bgblu; + break; - } - } - } - break; - case 270: /* Plot 90 degrees anti-clockwise */ - for(row = 0; row < image_width; row++) { - for(column = 0; column < image_height; column++) { - switch(*(pixelbuf + (image_width * column) + (image_width - row - 1))) - { - case '1': - symbol->bitmap[i++] = fgred; - symbol->bitmap[i++] = fggrn; - symbol->bitmap[i++] = fgblu; - break; - default: - symbol->bitmap[i++] = bgred; - symbol->bitmap[i++] = bggrn; - symbol->bitmap[i++] = bgblu; - break; + } + } + } + break; + case 270: /* Plot 90 degrees anti-clockwise */ + for (row = 0; row < image_width; row++) { + for (column = 0; column < image_height; column++) { + switch (*(pixelbuf + (image_width * column) + (image_width - row - 1))) { + case '1': + symbol->bitmap[i++] = fgred; + symbol->bitmap[i++] = fggrn; + symbol->bitmap[i++] = fgblu; + break; + default: + symbol->bitmap[i++] = bgred; + symbol->bitmap[i++] = bggrn; + symbol->bitmap[i++] = bgblu; + break; - } - } - } - break; - } + } + } + } + break; + } - return 0; + return 0; } -int png_to_file(struct zint_symbol *symbol, int image_height, int image_width, char *pixelbuf, int rotate_angle, int image_type) -{ - int error_number; - float scaler = symbol->scale; - char *scaled_pixelbuf; - int horiz, vert, i; - int scale_width, scale_height; +int png_to_file(struct zint_symbol *symbol, int image_height, int image_width, char *pixelbuf, int rotate_angle, int image_type) { + int error_number; + float scaler = symbol->scale; + char *scaled_pixelbuf; + int horiz, vert, i; + int scale_width, scale_height; - if(scaler == 0) { scaler = 0.5; } - scale_width = image_width * scaler; - scale_height = image_height * scaler; + if (scaler == 0) { + scaler = 0.5; + } + scale_width = image_width * scaler; + scale_height = image_height * scaler; - /* Apply scale options by creating another pixel buffer */ - if (!(scaled_pixelbuf = (char *) malloc(scale_width * scale_height))) { - printf("Insufficient memory for pixel buffer"); - return ZINT_ERROR_ENCODING_PROBLEM; - } else { - for(i = 0; i < (scale_width * scale_height); i++) { - *(scaled_pixelbuf + i) = '0'; - } - } + /* Apply scale options by creating another pixel buffer */ + if (!(scaled_pixelbuf = (char *) malloc(scale_width * scale_height))) { + printf("Insufficient memory for pixel buffer"); + return ZINT_ERROR_ENCODING_PROBLEM; + } else { + for (i = 0; i < (scale_width * scale_height); i++) { + *(scaled_pixelbuf + i) = '0'; + } + } - for(vert = 0; vert < scale_height; vert++) { - for(horiz = 0; horiz < scale_width; horiz++) { - *(scaled_pixelbuf + (vert * scale_width) + horiz) = *(pixelbuf + ((int)(vert / scaler) * image_width) + (int)(horiz / scaler)); - } - } + for (vert = 0; vert < scale_height; vert++) { + for (horiz = 0; horiz < scale_width; horiz++) { + *(scaled_pixelbuf + (vert * scale_width) + horiz) = *(pixelbuf + ((int) (vert / scaler) * image_width) + (int) (horiz / scaler)); + } + } - if(image_type == PNG_DATA) { + if (image_type == PNG_DATA) { #ifndef NO_PNG - error_number = png_pixel_plot(symbol, scale_height, scale_width, scaled_pixelbuf, rotate_angle); + error_number = png_pixel_plot(symbol, scale_height, scale_width, scaled_pixelbuf, rotate_angle); #else - return ZINT_ERROR_INVALID_OPTION; + return ZINT_ERROR_INVALID_OPTION; #endif - } else { - error_number = bmp_pixel_plot(symbol, scale_height, scale_width, scaled_pixelbuf, rotate_angle); - } + } else { + error_number = bmp_pixel_plot(symbol, scale_height, scale_width, scaled_pixelbuf, rotate_angle); + } - free(scaled_pixelbuf); + free(scaled_pixelbuf); - return error_number; + return error_number; } -void draw_bar(char *pixelbuf, int xpos, int xlen, int ypos, int ylen, int image_width, int image_height) -{ - /* Draw a rectangle */ - int i, j, png_ypos; +void draw_bar(char *pixelbuf, int xpos, int xlen, int ypos, int ylen, int image_width, int image_height) { + /* Draw a rectangle */ + int i, j, png_ypos; - png_ypos = image_height - ypos - ylen; - /* This fudge is needed because EPS measures height from the bottom up but - PNG measures y position from the top down */ + png_ypos = image_height - ypos - ylen; + /* This fudge is needed because EPS measures height from the bottom up but + PNG measures y position from the top down */ - for(i = (xpos); i < (xpos + xlen); i++) { - for( j = (png_ypos); j < (png_ypos + ylen); j++) { - *(pixelbuf + (image_width * j) + i) = '1'; - } - } + for (i = (xpos); i < (xpos + xlen); i++) { + for (j = (png_ypos); j < (png_ypos + ylen); j++) { + *(pixelbuf + (image_width * j) + i) = '1'; + } + } } int bullseye_pixel(int row, int col) { - int block_val, block_pos, return_val; + int block_val, block_pos, return_val; - block_val = bullseye_compressed[(row * 12) + (col / 8)]; - return_val = 0; - block_pos = col % 8; + block_val = bullseye_compressed[(row * 12) + (col / 8)]; + return_val = 0; + block_pos = col % 8; - switch(block_pos) { - case 0: if((block_val & 0x80) != 0) { return_val = 1; } break; - case 1: if((block_val & 0x40) != 0) { return_val = 1; } break; - case 2: if((block_val & 0x20) != 0) { return_val = 1; } break; - case 3: if((block_val & 0x10) != 0) { return_val = 1; } break; - case 4: if((block_val & 0x08) != 0) { return_val = 1; } break; - case 5: if((block_val & 0x04) != 0) { return_val = 1; } break; - case 6: if((block_val & 0x02) != 0) { return_val = 1; } break; - case 7: if((block_val & 0x01) != 0) { return_val = 1; } break; - } + if (block_val & (0x80 >> block_pos)) { + return_val = 1; + } - return return_val; + return return_val; } -void draw_bullseye(char *pixelbuf, int image_width, int xoffset, int yoffset) -{ - /* Central bullseye in Maxicode symbols */ - int i, j; +void draw_bullseye(char *pixelbuf, int image_width, int xoffset, int yoffset) { + /* Central bullseye in Maxicode symbols */ + int i, j; - for(j = 103; j < 196; j++) { - for(i = 0; i < 93; i++) { - if(bullseye_pixel(j - 103, i)) { - /* if(bullseye[(((j - 103) * 93) + i)] == 1) { */ - *(pixelbuf + (image_width * j) + (image_width * yoffset) + i + 99 + xoffset) = '1'; - } - } - } + for (j = 103; j < 196; j++) { + for (i = 0; i < 93; i++) { + if (bullseye_pixel(j - 103, i)) { + /* if(bullseye[(((j - 103) * 93) + i)] == 1) { */ + *(pixelbuf + (image_width * j) + (image_width * yoffset) + i + 99 + xoffset) = '1'; + } + } + } } -void draw_hexagon(char *pixelbuf, int image_width, int xposn, int yposn) -{ - /* Put a hexagon into the pixel buffer */ - int i, j; +void draw_hexagon(char *pixelbuf, int image_width, int xposn, int yposn) { + /* Put a hexagon into the pixel buffer */ + int i, j; - for(i = 0; i < 12; i++) { - for(j = 0; j < 10; j++) { - if(hexagon[(i * 10) + j] == 1) { - *(pixelbuf + (image_width * i) + (image_width * yposn) + xposn + j) = '1'; - } - } - } + for (i = 0; i < 12; i++) { + for (j = 0; j < 10; j++) { + if (hexagon[(i * 10) + j] == 1) { + *(pixelbuf + (image_width * i) + (image_width * yposn) + xposn + j) = '1'; + } + } + } } -void draw_letter(char *pixelbuf, unsigned char letter, int xposn, int yposn, int smalltext, int image_width, int image_height) -{ - /* Put a letter into a position */ - int skip, i, j, glyph_no, alphabet; +void draw_letter(char *pixelbuf, unsigned char letter, int xposn, int yposn, int smalltext, int image_width, int image_height) { + /* Put a letter into a position */ + int skip, i, j, glyph_no, alphabet; - skip = 0; - alphabet = 0; + skip = 0; + alphabet = 0; - if(letter < 33) { skip = 1; } - if((letter > 127) && (letter < 161)) { skip = 1; } + if (letter < 33) { + skip = 1; + } + if ((letter > 127) && (letter < 161)) { + skip = 1; + } - if(skip == 0) { - if(letter > 128) { - alphabet = 1; - glyph_no = letter - 161; - } else { - glyph_no = letter - 33; - } + if (skip == 0) { + if (letter > 128) { + alphabet = 1; + glyph_no = letter - 161; + } else { + glyph_no = letter - 33; + } - if(smalltext) { - for(i = 0; i <= 8; i++) { - for(j = 0; j < 5; j++) { - if(alphabet == 0) { - if(small_font[(glyph_no * 5) + (i * 475) + j - 1] == 1) { - *(pixelbuf + (i * image_width) + (yposn * image_width) + xposn + j) = '1'; - } - } else { - if(small_font_extended[(glyph_no * 5) + (i * 475) + j - 1] == 1) { - *(pixelbuf + (i * image_width) + (yposn * image_width) + xposn + j) = '1'; - } - } - } - } - } else { - for(i = 0; i <= 13; i++) { - for(j = 0; j < 7 ; j++) { - if(alphabet == 0) { - if(ascii_font[(glyph_no * 7) + (i * 665) + j - 1] == 1) { - *(pixelbuf + (i * image_width) + (yposn * image_width) + xposn + j) = '1'; - } - } else { - if(ascii_ext_font[(glyph_no * 7) + (i * 665) + j - 1] == 1) { - *(pixelbuf + (i * image_width) + (yposn * image_width) + xposn + j) = '1'; - } - } - } - } - } - } + if (smalltext) { + for (i = 0; i <= 8; i++) { + for (j = 0; j < 5; j++) { + if (alphabet == 0) { + if (small_font[(glyph_no * 5) + (i * 475) + j - 1] == 1) { + *(pixelbuf + (i * image_width) + (yposn * image_width) + xposn + j) = '1'; + } + } else { + if (small_font_extended[(glyph_no * 5) + (i * 475) + j - 1] == 1) { + *(pixelbuf + (i * image_width) + (yposn * image_width) + xposn + j) = '1'; + } + } + } + } + } else { + for (i = 0; i <= 13; i++) { + for (j = 0; j < 7; j++) { + if (alphabet == 0) { + if (ascii_font[(glyph_no * 7) + (i * 665) + j - 1] == 1) { + *(pixelbuf + (i * image_width) + (yposn * image_width) + xposn + j) = '1'; + } + } else { + if (ascii_ext_font[(glyph_no * 7) + (i * 665) + j - 1] == 1) { + *(pixelbuf + (i * image_width) + (yposn * image_width) + xposn + j) = '1'; + } + } + } + } + } + } } -void draw_string(char *pixbuf, char input_string[], int xposn, int yposn, int smalltext, int image_width, int image_height) -{ - /* Plot a string into the pixel buffer */ - int i, string_length, string_left_hand; +/* Plot a string into the pixel buffer */ +void draw_string(char *pixbuf, char input_string[], int xposn, int yposn, int smalltext, int image_width, int image_height) { + int i, string_length, string_left_hand; - string_length = strlen(input_string); - string_left_hand = xposn - ((7 * string_length) / 2); + string_length = strlen(input_string); + string_left_hand = xposn - ((7 * string_length) / 2); - for(i = 0; i < string_length; i++) { - draw_letter(pixbuf, input_string[i], string_left_hand + (i * 7), yposn, smalltext, image_width, image_height); - } + for (i = 0; i < string_length; i++) { + draw_letter(pixbuf, input_string[i], string_left_hand + (i * 7), yposn, smalltext, image_width, image_height); + } } -int maxi_png_plot(struct zint_symbol *symbol, int rotate_angle, int data_type) -{ - int i, row, column, xposn, yposn; - int image_height, image_width; - char *pixelbuf; - int error_number; - int xoffset, yoffset; +int maxi_png_plot(struct zint_symbol *symbol, int rotate_angle, int data_type) { + int i, row, column, xposn, yposn; + int image_height, image_width; + char *pixelbuf; + int error_number; + int xoffset, yoffset; - xoffset = symbol->border_width + symbol->whitespace_width; - yoffset = symbol->border_width; - image_width = 300 + (2 * xoffset * 2); - image_height = 300 + (2 * yoffset * 2); + xoffset = symbol->border_width + symbol->whitespace_width; + yoffset = symbol->border_width; + image_width = 300 + (2 * xoffset * 2); + image_height = 300 + (2 * yoffset * 2); - if (!(pixelbuf = (char *) malloc(image_width * image_height))) { - printf("Insifficient memory for pixel buffer"); - return ZINT_ERROR_ENCODING_PROBLEM; - } else { - for(i = 0; i < (image_width * image_height); i++) { - *(pixelbuf + i) = '0'; - } - } + if (!(pixelbuf = (char *) malloc(image_width * image_height))) { + printf("Insifficient memory for pixel buffer"); + return ZINT_ERROR_ENCODING_PROBLEM; + } else { + for (i = 0; i < (image_width * image_height); i++) { + *(pixelbuf + i) = '0'; + } + } - draw_bullseye(pixelbuf, image_width, (2 * xoffset), (2 * yoffset)); + draw_bullseye(pixelbuf, image_width, (2 * xoffset), (2 * yoffset)); - for(row = 0; row < symbol->rows; row++) { - yposn = row * 9; - for(column = 0; column < symbol->width; column++) { - xposn = column * 10; - if(module_is_set(symbol, row, column)) { - if(row & 1) { - /* Odd (reduced) row */ - xposn += 5; - draw_hexagon(pixelbuf, image_width, xposn + (2 * xoffset), yposn + (2 * yoffset)); - } else { - /* Even (full) row */ - draw_hexagon(pixelbuf, image_width, xposn + (2 * xoffset), yposn + (2 * yoffset)); - } - } - } - } + for (row = 0; row < symbol->rows; row++) { + yposn = row * 9; + for (column = 0; column < symbol->width; column++) { + xposn = column * 10; + if (module_is_set(symbol, row, column)) { + if (row & 1) { + /* Odd (reduced) row */ + xposn += 5; + draw_hexagon(pixelbuf, image_width, xposn + (2 * xoffset), yposn + (2 * yoffset)); + } else { + /* Even (full) row */ + draw_hexagon(pixelbuf, image_width, xposn + (2 * xoffset), yposn + (2 * yoffset)); + } + } + } + } - if(((symbol->output_options & BARCODE_BOX) != 0) || ((symbol->output_options & BARCODE_BIND) != 0)) { - /* boundary bars */ - draw_bar(pixelbuf, 0, image_width, 0, symbol->border_width * 2, image_width, image_height); - draw_bar(pixelbuf, 0, image_width, 300 + (symbol->border_width * 2), symbol->border_width * 2, image_width, image_height); - } + if (((symbol->output_options & BARCODE_BOX) != 0) || ((symbol->output_options & BARCODE_BIND) != 0)) { + /* boundary bars */ + draw_bar(pixelbuf, 0, image_width, 0, symbol->border_width * 2, image_width, image_height); + draw_bar(pixelbuf, 0, image_width, 300 + (symbol->border_width * 2), symbol->border_width * 2, image_width, image_height); + } - if((symbol->output_options & BARCODE_BOX) != 0) { - /* side bars */ - draw_bar(pixelbuf, 0, symbol->border_width * 2, 0, image_height, image_width, image_height); - draw_bar(pixelbuf, 300 + ((symbol->border_width + symbol->whitespace_width + symbol->whitespace_width) * 2), symbol->border_width * 2, 0, image_height, image_width, image_height); - } + if ((symbol->output_options & BARCODE_BOX) != 0) { + /* side bars */ + draw_bar(pixelbuf, 0, symbol->border_width * 2, 0, image_height, image_width, image_height); + draw_bar(pixelbuf, 300 + ((symbol->border_width + symbol->whitespace_width + symbol->whitespace_width) * 2), symbol->border_width * 2, 0, image_height, image_width, image_height); + } - error_number=png_to_file(symbol, image_height, image_width, pixelbuf, rotate_angle, data_type); - free(pixelbuf); - return error_number; + error_number = png_to_file(symbol, image_height, image_width, pixelbuf, rotate_angle, data_type); + free(pixelbuf); + return error_number; } /* Convert UTF-8 to Latin1 Codepage for the interpretation line */ -void to_latin1(unsigned char source[], unsigned char preprocessed[]) -{ - int j, i, input_length; +void to_latin1(unsigned char source[], unsigned char preprocessed[]) { + int j, i, input_length; - input_length = ustrlen(source); + input_length = ustrlen(source); - j = 0; - i = 0; - while (i < input_length) { - switch (source[i]) { - case 0xC2: - /* UTF-8 C2xxh */ - /* Character range: C280h (latin: 80h) to C2BFh (latin: BFh) */ - i++; - preprocessed[j] = source[i]; - j++; - break; - case 0xC3: - /* UTF-8 C3xx */ - /* Character range: C380h (latin: C0h) to C3BFh (latin: FFh) */ - i++; - preprocessed[j] = source[i] + 64; - j++; - break; - default: - /* Process ASCII (< 80h), all other unicode points are ignored */ - if(source[i] < 128) { - preprocessed[j] = source[i]; - j++; - } - break; - } - i++; - } - preprocessed[j] = '\0'; + j = 0; + i = 0; + while (i < input_length) { + switch (source[i]) { + case 0xC2: + /* UTF-8 C2xxh */ + /* Character range: C280h (latin: 80h) to C2BFh (latin: BFh) */ + i++; + preprocessed[j] = source[i]; + j++; + break; + case 0xC3: + /* UTF-8 C3xx */ + /* Character range: C380h (latin: C0h) to C3BFh (latin: FFh) */ + i++; + preprocessed[j] = source[i] + 64; + j++; + break; + default: + /* Process ASCII (< 80h), all other unicode points are ignored */ + if (source[i] < 128) { + preprocessed[j] = source[i]; + j++; + } + break; + } + i++; + } + preprocessed[j] = '\0'; - return; + return; } -int png_plot(struct zint_symbol *symbol, int rotate_angle, int data_type) -{ - int textdone, main_width, comp_offset, large_bar_count; - char textpart[10], addon[6]; - float addon_text_posn, preset_height, large_bar_height; - int i, r, textoffset, yoffset, xoffset, latch, image_width, image_height; - char *pixelbuf; - int addon_latch = 0, smalltext = 0; - int this_row, block_width, plot_height, plot_yposn, textpos; - float row_height, row_posn; - int error_number; - int default_text_posn; - int next_yposn; +int png_plot(struct zint_symbol *symbol, int rotate_angle, int data_type) { + int textdone, main_width, comp_offset, large_bar_count; + char textpart[10], addon[6]; + float addon_text_posn, preset_height, large_bar_height; + int i, r, textoffset, yoffset, xoffset, latch, image_width, image_height; + char *pixelbuf; + int addon_latch = 0, smalltext = 0; + int this_row, block_width, plot_height, plot_yposn, textpos; + float row_height, row_posn; + int error_number; + int default_text_posn; + int next_yposn; #ifndef _MSC_VER - unsigned char local_text[ustrlen(symbol->text) + 1]; + unsigned char local_text[ustrlen(symbol->text) + 1]; #else - unsigned char* local_text = (unsigned char*)_alloca(ustrlen(symbol->text) + 1); + unsigned char* local_text = (unsigned char*) _alloca(ustrlen(symbol->text) + 1); #endif - if(symbol->show_hrt != 0) { - to_latin1(symbol->text, local_text); - } else { - local_text[0] = '\0'; - } + if (symbol->show_hrt != 0) { + to_latin1(symbol->text, local_text); + } else { + local_text[0] = '\0'; + } - textdone = 0; - main_width = symbol->width; - strcpy(addon, ""); - comp_offset = 0; - addon_text_posn = 0.0; - row_height = 0; - if(symbol->output_options & SMALL_TEXT) { - smalltext = 1; - } + textdone = 0; + main_width = symbol->width; + strcpy(addon, ""); + comp_offset = 0; + addon_text_posn = 0.0; + row_height = 0; + if (symbol->output_options & SMALL_TEXT) { + smalltext = 1; + } - if (symbol->height == 0) { - symbol->height = 50; - } + if (symbol->height == 0) { + symbol->height = 50; + } - large_bar_count = 0; - preset_height = 0.0; - for(i = 0; i < symbol->rows; i++) { - preset_height += symbol->row_height[i]; - if(symbol->row_height[i] == 0) { - large_bar_count++; - } - } + large_bar_count = 0; + preset_height = 0.0; + for (i = 0; i < symbol->rows; i++) { + preset_height += symbol->row_height[i]; + if (symbol->row_height[i] == 0) { + large_bar_count++; + } + } - if (large_bar_count == 0) { - symbol->height = preset_height; - large_bar_height = 10; - } else { - large_bar_height = (symbol->height - preset_height) / large_bar_count; - } + if (large_bar_count == 0) { + symbol->height = preset_height; + large_bar_height = 10; + } else { + large_bar_height = (symbol->height - preset_height) / large_bar_count; + } - while(!(module_is_set(symbol, symbol->rows - 1, comp_offset))) { - comp_offset++; - } + while (!(module_is_set(symbol, symbol->rows - 1, comp_offset))) { + comp_offset++; + } - /* Certain symbols need whitespace otherwise characters get chopped off the sides */ - if ((((symbol->symbology == BARCODE_EANX) && (symbol->rows == 1)) || (symbol->symbology == BARCODE_EANX_CC)) - || (symbol->symbology == BARCODE_ISBNX)) { - switch(ustrlen(local_text)) { - case 13: /* EAN 13 */ - case 16: - case 19: - if(symbol->whitespace_width == 0) { - symbol->whitespace_width = 10; - } - main_width = 96 + comp_offset; - break; - default: - main_width = 68 + comp_offset; - } - } + /* Certain symbols need whitespace otherwise characters get chopped off the sides */ + if ((((symbol->symbology == BARCODE_EANX) && (symbol->rows == 1)) || (symbol->symbology == BARCODE_EANX_CC)) + || (symbol->symbology == BARCODE_ISBNX)) { + switch (ustrlen(local_text)) { + case 13: /* EAN 13 */ + case 16: + case 19: + if (symbol->whitespace_width == 0) { + symbol->whitespace_width = 10; + } + main_width = 96 + comp_offset; + break; + default: + main_width = 68 + comp_offset; + } + } - if (((symbol->symbology == BARCODE_UPCA) && (symbol->rows == 1)) || (symbol->symbology == BARCODE_UPCA_CC)) { - if(symbol->whitespace_width == 0) { - symbol->whitespace_width = 10; - main_width = 96 + comp_offset; - } - } + if (((symbol->symbology == BARCODE_UPCA) && (symbol->rows == 1)) || (symbol->symbology == BARCODE_UPCA_CC)) { + if (symbol->whitespace_width == 0) { + symbol->whitespace_width = 10; + main_width = 96 + comp_offset; + } + } - if (((symbol->symbology == BARCODE_UPCE) && (symbol->rows == 1)) || (symbol->symbology == BARCODE_UPCE_CC)) { - if(symbol->whitespace_width == 0) { - symbol->whitespace_width = 10; - main_width = 51 + comp_offset; - } - } + if (((symbol->symbology == BARCODE_UPCE) && (symbol->rows == 1)) || (symbol->symbology == BARCODE_UPCE_CC)) { + if (symbol->whitespace_width == 0) { + symbol->whitespace_width = 10; + main_width = 51 + comp_offset; + } + } - latch = 0; - r = 0; - /* Isolate add-on text */ - if(is_extendable(symbol->symbology)) { - for(i = 0; i < ustrlen(local_text); i++) { - if (latch == 1) { - addon[r] = local_text[i]; - r++; - } - if (symbol->text[i] == '+') { - latch = 1; - } - } - } - addon[r] = '\0'; + latch = 0; + r = 0; + /* Isolate add-on text */ + if (is_extendable(symbol->symbology)) { + for (i = 0; i < ustrlen(local_text); i++) { + if (latch == 1) { + addon[r] = local_text[i]; + r++; + } + if (symbol->text[i] == '+') { + latch = 1; + } + } + } + addon[r] = '\0'; - if(ustrlen(local_text) != 0) { - textoffset = 9; - } else { - textoffset = 0; - } - xoffset = symbol->border_width + symbol->whitespace_width; - yoffset = symbol->border_width; - image_width = 2 * (symbol->width + xoffset + xoffset); - image_height = 2 * (symbol->height + textoffset + yoffset + yoffset); + if (ustrlen(local_text) != 0) { + textoffset = 9; + } else { + textoffset = 0; + } + xoffset = symbol->border_width + symbol->whitespace_width; + yoffset = symbol->border_width; + image_width = 2 * (symbol->width + xoffset + xoffset); + image_height = 2 * (symbol->height + textoffset + yoffset + yoffset); - if (!(pixelbuf = (char *) malloc(image_width * image_height))) { - printf("Insufficient memory for pixel buffer"); - return ZINT_ERROR_ENCODING_PROBLEM; - } else { - for(i = 0; i < (image_width * image_height); i++) { - *(pixelbuf + i) = '0'; - } - } + if (!(pixelbuf = (char *) malloc(image_width * image_height))) { + printf("Insufficient memory for pixel buffer"); + return ZINT_ERROR_ENCODING_PROBLEM; + } else { + for (i = 0; i < (image_width * image_height); i++) { + *(pixelbuf + i) = '0'; + } + } - if(((symbol->output_options & BARCODE_BOX) != 0) || ((symbol->output_options & BARCODE_BIND) != 0)) { - default_text_posn = image_height - 17; - } else { - default_text_posn = image_height - 17 - symbol->border_width - symbol->border_width; - } + if (((symbol->output_options & BARCODE_BOX) != 0) || ((symbol->output_options & BARCODE_BIND) != 0)) { + default_text_posn = image_height - 17; + } else { + default_text_posn = image_height - 17 - symbol->border_width - symbol->border_width; + } - row_posn = textoffset + yoffset; - next_yposn = textoffset + yoffset; - row_height = 0; + row_posn = textoffset + yoffset; + next_yposn = textoffset + yoffset; + row_height = 0; - /* Plot the body of the symbol to the pixel buffer */ - for(r = 0; r < symbol->rows; r++) { - this_row = symbol->rows - r - 1; /* invert r otherwise plots upside down */ - row_posn += row_height; - plot_yposn = next_yposn; - if(symbol->row_height[this_row] == 0) { - row_height = large_bar_height; - } else { - row_height = symbol->row_height[this_row]; - } - next_yposn = (int)(row_posn + row_height); - plot_height = next_yposn - plot_yposn; + /* Plot the body of the symbol to the pixel buffer */ + for (r = 0; r < symbol->rows; r++) { + this_row = symbol->rows - r - 1; /* invert r otherwise plots upside down */ + row_posn += row_height; + plot_yposn = next_yposn; + if (symbol->row_height[this_row] == 0) { + row_height = large_bar_height; + } else { + row_height = symbol->row_height[this_row]; + } + next_yposn = (int) (row_posn + row_height); + plot_height = next_yposn - plot_yposn; - i = 0; - if(module_is_set(symbol, this_row, 0)) { - latch = 1; - } else { - latch = 0; - } + i = 0; + if (module_is_set(symbol, this_row, 0)) { + latch = 1; + } else { + latch = 0; + } - do { - block_width = 0; - do { - block_width++; - } while (module_is_set(symbol, this_row, i + block_width) == module_is_set(symbol, this_row, i)); - if((addon_latch == 0) && (r == 0) && (i > main_width)) { - plot_height = (int)(row_height - 5.0); - plot_yposn = (int)(row_posn - 5.0); - addon_text_posn = row_posn + row_height - 8.0; - addon_latch = 1; - } - if(latch == 1) { - /* a bar */ - draw_bar(pixelbuf, (i + xoffset) * 2, block_width * 2, plot_yposn * 2, plot_height * 2, image_width, image_height); - latch = 0; - } else { - /* a space */ - latch = 1; - } - i += block_width; + do { + block_width = 0; + do { + block_width++; + } while (module_is_set(symbol, this_row, i + block_width) == module_is_set(symbol, this_row, i)); + if ((addon_latch == 0) && (r == 0) && (i > main_width)) { + plot_height = (int) (row_height - 5.0); + plot_yposn = (int) (row_posn - 5.0); + addon_text_posn = row_posn + row_height - 8.0; + addon_latch = 1; + } + if (latch == 1) { + /* a bar */ + draw_bar(pixelbuf, (i + xoffset) * 2, block_width * 2, plot_yposn * 2, plot_height * 2, image_width, image_height); + latch = 0; + } else { + /* a space */ + latch = 1; + } + i += block_width; - } while (i < symbol->width); - } + } while (i < symbol->width); + } - xoffset += comp_offset; + xoffset += comp_offset; - if ((((symbol->symbology == BARCODE_EANX) && (symbol->rows == 1)) || (symbol->symbology == BARCODE_EANX_CC)) || (symbol->symbology == BARCODE_ISBNX)) { - /* guard bar extensions and text formatting for EAN8 and EAN13 */ - switch(ustrlen(local_text)) { - case 8: /* EAN-8 */ - case 11: - case 14: - draw_bar(pixelbuf, (0 + xoffset) * 2, 1 * 2, (4 + (int)yoffset) * 2, 5 * 2, image_width, image_height); - draw_bar(pixelbuf, (2 + xoffset) * 2, 1 * 2, (4 + (int)yoffset) * 2, 5 * 2, image_width, image_height); - draw_bar(pixelbuf, (32 + xoffset) * 2, 1 * 2, (4 + (int)yoffset) * 2, 5 * 2, image_width, image_height); - draw_bar(pixelbuf, (34 + xoffset) * 2, 1 * 2, (4 + (int)yoffset) * 2, 5 * 2, image_width, image_height); - draw_bar(pixelbuf, (64 + xoffset) * 2, 1 * 2, (4 + (int)yoffset) * 2, 5 * 2, image_width, image_height); - draw_bar(pixelbuf, (66 + xoffset) * 2, 1 * 2, (4 + (int)yoffset) * 2, 5 * 2, image_width, image_height); - for(i = 0; i < 4; i++) { - textpart[i] = symbol->text[i]; - } - textpart[4] = '\0'; - textpos = 2 * (17 + xoffset); + if ((((symbol->symbology == BARCODE_EANX) && (symbol->rows == 1)) || (symbol->symbology == BARCODE_EANX_CC)) || (symbol->symbology == BARCODE_ISBNX)) { + /* guard bar extensions and text formatting for EAN8 and EAN13 */ + switch (ustrlen(local_text)) { + case 8: /* EAN-8 */ + case 11: + case 14: + draw_bar(pixelbuf, (0 + xoffset) * 2, 1 * 2, (4 + (int) yoffset) * 2, 5 * 2, image_width, image_height); + draw_bar(pixelbuf, (2 + xoffset) * 2, 1 * 2, (4 + (int) yoffset) * 2, 5 * 2, image_width, image_height); + draw_bar(pixelbuf, (32 + xoffset) * 2, 1 * 2, (4 + (int) yoffset) * 2, 5 * 2, image_width, image_height); + draw_bar(pixelbuf, (34 + xoffset) * 2, 1 * 2, (4 + (int) yoffset) * 2, 5 * 2, image_width, image_height); + draw_bar(pixelbuf, (64 + xoffset) * 2, 1 * 2, (4 + (int) yoffset) * 2, 5 * 2, image_width, image_height); + draw_bar(pixelbuf, (66 + xoffset) * 2, 1 * 2, (4 + (int) yoffset) * 2, 5 * 2, image_width, image_height); + for (i = 0; i < 4; i++) { + textpart[i] = symbol->text[i]; + } + textpart[4] = '\0'; + textpos = 2 * (17 + xoffset); - draw_string(pixelbuf, textpart, textpos, default_text_posn, smalltext, image_width, image_height); - for(i = 0; i < 4; i++) { - textpart[i] = symbol->text[i + 4]; - } - textpart[4] = '\0'; - textpos = 2 * (50 + xoffset); - draw_string(pixelbuf, textpart, textpos, default_text_posn, smalltext, image_width, image_height); - textdone = 1; - switch(strlen(addon)) { - case 2: - textpos = 2 * (xoffset + 86); - draw_string(pixelbuf, addon, textpos, image_height - (addon_text_posn * 2) - 13, smalltext, image_width, image_height); - break; - case 5: - textpos = 2 * (xoffset + 100); - draw_string(pixelbuf, addon, textpos, image_height - (addon_text_posn * 2) - 13, smalltext, image_width, image_height); - break; - } + draw_string(pixelbuf, textpart, textpos, default_text_posn, smalltext, image_width, image_height); + for (i = 0; i < 4; i++) { + textpart[i] = symbol->text[i + 4]; + } + textpart[4] = '\0'; + textpos = 2 * (50 + xoffset); + draw_string(pixelbuf, textpart, textpos, default_text_posn, smalltext, image_width, image_height); + textdone = 1; + switch (strlen(addon)) { + case 2: + textpos = 2 * (xoffset + 86); + draw_string(pixelbuf, addon, textpos, image_height - (addon_text_posn * 2) - 13, smalltext, image_width, image_height); + break; + case 5: + textpos = 2 * (xoffset + 100); + draw_string(pixelbuf, addon, textpos, image_height - (addon_text_posn * 2) - 13, smalltext, image_width, image_height); + break; + } - break; - case 13: /* EAN 13 */ - case 16: - case 19: - draw_bar(pixelbuf, (0 + xoffset) * 2, 1 * 2, (4 + (int)yoffset) * 2, 5 * 2, image_width, image_height); - draw_bar(pixelbuf, (2 + xoffset) * 2, 1 * 2, (4 + (int)yoffset) * 2, 5 * 2, image_width, image_height); - draw_bar(pixelbuf, (46 + xoffset) * 2, 1 * 2, (4 + (int)yoffset) * 2, 5 * 2, image_width, image_height); - draw_bar(pixelbuf, (48 + xoffset) * 2, 1 * 2, (4 + (int)yoffset) * 2, 5 * 2, image_width, image_height); - draw_bar(pixelbuf, (92 + xoffset) * 2, 1 * 2, (4 + (int)yoffset) * 2, 5 * 2, image_width, image_height); - draw_bar(pixelbuf, (94 + xoffset) * 2, 1 * 2, (4 + (int)yoffset) * 2, 5 * 2, image_width, image_height); + break; + case 13: /* EAN 13 */ + case 16: + case 19: + draw_bar(pixelbuf, (0 + xoffset) * 2, 1 * 2, (4 + (int) yoffset) * 2, 5 * 2, image_width, image_height); + draw_bar(pixelbuf, (2 + xoffset) * 2, 1 * 2, (4 + (int) yoffset) * 2, 5 * 2, image_width, image_height); + draw_bar(pixelbuf, (46 + xoffset) * 2, 1 * 2, (4 + (int) yoffset) * 2, 5 * 2, image_width, image_height); + draw_bar(pixelbuf, (48 + xoffset) * 2, 1 * 2, (4 + (int) yoffset) * 2, 5 * 2, image_width, image_height); + draw_bar(pixelbuf, (92 + xoffset) * 2, 1 * 2, (4 + (int) yoffset) * 2, 5 * 2, image_width, image_height); + draw_bar(pixelbuf, (94 + xoffset) * 2, 1 * 2, (4 + (int) yoffset) * 2, 5 * 2, image_width, image_height); - textpart[0] = symbol->text[0]; - textpart[1] = '\0'; - textpos = 2 * (-7 + xoffset); - draw_string(pixelbuf, textpart, textpos, default_text_posn, smalltext, image_width, image_height); - for(i = 0; i < 6; i++) { - textpart[i] = symbol->text[i + 1]; - } - textpart[6] = '\0'; - textpos = 2 * (24 + xoffset); - draw_string(pixelbuf, textpart, textpos, default_text_posn, smalltext, image_width, image_height); - for(i = 0; i < 6; i++) { - textpart[i] = symbol->text[i + 7]; - } - textpart[6] = '\0'; - textpos = 2 * (71 + xoffset); - draw_string(pixelbuf, textpart, textpos, default_text_posn, smalltext, image_width, image_height); - textdone = 1; - switch(strlen(addon)) { - case 2: - textpos = 2 * (xoffset + 114); - draw_string(pixelbuf, addon, textpos, image_height - (addon_text_posn * 2) - 13, smalltext, image_width, image_height); - break; - case 5: - textpos = 2 * (xoffset + 128); - draw_string(pixelbuf, addon, textpos, image_height - (addon_text_posn * 2) - 13, smalltext, image_width, image_height); - break; - } - break; + textpart[0] = symbol->text[0]; + textpart[1] = '\0'; + textpos = 2 * (-7 + xoffset); + draw_string(pixelbuf, textpart, textpos, default_text_posn, smalltext, image_width, image_height); + for (i = 0; i < 6; i++) { + textpart[i] = symbol->text[i + 1]; + } + textpart[6] = '\0'; + textpos = 2 * (24 + xoffset); + draw_string(pixelbuf, textpart, textpos, default_text_posn, smalltext, image_width, image_height); + for (i = 0; i < 6; i++) { + textpart[i] = symbol->text[i + 7]; + } + textpart[6] = '\0'; + textpos = 2 * (71 + xoffset); + draw_string(pixelbuf, textpart, textpos, default_text_posn, smalltext, image_width, image_height); + textdone = 1; + switch (strlen(addon)) { + case 2: + textpos = 2 * (xoffset + 114); + draw_string(pixelbuf, addon, textpos, image_height - (addon_text_posn * 2) - 13, smalltext, image_width, image_height); + break; + case 5: + textpos = 2 * (xoffset + 128); + draw_string(pixelbuf, addon, textpos, image_height - (addon_text_posn * 2) - 13, smalltext, image_width, image_height); + break; + } + break; - } - } + } + } - if (((symbol->symbology == BARCODE_UPCA) && (symbol->rows == 1)) || (symbol->symbology == BARCODE_UPCA_CC)) { - /* guard bar extensions and text formatting for UPCA */ - latch = 1; + if (((symbol->symbology == BARCODE_UPCA) && (symbol->rows == 1)) || (symbol->symbology == BARCODE_UPCA_CC)) { + /* guard bar extensions and text formatting for UPCA */ + latch = 1; - i = 0 + comp_offset; - do { - block_width = 0; - do { - block_width++; - } while (module_is_set(symbol, symbol->rows - 1, i + block_width) == module_is_set(symbol, symbol->rows - 1, i)); - if(latch == 1) { - /* a bar */ - draw_bar(pixelbuf, (i + xoffset - comp_offset) * 2, block_width * 2, (4 + (int)yoffset) * 2, 5 * 2, image_width, image_height); - latch = 0; - } else { - /* a space */ - latch = 1; - } - i += block_width; - } while (i < 11 + comp_offset); - draw_bar(pixelbuf, (46 + xoffset) * 2, 1 * 2, (4 + (int)yoffset) * 2, 5 * 2, image_width, image_height); - draw_bar(pixelbuf, (48 + xoffset) * 2, 1 * 2, (4 + (int)yoffset) * 2, 5 * 2, image_width, image_height); - latch = 1; - i = 85 + comp_offset; - do { - block_width = 0; - do { - block_width++; - } while (module_is_set(symbol, symbol->rows - 1, i + block_width) == module_is_set(symbol, symbol->rows - 1, i)); - if(latch == 1) { - /* a bar */ - draw_bar(pixelbuf, (i + xoffset - comp_offset) * 2, block_width * 2, (4 + (int)yoffset) * 2, 5 * 2, image_width, image_height); - latch = 0; - } else { - /* a space */ - latch = 1; - } - i += block_width; - } while (i < 96 + comp_offset); - textpart[0] = symbol->text[0]; - textpart[1] = '\0'; - textpos = 2 * (-5 + xoffset); - draw_string(pixelbuf, textpart, textpos, default_text_posn, smalltext, image_width, image_height); - for(i = 0; i < 5; i++) { - textpart[i] = symbol->text[i + 1]; - } - textpart[5] = '\0'; - textpos = 2 * (27 + xoffset); - draw_string(pixelbuf, textpart, textpos, default_text_posn, smalltext, image_width, image_height); - for(i = 0; i < 5; i++) { - textpart[i] = symbol->text[i + 6]; - } - textpart[6] = '\0'; - textpos = 2 * (68 + xoffset); - draw_string(pixelbuf, textpart, textpos, default_text_posn, smalltext, image_width, image_height); - textpart[0] = symbol->text[11]; - textpart[1] = '\0'; - textpos = 2 * (100 + xoffset); - draw_string(pixelbuf, textpart, textpos, default_text_posn, smalltext, image_width, image_height); - textdone = 1; - switch(strlen(addon)) { - case 2: - textpos = 2 * (xoffset + 116); - draw_string(pixelbuf, addon, textpos, image_height - (addon_text_posn * 2) - 13, smalltext, image_width, image_height); - break; - case 5: - textpos = 2 * (xoffset + 130); - draw_string(pixelbuf, addon, textpos, image_height - (addon_text_posn * 2) - 13, smalltext, image_width, image_height); - break; - } + i = 0 + comp_offset; + do { + block_width = 0; + do { + block_width++; + } while (module_is_set(symbol, symbol->rows - 1, i + block_width) == module_is_set(symbol, symbol->rows - 1, i)); + if (latch == 1) { + /* a bar */ + draw_bar(pixelbuf, (i + xoffset - comp_offset) * 2, block_width * 2, (4 + (int) yoffset) * 2, 5 * 2, image_width, image_height); + latch = 0; + } else { + /* a space */ + latch = 1; + } + i += block_width; + } while (i < 11 + comp_offset); + draw_bar(pixelbuf, (46 + xoffset) * 2, 1 * 2, (4 + (int) yoffset) * 2, 5 * 2, image_width, image_height); + draw_bar(pixelbuf, (48 + xoffset) * 2, 1 * 2, (4 + (int) yoffset) * 2, 5 * 2, image_width, image_height); + latch = 1; + i = 85 + comp_offset; + do { + block_width = 0; + do { + block_width++; + } while (module_is_set(symbol, symbol->rows - 1, i + block_width) == module_is_set(symbol, symbol->rows - 1, i)); + if (latch == 1) { + /* a bar */ + draw_bar(pixelbuf, (i + xoffset - comp_offset) * 2, block_width * 2, (4 + (int) yoffset) * 2, 5 * 2, image_width, image_height); + latch = 0; + } else { + /* a space */ + latch = 1; + } + i += block_width; + } while (i < 96 + comp_offset); + textpart[0] = symbol->text[0]; + textpart[1] = '\0'; + textpos = 2 * (-5 + xoffset); + draw_string(pixelbuf, textpart, textpos, default_text_posn, smalltext, image_width, image_height); + for (i = 0; i < 5; i++) { + textpart[i] = symbol->text[i + 1]; + } + textpart[5] = '\0'; + textpos = 2 * (27 + xoffset); + draw_string(pixelbuf, textpart, textpos, default_text_posn, smalltext, image_width, image_height); + for (i = 0; i < 5; i++) { + textpart[i] = symbol->text[i + 6]; + } + textpart[6] = '\0'; + textpos = 2 * (68 + xoffset); + draw_string(pixelbuf, textpart, textpos, default_text_posn, smalltext, image_width, image_height); + textpart[0] = symbol->text[11]; + textpart[1] = '\0'; + textpos = 2 * (100 + xoffset); + draw_string(pixelbuf, textpart, textpos, default_text_posn, smalltext, image_width, image_height); + textdone = 1; + switch (strlen(addon)) { + case 2: + textpos = 2 * (xoffset + 116); + draw_string(pixelbuf, addon, textpos, image_height - (addon_text_posn * 2) - 13, smalltext, image_width, image_height); + break; + case 5: + textpos = 2 * (xoffset + 130); + draw_string(pixelbuf, addon, textpos, image_height - (addon_text_posn * 2) - 13, smalltext, image_width, image_height); + break; + } - } + } - if (((symbol->symbology == BARCODE_UPCE) && (symbol->rows == 1)) || (symbol->symbology == BARCODE_UPCE_CC)) { - /* guard bar extensions and text formatting for UPCE */ - draw_bar(pixelbuf, (0 + xoffset) * 2, 1 * 2, (4 + (int)yoffset) * 2, 5 * 2, image_width, image_height); - draw_bar(pixelbuf, (2 + xoffset) * 2, 1 * 2, (4 + (int)yoffset) * 2, 5 * 2, image_width, image_height); - draw_bar(pixelbuf, (46 + xoffset) * 2, 1 * 2, (4 + (int)yoffset) * 2, 5 * 2, image_width, image_height); - draw_bar(pixelbuf, (48 + xoffset) * 2, 1 * 2, (4 + (int)yoffset) * 2, 5 * 2, image_width, image_height); - draw_bar(pixelbuf, (50 + xoffset) * 2, 1 * 2, (4 + (int)yoffset) * 2, 5 * 2, image_width, image_height); + if (((symbol->symbology == BARCODE_UPCE) && (symbol->rows == 1)) || (symbol->symbology == BARCODE_UPCE_CC)) { + /* guard bar extensions and text formatting for UPCE */ + draw_bar(pixelbuf, (0 + xoffset) * 2, 1 * 2, (4 + (int) yoffset) * 2, 5 * 2, image_width, image_height); + draw_bar(pixelbuf, (2 + xoffset) * 2, 1 * 2, (4 + (int) yoffset) * 2, 5 * 2, image_width, image_height); + draw_bar(pixelbuf, (46 + xoffset) * 2, 1 * 2, (4 + (int) yoffset) * 2, 5 * 2, image_width, image_height); + draw_bar(pixelbuf, (48 + xoffset) * 2, 1 * 2, (4 + (int) yoffset) * 2, 5 * 2, image_width, image_height); + draw_bar(pixelbuf, (50 + xoffset) * 2, 1 * 2, (4 + (int) yoffset) * 2, 5 * 2, image_width, image_height); - textpart[0] = symbol->text[0]; - textpart[1] = '\0'; - textpos = 2 * (-5 + xoffset); - draw_string(pixelbuf, textpart, textpos, default_text_posn, smalltext, image_width, image_height); - for(i = 0; i < 6; i++) { - textpart[i] = symbol->text[i + 1]; - } - textpart[6] = '\0'; - textpos = 2 * (24 + xoffset); - draw_string(pixelbuf, textpart, textpos, default_text_posn, smalltext, image_width, image_height); - textpart[0] = symbol->text[7]; - textpart[1] = '\0'; - textpos = 2 * (55 + xoffset); - draw_string(pixelbuf, textpart, textpos, default_text_posn, smalltext, image_width, image_height); - textdone = 1; - switch(strlen(addon)) { - case 2: - textpos = 2 * (xoffset + 70); - draw_string(pixelbuf, addon, textpos, image_height - (addon_text_posn * 2) - 13, smalltext, image_width, image_height); - break; - case 5: - textpos = 2 * (xoffset + 84); - draw_string(pixelbuf, addon, textpos, image_height - (addon_text_posn * 2) - 13, smalltext, image_width, image_height); - break; - } + textpart[0] = symbol->text[0]; + textpart[1] = '\0'; + textpos = 2 * (-5 + xoffset); + draw_string(pixelbuf, textpart, textpos, default_text_posn, smalltext, image_width, image_height); + for (i = 0; i < 6; i++) { + textpart[i] = symbol->text[i + 1]; + } + textpart[6] = '\0'; + textpos = 2 * (24 + xoffset); + draw_string(pixelbuf, textpart, textpos, default_text_posn, smalltext, image_width, image_height); + textpart[0] = symbol->text[7]; + textpart[1] = '\0'; + textpos = 2 * (55 + xoffset); + draw_string(pixelbuf, textpart, textpos, default_text_posn, smalltext, image_width, image_height); + textdone = 1; + switch (strlen(addon)) { + case 2: + textpos = 2 * (xoffset + 70); + draw_string(pixelbuf, addon, textpos, image_height - (addon_text_posn * 2) - 13, smalltext, image_width, image_height); + break; + case 5: + textpos = 2 * (xoffset + 84); + draw_string(pixelbuf, addon, textpos, image_height - (addon_text_posn * 2) - 13, smalltext, image_width, image_height); + break; + } - } + } - xoffset -= comp_offset; + xoffset -= comp_offset; - /* Put boundary bars or box around symbol */ - if(((symbol->output_options & BARCODE_BOX) != 0) || ((symbol->output_options & BARCODE_BIND) != 0)) { - /* boundary bars */ - draw_bar(pixelbuf, 0, (symbol->width + xoffset + xoffset) * 2, textoffset * 2, symbol->border_width * 2, image_width, image_height); - draw_bar(pixelbuf, 0, (symbol->width + xoffset + xoffset) * 2, (textoffset + symbol->height + symbol->border_width) * 2, symbol->border_width * 2, image_width, image_height); - if((symbol->output_options & BARCODE_BIND) != 0) { - if((symbol->rows > 1) && (is_stackable(symbol->symbology) == 1)) { - /* row binding */ - for(r = 1; r < symbol->rows; r++) { - draw_bar(pixelbuf, xoffset * 2, symbol->width * 2, ((r * row_height) + textoffset + yoffset - 1) * 2, 2 * 2, image_width, image_height); - } - } - } - } + /* Put boundary bars or box around symbol */ + if (((symbol->output_options & BARCODE_BOX) != 0) || ((symbol->output_options & BARCODE_BIND) != 0)) { + /* boundary bars */ + draw_bar(pixelbuf, 0, (symbol->width + xoffset + xoffset) * 2, textoffset * 2, symbol->border_width * 2, image_width, image_height); + draw_bar(pixelbuf, 0, (symbol->width + xoffset + xoffset) * 2, (textoffset + symbol->height + symbol->border_width) * 2, symbol->border_width * 2, image_width, image_height); + if ((symbol->output_options & BARCODE_BIND) != 0) { + if ((symbol->rows > 1) && (is_stackable(symbol->symbology) == 1)) { + /* row binding */ + for (r = 1; r < symbol->rows; r++) { + draw_bar(pixelbuf, xoffset * 2, symbol->width * 2, ((r * row_height) + textoffset + yoffset - 1) * 2, 2 * 2, image_width, image_height); + } + } + } + } - if((symbol->output_options & BARCODE_BOX) != 0) { - /* side bars */ - draw_bar(pixelbuf, 0, symbol->border_width * 2, textoffset * 2, (symbol->height + (2 * symbol->border_width)) * 2, image_width, image_height); - draw_bar(pixelbuf, (symbol->width + xoffset + xoffset - symbol->border_width) * 2, symbol->border_width * 2, textoffset * 2, (symbol->height + (2 * symbol->border_width)) * 2, image_width, image_height); - } + if ((symbol->output_options & BARCODE_BOX) != 0) { + /* side bars */ + draw_bar(pixelbuf, 0, symbol->border_width * 2, textoffset * 2, (symbol->height + (2 * symbol->border_width)) * 2, image_width, image_height); + draw_bar(pixelbuf, (symbol->width + xoffset + xoffset - symbol->border_width) * 2, symbol->border_width * 2, textoffset * 2, (symbol->height + (2 * symbol->border_width)) * 2, image_width, image_height); + } - /* Put the human readable text at the bottom */ - if((textdone == 0) && (ustrlen(local_text) != 0)) { - textpos = (image_width / 2); - draw_string(pixelbuf, (char*)local_text, textpos, default_text_posn, smalltext, image_width, image_height); - } + /* Put the human readable text at the bottom */ + if ((textdone == 0) && (ustrlen(local_text) != 0)) { + textpos = (image_width / 2); + draw_string(pixelbuf, (char*) local_text, textpos, default_text_posn, smalltext, image_width, image_height); + } - error_number=png_to_file(symbol, image_height, image_width, pixelbuf, rotate_angle, data_type); - free(pixelbuf); - return error_number; + error_number = png_to_file(symbol, image_height, image_width, pixelbuf, rotate_angle, data_type); + free(pixelbuf); + return error_number; } #ifndef NO_PNG -int png_handle(struct zint_symbol *symbol, int rotate_angle) -{ - int error; - if(symbol->symbology == BARCODE_MAXICODE) { - error = maxi_png_plot(symbol, rotate_angle, PNG_DATA); - } else { +int png_handle(struct zint_symbol *symbol, int rotate_angle) { + int error; - error = png_plot(symbol, rotate_angle, PNG_DATA); - } + if (symbol->symbology == BARCODE_MAXICODE) { + error = maxi_png_plot(symbol, rotate_angle, PNG_DATA); + } else { - return error; + error = png_plot(symbol, rotate_angle, PNG_DATA); + } + + return error; } #endif /* NO_PNG */ -int bmp_handle(struct zint_symbol *symbol, int rotate_angle) -{ - int error; +int bmp_handle(struct zint_symbol *symbol, int rotate_angle) { + int error; - if(symbol->symbology == BARCODE_MAXICODE) { - error = maxi_png_plot(symbol, rotate_angle, BMP_DATA); - } else { - error = png_plot(symbol, rotate_angle, BMP_DATA); - } + if (symbol->symbology == BARCODE_MAXICODE) { + error = maxi_png_plot(symbol, rotate_angle, BMP_DATA); + } else { + error = png_plot(symbol, rotate_angle, BMP_DATA); + } - return error; + return error; } - diff --git a/backend/postal.c b/backend/postal.c index 8ffd3cd1..9ac7c84e 100644 --- a/backend/postal.c +++ b/backend/postal.c @@ -1,7 +1,8 @@ /* postal.c - Handles PostNet, PLANET, FIM. RM4SCC and Flattermarken */ -/* Zint - A barcode generating program using libpng - Copyright (C) 2008 Robin Stuart +/* + libzint - the open source barcode library + Copyright (C) 2008-2016 Robin Stuart Including bug fixes by Bryan Hatton Redistribution and use in source and binary forms, with or without @@ -28,7 +29,7 @@ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ + */ #include #include @@ -45,570 +46,571 @@ #define SHKASUTSET "1234567890-ABCDEFGHIJKLMNOPQRSTUVWXYZ" /* PostNet number encoding table - In this table L is long as S is short */ -static const char *PNTable[10] = {"LLSSS", "SSSLL", "SSLSL", "SSLLS", "SLSSL", "SLSLS", "SLLSS", "LSSSL", - "LSSLS", "LSLSS"}; -static const char *PLTable[10] = {"SSLLL", "LLLSS", "LLSLS", "LLSSL", "LSLLS", "LSLSL", "LSSLL", "SLLLS", - "SLLSL", "SLSLL"}; +static const char *PNTable[10] = { + "LLSSS", "SSSLL", "SSLSL", "SSLLS", "SLSSL", "SLSLS", "SLLSS", "LSSSL", + "LSSLS", "LSLSS" +}; -static const char *RoyalValues[36] = {"11", "12", "13", "14", "15", "10", "21", "22", "23", "24", "25", - "20", "31", "32", "33", "34", "35", "30", "41", "42", "43", "44", "45", "40", "51", "52", - "53", "54", "55", "50", "01", "02", "03", "04", "05", "00"}; +static const char *PLTable[10] = { + "SSLLL", "LLLSS", "LLSLS", "LLSSL", "LSLLS", "LSLSL", "LSSLL", "SLLLS", + "SLLSL", "SLSLL" +}; + +static const char *RoyalValues[36] = { + "11", "12", "13", "14", "15", "10", "21", "22", "23", "24", "25", + "20", "31", "32", "33", "34", "35", "30", "41", "42", "43", "44", "45", "40", "51", "52", + "53", "54", "55", "50", "01", "02", "03", "04", "05", "00" +}; /* 0 = Full, 1 = Ascender, 2 = Descender, 3 = Tracker */ -static const char *RoyalTable[36] = {"3300", "3210", "3201", "2310", "2301", "2211", "3120", "3030", "3021", - "2130", "2121", "2031", "3102", "3012", "3003", "2112", "2103", "2013", "1320", "1230", - "1221", "0330", "0321", "0231", "1302", "1212", "1203", "0312", "0303", "0213", "1122", - "1032", "1023", "0132", "0123", "0033"}; - -static const char *FlatTable[10] = {"0504", "18", "0117", "0216", "0315", "0414", "0513", "0612", "0711", - "0810"}; +static const char *RoyalTable[36] = { + "3300", "3210", "3201", "2310", "2301", "2211", "3120", "3030", "3021", + "2130", "2121", "2031", "3102", "3012", "3003", "2112", "2103", "2013", "1320", "1230", + "1221", "0330", "0321", "0231", "1302", "1212", "1203", "0312", "0303", "0213", "1122", + "1032", "1023", "0132", "0123", "0033" +}; -static const char *KoreaTable[10] = {"1313150613", "0713131313", "0417131313", "1506131313", - "0413171313", "17171313", "1315061313", "0413131713", "17131713", "13171713"}; - -static const char *JapanTable[19] = {"114", "132", "312", "123", "141", "321", "213", "231", "411", "144", - "414", "324", "342", "234", "432", "243", "423", "441", "111"}; +static const char *FlatTable[10] = { + "0504", "18", "0117", "0216", "0315", "0414", "0513", "0612", "0711", "0810" +}; -int postnet(struct zint_symbol *symbol, unsigned char source[], char dest[], int length) -{ - /* Handles the PostNet system used for Zip codes in the US */ - unsigned int i, sum, check_digit; - int error_number; +static const char *KoreaTable[10] = { + "1313150613", "0713131313", "0417131313", "1506131313", + "0413171313", "17171313", "1315061313", "0413131713", "17131713", "13171713" +}; - error_number = 0; +static const char *JapanTable[19] = { + "114", "132", "312", "123", "141", "321", "213", "231", "411", "144", + "414", "324", "342", "234", "432", "243", "423", "441", "111" +}; - if(length > 38) { - strcpy(symbol->errtxt, "Input too long"); - return ZINT_ERROR_TOO_LONG; - } - error_number = is_sane(NEON, source, length); - if(error_number == ZINT_ERROR_INVALID_DATA) { - strcpy(symbol->errtxt, "Invalid characters in data"); - return error_number; - } - sum = 0; +/* Handles the PostNet system used for Zip codes in the US */ +int postnet(struct zint_symbol *symbol, unsigned char source[], char dest[], int length) { + unsigned int i, sum, check_digit; + int error_number; - /* start character */ - strcpy(dest, "L"); + error_number = 0; - for (i=0; i < length; i++) - { - lookup(NEON, PNTable, source[i], dest); - sum += ctoi(source[i]); - } + if (length > 38) { + strcpy(symbol->errtxt, "Input too long"); + return ZINT_ERROR_TOO_LONG; + } + error_number = is_sane(NEON, source, length); + if (error_number == ZINT_ERROR_INVALID_DATA) { + strcpy(symbol->errtxt, "Invalid characters in data"); + return error_number; + } + sum = 0; - check_digit = (10 - (sum % 10)) % 10; - concat(dest, PNTable[check_digit]); + /* start character */ + strcpy(dest, "L"); - /* stop character */ - concat (dest, "L"); + for (i = 0; i < length; i++) { + lookup(NEON, PNTable, source[i], dest); + sum += ctoi(source[i]); + } - return error_number; + check_digit = (10 - (sum % 10)) % 10; + concat(dest, PNTable[check_digit]); + + /* stop character */ + concat(dest, "L"); + + return error_number; } -int post_plot(struct zint_symbol *symbol, unsigned char source[], int length) -{ - /* Puts PostNet barcodes into the pattern matrix */ - char height_pattern[256]; /* 5 + 38 * 5 + 5 + 5 + 1 ~ 256 */ - unsigned int loopey, h; - int writer; - int error_number; +/* Puts PostNet barcodes into the pattern matrix */ +int post_plot(struct zint_symbol *symbol, unsigned char source[], int length) { + char height_pattern[256]; /* 5 + 38 * 5 + 5 + 5 + 1 ~ 256 */ + unsigned int loopey, h; + int writer; + int error_number; - error_number = 0; + error_number = 0; - error_number = postnet(symbol, source, height_pattern, length); - if(error_number != 0) { - return error_number; - } + error_number = postnet(symbol, source, height_pattern, length); + if (error_number != 0) { + return error_number; + } - writer = 0; - h = strlen(height_pattern); - for(loopey = 0; loopey < h; loopey++) - { - if(height_pattern[loopey] == 'L') - { - set_module(symbol, 0, writer); - } - set_module(symbol, 1, writer); - writer += 3; - } - symbol->row_height[0] = 6; - symbol->row_height[1] = 6; - symbol->rows = 2; - symbol->width = writer - 1; + writer = 0; + h = strlen(height_pattern); + for (loopey = 0; loopey < h; loopey++) { + if (height_pattern[loopey] == 'L') { + set_module(symbol, 0, writer); + } + set_module(symbol, 1, writer); + writer += 3; + } + symbol->row_height[0] = 6; + symbol->row_height[1] = 6; + symbol->rows = 2; + symbol->width = writer - 1; - return error_number; + return error_number; } -int planet(struct zint_symbol *symbol, unsigned char source[], char dest[], int length) -{ - /* Handles the PLANET system used for item tracking in the US */ - unsigned int i, sum, check_digit; - int error_number; +/* Handles the PLANET system used for item tracking in the US */ +int planet(struct zint_symbol *symbol, unsigned char source[], char dest[], int length) { + unsigned int i, sum, check_digit; + int error_number; - error_number = 0; + error_number = 0; - if(length > 38) { - strcpy(symbol->errtxt, "Input too long"); - return ZINT_ERROR_TOO_LONG; - } - error_number = is_sane(NEON, source, length); - if(error_number == ZINT_ERROR_INVALID_DATA) { - strcpy(symbol->errtxt, "Invalid characters in data"); - return error_number; - } - sum = 0; + if (length > 38) { + strcpy(symbol->errtxt, "Input too long"); + return ZINT_ERROR_TOO_LONG; + } + error_number = is_sane(NEON, source, length); + if (error_number == ZINT_ERROR_INVALID_DATA) { + strcpy(symbol->errtxt, "Invalid characters in data"); + return error_number; + } + sum = 0; - /* start character */ - strcpy(dest, "L"); + /* start character */ + strcpy(dest, "L"); - for (i=0; i < length; i++) - { - lookup(NEON, PLTable, source[i], dest); - sum += ctoi(source[i]); - } + for (i = 0; i < length; i++) { + lookup(NEON, PLTable, source[i], dest); + sum += ctoi(source[i]); + } - check_digit = (10 - (sum % 10)) % 10; - concat(dest, PLTable[check_digit]); + check_digit = (10 - (sum % 10)) % 10; + concat(dest, PLTable[check_digit]); - /* stop character */ - concat (dest, "L"); + /* stop character */ + concat(dest, "L"); - return error_number; + return error_number; } -int planet_plot(struct zint_symbol *symbol, unsigned char source[], int length) -{ - /* Puts PLANET barcodes into the pattern matrix */ - char height_pattern[256]; /* 5 + 38 * 5 + 5 + 5 + 1 ~ 256 */ - unsigned int loopey, h; - int writer; - int error_number; +/* Puts PLANET barcodes into the pattern matrix */ +int planet_plot(struct zint_symbol *symbol, unsigned char source[], int length) { + char height_pattern[256]; /* 5 + 38 * 5 + 5 + 5 + 1 ~ 256 */ + unsigned int loopey, h; + int writer; + int error_number; - error_number = 0; + error_number = 0; - error_number = planet(symbol, source, height_pattern, length); - if(error_number != 0) { - return error_number; - } + error_number = planet(symbol, source, height_pattern, length); + if (error_number != 0) { + return error_number; + } - writer = 0; - h = strlen(height_pattern); - for(loopey = 0; loopey < h; loopey++) - { - if(height_pattern[loopey] == 'L') - { - set_module(symbol, 0, writer); - } - set_module(symbol, 1, writer); - writer += 3; - } - symbol->row_height[0] = 6; - symbol->row_height[1] = 6; - symbol->rows = 2; - symbol->width = writer - 1; - return error_number; + writer = 0; + h = strlen(height_pattern); + for (loopey = 0; loopey < h; loopey++) { + if (height_pattern[loopey] == 'L') { + set_module(symbol, 0, writer); + } + set_module(symbol, 1, writer); + writer += 3; + } + symbol->row_height[0] = 6; + symbol->row_height[1] = 6; + symbol->rows = 2; + symbol->width = writer - 1; + return error_number; } -int korea_post(struct zint_symbol *symbol, unsigned char source[], int length) -{ /* Korean Postal Authority */ +/* Korean Postal Authority */ +int korea_post(struct zint_symbol *symbol, unsigned char source[], int length) { + int total, loop, check, zeroes, error_number; + char localstr[8], dest[80]; - int total, loop, check, zeroes, error_number; - char localstr[8], dest[80]; + error_number = 0; + if (length > 6) { + strcpy(symbol->errtxt, "Input too long"); + return ZINT_ERROR_TOO_LONG; + } + error_number = is_sane(NEON, source, length); + if (error_number == ZINT_ERROR_INVALID_DATA) { + strcpy(symbol->errtxt, "Invalid characters in data"); + return error_number; + } + zeroes = 6 - length; + memset(localstr, '0', zeroes); + strcpy(localstr + zeroes, (char *) source); - error_number = 0; - if(length > 6) { - strcpy(symbol->errtxt, "Input too long"); - return ZINT_ERROR_TOO_LONG; - } - error_number = is_sane(NEON, source, length); - if(error_number == ZINT_ERROR_INVALID_DATA) { - strcpy(symbol->errtxt, "Invalid characters in data"); - return error_number; - } - zeroes = 6 - length; - memset(localstr, '0', zeroes); - strcpy(localstr + zeroes, (char *)source); - - total = 0; - for(loop = 0; loop < 6; loop++) { - total += ctoi(localstr[loop]); - } - check = 10 - (total % 10); - if(check == 10) { check = 0; } - localstr[6] = itoc(check); - localstr[7] = '\0'; - *dest = '\0'; - for(loop = 5; loop >= 0; loop--) { - lookup(NEON, KoreaTable, localstr[loop], dest); - } - lookup(NEON, KoreaTable, localstr[6], dest); - expand(symbol, dest); - ustrcpy(symbol->text, (unsigned char*)localstr); - return error_number; + total = 0; + for (loop = 0; loop < 6; loop++) { + total += ctoi(localstr[loop]); + } + check = 10 - (total % 10); + if (check == 10) { + check = 0; + } + localstr[6] = itoc(check); + localstr[7] = '\0'; + *dest = '\0'; + for (loop = 5; loop >= 0; loop--) { + lookup(NEON, KoreaTable, localstr[loop], dest); + } + lookup(NEON, KoreaTable, localstr[6], dest); + expand(symbol, dest); + ustrcpy(symbol->text, (unsigned char*) localstr); + return error_number; } -int fim(struct zint_symbol *symbol, unsigned char source[], int length) -{ - /* The simplest barcode symbology ever! Supported by MS Word, so here it is! */ - /* glyphs from http://en.wikipedia.org/wiki/Facing_Identification_Mark */ +/* The simplest barcode symbology ever! Supported by MS Word, so here it is! + glyphs from http://en.wikipedia.org/wiki/Facing_Identification_Mark */ +int fim(struct zint_symbol *symbol, unsigned char source[], int length) { + - char dest[16] = { 0 }; + char dest[16] = {0}; - if(length > 1) { - strcpy(symbol->errtxt, "Input too long"); - return ZINT_ERROR_TOO_LONG; - } + if (length > 1) { + strcpy(symbol->errtxt, "Input too long"); + return ZINT_ERROR_TOO_LONG; + } - switch((char)source[0]) { - case 'a': - case 'A': - strcpy(dest, "111515111"); - break; - case 'b': - case 'B': - strcpy(dest, "13111311131"); - break; - case 'c': - case 'C': - strcpy(dest, "11131313111"); - break; - case 'd': - case 'D': - strcpy(dest, "1111131311111"); - break; - default: - strcpy(symbol->errtxt, "Invalid characters in data"); - return ZINT_ERROR_INVALID_DATA; - break; - } + switch ((char) source[0]) { + case 'a': + case 'A': + strcpy(dest, "111515111"); + break; + case 'b': + case 'B': + strcpy(dest, "13111311131"); + break; + case 'c': + case 'C': + strcpy(dest, "11131313111"); + break; + case 'd': + case 'D': + strcpy(dest, "1111131311111"); + break; + default: + strcpy(symbol->errtxt, "Invalid characters in data"); + return ZINT_ERROR_INVALID_DATA; + break; + } - expand(symbol, dest); - return 0; + expand(symbol, dest); + return 0; } -char rm4scc(char source[], unsigned char dest[], int length) -{ - /* Handles the 4 State barcodes used in the UK by Royal Mail */ - unsigned int i; - int top, bottom, row, column, check_digit; - char values[3], set_copy[] = KRSET; +/* Handles the 4 State barcodes used in the UK by Royal Mail */ +char rm4scc(char source[], unsigned char dest[], int length) { + unsigned int i; + int top, bottom, row, column, check_digit; + char values[3], set_copy[] = KRSET; - top = 0; - bottom = 0; + top = 0; + bottom = 0; - /* start character */ - strcpy((char*)dest, "1"); + /* start character */ + strcpy((char*) dest, "1"); - for (i = 0; i < length; i++) { - lookup(KRSET, RoyalTable, source[i], (char*)dest); - strcpy(values, RoyalValues[posn(KRSET, source[i])]); - top += ctoi(values[0]); - bottom += ctoi(values[1]); - } + for (i = 0; i < length; i++) { + lookup(KRSET, RoyalTable, source[i], (char*) dest); + strcpy(values, RoyalValues[posn(KRSET, source[i])]); + top += ctoi(values[0]); + bottom += ctoi(values[1]); + } - /* Calculate the check digit */ - row = (top % 6) - 1; - column = (bottom % 6) - 1; - if(row == -1) { row = 5; } - if(column == -1) { column = 5; } - check_digit = (6 * row) + column; - concat((char*)dest, RoyalTable[check_digit]); + /* Calculate the check digit */ + row = (top % 6) - 1; + column = (bottom % 6) - 1; + if (row == -1) { + row = 5; + } + if (column == -1) { + column = 5; + } + check_digit = (6 * row) + column; + concat((char*) dest, RoyalTable[check_digit]); - /* stop character */ - concat ((char*)dest, "0"); + /* stop character */ + concat((char*) dest, "0"); - return set_copy[check_digit]; + return set_copy[check_digit]; } -int royal_plot(struct zint_symbol *symbol, unsigned char source[], int length) -{ - /* Puts RM4SCC into the data matrix */ - char height_pattern[200]; - unsigned int loopey, h; - int writer; - int error_number; - strcpy(height_pattern, ""); +/* Puts RM4SCC into the data matrix */ +int royal_plot(struct zint_symbol *symbol, unsigned char source[], int length) { + char height_pattern[200]; + unsigned int loopey, h; + int writer; + int error_number; + strcpy(height_pattern, ""); - error_number = 0; + error_number = 0; - if(length > 120) { - strcpy(symbol->errtxt, "Input too long"); - return ZINT_ERROR_TOO_LONG; - } - to_upper(source); - error_number = is_sane(KRSET, source, length); - if(error_number == ZINT_ERROR_INVALID_DATA) { - strcpy(symbol->errtxt, "Invalid characters in data"); - return error_number; - } - /*check = */rm4scc((char*)source, (unsigned char*)height_pattern, length); - - writer = 0; - h = strlen(height_pattern); - for(loopey = 0; loopey < h; loopey++) - { - if((height_pattern[loopey] == '1') || (height_pattern[loopey] == '0')) - { - set_module(symbol, 0, writer); - } - set_module(symbol, 1, writer); - if((height_pattern[loopey] == '2') || (height_pattern[loopey] == '0')) - { - set_module(symbol, 2, writer); - } - writer += 2; - } + if (length > 120) { + strcpy(symbol->errtxt, "Input too long"); + return ZINT_ERROR_TOO_LONG; + } + to_upper(source); + error_number = is_sane(KRSET, source, length); + if (error_number == ZINT_ERROR_INVALID_DATA) { + strcpy(symbol->errtxt, "Invalid characters in data"); + return error_number; + } + /*check = */rm4scc((char*) source, (unsigned char*) height_pattern, length); - symbol->row_height[0] = 3; - symbol->row_height[1] = 2; - symbol->row_height[2] = 3; - symbol->rows = 3; - symbol->width = writer - 1; + writer = 0; + h = strlen(height_pattern); + for (loopey = 0; loopey < h; loopey++) { + if ((height_pattern[loopey] == '1') || (height_pattern[loopey] == '0')) { + set_module(symbol, 0, writer); + } + set_module(symbol, 1, writer); + if ((height_pattern[loopey] == '2') || (height_pattern[loopey] == '0')) { + set_module(symbol, 2, writer); + } + writer += 2; + } - return error_number; + symbol->row_height[0] = 3; + symbol->row_height[1] = 2; + symbol->row_height[2] = 3; + symbol->rows = 3; + symbol->width = writer - 1; + + return error_number; } -int kix_code(struct zint_symbol *symbol, unsigned char source[], int length) -{ - /* Handles Dutch Post TNT KIX symbols */ - /* The same as RM4SCC but without check digit */ - /* Specification at http://www.tntpost.nl/zakelijk/klantenservice/downloads/kIX_code/download.aspx */ - char height_pattern[50], localstr[20]; - unsigned int loopey; - int writer, i, h; - int error_number; /* zeroes; */ - strcpy(height_pattern, ""); +/* Handles Dutch Post TNT KIX symbols + The same as RM4SCC but without check digit + Specification at http://www.tntpost.nl/zakelijk/klantenservice/downloads/kIX_code/download.aspx */ +int kix_code(struct zint_symbol *symbol, unsigned char source[], int length) { + char height_pattern[50], localstr[20]; + unsigned int loopey; + int writer, i, h; + int error_number; /* zeroes; */ + strcpy(height_pattern, ""); - error_number = 0; + error_number = 0; - if(length > 18) { - strcpy(symbol->errtxt, "Input too long"); - return ZINT_ERROR_TOO_LONG; - } - to_upper(source); - error_number = is_sane(KRSET, source, length); - if(error_number == ZINT_ERROR_INVALID_DATA) { - strcpy(symbol->errtxt, "Invalid characters in data"); - return error_number; - } + if (length > 18) { + strcpy(symbol->errtxt, "Input too long"); + return ZINT_ERROR_TOO_LONG; + } + to_upper(source); + error_number = is_sane(KRSET, source, length); + if (error_number == ZINT_ERROR_INVALID_DATA) { + strcpy(symbol->errtxt, "Invalid characters in data"); + return error_number; + } - /* Add leading zeroes */ - /* zeroes = 11 - length; - memset(localstr, '0', zeroes); - strcpy(localstr + zeroes, (char *)source);*/ - strcpy(localstr, (char *)source); + strcpy(localstr, (char *) source); - /* Encode data */ - for (i = 0; i < 18; i++) { - lookup(KRSET, RoyalTable, localstr[i], height_pattern); - } + /* Encode data */ + for (i = 0; i < 18; i++) { + lookup(KRSET, RoyalTable, localstr[i], height_pattern); + } - writer = 0; - h = strlen(height_pattern); - for(loopey = 0; loopey < h; loopey++) - { - if((height_pattern[loopey] == '1') || (height_pattern[loopey] == '0')) - { - set_module(symbol, 0, writer); - } - set_module(symbol, 1, writer); - if((height_pattern[loopey] == '2') || (height_pattern[loopey] == '0')) - { - set_module(symbol, 2, writer); - } - writer += 2; - } + writer = 0; + h = strlen(height_pattern); + for (loopey = 0; loopey < h; loopey++) { + if ((height_pattern[loopey] == '1') || (height_pattern[loopey] == '0')) { + set_module(symbol, 0, writer); + } + set_module(symbol, 1, writer); + if ((height_pattern[loopey] == '2') || (height_pattern[loopey] == '0')) { + set_module(symbol, 2, writer); + } + writer += 2; + } - symbol->row_height[0] = 3; - symbol->row_height[1] = 2; - symbol->row_height[2] = 3; - symbol->rows = 3; - symbol->width = writer - 1; + symbol->row_height[0] = 3; + symbol->row_height[1] = 2; + symbol->row_height[2] = 3; + symbol->rows = 3; + symbol->width = writer - 1; - return error_number; + return error_number; } -int daft_code(struct zint_symbol *symbol, unsigned char source[], int length) -{ - /* Handles DAFT Code symbols */ - /* Presumably 'daft' doesn't mean the same thing in Germany as it does in the UK! */ - char height_pattern[100]; - unsigned int loopey, h; - int writer, i, error_number; - strcpy(height_pattern, ""); +/* Handles DAFT Code symbols */ +int daft_code(struct zint_symbol *symbol, unsigned char source[], int length) { + char height_pattern[100]; + unsigned int loopey, h; + int writer, i, error_number; + strcpy(height_pattern, ""); - error_number = 0; - if(length > 50) { - strcpy(symbol->errtxt, "Input too long"); - return ZINT_ERROR_TOO_LONG; - } - to_upper((unsigned char*)source); - error_number = is_sane(DAFTSET, (unsigned char*)source, length); + error_number = 0; + if (length > 50) { + strcpy(symbol->errtxt, "Input too long"); + return ZINT_ERROR_TOO_LONG; + } + to_upper((unsigned char*) source); + error_number = is_sane(DAFTSET, (unsigned char*) source, length); - if(error_number == ZINT_ERROR_INVALID_DATA) { - strcpy(symbol->errtxt, "Invalid characters in data"); - return error_number; - } + if (error_number == ZINT_ERROR_INVALID_DATA) { + strcpy(symbol->errtxt, "Invalid characters in data"); + return error_number; + } - for (i = 0; i < length; i++) { - if(source[i] == 'D') { concat(height_pattern, "2"); } - if(source[i] == 'A') { concat(height_pattern, "1"); } - if(source[i] == 'F') { concat(height_pattern, "0"); } - if(source[i] == 'T') { concat(height_pattern, "3"); } - } + for (i = 0; i < length; i++) { + if (source[i] == 'D') { + concat(height_pattern, "2"); + } + if (source[i] == 'A') { + concat(height_pattern, "1"); + } + if (source[i] == 'F') { + concat(height_pattern, "0"); + } + if (source[i] == 'T') { + concat(height_pattern, "3"); + } + } - writer = 0; - h = strlen(height_pattern); - for(loopey = 0; loopey < h; loopey++) - { - if((height_pattern[loopey] == '1') || (height_pattern[loopey] == '0')) - { - set_module(symbol, 0, writer); - } - set_module(symbol, 1, writer); - if((height_pattern[loopey] == '2') || (height_pattern[loopey] == '0')) - { - set_module(symbol, 2, writer); - } - writer += 2; - } + writer = 0; + h = strlen(height_pattern); + for (loopey = 0; loopey < h; loopey++) { + if ((height_pattern[loopey] == '1') || (height_pattern[loopey] == '0')) { + set_module(symbol, 0, writer); + } + set_module(symbol, 1, writer); + if ((height_pattern[loopey] == '2') || (height_pattern[loopey] == '0')) { + set_module(symbol, 2, writer); + } + writer += 2; + } - symbol->row_height[0] = 3; - symbol->row_height[1] = 2; - symbol->row_height[2] = 3; - symbol->rows = 3; - symbol->width = writer - 1; + symbol->row_height[0] = 3; + symbol->row_height[1] = 2; + symbol->row_height[2] = 3; + symbol->rows = 3; + symbol->width = writer - 1; - return error_number; + return error_number; } -int flattermarken(struct zint_symbol *symbol, unsigned char source[], int length) -{ /* Flattermarken - Not really a barcode symbology and (in my opinion) probably not much use - but it's supported by TBarCode so it's supported by Zint! */ - int loop, error_number; - char dest[512]; /* 90 * 4 + 1 ~ */ +/* Flattermarken - Not really a barcode symbology! */ +int flattermarken(struct zint_symbol *symbol, unsigned char source[], int length) { + int loop, error_number; + char dest[512]; /* 90 * 4 + 1 ~ */ - error_number = 0; + error_number = 0; - if(length > 90) { - strcpy(symbol->errtxt, "Input too long"); - return ZINT_ERROR_TOO_LONG; - } - error_number = is_sane(NEON, source, length); - if(error_number == ZINT_ERROR_INVALID_DATA) { - strcpy(symbol->errtxt, "Invalid characters in data"); - return error_number; - } - *dest = '\0'; - for(loop = 0; loop < length; loop++) { - lookup(NEON, FlatTable, source[loop], dest); - } - - expand(symbol, dest); - return error_number; + if (length > 90) { + strcpy(symbol->errtxt, "Input too long"); + return ZINT_ERROR_TOO_LONG; + } + error_number = is_sane(NEON, source, length); + if (error_number == ZINT_ERROR_INVALID_DATA) { + strcpy(symbol->errtxt, "Invalid characters in data"); + return error_number; + } + *dest = '\0'; + for (loop = 0; loop < length; loop++) { + lookup(NEON, FlatTable, source[loop], dest); + } + + expand(symbol, dest); + return error_number; } -int japan_post(struct zint_symbol *symbol, unsigned char source[], int length) -{ /* Japanese Postal Code (Kasutama Barcode) */ - int error_number, h; - char pattern[69]; - int writer, loopey, inter_posn, i, sum, check; - char check_char; - char inter[23]; +/* Japanese Postal Code (Kasutama Barcode) */ +int japan_post(struct zint_symbol *symbol, unsigned char source[], int length) { + int error_number, h; + char pattern[69]; + int writer, loopey, inter_posn, i, sum, check; + char check_char; + char inter[23]; #ifndef _MSC_VER - char local_source[length + 1]; + char local_source[length + 1]; #else - char* local_source = (char*)_alloca(length + 1); + char* local_source = (char*) _alloca(length + 1); #endif - - inter_posn = 0; - error_number = 0; - strcpy(local_source, (char*)source); - for(i = 0; i < length; i++) { - local_source[i] = source[i]; - } - to_upper((unsigned char*)local_source); - error_number = is_sane(SHKASUTSET, (unsigned char*)local_source, length); + inter_posn = 0; + error_number = 0; - if(error_number == ZINT_ERROR_INVALID_DATA) { - strcpy(symbol->errtxt, "Invalid characters in data"); - return error_number; - } - memset(inter, 'd', 20);/* Pad character CC4 */ - inter[20] = '\0'; + strcpy(local_source, (char*) source); + for (i = 0; i < length; i++) { + local_source[i] = source[i]; + } + to_upper((unsigned char*) local_source); + error_number = is_sane(SHKASUTSET, (unsigned char*) local_source, length); - i = 0; - inter_posn = 0; - do { - if(((local_source[i] >= '0') && (local_source[i] <= '9')) || (local_source[i] == '-')) { - inter[inter_posn] = local_source[i]; - inter_posn++; - } else { - if((local_source[i] >= 'A') && (local_source[i] <= 'J')) { - inter[inter_posn] = 'a'; - inter[inter_posn + 1] = local_source[i] - 'A' + '0'; - inter_posn += 2; - } - if((local_source[i] >= 'K') && (local_source[i] <= 'T')) { - inter[inter_posn] = 'b'; - inter[inter_posn + 1] = local_source[i] - 'K' + '0'; - inter_posn += 2; - } - if((local_source[i] >= 'U') && (local_source[i] <= 'Z')) { - inter[inter_posn] = 'c'; - inter[inter_posn + 1] = local_source[i] - 'U' + '0'; - inter_posn += 2; - } - } - i++; - }while((i < length) && (inter_posn < 20)); - inter[20] = '\0'; + if (error_number == ZINT_ERROR_INVALID_DATA) { + strcpy(symbol->errtxt, "Invalid characters in data"); + return error_number; + } + memset(inter, 'd', 20); /* Pad character CC4 */ + inter[20] = '\0'; - strcpy(pattern, "13"); /* Start */ + i = 0; + inter_posn = 0; + do { + if (((local_source[i] >= '0') && (local_source[i] <= '9')) || (local_source[i] == '-')) { + inter[inter_posn] = local_source[i]; + inter_posn++; + } else { + if ((local_source[i] >= 'A') && (local_source[i] <= 'J')) { + inter[inter_posn] = 'a'; + inter[inter_posn + 1] = local_source[i] - 'A' + '0'; + inter_posn += 2; + } + if ((local_source[i] >= 'K') && (local_source[i] <= 'T')) { + inter[inter_posn] = 'b'; + inter[inter_posn + 1] = local_source[i] - 'K' + '0'; + inter_posn += 2; + } + if ((local_source[i] >= 'U') && (local_source[i] <= 'Z')) { + inter[inter_posn] = 'c'; + inter[inter_posn + 1] = local_source[i] - 'U' + '0'; + inter_posn += 2; + } + } + i++; + } while ((i < length) && (inter_posn < 20)); + inter[20] = '\0'; - sum = 0; - for(i = 0; i < 20; i++) { - concat(pattern, JapanTable[posn(KASUTSET, inter[i])]); - sum += posn(CHKASUTSET, inter[i]); - /* printf("%c (%d)\n", inter[i], posn(CHKASUTSET, inter[i])); */ - } + strcpy(pattern, "13"); /* Start */ - /* Calculate check digit */ - check = 19 - (sum % 19); - if(check == 19) { check = 0; } - if(check <= 9) { check_char = check + '0'; } - if(check == 10) { check_char = '-'; } - if(check >= 11) { check_char = (check - 11) + 'a'; } - concat(pattern, JapanTable[posn(KASUTSET, check_char)]); - /* printf("check %c (%d)\n", check_char, check); */ + sum = 0; + for (i = 0; i < 20; i++) { + concat(pattern, JapanTable[posn(KASUTSET, inter[i])]); + sum += posn(CHKASUTSET, inter[i]); + } - concat(pattern, "31"); /* Stop */ + /* Calculate check digit */ + check = 19 - (sum % 19); + if (check == 19) { + check = 0; + } + if (check <= 9) { + check_char = check + '0'; + } + if (check == 10) { + check_char = '-'; + } + if (check >= 11) { + check_char = (check - 11) + 'a'; + } + concat(pattern, JapanTable[posn(KASUTSET, check_char)]); - /* Resolve pattern to 4-state symbols */ - writer = 0; - h = strlen(pattern); - for(loopey = 0; loopey < h; loopey++) - { - if((pattern[loopey] == '2') || (pattern[loopey] == '1')) - { - set_module(symbol, 0, writer); - } - set_module(symbol, 1, writer); - if((pattern[loopey] == '3') || (pattern[loopey] == '1')) - { - set_module(symbol, 2, writer); - } - writer += 2; - } + concat(pattern, "31"); /* Stop */ - symbol->row_height[0] = 3; - symbol->row_height[1] = 2; - symbol->row_height[2] = 3; - symbol->rows = 3; - symbol->width = writer - 1; + /* Resolve pattern to 4-state symbols */ + writer = 0; + h = strlen(pattern); + for (loopey = 0; loopey < h; loopey++) { + if ((pattern[loopey] == '2') || (pattern[loopey] == '1')) { + set_module(symbol, 0, writer); + } + set_module(symbol, 1, writer); + if ((pattern[loopey] == '3') || (pattern[loopey] == '1')) { + set_module(symbol, 2, writer); + } + writer += 2; + } - return error_number; + symbol->row_height[0] = 3; + symbol->row_height[1] = 2; + symbol->row_height[2] = 3; + symbol->rows = 3; + symbol->width = writer - 1; + + return error_number; }