예제 #1
0
void CL_Texture::set_border_color(const CL_Color &color)
{
	set_border_color(
		color.get_red()/255.0f,
		color.get_green()/255.0f,
		color.get_blue()/255.0f,
		color.get_alpha()/255.0f);
}
예제 #2
0
unsigned char find_nearest_color(const CL_Palette& palette, const CL_Color& rgb)
{ // Copyright (C) 1998 Pyrosoft Inc. (www.pyrosoftgames.com), Matthew Bogue
  float bestDist = 10000000.0f;
  int   best     = 0;

  float vPic = sqrt(rgb.get_red() * rgb.get_red() 
                    + rgb.get_green() * rgb.get_green()
                    + rgb.get_blue() * rgb.get_blue()) * 0.57735027;
 
  for (int i = 0; i < 256; i++) {
    float vPal = sqrt(palette.colors[i].get_red()     * palette.colors[i].get_red()
                      + palette.colors[i].get_green() * palette.colors[i].get_green()
                      + palette.colors[i].get_blue()  * palette.colors[i].get_blue()) * 0.57735027;

    float dr = palette.colors[i].get_red()   - rgb.get_red();
    float dg = palette.colors[i].get_green() - rgb.get_green();
    float db = palette.colors[i].get_blue()  - rgb.get_blue();
    float dv = vPal-vPic;
    float dist = dr * dr * 0.3 + dg * dg * 0.59 + db * db * 0.11 + dv * dv * 0.7;

    if (dist < bestDist) {
      bestDist = dist;
      best = i;
    }
  }

  return best;
}
void CL_PixelFillRenderer::clear(const CL_Colorf &color)
{
	int dest_buffer_width = colorbuffer0.size.width;
	int dest_buffer_height = colorbuffer0.size.height;
	unsigned char *dest_data = (unsigned char *) colorbuffer0.data;

	CL_Color c = color;
	unsigned int color8888 = (c.get_alpha() << 24) + (c.get_red() << 16) + (c.get_green() << 8) + c.get_blue();
	unsigned char *ptr_color8888 = (unsigned char *) &color8888;

	for (int y = find_first_line_for_core(clip_rect.top, core, num_cores); y < clip_rect.bottom; y += num_cores)
	{
		unsigned char *line = dest_data + y * dest_buffer_width * 4 + clip_rect.left * 4;
		unsigned int line_align = ((line) - ((unsigned char *) 0)) & 0xf; // A gcc safe way of obtaining an address
		int pos = 0;
		int length = clip_rect.get_width()*4;

		// Write single bytes until we are byte aligned:
		if (line_align)
		{
			int prefix_length = cl_min(length, (int) (16 - line_align));
			for (; pos < prefix_length; pos++)
				line[pos] = ptr_color8888[pos&0x3];
		}

		// Figure out how our 16 bytes should look like after we applied the alignment:
		unsigned int b0 = ptr_color8888[(pos+0)&0x3];
		unsigned int b1 = ptr_color8888[(pos+1)&0x3];
		unsigned int b2 = ptr_color8888[(pos+2)&0x3];
		unsigned int b3 = ptr_color8888[(pos+3)&0x3];
		__m128i c_sse = _mm_set1_epi32((b3<<24)+(b2<<16)+(b1<<8)+b0);

		// Fill 16 byte aligned:
		int align_length = length-pos-15;
		for (; pos < align_length; pos+=16)
			_mm_stream_si128((__m128i*)(line+pos), c_sse);

		// Fill remaining bytes:
		for (; pos < length; pos++)
			line[pos] = ptr_color8888[pos&0x3];
	}
}
예제 #4
0
CL_ColorHSVx<int>::CL_ColorHSVx(const CL_Color &color)
{
	int red = color.get_red();
	int green = color.get_green();
	int blue = color.get_blue();

	const int min_value = cl_min(red,cl_min(blue, green));
	const int max_value = cl_max(red,cl_max(blue, green));
	a = color.get_alpha();
	
	if (min_value == max_value)
	{
		h = 0;
		s = 0;
		v = min_value;
		return;
	}

	s = max_value != 0 ? 255 * (max_value - min_value) / max_value : 0;
	v = max_value;
	
	float r = float(max_value - red) / (max_value - min_value);
	float g = float(max_value - green) / (max_value - min_value);
	float b = float(max_value - blue) / (max_value - min_value);

	if (max_value == red)
	{
		h = (60 * (b - g))+0.5f;
	}
	else if (max_value == green)
	{
		h = (60 * (2 + r - b))+0.5f;
	}
	else
	{
		h = (60 * (4 + g - r))+0.5f;
	}
}
예제 #5
0
	void setRacketColor(const CL_Color _racketColor) { racketColor = CL_Color(_racketColor.get_red(), _racketColor.get_green(), _racketColor.get_blue()); }
