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> </DIV> <DIV><FONT face=3DArial size=3D2>int print_data(SANE_Handle=20 devHnd)<BR>{</FONT></DIV> <DIV><FONT face=3DArial size=3D2></FONT> </DIV> <DIV><FONT face=3DArial size=3D2> SANE_Int MAX_LEN =3D = 4048;<BR> char=20 filepnm[INIT_SIZE];<BR> int size =3D INIT_SIZE, ret =3D = 0;<BR> int=20 first_frame =3D1;<BR> SANE_Parameters parm;<BR> SANE_Int len = =3D 0;=20 <BR> FILE* fp =3D NULL;<BR> char *name =3D = malloc(INIT_SIZE);<BR> =20 char *value =3D malloc(INIT_SIZE);<BR> SANE_Byte* buffer =3D=20 (SANE_Byte*)malloc(sizeof(SANE_Byte) *=20 MAX_LEN);<BR> <BR> <BR> =20 strcpy(filepnm,"images//out.pnm");<BR> fp =3D=20 fopen(filepnm,"wb+");<BR> <BR> <BR> =20 strcpy(name,"State");<BR> <BR> if(fp =3D=3D = NULL)<BR> =20 {<BR> status =3D=20 SANE_STATUS_IO_ERROR;<BR> =20 set_error(act);<BR> =20 free(buffer);<BR> =20 free(name);<BR> =20 free(value);<BR> ret =3D = 1;<BR> =20 printf("File null...\n");<BR> =20 return ret;<BR> }<BR> = do<BR> =20 {<BR> if((status =3D sane_get_parameters (devHnd, = &parm)) !=3D=20 SANE_STATUS_GOOD)<BR> = {<BR> <BR> =20 set_error(act);<BR> printf("get parameters=20 failed...\n");<BR> free(buffer);<BR> = free(name);<BR> free(value);<BR> =20 fclose(fp);<BR> ret =3D 1;<BR> = return=20 ret;</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2> }</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2> =20 if(first_frame)<BR> {</FONT></DIV> <DIV><FONT face=3DArial size=3D2> printf("Printing = scanned=20 data...\n\n");<BR> write_pnm_header = (parm.format,fp, =20 parm.pixels_per_line,<BR> = =20 parm.lines, parm.depth);<BR></FONT></DIV> <DIV><FONT face=3DArial size=3D2></FONT> </DIV> <DIV><FONT face=3DArial size=3D2> }<BR> <BR> = do<BR> =20 {<BR> <BR> status =3D = read_data(devHnd,=20 buffer, MAX_LEN, &len);<BR> if(status =3D=3D = SANE_STATUS_GOOD=20 )<BR> {<BR> = <BR> =20 = fwrite(buffer,len,sizeof(SANE_Byte),fp);<BR> =20 }<BR> else if(status !=3D = SANE_STATUS_EOF)<BR> =20 {<BR> <BR> = set_error(act);=20 <BR> printf("Reading scanned data=20 failed...\n");<BR> }<BR> =20 free(buffer);<BR> buffer =3D=20 (SANE_Byte*)malloc(sizeof(SANE_Byte) * MAX_LEN);</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2> }while( status =3D=3D = SANE_STATUS_GOOD=20 && len !=3D 0);</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2> if( status =3D=3D = SANE_STATUS_EOF)<BR> =20 {<BR> =20 pthread_cond_signal(&pollevent);<BR> printf("R= eading=20 complete...\n"); <BR> }<BR> else <BR> = {<BR> =20 pthread_cond_signal(&pollevent);<BR> ret =3D=20 1;<BR> set_error(act); <BR> =20 printf("Reason: %s",(char*)sane_strstatus(status)); = <BR> =20 }</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2> first_frame =3D = 0;</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2> = }while(!parm.last_frame);</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2> free(buffer);<BR> =20 free(name);<BR> free(value);<BR> fclose(fp);</FONT></DIV> <DIV><FONT face=3DArial size=3D2> </DIV> <DIV> return ret;<BR>}</FONT></DIV> <DIV><FONT face=3DArial size=3D2></FONT> </DIV> <DIV><FONT face=3DArial size=3D2></FONT> </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--