[sane-devel] problem setting custom resolution

aneesh m raj aneeshmraj@hotmail.com
Tue, 23 Sep 2003 10:34:13 +0530


This is a multi-part message in MIME format.

------=_NextPart_000_0059_01C381BE.3B3738F0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

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


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

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

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

   first_frame =3D 0;

  }while(!parm.last_frame);

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

 return ret;
}


any help is appreciated
Aneesh
------=_NextPart_000_0059_01C381BE.3B3738F0
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2800.1106" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Hi all,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Im trying to read the scanned data =
using sane form=20
UMAX 2000p but when i set a custom resolution the read is causing some =
problem.=20
This is my code.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>int print_data(SANE_Handle=20
devHnd)<BR>{</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp; SANE_Int MAX_LEN =3D =
4048;<BR>&nbsp; char=20
filepnm[INIT_SIZE];<BR>&nbsp; int size =3D INIT_SIZE, ret =3D =
0;<BR>&nbsp; int=20
first_frame =3D1;<BR>&nbsp; SANE_Parameters parm;<BR>&nbsp; SANE_Int len =
=3D 0;=20
<BR>&nbsp; FILE* fp =3D NULL;<BR>&nbsp; char *name =3D =
malloc(INIT_SIZE);<BR>&nbsp;=20
char *value =3D malloc(INIT_SIZE);<BR>&nbsp; SANE_Byte* buffer =3D=20
(SANE_Byte*)malloc(sizeof(SANE_Byte) *=20
MAX_LEN);<BR>&nbsp;<BR>&nbsp;<BR>&nbsp;&nbsp;=20
strcpy(filepnm,"images//out.pnm");<BR>&nbsp;&nbsp;fp =3D=20
fopen(filepnm,"wb+");<BR>&nbsp; <BR>&nbsp;<BR>&nbsp;=20
strcpy(name,"State");<BR>&nbsp; <BR>&nbsp; if(fp =3D=3D =
NULL)<BR>&nbsp;&nbsp;=20
{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; status =3D=20
SANE_STATUS_IO_ERROR;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
set_error(act);<BR>&nbsp;&nbsp;&nbsp;&nbsp;=20
&nbsp;free(buffer);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
free(name);<BR>&nbsp;&nbsp;&nbsp;&nbsp;=20
&nbsp;free(value);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ret =3D =
1;<BR>&nbsp;=20
&nbsp;&nbsp;&nbsp;&nbsp; printf("File null...\n");<BR>&nbsp;=20
&nbsp;&nbsp;&nbsp;&nbsp; return ret;<BR>&nbsp;&nbsp; }<BR>&nbsp; =
do<BR>&nbsp;=20
{<BR>&nbsp;&nbsp; if((status =3D sane_get_parameters (devHnd, =
&amp;parm)) !=3D=20
SANE_STATUS_GOOD)<BR>&nbsp;&nbsp; =
{<BR>&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;=20
set_error(act);<BR>&nbsp;&nbsp;&nbsp; printf("get parameters=20
failed...\n");<BR>&nbsp;&nbsp; &nbsp;free(buffer);<BR>&nbsp;&nbsp;&nbsp; =

free(name);<BR>&nbsp;&nbsp;&nbsp; free(value);<BR>&nbsp;&nbsp;&nbsp;=20
fclose(fp);<BR>&nbsp;&nbsp;&nbsp; ret =3D 1;<BR>&nbsp;&nbsp; =
&nbsp;return=20
ret;</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp; }</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;=20
if(first_frame)<BR>&nbsp;&nbsp;{</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; printf("Printing =
scanned=20
data...\n\n");<BR>&nbsp;&nbsp;&nbsp; write_pnm_header =
(parm.format,fp,&nbsp;=20
parm.pixels_per_line,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
=20
parm.lines, parm.depth);<BR></FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;}<BR>&nbsp; <BR>&nbsp; =
do<BR>&nbsp;=20
{<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; status =3D =
read_data(devHnd,=20
buffer, MAX_LEN, &amp;len);<BR>&nbsp;&nbsp;&nbsp; if(status =3D=3D =
SANE_STATUS_GOOD=20
)<BR>&nbsp;&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp; =
<BR>&nbsp;&nbsp;&nbsp;=20
&nbsp; =
fwrite(buffer,len,sizeof(SANE_Byte),fp);<BR>&nbsp;&nbsp;&nbsp;&nbsp;=20
}<BR>&nbsp;&nbsp;&nbsp; else if(status !=3D =
SANE_STATUS_EOF)<BR>&nbsp;&nbsp;=20
&nbsp;{<BR>&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
set_error(act);=20
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("Reading scanned data=20
failed...\n");<BR>&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;&nbsp;=20
free(buffer);<BR>&nbsp;&nbsp;&nbsp; buffer =3D=20
(SANE_Byte*)malloc(sizeof(SANE_Byte) * MAX_LEN);</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp; }while( status =3D=3D =
SANE_STATUS_GOOD=20
&amp;&amp; len !=3D 0);</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp; if( status =3D=3D =
SANE_STATUS_EOF)<BR>&nbsp;=20
{<BR>&nbsp;&nbsp;&nbsp;=20
pthread_cond_signal(&amp;pollevent);<BR>&nbsp;&nbsp;&nbsp;&nbsp;printf("R=
eading=20
complete...\n"); <BR>&nbsp; }<BR>&nbsp; else <BR>&nbsp; =
{<BR>&nbsp;&nbsp;&nbsp;=20
pthread_cond_signal(&amp;pollevent);<BR>&nbsp;&nbsp;&nbsp; ret =3D=20
1;<BR>&nbsp;&nbsp; &nbsp;set_error(act);&nbsp;<BR>&nbsp;=20
&nbsp;&nbsp;printf("Reason: %s",(char*)sane_strstatus(status)); =
<BR>&nbsp;=20
}</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp; &nbsp;first_frame =3D =
0;</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp; =
}while(!parm.last_frame);</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp; free(buffer);<BR>&nbsp;=20
free(name);<BR>&nbsp; free(value);<BR>&nbsp; fclose(fp);</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;</DIV>
<DIV>&nbsp;return ret;<BR>}</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>any help is appreciated</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Aneesh</FONT></DIV></BODY></HTML>

------=_NextPart_000_0059_01C381BE.3B3738F0--