IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Nov 17, 2011, 2:17:35 PM (15 years ago)
Author:
eugene
Message:

fix psphotStack 2nd pass (subtract 1st pass sources from the correct image); fix PS color plotting; plug a leak in psphotStack

Location:
trunk
Files:
9 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/Ohana/src/kapa2/include/prototypes.h

    r30606 r32695  
    126126void          PSPixmap24          PROTO((Graphic *graphic, KapaImageWidget *image, FILE *f));
    127127void          PSPixmap32          PROTO((Graphic *graphic, KapaImageWidget *image, FILE *f));
     128void          PSPixmap_3byte      PROTO((Graphic *graphic, KapaImageWidget *image, FILE *f));
    128129
    129130/* kapa bDraw Functions */
  • trunk/Ohana/src/kapa2/include/structures.h

    r29938 r32695  
    2626  XFontStruct   *font;
    2727  Cursor         cursor;
    28   int            x,  y;
    29   unsigned int   dx, dy;
     28  int            x,  y;       // corner coord in X world coords
     29  unsigned int   dx, dy;      // size of window in X coords
     30  int            xwin, ywin;  // corner coord of display subregion (eg, png, ps plot)
     31  int            dxwin, dywin; // corner coord of display subregion (eg, png, ps plot)
    3032  CCNode        *cube;
    3133  XColor        *cmap;
  • trunk/Ohana/src/kapa2/src/PSPixmap.c

    r16256 r32695  
    11# include "Ximage.h"
    2 
    3 // XXX this stuff has been broken by the conversion to the pixmap stuff
    42
    53void PSPixmap8 (Graphic *graphic, KapaImageWidget *image, FILE *f) {
     
    146144}
    147145
    148 # if (0)
    149 // XXX needs work!
    150 void PSPixmap32_RGB (Graphic *graphic, KapaImageWidget *image, FILE *f) {
    151 
    152   int i, k, m, val;
    153   double Nchar, Npix, start, slope, frac;
    154   unsigned int *buff;
    155   unsigned long back;
    156   unsigned char
    157 
    158   ALLOCATE (pixelR, unsigned char, graphic[0].Npixels);
    159   ALLOCATE (pixelG, unsigned char, graphic[0].Npixels);
    160   ALLOCATE (pixelB, unsigned char, graphic[0].Npixels);
     146# define WHITE_R 255
     147# define WHITE_G 255
     148# define WHITE_B 255
     149
     150void PSPixmap_3byte (Graphic *graphic, KapaImageWidget *image, FILE *f) {
     151
     152  int i, j, ii, jj;
     153  int i_start, i_end, j_start, j_end;
     154  int I_start, J_start;
     155  int dropback;  /* this is a bit of a kludge... */
     156  int dx, dy, DX, DY, inDX, inDY, Xs, Ys;
     157  int expand_in, expand_out;
     158  double expand, Ix, Iy;
     159  unsigned short *in_pix, *in_pix_ref;
     160  unsigned char *pixel1, *pixel2, *pixel3;
     161
     162  if (image == NULL) return;
     163
     164  ALLOCATE (pixel1, unsigned char, graphic[0].Npixels);
     165  ALLOCATE (pixel2, unsigned char, graphic[0].Npixels);
     166  ALLOCATE (pixel3, unsigned char, graphic[0].Npixels);
    161167
    162168  /** cmap[i].pixel must be defined even if X is not used **/
    163169  for (i = 0; i < graphic[0].Npixels; i++) { /* set up pixel array */
    164     pixelR[i] = graphic[0].cmap[i].red >> 8;
    165     pixelG[i] = graphic[0].cmap[i].green >> 8;
    166     pixelB[i] = graphic[0].cmap[i].blue >> 8;
    167   }
    168 
    169   for (i = 0; i < image[0].picture.dy; i++) {
    170     for (k = 0; k < image[0].picture.dx; k++, buff++) {
    171       if (*buff == back)
    172         val = Nchar;
    173       else {
    174         for (m = 0; (graphic[0].cmap[m].pixel != *buff) && (m < Npix); m++);
    175         val = Nchar - frac * MIN (MAX (start + m * slope, 0), Npix);
    176       }
    177       fprintf (f, "%02x", val);
    178       if (!((k+1) % 40)) fprintf (f, "\n");
    179     }
    180     fprintf (f, "\n");
    181     buff -= 2*image[0].picture.dx;
    182   }
    183   return;
    184 }
    185 # endif
     170    pixel1[i] = graphic[0].cmap[i].red >> 8;
     171    pixel2[i] = graphic[0].cmap[i].green >> 8;
     172    pixel3[i] = graphic[0].cmap[i].blue >> 8;
     173  }
     174
     175  assert ((image[0].picture.expand >= 1) || (image[0].picture.expand <= -2));
     176  expand = expand_in = expand_out = 1.0;
     177  if (image[0].picture.expand > 0) {
     178    expand = 1 / (1.0*image[0].picture.expand);
     179    expand_out = image[0].picture.expand;
     180    expand_in  = 1;
     181  }
     182  if (image[0].picture.expand < 0) {
     183    expand = fabs((double)image[0].picture.expand);
     184    expand_out = 1;
     185    expand_in  = -image[0].picture.expand;
     186  }
     187
     188  Xs = image[0].picture.x;
     189  Ys = image[0].picture.y;
     190  dx = image[0].picture.dx;
     191  dy = image[0].picture.dy;
     192  DX = image[0].image[0].matrix.Naxis[0];
     193  DY = image[0].image[0].matrix.Naxis[1];
     194
     195  // i_start, j_start are the closest lit screen pixel to 0,0
     196  // I_start, J_start are the image pixel corresponding to i_start, j_start
     197  Picture_Lower (&i_start, &j_start, &I_start, &J_start, &image[0].image[0].matrix, &image[0].picture);
     198
     199  // i_end, j_end are the closest lit screen pixel to dx, dy
     200  // I_end, J_end are the image pixel corresponding to i_end, j_end
     201  Picture_Upper (&i_end, &j_end, i_start, j_start, &image[0].image[0].matrix, &image[0].picture);
     202
     203  assert (i_start <= i_end);
     204  assert (j_start <= j_end);
     205
     206  Ix = image[0].picture.flipx ? I_start - 1 : I_start;
     207  Iy = image[0].picture.flipy ? J_start - 1 : J_start;
     208
     209  inDX = image[0].picture.flipx ? -1 : +1;
     210  inDY = image[0].picture.flipy ? -1 : +1;
     211
     212  dropback = expand_out - (i_end - i_start) % expand_out;
     213  if ((i_end - i_start) % expand_out == 0) dropback = 0;
     214
     215  in_pix_ref  = &image[0].pixmap[DX*(int)MAX(Iy,0) + (int)MAX(Ix,0)];
     216
     217  /********** below we do the mapping from buffer pixels (in) to picture pixels (out) **********/
     218
     219  // add in occasional return chars
     220
     221  /**** fill in bottom area ****/
     222  for (j = 0; j < j_start; j++) {
     223    for (i = 0; i < dx; i++) {
     224      fprintf (f, "%02x%02x%02x", WHITE_R, WHITE_G, WHITE_B);
     225    }
     226  }
     227 
     228  // probably could do this all smarter with scale operations in PS...
     229
     230  /*** fill in the image data region ***/
     231  for (j = j_start; j < j_end; j+= expand_out, in_pix_ref += inDY*expand_in*DX) {
     232   
     233    // repeat the section below 'expand_out' times
     234    for (jj = 0; jj < expand_out; jj++) {
     235
     236      /* create one output image line */
     237      in_pix = in_pix_ref;
     238
     239      /**** fill in area to the left of the picture ****/
     240      for (i = 0; i < i_start; i++) {
     241        fprintf (f, "%02x%02x%02x", WHITE_R, WHITE_G, WHITE_B);
     242      }
     243   
     244      /*** fill in the picture region ***/
     245      for (i = i_start; i < i_end; i+=expand_out, in_pix += inDX*expand_in) {
     246        for (ii = 0; ii < expand_out; ii++) {
     247          fprintf (f, "%02x%02x%02x", pixel1[*in_pix], pixel2[*in_pix], pixel3[*in_pix]);
     248        }
     249      }
     250   
     251      /**** fill in area to the right of the picture ****/
     252      for (i = i_end; i < dx; i++) {
     253        fprintf (f, "%02x%02x%02x", WHITE_R, WHITE_G, WHITE_B);
     254      }
     255    }
     256  }
     257
     258  /**** fill in top area ****/
     259  for (j = j_end; j < dy; j++) {
     260    for (i = 0; i < dx; i++) {
     261      fprintf (f, "%02x%02x%02x", WHITE_R, WHITE_G, WHITE_B);
     262    }
     263  }
     264
     265  free (pixel1);
     266  free (pixel2);
     267  free (pixel3);
     268
     269  return;
     270}
  • trunk/Ohana/src/kapa2/src/PSimage.c

    r29938 r32695  
    1313  graphic = GetGraphic();
    1414
     15  // Update this to generate color PS images: I need to test if the image if color or BW (based
     16  // on the colormap).  If it is a color image, I need to generate a 24 bit image. the header
     17  // should look the same (Nx Ny 8 [1 0 0 1 0 0]) but then it should finish with "false 3
     18  // colorimage" instead of just "image" (see ../doc/color.image.s for an example).  the hex
     19  // string needs to have RGB represented as chars (2 hex chars per R,G,B).
     20  // the values come from the following map: image[0].pixmap[i] -> cmap[pixel].red -> R (0-255)
     21
    1522  fprintf (f, " newpath %d %d moveto %d %d lineto %d %d lineto %d %d lineto closepath\n\n",
    1623           (int) image[0].picture.x,                       graphic->dy - (int) image[0].picture.y,
     
    2128  fprintf (f, "%d %d translate\n", (int) image[0].picture.x, graphic->dy - (int) image[0].picture.y - image[0].picture.dy);
    2229  fprintf (f, "%d %d 8\n", image[0].picture.dx, image[0].picture.dy);
    23   fprintf (f, "[1 0 0 1 0 0]\n");
     30  fprintf (f, "[1 0 0 -1 0 %d]\n", image[0].picture.dy);
     31  // write out the image in normal order, but flip in PS
     32
     33# if (0)
     34
    2435  fprintf (f, "{currentfile %d string readhexstring pop} image\n\n", image[0].picture.dx);
     36  PSPixmap_1byte (graphic, image, f);
    2537
    26   /******** First we draw the picture itself ********/
    27   /* in !USE_XWINDOW, we'll have to change this to use the JPEG function */
    28   switch (graphic[0].Nbits) {
    29   case 8:
    30     PSPixmap8 (graphic, image, f);
    31     break;
    32   case 16:
    33     PSPixmap16 (graphic, image, f);
    34     break;
    35   case 24:
    36     PSPixmap24 (graphic, image, f);
    37     break;
    38   case 32:
    39     PSPixmap32 (graphic, image, f);
    40     break;
    41   }
     38# else
     39
     40  fprintf (f, "{currentfile %d string readhexstring pop} false 3 colorimage\n\n", 3*image[0].picture.dx);
     41  PSPixmap_3byte (graphic, image, f);
     42
     43# endif
    4244
    4345  fprintf (f, "grestore %% end of image\n");
  • trunk/Ohana/src/kapa2/src/Sections.c

    r27790 r32695  
    237237  return (TRUE);
    238238}
     239
     240int SectionMinBoundary (Graphic *graphic) {
     241
     242    int i;
     243    int Xs = graphic->dx;
     244    int Ys = graphic->dy;
     245    int Xe = 0;
     246    int Ye = 0;
     247
     248    // the boundary for a single section should probably be adjusted depending on the
     249    // image status (should not include the imtool portion)
     250    for (i = 0; i < Nsections; i++) {
     251        Xs = MIN (Xs, sections[i][0].x);
     252        Ys = MIN (Ys, sections[i][0].y);
     253        Xe = MAX (Xe, sections[i][0].x + sections[i][0].dx);
     254        Ye = MAX (Ye, sections[i][0].y + sections[i][0].dy);
     255    }
     256
     257    if ((Xs >= Xe) || (Ys >- Ye)) {
     258        // default values for the region window
     259        graphic->xwin  = 0;
     260        graphic->ywin  = 0;
     261        graphic->dxwin = graphic->dx;
     262        graphic->dywin = graphic->dy;
     263    }   
     264   
     265    // set min/max boundary (min window containing max range of sections)
     266    graphic->xwin = Xs;
     267    graphic->ywin = Ys;
     268    graphic->dxwin = Xe - Xs;
     269    graphic->dywin = Ye - Ys;
     270    return TRUE;
     271}
  • trunk/Ohana/src/kapa2/src/SetUpGraphic.c

    r25757 r32695  
    1616  graphic->dx = 512;
    1717  graphic->dy = 512;
     18
     19  // default values for the region window
     20  graphic->xwin  = 0;
     21  graphic->ywin  = 0;
     22  graphic->dxwin = graphic->dx;
     23  graphic->dywin = graphic->dy;
    1824
    1925  if (!USE_XWINDOW) {
  • trunk/Ohana/src/kapa2/src/bDrawImage.c

    r29938 r32695  
    4747  }
    4848
    49   Xs = image[0].picture.x;
    50   Ys = image[0].picture.y;
     49  // Xs,Ys are in full-frame coords.  can we trim here?
     50  Xs = image[0].picture.x - graphic[0].xwin;
     51  Ys = image[0].picture.y - graphic[0].ywin;
    5152  dx = image[0].picture.dx;
    5253  dy = image[0].picture.dy;
     
    5455  DY = image[0].image[0].matrix.Naxis[1];
    5556
     57  // the created buffer is supposed to contain the output windows
    5658  if (buffer[0].Nx < Xs + dx) {
    5759    fprintf (stderr, "invalid condition\n");
  • trunk/Ohana/src/kapa2/src/bDrawIt.c

    r29938 r32695  
    1313  black = KapaColorByName ("black");
    1414
    15   buffer = bDrawBufferCreate (graphic->dx, graphic->dy, Nbyte, palette, Npalette);
     15  // SectionMinBoundary (graphic);
     16
     17  // if we want to trim, we'll need to carry about the start in graphic coords and
     18  // the dx,dy size. 
     19  buffer = bDrawBufferCreate (graphic->dxwin, graphic->dywin, Nbyte, palette, Npalette);
    1620  bDrawSetStyle (buffer, black, 0, 0);
    1721 
Note: See TracChangeset for help on using the changeset viewer.