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AEX,EAAuB,KAAlB,EAAK,GAAO,GACjB,EAAM,EAAS,GAAM,GAAO,CAC7B,CAGA,OADA,GAAa,MAAN,GAAc,SAAS,IAAI,cAC3B,OAAO,OAAO,EAAI,QAAU,CACpC,CAEA,OAAO,EAAO,CAAE,YAAW,aAAc,CAAE,YAAW,YAAW,WA5ZjE,SAAoB,EAAK,GAExB,IAAI,EAAM,SAAS,cAAc,UAC7B,EAAM,EAAI,WAAW,MAEzB,EAAI,OAAU,EAAI,OAAS,EAAI,YAC/B,EAAI,QAAU,EAAI,QAAU,EAAI,aAC7B,EAAI,sBAAwB,OAC5B,EAAI,UAAU,EAAK,EAAG,EAAG,EAAI,MAAO,EAAI,QAE3C,IAAI,EAAS,EAAI,aAAa,EAAG,EAAG,EAAI,MAAO,EAAI,QACnD,OAAO,EAAU,EAAO,KAAM,EAAO,MAAO,EAC7C,EAgZ6E,WA7Y7E,SAAoB,EAAK,GAExB,IAAI,EAAM,SAAS,cAAc,UAC7B,EAAM,EAAI,WAAW,MAEzB,EAAI,OAAU,EAAI,OAAS,EAAI,YAC/B,EAAI,QAAU,EAAI,QAAU,EAAI,aAC7B,EAAI,sBAAwB,OAC5B,EAAI,UAAU,EAAK,EAAG,EAAG,EAAI,MAAO,EAAI,QAE3C,IAAI,EAAS,EAAI,aAAa,EAAG,EAAG,EAAI,MAAO,EAAI,QACnD,OAAO,EAAU,EAAO,KAAM,EAAO,MAAO,EAC7C,EAkYA","file":"/npm/zpl-image@0.2.0/zpl-image.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/zpl-image@0.2.0/zpl-image.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","\n(function (root, factory) {\n    if (typeof define === 'function' && define.amd) {\n        define([], factory);\n    } else if (typeof module === 'object' && module.exports) {\n        module.exports = factory();\n    } else {\n\t\t// generic browser usage\n        let ex = factory();\n\t\tfor (let id in ex) {\n\t\t\troot[id] = ex[id];\n\t\t}\n  }\n}(typeof self !== 'undefined' ? self : this, function () {\n\nconst zlib = typeof process == 'object' && typeof process.release == 'object' &&\n\t\t\t\tprocess.release.name == 'node' ? require('zlib') : null;\n\nconst hexmap = (()=> {\n    let arr = Array(256);\n    for (let i = 0; i < 16; i++) {\n        arr[i] = '0' + i.toString(16);\n    }\n    for (let i = 16; i < 256; i++) {\n        arr[i] = i.toString(16);\n    }\n    return arr;\n})();\n\n// DOM-specialized version for browsers.\nfunction imageToZ64(img, opts) {\n\t// Draw the image to a temp canvas so we can access its RGBA data\n\tlet cvs = document.createElement('canvas');\n\tlet ctx = cvs.getContext('2d');\n\n\tcvs.width  = +img.width || img.offsetWidth;\n\tcvs.height = +img.height || img.offsetHeight;\n    ctx.imageSmoothingQuality = 'high'; // in case canvas needs to scale image\n    ctx.drawImage(img, 0, 0, cvs.width, cvs.height);\n\n\tlet pixels = ctx.getImageData(0, 0, cvs.width, cvs.height);\n\treturn rgbaToZ64(pixels.data, pixels.width, opts);\n}\n\n// DOM-specialized version for browsers.\nfunction imageToACS(img, opts) {\n\t// Draw the image to a temp canvas so we can access its RGBA data\n\tlet cvs = document.createElement('canvas');\n\tlet ctx = cvs.getContext('2d');\n\n\tcvs.width  = +img.width || img.offsetWidth;\n\tcvs.height = +img.height || img.offsetHeight;\n    ctx.imageSmoothingQuality = 'high'; // in case canvas needs to scale image\n    ctx.drawImage(img, 0, 0, cvs.width, cvs.height);\n\n\tlet pixels = ctx.getImageData(0, 0, cvs.width, cvs.height);\n\treturn rgbaToACS(pixels.data, pixels.width, opts);\n}\n\n// Uses zlib on node.js, pako.js in the browser.\n//\n// `rgba` can be a Uint8Array or Buffer, or an Array of integers between 0 and 255.\n// `width` is the image width, in pixels\n// `opts` is an options object:\n//\t\t`black` is the blackness percent between 1..99, default 50.\n//\t\t`rotate` is one of:\n//\t\t\t'N' no rotation (default)\n//\t\t\t'L' rotate 90 degrees counter-clockwise\n//\t\t\t'R' rotate 90 degrees clockwise\n//\t\t\t'I' rotate 180 degrees (inverted)\n//\t\t\t'B' same as 'L'\nfunction rgbaToZ64(rgba, width, opts) {\n\topts = opts || {};\n\twidth = width|0;\n\tif (!width || width < 0) {\n\t\tthrow new Error('Invalid width');\n\t}\n\tlet height = ~~(rgba.length / width / 4);\n\n\t// Create a monochome image, cropped to remove padding.\n\t// The return is a Uint8Array with extra properties width and height.\n\tlet mono = monochrome(rgba, width, height, +opts.black || 50, opts.notrim);\n\n\tlet buf;\n\tswitch (opts.rotate) {\n\tcase 'R': buf = right(mono); break;\n\tcase 'B':\n\tcase 'L': buf = left(mono); break;\n\tcase 'I': buf = invert(mono); break;\n\tdefault:  buf = normal(mono); break;\n\t}\n\n\t// Compress and base64 encode\n\tlet imgw = buf.width;\n\tlet imgh = buf.height;\n\tlet rowl = ~~((imgw + 7) / 8);\n\tlet b64;\n\tif (zlib) {\n\t\tb64 = zlib.deflateSync(buf).toString('base64');\n\t} else {\n\t\tb64 = u8tob64(pako.deflate(buf));\n\t}\n\n\t// Example usage of the return value `rv`:\n\t//\t\t'^GFA,' + rv.length + ',' + rv.length + ',' + rv.rowlen + ',' + rv.z64\n\treturn {\n\t\tlength:\tbuf.length,\t// uncompressed number of bytes\n\t\trowlen:\trowl,\t\t// number of packed bytes per row\n\t\twidth:\timgw,\t\t// rotated image width in pixels\n\t\theight:\timgh,\t\t// rotated image height in pixels\n\t\tz64:\t':Z64:' + b64 + ':' + crc16(b64),\n\t};\n}\n\n// Implements the Alternative Data Compression Scheme as described in the ref manual.\n//\n// `rgba` can be a Uint8Array or Buffer, or an Array of integers between 0 and 255.\n// `width` is the image width, in pixels\n// `opts` is an options object:\n//\t\t`black` is the blackness percent between 1..99, default 50.\n//\t\t`rotate` is one of:\n//\t\t\t'N' no rotation (default)\n//\t\t\t'L' rotate 90 degrees counter-clockwise\n//\t\t\t'R' rotate 90 degrees clockwise\n//\t\t\t'I' rotate 180 degrees (inverted)\n//\t\t\t'B' same as 'L'\nfunction rgbaToACS(rgba, width, opts) {\n\topts = opts || {};\n\twidth = width|0;\n\tif (!width || width < 0) {\n\t\tthrow new Error('Invalid width');\n\t}\n\tlet height = ~~(rgba.length / width / 4);\n\n\t// Create a monochome image, cropped to remove padding.\n\t// The return is a Uint8Array with extra properties width and height.\n\tlet mono = monochrome(rgba, width, height, +opts.black || 50, opts.notrim);\n\n\tlet buf;\n\tswitch (opts.rotate) {\n\tcase 'R': buf = right(mono); break;\n\tcase 'B':\n\tcase 'L': buf = left(mono); break;\n\tcase 'I': buf = invert(mono); break;\n\tdefault:  buf = normal(mono); break;\n\t}\n\n\t// Encode in hex and apply the \"Alternative Data Compression Scheme\"\n    //\n    //      G   H   I   J   K   L   M   N   O   P   Q   R   S   T   U   V   W   X   Y\n    //      1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17  18  19\n    //\n    //      g   h   i   j   k   l   m   n   o   p   q   r   s   t   u   v   w   x   y   z   \n    //     20  40  60  80 100 120 140 160 180 200 220 240 260 280 300 320 340 360 380 400\n    //\n\tlet imgw = buf.width;\n\tlet imgh = buf.height;\n\tlet rowl = ~~((imgw + 7) / 8);\n\n    let hex = '';\n    for (let i = 0, l = buf.length; i < l; i++) {\n        hex += hexmap[buf[i]];\n    }\n    let acs = '';\n    let re = /([0-9a-fA-F])\\1{2,}/g;\n    let match = re.exec(hex);\n    let offset = 0;\n    while (match) {\n        acs += hex.substring(offset, match.index);\n        let l = match[0].length;\n        while (l >= 400) {\n            acs += 'z';\n            l -= 400;\n        }\n        if (l >= 20) {\n            acs += '_ghijklmnopqrstuvwxy'[((l / 20)|0)];\n            l = l % 20;\n        }\n        if (l) {\n            acs += '_GHIJKLMNOPQRSTUVWXY'[l];\n        }\n        acs += match[1];\n        offset = re.lastIndex;\n        match = re.exec(hex);\n    }\n    acs += hex.substr(offset);\n\n\t// Example usage of the return value `rv`:\n\t//\t\t'^GFA,' + rv.length + ',' + rv.length + ',' + rv.rowlen + ',' + rv.acs\n\treturn {\n\t\tlength:\tbuf.length,\t// uncompressed number of bytes\n\t\trowlen:\trowl,\t\t// number of packed bytes per row\n\t\twidth:\timgw,\t\t// rotated image width in pixels\n\t\theight:\timgh,\t\t// rotated image height in pixels\n\t\tacs:\tacs,\n\t};\n}\n\n// Normal, unrotated case\nfunction normal(mono) {\n\tlet width\t= mono.width;\n\tlet height\t= mono.height;\n\n\tlet buf\t = new Uint8Array(~~((width + 7) / 8) * height);\n\tlet idx\t = 0;\t// index into buf\n\tlet byte = 0;\t// current byte of image data\n\tlet bitx = 0;\t// bit index\n\tfor (let i = 0, n = mono.length; i < n; i++) {\n\t\tbyte |= mono[i] << (7 - (bitx++ & 7));\n\n\t\tif (bitx == width || !(bitx & 7)) {\n\t\t\tbuf[idx++] = byte;\n\t\t\tbyte = 0;\n\t\t\tif (bitx == width) {\n\t\t\t\tbitx = 0;\n\t\t\t}\n\t\t}\n\t}\n\tbuf.width  = width;\n\tbuf.height = height;\n\treturn buf;\n}\n\n// Inverted 180 degrees\nfunction invert(mono) {\n\tlet width\t= mono.width;\n\tlet height\t= mono.height;\n\n\tlet buf\t = new Uint8Array(~~((width + 7) / 8) * height);\n\tlet idx\t = 0;\t// index into buf\n\tlet byte = 0;\t// current byte of image data\n\tlet bitx = 0;\t// bit index\n\tfor (let i = mono.length-1; i >= 0; i--) {\n\t\tbyte |= mono[i] << (7 - (bitx++ & 7));\n\n\t\tif (bitx == width || !(bitx & 7)) {\n\t\t\tbuf[idx++] = byte;\n\t\t\tbyte = 0;\n\t\t\tif (bitx == width) {\n\t\t\t\tbitx = 0;\n\t\t\t}\n\t\t}\n\t}\n\tbuf.width  = width;\n\tbuf.height = height;\n\treturn buf;\n}\n\n// Rotate 90 degrees counter-clockwise\nfunction left(mono) {\n\tlet width\t= mono.width;\n\tlet height\t= mono.height;\n\n\tlet buf\t = new Uint8Array(~~((height + 7) / 8) * width);\n\tlet idx\t = 0;\t// index into buf\n\tlet byte = 0;\t// current byte of image data\n\tfor (let x = width - 1; x >= 0; x--) {\n\t\tlet bitx = 0;\t// bit index\n\t\tfor (let y = 0; y < height; y++) {\n\t\t\tbyte |= mono[y * width + x] << (7 - (bitx++ & 7));\n\n\t\t\tif (y == height-1 || !(bitx & 7)) {\n\t\t\t\tbuf[idx++] = byte;\n\t\t\t\tbyte = 0;\n\t\t\t}\n\t\t}\n\t}\n\tbuf.width  = height;\n\tbuf.height = width;\n\treturn buf;\n}\n\n\n// Rotate 90 degrees clockwise\nfunction right(mono) {\n\tlet width\t= mono.width;\n\tlet height\t= mono.height;\n\n\tlet buf\t = new Uint8Array(~~((height + 7) / 8) * width);\n\tlet idx\t = 0;\t// index into buf\n\tlet byte = 0;\t// current byte of image data\n\tfor (let x = 0; x < width; x++) {\n\t\tlet bitx = 0;\t// bit index\n\t\tfor (let y = height - 1; y >= 0; y--) {\n\t\t\tbyte |= mono[y * width + x] << (7 - (bitx++ & 7));\n\n\t\t\tif (y == 0 || !(bitx & 7)) {\n\t\t\t\tbuf[idx++] = byte;\n\t\t\t\tbyte = 0;\n\t\t\t}\n\t\t}\n\t}\n\tbuf.width  = height;\n\tbuf.height = width;\n\treturn buf;\n}\n\n// Convert the RGBA to monochrome, 1-bit-per-byte.  Crops\n// empty space around the edges of the image if !notrim.\nfunction monochrome(rgba, width, height, black, notrim) {\n\t// Convert black from percent to 0..255 value\n\tblack = 255 * black / 100;\n\n\tlet minx, maxx, miny, maxy;\n\tif (notrim) {\n\t\tminx = miny = 0;\n\t\tmaxx = width-1;\n\t\tmaxy = height-1;\n\t} else {\n\t\t// Run through the image and determine bounding box\n\t\tmaxx = maxy = 0;\n\t\tminx = width;\n\t\tminy = height;\n\t\tlet x = 0, y = 0;\n\t\tfor (let i = 0, n = width * height * 4; i < n; i += 4) {\n\t\t\t// Alpha blend with white.\n\t\t\tlet a = rgba[i+3] / 255;\n\t\t\tlet r = rgba[i] * .3 * a + 255 * (1 - a);\n\t\t\tlet g = rgba[i+1] * .59 * a + 255 * (1 - a);\n\t\t\tlet b = rgba[i+2] * .11 * a + 255 * (1 - a);\n\t\t\tlet gray = r + g + b;\n\n\t\t\tif (gray <= black) {\n\t\t\t\tif (minx > x) minx = x;\n\t\t\t\tif (miny > y) miny = y;\n\t\t\t\tif (maxx < x) maxx = x;\n\t\t\t\tif (maxy < y) maxy = y;\n\t\t\t}\n\t\t\tif (++x == width) {\n\t\t\t\tx = 0;\n\t\t\t\ty++;\n\t\t\t}\n\t\t}\n\t}\n\n\t// One more time through the data, this time we create the cropped image.\n\tlet cx = maxx - minx + 1;\n\tlet cy = maxy - miny + 1;\n\tlet buf = new Uint8Array(cx * cy);\n\tlet idx = 0;\n\tfor (y = miny; y <= maxy; y++) {\n\t\tlet i = (y * width + minx) * 4;\n\t\tfor (x = minx; x <= maxx; x++) {\n\t\t\t// Alpha blend with white.\n\t\t\tlet a = rgba[i+3] / 255;\n\t\t\tlet r = rgba[i] * .3 * a + 255 * (1 - a);\n\t\t\tlet g = rgba[i+1] * .59 * a + 255 * (1 - a);\n\t\t\tlet b = rgba[i+2] * .11 * a + 255 * (1 - a);\n\t\t\tlet gray = r + g + b;\n\n\t\t\tbuf[idx++] = gray <= black ? 1 : 0;\n\t\t\ti += 4;\n\t\t}\n\t}\n\n\t// Return the monochrome image\n\tbuf.width  = cx;\n\tbuf.height = cy;\n\treturn buf;\n}\n\n// Cannot use btoa() with Uint8Arrays.  Used only by the browser.\nfunction u8tob64(a) {\n\tlet s = '';\n\tlet i = 0;\n\tfor (let l = a.length & 0xfffffff0; i < l; i += 16) {\n\t\ts += String.fromCharCode(a[i],a[i+1],a[i+2],a[i+3],a[i+4],a[i+5],\n\t\t\t\t\t\t\t\t a[i+6],a[i+7],a[i+8],a[i+9],a[i+10],\n\t\t\t\t\t\t\t\t a[i+11],a[i+12],a[i+13],a[i+14],a[i+15]);\n\t}\n\twhile (i < a.length) {\n\t\ts += String.fromCharCode(a[i++]);\n\t}\n\treturn btoa(s);\n}\n\n// CRC16 used by zebra\nconst crcTable = [\n\t0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5,\n\t0x60c6, 0x70e7, 0x8108, 0x9129, 0xa14a, 0xb16b,\n\t0xc18c, 0xd1ad, 0xe1ce, 0xf1ef, 0x1231, 0x0210,\n\t0x3273, 0x2252, 0x52b5, 0x4294, 0x72f7, 0x62d6,\n\t0x9339, 0x8318, 0xb37b, 0xa35a, 0xd3bd, 0xc39c,\n\t0xf3ff, 0xe3de, 0x2462, 0x3443, 0x0420, 0x1401,\n\t0x64e6, 0x74c7, 0x44a4, 0x5485, 0xa56a, 0xb54b,\n\t0x8528, 0x9509, 0xe5ee, 0xf5cf, 0xc5ac, 0xd58d,\n\t0x3653, 0x2672, 0x1611, 0x0630, 0x76d7, 0x66f6,\n\t0x5695, 0x46b4, 0xb75b, 0xa77a, 0x9719, 0x8738,\n\t0xf7df, 0xe7fe, 0xd79d, 0xc7bc, 0x48c4, 0x58e5,\n\t0x6886, 0x78a7, 0x0840, 0x1861, 0x2802, 0x3823,\n\t0xc9cc, 0xd9ed, 0xe98e, 0xf9af, 0x8948, 0x9969,\n\t0xa90a, 0xb92b, 0x5af5, 0x4ad4, 0x7ab7, 0x6a96,\n\t0x1a71, 0x0a50, 0x3a33, 0x2a12, 0xdbfd, 0xcbdc,\n\t0xfbbf, 0xeb9e, 0x9b79, 0x8b58, 0xbb3b, 0xab1a,\n\t0x6ca6, 0x7c87, 0x4ce4, 0x5cc5, 0x2c22, 0x3c03,\n\t0x0c60, 0x1c41, 0xedae, 0xfd8f, 0xcdec, 0xddcd,\n\t0xad2a, 0xbd0b, 0x8d68, 0x9d49, 0x7e97, 0x6eb6,\n\t0x5ed5, 0x4ef4, 0x3e13, 0x2e32, 0x1e51, 0x0e70,\n\t0xff9f, 0xefbe, 0xdfdd, 0xcffc, 0xbf1b, 0xaf3a,\n\t0x9f59, 0x8f78, 0x9188, 0x81a9, 0xb1ca, 0xa1eb,\n\t0xd10c, 0xc12d, 0xf14e, 0xe16f, 0x1080, 0x00a1,\n\t0x30c2, 0x20e3, 0x5004, 0x4025, 0x7046, 0x6067,\n\t0x83b9, 0x9398, 0xa3fb, 0xb3da, 0xc33d, 0xd31c,\n\t0xe37f, 0xf35e, 0x02b1, 0x1290, 0x22f3, 0x32d2,\n\t0x4235, 0x5214, 0x6277, 0x7256, 0xb5ea, 0xa5cb,\n\t0x95a8, 0x8589, 0xf56e, 0xe54f, 0xd52c, 0xc50d,\n\t0x34e2, 0x24c3, 0x14a0, 0x0481, 0x7466, 0x6447,\n\t0x5424, 0x4405, 0xa7db, 0xb7fa, 0x8799, 0x97b8,\n\t0xe75f, 0xf77e, 0xc71d, 0xd73c, 0x26d3, 0x36f2,\n\t0x0691, 0x16b0, 0x6657, 0x7676, 0x4615, 0x5634,\n\t0xd94c, 0xc96d, 0xf90e, 0xe92f, 0x99c8, 0x89e9,\n\t0xb98a, 0xa9ab, 0x5844, 0x4865, 0x7806, 0x6827,\n\t0x18c0, 0x08e1, 0x3882, 0x28a3, 0xcb7d, 0xdb5c,\n\t0xeb3f, 0xfb1e, 0x8bf9, 0x9bd8, 0xabbb, 0xbb9a,\n\t0x4a75, 0x5a54, 0x6a37, 0x7a16, 0x0af1, 0x1ad0,\n\t0x2ab3, 0x3a92, 0xfd2e, 0xed0f, 0xdd6c, 0xcd4d,\n\t0xbdaa, 0xad8b, 0x9de8, 0x8dc9, 0x7c26, 0x6c07,\n\t0x5c64, 0x4c45, 0x3ca2, 0x2c83, 0x1ce0, 0x0cc1,\n\t0xef1f, 0xff3e, 0xcf5d, 0xdf7c, 0xaf9b, 0xbfba,\n\t0x8fd9, 0x9ff8, 0x6e17, 0x7e36, 0x4e55, 0x5e74,\n\t0x2e93, 0x3eb2, 0x0ed1, 0x1ef0\n];\n\nfunction crc16(s) {\n\t// This is not an accumlating crc routine.  Normally, the acc is intialized to\n\t// 0xffff then inverted on each call.  We just start with 0.\n\tlet crc = 0;\n\tlet j, i;\n\n\tfor (i = 0; i < s.length; i++) {\n\t\tc = s.charCodeAt(i);\n\t\tif (c > 255) {\n\t\t\tthrow new RangeError();\n\t\t}\n\t\tj = (c ^ (crc >> 8)) & 0xFF;\n\t\tcrc = crcTable[j] ^ (crc << 8);\n\t}\n\n\tcrc = (crc & 0xffff).toString(16).toLowerCase();\n\treturn '0000'.substr(crc.length) + crc;\n}\n\nreturn zlib ? { rgbaToZ64, rgbaToACS } : { rgbaToZ64, rgbaToACS, imageToZ64, imageToACS };\n}));\n"]}