#include #include #include #include #include "qrencode.h" #include "Imlib2.h" #include "barcode.h" #include "Evas.h" #include "Ecore.h" #include "Ecore_Evas.h" static int margin = 4; static int size = 3; void write_img(QRcode *code) { Ecore_Evas *ee; Evas_Object *pic; Evas *e; ee = ecore_evas_buffer_new(1, 1); e = ecore_evas_get(ee); if (!e) { fputs("ERROR: could not create ecore evas buffer\n", stderr); return; } evas_image_cache_set(e, 0); evas_font_cache_set(e, 0); pic = evas_object_image_add(e); evas_object_image_file_set(pic, "barcode.png", NULL); evas_object_image_size_set(pic, code->width, code->width); //evas_object_image_alpha_set(pic, 0); evas_object_image_data_set(pic, code->data); //evas_object_image_data_convert(pic, EVAS_COLORSPACE_ARGB8888); evas_object_image_save(pic, "barcode.png", NULL, "quality=100 compress=9"); } static int write_png(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; char* outfile = "barcode.png"; realwidth = (qrcode->width + margin * 2) * size; row = (unsigned char *)malloc((realwidth + 7) / 8); if(row == NULL) { fprintf(stderr, "Failed to allocate memory.\n"); exit(EXIT_FAILURE); } if(outfile[0] == '-' && outfile[1] == '\0') { fp = stdout; } else { fp = fopen(outfile, "wb"); if(fp == NULL) { fprintf(stderr, "Failed to create file: %s\n", outfile); perror(NULL); exit(EXIT_FAILURE); } } png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); if(png_ptr == NULL) { fprintf(stderr, "Failed to initialize PNG writer.\n"); exit(EXIT_FAILURE); } info_ptr = png_create_info_struct(png_ptr); if(info_ptr == NULL) { fprintf(stderr, "Failed to initialize PNG write.\n"); exit(EXIT_FAILURE); } /* if(setjmp(png_jmpbuf(png_ptr))) { png_destroy_write_struct(&png_ptr, &info_ptr); fprintf(stderr, "Failed to write PNG image.\n"); exit(EXIT_FAILURE); }*/ 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); memset(row, 0xff, (realwidth + 7) / 8); for(y=0; ydata; for(y=0; ywidth; y++) { bit = 7; memset(row, 0xff, (realwidth + 7) / 8); q = row; q += margin * size / 8; bit = 7 - (margin * size % 8); for(x=0; xwidth; x++) { for(xx=0; xx