home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 580a.lha / HDFView_v3.01 / source.LZH / source / src / DumpPS.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-11-20  |  4.5 KB  |  175 lines

  1. #include <exec/types.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <intuition/intuition.h>
  5. #include <libraries/dos.h>
  6.  
  7. #include <proto/dos.h>
  8. #include <proto/intuition.h>
  9. #include <proto/graphics.h>
  10.  
  11.  
  12. #include "View_define.h"
  13. #include "Viewprotos.h"
  14.  
  15. #define PWWIDTH 600
  16. #define PWHEIGHT 26
  17.  
  18. /* NewWindow structure for progress window */
  19.  
  20. struct NewWindow PNW = 
  21. {
  22.    20, 40,
  23.    PWWIDTH, PWHEIGHT,
  24.    2, 1,
  25.    NULL,
  26.    WINDOWDEPTH|WINDOWDRAG|SMART_REFRESH,
  27.    NULL,
  28.    NULL,
  29.    "Printing Progress",
  30.    NULL,
  31.    NULL,
  32.    0,0,
  33.    0,0,
  34.    CUSTOMSCREEN
  35. };   
  36.  
  37. struct Window *progwin=NULL;
  38.  
  39. extern float min, max;
  40. extern struct Screen *gScreen;
  41. extern char hdfdirname[81];
  42. extern char hdffilename[81];
  43.  
  44. int
  45. DumpPS(unsigned char *Image,int width, int height,
  46.           char *filename)
  47. {
  48.    register int i;
  49.    FILE *fp=NULL;
  50.    char  *buffer;
  51.    char  buffer2[81];
  52.    BOOL ret;
  53.    int extras;
  54.    unsigned char *imadr;
  55.  
  56.    scrollUp(gScreen,10);
  57.    strcpy(buffer2,hdffilename);
  58.    strcat(buffer2,".ps");
  59.    
  60.    if(!(buffer=getFilename(buffer2,hdfdirname,
  61.          "Save to PS File...","#?.ps")))
  62.    {
  63.       scrollDown(gScreen,180);
  64.       return(0);
  65.    }
  66.    fp = fopen(buffer,"w");
  67.    if(fp==NULL) {
  68.       request("Can't open file for writing!",NULL);
  69.       scrollDown(gScreen,180);
  70.       return(0);
  71.       }
  72.    
  73.    PNW.Screen = gScreen;
  74.    progwin = OpenWindow(&PNW);
  75.    if(progwin==NULL) {
  76.       request("Error: Can't open print window", NULL);
  77.       scrollDown(gScreen,180);
  78.       return(0);
  79.       }
  80.    
  81.       
  82.    scrollDown(gScreen,140);
  83.    SetAPen(progwin->RPort,2);
  84.    RectFill(progwin->RPort,5,12,594,22);
  85.    
  86.    fprintf(fp,"%%!\n\n");
  87.    fprintf(fp,"/inch { 72 mul } def\n");
  88.    fprintf(fp,"/myxoffset { .75 inch } def\n");
  89.    fprintf(fp,"/myyoffset { 2.0 inch } def\n");
  90.    fprintf(fp,"/myxsize { 7 inch } def\n");
  91.    fprintf(fp,"/myysize { 7 inch } def\n");
  92.    fprintf(fp,"/negmyxsize { -7 inch } def\n\n");               
  93.    fprintf(fp,"/picstr %d string def\n",width);
  94.    fprintf(fp,"/sclstr 256 string def\n\n");
  95.    fprintf(fp,"/Times-Bold findfont 12 scalefont setfont\n");
  96.    fprintf(fp,"1 inch 1 inch moveto\n");
  97.    fprintf(fp,"(%s) show\n",filename);
  98.  if(max>min)
  99.  {  
  100.    fprintf(fp,".75 inch 9.5 inch moveto");
  101.    fprintf(fp,"(Min: %3.2e) show\n",min);
  102.    fprintf(fp,"6.5 inch 9.5 inch moveto");
  103.    fprintf(fp,"(Max: %3.2e) show\n",max);
  104.  } 
  105.    fprintf(fp,"newpath\n");
  106.    fprintf(fp,"myxoffset  myyoffset moveto\n");
  107.    fprintf(fp,"myxsize    0         rlineto\n");
  108.    fprintf(fp,"0          myysize   rlineto\n");
  109.    fprintf(fp,"negmyxsize 0         rlineto\n");
  110.    fprintf(fp,"closepath\n2 setlinewidth\nstroke\n\n");
  111.    
  112.    fprintf(fp,"myxoffset myyoffset translate\n");
  113.    fprintf(fp,"myxsize myysize scale\n\n");
  114.    fprintf(fp,"%d %d 8\n",width,height);
  115.    fprintf(fp,"[%d 0 0 -%d 0 %d]\n",width,height,height);
  116.    fprintf(fp,"{currentfile\n picstr readhexstring pop}\nimage\n");
  117.       
  118.    SetAPen(progwin->RPort,3);
  119.    extras = (width*height)%16;
  120.    for(i=0;i<=width*height-16;i+=16)
  121.    {
  122.       imadr = Image+i;
  123.       fprintf(fp,"%02.2x%02.2x%02.2x%02.2x%02.2x%02.2x%02.2x%02.2x%02.2x%02.2x%02.2x%02.2x%02.2x%02.2x%02.2x%02.2x\n",
  124.                             255- *(imadr),
  125.                             255- *(imadr+1),
  126.                             255- *(imadr+2),
  127.                             255- *(imadr+3),
  128.                             255- *(imadr+4),
  129.                             255- *(imadr+5),
  130.                             255- *(imadr+6),
  131.                             255- *(imadr+7),
  132.                             255- *(imadr+8),
  133.                             255- *(imadr+9),
  134.                             255- *(imadr+10),
  135.                             255- *(imadr+11),
  136.                             255- *(imadr+12),
  137.                             255- *(imadr+13),
  138.                             255- *(imadr+14),
  139.                             255- *(imadr+15)
  140.                             );
  141.           RectFill(progwin->RPort,5,
  142.             12,i*594/(width*height),22);
  143.    }
  144.    for(i=width*height-extras;i<width*height;i++)
  145.    {
  146.       fprintf(fp,"%02.2x",255- (*(Image+i)));
  147.    }
  148.    fprintf(fp,"\n");
  149.  
  150.  
  151.    fprintf(fp,"0 1.1 translate\n");
  152.    fprintf(fp,"1 0.075 scale \n\n");
  153.    
  154.    fprintf(fp,"256 1 8\n");
  155.    fprintf(fp,"[256 0 0 1 0 0]\n");
  156.    fprintf(fp,"{currentfile\n sclstr readhexstring pop}\nimage\n");
  157.    for(i=255;i>=0;i--)
  158.    {
  159.       fprintf(fp,"%02.2x",i);
  160.       if((i%16)==0) fprintf(fp,"\n");                         
  161.    }
  162.    fprintf(fp,"showpage\n");
  163.    fprintf(fp,"\n");
  164.    
  165.    
  166.    fclose(fp);
  167.    
  168.    
  169.    scrollDown(gScreen,180);
  170.    CloseWindow(progwin);
  171.  
  172.    return(1);  
  173. }
  174.    
  175.