Exemple #1
0
void onMessage() {
	char op = 0;
	op = msg.readChar();
	// s - set color, f - fade to color
	if (op == 's' || op == 'f') {
		int red = msg.readInt();
		int green = msg.readInt();
		int blue = msg.readInt();
		if (op == 'f') {
			fade_to_color(red, green, blue);
		} else if (op == 's') {
			set_color(red, green, blue);
		}
		String color = "colorChange " + String(red) + " " + String(green) + " "
				+ String(blue) + "\n";
		serial.print(color);
	}
	// q - query color
	else if (op == 'q') {
		String color = "currentColor " + String(get_red()) + " " + String(
				get_green()) + " " + String(get_blue()) + "\n";
		serial.print(color);
	} else {
		serial.print("Unknown command.");
		serial.print(op);
		serial.print("\n");
	}
}
Exemple #2
0
void			tric(t_env *e)
{
	int x;
	int	y;
	int i;
	int	pxl;

	e->fract = 3;
	x = 0;
	while (x <= W_WIDTH)
	{
		y = 0;
		while (y <= W_HEIGHT)
		{
			init_tric(x, y, e);
			i = iter_tric(e);
			pxl = x * e->bpp / 8 + y * e->sl;
			e->data[pxl] = get_red(i, e);
			e->data[pxl + 1] = get_green(i, e);
			e->data[pxl + 2] = get_blue(i, e);
			y++;
		}
		x++;
	}
}
Exemple #3
0
static void cdstipple(cdCtxCanvas *ctxcanvas, int n, int m, const unsigned char *stipple)
{
  double *pattab;
  int i, j=0;

  pattab = (double *) malloc ( n*m*3*sizeof(double));
  
  for ( i=0; i<n*m; i++ )
  {
    pattab[j+0] = ( stipple[i] ) ? get_red(ctxcanvas->canvas->foreground) : get_red(ctxcanvas->canvas->background);
    pattab[j+1] = ( stipple[i] ) ? get_green(ctxcanvas->canvas->foreground) : get_green(ctxcanvas->canvas->background);
    pattab[j+2] = ( stipple[i] ) ? get_blue(ctxcanvas->canvas->foreground) : get_blue(ctxcanvas->canvas->background);
    j+=3;
  }
  
  cgm_pattern_table ( ctxcanvas->cgm, (long) ctxcanvas->patindex, (long) n, (long) m, (int) 8, pattab );
  cgm_pattern_index ( ctxcanvas->cgm, (long) ctxcanvas->patindex++ );
  free(pattab);
  
  cgm_interior_style  ( ctxcanvas->cgm, 2 );  /* PATTERN */
}
Exemple #4
0
static long int cdbackground(cdCtxCanvas *ctxcanvas, long int color)
{
  double bc[3];
  
  bc[0] = get_red(color);
  bc[1] = get_green(color);
  bc[2] = get_blue(color);
  
  ctxcanvas->canvas->background = color;
  cgm_backgound_colour ( ctxcanvas->cgm, bc );
  
  return color;
}
Exemple #5
0
static long int cdforeground(cdCtxCanvas *ctxcanvas, long int color)
{
  double cor[3];
  
  cor[0] = get_red(color);
  cor[1] = get_green(color);
  cor[2] = get_blue(color);
  
  cgm_text_colour( ctxcanvas->cgm, cor );
  cgm_fill_colour( ctxcanvas->cgm, cor );
  cgm_line_colour( ctxcanvas->cgm, cor );
  
  return color;
}
Exemple #6
0
static void cdpixel(cdCtxCanvas *ctxcanvas, int x, int y, long int color)
{
  double cor[3];
  double pts[2];

  pts[0] = (double) x;
  pts[1] = (double) y;
  
  cor[0] = get_red(color);
  cor[1] = get_green(color);
  cor[2] = get_blue(color);

  cgm_marker_colour( ctxcanvas->cgm, cor);
  cgm_polymarker ( ctxcanvas->cgm, 1, pts );
}
Exemple #7
0
void bmp_image::plot_with_brightness(int x, int y, rgba_color_t color, double brightness) {
    if ( brightness < 0.0 ) {
        brightness = 0.0;
    }
    if ( brightness > 1.0 ) {
        brightness = 1.0;
    }

    brightness = 1.0 - brightness;   

    color = set_red(color,      std::min(255, round_half_up( 255. * brightness + get_red(color) )) );
    color = set_green(color,    std::min(255, round_half_up( 255. * brightness + get_green(color) )) );
    color = set_blue(color,     std::min(255, round_half_up( 255. * brightness + get_blue(color) )) );

    pixels.set_if_inbounds(x, y, color);
}
Exemple #8
0
void test_colors() {
  printf("testing colors\n");
  int r = 25;
  int g = 225;
  int b = 200;
  int a = 255;
  color c = get_color(r,g,b,a);
  assert(c == 0x19E1C8FF);
  assert(get_red(c) == r);
  assert(get_green(c) == g);
  assert(get_blue(c) == b);
  assert(get_alpha(c) == a);
  assert(set_red(c,0xAA) == 0xAAE1C8FF);
  assert(set_green(c,0xAA) == 0x19AAC8FF);
  assert(set_blue(c,0xAA) == 0x19E1AAFF);
  assert(set_alpha(c,0xAA) == 0x19E1C8AA);
}
Exemple #9
0
/**
 * Draws a curve for the speed graph.
 */
