home *** CD-ROM | disk | FTP | other *** search
/ Dream 45 / Amiga_Dream_45.iso / Atari / Graphics / img2ps.lzh / IMG2PS / IMG2PS.C < prev    next >
C/C++ Source or Header  |  1994-12-31  |  3KB  |  131 lines

  1. #include <tos.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5.  
  6. #include <image.h>
  7.  
  8. IMG_HEADER head;
  9. MFDB picture;
  10.  
  11. void do_output_data(FILE *file)
  12. {
  13. int i,j;
  14. char *l;
  15. char str[258];
  16.  
  17.     for ( i=0; i<picture.fd_h; i++ ) {
  18.         l=(char*)picture.fd_addr+picture.fd_wdwidth*2l*i;
  19.         for ( j=0; j<picture.fd_w; j+=8,l++ ) {
  20.             sprintf(str+j/4,"%02x",~*l);
  21.         }
  22.         fprintf(file,str);
  23.         fprintf(file,"\n");
  24.     }
  25. }
  26.  
  27. int main(int argc,char *argv[])
  28. {
  29. char out[256],*c;
  30. FILE *file;
  31. double x,y,w,h;
  32.  
  33.     printf("img2ps V0.1 (%s) by Th. Morus Walter\n",__DATE__);
  34.     if ( argc!=3 ) {
  35.         printf(" usage: img2ps infile outfile\n");
  36.         printf(" thanx to John Bradley for XV\n\n");
  37.         return 1;
  38.     }
  39.  
  40.     printf("reading %s ...\n",argv[1]);
  41.     if ( xload_img(&head,argv[1],&picture)!=IMG_OK ) {
  42.         printf("load-error: img2ps aborts\n");
  43.         return 1;
  44.     }
  45.     if ( picture.fd_nplanes!=1 ) {
  46.         printf("error: can't handle color images\n");
  47.         return 1;
  48.     }
  49.     if ( picture.fd_w>1024 ) {
  50.         printf("error: picture width too large\n");
  51.         return 1;
  52.     }
  53.  
  54.     strcpy(out,argv[2]);
  55.     c=strrchr(out,'.');
  56.     if ( c!=0 )
  57.         strcpy(c+1,"ps");
  58.  
  59.     printf("writing %s ...\n",out);
  60.  
  61.     w=picture.fd_w;
  62.     w*=head.pix_wid;
  63.     h=picture.fd_h;
  64.     h*=head.pix_hght;
  65.     w/=25400.0/72.0;
  66.     h/=25400.0/72.0;
  67.     x=(612.0-w)/2;        /* 612/72" papierbreite */
  68.     y=(792.0-h)/2;        /* 792/72" papierhöhe */
  69.  
  70.     file=fopen(out,"w");
  71.     if ( file ) {
  72.         fprintf(file,"%%!PS-Adobe-2.0 EPSF-2.0\n");
  73.         fprintf(file,"%%%%Title: %s\n",out);
  74.         fprintf(file,"%%%%Creator: img2ps V0.1 %s by Th. Morus Walter\n",__DATE__);
  75.         fprintf(file,"%%%%BoundingBox: %d %d %d %d\n",(int)(x+.5),(int)(y+.5),(int)(x+w+.5),(int)(y+h+.5));
  76.         fprintf(file,"%%%%Pages: 1\n");
  77.         fprintf(file,"%%%%DocumentFonts:\n");
  78.         fprintf(file,"%%%%EndComments\n");
  79.         fprintf(file,"%%%%EndProlog\n");
  80.         fprintf(file,"\n");
  81.         fprintf(file,"%%%%Page: 1 1\n");
  82.         fprintf(file,"\n");
  83.         fprintf(file,"%% remember original state\n");
  84.         fprintf(file,"/origstate save def\n");
  85.         fprintf(file,"\n");
  86.         fprintf(file,"%% build a temporary dictionary\n");
  87.         fprintf(file,"20 dict begin\n");
  88.         fprintf(file,"\n");
  89.         fprintf(file,"%% define string to hold a scanline's worth of data\n");
  90.         fprintf(file,"/pix %d string def\n",(picture.fd_w+7)/8);
  91.         fprintf(file,"\n");
  92.         fprintf(file,"%% lower left corner\n");
  93.         fprintf(file,"%d %d translate\n",(int)(x+.5),(int)(y+.5));
  94.         fprintf(file,"\n");
  95.         fprintf(file,"%% size of image (on paper, in 1/72inch coords)\n");
  96.         fprintf(file,"%lf %lf scale\n",w,h);
  97.  
  98.         fprintf(file,"\n");
  99.         fprintf(file,"%% dimensions of data\n");
  100.         fprintf(file,"%d %d %d\n",picture.fd_w,picture.fd_h,picture.fd_nplanes);
  101.         fprintf(file,"\n");
  102.         fprintf(file,"%% mapping matrix\n");
  103.         fprintf(file,"[%d %d %d %d %d %d]\n",picture.fd_w,0,0,-picture.fd_h,0,picture.fd_h);
  104.         fprintf(file,"\n");
  105.  
  106.         fprintf(file,"{currentfile pix readhexstring pop}\n");
  107.         fprintf(file,"image\n");
  108.  
  109.         do_output_data(file);
  110.  
  111.         fprintf(file,"\n");
  112.         fprintf(file,"showpage\n");
  113.  
  114.         fprintf(file,"\n");
  115.         fprintf(file,"%% stop using temporary dictionary\n");
  116.         fprintf(file,"end\n");
  117.  
  118.         fprintf(file,"\n");
  119.         fprintf(file,"%% restore original state\n");
  120.         fprintf(file,"origstate restore\n");
  121.  
  122.         fprintf(file,"\n");
  123.         fprintf(file,"%%%% Trailer\n");
  124.         fclose(file);
  125.     }
  126.  
  127.     free(picture.fd_addr);
  128.     return 0;
  129. }
  130.  
  131.