summaryrefslogtreecommitdiffstats
path: root/friendfinder/barcode.c
blob: 50627e523601bb698d18aab9cff10656a9c4e718 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <stdio.h>
#include <assert.h>
#include <string.h>
#include <stdlib.h>

#include "qrencode.h"
#include "Imlib2.h"
#include "barcode.h"

/*
Imlib2 doku:
	http://docs.enlightenment.org/api/imlib2/html/

unter imlib2-1.2.2/src/bin bsp'le durchsehen
*/
void generate_barcode(char* key)
{
	QRcode *code;

	code = QRcode_encodeString(key, 0, QR_ECLEVEL_M, QR_MODE_8, 0);

	/* create image */
	create_img(code);

	//QRcode_free(&code);
}

//TODO: create picture
void create_img(QRcode *code)
{
	printf("create_img 1 \n");
	Imlib_Image img;
	int width = code->width;

	img = imlib_create_image_using_data(width, width, code->data);
	
	if (img == NULL)
	{
		printf("Barcode creation failed \n");
		return;
	}
	else
	{
		//set img to current context
		imlib_context_set_image(img);

		//disable usage of filters
		imlib_context_set_filter(NULL);

		//set color of the context....everything is printed in this color
		//black
		imlib_context_set_color(255, 255, 255, 0);

		imlib_image_set_format("png");

		imlib_save_image("barcode");

		printf("Image written \n");

		imlib_free_image_and_decache();
	}
}