Ejemplo n.º 1
0
static int RSblock_init(RSblock *blocks, int spec[5], unsigned char *data, unsigned char *ecc)
{
  int i;
  RSblock *block;
  unsigned char *dp, *ep;
  RS *rs;
  int el, dl;

  dl = QRspec_rsDataCodes1(spec);
  el = QRspec_rsEccCodes1(spec);
  rs = init_rs(8, 0x11d, 0, 1, el, 255 - dl - el);
  if(rs == NULL) return -1;

  block = blocks;
  dp = data;
  ep = ecc;
  for(i=0; i<QRspec_rsBlockNum1(spec); i++) {
    RSblock_initBlock(block, dl, dp, el, ep, rs);
    dp += dl;
    ep += el;
    block++;
  }

  if(QRspec_rsBlockNum2(spec) == 0) return 0;

  dl = QRspec_rsDataCodes2(spec);
  el = QRspec_rsEccCodes2(spec);
  rs = init_rs(8, 0x11d, 0, 1, el, 255 - dl - el);
  if(rs == NULL) return -1;
  for(i=0; i<QRspec_rsBlockNum2(spec); i++) {
    RSblock_initBlock(block, dl, dp, el, ep, rs);
    dp += dl;
    ep += el;
    block++;
  }

  return 0;
}
Ejemplo n.º 2
0
__STATIC MQRRawCode *MQRraw_new(QRinput *input)
{
	MQRRawCode *raw;
	RS *rs;

	raw = (MQRRawCode *)malloc(sizeof(MQRRawCode));
	if(raw == NULL) return NULL;

	raw->version = input->version;
	raw->dataLength = MQRspec_getDataLength(input->version, input->level);
	raw->eccLength = MQRspec_getECCLength(input->version, input->level);
	raw->oddbits = raw->dataLength * 8 - MQRspec_getDataLengthBit(input->version, input->level);
	raw->datacode = QRinput_getByteStream(input);
	if(raw->datacode == NULL) {
		free(raw);
		return NULL;
	}
	raw->ecccode = (unsigned char *)malloc(raw->eccLength);
	if(raw->ecccode == NULL) {
		free(raw->datacode);
		free(raw);
		return NULL;
	}

	raw->rsblock = (RSblock *)calloc(1, sizeof(RSblock));
	if(raw->rsblock == NULL) {
		MQRraw_free(raw);
		return NULL;
	}

	rs = init_rs(8, 0x11d, 0, 1, raw->eccLength, 255 - raw->dataLength - raw->eccLength);
	if(rs == NULL) {
		MQRraw_free(raw);
		return NULL;
	}

	RSblock_initBlock(raw->rsblock, raw->dataLength, raw->datacode, raw->eccLength, raw->ecccode, rs);

	raw->count = 0;

	return raw;
}