Beispiel #1
0
Datei: cdmf.c Projekt: LuaDist/cd
static void cdputimagerectmap(cdCtxCanvas *ctxcanvas, int iw, int ih, const unsigned char *index, const long int *colors, int x, int y, int w, int h, int xmin, int xmax, int ymin, int ymax)
{
  int c, l, n = 0, offset;
  unsigned char r, g, b;

  fprintf(ctxcanvas->file, "%d %d %d %d %d %d %d\n", CDMF_PUTIMAGEMAP, iw, ih, x, y, w, h);

  index += ymin*iw + xmin;
  offset = iw - (xmax-xmin+1);

  for (l = ymin; l <= ymax; l++)
  {
    for (c = xmin; c <= xmax; c++)
    {
      if (*index > n)
        n = *index;

      fprintf(ctxcanvas->file, "%d ", (int)*index++);
    }

    index += offset;

    fprintf(ctxcanvas->file, "\n");
  }

  n++;

  for (c = 0; c < n; c++)
  {
    cdDecodeColor(*colors++, &r, &g, &b);
    fprintf(ctxcanvas->file, "%d %d %d\n", (int)r, (int)g, (int)b);
  }
}
Beispiel #2
0
Datei: cdmf.c Projekt: LuaDist/cd
static long cdforeground(cdCtxCanvas *ctxcanvas, long int color)
{
  unsigned char r, g, b;
  cdDecodeColor(color, &r, &g, &b);
	fprintf(ctxcanvas->file, "%d %d %d %d\n", CDMF_FOREGROUND, (int)r, (int)g, (int)b);
  return color;
}
Beispiel #3
0
/* This function is used to draw a box for a cell. */
static void iColorbarDrawBox(Ihandle* ih, int xmin, int xmax, int ymin, int ymax, int idx)
{
  long int color = ih->data->colors[idx];
  cdCanvasInteriorStyle(ih->data->cddbuffer, CD_SOLID);

  if (color == ih->data->transparency)
  { 
    int xm = (xmin+xmax)/2;
    int ym = (ymin+ymax)/2;
    cdCanvasForeground(ih->data->cddbuffer,0xeeeeee);
    cdCanvasBox(ih->data->cddbuffer,xmin, xm, ymin, ym);
    cdCanvasBox(ih->data->cddbuffer,xm, xmax, ym, ymax);
    cdCanvasForeground(ih->data->cddbuffer,0xcccccc);
    cdCanvasBox(ih->data->cddbuffer,xmin, xm, ym, ymax);
    cdCanvasBox(ih->data->cddbuffer,xm, xmax, ymin, ym);
  }
  else
  {
    if (!iupdrvIsActive(ih))
    {
      unsigned char r, g, b, bg_r, bg_g, bg_b;
      cdDecodeColor(color, &r, &g, &b);
      cdDecodeColor(ih->data->bgcolor, &bg_r, &bg_g, &bg_b);
      iupImageColorMakeInactive(&r, &g, &b, bg_r, bg_g, bg_b);
      color = cdEncodeColor(r, g, b);
    }
    cdCanvasForeground(ih->data->cddbuffer,color);
    cdCanvasBegin(ih->data->cddbuffer,CD_FILL);
    cdCanvasVertex(ih->data->cddbuffer,xmin, ymin); cdCanvasVertex(ih->data->cddbuffer,xmin, ymax);
    cdCanvasVertex(ih->data->cddbuffer,xmax, ymax); cdCanvasVertex(ih->data->cddbuffer,xmax, ymin);
    cdCanvasEnd(ih->data->cddbuffer);
  }

  cdCanvasForeground(ih->data->cddbuffer,CD_BLACK);
  cdCanvasBegin(ih->data->cddbuffer,CD_CLOSED_LINES);
  cdCanvasVertex(ih->data->cddbuffer,xmin, ymin); cdCanvasVertex(ih->data->cddbuffer,xmin, ymax);
  cdCanvasVertex(ih->data->cddbuffer,xmax, ymax); cdCanvasVertex(ih->data->cddbuffer,xmax, ymin);
  cdCanvasEnd(ih->data->cddbuffer);
}
Beispiel #4
0
Datei: cdmf.c Projekt: LuaDist/cd
static void cdpalette(cdCtxCanvas *ctxcanvas, int n, const long int *palette, int mode)
{
  int c;
  unsigned char r, g, b;

  fprintf(ctxcanvas->file, "%d %d %d\n", CDMF_PALETTE, n, mode);

  for (c = 0; c < n; c++)
  {
    cdDecodeColor(*palette++, &r, &g, &b);
    fprintf(ctxcanvas->file, "%d %d %d\n", (int)r, (int)g, (int)b);
  }
}
Beispiel #5
0
Datei: cdmf.c Projekt: LuaDist/cd
static void cdpattern(cdCtxCanvas *ctxcanvas, int w, int h, const long int *pattern)
{
  int c, t;
  unsigned char r, g, b;

  fprintf(ctxcanvas->file, "%d %d %d\n", CDMF_PATTERN, w, h);

  t = w * h;

  /* stores the pattern with separeted RGB values */
  for (c = 0; c < t; c++)
  {
    cdDecodeColor(*pattern++, &r, &g, &b);
    fprintf(ctxcanvas->file, "%d %d %d ", (int)r, (int)g, (int)b);
    if ((c + 1) % w == 0)
      fprintf(ctxcanvas->file, "\n");
  }
}
Beispiel #6
0
static void cdIupInitPalette(Ihandle* image, long* palette, long bgcolor, int make_inactive)
{
  int i;
  unsigned char r, g, b, bg_r, bg_g, bg_b;

  cdDecodeColor(bgcolor, &bg_r, &bg_g, &bg_b);

  for(i = 0; i < 256; i++)
  {
    char* color = IupGetAttributeId(image, "", i);
    r = bg_r; g = bg_g; b = bg_b;
    iupStrToRGB(color, &r, &g, &b);  /* no need to test for BGCOLOR, if this failed it will not set the parameters */

    if (make_inactive)
      iupImageColorMakeInactive(&r, &g, &b, bg_r, bg_g, bg_b);

    palette[i] = cdEncodeColor(r, g, b);
  }
}
static void iMatrixDrawToggle(Ihandle* ih, int x2, int y1, int y2, int lin, int col, int marked, int active)
{
  int x1;
  long bgcolor = ih->data->bgcolor_cd;

  /* toggle area */
  iupMatrixDrawSetToggleArea(&x1, &y1, &x2, &y2);

  /* toggle background */
  if (marked)
  {
    unsigned char bg_r, bg_g, bg_b;
    cdDecodeColor(bgcolor, &bg_r, &bg_g, &bg_b);
    bg_r = IMAT_ATENUATION(bg_r);
    bg_g = IMAT_ATENUATION(bg_g);
    bg_b = IMAT_ATENUATION(bg_b);
    bgcolor = cdEncodeColor(bg_r, bg_g, bg_b);
  }
  cdCanvasForeground(ih->data->cd_canvas, bgcolor);
  iupMATRIX_BOX(ih, x1, x2, y1, y2);

  /* toggle frame */
  iMatrixDrawSetFgColor(ih, lin, col, marked, active);
  iupMATRIX_RECT(ih, x1, x2, y1, y2);

  /* toggle check */
  if (iupAttribGetIntId2(ih, "TOGGLEVALUE", lin, col))
  {
    int half = IMAT_TOGGLE_SIZE/2;
    iupMATRIX_LINE(ih, x1 + half - 2, y2 - 2, x1 + half - 2 + 6, y2 - 2 - 6);
    iupMATRIX_LINE(ih, x1 + half - 2, y2 - 3, x1 + half - 2 + 6, y2 - 3 - 6);
    iupMATRIX_LINE(ih, x1 + half - 2, y2 - 4, x1 + half - 2 + 5, y2 - 4 - 5);

    iupMATRIX_LINE(ih, x1 + half - 2, y2 - 2, x1 + half - 2 - 2, y2 - 2 - 2);
    iupMATRIX_LINE(ih, x1 + half - 2, y2 - 3, x1 + half - 2 - 2, y2 - 3 - 2);
    iupMATRIX_LINE(ih, x1 + half - 2, y2 - 4, x1 + half - 2 - 1, y2 - 4 - 1);
  }
}
Beispiel #8
0
static void cdputimagerectmap(cdCtxCanvas *ctxcanvas, int iw, int ih, const unsigned char *index, const long int *colors, int x, int y, int w, int h, int xmin, int xmax, int ymin, int ymax)
{
  double p[6];
  double *color_array;
  int i,j,c;
  unsigned char r, g, b;
  int rw, rh;

  rw = xmax-xmin+1;
  rh = ymax-ymin+1;
  
  color_array = (double *) malloc ( rw*rh*3*sizeof(double) );
  if (!color_array)
    return;
  
  p[0] = (double) x;      p[1] = (double) y;
  p[2] = (double) (x+w);  p[3] = (double) (y+h);
  p[4] = (double) (x+w);  p[5] = (double) y;
  
  for ( i=0; i<rh; i++ )
  {
    for ( j=0; j<rw; j++ )
    {
      c = i*rw*3+j*3;
      cdDecodeColor(colors[index[(ih-i-1-ymin)*iw+j+xmin]], &r,&b,&g);
      color_array[c]   = ((double)r)/255.;
      color_array[c+1] = ((double)g)/255.;
      color_array[c+2] = ((double)b)/255.;
    }
  }
    
  cgm_cell_array ( ctxcanvas->cgm, p, (long)rw, (long)rh, 8, color_array );
  
  free(color_array);
  
  setbbox (ctxcanvas, p[0], p[1] );
  setbbox (ctxcanvas, p[2], p[3] );
}
Beispiel #9
0
static unsigned char* cdIupBuildImageBuffer(Ihandle *image, int width, int height, int depth, int make_inactive, long bgcolor)
{
  int size, plane_size, i, j;
  unsigned char bg_r, bg_g, bg_b;
  unsigned char* image_buffer;
  /* images from stock or resources are not supported */
  unsigned char* data = (unsigned char*)IupGetAttribute(image, "WID");
  if (!data)
    return NULL;

  plane_size = width*height;
  size = plane_size*depth;

  image_buffer = malloc(size);
  if (!image_buffer)
    return NULL;

  cdDecodeColor(bgcolor, &bg_r, &bg_g, &bg_b);

  /* IUP image is top-down, CD image is bottom up */
  if (depth==1)
  {
    /* inactive will be set at the palette */
    for (i=0; i<height; i++)
      memcpy(image_buffer + i*width, data + (height-1 - i)*width, width);
  }
  else if (depth==3)
  {
    int pos;
    unsigned char r, g, b;
    unsigned char *dst_r = image_buffer + 0*plane_size;
    unsigned char *dst_g = image_buffer + 1*plane_size;
    unsigned char *dst_b = image_buffer + 2*plane_size;

    for (i=0; i<height; i++)
    {
      int line_offset = i*width;
      unsigned char *line_r = dst_r + line_offset;
      unsigned char *line_g = dst_g + line_offset;
      unsigned char *line_b = dst_b + line_offset;
      unsigned char *src_rgb = data + (height-1 - i)*(3*width);

      for (j=0; j<width; j++)
      {
        pos = j*3;
        r = src_rgb[pos+0];
        g = src_rgb[pos+1];
        b = src_rgb[pos+2];

        if (make_inactive)
          iupImageColorMakeInactive(&r, &g, &b, bg_r, bg_g, bg_b);

        line_r[j] = r;
        line_g[j] = g;
        line_b[j] = b;
      }
    }
  }
  else /* depth==4 */
  {
    int pos;
    unsigned char r, g, b, a;
    unsigned char *dst_r = image_buffer + 0*plane_size;
    unsigned char *dst_g = image_buffer + 1*plane_size;
    unsigned char *dst_b = image_buffer + 2*plane_size;
    unsigned char *dst_a = image_buffer + 3*plane_size;

    for (i=0; i<height; i++)
    {
      int line_offset = i*width;
      unsigned char *line_r = dst_r + line_offset;
      unsigned char *line_g = dst_g + line_offset;
      unsigned char *line_b = dst_b + line_offset;
      unsigned char *line_a = dst_a + line_offset;
      unsigned char *src_rgba = data + (height-1 - i)*(4*width);

      for (j=0; j<width; j++)
      {
        pos = j*4;
        r = src_rgba[pos+0];
        g = src_rgba[pos+1];
        b = src_rgba[pos+2];
        a = src_rgba[pos+3];

        if (make_inactive)
          iupImageColorMakeInactive(&r, &g, &b, bg_r, bg_g, bg_b);

        line_r[j] = r;
        line_g[j] = g;
        line_b[j] = b;
        line_a[j] = a;
      }
    }
  }

  return image_buffer;
}
Beispiel #10
0
static void iColorBrowserRenderImageSI(Ihandle* ih)
{
  int x, y, active = 1;
  unsigned char *red, *green, *blue;
  unsigned char bg_red, bg_green, bg_blue;
  float angle, cos_angle, sin_angle;
  if (!ih->data->cddbuffer)
    return;

  if (!iupdrvIsActive(ih))
    active = 0;

  red = cdRedImage(ih->data->cddbuffer);
  green = cdGreenImage(ih->data->cddbuffer);
  blue = cdBlueImage(ih->data->cddbuffer);

  cdDecodeColor(ih->data->bgcolor, &bg_red, &bg_green, &bg_blue);

  angle = ih->data->hue * ICB_DEG2RAD;
  cos_angle = cosf(angle);
  sin_angle = sinf(angle);

  for (y = 0; y < ih->data->h; y++)
  {
    float sx_max, i;

    if (y < ih->data->Iy1)
      continue;
    else if (y > ih->data->Iy2)
      continue;

    sx_max = iColorBrowserSXmax(ih, y);
    i = iColorBrowserCalcIntensity(ih, y);

    for (x = 0; x < ih->data->w; x++)
    {
      if (x < ih->data->Ix)
        continue;
      else if (x > ih->data->Ix+(int)sx_max)
        continue;

      {
        int offset = y*ih->data->w + x;
        unsigned char* r = red + offset;
        unsigned char* g = green + offset;
        unsigned char* b = blue + offset;
        float s, diff;

        s = iColorBrowserCalcSaturation(ih, x, sx_max);

        iupColorHSI2RGB(ih->data->hue, s, i, r, g, b);

        diff = sx_max - (float)(x - ih->data->Ix);
        if (diff<1.0f)  /* anti-aliasing */
        {
          *r = (unsigned char)((*r)*diff + bg_red*(1.0f-diff));
          *g = (unsigned char)((*g)*diff + bg_green*(1.0f-diff));
          *b = (unsigned char)((*b)*diff + bg_blue*(1.0f-diff));
        }

        if (!active)
        {
          *r = cdIupLIGTHER(*r);
          *g = cdIupLIGTHER(*g);
          *b = cdIupLIGTHER(*b);
        }
      }
    }
  }
}
Beispiel #11
0
static void iColorBrowserRenderImageHue(Ihandle* ih)
{
  int x, y, active = 1;
  unsigned char *red, *green, *blue;
  unsigned char bg_red, bg_green, bg_blue;
  if (!ih->data->cddbuffer)
    return;

  cdCanvasBackground(ih->data->cddbuffer, ih->data->bgcolor);
  cdCanvasClear(ih->data->cddbuffer);

  if (!iupdrvIsActive(ih))
    active = 0;

  if (ih->data->has_focus)
    cdDrawFocusRect(ih->data->cddbuffer, 0, 0, ih->data->w-1, ih->data->h-1);

  red = cdRedImage(ih->data->cddbuffer);
  green = cdGreenImage(ih->data->cddbuffer);
  blue = cdBlueImage(ih->data->cddbuffer);

  cdDecodeColor(ih->data->bgcolor, &bg_red, &bg_green, &bg_blue);

  for (y = 0; y < ih->data->h; y++)
  {
    float sx_max = iColorBrowserSXmax(ih, y);

    for (x = 0; x < ih->data->w; x++)
    {
      int xl, yl;
      float radius, diff1, diff2;

      if (y > ih->data->Iy1 && 
          y < ih->data->Iy2 &&
          x > ih->data->Ix  &&
          x < ih->data->Ix+(int)sx_max)
        continue;

      xl = x - ih->data->xc;
      yl = y - ih->data->yc;
      radius = sqrtf(xl*xl + yl*yl);

      diff1 = radius - (ih->data->R-ICB_SPACE-ICB_HUEWIDTH);
      diff2 = (ih->data->R-ICB_SPACE) - radius;

      if (diff1>0 && diff2>0)
      {
        float h, s, i;
        int offset = y*ih->data->w + x;
        unsigned char* r = red + offset;
        unsigned char* g = green + offset;
        unsigned char* b = blue + offset;

        h = atan2f(yl, xl);
        h = (float)(h * CD_RAD2DEG);
        s = 1.0f;   /* maximum saturation */
        i = 0.5f;   /* choose I where S is maximum */

        iupColorHSI2RGB(h, s, i, r, g, b);

        if (diff1<1 || diff2<1)  /* anti-aliasing */
        {
          float diff = (float)(diff1<1? diff1: diff2);
          *r = (unsigned char)((*r)*diff + bg_red*(1.0f-diff));
          *g = (unsigned char)((*g)*diff + bg_green*(1.0f-diff));
          *b = (unsigned char)((*b)*diff + bg_blue*(1.0f-diff));
        }

        if (!active)
        {
          *r = cdIupLIGTHER(*r);
          *g = cdIupLIGTHER(*g);
          *b = cdIupLIGTHER(*b);
        }
      }
    }
  }

  if (active)
  {
    float x1, x2, y1, y2;
    unsigned char shade_lr, shade_lg, shade_lb,
                  shade_dr, shade_dg, shade_db;
    shade_dr = (unsigned char)((2 * bg_red) / 3);
    shade_dg = (unsigned char)((2 * bg_green) / 3);
    shade_db = (unsigned char)((2 * bg_blue) / 3);
    shade_lr = (unsigned char)((255 + bg_red) / 2);
    shade_lg = (unsigned char)((255 + bg_green) / 2);
    shade_lb = (unsigned char)((255 + bg_blue) / 2);
    cdCanvasForeground(ih->data->cddbuffer, cdEncodeColor(shade_dr, shade_dg, shade_db));
    x1 = (float)(ih->data->xc-ih->data->R+ICB_SPACE); y1 = (float)ih->data->yc; x2 = (float)(x1+ICB_HUEWIDTH/2); y2 = (float)ih->data->yc;
    cdCanvasLine(ih->data->cddbuffer, (int) x1, (int) y1, (int) x2, (int) y2);
    iColorBrowserRotatePoints(&x1, &y1, &x2, &y2, ih->data->xc, ih->data->yc);
    cdCanvasForeground(ih->data->cddbuffer, cdEncodeColor(shade_lr, shade_lg, shade_lb));
    cdCanvasLine(ih->data->cddbuffer, (int) x1, (int) y1, (int) x2, (int) y2);
    iColorBrowserRotatePoints(&x1, &y1, &x2, &y2, ih->data->xc, ih->data->yc);
    cdCanvasForeground(ih->data->cddbuffer, cdEncodeColor(shade_dr, shade_dg, shade_db));
    cdCanvasLine(ih->data->cddbuffer, (int) x1, (int) y1, (int) x2, (int) y2);
    iColorBrowserRotatePoints(&x1, &y1, &x2, &y2, ih->data->xc, ih->data->yc);
    cdCanvasForeground(ih->data->cddbuffer, cdEncodeColor(shade_lr, shade_lg, shade_lb));
    cdCanvasLine(ih->data->cddbuffer, (int) x1, (int) y1, (int) x2, (int) y2);
    iColorBrowserRotatePoints(&x1, &y1, &x2, &y2, ih->data->xc, ih->data->yc);
    cdCanvasForeground(ih->data->cddbuffer, cdEncodeColor(shade_dr, shade_dg, shade_db));
    cdCanvasLine(ih->data->cddbuffer, (int) x1, (int) y1, (int) x2, (int) y2);
    iColorBrowserRotatePoints(&x1, &y1, &x2, &y2, ih->data->xc, ih->data->yc);
    cdCanvasLine(ih->data->cddbuffer, (int) x1, (int) y1, (int) x2, (int) y2);
  }
}
Beispiel #12
0
Datei: cdmf.c Projekt: LuaDist/cd
static void cdpixel(cdCtxCanvas *ctxcanvas, int x, int y, long int color)
{
  unsigned char r, g, b;
  cdDecodeColor(color, &r, &g, &b);
  fprintf(ctxcanvas->file, "%d %d %d %d %d %d\n", CDMF_PIXEL, x, y, (int)r, (int)g, (int)b);
}