summaryrefslogtreecommitdiff
path: root/lib/Data/QRCode/XS.pm
blob: f46cba6d2e31df63fe66ca92ad7d24a5cce9f3b2 (plain)
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
package Data::QRCode::XS; 
use strict;
use warnings;
# ABSTRACT: qrcodes in C 
# VERSION 
use Alien::QREncode;
use Data::QRCode::XS::Inline => ( );
 
1;
 
__DATA__
 
__C__
 
#include "qrencode.h" 
 
int ECLEVEL_L() { return QR_ECLEVEL_L; }
int ECLEVEL_M() { return QR_ECLEVEL_M; }
int ECLEVEL_Q() { return QR_ECLEVEL_Q; }
int ECLEVEL_H() { return QR_ECLEVEL_H; }
 
SV* _build(const char* class, SV* data, int level, int version ) {
    unsigned char * str;
    STRLEN len;
    SV * qrsv; SV* self;
    QRcode* qr_code;
 
    str = SvPVutf8(data,len);
    qr_code = QRcode_encodeData(len,str,version,(QRecLevel)level);
    qrsv = newSViv((IV)qr_code);
    self = newRV_noinc(qrsv);
    sv_bless(self, gv_stashpv(class, GV_ADD));
    SvREADONLY_on(qrsv);
 
    return self;
}
 
int version(SV* self) {
    return ((QRcode*)SvIV(SvRV(self)))->version;
}
 
int width(SV* self) {
    return ((QRcode*)SvIV(SvRV(self)))->width;
}
 
void DESTROY(SV* self) {
    QRcode* qr_code = (QRcode*)SvIV(SvRV(self));
    QRcode_free(qr_code);
}
 
int _data_at(SV* self, int x, int y) {
    QRcode* qr_code = (QRcode*)SvIV(SvRV(self));
    return qr_code->data[x+y*qr_code->width];
}