Method: QREncoder::QRCode#data

Defined in:
ext/qrencoder_ext/qrencoder_ext.c

#dataObject

Returns the raw data of the QRcode within a single array of width*width elements. Each item is a byte of data of which only the least significant bit is the pixel. The full use of each bit from Least Significant to Most is as follows

  • 1=black / 0=white

  • data and ecc code area

  • format information

  • version information

  • timing pattern

  • alignment pattern

  • finder pattern and separator

  • non-data modules (format, timing, etc.)

This structure allows the QRcode spec to store multiple types of information within the allocated output buffers, but you usually only care about the pixel color. For those cases, just use the pixels or points methods.



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'ext/qrencoder_ext/qrencoder_ext.c', line 67

static VALUE _data(VALUE self) {
  QRcode *qrcode;
  VALUE out;
  unsigned char *p, b;
  int i, max;

  Data_Get_Struct(self, QRcode, qrcode);
  p = qrcode->data;
  max = qrcode->width * qrcode->width;
  out = rb_ary_new2(max);

  for (i=0; i < max; i++) {
    b = *p;
    rb_ary_push(out, INT2FIX(b));
    p++;
  }

  return out;
}