IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Dec 27, 2006, 9:11:44 AM (20 years ago)
Author:
eugene
Message:

support for multipage plots, moved ConvertPixmap functions to separate file

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/kii/button/PSit.c

    r5852 r10838  
    11# include "Ximage.h"
    2 /* Notice: we are using a fixed border size of 10 pt */
    3 void ConvertPixmap8  (Layout *layout, FILE *f);
    4 void ConvertPixmap16 (Layout *layout, FILE *f);
    5 void ConvertPixmap24 (Layout *layout, FILE *f);
    6 void ConvertPixmap32 (Layout *layout, FILE *f);
     2# define PADDING 10
     3# define XOFFSET 60
     4# define YOFFSET 60
     5
     6static char *name = "$Name: not supported by cvs2svn $";
    77
    88int PSit (Graphic *graphic, Layout *layout, int Raw) {
    99 
    1010  FILE *f;
    11   int i;
     11  int i, pageMode, scaleMode;
    1212  double scale;
    13   char filename[1024];
     13  char filename[1024], pagename[1024], *version;
    1414  int Nbytes, status;
    1515
    1616  /* expect a line telling the number of bytes and a filename */
    17   status = read (layout[0].Ximage, filename, 16);
    18   filename[16] = 0;
    19   sscanf (filename, "%*s %d", &Nbytes);
    20   status = read (layout[0].Ximage, filename, Nbytes);
    21   filename[status] = 0; /* make the string easy to parse */
     17  KiiScanMessage (layout[0].Ximage, "%s %s %d %d", filename, pagename, &scaleMode, &pageMode);
    2218
    23   f = fopen (filename, "w");
     19  if (pageMode == KAPA_PS_NEWPAGE) {
     20    f = fopen (filename, "a+");
     21  } else {
     22    f = fopen (filename, "w");
     23  }
    2424  if (f == (FILE *) NULL) {
    2525    fprintf (stderr, "failed to open %s for output\n", filename);
     
    3232  }
    3333
    34   scale = MIN ((500.0/(double)layout[0].picture.dx), (700.0/(double)layout[0].picture.dy));
    35   if (!Raw) {
    36     fprintf (f, "%%!PS-Adobe-2.0 EPSF-2.0\n");
    37     fprintf (f, "%%%%Title: %s\n", layout[0].file);
    38     fprintf (f, "%%%%Creator: Ki'i (0.95)\n");
    39     fprintf (f, "%%%%BoundingBox: 10 40 %d %d \n", (int)(scale*layout[0].picture.dx + 30), (int)(scale*layout[0].picture.dy + 60));
    40     fprintf (f, "%%%%Pages: 1\n");
    41     fprintf (f, "%%%%DocumentFonts:\n");
    42     fprintf (f, "%%%%EndComments\n");
    43     fprintf (f, "%%%%EndProlog\n");
    44     fprintf (f, "%%%%Page: 1 1\n\n");
     34  if (scaleMode) {
     35    scale = MIN ((500.0/(double)layout[0].picture.dx), (700.0/(double)layout[0].picture.dy));
     36  } else {
     37    scale = 72.0 / 96.0; /* ratio of screen pixels to points */
     38  }
    4539
    46   }
     40  switch (pageMode) {
     41    case KAPA_PS_NEWPLOT:
     42      fprintf (f, "%%!PS-Adobe-2.0 EPSF-2.0\n");
     43      fprintf (f, "%%%%Title: %s\n", filename);
     44      version = strip_version (name);
     45      fprintf (f, "%%%%Creator: Ki'i (%s)\n", version);
     46      free (version);
     47      fprintf (f, "%%%%BoundingBox: %d %d %.0f %.0f\n",
     48               XOFFSET - PADDING, YOFFSET - PADDING,
     49               scale*layout[0].picture.dx + PADDING + XOFFSET,
     50               scale*layout[0].picture.dy + PADDING + YOFFSET);
     51      fprintf (f, "%%%%Pages: 1\n");
     52      fprintf (f, "%%%%DocumentFonts:\n");
     53      fprintf (f, "%%%%EndComments\n");
     54      fprintf (f, "%%%%EndProlog\n");
     55      fprintf (f, "%%%%Page: %s\n\n", pagename);
     56      break;
     57
     58    case KAPA_PS_NEWPAGE:
     59      fprintf (f, "%%%%Page: %s\n\n", pagename);
     60      break;
     61
     62    case KAPA_PS_RAWPAGE:
     63      break;
     64  }
    4765
    4866  fprintf (f, "gsave %% encloses picture\n");
     
    5573  fprintf (f, "/L {newpath moveto lineto stroke} def\n\n");
    5674
    57   if (!Raw) {
    58     fprintf (f, " 20 50 translate\n");
     75  if (pageMode != KAPA_PS_RAWPAGE) {
     76    fprintf (f, " %d %d translate\n", XOFFSET, YOFFSET);
    5977    fprintf (f, "  %f  %f scale\n", scale, scale);
    6078  }
     
    105123  fprintf (f, "grestore %% end of picture\n");
    106124
    107   if (!Raw) fprintf (f, "showpage\n");
     125  if (pageMode != KAPA_PS_RAWPAGE) fprintf (f, "showpage\n");
    108126
    109127  fclose (f);
     
    113131}
    114132
    115 # if (0)
    116 void ConvertPixmap (Layout *layout, File *f) {
    117  
    118   /* set up expansions */
    119   expand = expand_in = expand_out = 1.0;
    120   if (layout[0].expand == 0)
    121     layout[0].expand = 1;
    122   if (layout[0].expand > 0) {
    123     expand = 1 / (1.0*layout[0].expand);
    124     expand_out = layout[0].expand;
    125     expand_in  = 1;
    126   }
    127   if (layout[0].expand < 0) {
    128     expand = fabs((double)layout[0].expand);
    129     expand_out = 1;
    130     expand_in  = -layout[0].expand;
    131   }
    132 
    133   dx = layout[0].picture.dx;
    134   dy = layout[0].picture.dy;
    135   DX = layout[0].matrix.Naxis[0];
    136   DY = layout[0].matrix.Naxis[1];
    137 
    138   /* X,Y are the image coordinates of the first image pixel */
    139   X = MAX(0.5*(DX - dx*expand) - layout[0].X, 0);
    140   if ((int)X != X)
    141     X = (int) X + 1;
    142   else
    143     X = (int) X;
    144   Y = MAX(0.5*(DY - dy*expand) - layout[0].Y, 0);
    145   if ((int)Y != Y)
    146     Y = (int) Y + 1;
    147   else
    148     Y = (int) Y;
    149 
    150   /* Rx,Ry are the screen coordinates of the first image pixel */
    151   Rx = (X + layout[0].X - 0.5*DX)/expand + 0.5*dx;
    152   Ry = (Y + layout[0].Y - 0.5*DY)/expand + 0.5*dy;
    153 
    154   i_start = MIN (MAX (Rx, 0), dx - expand_out + 1);
    155   j_start = MIN (MAX (Ry, 0), dy - expand_out + 1);
    156  
    157   if (layout[0].expand > 0) {
    158     i_end = MAX (MIN (i_start + ((int)(expand*(dx-i_start)))/expand, expand_out*(DX-X) + Rx), 0);
    159     j_end = MAX (MIN (j_start + ((int)(expand*(dy-j_start)))/expand, expand_out*(DY-Y) + Ry), 0);
    160   } else {
    161     i_end = MAX (MIN (dx, (DX-X)/expand + Rx), 0);
    162     j_end = MAX (MIN (dy, (DY-Y)/expand + Ry), 0);
    163   }   
    164 
    165   dropback = expand_out - (i_end - i_start) % expand_out;
    166   if ((i_end - i_start) % expand_out == 0) dropback = 0;
    167 
    168   /* output line buffer */
    169   ALLOCATE (line_buffer, char, dx);
    170 
    171   in_pix_ref  = (unsigned char *) (layout[0].matrix.buffer) + DX*(int)MAX(Y,0) + (int)MAX(X,0);
    172 
    173   /********** below we do the mapping from buffer pixels (in) to picture pixels (out) **********/
    174 
    175   Nchar = 255.0;
    176   Npix = layout[0].Npixels;
    177   frac = Nchar / Npix;
    178 
    179   /**** fill in bottom area ****/
    180   out_pix = line_buffer;
    181   for (i = 0; i < dx; i++, out_pix++) {
    182     *out_pix = WHITE;
    183   }
    184   for (j = 0; j < j_start; j++) {
    185     for (i = 0; i < dx; i++) {
    186       fprintf (f, "%02x", val);
    187       if ((Npt % 40) == 0) {
    188         fprintf (f, "\n");
    189       }
    190     }
    191   }
    192  
    193   /*** fill in the image data region ***/
    194   for (j = j_start; j < j_end; j+= expand_out, in_pix_ref += expand_in*DX) {
    195    
    196     /* create one output image line */
    197     in_pix = in_pix_ref;
    198     out_pix = line_buffer;
    199 
    200     /**** fill in area to the left of the picture ****/
    201     for (i = 0; i < i_start; i++, out_pix+=3) {
    202       *out_pix = WHITE;
    203     }
    204    
    205     /*** fill in the picture region ***/
    206     for (i = i_start; i < i_end; i+=expand_out, in_pix+=expand_in) {
    207       for (ii = 0; ii < expand_out; ii++, out_pix++) {
    208         *out_pix = *in_pix*frac;
    209       }
    210     }
    211    
    212     /**** fill in area to the right of the picture ****/
    213     for (i = i_end; i < dx; i++, out_pix++) {
    214       *out_pix = WHITE;
    215     }
    216 
    217     /* write out the image line expand_out times */
    218     for (j = 0; j < expand_out; j++) {
    219       for (i = 0; i < dx; i++) {
    220         fprintf (f, "%02x", val);
    221         if ((Npt % 40) == 0) {
    222           fprintf (f, "\n");
    223         }
    224       }
    225     }
    226   }
    227 
    228   /**** fill in top area ****/
    229   out_pix = line_buffer;
    230   for (i = 0; i < dx; i++, out_pix++) {
    231     *out_pix = WHITE;
    232   }
    233   for (j = j_end; j < dy; j++) {
    234     for (i = 0; i < dx; i++) {
    235       fprintf (f, "%02x", val);
    236       if ((Npt % 40) == 0) {
    237         fprintf (f, "\n");
    238       }
    239     }
    240   }
    241 }
    242 # endif
    243 
    244 void ConvertPixmap8 (Layout *layout, FILE *f) {
    245 
    246   int i, k, m, val;
    247   double Nchar, Npix, start, slope, frac;
    248   unsigned char *buff;
    249 
    250   Nchar = 255.0;
    251   Npix = layout[0].Npixels;
    252   frac = Nchar / Npix;
    253   /* start at the last line, print lines in decending order */
    254   buff = (unsigned char *)layout[0].picture.data + layout[0].picture.dx*(layout[0].picture.dy - 1);
    255   slope = layout[0].slope;
    256   start = layout[0].start;
    257 
    258   for (i = 0; i < layout[0].picture.dy; i++) {
    259     for (k = 0; k < layout[0].picture.dx; k++, buff++) {
    260       if (*buff == layout[0].white)
    261         val = Nchar;
    262       else {
    263         for (m = 0; (layout[0].cmap[m].pixel != *buff) && (m < Npix); m++);
    264         val = Nchar - frac * MIN (MAX (start + m * slope, 0), Npix);
    265       }
    266       fprintf (f, "%02x", val);
    267       if (!((k+1) % 40)) fprintf (f, "\n");
    268     }
    269     fprintf (f, "\n");
    270     buff -= 2*layout[0].picture.dx;
    271   }
    272   return;
    273 }
    274 
    275 void ConvertPixmap16 (Layout *layout, FILE *f) {
    276 
    277   int i, k, m, val;
    278   double Nchar, Npix, start, slope, frac;
    279   unsigned short *buff;
    280 
    281   Nchar = 255.0;
    282   Npix = layout[0].Npixels;
    283   frac = Nchar / Npix;
    284   /* start at the last line, print lines in decending order */
    285   buff = (unsigned short *)layout[0].picture.data + layout[0].picture.dx*(layout[0].picture.dy - 1);
    286   slope = layout[0].slope;
    287   start = layout[0].start;
    288 
    289   for (i = 0; i < layout[0].picture.dy; i++) {
    290     for (k = 0; k < layout[0].picture.dx; k++, buff++) {
    291       if (*buff == layout[0].white)
    292         val = Nchar;
    293       else {
    294         for (m = 0; (layout[0].cmap[m].pixel != *buff) && (m < Npix); m++);
    295         val = Nchar - frac * MIN (MAX (start + m * slope, 0), Npix);
    296       }
    297       fprintf (f, "%02x", val);
    298       if (!((k+1) % 40)) fprintf (f, "\n");
    299     }
    300     fprintf (f, "\n");
    301     buff -= 2*layout[0].picture.dx;
    302   }
    303   return;
    304 }
    305 
    306 void ConvertPixmap24 (Layout *layout, FILE *f) {
    307 
    308   int i, k, m, dx, dy, val, extra;
    309   unsigned char *buff;
    310   unsigned long color, byte;
    311   double Nchar, Npix, start, slope, frac;
    312 
    313   Nchar = 255.0;
    314   Npix = layout[0].Npixels;
    315   frac = Nchar / Npix;
    316   dx = layout[0].picture.dx;
    317   dy = layout[0].picture.dy;
    318   extra = 4 - (dx * 3) % 4;
    319   /* start at the last line, print lines in decending order */
    320   buff = (unsigned char *)&layout[0].picture.data[(dy - 1)*(3*dx + extra)];
    321   slope = layout[0].slope;
    322   start = layout[0].start;
    323 
    324   for (i = 0; i < dy; i++) {
    325     for (k = 0; k < dx; k++, buff+=3) {
    326       color = 0;
    327       byte = buff[2];
    328       color = (byte << 16);
    329       byte = buff[1];
    330       color |= (byte << 8);
    331       byte = buff[0];
    332       color |= byte;
    333       for (m = 0; (layout[0].cmap[m].pixel != color) && (m < Npix); m++);
    334       val = Nchar - frac * MIN (MAX (start + m * slope, 0), Npix);
    335       fprintf (f, "%02x", val);
    336       if (!((k+1) % 40)) fprintf (f, "\n");
    337     }
    338     fprintf (f, "\n");
    339     buff -= 2*3*dx + extra;
    340   }
    341   return;
    342 }
    343 
    344 void ConvertPixmap32 (Layout *layout, FILE *f) {
    345 
    346   int i, k, m, val;
    347   double Nchar, Npix, start, slope, frac;
    348   unsigned int *buff;
    349 
    350   Nchar = 255.0;
    351   Npix = layout[0].Npixels;
    352   frac = Nchar / Npix;
    353   /* start at the last line, print lines in decending order */
    354   buff = (unsigned int *)layout[0].picture.data + layout[0].picture.dx*(layout[0].picture.dy - 1);
    355   slope = layout[0].slope;
    356   start = layout[0].start;
    357 
    358   for (i = 0; i < layout[0].picture.dy; i++) {
    359     for (k = 0; k < layout[0].picture.dx; k++, buff++) {
    360       if (*buff == layout[0].white)
    361         val = Nchar;
    362       else {
    363         for (m = 0; (layout[0].cmap[m].pixel != *buff) && (m < Npix); m++);
    364         val = Nchar - frac * MIN (MAX (start + m * slope, 0), Npix);
    365       }
    366       fprintf (f, "%02x", val);
    367       if (!((k+1) % 40)) fprintf (f, "\n");
    368     }
    369     fprintf (f, "\n");
    370     buff -= 2*layout[0].picture.dx;
    371   }
    372   return;
    373 }
Note: See TracChangeset for help on using the changeset viewer.