Class: QRTools::Decoder

Inherits:
Object
  • Object
show all
Defined in:
lib/qrtools/decoder.rb,
ext/qrtools/qrtools_decoder.c

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.decode(image, size = 25, delta = 10) ⇒ Object



4
5
6
7
8
9
10
# File 'lib/qrtools/decoder.rb', line 4

def decode image, size = 25, delta = 10
  decoder = new(image)
  25.step(3, -2) { |i|
    return decoder if decoder.decode(size, delta)
  }
  decoder
end

.new(image) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
# File 'ext/qrtools/qrtools_decoder.c', line 3

static VALUE new(VALUE klass, VALUE image)
{
  QrDecoderHandle decoder = qr_decoder_open();

  IplImage * src;
  Data_Get_Struct(image, IplImage, src);
  qr_decoder_set_image_buffer(decoder, src);

  VALUE self = Data_Wrap_Struct(klass, NULL, qr_decoder_close, decoder);
  return self;
}

Instance Method Details

#binarized_imageObject



77
78
79
80
81
82
83
84
85
# File 'ext/qrtools/qrtools_decoder.c', line 77

static VALUE binarized_image(VALUE self)
{
  QrDecoderHandle decoder;
  Data_Get_Struct(self, struct QrDecoderHandle, decoder);

  IplImage * bin = cvCloneImage(qr_decoder_get_binarized_image_buffer(decoder));

  return QRTools_Wrap_Image(bin);
}

#bodyObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'ext/qrtools/qrtools_decoder.c', line 44

static VALUE body(VALUE self)
{
  QrDecoderHandle decoder;
  QrCodeHeader * head;

  VALUE _header = rb_funcall(self, rb_intern("header"), 0);
  if(Qnil == _header) return Qnil;

  Data_Get_Struct(self, struct QrDecoderHandle, decoder);
  Data_Get_Struct(_header, QrCodeHeader, head);

  char *buf = calloc(head->byte_size + 1, sizeof(char));
  VALUE b = Qnil;

  if(qr_decoder_get_body(decoder, (unsigned char *)buf, head->byte_size + 1))
    b = rb_str_new(buf, head->byte_size);

  free(buf);
  return b;
}

#coderegion_vertexesObject



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'ext/qrtools/qrtools_decoder.c', line 87

static VALUE coderegion_vertexes(VALUE self)
{
  QrDecoderHandle decoder;
  Data_Get_Struct(self, struct QrDecoderHandle, decoder);

  CvPoint *vertexes = qr_decoder_get_coderegion_vertexes(decoder);
  VALUE cPoint = rb_const_get(cQRToolsImage, rb_intern("Point"));

  VALUE list = rb_ary_new();
  int i = 0;
  for(i = 0; i < 4; i++) {
    CvPoint p = vertexes[i];
    VALUE point = rb_funcall(cPoint, rb_intern("new"), 2, INT2NUM(p.x), INT2NUM(p.y));
    rb_ary_push(list, point);
  }

  return list;
}

#decode(size = 25, delta = 10) ⇒ Object



13
14
15
# File 'lib/qrtools/decoder.rb', line 13

def decode size = 25, delta = 10
  native_decode(size, delta)
end

#headerObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'ext/qrtools/qrtools_decoder.c', line 28

static VALUE header(VALUE self)
{
  QrCodeHeader * header = calloc(1, sizeof(QrCodeHeader));
  QrDecoderHandle decoder;

  Data_Get_Struct(self, struct QrDecoderHandle, decoder);

  qr_decoder_get_header(decoder, header);

  if(header)
    return Data_Wrap_Struct(cQRToolsHeader, NULL, free, header);

  free(header);
  return Qnil;
}

#image=(image) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
# File 'ext/qrtools/qrtools_decoder.c', line 65

static VALUE set_image(VALUE self, VALUE image)
{
  QrDecoderHandle decoder;
  Data_Get_Struct(self, struct QrDecoderHandle, decoder);

  IplImage * src;
  Data_Get_Struct(image, IplImage, src);
  qr_decoder_set_image_buffer(decoder, src);

  return self;
}