void render_graymap_alleg(BITMAP* canvas, graymap_t* gm, color_t* pal_cols,
 double* pal_grays, int pal_n)
{
	int limit_w = gm->w;
	int limit_h = gm->h;
	if(limit_w > canvas->w)
		limit_w = canvas->w;
	if(limit_h > canvas->h)
		limit_h = canvas->h;
	
	color_t col;
	
	int x,y,i;
	uint_8 r,g,b,a;
	for(y = 0, i = 0; y < limit_h; ++y)
	{
		for(x = 0; x < limit_w; ++x, ++i)
		{
			col = get_palette_color(gm->data[i], pal_cols, pal_grays, pal_n);
			r = (uint_8) round(col.r * 255.0);
			g = (uint_8) round(col.g * 255.0);
			b = (uint_8) round(col.b * 255.0);
			a = (uint_8) round(col.a * 255.0);
			putpixel(canvas, x,y,makeacol(r,g,b,a));
		}
	}
}
Esempio n. 2
0
void _wsetcolor(
/**************/

    int         color
) {
    if( color < 0 ) {
        /* indicates that real BLACK is desired */
        Set_color = _wpi_getrgb( 0, 0, 0 );
    } else {
        Set_color = get_palette_color( color );
    }
}
Esempio n. 3
0
void PaletteEditor::rgb_changed()
{
    if (ignore_rgb)
        return;
    RGBColor & pal = get_palette_color();
    pal.r = r_edit->value();
    pal.g = g_edit->value();
    pal.b = b_edit->value();
    ignore_rgb = true;
    set_current();
    ignore_rgb = false;
    window->model_changed();
}
void
plot_bitmap_to_cairo_surface(cairo_t * cairo_context,
			     double origin_x, double origin_y,
			     double size_x, double size_y,
			     double map_min, double map_max,
			     const float * bitmap,
			     unsigned int bitmap_width,
			     unsigned int bitmap_height)
{
    const double pixel_width  = size_x / bitmap_width;
    const double pixel_height = size_y / bitmap_height;
    const double dynamic_range = map_max - map_min;
    const float * cur_pixel = bitmap;

    unsigned int cur_y;

    for(cur_y = bitmap_height; cur_y > 0; --cur_y)
    {
	unsigned int cur_x;
	for(cur_x = 0; cur_x < bitmap_width; ++cur_x)
	{
	    double value = *bitmap++;
	    color_t color;

	    if(isinff(value))
		continue;
	    else if (isnanf(value) || value < -1.6e+30)
		color.red = color.green = color.blue = 0.5;
	    else
	    {
		double normalized_value = (value - map_min) / dynamic_range;
		get_palette_color(normalized_value, &color);
	    }

	    cairo_rectangle(cairo_context,
			    origin_x + (cur_x * size_x) / bitmap_width,
			    origin_y + (cur_y * size_y) / bitmap_height,
			    pixel_width,
			    pixel_height);
	    cairo_set_source_rgb(cairo_context,
				 color.red,
				 color.green,
				 color.blue);
	    cairo_fill(cairo_context);
	}
    }
}
Esempio n. 5
0
void PaletteEditor::set_palette()
{
    QColor col = QColor::fromHsvF(color_space->hue, 
                                  color_space->sat, 
                                  color_space->val);
    RGBColor & pal = get_palette_color();
    pal.r = col.red();
    pal.g = col.green();
    pal.b = col.blue();
    ignore_rgb = true;
    r_edit->setValue(pal.r);
    g_edit->setValue(pal.g);
    b_edit->setValue(pal.b);
    ignore_rgb = false;
    grid->update();
    window->model_changed();
}
Esempio n. 6
0
void PaletteEditor::set_current()
{
    if (!window->get_voxel())
        return;
    name->setText(palette_names[grid->palette_index]);
    RGBColor & col = get_palette_color();
    QColor color(col.r, col.g, col.b);
    qreal h, s, v;
    color.getHsvF(&h, &s, &v);
    color_space->set_hsv(h, s, v);
    color_slider->set(h);
    if (!ignore_rgb) {
        ignore_rgb = true;
        r_edit->setValue(col.r);
        g_edit->setValue(col.g);
        b_edit->setValue(col.b);
        ignore_rgb = false;
    }
    grid->update();
}
Esempio n. 7
0
void View::create_gl_palette()
{
  int i;
  unsigned char palette[256][3];
  for (i = 0; i < pal_steps; i++)
  {
    float gl_color[3];
    get_palette_color((double) i / pal_steps, gl_color);
    palette[i][0] = (unsigned char) (gl_color[0] * 255);
    palette[i][1] = (unsigned char) (gl_color[1] * 255);
    palette[i][2] = (unsigned char) (gl_color[2] * 255);
  }
  for (i = pal_steps; i < 256; i++)
    memcpy(palette[i], palette[pal_steps-1], 3);

  if (gl_pallete_tex_id == 0)
    glGenTextures(1, &gl_pallete_tex_id);
  glBindTexture(GL_TEXTURE_1D, gl_pallete_tex_id);
  glTexImage1D(GL_TEXTURE_1D, 0, 3, 256, 0, GL_RGB, GL_UNSIGNED_BYTE, palette);
  glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_CLAMP);
  glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
}
Esempio n. 8
0
      void OrderView::init_order_palette(double3* vert)
      {
        int min = 1, max = (int)vert[0][2];
        for (int i = 0; i < ord.get_num_vertices(); i++)
        {
          if ((int)vert[i][2] < min) min = (int)vert[i][2];
          if ((int)vert[i][2] > max) max = (int)vert[i][2];
        }

        num_boxes = max - min + 1;
        char* buf = text_buffer;
        for (int i = 0; i < num_boxes; i++)
        {
          get_palette_color((i + min) / (double)H2DV_MAX_VIEWABLE_ORDER, &order_colors[i + min][0]);

          sprintf(buf, "%d", i + min);
          box_names[i] = buf;
          buf += strlen(buf) + 1;
        }

        scale_height = num_boxes * scale_box_height + (num_boxes - 1) * scale_box_skip;
        order_min = min;
      }
