/* * Linux VeeJay * * Copyright(C)2015 Niels Elburg * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License , or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software */ /* * qrencode - QR Code encoder * * Copyright (C) 2006-2012 Kentaro Fukuchi * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ /* least effort, take one of kentaro's examples, slightly modify it and write qr code to .png file */ #include #include #include #include #include #include #include #include #include #include #include static int qrcode_open(const char *filename, const char *data, const int len); #ifdef HAVE_QRENCODE #include #include static int qrwrap_writePNG(const char *outfile, QRcode *qrcode) { static FILE *fp; png_structp png_ptr; png_infop info_ptr; unsigned char *row, *p, *q; int x, y, xx, yy, bit; int realwidth; const int margin = 0; const int size = 8; const int width = qrcode->width; realwidth = (width + margin * 2) * size; row = (unsigned char *)vj_malloc((realwidth + 7) / 8); if(row == NULL) { return 0; } fp = fopen(outfile, "wb"); if(fp == NULL) { veejay_msg(VEEJAY_MSG_ERROR, "Unable to write QR code to file:%s", outfile); return 0; } png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); if(png_ptr == NULL) { fclose(fp); return 0; } info_ptr = png_create_info_struct(png_ptr); if(info_ptr == NULL) { fclose(fp); return 0; } if(setjmp(png_jmpbuf(png_ptr))) { png_destroy_write_struct(&png_ptr, &info_ptr); fclose(fp); return 0; } png_init_io(png_ptr, fp); png_set_IHDR(png_ptr, info_ptr, realwidth, realwidth, 1, PNG_COLOR_TYPE_GRAY, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); png_write_info(png_ptr, info_ptr); /* top margin */ veejay_memset(row, 0xff, (realwidth + 7) / 8); for(y=0; ydata; for(y=0; ywidth - qr->width - 10; int offset_y = 10; int x,y; int w = out->width; uint8_t *Y = out->data[0]; uint8_t *U = out->data[1]; uint8_t *V = out->data[2]; const uint8_t *qY = qr->data[0]; if( offset_x < 0 ) offset_x = 0; for(y = 0; y < qr->height; y ++ ) { for( x = 0; x < qr->width; x ++ ) { Y[ ((y+offset_y) * w + x + offset_x) ] = qY[ (y*qr->width+x) ]; U[ ((y+offset_y) * w + x + offset_x) ] = 128; V[ ((y+offset_y) * w + x + offset_x) ] = 128; } } } } void qrwrap_free() { if( pic_ != NULL ) { vj_picture_cleanup( pic_ ); } }