예제 #6
0
  void draw(const Stroke& stroke, CL_GraphicContext* gc)
  {
    CL_OpenGLState state(CL_Display::get_current_window()->get_gc());
    state.set_active();
    state.setup_2d();

    CL_Color color = DrawerProperties::current()->get_color();

    const Stroke::Dabs& dabs = stroke.get_interpolated_dabs(DrawerProperties::current()->get_spacing(),
                                                            DrawerProperties::current()->get_spacing());

    if (dabs.size() >= 2)
    {
      std::vector<CL_Pointf> normals;

      if (stroke.get_dab_count() == 2)
      {
        normals.push_back(CL_Pointf(1.0f, 1.0f));
        normals.push_back(CL_Pointf(1.0f, 1.0f));
      }
      else if (stroke.get_dab_count() >= 3)
      {
        for(Stroke::Dabs::size_type i = 0; i < dabs.size()-1; ++i)
        {
          CL_Pointf normal((dabs[i].pos.y - dabs[i+1].pos.y),
                           -(dabs[i].pos.x - dabs[i+1].pos.x));

          float length = sqrt(normal.x * normal.x + normal.y * normal.y);

          normal.x /= length;
          normal.y /= length;

          normals.push_back(normal);
        }

        normals.push_back(CL_Pointf(1.0f, 1.0f));
      }

      float len  = DrawerProperties::current()->get_size() * 8.0f;
      float len2 = DrawerProperties::current()->get_size() * 16.0f;

      glEnable(GL_BLEND);
      glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );

      glBegin(GL_QUAD_STRIP);
      for(unsigned int j = 0; j < dabs.size()-2; ++j)
      {
        glColor4ub(color.get_red(), color.get_green(), color.get_blue(), color.get_alpha());
        glVertex2f(dabs[j].pos.x + normals[j].x * len,
                   dabs[j].pos.y + normals[j].y * len);

        glColor4ub(color.get_red(), color.get_green(), color.get_blue(), 0);
        glVertex2f(dabs[j].pos.x + normals[j].x * len2,
                   dabs[j].pos.y + normals[j].y * len2);
      }
      glEnd();

      glBegin(GL_QUAD_STRIP);
      for(unsigned int j = 0; j < dabs.size()-2; ++j)
      {
        glColor4ub(color.get_red(), color.get_green(), color.get_blue(), 0);
        glVertex2f(dabs[j].pos.x - normals[j].x * len2,
                   dabs[j].pos.y - normals[j].y * len2);

        glColor4ub(color.get_red(), color.get_green(), color.get_blue(), color.get_alpha());
        glVertex2f(dabs[j].pos.x - normals[j].x * len,
                   dabs[j].pos.y - normals[j].y * len);
      }
      glEnd();

      glBegin(GL_QUAD_STRIP);
      glColor4ub(color.get_red(), color.get_green(), color.get_blue(), color.get_alpha());
      for(unsigned int j = 0; j < dabs.size()-2; ++j)
      {
        glVertex2f(dabs[j].pos.x + normals[j].x * len,
                   dabs[j].pos.y + normals[j].y * len);
        glVertex2f(dabs[j].pos.x - normals[j].x * len,
                   dabs[j].pos.y - normals[j].y * len);
      }
      glEnd();
    }
  }