home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / grafik / hpcd06 / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-03-24  |  29.4 KB  |  1,273 lines

  1. /* hpcdtoppm (Hadmut's pcdtoppm) v0.6.beta
  2. *  Copyright (c) 1992, 1993, 1994 by Hadmut Danisch (danisch@ira.uka.de).
  3. *  Permission to use and distribute this software and its
  4. *  documentation for noncommercial use and without fee is hereby granted,
  5. *  provided that the above copyright notice appear in all copies and that
  6. *  both that copyright notice and this permission notice appear in
  7. *  supporting documentation. It is not allowed to sell this software in
  8. *  any way. This software is not public domain.
  9. */
  10.  
  11. #include "hpcdtoppm.h"
  12.  
  13.  
  14. uBYTE sbuffer[SECSIZE];
  15.  
  16. enum TURNS  turn     = T_UNSPEC;
  17. enum TURNS  contori  = T_UNSPEC;
  18. enum SIZES  size     = S_UNSPEC;
  19. enum OUTFOR outfor   = O_UNSPEC;
  20. enum CORR   corrmode = C_UNSPEC;
  21.  
  22. sINT do_info,do_diff,do_overskip,do_sharp,monochrome,paper;
  23. sINT do_melde,do_rep,do_crop;
  24. sINT flhori=0,flvert=0;
  25. sINT bufpos=0;
  26.  
  27. char *pcdname=0,*ppmname=0;
  28. static FILE  *fin=0,*fout=0;
  29.  
  30. static char    *suba1=0,*suba2=0,*dir64=0;
  31. static implane Luma, Chroma1,Chroma2;
  32. static implane *PLuma,*PChroma1,*PChroma2;
  33. static sINT    contsize=1;
  34. static sINT    emulate_seek=0;
  35. static sINT    print_pos;
  36.  
  37.  
  38. #define PrintPos(x) {if(print_pos) fprintf(stderr,"File-Offset: %8d = %8x (hex) = %d (sec)\n",(x),(x),(x)/0x800);}
  39.  
  40. static void checkin(void);
  41. static void parseargs(int,char**);
  42. static void sizecontrol(sizeinfo *,dim,dim,dim sMASK);
  43. static void f_1 (dim,dim,sINT,sINT);
  44. static void f_3 (dim,dim,sINT);
  45. static void f_4 (dim,dim,sINT);
  46. static void f_5 (dim,dim);
  47. static void f_6 (dim,dim);
  48. static void f_ov(dim,dim,sINT,sINT);
  49. static void f_co(dim,dim,sINT,sINT);
  50.  
  51.  
  52.  
  53. void close_all(void)
  54.  {
  55.   if(fin && (fin != stdin)) fclose(fin);
  56.  
  57.   if(fout)
  58.    {if(fout==stdout)
  59.       fflush(fout);
  60.     else
  61.       fclose(fout);
  62.    }
  63.  }
  64.  
  65. /***************************/
  66. /*                         */
  67. /*      Routine MAIN       */
  68. /*                         */
  69. /***************************/
  70.  
  71.  
  72. void main(int argc,char **argv)
  73.  {
  74.  
  75.   typecheck();
  76.  
  77.   do_info=do_diff=do_overskip=do_sharp=monochrome=paper=0;
  78.   do_melde=do_rep=do_crop=0;
  79.   print_pos=0;
  80.  
  81.  
  82.   parseargs(argc,argv);
  83.  
  84.   if(size     == S_UNSPEC) size     = S_DEFAULT;
  85.   if(outfor   == O_UNSPEC) outfor   = O_DEFAULT;
  86.   if(corrmode == C_UNSPEC) corrmode = C_DEFAULT;
  87.   if(turn     == T_UNSPEC) turn     = T_DEFAULT;
  88.  
  89.   monochrome=(outfor==O_PGM)||(outfor==O_PSG)||(outfor==O_EPSG)||(outfor==O_PSD)||(outfor==O_EPSD);
  90.   paper     =(outfor==O_PS )||(outfor==O_EPS)||(outfor==O_PSG )||(outfor==O_EPSG)||(outfor==O_PSD)||(outfor==O_EPSD);
  91.  
  92.   if((size==S_Over) && (!ppmname)) error(E_ARG);
  93.   if((size==S_Contact) && do_crop) error(E_ARG);
  94.   if(do_overskip && do_diff)       error(E_OPT);
  95.  
  96.   if(do_diff && (size != S_4Base) && (size != S_16Base) && (size != S_64Base)) error(E_OPT);
  97.  
  98.   if(do_overskip && (size != S_Base16) && (size != S_Base4) && (size != S_Base) && (size != S_4Base) ) error(E_OVSKIP);
  99.   if(print_pos   && (size != S_Base16) && (size != S_Base4) && (size != S_Base) && (size != S_4Base) ) error(E_OPT);
  100.   if(do_info     && (size != S_Base16) && (size != S_Base4) && (size != S_Base) && (size != S_4Base) ) error(E_OPT);
  101.   if(monochrome && do_overskip) error(E_OPT);
  102.   if((size==S_Contact) &&((contsize<1) || (contsize>100))) error(E_OPT);
  103.   if(suba1 && ( size==S_Contact || size==S_Over)) error(E_OPT);
  104.   if(suba1 && do_crop) error(E_OPT);
  105.  
  106.   if((!paper) && (PSIZE_SET || DPI_SET || FAK_SET)) error(E_OPT);
  107.   if(PSIZE_SET && DPI_SET && FAK_SET) error(E_OPT);
  108.   if((DPI_SET || FAK_SET) && (outfor!=O_PSD) && (outfor!=O_EPSD)) error(E_OPT);
  109.  
  110.  
  111.  
  112.  
  113.   if(strcmp(pcdname,"-"))
  114.    { if(!(fin=fopen(pcdname,R_OP))) error(E_FOPEN);
  115.      emulate_seek=0;
  116.    }
  117.   else
  118.    {pcdname="<stdin>";
  119.     emulate_seek=1;
  120. #ifdef USE_FDOPEN
  121.     fin=fdopen(fileno(stdin),R_OP);
  122.     if(!fin) error(E_READ);
  123. #else
  124.     fin=stdin;
  125. #endif
  126.    }
  127.  
  128.   bufpos=0;
  129.  
  130.  
  131.   if((size != S_Over) && (size != S_Contact)) checkin();
  132.  
  133.   PLuma=    &Luma;
  134.   PChroma1= monochrome ? 0 : &Chroma1;
  135.   PChroma2= monochrome ? 0 : &Chroma2;
  136.  
  137.   switch(size)
  138.    {
  139.     case S_Base16:  f_1(BaseW/4,BaseH/4,L_Head,(L_Head+L_Base16));
  140.                     break;
  141.  
  142.     case S_Base4:   f_1(BaseW/2,BaseH/2,(L_Head+L_Base16),(L_Head+L_Base16+L_Base4));
  143.                     break;
  144.  
  145.     case S_Base:    f_3(BaseW,BaseH,(L_Head+L_Base16+L_Base4));
  146.                     break;
  147.  
  148.     case S_4Base:   f_4(BaseW*2,BaseH*2,(L_Head+L_Base16+L_Base4));
  149.                     break;
  150.  
  151.     case S_16Base:  f_5(BaseW*4,BaseH*4);
  152.                     break;
  153.  
  154.     case S_64Base:  f_6(BaseW*8,BaseH*8);
  155.                     break;
  156.  
  157.     case S_Over:    f_ov(BaseW/4,BaseH/4,5,SeBase16);
  158.                     break;
  159.  
  160.     case S_Contact: f_co(BaseW/4,BaseH/4,5,SeBase16);
  161.                     break;
  162.  
  163.     default: error(E_INTERN);
  164.    }
  165.  
  166.   close_all();
  167.   exit(0);
  168.  
  169.  }
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176. static void openoutput(void)
  177.  {
  178.   if(!ppmname)
  179.    {
  180. #ifdef USE_FDOPEN
  181.     fout=fdopen(fileno(stdout),W_OP);
  182.     if(!fout) error(E_WRITE);
  183. #else
  184.     fout=stdout;
  185. #endif
  186.    }
  187.   else
  188.    {if (!(fout=fopen(ppmname,W_OP))) error(E_WRITE);
  189.    }
  190.  }
  191.  
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198. static void f_1(dim w,dim h,sINT normal,sINT overskip)
  199.  {sizeinfo si;
  200.  
  201.   sizecontrol(&si,w,h,~3);
  202.  
  203.                    planealloc(PLuma   ,si.rdhlen,si.rdvlen);
  204.   if (!monochrome) planealloc(PChroma1,si.rdhlen,si.rdvlen);
  205.   if (!monochrome) planealloc(PChroma2,si.rdhlen,si.rdvlen);
  206.  
  207.   PrintPos(normal*SECSIZE);
  208.   SEEK(normal+1);
  209.  
  210.   if(!do_overskip)
  211.     { error(readplain(&si,1,PLuma,PChroma1,PChroma2));
  212.       if (!monochrome)
  213.         {interpolate(PChroma1);
  214.          interpolate(PChroma2);
  215.         }
  216.     }
  217.   else
  218.     { error(readplain(&si,1,PLuma,nullplane,nullplane));
  219.       SEEK(overskip+1);
  220.       error(readplain(&si,2,nullplane,PChroma1,PChroma2));
  221.     }
  222.  
  223.  
  224.   colconvert(&si,PLuma,PChroma1,PChroma2);
  225.   /* Now Luma holds red, Chroma1 hold green, Chroma2 holds blue */
  226.  
  227.  
  228.   openoutput();
  229.   writepicture(fout,&si,PLuma,PChroma1,PChroma2,turn);
  230.  
  231.  }
  232.  
  233.  
  234. static void f_3(dim w,dim h,sINT normal)
  235.  {sINT cd_offset,cd_offhelp;
  236.   sizeinfo si;
  237.  
  238.   sizecontrol(&si,w,h,~3);
  239.  
  240.   PrintPos(normal*SECSIZE);
  241.   SEEK(normal+1);
  242.  
  243.   if(!do_overskip)
  244.     {                 planealloc(PLuma   ,si.rdhlen,si.rdvlen);
  245.      if (!monochrome) planealloc(PChroma1,si.rdhlen,si.rdvlen);
  246.      if (!monochrome) planealloc(PChroma2,si.rdhlen,si.rdvlen);
  247.  
  248.      error(readplain(&si,1,PLuma,PChroma1,PChroma2));
  249.       if (!monochrome)
  250.         {interpolate(PChroma1);
  251.          interpolate(PChroma2);
  252.         }
  253.     }
  254.    else
  255.     {planealloc(PLuma   ,  si.rdhlen,  si.rdvlen);
  256.      planealloc(PChroma1,2*si.rdhlen,2*si.rdvlen);
  257.      planealloc(PChroma2,2*si.rdhlen,2*si.rdvlen);
  258.  
  259.      error(readplain(&si,1,PLuma,PChroma1,PChroma2));
  260.      interpolate(PChroma1);
  261.      interpolate(PChroma2);
  262.      interpolate(PChroma1);
  263.      interpolate(PChroma2);
  264.  
  265.      cd_offset=Skip4Base();
  266.      SEEK(cd_offset+10);          EREADBUF;    cd_offhelp=(((uINT)sbuffer[2])<<8)|sbuffer[3];
  267.      SEEK(cd_offset+12);          readhqt(3);
  268.      SEEK(cd_offset+cd_offhelp);  decode(&si,4,nullplane,PChroma1,PChroma2,1);
  269.  
  270.      halve(PChroma1);
  271.      halve(PChroma2);
  272.     }
  273.   colconvert(&si,PLuma,PChroma1,PChroma2);
  274.   /* Now Luma holds red, Chroma1 hold green, Chroma2 holds blue */
  275.  
  276.   openoutput();
  277.   writepicture(fout,&si,PLuma,PChroma1,PChroma2,turn);
  278.  
  279.  
  280.  }
  281.  
  282.  
  283.  
  284. static void f_4(dim w,dim h,sINT normal)
  285.  {sINT cd_offset,cd_offhelp;
  286.   sizeinfo si;
  287.   sizecontrol(&si,w,h,~3);
  288.  
  289.                    planealloc(PLuma   ,si.rdhlen,si.rdvlen);
  290.   if (!monochrome) planealloc(PChroma1,si.rdhlen,si.rdvlen);
  291.   if (!monochrome) planealloc(PChroma2,si.rdhlen,si.rdvlen);
  292.  
  293.   PrintPos((L_Head+L_Base16+L_Base4+L_Base)*SECSIZE);
  294.  
  295.   if(!do_overskip)
  296.    {SEEK(L_Head+L_Base16+L_Base4+1);
  297.     error(readplain(&si,-2,PLuma,PChroma1,PChroma2));
  298.     interpolate(PLuma);
  299.     if (!monochrome)
  300.      {interpolate(PChroma1);
  301.       interpolate(PChroma1);
  302.       interpolate(PChroma2);
  303.       interpolate(PChroma2);
  304.      }
  305.  
  306.     if(do_diff) {clearimpl(PLuma,neutrLum);clearimpl(PChroma1,neutrCh1);clearimpl(PChroma2,neutrCh2);}
  307.  
  308.     cd_offset = L_Head + L_Base16 + L_Base4 + L_Base ;
  309.     SEEK(cd_offset + 4);     readhqt(1);
  310.     SEEK(cd_offset + 5);     decode(&si,1,PLuma,nullplane,nullplane,0);
  311.    }
  312.   else
  313.    {SEEK(L_Head+L_Base16+L_Base4+1);
  314.     error(readplain(&si,-2,PLuma,PChroma1,PChroma2));
  315.     interpolate(PLuma);
  316.     interpolate(PChroma1);
  317.     interpolate(PChroma1);
  318.     interpolate(PChroma2);
  319.     interpolate(PChroma2);
  320.  
  321.     cd_offset = L_Head + L_Base16 + L_Base4 + L_Base ;
  322.     SEEK(cd_offset + 4);     readhqt(1);
  323.     SEEK(cd_offset + 5);     decode(&si,1,PLuma,nullplane,nullplane,0);
  324.  
  325.     cd_offset=bufpos;
  326.     if(cd_offset % SECSIZE) error(E_POS);
  327.     cd_offset/=SECSIZE;
  328.     SEEK(cd_offset+10);          EREADBUF;    cd_offhelp=(((uINT)sbuffer[2])<<8)|sbuffer[3];
  329.     SEEK(cd_offset+12);          readhqt(3);
  330.     SEEK(cd_offset+cd_offhelp);  decode(&si,2,nullplane,PChroma1,PChroma2,1);
  331.  
  332.    }
  333.   colconvert(&si,PLuma,PChroma1,PChroma2);
  334.   /* Now Luma holds red, Chroma1 hold green, Chroma2 holds blue */
  335.  
  336.   openoutput();
  337.   writepicture(fout,&si,PLuma,PChroma1,PChroma2,turn);
  338.  
  339.  }
  340.  
  341.  
  342.  
  343.  
  344.  
  345.  
  346.  
  347.  
  348.  
  349.  
  350.  
  351.  
  352.  
  353. static void f_5sub(dim w, dim h, sizeinfo *sip,int fak1,int fak2,int fak3,dim sMASK)
  354.  {sINT cd_offset;
  355.  
  356.   sizecontrol(sip,w,h,sMASK);
  357.  
  358.                    planealloc(PLuma   ,sip->rdhlen,sip->rdvlen);
  359.   if (!monochrome) planealloc(PChroma1,sip->rdhlen,sip->rdvlen);
  360.   if (!monochrome) planealloc(PChroma2,sip->rdhlen,sip->rdvlen);
  361.  
  362.   SEEK(L_Head+L_Base16+L_Base4+1);
  363.   error(readplain(sip,fak1,PLuma,PChroma1,PChroma2));
  364.   interpolate(PLuma);
  365.   if(!monochrome)
  366.    {interpolate(PChroma1);
  367.     interpolate(PChroma1);
  368.     interpolate(PChroma2);
  369.     interpolate(PChroma2);
  370.    }
  371.  
  372.   cd_offset = L_Head + L_Base16 + L_Base4 + L_Base ;
  373.   SEEK(cd_offset + 4);       readhqt(1);
  374.   SEEK(cd_offset + 5);       decode(sip,fak2,PLuma,nullplane,nullplane,0);
  375.   interpolate(PLuma);
  376.  
  377.   if(do_diff) {clearimpl(PLuma,neutrLum);clearimpl(PChroma1,neutrCh1);clearimpl(PChroma2,neutrCh2);}
  378.  
  379.   cd_offset=bufpos;
  380.   if(cd_offset % SECSIZE) error(E_POS);
  381.   PrintPos(cd_offset);
  382.   cd_offset/=SECSIZE;
  383.  
  384.   SEEK(cd_offset+12);        readhqt(3);
  385.   SEEK(cd_offset+14);        decode(sip,fak3,PLuma,PChroma1,PChroma2,0);
  386.  
  387.  }
  388.  
  389.  
  390.  
  391.  
  392. static void f_5(dim w,dim h)
  393.  {sizeinfo si;
  394.  
  395.   f_5sub(w,h,&si,-4,-2,1,~7);
  396.  
  397.   if(!monochrome)
  398.    {interpolate(PChroma1);
  399.     interpolate(PChroma2);
  400.    }
  401.  
  402.   colconvert(&si,PLuma,PChroma1,PChroma2);
  403.   /* Now Luma holds red, Chroma1 hold green, Chroma2 holds blue */
  404.  
  405.   openoutput();
  406.   writepicture(fout,&si,PLuma,PChroma1,PChroma2,turn);
  407.  
  408.  }
  409.  
  410.  
  411.  
  412.  
  413. static void f_6(dim w,dim h)
  414.  {sizeinfo si;
  415.   FILE *ic,*icr;
  416.   struct ic_header ic_h;
  417.   struct ic_descr descr[3];
  418.   struct ic_fname names[3];
  419.   uINT   file_offset[3];
  420.   struct file16 namecount,descrcount;
  421.   struct file32 foff;
  422.   int i,j,nc,dc;
  423.   char   FN[300];
  424.  
  425.  
  426.   f_5sub(w,h,&si,-8,-4,-2,~15);
  427.  
  428.   interpolate(PLuma);
  429.   if(!monochrome)
  430.    {interpolate(PChroma1);
  431.     interpolate(PChroma2);
  432.    }
  433.  
  434.   if(!(ic=fopen("64base/info.ic",R_OP))) error(E_FOPEN);
  435.   if(fread(&ic_h,sizeof(ic_h),1,ic)<1) error(E_READ);
  436.  
  437.  
  438.  
  439.  
  440.   /******************************************************************************/
  441.   /* layer descriptions */
  442.   /******************************************************************************/
  443.   if(fseek(ic,FILE32(ic_h.off_descr),0)) error(E_READ);
  444.  
  445.   if(fread(&descrcount,sizeof(descrcount),1,ic)<1) error(E_READ);
  446.   dc=FILE16(descrcount);
  447.  
  448.   if((dc<1) || (dc>3)) error(E_SEQ);
  449.   if((!monochrome) && (dc<3))         error(E_SEQ);
  450.  
  451.   if(fread(descr,sizeof(descr[0]),dc,ic)<dc) error(E_READ);
  452.  
  453.  
  454.  
  455.  
  456.  
  457.  
  458.   /******************************************************************************/
  459.   /* Filenames */
  460.   /******************************************************************************/
  461.   if(fseek(ic,FILE32(ic_h.off_fnames),0)) error(E_READ);
  462.  
  463.   if(fread(&namecount,sizeof(namecount),1,ic)<1) error(E_READ);
  464.   nc=FILE16(namecount);
  465.  
  466.   if((nc<1) || (nc>3)) error(E_SEQ);
  467.   if((!monochrome) && (nc<3))         error(E_SEQ);
  468.  
  469.   if(fread(names,sizeof(names[0]),nc,ic)<nc) error(E_READ);
  470.  
  471. #ifdef SMALLNAMES
  472.   for (i=0;i<nc;i++)
  473.    {
  474.     {for (j=0;j<sizeof(names[0].fname);j++)
  475.       {if((names[i].fname[j]>= 'A') && (names[i].fname[j]<= 'Z'))
  476.         names[i].fname[j] += 'a'-'A';
  477.       }
  478.     }
  479. #ifdef DEBUG
  480.    fprintf(stderr,"%-*.*s %d\n",sizeof(names[0].fname),sizeof(names[0].fname),names[i].fname, FILE32(names[i].size));
  481. #endif
  482. #endif
  483.    }
  484.  
  485.  
  486.   /******************************************************************************/
  487.   /* File-Offsets */
  488.   /******************************************************************************/
  489.   for(i=0;i< (monochrome?1:3); i++)
  490.    {if(fseek(ic,FILE32(descr[i].off_pointers)+ 6*4*(i?si.rdvoff/2:si.rdvoff) + 2,0)) error(E_READ);
  491.     if(fread(&foff,sizeof(foff),1,ic)<1) error(E_READ);
  492.     file_offset[i]=FILE32(foff);
  493. #ifdef DEBUG
  494.     fprintf(stderr,"Fileoffset %d  %d %x\n",i,file_offset[i],file_offset[i]);
  495. #endif
  496.    }
  497.  
  498.  
  499.  
  500.   /******************************************************************************/
  501.   /* Huffman-Tables */
  502.   /******************************************************************************/
  503.   if(fseek(ic,FILE32(ic_h.off_huffman),0)) error(E_READ);
  504.   if(fread(sbuffer,1,sizeof(sbuffer),ic)<5) error(E_READ);
  505.  
  506.   readhqtx(monochrome?1:3);
  507.  
  508.  
  509.  
  510.   /******************************************************************************/
  511.   /* Decode it */
  512.   /******************************************************************************/
  513.   for(i=0;i< (monochrome?1:3); i++)
  514.    {sprintf(FN,"%s%s%s",dir64,DIRSEP,names[i].fname);
  515. #ifdef DEBUG
  516.     fprintf(stderr,"Filename %s\n",FN);
  517. #endif
  518.     if(!(icr=fopen(FN,R_OP))) error(E_FOPEN);
  519.     if(fseek(icr,file_offset[i],0)) error(E_READ);
  520.     switch (i)
  521.      {case 0:  decodex(icr,0,&descr[0],&si, 1,PLuma,   1);  break;
  522.       case 1:  decodex(icr,1,&descr[1],&si,-2,PChroma1,1);  break;
  523.       case 2:  decodex(icr,2,&descr[2],&si,-2,PChroma2,1);  break;
  524.      }
  525.     fclose(icr);
  526.    }
  527.   fclose(ic);
  528.  
  529.  
  530.   if(!monochrome)
  531.    {interpolate(PChroma1);
  532.     interpolate(PChroma2);
  533.    }
  534.  
  535.   colconvert(&si,PLuma,PChroma1,PChroma2);
  536.   openoutput();
  537.   writepicture(fout,&si,PLuma,PChroma1,PChroma2,turn);
  538.  
  539.  }
  540.  
  541.  
  542.  
  543.  
  544.  
  545.  
  546.  
  547.  
  548.  
  549.  
  550.  
  551.  
  552.  
  553.  
  554.  
  555.  
  556. static void f_ov(dim w,dim h,sINT offset,sINT imsize)
  557.  {sINT bildnr,bilder;
  558.   dim wx,hx;
  559.   enum ERRORS eret;
  560.   enum TURNS imorient;
  561.   char nbuf[100];
  562.   uBYTE hbuf[SECSIZE];
  563.   sizeinfo si;
  564.  
  565.   sizecontrol(&si,w,h,~3);
  566.  
  567.   wx=w; hx=h;
  568.  
  569.                    planealloc(PLuma   ,si.rdhlen,si.rdvlen);
  570.   if (!monochrome) planealloc(PChroma1,si.rdhlen,si.rdvlen);
  571.   if (!monochrome) planealloc(PChroma2,si.rdhlen,si.rdvlen);
  572.  
  573.  
  574.   SEEK(0);
  575.   if(READ(hbuf,sizeof(hbuf))<1) error(E_READ);
  576.  
  577.   bilder=(((sINT) hbuf[10])<<8) | hbuf[11];
  578.  
  579.  
  580.   for(bildnr=0;bildnr<bilder;bildnr++)
  581.    {w=wx;h=hx;
  582.     sizecontrol(&si,w,h,~3);
  583.     PLuma->im=PLuma->mp;
  584.     if(PChroma1) PChroma1->im=PChroma1->mp;
  585.     if(PChroma2) PChroma2->im=PChroma2->mp;
  586.  
  587.     SEEK(offset+imsize*bildnr);
  588.  
  589.     eret=readplain(&si,1,PLuma,PChroma1,PChroma2);
  590.     if(eret==E_READ) break;
  591.     error(eret);
  592.  
  593.     if(!monochrome)
  594.      {interpolate(PChroma1);
  595.       interpolate(PChroma2);
  596.      }
  597.  
  598.     colconvert(&si,PLuma,PChroma1,PChroma2);
  599.  
  600.     sprintf(nbuf,"%s%04d",ppmname,bildnr+1);
  601.     if (!(fout=fopen(nbuf,W_OP))) error(E_WRITE);
  602.      switch(hbuf[12+bildnr] & 3)
  603.       {case 0:  imorient=T_NONE;  break;
  604.        case 1:  imorient=T_LEFT;  break;
  605.        case 2:  imorient=T_HEAD;  break;
  606.        case 3:  imorient=T_RIGHT; break;
  607.        default: imorient=T_NONE;
  608.       }
  609.     writepicture(fout,&si,PLuma,PChroma1,PChroma2,turn != T_AUTO ? turn : imorient);
  610.     fclose(fout);
  611.     fout=0;
  612.    }
  613.  }
  614.  
  615.  
  616.  
  617.  
  618. static void f_co(dim w,dim h,sINT offset,sINT imsize)
  619.  {sINT bildnr,bilder,cols,rows,xstep,ystep,mw,mh;
  620.   enum ERRORS eret;
  621.   enum TURNS imorient;
  622.   implane mLuma,mChroma1,mChroma2;
  623.   implane *pmL,*pmCh1,*pmCh2;
  624.   uBYTE hbuf[SECSIZE];
  625.   sizeinfo sibig,sismall;
  626.  
  627.   pmL=                    &mLuma;
  628.   pmCh1= monochrome ? 0 : &mChroma1;
  629.   pmCh2= monochrome ? 0 : &mChroma2;
  630.  
  631.  
  632.   SEEK(0);
  633.   if(READ(hbuf,sizeof(hbuf))<1) error(E_READ);
  634.   bilder=(((sINT) hbuf[10])<<8) | hbuf[11];
  635.  
  636.   cols=contsize;
  637.   rows=(bilder+cols-1)/cols;
  638.  
  639.   xstep=ystep=0;
  640.   switch(turn)
  641.    {case T_NONE:
  642.     case T_HEAD: xstep=w;ystep=h; break;
  643.     case T_RIGHT:
  644.     case T_LEFT: xstep=h;ystep=w; break;
  645.     case T_AUTO: xstep=ystep=w;   break;
  646.     default: error(E_INTERN);
  647.    }
  648.  
  649.   mw=cols*xstep;
  650.   mh=rows*ystep;
  651.  
  652.   sizecontrol(&sibig  ,mw,mh,~3);
  653.   sizecontrol(&sismall, w, h,~3);
  654.  
  655.   planealloc(PLuma   ,w,h);
  656.   if (!monochrome) planealloc(PChroma1,w,h);
  657.   if (!monochrome) planealloc(PChroma2,w,h);
  658.  
  659.   planealloc(pmL,mw,mh);
  660.   mLuma.iwidth=mw;
  661.   mLuma.iheight=mh;
  662.   clearimpl(pmL,CONTLUM);
  663.  
  664.   if(!monochrome)
  665.    { planealloc(pmCh1,mw,mh);
  666.      mChroma1.iwidth=mw;
  667.      mChroma1.iheight=mh;
  668.      clearimpl(pmCh1,CONTCH1);
  669.  
  670.      planealloc(pmCh2,mw,mh);
  671.      mChroma2.iwidth=mw;
  672.      mChroma2.iheight=mh;
  673.      clearimpl(pmCh2,CONTCH2);
  674.    }
  675.  
  676.  
  677.   for(bildnr=0;bildnr<bilder;bildnr++)
  678.    {SEEK(offset+imsize*bildnr);
  679.  
  680.     eret=readplain(&sismall,1,PLuma,PChroma1,PChroma2);
  681.     if(eret==E_READ) break;
  682.     error(eret);
  683.  
  684.     if(!monochrome)
  685.      {interpolate(PChroma1);
  686.       interpolate(PChroma2);
  687.      }
  688.  
  689.     switch(hbuf[12+bildnr] & 3)
  690.      {case 0:  imorient=T_NONE;  break;
  691.       case 1:  imorient=T_LEFT;  break;
  692.       case 2:  imorient=T_HEAD;  break;
  693.       case 3:  imorient=T_RIGHT; break;
  694.       default: imorient=T_NONE;
  695.      }
  696.     pastein(pmL,(bildnr%cols)*xstep,xstep,(bildnr/cols)*ystep,ystep,PLuma,((turn==T_AUTO)? imorient:turn));
  697.     if(!monochrome)
  698.      {pastein(pmCh1,(bildnr%cols)*xstep,xstep,(bildnr/cols)*ystep,ystep,PChroma1,((turn==T_AUTO)? imorient:turn));
  699.       pastein(pmCh2,(bildnr%cols)*xstep,xstep,(bildnr/cols)*ystep,ystep,PChroma2,((turn==T_AUTO)? imorient:turn));
  700.      }
  701.    }
  702.  
  703.   colconvert(&sibig,pmL,pmCh1,pmCh2);
  704.  
  705.   openoutput();
  706.   writepicture(fout,&sibig,pmL,pmCh1,pmCh2,contori);
  707.  
  708.  }
  709.  
  710.  
  711.  
  712.  
  713.  
  714.  
  715.  
  716.  
  717. #define ASKIP { argc--; argv ++;}
  718.  
  719. static void parseargs(int  argc,char **argv)
  720.  {
  721.   char *opt;
  722.  
  723.   ASKIP;
  724.  
  725.   while((argc>0) && argv[0][0]=='-' && argv[0][1])
  726.    {
  727.     opt= (*argv)+1;
  728.     ASKIP;
  729.  
  730. /**** additional options ****/
  731.  
  732.     if(!strcmp(opt,"x"))
  733.      { if (!do_overskip) do_overskip=1;
  734.        else error(E_ARG);
  735.        continue;
  736.      }
  737.  
  738.     if(!strcmp(opt,"s"))
  739.      { if (!do_sharp) do_sharp=1;
  740.        else error(E_ARG);
  741.        continue;
  742.      }
  743.  
  744.     if(!strcmp(opt,"d"))
  745.      { if (!do_diff) do_diff=1;
  746.        else error(E_ARG);
  747.        continue;
  748.      }
  749.  
  750.     if(!strcmp(opt,"i"))
  751.      { if (!do_info) do_info=1;
  752.        else error(E_ARG);
  753.        continue;
  754.      }
  755.  
  756.  
  757.     if(!strcmp(opt,"m"))
  758.      { if (!do_melde) do_melde=1;
  759.        else error(E_ARG);
  760.        continue;
  761.      }
  762.  
  763.     if(!strcmp(opt,"crop"))
  764.      { if (!do_crop) do_crop=1;
  765.        else error(E_ARG);
  766.        continue;
  767.      }
  768.  
  769.     if(!strcmp(opt,"pos"))
  770.      { if (!print_pos) print_pos=1;
  771.        else error(E_ARG);
  772.        continue;
  773.      }
  774.  
  775.     if(!strcmp(opt,"rep"))
  776.      { if (!do_rep) do_rep=1;
  777.        else error(E_ARG);
  778.        continue;
  779.      }
  780.  
  781. /****  Orientation options ****/
  782.  
  783.     if(!strcmp(opt,"n"))
  784.      {if (turn == T_UNSPEC) turn=T_NONE;
  785.       else error(E_ARG);
  786.       continue;
  787.      }
  788.  
  789.     if(!strcmp(opt,"r"))
  790.      {if (turn == T_UNSPEC) turn=T_RIGHT;
  791.       else error(E_ARG);
  792.       continue;
  793.      }
  794.  
  795.     if(!strcmp(opt,"l"))
  796.      {if (turn == T_UNSPEC) turn=T_LEFT;
  797.       else error(E_ARG);
  798.       continue;
  799.      }
  800.  
  801.     if(!strcmp(opt,"h"))
  802.      {if (turn == T_UNSPEC) turn=T_HEAD;
  803.       else error(E_ARG);
  804.       continue;
  805.      }
  806.  
  807.     if(!strcmp(opt,"a"))
  808.      {if (turn == T_UNSPEC) turn=T_AUTO;
  809.       else error(E_ARG);
  810.       continue;
  811.      }
  812.  
  813.     if(!strcmp(opt,"vert"))
  814.      {if (!flvert) flvert=1;
  815.       else error(E_ARG);
  816.       continue;
  817.      }
  818.  
  819.     if(!strcmp(opt,"hori"))
  820.      {if (!flhori) flhori=1;
  821.       else error(E_ARG);
  822.       continue;
  823.      }
  824.  
  825.  
  826.  
  827.  
  828.  
  829.  
  830. /**** Output options ****/
  831.  
  832.  
  833.     if((!strcmp(opt,"ppm")) || (!strcmp(opt,"PPM")))
  834.      { if (outfor == O_UNSPEC) outfor=O_PPM;
  835.        else error(E_ARG);
  836.        continue;
  837.      }
  838.  
  839.  
  840.     if((!strcmp(opt,"pgm")) || (!strcmp(opt,"PGM")))
  841.      { if (outfor == O_UNSPEC) outfor=O_PGM;
  842.        else error(E_ARG);
  843.        continue;
  844.      }
  845. /** SD added TGA format **/
  846.     if((!strcmp(opt,"tga")) || (!strcmp(opt,"TGA")))
  847.      { if (outfor == O_UNSPEC) outfor=O_TGA;
  848.        else error(E_ARG);
  849.        continue;
  850.      }
  851.  
  852.  
  853.  
  854.     if(!strcmp(opt,"ycc"))
  855.      { if (outfor == O_UNSPEC) outfor=O_YCC;
  856.        else error(E_ARG);
  857.        continue;
  858.      }
  859.  
  860.     if((!strcmp(opt,"ps")) || (!strcmp(opt,"PS")))
  861.      { if (outfor == O_UNSPEC) outfor=O_PS;
  862.        else error(E_ARG);
  863.        continue;
  864.      }
  865.  
  866.     if((!strcmp(opt,"eps")) || (!strcmp(opt,"EPS")))
  867.      { if (outfor == O_UNSPEC) outfor=O_EPS;
  868.        else error(E_ARG);
  869.        continue;
  870.      }
  871.  
  872.     if((!strcmp(opt,"psg")) || (!strcmp(opt,"PSG")))
  873.      { if (outfor == O_UNSPEC) outfor=O_PSG;
  874.        else error(E_ARG);
  875.        continue;
  876.      }
  877.  
  878.     if((!strcmp(opt,"epsg")) || (!strcmp(opt,"EPSG")))
  879.      { if (outfor == O_UNSPEC) outfor=O_EPSG;
  880.        else error(E_ARG);
  881.        continue;
  882.      }
  883.  
  884.     if((!strcmp(opt,"psd")) || (!strcmp(opt,"PSD")))
  885.      { if (outfor == O_UNSPEC) outfor=O_PSD;
  886.        else error(E_ARG);
  887.        continue;
  888.      }
  889.  
  890.     if((!strcmp(opt,"epsd")) || (!strcmp(opt,"EPSD")))
  891.      { if (outfor == O_UNSPEC) outfor=O_EPSD;
  892.        else error(E_ARG);
  893.        continue;
  894.      }
  895.  
  896.  
  897.     if(!strcmp(opt,"pl" ))
  898.      { if(argc<1) error(E_ARG);
  899.        if((sscanf(*argv,SSFLTPT,&PAPER_LEFT))!=1) error(E_ARG);
  900.        ASKIP;
  901.        continue;
  902.      }
  903.  
  904.     if(!strcmp(opt,"pb" ))
  905.      { if(argc<1) error(E_ARG);
  906.        if((sscanf(*argv,SSFLTPT,&PAPER_BOTTOM))!=1) error(E_ARG);
  907.        ASKIP;
  908.        continue;
  909.      }
  910.  
  911.  
  912.     if(!strcmp(opt,"pw" ))
  913.      { if(argc<1) error(E_ARG);
  914.        PSIZE_SET=1;
  915.        if((sscanf(*argv,SSFLTPT,&PAPER_WIDTH))!=1) error(E_ARG);
  916.        ASKIP;
  917.        continue;
  918.      }
  919.  
  920.     if(!strcmp(opt,"ph" ))
  921.      { if(argc<1) error(E_ARG);
  922.        PSIZE_SET=1;
  923.        if((sscanf(*argv,SSFLTPT,&PAPER_HEIGHT))!=1) error(E_ARG);
  924.        ASKIP;
  925.        continue;
  926.      }
  927.  
  928.  
  929.     if(!strcmp(opt,"dpi" ))
  930.      { if(argc<1) error(E_ARG);
  931.        DPI_SET=1;
  932.        if((sscanf(*argv,SSFLTPT,&PRINTER_XDPI))!=1) error(E_ARG);
  933.        if(PRINTER_XDPI <= 0.0) error(E_OPT);
  934.        PRINTER_YDPI=PRINTER_XDPI;
  935.        ASKIP;
  936.        continue;
  937.      }
  938.  
  939.     if(!strcmp(opt,"fak" ))
  940.      { if(argc<1) error(E_ARG);
  941.        FAK_SET=1;
  942.        if((sscanf(*argv,SSFLTPT,&PRINTER_FAK))!=1) error(E_ARG);
  943.        if(PRINTER_FAK <= 0.0) error(E_OPT);
  944.        if(PRINTER_FAK >  1000.0) error(E_OPT);
  945.        ASKIP;
  946.        continue;
  947.      }
  948.  
  949.  
  950.  
  951. /**** Color model options ****/
  952.  
  953.     if(!strcmp(opt,"c0"))
  954.      { if (corrmode == C_UNSPEC) corrmode = C_LINEAR;
  955.        else error(E_ARG);
  956.        continue;
  957.      }
  958.  
  959.     if(!strcmp(opt,"c-"))
  960.      { if (corrmode == C_UNSPEC) corrmode = C_DARK;
  961.        else error(E_ARG);
  962.        continue;
  963.      }
  964.  
  965.     if(!strcmp(opt,"c+"))
  966.      { if (corrmode == C_UNSPEC) corrmode = C_BRIGHT;
  967.        else error(E_ARG);
  968.        continue;
  969.      }
  970.  
  971.  
  972. /**** Subrectangel option ****/
  973.  
  974.     if(!strcmp(opt,"S"))
  975.      { if (suba1) error(E_ARG);
  976.        if(argc<2) error(E_ARG);
  977.        suba1=argv[0];
  978.        ASKIP;
  979.        suba2=argv[0];
  980.        ASKIP;
  981.        continue;
  982.      }
  983.  
  984.  
  985. /**** Resolution options ****/
  986.  
  987.     if((!strcmp(opt,"Base/16")) || (!strcmp(opt,"1"))  || (!strcmp(opt,"128x192")))
  988.      { if (size == S_UNSPEC) size = S_Base16;
  989.        else error(E_ARG);
  990.        continue;
  991.      }
  992.     if((!strcmp(opt,"Base/4" )) || (!strcmp(opt,"2"))  || (!strcmp(opt,"256x384")))
  993.      { if (size == S_UNSPEC) size = S_Base4;
  994.        else error(E_ARG);
  995.        continue;
  996.      }
  997.     if((!strcmp(opt,"Base"   )) || (!strcmp(opt,"3"))  || (!strcmp(opt,"512x768")))
  998.      { if (size == S_UNSPEC) size = S_Base;
  999.        else error(E_ARG);
  1000.        continue;
  1001.      }
  1002.     if((!strcmp(opt,"4Base"  )) || (!strcmp(opt,"4"))  || (!strcmp(opt,"1024x1536")))
  1003.      { if (size == S_UNSPEC) size = S_4Base;
  1004.        else error(E_ARG);
  1005.        continue;
  1006.      }
  1007.     if((!strcmp(opt,"16Base" )) || (!strcmp(opt,"5"))  || (!strcmp(opt,"2048x3072")))
  1008.      { if (size == S_UNSPEC) size = S_16Base;
  1009.        else error(E_ARG);
  1010.        continue;
  1011.      }
  1012.  
  1013.     if((!strcmp(opt,"64Base" )) || (!strcmp(opt,"6"))  || (!strcmp(opt,"4096x6144")))
  1014.      { if (size == S_UNSPEC) size = S_64Base;
  1015.        else error(E_ARG);
  1016.  
  1017.        if(argc<1) error(E_ARG);
  1018.        dir64=argv[0];
  1019.        ASKIP;
  1020.        continue;
  1021.      }
  1022.  
  1023.     if((!strcmp(opt,"Overview" )) || (!strcmp(opt,"0"))  || (!strcmp(opt,"O")))
  1024.      { if (size == S_UNSPEC) size = S_Over;
  1025.        else error(E_ARG);
  1026.        continue;
  1027.      }
  1028.  
  1029.     if((!strcmp(opt,"Contact" )) || (!strcmp(opt,"C")))
  1030.      { if (size == S_UNSPEC) size = S_Contact;
  1031.        else error(E_ARG);
  1032.        if(argc<2) error(E_ARG);
  1033.        if((sscanf(*argv,"%d",&contsize))!=1) error(E_ARG);
  1034.        ASKIP;
  1035.        if     (!strcmp(*argv,"n")) contori=T_NONE;
  1036.        else if(!strcmp(*argv,"r")) contori=T_RIGHT;
  1037.        else if(!strcmp(*argv,"l")) contori=T_LEFT;
  1038.        else if(!strcmp(*argv,"h")) contori=T_HEAD;
  1039.        else error(E_ARG);
  1040.        ASKIP;
  1041.  
  1042.        continue;
  1043.      }
  1044.  
  1045.    fprintf(stderr,"Unknown option: -%s\n",opt);
  1046.    error(E_ARG);
  1047.    }
  1048.  
  1049.  
  1050.   if(argc<1) error(E_ARG);
  1051.   pcdname= *argv;
  1052.   ASKIP;
  1053.  
  1054.   if(argc>0)
  1055.    {ppmname= *argv;
  1056.     ASKIP;
  1057.    }
  1058.  
  1059.   if(argc>0) error(E_ARG);
  1060.  
  1061.  
  1062.  }
  1063. #undef ASKIP
  1064.  
  1065.  
  1066.  
  1067. static void checkin(void)
  1068.  {
  1069.    if (do_info || (turn==T_AUTO))
  1070.      { SEEK(1);
  1071.        EREADBUF;
  1072.      }
  1073.  
  1074.     if(turn==T_AUTO)
  1075.      {
  1076.       switch(sbuffer[0xe02 & 0x7ff]&0x03)
  1077.        {case 0x00: turn=T_NONE;  break;
  1078.         case 0x01: turn=T_LEFT;  break;
  1079.         case 0x02: turn=T_HEAD;  break;
  1080.         case 0x03: turn=T_RIGHT; break;
  1081.         default: error(E_TCANT);
  1082.        }
  1083.       }
  1084.  
  1085.     if(do_info) druckeid();
  1086.  
  1087.  }
  1088.  
  1089.  
  1090.  
  1091. /************************** file access functions **************/
  1092.  
  1093. int READ(uBYTE *ptr,int n)
  1094.  {int d;
  1095.   if(!n) return 1;
  1096.   bufpos+=n;
  1097.   for(;;)
  1098.    {d=fread((char *)ptr,1,n,fin);
  1099.     if(d<1) return 0;
  1100.     n-=d;
  1101.     if (!n) break;
  1102.     ptr+=d;
  1103.    }
  1104.   return 1;
  1105.  }
  1106.  
  1107. static int friss(int n)
  1108.  {int d;
  1109.  
  1110.   while(n>0)
  1111.    {
  1112.     d= n>sizeof(sbuffer) ? sizeof(sbuffer) : n;
  1113.     n-=d;
  1114.     if(READ(sbuffer,d) !=1) return 1;
  1115.    }
  1116.  
  1117.   return 0;
  1118.  }
  1119.  
  1120.  
  1121. void SEEK(int x)
  1122.  {
  1123.   x *= SECSIZE;
  1124.   if(x<bufpos) error(E_INTERN);
  1125.   if(x==bufpos) return;
  1126.  
  1127.   if(emulate_seek)
  1128.    {if(friss(x-bufpos)) error(E_READ);
  1129.     if(x!=bufpos) error(E_INTERN);
  1130.    }
  1131.   else
  1132.    {bufpos=x;
  1133.     if (fseek(fin,x,0)) error(E_READ);
  1134.    }
  1135. #ifdef DEBUG
  1136.   fprintf(stderr,"S-Position %x\n",bufpos);
  1137. #endif
  1138.  
  1139.  }
  1140.  
  1141.  
  1142.  
  1143. int SKIPn(int n)
  1144.  {
  1145.   if(!n) return 0;
  1146.   if(n<0) error(E_INTERN);
  1147.  
  1148.   if(emulate_seek)
  1149.    {return friss(n);
  1150.    }
  1151.   else
  1152.    {bufpos+=n;
  1153.     return fseek(fin,(n),1);
  1154.    }
  1155.  }
  1156.  
  1157.  
  1158.  
  1159.  
  1160.  
  1161. /************************** size control functions **************/
  1162.  
  1163. #define ISDIGIT(x) (((x)>='0') && ((x)<='9'))
  1164.  
  1165. static void number(char **s,char **i,char **f)
  1166.  {char *p;
  1167.  
  1168.   p= *s;
  1169.   (*i)=(*f)=0;
  1170.  
  1171.   if(!ISDIGIT(*p)) error(E_SUBR);
  1172.   while(ISDIGIT(*p)) p++;
  1173.   if(*p != '.')
  1174.    { *i=*s;
  1175.      *s=p;
  1176.      return;
  1177.    }
  1178.   p++;
  1179.   if(!ISDIGIT(*p)) error(E_SUBR);
  1180.   while(ISDIGIT(*p)) p++;
  1181.   *f=*s;
  1182.   *s=p;
  1183.  }
  1184.  
  1185. static sdim makedim(sdim full,char *i,char *f)
  1186.  {sdim val;
  1187.   FLTPT fl;
  1188.  
  1189.   if(i)
  1190.    {if(f) error(E_INTERN);
  1191.     if(sscanf(i,"%u",&val) != 1) error(E_SUBR);
  1192.     if((val<0) || (val >full)) error(E_SUBR);
  1193.     return val;
  1194.    }
  1195.   else
  1196.    {if(!f) error(E_INTERN);
  1197.     if(sscanf(f,SSFLTPT,&fl) != 1) error(E_SUBR);
  1198.     if((fl < 0.0) || (fl > 1.0)) error(E_SUBR);
  1199.     val= full * fl + 0.5;
  1200.     return val;
  1201.    }
  1202.  }
  1203.  
  1204. /*
  1205. #define xsMASK (~7)
  1206. #define sMASK (~15)
  1207. */
  1208. static void sizealign(char *str,dim full,
  1209.                       dim *rdoff,dim *rdlen,dim *imoff,dim *imlen,dim sMASK)
  1210.  {char *i1,*f1,*tr,*i2,*f2,*ptr;
  1211.   int vonbis=0;
  1212.   sdim von,len,rest;
  1213.  
  1214.   i1=f1=tr=i2=f2=0;
  1215.  
  1216.   ptr=str;
  1217.   number(&ptr,&i1,&f1);
  1218.  
  1219.   if(*ptr == '-') vonbis=1;
  1220.   else if (*ptr == '+') vonbis=0;
  1221.   else error(E_SUBR);
  1222.   ptr++;
  1223.  
  1224.   number(&ptr,&i2,&f2);
  1225.   if(*ptr) error(E_SUBR);
  1226.  
  1227.   von=makedim(full,i1,f1);
  1228.   len=makedim(full,i2,f2);
  1229.   if(vonbis) len-=von;
  1230.   rest=full-von-len;
  1231.  
  1232.   if((von<0) || (len<1) || (rest<0)) error(E_SUBR);
  1233.  
  1234.   *imlen = (dim) len;
  1235.  
  1236.   *rdoff = (dim) (von & sMASK);
  1237.   *rdlen = full - *rdoff - ((dim)( rest & sMASK) );
  1238.  
  1239.   *imoff = ((dim) von) - *rdoff;
  1240.  
  1241.  }
  1242.  
  1243.  
  1244. static void sizecontrol(sizeinfo *si,dim w,dim h,dim sMASK)
  1245.  {
  1246.   si->w=w;
  1247.   si->h=h;
  1248.  
  1249.   if(!suba1)
  1250.    {
  1251.     si->rdhlen=w;
  1252.     si->rdvlen=h;
  1253.     si->rdhoff=0;
  1254.     si->rdvoff=0;
  1255.     si->imhlen=0;
  1256.     si->imvlen=0;
  1257.     si->imhoff=0;
  1258.     si->imvoff=0;
  1259.    }
  1260.   else
  1261.    {sizealign(suba1,w,&si->rdhoff,&si->rdhlen,&si->imhoff,&si->imhlen,sMASK);
  1262.     sizealign(suba2,h,&si->rdvoff,&si->rdvlen,&si->imvoff,&si->imvlen,sMASK);
  1263.    }
  1264.  
  1265. #ifdef DEBUG
  1266.   fprintf(stderr,"Align: %5d %5d \n",si->w,si->h);
  1267.   fprintf(stderr,"Align: %5d %5d %5d %5d \n",si->rdhoff,si->rdhlen,si->rdvoff,si->rdvlen);
  1268.   fprintf(stderr,"Align: %5d %5d %5d %5d \n",si->imhoff,si->imhlen,si->imvoff,si->imvlen);
  1269. #endif
  1270.  
  1271.  }
  1272.  
  1273.