Esempio n. 9
0
WPI_FONT _wtextinit(
/******************/
/* initial text, pass back font handle for _wtextout */

    text_def            *text
) {
    WPI_LOGFONT         font;
    WPI_FONT            font_hld;
    BOOL                is_bold;
    int                 size;
    int                 match_no;

    _wpi_getdeffm( font );
    if( text->style & TEXT_SIZEABLE ) {
        _wpi_setfontsizeable( &font, TRUE );
    }
    if( text->not_set ) {
        _wpi_setfontfacename( &font, NULL );
    } else {
        _wpi_setfontfacename( &font, text->face_name );
    }

#if 0
    size = text->size%100;
    match_no = ((text->size-(text->size%100))/100);;
#else
    size = text->size;
    match_no = 0;
#endif
    _wpi_setfontpointsize( &font, size, points_to_pixel( text->size ),
                match_no );

    _wpi_settextcolor( Win_dc, get_palette_color( text->color - 1 ) );
    is_bold = text->style & TEXT_BOLD;
    _wpi_setfontbold( &font, is_bold );

    /* due to some wierd, undocumented bug in Windows, italics will
       not print on some devices unless the style booleans below
       are set to -1 (255)! We found this out by looking at what
       commdlg.dll returned in the LOGFONT. I don't understand,
       but leave it this way */
    _wpi_setfontitalic( &font, text->style & TEXT_ITALIC );
    _wpi_setfontunderline( &font, text->style & TEXT_UNDERLINE );
    _wpi_setfontstrikeout( &font, text->style & TEXT_STRIKEOUT );
    if( text->not_set ) {
        _wpi_setfontcharset( &font, ANSI_CHARSET );
        _wpi_setfontpitch( &font, DEFAULT_PITCH | FF_ROMAN );
    } else {
        _wpi_setfontcharset( &font, text->char_set );
        _wpi_setfontpitch( &font, text->pitchfamily );
    }

    _wpi_setfontprecision( &font, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS );
    _wpi_setfontquality( &font, DRAFT_QUALITY );

    _wpi_setfontescapement( &font, 0 );
    _wpi_setfontorientation( &font, 0 );

    _wpi_createfont( font, font_hld );

    return( font_hld );
}
Esempio n. 10
0
void VectorView::plot_arrow(double x, double y, double xval, double yval, double max, double min, double gs)
{
  if (mode == 1)
    glColor3f(0.0f,0.0f,0.0f);
  else
    glColor3f(0.5f,0.5f,0.5f);

  // magnitude
  double real_mag = sqrt(sqr(xval) + sqr(yval));
  double mag = real_mag;
  if (real_mag > max) mag = max;
  double length = mag/max * gs * length_coef;
  double width = 0.1 * gs;
  if (mode == 1) width *= 1.2;
  double xnew = x + gs * xval * mag / (max * real_mag) * length_coef;
  double ynew = y - gs * yval * mag / (max * real_mag) * length_coef;


  if ((mag)/(max - min) < 1e-5)
  {
    glTranslated(x,y,0.0);

    glBegin(GL_QUADS);
    glVertex2d( width,  width);
    glVertex2d( width, -width);
    glVertex2d(-width, -width);
    glVertex2d(-width,  width);
    glEnd();
  }
  else
  {

    glBegin(GL_LINES);
    glVertex2d(x,y);
    glVertex2d(xnew, ynew);
    glEnd();

    glTranslated(x,y,0.0);
    glRotated(atan2(-yval,xval) * 180.0/M_PI, 0.0, 0.0, 1.0);

    glBegin(GL_TRIANGLES);
    glVertex2d(length + 3 * width,  0.0);
    glVertex2d(length - 2 * width,  width);
    glVertex2d(length - 2 * width, -width);
    glEnd();
  }

  glLoadIdentity();

  if (mode == 1)
  {
    float color[3];
    get_palette_color((mag - min)/(max - min), color); //  0.0 -- 1.0
    glColor3f(color[0], color[1], color[2]);


    if (mag/(max - min) < 1e-5)
    {
      glBegin(GL_QUADS);
      glVertex2d( width,  width);
      glVertex2d( width, -width);
      glVertex2d(-width, -width);
      glVertex2d(-width,  width);
      glEnd();
    }
    else
    {

      glBegin(GL_LINES);
      glVertex2d(x,y);
      glVertex2d(xnew, ynew);
      glEnd();

      glTranslated(x - 1, y,0.0);
      glRotated(atan2(-yval,xval) * 180.0/M_PI, 0.0, 0.0, 1.0);

      glBegin(GL_TRIANGLES);
      glVertex2d(length + 3 * width,  0.0);
      glVertex2d(length - 2 * width,  width);
      glVertex2d(length - 2 * width, -width);
      glEnd();

      glLoadIdentity();
    }
  }
}