Exemple #1
0
static void cdfbox(cdCtxCanvas *ctxcanvas, double xmin, double xmax, double ymin, double ymax)
{
  if(ctxcanvas->canvas->back_opacity == CD_OPAQUE && glIsEnabled(GL_POLYGON_STIPPLE))
  {
    /* draw twice, one with background color only, and one with foreground color */
    glDisable(GL_POLYGON_STIPPLE);
    glColor4ub(cdRed(ctxcanvas->canvas->background), 
               cdGreen(ctxcanvas->canvas->background), 
               cdBlue(ctxcanvas->canvas->background), 
               cdAlpha(ctxcanvas->canvas->background));

    glBegin(GL_QUADS);
      glVertex2d(xmin, ymin);
      glVertex2d(xmax, ymin);
      glVertex2d(xmax, ymax);
      glVertex2d(xmin, ymax);
    glEnd();

    /* restore the foreground color */
    glColor4ub(cdRed(ctxcanvas->canvas->foreground), 
               cdGreen(ctxcanvas->canvas->foreground), 
               cdBlue(ctxcanvas->canvas->foreground), 
               cdAlpha(ctxcanvas->canvas->foreground));
    glEnable(GL_POLYGON_STIPPLE);
  }

  glBegin(GL_QUADS);
    glVertex2d(xmin, ymin);
    glVertex2d(xmax, ymin);
    glVertex2d(xmax, ymax);
    glVertex2d(xmin, ymax);
  glEnd();

  (void)ctxcanvas;
}
Exemple #2
0
static GLubyte* cdglCreateImageMap(int width, int height, const long* colors, const unsigned char *map, int image_width)
{
  const GLubyte *line_data;
  GLubyte *pixline_data;
  GLubyte *glImage;
  int x, y, channels = 3;
  int rowstride = width * channels;

  glImage = (GLubyte*)malloc(rowstride * height);

  for (y = 0; y < height; y++)
  {
    pixline_data = glImage + y * rowstride;
    line_data = map + y * image_width;

    for (x=0; x<width; x++)
    {
      GLubyte index = line_data[x];
      long c = colors[index];
      GLubyte *r = &pixline_data[channels*x],
              *g = r+1,
              *b = g+1;

      *r = cdRed(c);
      *g = cdGreen(c);
      *b = cdBlue(c);
    }
  }

  return glImage;
}
static int iColorBrowserDlgColorCnvButton_CB(Ihandle* ih, int b, int press, int x, int y)
{
  IcolorDlgData* colordlg_data = (IcolorDlgData*)iupAttribGetInherit(ih, "_IUP_GC_DATA");
  int width;
  (void)y;

  if (b != IUP_BUTTON1 || !press || !colordlg_data->cd_canvas_color)
    return IUP_DEFAULT;

  cdCanvasGetSize(colordlg_data->cd_canvas_color, &width, NULL, NULL, NULL);

  if (x < width/2)
  {
    /* reset color to previous */
    colordlg_data->red = cdRed(colordlg_data->previous_color);
    colordlg_data->green = cdGreen(colordlg_data->previous_color);
    colordlg_data->blue = cdBlue(colordlg_data->previous_color);
    colordlg_data->alpha = cdAlpha(colordlg_data->previous_color);

    IupSetInt(colordlg_data->alpha_txt, "VALUE", (int)colordlg_data->alpha);
    IupSetInt(colordlg_data->alpha_val, "VALUE", (int)colordlg_data->alpha);

    iColorBrowserDlgRGB_TXT_Update(colordlg_data);
    iColorBrowserDlgRGBChanged(colordlg_data);
  }

  return IUP_DEFAULT;
}
Exemple #4
0
static void cdclear(cdCtxCanvas* ctxcanvas)
{
  GLclampf r = (GLclampf)cdRed(ctxcanvas->canvas->background)/255.0f; 
  GLclampf g = (GLclampf)cdGreen(ctxcanvas->canvas->background)/255.0f;
  GLclampf b = (GLclampf)cdBlue(ctxcanvas->canvas->background)/255.0f;
  GLclampf a = (GLclampf)cdAlpha(ctxcanvas->canvas->background)/255.0f;

  glClearColor(r, g, b, a);

  glClear(GL_COLOR_BUFFER_BIT);

  /* restore the foreground color */
  glColor4ub(cdRed(ctxcanvas->canvas->foreground), 
             cdGreen(ctxcanvas->canvas->foreground), 
             cdBlue(ctxcanvas->canvas->foreground), 
             cdAlpha(ctxcanvas->canvas->foreground));
}
Exemple #5
0
/* %F Converte cor de CD para DIB. */
static RGBQUAD sColorToDIB(long cd_color)
{
  RGBQUAD color;
  color.rgbRed = cdRed(cd_color);
  color.rgbGreen = cdGreen(cd_color);
  color.rgbBlue = cdBlue(cd_color);
  return color;
}
Exemple #6
0
static GdkColor cdColorToGdk(unsigned long rgb)
{
  GdkColor clrRGB;

  clrRGB.red   = cdCOLOR8TO16(cdRed(rgb));
  clrRGB.green = cdCOLOR8TO16(cdGreen(rgb));
  clrRGB.blue  = cdCOLOR8TO16(cdBlue(rgb));

  return clrRGB;
}
Exemple #7
0
static long int cdforeground(cdCtxCanvas *ctxcanvas, long int color)
{
  (void)ctxcanvas;

  glColor4ub(cdRed(color), 
             cdGreen(color), 
             cdBlue(color), 
             cdAlpha(color));

  return color;
}
Exemple #8
0
static void cdpixel(cdCtxCanvas *ctxcanvas, int x, int y, long int color)
{
  glColor4ub(cdRed(color), 
             cdGreen(color), 
             cdBlue(color), 
             cdAlpha(color));

  /* Draw pixel */
  glPointSize(1);
  glBegin(GL_POINTS);
    glVertex2i(x, y);
  glEnd();

  /* restore the foreground color */
  glColor4ub(cdRed(ctxcanvas->canvas->foreground), 
             cdGreen(ctxcanvas->canvas->foreground), 
             cdBlue(ctxcanvas->canvas->foreground), 
             cdAlpha(ctxcanvas->canvas->foreground));

  (void)ctxcanvas;
}
Exemple #9
0
static char* iColorbarGetCellAttrib(Ihandle* ih, const char* name_id)
{
  char* buffer = iupStrGetMemory(100);
  int idx = -1;
  long color;
  
  iupStrToInt(name_id, &idx);
  if (idx < 0 || idx >= ih->data->num_cells)
    return NULL;

  color = ih->data->colors[idx];
  sprintf(buffer, "%d %d %d", cdRed(color), cdGreen(color), cdBlue(color));
  return buffer;
}
Exemple #10
0
void cdIupCalcShadows(long bgcolor, long *light_shadow, long *mid_shadow, long *dark_shadow)
{
  int r, bg_r = cdRed(bgcolor);
  int g, bg_g = cdGreen(bgcolor);
  int b, bg_b = cdBlue(bgcolor);

  /* light_shadow */

  int max = bg_r;
  if (bg_g > max) max = bg_g;
  if (bg_b > max) max = bg_b;

  if (255-max < 64)
  {
    r = 255;
    g = 255;
    b = 255;
  }
  else
  {
    /* preserve some color information */
    if (bg_r == max) r = 255;
    else             r = bg_r + (255-max);
    if (bg_g == max) g = 255;
    else             g = bg_g + (255-max);
    if (bg_b == max) b = 255;
    else             b = bg_b + (255-max);
  }

  if (light_shadow) *light_shadow = cdEncodeColor((unsigned char)r, (unsigned char)g, (unsigned char)b); 

  /* dark_shadow */
  r = bg_r - 128;
  g = bg_g - 128;
  b = bg_b - 128;
  if (r < 0) r = 0;
  if (g < 0) g = 0;
  if (b < 0) b = 0;

  if (dark_shadow) *dark_shadow = cdEncodeColor((unsigned char)r, (unsigned char)g, (unsigned char)b); 

  /*   mid_shadow = (dark_shadow+bgcolor)/2    */
  if (mid_shadow) *mid_shadow = cdEncodeColor((unsigned char)((bg_r+r)/2), (unsigned char)((bg_g+g)/2), (unsigned char)((bg_b+b)/2));
}
Exemple #11
0
static GdkPixbuf* cdgdkCreatePixbufMap(int width, int height, const long* colors, const unsigned char *map, int ix, int iy, int image_width)
{
  GdkPixbuf* pixbuf;
  guchar *pixdata, *pixline_data;
  int rowstride, channels;
  const unsigned char *line_data;
  int x, y;

  pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8, width, height);
  if (!pixbuf)
    return NULL;

  pixdata = gdk_pixbuf_get_pixels(pixbuf);
  rowstride = gdk_pixbuf_get_rowstride(pixbuf);
  channels = gdk_pixbuf_get_n_channels(pixbuf);

  /* GdkPixbuf is top-bottom */
  /* map is bottom-top */

  for (y=0; y<height; y++)
  {
    line_data = map + (height-1 - y + iy) * image_width;  /* map is bottom-top */

    pixline_data = pixdata + y * rowstride;

    for (x=0; x<width; x++)
    {
      unsigned char index = line_data[x+ix];
      long c = colors[index];
      guchar *r = &pixline_data[channels*x],
             *g = r+1,
             *b = g+1;

      *r = cdRed(c);
      *g = cdGreen(c);
      *b = cdBlue(c);
    }
  }

  return pixbuf;
}
Exemple #12
0
static void cdfpoly(cdCtxCanvas *ctxcanvas, int mode, cdfPoint* poly, int n)
{
  int i;

  if (mode == CD_CLIP)
    return;

  if (mode == CD_BEZIER)
  {
    int i, prec = 100;
    double (*points)[3] = malloc(n * sizeof(*points));

    for(i = 0; i < n; i++)
    {
      points[i][0] = poly[i].x;
      points[i][1] = poly[i].y;
      points[i][2] = 0;
    }

    glMap1d(GL_MAP1_VERTEX_3, 0.0, 1.0, 3, n, &points[0][0]);
    glEnable(GL_MAP1_VERTEX_3);
    glMapGrid1d(prec, 0.0, 1.0);
    glEvalMesh1(GL_LINE, 0, prec);
    glDisable(GL_MAP1_VERTEX_3);

    free(points);
    return;
  }

  if (mode == CD_PATH)
  {
    cdfSimPolyPath(ctxcanvas->canvas, poly, n);
    return;
  }

  switch (mode)
  {
  case CD_CLOSED_LINES :
    glBegin(GL_LINE_LOOP);
    break;
  case CD_OPEN_LINES :
    glBegin(GL_LINE_STRIP);
    break;
  case CD_FILL :
    if(ctxcanvas->canvas->back_opacity == CD_OPAQUE && glIsEnabled(GL_POLYGON_STIPPLE))
    {
      glDisable(GL_POLYGON_STIPPLE);
      glColor4ub(cdRed(ctxcanvas->canvas->background), 
                 cdGreen(ctxcanvas->canvas->background), 
                 cdBlue(ctxcanvas->canvas->background), 
                 cdAlpha(ctxcanvas->canvas->background));

      glBegin(GL_POLYGON);
      for(i = 0; i < n; i++)
        glVertex2d(poly[i].x, poly[i].y);
      glEnd();

      /* restore the foreground color */
      glColor4ub(cdRed(ctxcanvas->canvas->foreground), 
                 cdGreen(ctxcanvas->canvas->foreground), 
                 cdBlue(ctxcanvas->canvas->foreground), 
                 cdAlpha(ctxcanvas->canvas->foreground));
      glEnable(GL_POLYGON_STIPPLE);
    }

    glBegin(GL_POLYGON);
    break;
  }

  for(i = 0; i < n; i++)
    glVertex2d(poly[i].x, poly[i].y);
  glEnd();

  (void)ctxcanvas;
}
Exemple #13
0
static char* iColorbarGetTransparencyAttrib(Ihandle* ih)
{
  if (ih->data->transparency == ICOLORBAR_NO_COLOR)
    return NULL;
  else
  {
    char* buffer = iupStrGetMemory(100);
    sprintf(buffer, "%d %d %d", cdRed(ih->data->transparency), cdGreen(ih->data->transparency), cdBlue(ih->data->transparency));
    return buffer;
  }
}
Exemple #14
0
static void simDrawTextBitmap(cdSimulation* simulation, FT_Bitmap* bitmap, int x, int y)
{
  unsigned char *red, *green, *blue, *alpha, *bitmap_data;
  int width = bitmap->width;
  int height = bitmap->rows;
  int size = width*height;
  int rgba_data_size = size*4;
  int old_use_matrix = simulation->canvas->use_matrix;

  /* avoid spaces */
  if (width == 0 || height == 0)
    return;

  if (!simulation->tt_text->rgba_data)
    simulation->tt_text->rgba_data = malloc(rgba_data_size);
  else if (rgba_data_size > simulation->tt_text->rgba_data_size)
  {
    simulation->tt_text->rgba_data = realloc(simulation->tt_text->rgba_data, rgba_data_size);
    simulation->tt_text->rgba_data_size = rgba_data_size;
  }

  /* disable image transformation */
  simulation->canvas->use_matrix = 0;

  /* this is the char bitmap, contains an alpha map of the char 
     to be combined with the foreground color */
  bitmap_data = bitmap->buffer + (height-1)*width;  /* bitmap is top down. */

  /* this is the image used to draw the char with the foreground color */ 
  red   = simulation->tt_text->rgba_data;
  green = red   + size;
  blue  = green + size;
  alpha = blue  + size;

  if (!simulation->canvas->cxPutImageRectRGBA && !simulation->canvas->cxGetImageRGB)
  {
    int i, j;
    unsigned char bg_red, bg_green, bg_blue, 
                  fg_red, fg_green, fg_blue, fg_alpha, calpha;
    long int c;

    /* must manually combine using only the background color, ignore canvas contents */

    c = simulation->canvas->background;
    bg_red   = cdRed(c);
    bg_green = cdGreen(c);
    bg_blue  = cdBlue(c);
    c = simulation->canvas->foreground;
    fg_red   = cdRed(c);
    fg_green = cdGreen(c);
    fg_blue  = cdBlue(c);
    fg_alpha = cdAlpha(c);

    for (i = 0; i < height; i++)
    {
      for (j = 0; j < width; j++)
      {
        if (simulation->antialias)
        {
          if (fg_alpha == 255)
            calpha = bitmap_data[j];
          else
            calpha = (fg_alpha*bitmap_data[j])/255;
        }
        else
        {
          if (bitmap_data[j] > 128)  /* behave as 255 */
            calpha = fg_alpha;
          else
            calpha = 0;
        }

        *red++ = CD_ALPHA_BLEND(fg_red, bg_red, calpha);
        *green++ = CD_ALPHA_BLEND(fg_green, bg_green, calpha);
        *blue++ = CD_ALPHA_BLEND(fg_blue, bg_blue, calpha);
      }

      bitmap_data -= width;
    }

    /* reset pointers */
    red   = simulation->tt_text->rgba_data;
    green = red   + size;
    blue  = green + size;

    /* draw the char */
    simulation->canvas->cxPutImageRectRGB(simulation->canvas->ctxcanvas, width,height,red,green,blue,x,y,width,height,0,width-1,0,height-1);
  }
  else
  {
    int i, j;
    long int fg = simulation->canvas->foreground;
    unsigned char fg_alpha = cdAlpha(fg);
    memset(red,   cdRed(fg), size);
    memset(green, cdGreen(fg), size);
    memset(blue,  cdBlue(fg), size);

    /* alpha is the bitmap_data itself 
       if the foreground color does not contains alpha.
       Also must invert since it is top-down. */

    for (i = 0; i < height; i++)
    {
      if (simulation->antialias)
      {
        if (fg_alpha == 255)
        {
          memcpy(alpha,  bitmap_data, width);
          alpha += width;
        }
        else
        {
          for (j = 0; j < width; j++)
          {
            *alpha++ = (fg_alpha*bitmap_data[j])/255;
          }
        }
      }
      else
      {
        for (j = 0; j < width; j++)
        {
          if (bitmap_data[j] > 128)  /* behave as 255 */
            *alpha++ = fg_alpha;
          else
            *alpha++ = 0;
        }
      }

      bitmap_data -= width;
    }

    /* reset alpha pointer */
    alpha = blue + size;

    /* draw the char */
    simulation->canvas->cxPutImageRectRGBA(simulation->canvas->ctxcanvas, width,height,red,green,blue,alpha,x,y,width,height,0,width-1,0,height-1);
  }

  simulation->canvas->use_matrix = old_use_matrix;
}