示例#1
0
int main (int argc, const char *argv[])
{
  processor = zbar_processor_create(0);
  assert(processor);
  if(zbar_processor_init(processor, NULL, 0)) {
      zbar_processor_error_spew(processor, 0);
      return(1);
  }

  zbar_image_t *zimage = zbar_image_create();
  assert(zimage);
  zbar_image_set_format(zimage, *(unsigned long*)"Y800");

  int width = js_get_width();
  int height = js_get_height();
  zbar_image_set_size(zimage, width, height);

  size_t bloblen = width * height;
  unsigned char *blob = malloc(bloblen);
  zbar_image_set_data(zimage, blob, bloblen, zbar_image_free_data);

  js_read_image(blob, bloblen);

  zbar_process_image(processor, zimage);

  // print results
  const zbar_symbol_t *sym = zbar_image_first_symbol(zimage);
  for(; sym; sym = zbar_symbol_next(sym)) {
      zbar_symbol_type_t typ = zbar_symbol_get_type(sym);
      if(typ == ZBAR_PARTIAL)
          continue;
      js_output_result(zbar_get_symbol_name(typ),
                       zbar_get_addon_name(typ),
                       zbar_symbol_get_data(sym));
  }

  zbar_image_destroy(zimage);

  if(zbar_processor_is_visible(processor)) {
     zbar_processor_user_wait(processor, -1);
  }

  zbar_processor_destroy(processor);

  return 0;
}
示例#2
0
static PyObject*
processor_get_bool (zbarProcessor *self,
                    void *closure)
{
    int val;
    switch((intptr_t)closure) {
    case 0:
        val = zbar_processor_is_visible(self->zproc);
        break;
    default:
        assert(0);
        return(NULL);
    }
    if(val < 0)
        return(zbarErr_Set((PyObject*)self));
    return(PyBool_FromLong(val));
}
static int scan_image (IplImage * image)
{
  if(exit_code == 3)
    return(-1);

  int found = 0;
  if(exit_code == 3)
    return(-1);
      
  zbar_image_t *zimage = zbar_image_create();
  assert(zimage);
  zbar_image_set_format(zimage, *(unsigned long*)"Y800");
    
    
  int width = image->width;
  int height = image->height;
  zbar_image_set_size(zimage, width, height);
    
  // extract grayscale image pixels
  // FIXME color!! ...preserve most color w/422P
  // (but only if it's a color image)
  size_t bloblen = width * height;
  unsigned char *blob = malloc(bloblen);
  zbar_image_set_data(zimage, blob, bloblen, zbar_image_free_data);
      
      
  memcpy(blob, image->imageData, image->imageSize); 
      
  if(xmllvl == 1) 
  {
    xmllvl++;
    //printf("<source href='%s'>\n", filename);
  }
      
  zbar_process_image(processor, zimage);
      
  // output result data
  const zbar_symbol_t *sym = zbar_image_first_symbol(zimage);
  for(; sym; sym = zbar_symbol_next(sym)) 
  {
    zbar_symbol_type_t typ = zbar_symbol_get_type(sym);
    if(typ == ZBAR_PARTIAL)
      continue;
    else if(!xmllvl)
      printf("%s%s:%s\n",
             zbar_get_symbol_name(typ),
             zbar_get_addon_name(typ),
             zbar_symbol_get_data(sym));
    else if(xmllvl < 0)
      printf("%s\n", zbar_symbol_get_data(sym));
    else {
      if(xmllvl < 3) 
      {
        xmllvl++;
        //printf("<index num='%u'>\n", seq);
      }
      zbar_symbol_xml(sym, &xmlbuf, &xmlbuflen);
      printf("%s\n", xmlbuf);
    }
    found++;
    num_symbols++;
  }
  if(xmllvl > 2) 
  {
    xmllvl--;
    printf("</index>\n");
  }
  fflush(stdout);
      
  zbar_image_destroy(zimage);
      
  num_images++;
  if(zbar_processor_is_visible(processor)) 
  {
    printf("waiting for q\n");
    int rc = zbar_processor_user_wait(processor, -1);
    if(rc < 0 || rc == 'q' || rc == 'Q')
      exit_code = 3;
  }
  //}
    
  if(xmllvl > 1) 
  {
    xmllvl--;
    printf("</source>\n");
  }
    
  if(!found)
    notfound++;
    
  //DestroyMagickWand(images);
  return(0);
}//scan_image
示例#4
0
static int scan_image (const char *filename)
{
    if(exit_code == 3)
        return(-1);

    int found = 0;
    MagickWand *images = NewMagickWand();
    if(!MagickReadImage(images, filename) && dump_error(images))
        return(-1);

    unsigned seq, n = MagickGetNumberImages(images);
    for(seq = 0; seq < n; seq++) {
        if(exit_code == 3)
            return(-1);

        if(!MagickSetIteratorIndex(images, seq) && dump_error(images))
            return(-1);

        zbar_image_t *zimage = zbar_image_create();
        assert(zimage);
        zbar_image_set_format(zimage, zbar_fourcc('Y','8','0','0'));

        int width = MagickGetImageWidth(images);
        int height = MagickGetImageHeight(images);
        zbar_image_set_size(zimage, width, height);

        // extract grayscale image pixels
        // FIXME color!! ...preserve most color w/422P
        // (but only if it's a color image)
        size_t bloblen = width * height;
        unsigned char *blob = malloc(bloblen);
        zbar_image_set_data(zimage, blob, bloblen, zbar_image_free_data);

        if(!MagickExportImagePixels(images, 0, 0, width, height,
                                    "I", CharPixel, blob))
            return(-1);

        if(xmllvl == 1) {
            xmllvl++;
            printf("<source href='%s'>\n", filename);
        }

        zbar_process_image(processor, zimage);

        // output result data
        const zbar_symbol_t *sym = zbar_image_first_symbol(zimage);
        for(; sym; sym = zbar_symbol_next(sym)) {
            zbar_symbol_type_t typ = zbar_symbol_get_type(sym);
            unsigned len = zbar_symbol_get_data_length(sym);
            if(typ == ZBAR_PARTIAL)
                continue;
            else if(xmllvl <= 0) {
                if(!xmllvl)
                    printf("%s:", zbar_get_symbol_name(typ));
                if(len &&
                   fwrite(zbar_symbol_get_data(sym), len, 1, stdout) != 1) {
                    exit_code = 1;
                    return(-1);
                }
            }
            else {
                if(xmllvl < 3) {
                    xmllvl++;
                    printf("<index num='%u'>\n", seq);
                }
                zbar_symbol_xml(sym, &xmlbuf, &xmlbuflen);
                if(fwrite(xmlbuf, xmlbuflen, 1, stdout) != 1) {
                    exit_code = 1;
                    return(-1);
                }
            }
            printf("\n");
            found++;
            num_symbols++;
        }
        if(xmllvl > 2) {
            xmllvl--;
            printf("</index>\n");
        }
        fflush(stdout);

        zbar_image_destroy(zimage);

        num_images++;
        if(zbar_processor_is_visible(processor)) {
            int rc = zbar_processor_user_wait(processor, -1);
            if(rc < 0 || rc == 'q' || rc == 'Q')
                exit_code = 3;
        }
    }

    if(xmllvl > 1) {
        xmllvl--;
        printf("</source>\n");
    }

    if(!found)
        notfound++;

    DestroyMagickWand(images);
    return(0);
}