void QRcode::drawQRCode(int16_t xOffset, int16_t yOffset, String message) { // create QR code message.toCharArray((char *)strinbuf,260); qrencode(); // print QR Code for (byte x = 0; x < WD; x+=2) { for (byte y = 0; y < WD; y++) { if ( QRBIT(x,y) && QRBIT((x+1),y)) { // black square on top of black square render(x * scale + xOffset, y * scale + yOffset, foregroundColor); render((x+1) * scale + xOffset, y * scale + yOffset, foregroundColor); } if (!QRBIT(x,y) && QRBIT((x+1),y)) { // white square on top of black square render(x * scale + xOffset, y * scale + yOffset, backgroundColor); render((x+1) * scale + xOffset, y * scale + yOffset, foregroundColor); } if ( QRBIT(x,y) && !QRBIT((x+1),y)) { // black square on top of white square render(x * scale + xOffset, y * scale + yOffset, foregroundColor); render((x+1) * scale + xOffset, y * scale + yOffset, backgroundColor); } if (!QRBIT(x,y) && !QRBIT((x+1),y)) { // white square on top of white square render(x * scale + xOffset, y * scale + yOffset, backgroundColor); render((x+1) * scale + xOffset, y * scale + yOffset, backgroundColor); } } Serial.println(); } }
int main(int argc, char *argv[]) { unsigned char x, y, v = 0, l = 1; char *c; unsigned width, height, j, k; int argp = 0; if( argc < 2 ) { printf( "Usage:\n\nqrjpeg [-v VERS_1_40] [-l ECCLVL_1_4] \"text to encode\" >output.jpg\n" ); printf( "version defaults to auto, same as \"-v 0\"\necc level defaults to 1\n" ); return 1; } c = "Test Message"; while( ++argp < argc ) { if( argv[argp][0] == '-' ) { if( argv[argp][1] == 'v' ) v = atoi( argv[++argp]); else if( argv[argp][1] == 'l' ) l = atoi( argv[++argp]); else { printf( "Usage:\n\nqrjpeg [-v VERS_1_40] [-l ECCLVL_1_4] \"text to encode\" >output.jpg\n" ); printf( "version defaults to auto, same as \"-v 0\"\necc level defaults to 1\n" ); return 1; } } else c = argv[argp]; } if( v > 40 ) { fprintf( stderr, "Bad version (size) parameter (should be 0 (auto) to 40)\n" ); return -1; } if( l < 1 || l > 4 ) { fprintf( stderr, "Bad ECC level parameter (should be 1 to 4)\n" ); return -1; } if( v ) k = initecc(l, v); else k = initeccsize( l, strlen(c)); initframe(); strcpy((char *)strinbuf, c ); qrencode(); width = height = WD+8; // set height and width in header jpeg0[0x5e] = width >> 5; jpeg0[0x5f] = width << 3; jpeg0[0x60] = width >> 5; jpeg0[0x61] = width << 3; // write out header fwrite(jpeg0, 1, sizeof(jpeg0), stdout); // put half full scale, 3e for white, 40 for black putchar(0x40); for (j = 0; j < width * 4 + 3; j++) putchar(0x80); for (y = 0; y < WD; y++) { k = 0; for (x = 0; x < WD; x++) { j = QRBIT(x, y); if (k == j) { putchar(0x80); // code for no change continue; } putchar(j ? 0 : 0x7e); // full scale flip k = j; } if (k != 0) putchar(0x7e); else putchar(0x80); for (j = 0; j < 7; j++) putchar(0x80); } for (j = 0; j < width * 4 - 4; j++) putchar(0x80); putchar(0x80); // one last for EOF putchar(0xFF); // end marker putchar(0xd9); return 0; }