IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 40731


Ignore:
Timestamp:
May 14, 2019, 2:41:45 PM (7 years ago)
Author:
eugene
Message:

add anti-aliasing smoothing to bDraw functions; use bDrawBuffer to generate display elements then map to X window (skips use of native X drawing functions for graphs and images; still used for the image toolbox)

Location:
branches/eam_branches/ohana.20190329/src/kapa2
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ohana.20190329/src/kapa2/include/prototypes.h

    r40165 r40731  
    8585int           SetColormapFromPipe PROTO((int sock));
    8686int           SetNanColorFromPipe PROTO((int sock));
     87int           SetSmoothSigma      PROTO((int sock));
    8788
    8889int           LoadVectorData      PROTO((int sock, KapaGraphWidget *graph, int N, char *type));
     
    179180void          InitButtonFunc      PROTO((Button *button, int (*function)(Graphic *graphic, KapaImageWidget *image)));
    180181void          DrawImage           PROTO((KapaImageWidget *image));
     182void          DrawImageTool       PROTO((KapaImageWidget *image));
    181183void          DrawButton          PROTO((Graphic *graphic, Button *button));
    182184void          DrawBitmap          PROTO((Graphic *graphic, int x, int y, int dx, int dy, unsigned char *bitmap, int mode));
  • branches/eam_branches/ohana.20190329/src/kapa2/include/structures.h

    r40570 r40731  
    4848  unsigned long  back;        // basic background color
    4949
     50  float smooth_sigma; // anti-aliasing smoothing scale
     51
    5052  unsigned long  overlay_color[NOVERLAYS]; // image plotting colors
    5153} Graphic;
  • branches/eam_branches/ohana.20190329/src/kapa2/src/CheckPipe.c

    r38465 r40731  
    352352  }
    353353
     354  if (!strcmp (word, "SIGM")) {
     355    SetSmoothSigma (sock);
     356    KiiSendCommand (sock, 4, "DONE");
     357    FINISHED (TRUE);
     358  }
     359
    354360  fprintf (stderr, "unknown signal %s\n", word);
    355361  KiiSendCommand (sock, 4, "DONE");
  • branches/eam_branches/ohana.20190329/src/kapa2/src/Image.c

    r39457 r40731  
    148148void DrawImage (KapaImageWidget *image) {
    149149
     150  Graphic *graphic;
     151
     152  if (image == NULL) return;
     153
     154  graphic = GetGraphic ();
     155
     156  if (image[0].picture.pix) {
     157    XPutImage (graphic[0].display, graphic[0].window, graphic[0].gc,
     158               image[0].picture.pix, 0, 0,
     159               image[0].picture.x + 1, image[0].picture.y + 1,
     160               image[0].picture.dx, image[0].picture.dy);
     161  }
     162}
     163
     164// add the zoom, pan, crosshairs, status box, buttons
     165void DrawImageTool (KapaImageWidget *image) {
     166
    150167  int i;
    151168  Graphic *graphic;
     
    160177                  image[0].picture.dx+1, image[0].picture.dy+1);
    161178 
    162   if (image[0].picture.pix) {
    163     XPutImage (graphic[0].display, graphic[0].window, graphic[0].gc,
    164                image[0].picture.pix, 0, 0,
    165                image[0].picture.x + 1, image[0].picture.y + 1,
    166                image[0].picture.dx, image[0].picture.dy);
    167   }
    168 
    169   for (i = 0; i < NOVERLAYS; i++) {
    170     if (image[0].overlay[i].active) {
    171       PaintOverlay (graphic, image, i);
    172     }
    173   }
    174 
    175179  if (image[0].location) {
    176180    if (image[0].cmapbar.pix) {
     
    211215    StatusBox (graphic, image);
    212216  }
    213 
    214   FlushDisplay ();
    215217}
    216218
  • branches/eam_branches/ohana.20190329/src/kapa2/src/LoadFrame.c

    r38986 r40731  
    9393  SetSectionSizes (section);
    9494  Refresh();
    95   // if (USE_XWINDOW) DrawFrame (graph);
    96   // FlushDisplay ();
    97 
    98   /* XXX why did I do this??? */
    99 # if (0)
    100   status = TRUE;
    101   if (status) {
    102     for (i = 0; i < Nsection; i++) {
    103       PositionPicture (&section[i]);
    104     }
    105     if (USE_XWINDOW) XClearWindow (graphic.display, graphic.window);
    106     Refresh ();
    107   } else {
    108     FlushDisplay ();
    109   }
    110 # endif
    11195
    11296  return (TRUE);
  • branches/eam_branches/ohana.20190329/src/kapa2/src/LoadObject.c

    r40570 r40731  
    103103
    104104  if (USE_XWINDOW) {
    105     Graphic *graphic = GetGraphic();
    106     DrawObjectN (graphic, graph, &graph[0].objects[graph[0].Nobjects-1]);
    107   }
    108   FlushDisplay ();
     105    if (0) {
     106      // use this if we are not using buffered plotting
     107      Graphic *graphic = GetGraphic();
     108      DrawObjectN (graphic, graph, &graph[0].objects[graph[0].Nobjects-1]);
     109      FlushDisplay ();
     110    } else {
     111      Refresh ();
     112    }
     113  }
    109114
    110115  return (TRUE);
  • branches/eam_branches/ohana.20190329/src/kapa2/src/PNGit.c

    r39457 r40731  
    9898  png_write_info (png_ptr, info_ptr);
    9999
     100  if (graphic->smooth_sigma == 0.0) {
     101    fprintf (stderr, "making PNG without antialias smoothing\n");
     102    fprintf (stderr, "use 'antialias (value)' to set smoothing scale (0.4 - 0.7 recommended)\n");
     103  }
     104   
    100105  if (haveImage) {
    101106    buffer = bDrawIt (palette, Npalette, 3);
     
    109114 
    110115  bDrawBufferFree (buffer);
     116  free (palette);
     117 
    111118  fclose (f);
    112119  return (TRUE);
  • branches/eam_branches/ohana.20190329/src/kapa2/src/Refresh.c

    r36833 r40731  
    11# include "Ximage.h"
    22
     3void bDrawXimage (bDrawBuffer *buffer);
     4void Refresh_Buffered (void);
     5void Refresh_Unbuffered (void);
     6
    37void Refresh (void) {
     8  Refresh_Buffered();
     9}
     10
     11void Refresh_Buffered (void) {
     12
     13  int Npalette;
     14  Graphic *graphic;
     15
     16  if (!USE_XWINDOW) return;
     17  // if (HAVE_BACKING) return;
     18
     19  graphic = GetGraphic();
     20 
     21  // limit the png window to the min needed to contain the active graphic regions
     22  SectionMinBoundary (graphic);
     23
     24  // is the palette reasonable in modern context?
     25  png_color *palette = KapaPNGPalette (&Npalette);
     26
     27  bDrawBuffer *buffer = bDrawIt (palette, Npalette, 3);
     28 
     29  /* XClearWindow   (graphic.display, graphic.window); */
     30  XSetForeground (graphic->display, graphic->gc, graphic->back);
     31  XFillRectangle (graphic->display, graphic->window, graphic->gc, 0, 0, graphic->dx, graphic->dy);
     32  XSetForeground (graphic->display, graphic->gc, graphic->fore);
     33 
     34  // copy buffer to Xwindow as image?
     35  bDrawXimage (buffer);
     36
     37  // draw image tool for all sections
     38  int Nsection = GetNumberOfSections ();
     39  for (int i = 0; i < Nsection; i++) {
     40    Section *section = GetSectionByNumber (i);
     41    DrawImageTool (section->image);
     42  }
     43  FlushDisplay ();
     44}
     45
     46void Refresh_Unbuffered (void) {
    447
    548  int i, Nsection;
  • branches/eam_branches/ohana.20190329/src/kapa2/src/SetUpGraphic.c

    r39532 r40731  
    5151  CheckColors (graphic, argc, argv);
    5252
     53  graphic->smooth_sigma = 0.0;
    5354
    5455  icon.width = icon_width;
     
    8485}
    8586
     87int SetSmoothSigma (int sock) {
     88
     89  float sigma;
     90  KiiScanMessage (sock, "%f", &sigma);
     91
     92  if (isfinite(sigma)) {
     93    if ((sigma < 10.0) && (sigma >= 0.0)) {
     94      graphic->smooth_sigma = sigma;
     95    }
     96  }
     97  return TRUE;
     98}
  • branches/eam_branches/ohana.20190329/src/kapa2/src/bDrawImage.c

    r34088 r40731  
    11# include "Ximage.h"
     2
     3// XXX for the moment, this function does NOT set the mask bits.
     4// since we lay graphics on top of images, this is OK for now
    25
    36# define WHITE_R 255
     
    5457
    5558  // the created buffer is supposed to contain the output windows
     59  if (Xs < 0) {
     60    fprintf (stderr, "image display boundaries out of range of window (invalid condition) : fix Kapa\n");
     61    abort();
     62  }
    5663  if (buffer[0].Nx < Xs + dx) {
    57     fprintf (stderr, "invalid condition\n");
     64    fprintf (stderr, "image display boundaries out of range of window (invalid condition) : fix Kapa\n");
     65    abort();
     66  }
     67  if (Ys < 0) {
     68    fprintf (stderr, "image display boundaries out of range of window (invalid condition) : fix Kapa\n");
    5869    abort();
    5970  }
    6071  if (buffer[0].Ny < Ys + dy) {
    61     fprintf (stderr, "invalid condition\n");
     72    fprintf (stderr, "image display boundaries out of range of window (invalid condition) : fix Kapa\n");
    6273    abort();
    6374  }
     
    153164
    154165  return (TRUE);
     166}
     167
     168void bDrawXimage (bDrawBuffer *buffer) {
     169
     170  Graphic *graphic = GetGraphic ();
     171
     172  ALLOCATE_PTR (data, char, 4*buffer->Nx*buffer->Ny);
     173
     174  for (int iy = 0; iy < buffer->Ny; iy++) {
     175    for (int ix = 0; ix < buffer->Nx; ix++) {
     176      data[4*(iy*buffer->Nx + ix) + 0] = buffer->pixels[iy][3*ix + 2];
     177      data[4*(iy*buffer->Nx + ix) + 1] = buffer->pixels[iy][3*ix + 1];
     178      data[4*(iy*buffer->Nx + ix) + 2] = buffer->pixels[iy][3*ix + 0];
     179      data[4*(iy*buffer->Nx + ix) + 3] = 0;
     180    }
     181  }
     182
     183  XImage *pix = XCreateImage (graphic[0].display, graphic[0].visual, graphic[0].depth, ZPixmap, 0,
     184                              data, buffer->Nx, buffer->Ny, 32, 0);
     185
     186  XPutImage (graphic[0].display, graphic[0].window, graphic[0].gc, pix, 0, 0, 1, 1, buffer->Nx, buffer->Ny);
    155187}
    156188
  • branches/eam_branches/ohana.20190329/src/kapa2/src/bDrawIt.c

    r40558 r40731  
    33bDrawBuffer *bDrawIt (png_color *palette, int Npalette, int Nbyte) {
    44
    5   int i, j, Nsection;
    6   bDrawBuffer *buffer;
    7   bDrawColor black;
    8   Graphic *graphic;
    9   Section *section;
     5  Graphic *graphic = GetGraphic();
     6  bDrawColor black = KapaColorByName ("black");
    107
    11   graphic = GetGraphic();
     8  // get the number of sections
     9  int Nsection = GetNumberOfSections ();
    1210
    13   black = KapaColorByName ("black");
     11  // in order to allow the anti-aliasing to affect the text & graphs but not the images
     12  // I need to generate the images in one buffer and the graphs in a second buffer
     13  // then merge the two buffers.
    1414
    15   // if we want to trim, we'll need to carry about the start in graphic coords and
    16   // the dx,dy size. 
    17   buffer = bDrawBufferCreate (graphic->dxwin, graphic->dywin, Nbyte, palette, Npalette);
    18   bDrawSetStyle (buffer, black, 0, 0, 1.0);
     15  // base will hold the images
     16  bDrawBuffer *base = bDrawBufferCreate (graphic->dxwin, graphic->dywin, Nbyte, palette, Npalette);
     17  bDrawSetStyle (base, black, 0, 0, 1.0);
    1918 
    20   // reset the sizes for all sections
    21   Nsection = GetNumberOfSections ();
    22   for (i = 0; i < Nsection; i++) {
    23       section = GetSectionByNumber (i);
    24       bDrawImage (buffer, section->image, graphic);
    25       for (j = 0; section->image && (j < NOVERLAYS); j++) {
    26         if (section->image->overlay[j].active) bDrawOverlay (buffer, section->image, j);
    27       }
    28       bDrawGraph (buffer, section->graph);
     19  for (int i = 0; i < Nsection; i++) {
     20    Section *section = GetSectionByNumber (i);
     21    bDrawImage (base, section->image, graphic);
    2922  }
    3023
    31   return (buffer);
     24  // graph will hold the graphic overlay
     25  bDrawBuffer *graph = bDrawBufferCreate (graphic->dxwin, graphic->dywin, Nbyte, palette, Npalette);
     26  bDrawSetStyle (graph, black, 0, 0, 1.0);
     27
     28  for (int i = 0; i < Nsection; i++) {
     29    Section *section = GetSectionByNumber (i);
     30    for (int j = 0; section->image && (j < NOVERLAYS); j++) {
     31      if (section->image->overlay[j].active) bDrawOverlay (graph, section->image, j);
     32    }
     33    bDrawGraph (graph, section->graph);
     34  }
     35
     36  // apply anti-aliasing only to the graph
     37  if (graphic->smooth_sigma > 0.0) {
     38    bDrawSmooth (graph, graphic->smooth_sigma);
     39  }
     40 
     41  // place graph on base
     42  bDrawMerge (base, graph);
     43  bDrawBufferFree (graph);
     44
     45  return (base);
    3246}
    3347
  • branches/eam_branches/ohana.20190329/src/kapa2/src/bDrawObjects.c

    r40570 r40731  
    99# define OpenTriangle(BUF,X1,Y1,X2,Y2,X3,Y3) (bDrawTriOpen (BUF, (X1), (Y1), (X2), (Y2), (X3), (Y3)))
    1010
     11// I should not have a local static variable for this:
     12// I should just pass the graphic structure to the called functions below
    1113static Graphic *graphic;
    1214
Note: See TracChangeset for help on using the changeset viewer.