[sane-devel] problem setting custom resolution

aneesh m raj aneeshmraj at hotmail.com
Tue Sep 23 06:04:13 BST 2003


Hi all,
Im trying to read the scanned data using sane form UMAX 2000p but when i set a custom resolution the read is causing some problem. This is my code.

int print_data(SANE_Handle devHnd)
{

  SANE_Int MAX_LEN = 4048;
  char filepnm[INIT_SIZE];
  int size = INIT_SIZE, ret = 0;
  int first_frame =1;
  SANE_Parameters parm;
  SANE_Int len = 0; 
  FILE* fp = NULL;
  char *name = malloc(INIT_SIZE);
  char *value = malloc(INIT_SIZE);
  SANE_Byte* buffer = (SANE_Byte*)malloc(sizeof(SANE_Byte) * MAX_LEN);
 
 
   strcpy(filepnm,"images//out.pnm");
  fp = fopen(filepnm,"wb+");
  
 
  strcpy(name,"State");
  
  if(fp == NULL)
   {
      status = SANE_STATUS_IO_ERROR;
      set_error(act);
      free(buffer);
      free(name);
      free(value);
      ret = 1;
       printf("File null...\n");
       return ret;
   }
  do
  {
   if((status = sane_get_parameters (devHnd, &parm)) != SANE_STATUS_GOOD)
   {
  
     set_error(act);
    printf("get parameters failed...\n");
    free(buffer);
    free(name);
    free(value);
    fclose(fp);
    ret = 1;
    return ret;

   }

  if(first_frame)
  {
    printf("Printing scanned data...\n\n");
    write_pnm_header (parm.format,fp,  parm.pixels_per_line,
         parm.lines, parm.depth);


  }
  
  do
  {
    
    status = read_data(devHnd, buffer, MAX_LEN, &len);
    if(status == SANE_STATUS_GOOD )
     {
    
      fwrite(buffer,len,sizeof(SANE_Byte),fp);
     }
    else if(status != SANE_STATUS_EOF)
    {
  
      set_error(act); 
      printf("Reading scanned data failed...\n");
    }
    free(buffer);
    buffer = (SANE_Byte*)malloc(sizeof(SANE_Byte) * MAX_LEN);

  }while( status == SANE_STATUS_GOOD && len != 0);

  if( status == SANE_STATUS_EOF)
  {
    pthread_cond_signal(&pollevent);
    printf("Reading complete...\n"); 
  }
  else 
  {
    pthread_cond_signal(&pollevent);
    ret = 1;
    set_error(act); 
    printf("Reason: %s",(char*)sane_strstatus(status)); 
  }

   first_frame = 0;

  }while(!parm.last_frame);

  free(buffer);
  free(name);
  free(value);
  fclose(fp);

 return ret;
}


any help is appreciated
Aneesh
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/sane-devel/attachments/20030923/8910de20/attachment.htm>


More information about the sane-devel mailing list