summaryrefslogtreecommitdiff
path: root/lib/Data/QRCode.pm
blob: b7f8c4e62df3e7ab804cecc4cd166713b5f382a7 (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
55
56
57
58
59
package Data::QRCode; 
use strict;
use warnings;
# ABSTRACT: qrcodes in C 
# VERSION 
use Data::QRCode::Inline with => 'Alien::QREncode';
use Data::QRCode::Inline => (
    'DATA',
    autowrap => 1,
    typemaps => 'typemap',
);
 
sub new {
    my ($class$input) = @_;
    my $self = QRcode_encodeInput($input);
    bless $self$class;
    return $self;
}
 
sub data_at {
    my ($self,$x,$y) = @_;
    my $width = $self->width;
    if ($x < 0 or $x >= $width or $y < 0 or $y >= $width) {
        return;
    }
    my $value = _data_at($self,$x,$y);
 
    return {
        color        => $value & 0x01,
        in_data      => $value & 0x02,
        in_format    => $value & 0x04,
        in_version   => $value & 0x08,
        in_timing    => $value & 0x10,
        in_alignment => $value & 0x20,
        in_finder    => $value & 0x40,
        in_misc      => $value & 0x80,
    };
}
 
1;
 
__DATA__
__C__
 
QRcode *QRcode_encodeInput(QRinput *input);
 
void DESTROY(QRcode *qrcode) { QRcode_free(qrcode); }
 
int version(QRcode* self) {
    return self->version;
}
 
int width(QRcode* self) {
    return self->width;
}
 
int _data_at(QRcode* self, int x, int y) {
    return self->data[x+y*self->width];
}