summaryrefslogtreecommitdiffstats
path: root/friendfinder/barcode.c
diff options
context:
space:
mode:
authorpatrick2010-01-20 15:55:20 +0100
committerpatrick2010-01-20 15:55:20 +0100
commit1ca34dfd0430db7b50f2a12f27b2baebce5f5266 (patch)
tree3d51ec6dadf508aff9eb24adeaff9fcb8907e42e /friendfinder/barcode.c
parentadditional .tex files (diff)
downloadfriendfinder-1ca34dfd0430db7b50f2a12f27b2baebce5f5266.tar.gz
friendfinder-1ca34dfd0430db7b50f2a12f27b2baebce5f5266.tar.xz
friendfinder-1ca34dfd0430db7b50f2a12f27b2baebce5f5266.zip
tex data
Diffstat (limited to 'friendfinder/barcode.c')
-rw-r--r--friendfinder/barcode.c61
1 files changed, 51 insertions, 10 deletions
diff --git a/friendfinder/barcode.c b/friendfinder/barcode.c
index 555205a..8573f80 100644
--- a/friendfinder/barcode.c
+++ b/friendfinder/barcode.c
@@ -1,21 +1,62 @@
#include <stdio.h>
+#include <assert.h>
+#include <string.h>
+#include <stdlib.h>
-#include "qrencode.h"
+#include "dmtx.h"
+#include "file_read.h"
+void generate_barcode(unsigned char* key)
+{
+/*
+ 1. Call dmtxEncodeCreate()
+ Creates a new DmtxEncode structure and initializes the encoding pro-
+ cess. This function must be called before using the other encoding
+ functions.
-void generate_barcode(char* key)
-{
- QRcode *code;
+ 2. Call dmtxEncodeSetProp() [optional]
+
+ Allows you to control specific aspects of the encoding behavior. If
+ this function is not called, libdmtx will use the defaults set by dmtx-
+ EncodeCreate() above. The complementary function, dmtxEncodeGetProp(),
+ allows you to detect the current settings.
+
+ 3. Call either dmtxEncodeDataMatrix() or dmtxEncodeDataMosaic()
+
+ Call one of these functions to generate an image of the desired barcode
+ type. Your program is responsible for dispatching the resulting output
+ to its destination, whether that means displaying it on a screen, writ-
+ ing an image file, copying it elsewhere, etc...
+
+ 4. Call dmtxEncodeDestroy()
+
+ Releases memory allocated during the encoding process.
+*/
+ size_t width, height, bytesPerPixel;
+ unsigned char *pxl;
+ DmtxEncode *enc;
+ DmtxImage *img;
- code = QRcode_encodeString(key, 0, QR_ECLEVEL_M, QR_MODE_8, 1);
+ enc = dmtxEncodeCreate();
+ assert(enc != NULL);
+ dmtxEncodeDataMatrix(enc, strlen(key), key);
+
+ width = dmtxImageGetProp(enc->image, DmtxPropWidth);
+ height = dmtxImageGetProp(enc->image, DmtxPropHeight);
+
+ pxl = (unsigned char *)malloc(width * height * bytesPerPixel);
+ assert(pxl != NULL);
+ memcpy(pxl, enc->image->pxl, width * height * bytesPerPixel);
+
+ img = dmtxImageCreate(pxl, width, height, DmtxPack24bppRGB);
+ assert(img != NULL);
+ /* write to png file */
- QRinput_free(code);
-}
-
-void generate_png(QRcode *code)
-{
+ dmtxEncodeDestroy(&enc);
+ dmtxImageDestroy(&img);
}
+