Example #1
0
int qransi (const char *encodable)
{
  int padding = 2;
  QRecLevel level = QR_ECLEVEL_L;
  int x, y, width;
  unsigned char *data;
  QRcode * code = QRcode_encodeString(encodable, 0, level, QR_MODE_8, 1);
  if (!code)
    return 1;
  width = code->width;
  data = code->data;
  whiteRow(padding, width);
  for (y=0; y<width; y++) {
    pixels(WHITE, padding);
    for (x=0; x<width; x++, data++)
      pixels(*data&1?BLACK:WHITE, 1); 
    pixels(WHITE, padding);
    printf("\n");
  }
  whiteRow(padding, width);
  QRcode_free(code);
  return 0;
}
Example #2
0
fields_t* limits(filtro_gestos_in_imagen_t* image)
{

  int left,right,up,down;
  int arriba,izq,i,l,cont,punt,posi,media,dif,jumps;
  fields_t* fields= (fields_t*)malloc(sizeof(fields_t));
  int* caracXfila;
  fields->cimaCI=fields->cimaCD=fields->cimaFT=fields->cimaFD=0;
  arriba=izq=cont=punt=posi=media=jumps=0;
  for(i=1; i<image->m_alto-1; i++)
    if(whiteRow(i,0,image->m_ancho*image->m_bytes,image)){
      if(!whiteRow(i-1,0,image->m_ancho*image->m_bytes,image) && arriba){
	fields->filasDown[fields->cimaFD]=i; fields->cimaFD++; arriba=0;
      }
      if(!whiteRow(i+1,0,image->m_ancho*image->m_bytes,image)){
	fields->filasTop[fields->cimaFT]=i; fields->cimaFT++; arriba=1;
      }
    }
  caracXfila= (int*)malloc(sizeof(int)*fields->cimaFT);

  for(l=0; l<fields->cimaFT; l++){
    for(i=image->m_bytes; i<(image->m_ancho-1)*image->m_bytes; i+=image->m_bytes){
      if(whiteColumn(i,fields->filasTop[l],fields->filasDown[l],image)){
	if(!whiteColumn(i-image->m_bytes,fields->filasTop[l],fields->filasDown[l],image) && izq){
	  fields->columnasIzq[fields->cimaCI]=i; fields->cimaCI++; izq=0;
	}
	if(!whiteColumn(i+image->m_bytes,fields->filasTop[l],fields->filasDown[l],image)){
	  fields->columnasDcha[fields->cimaCD]=i; fields->cimaCD++; izq=1;
	}
      }
    }
    caracXfila[l] = (l>0) ? fields->cimaCI-caracXfila[l-1]: fields->cimaCI;
  }

  fields->ptosSI= (coord_t**)malloc(sizeof(coord_t*)*fields->cimaCD);
  for(i=0; i<fields->cimaCD; i++){
    if(punt==caracXfila[posi]){punt=0; posi++;}
    fields->ptosSI[cont]= (coord_t*)malloc(sizeof(coord_t));
    fields->ptosSI[cont]->m_x= fields->columnasDcha[i];
    fields->ptosSI[cont]->m_y= fields->filasTop[posi];
    cont++; punt++;
  }

  fields->ptosID= (coord_t**)malloc(sizeof(coord_t*)*fields->cimaCI);
  cont=punt=posi=0;
  for(i=0; i<fields->cimaCI; i++){
    if(punt==caracXfila[posi]){punt=0; posi++;}
    fields->ptosID[cont]= (coord_t*)malloc(sizeof(coord_t));
    fields->ptosID[cont]->m_x= fields->columnasIzq[i];
    fields->ptosID[cont]->m_y= fields->filasDown[posi];
    cont++; punt++;
  }
  free(caracXfila);

  //Saca espacios
  if(fields->cimaCI > 0) {
    fields->espacios= (int*)malloc(sizeof(int)*fields->cimaCI-1);
    for(i=0; i<fields->cimaCI-1; i++)fields->espacios[i]=0;
    for(i=0; i<fields->cimaCI-1; i++){
      dif= fields->ptosSI[i+1]->m_x-fields->ptosID[i]->m_x;
      if(dif<0){fields->espacios[i]=1;jumps++;}else media+=dif;
    }
    if(fields->cimaCI-jumps>0) {
      media/=fields->cimaCI-jumps;
    }
    else {
      media=0;
    }
    for(i=0; i<fields->cimaCI-1; i++){
      dif= fields->ptosSI[i+1]->m_x-fields->ptosID[i]->m_x;
      if(dif>media*FACTOR)fields->espacios[i]=1;
    }
  }
  else {
    fields->espacios = 0;
  }

  // Ajustar

  for(i=0; i<fields->cimaCI; i++){

    int upi,downi,lefti,righti;
    
    left = fields->ptosSI[i]->m_x; 
    right=fields->ptosID[i]->m_x;
    down = fields->ptosID[i]->m_y;
    up = fields->ptosSI[i]->m_y;   

    upi = downi = lefti = righti = 0;

    while(!upi) {
      !whiteRow(up,left,right,image) ? upi=1: up++;
    }
    while(!downi) {
      !whiteRow(down,left,right,image) ? downi=1: down--;
    }
    while(!lefti) {
      // WARNING: añado esto porque
      // si no, se queda colgado aquí
      if(left >= image->m_ancho) {
	break;
      }
      !whiteColumn(left,up,down,image) ? lefti=1: left++;
    }
    while(!righti) {
      // WARNING: lo mismo aquí
      // esto debería estar programado de otra manera
      if(right == 0) {
	break;
      }

      !whiteColumn(right,up,down,image) ? righti=1: right--;
    }

    fields->ptosID[i]->m_x = right;
    fields->ptosSI[i]->m_x = left;
    fields->ptosSI[i]->m_y = up;
    fields->ptosID[i]->m_y = down;
  }

  return fields;
}