summaryrefslogtreecommitdiffstats
path: root/friendfinder
diff options
context:
space:
mode:
authorPatrick Hornecker2010-02-05 11:39:08 +0100
committerPatrick Hornecker2010-02-05 11:39:08 +0100
commit8da0a26e7549b53803f6eec2d97091d9b5879096 (patch)
tree555a7f29d4b6460efdc13154024abba5f993f932 /friendfinder
parenttex source and barcode improvements (diff)
downloadfriendfinder-8da0a26e7549b53803f6eec2d97091d9b5879096.tar.gz
friendfinder-8da0a26e7549b53803f6eec2d97091d9b5879096.tar.xz
friendfinder-8da0a26e7549b53803f6eec2d97091d9b5879096.zip
barcode working with libpng version < 1.2.42
Diffstat (limited to 'friendfinder')
-rw-r--r--friendfinder/Makefile.inc2
-rw-r--r--friendfinder/barcode.c135
-rw-r--r--friendfinder/barcode.pngbin524 -> 295 bytes
-rwxr-xr-xfriendfinder/guibin186893 -> 197193 bytes
4 files changed, 106 insertions, 31 deletions
diff --git a/friendfinder/Makefile.inc b/friendfinder/Makefile.inc
index 75b248c..cd381c4 100644
--- a/friendfinder/Makefile.inc
+++ b/friendfinder/Makefile.inc
@@ -4,7 +4,7 @@
CFLAGS = -g -Wall -rdynamic -std=c99
INCLUDES = -I../include
-LIBS = -ledje -lecore -levas -lelementary -lircclient -lcrypto -lproj -lpthread -lqrencode
+LIBS = -ledje -lecore -levas -lelementary -lircclient -lcrypto -lproj -lpthread -lqrencode -lpng
###########
diff --git a/friendfinder/barcode.c b/friendfinder/barcode.c
index 21915db..99b6886 100644
--- a/friendfinder/barcode.c
+++ b/friendfinder/barcode.c
@@ -2,6 +2,7 @@
#include <string.h>
#include <stdlib.h>
+#include <png.h>
#include "qrencode.h"
#include "Imlib2.h"
#include "barcode.h"
@@ -9,6 +10,9 @@
#include "Ecore.h"
#include "Ecore_Evas.h"
+static int margin = 4;
+static int size = 3;
+
void write_img(QRcode *code)
{
Ecore_Evas *ee;
@@ -33,48 +37,119 @@ void write_img(QRcode *code)
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_data_convert(pic, EVAS_COLORSPACE_ARGB8888);
evas_object_image_save(pic, "barcode.png", NULL, "quality=100 compress=9");
-// return pic;
}
-void generate_barcode(char* key)
+static int write_png(QRcode *qrcode)
{
- QRcode *code;
-
- code = QRcode_encodeString8bit(key, 0, QR_ECLEVEL_M);//, QR_MODE_8, 1);
+ 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; y<margin * size; y++) {
+ png_write_row(png_ptr, row);
+ }
+
+ p = qrcode->data;
+ for(y=0; y<qrcode->width; y++) {
+ bit = 7;
+ memset(row, 0xff, (realwidth + 7) / 8);
+ q = row;
+ q += margin * size / 8;
+ bit = 7 - (margin * size % 8);
+ for(x=0; x<qrcode->width; x++) {
+ for(xx=0; xx<size; xx++) {
+ *q ^= (*p & 1) << bit;
+ bit--;
+ if(bit < 0) {
+ q++;
+ bit = 7;
+ }
+ }
+ p++;
+ }
+ for(yy=0; yy<size; yy++) {
+ png_write_row(png_ptr, row);
+ }
+ }
+
+ memset(row, 0xff, (realwidth + 7) / 8);
+ for(y=0; y<margin * size; y++) {
+ png_write_row(png_ptr, row);
+ }
- write_img(code);
+ png_write_end(png_ptr, info_ptr);
+ png_destroy_write_struct(&png_ptr, &info_ptr);
- QRcode_free(code);
-/*
- Evas_Object *pic;
- size_t width, height, bytesPerPixel;
- unsigned char *pxl;
- DmtxEncode *enc;
+ fclose(fp);
+ free(row);
- enc = dmtxEncodeCreate();
- if (enc != NULL);
- dmtxEncodeDataMatrix(enc, strlen(key), key);
+ return 0;
+}
- width = dmtxImageGetProp(enc->image, DmtxPropWidth);
- height = dmtxImageGetProp(enc->image, DmtxPropHeight);
- bytesPerPixel = dmtxImageGetProp(enc->image, DmtxPropBytesPerPixel);
+void generate_barcode(char* key)
+{
+ QRcode *code;
- pxl = (unsigned char *)malloc(width * height * bytesPerPixel);
-
- if(pxl != NULL);
- memcpy(pxl, enc->image->pxl, width * height * bytesPerPixel);
+ code = QRcode_encodeString(key, 0, QR_ECLEVEL_M, QR_MODE_8, 1);
- dmtxImageSetProp(enc->image, DmtxPropImageFlip, DmtxFlipNone);
-
- write_img(enc, win);
-
- if (pic != NULL)
- printf("barcode created...\n"); */
+ write_png(code);
-// return pic;
+ QRcode_free(code);
}
diff --git a/friendfinder/barcode.png b/friendfinder/barcode.png
index 17a47e7..1b161ff 100644
--- a/friendfinder/barcode.png
+++ b/friendfinder/barcode.png
Binary files differ
diff --git a/friendfinder/gui b/friendfinder/gui
index 2a3c03f..27e0594 100755
--- a/friendfinder/gui
+++ b/friendfinder/gui
Binary files differ