void GtkGraph::draw(std::queue<double> q, double height, double increment, double maxValue, const Cairo::RefPtr<Cairo::Context>& cr)
{
	// wizards use computers
	// computers use numbers
	// no magic
	
	double offset = increment * (m_displaySize - q.size());

	cr->move_to(0, height);
	for(unsigned i = 0; i< (m_displaySize - q.size());++i)
		cr->line_to(i*increment, height);


	double oldy;
	if(q.empty()) return;

	oldy = height - (q.front() * height / maxValue);
	cr->line_to(offset, oldy);
	q.pop();
	double x = increment + offset;
	while(!q.empty())
	{
		double y = height - (q.front() * height / maxValue);
		cr->curve_to(x - increment/2, oldy, x - increment/2, y, x, y);
		q.pop();
		oldy = y;
		x += increment;
	}

	if(gt::Settings::settings["GraphStyle"] == "Fill")
	{
		cr->stroke_preserve();
		Gdk::Cairo::set_source_rgba(cr, Gdk::RGBA(gt::Settings::settings[(upl) ? "GraphUploadFillColor" : "GraphDownloadFillColor"]));
		cr->line_to(x - increment, height);
		cr->line_to(0,height);
		auto k = Gdk::RGBA(gt::Settings::settings[(upl) ? "GraphUploadFillColor" : "GraphDownloadFillColor"]);
		cr->set_source_rgba(k.get_red(), k.get_green(), k.get_blue(), k.get_alpha() * 0.5);
		cr->fill();
	}
	else cr->stroke();
}
Exemple #10
0
static void cdpattern(cdCtxCanvas *ctxcanvas, int n, int m, const long int *pattern)
{
  double *pattab;
  int i, j=0;

  pattab = (double *) malloc ( n*m*3*sizeof(double) );
  
  for ( i=0; i<n*m; i++ )
  {
    pattab[j+0] = get_red(pattern[i]);
    pattab[j+1] = get_green(pattern[i]);
    pattab[j+2] = get_blue(pattern[i]);
    j+=3;
  }
  
  cgm_pattern_table ( ctxcanvas->cgm, (long) ctxcanvas->patindex, (long) n, (long) m, (int) 8, pattab );
  cgm_pattern_index ( ctxcanvas->cgm, (long) ctxcanvas->patindex++ );
  free(pattab);
  
  cgm_interior_style  ( ctxcanvas->cgm, 2 );  /* PATTERN */
}
Exemple #11
0
int bmp_image::output_to_file(const std::string& file_name) const {
    std::ofstream out(file_name.c_str(), std::ios_base::binary | std::ios_base::out);

    if ( !out ) {
        return 1;
    }
    //full header size 122
    /* BMP structure
     *    File Header
     * 0   Magic number 0x42, 0x4d (2 bytes)
     * 2   File size = w*h + h*(w%4) + 122 ? (4 bytes)
     * 6   Unused (4 bytes)
     * 10  Pixel array offset = 122 (4 bytes)
     *    DIB Header
     * 14  Bytes in DIB Header = 108 (4 bytes)
     * 18  Bitmap width (4 bytes)
     * 22  Bitmap width (4 bytes)
     * 26  Color planes = 1 (2 bytes) 
     * 28  Bits/pixel = 32 (2 bytes)
     * 30  BI_BITFIELDS = 3 (no compression used) (4 bytes)
     * 34  Size of the raw data in the Pixel Array = w*h + h*(w%4) ? (incl padding) (4 bytes)
     * 38  horizonal pixels/meter = 2835 (4 bytes)
     * 42  vertival pixels/meter = 2835 (4 bytes)
     * 46  Number of colors in the palette = 0 (4 bytes)
     * 50  Important colors = 0 (4 bytes)
     * 54  Red channel bit mask = 0x00FF0000 (4 bytes)
     * 58  Green channel bit mask = 0x0000FF00 (4 bytes)
     * 62  Blue channel bit mask = 0x000000FF (4 bytes)
     * 66  Alpha channel bit mask = 0xFF000000 (4 bytes)
     * 70  Color space type = 0x206E6957 ?? (4 bytes) //LCS_WINDOWS_COLOR_SPACE
     * 74  CIEXYZTRIPLE Color Space (unused) (36 bytes)
     * 110 red gamma = unused (4 bytes)
     * 114 green gamma = unused (4 bytes)
     * 118 blue gamma = unused (4 bytes)
     * 122 <Pixel Data>
     */

    //TODO endianess

    //const boost::uint8_t unused_8 = 0;
    //const boost::uint16_t unused_16 = 0;
    const boost::uint32_t unused_32 = 0;

    //File Header
    out.write("\x42\x4d", 2); //magic number

    const boost::uint32_t file_size = width*height*4 + 122; 
    out.write( (const char *)(&file_size), 4); //file_size

    out.write( (const char *)(&unused_32), 4); //unused

    const boost::uint32_t pixel_array_offset = 122;
    out.write( (const char *)(&pixel_array_offset), 4); //pixel_array_offset

    const boost::uint32_t dib_header_size = 108;
    out.write( (const char *)(&dib_header_size), 4); //dib_header_size

    const boost::uint32_t bitmap_width = width;
    const boost::uint32_t bitmap_height = height;
    out.write( (const char *)(&bitmap_width), 4); //bitmap_width
    out.write( (const char *)(&bitmap_height), 4); //bitmap_height

    const boost::uint16_t color_planes = 1;
    out.write( (const char *)(&color_planes), 2); //color_planes

    const boost::uint16_t bits_per_pixel = 32;
    out.write( (const char *)(&bits_per_pixel), 2); //bits_per_pixel

    const boost::uint32_t bitfields = 3;
    out.write( (const char *)(&bitfields), 4); //bitfields

    const boost::uint32_t pixel_array_size = width*height*4;
    out.write( (const char *)(&pixel_array_size), 4); //pixel_array_size

    const boost::uint32_t horizontal_physical_resolution = 2835;
    const boost::uint32_t vertical_physical_resolution = 2835;
    out.write( (const char *)(&horizontal_physical_resolution), 4); //horizontal_physical_resolution
    out.write( (const char *)(&vertical_physical_resolution), 4); //vertical_physical_resolution

    out.write( (const char *)(&unused_32), 4); //num of colors on palette
    out.write( (const char *)(&unused_32), 4); //num of important colors

    const boost::uint32_t red_channel_bit_mask = bmp_impl::endian_swap( 0x00FF0000U );
    const boost::uint32_t green_channel_bit_mask = bmp_impl::endian_swap( 0x0000FF00U );
    const boost::uint32_t blue_channel_bit_mask = bmp_impl::endian_swap( 0x000000FFU );
    const boost::uint32_t alpha_channel_bit_mask = bmp_impl::endian_swap( 0xFF000000U );
    out.write( (const char *)(&red_channel_bit_mask), 4); //red_channel_bit_mask    
    out.write( (const char *)(&green_channel_bit_mask), 4); //green_channel_bit_mask
    out.write( (const char *)(&blue_channel_bit_mask), 4); //blue_channel_bit_mask
    out.write( (const char *)(&alpha_channel_bit_mask), 4); //alpha_channel_bit_mask

    const boost::uint32_t color_space_type = bmp_impl::endian_swap( 0x206E6957U );
    out.write( (const char *)(&color_space_type), 4); //color_space_type

    //CIEXYZTRIPLE Color Space (unused) (36 bytes)
    for(unsigned i = 0; i < 36/4; ++i) {
        out.write( (const char *)(&unused_32), 4);
    }

    out.write( (const char *)(&unused_32), 4); //red gamma
    out.write( (const char *)(&unused_32), 4); //green gamma
    out.write( (const char *)(&unused_32), 4); //blue gamma

    for(unsigned cy = 0; cy < pixels.height(); ++cy) {
        for(unsigned x = 0; x < pixels.width(); ++x) {

            unsigned y = pixels.height() - cy - 1;
           
            const single_color_t alpha = get_alpha(pixels(x, y));
            const single_color_t red = get_red(pixels(x, y));
            const single_color_t green = get_green(pixels(x, y));
            const single_color_t blue = get_blue(pixels(x, y));
            
            out.write((const char *)&alpha, 1);
            out.write((const char *)&red, 1);
            out.write((const char *)&green, 1);
            out.write((const char *)&blue, 1);
            
            

        }
        //no padding required as the pixels themselves are 4 bytes long
    }

    out.close();

    return 0;
}
Exemple #12
0
Light::operator int() const {
  return 256 * (
    256 * color_component_of_light_component(get_red()) +
    color_component_of_light_component(get_green())
  ) + color_component_of_light_component(get_blue());
}
Exemple #13
0
void EditorCanvas::paint()
{
  auto status = SetCurrent(*context);
  assert(status);
  int w, h;
  GetClientSize(&w, &h);
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  glOrtho(0, w, -h, 0, 0, 1);
  glClearColor(0.f, 0.f, 0.f, 0.f);
  glClear(GL_COLOR_BUFFER_BIT);
  // add a red border if it is a keyframe
  if (scene.anyKeyframe(frame)) {
    glLineWidth(8);
    glColor3d(1, 0, 0);
    glBegin(GL_LINE_STRIP);
    {
      glVertex2d(    1,     -1);
      glVertex2d(    1, -h + 1);
      glVertex2d(w - 1, -h + 1);
      glVertex2d(w - 1,     -1);
      glVertex2d(    1,     -1);
    }
    glEnd();
  }
  glLineWidth(1);
  auto polygons = scene.getPolygons();
  auto selected = scene.getSelectedPolygon();
  for (auto& p : polygons) {
    std::vector<Point> vertices;
    auto color = p->getVertices(frame, vertices);
    glColor3d(color.get_red(), color.get_green(), color.get_blue());
    glLineWidth(selected == p ? 3 : 1);
    // draw the edges
    glBegin(GL_LINE_STRIP);
    {
      for (auto& v : vertices) {
        glVertex2d(v.x, -v.y);
      }
      glVertex2d(vertices[0].x, -vertices[0].y);
    }
    glEnd();
    // now draw the vertices on top of the lines
    if (selected == p) {
      auto v = scene.getSelectedVertex();
      glBegin(GL_LINES);
      {
        decltype(v) j = 0;
        for (auto& p : vertices) {
          glColor3d(0, 1, j++ == v ? 0 : 1);
          glVertex2d(p.x + 5, -p.y);
          glVertex2d(p.x - 5, -p.y);
          glVertex2d(p.x, -p.y + 5);
          glVertex2d(p.x, -p.y - 5);
        }
      }
      glEnd();
    }
  }

  if (state == State::CENTER ||
      state == State::ROTATE ||
      state == State::SCALE) {
    glBegin(GL_LINES);
    {
      glColor3d(0.5, 0.5, 0.5);
      auto rc = scene.getCenter();
      auto x = static_cast<int>(rc.x);
      auto y = static_cast<int>(rc.y);
      glVertex2d(x + 5, -y);
      glVertex2d(x - 5, -y);
      glVertex2d(x, -y + 5);
      glVertex2d(x, -y - 5);
    }
    glEnd();
  } else if (state == State::DRAW) { // draw the object currently being created
    glLineWidth(3);
    // first draw the edges
    auto p = scene.getActivePolygon();
    const auto& c = p->getColor();
    glColor3d(c.get_red(), c.get_green(), c.get_blue());
    auto& vertices = p->keyframes[0].vertices;
    glBegin(GL_LINE_STRIP);
    {
      for (auto& v : vertices) {
        glVertex2d(v.x, -v.y);
      }
    }
    glEnd();
    // now draw the vertices
    glColor3d(0, 1, 1);
    glBegin(GL_LINES);
    {
      for (auto& v : vertices) {
        glVertex2d(v.x + 5, -v.y);
        glVertex2d(v.x - 5, -v.y);
        glVertex2d(v.x, -v.y + 5);
        glVertex2d(v.x, -v.y - 5);
      }
    }
    glEnd();
  }

  glFlush();
  status = SwapBuffers();
  assert(status);
}