예제 #1
0
static void
recolor(rbtree_t      *tree,
        rbtree_node_t *parent,
        rbtree_node_t *node)
{
  rbtree_node_t *sibling;

  while(is_black(node) && node != tree->root)
  {
    int left = (node == parent->child[LEFT]);

    sibling = parent->child[left];

    if(is_red(sibling))
    {
      set_black(sibling);
      set_red(parent);
      rbtree_rotate(tree, parent, left);
      sibling = parent->child[left];
    }

    if(is_black(sibling->child[LEFT]) && is_black(sibling->child[RIGHT]))
    {
      set_red(sibling);
      node = parent;
      parent = get_parent(node);
    }
    else
    {
      if(is_black(sibling->child[left]))
      {
        set_black(sibling->child[!left]);
        set_red(sibling);
        rbtree_rotate(tree, sibling, !left);
        sibling = parent->child[left];
      }

      if(is_black(parent))
        set_black(sibling);
      else
        set_red(sibling);
      set_black(parent);
      set_black(sibling->child[left]);

      rbtree_rotate(tree, parent, left);

      node = tree->root;
    }
  }

  if(node != NULL)
    set_black(node);
}
예제 #2
0
void set_color(SDL_Surface *surface, int x, int y, SDL_Color color)
{
	set_red(surface, x, y, color.r);
	set_green(surface, x, y, color.g);
	set_blue(surface, x, y, color.g);
	set_alpha(surface, x, y, color.a);
}
예제 #3
0
파일: Color.cpp 프로젝트: Holygitzdq/ElVis
 std::unique_ptr<ElVis::Serialization::Color> Color::Serialize() const
 {
   auto pResult = std::unique_ptr<ElVis::Serialization::Color>(new ElVis::Serialization::Color());
   pResult->set_red(m_red);
   pResult->set_green(m_green);
   pResult->set_blue(m_blue);
   pResult->set_alpha(m_alpha);
   return pResult;
 }
예제 #4
0
파일: main.c 프로젝트: j4cbo/lumiafw
void init() {
	LED_1_DDR |= (1 << LED_1_PINNUM);
	LED_1_PORT |= (1 << LED_1_PINNUM);
	LED_2_DDR |= (1 << LED_2_PINNUM);
	LED_2_PORT |= (1 << LED_2_PINNUM);
	LED_3_DDR |= (1 << LED_3_PINNUM);
	LED_3_PORT |= (1 << LED_3_PINNUM);

	/* Turn on PLL - 48 MHz; send 48 MHz to counter and USB */
	PLLFRQ =  (1 << PLLTM0) | (1 << PDIV2);
	PLLCSR = (1 << PINDIV);
	PLLCSR = (1 << PINDIV) | (1 << PLLE);
	while (!(PLLCSR & (1 << PLOCK)));

	/* Set up timer 1 for diode PWM */
	LASER_R_DDR |= (1 << LASER_R_PINNUM);
	LASER_G_DDR |= (1 << LASER_G_PINNUM);
	LASER_B_DDR |= (1 << LASER_B_PINNUM);
	LASER_R_PORT |= (1 << LASER_R_PINNUM);
	LASER_G_PORT |= (1 << LASER_G_PINNUM);
	LASER_B_PORT |= (1 << LASER_B_PINNUM);
	_delay_ms(1);
	set_red(0);
	set_green(0);
	set_blue(0);
	TCCR1A = (1 << COM1A1) | (1 << COM1B1) | (1 << COM1C1) | (1 << WGM10);
	TCCR1B = (1 << WGM12) | (1 << CS10);

	/* Set up timers 0 and 3 for motor PWM */
	TCCR0A = (1 << COM0B1) | (1 << WGM01) | (1 << WGM00);
	TCCR0B = (1 << CS00);
	TCCR3A = (1 << COM3A1) | (1 << WGM30);
	TCCR3B = (1 << WGM32) | (1 << CS30);
	M1_DDR |= (1 << M1_PINNUM);
	M2_DDR |= (1 << M2_PINNUM);

	/* Set up timer 4 for TEC PWM at 94 kHz */
	/* Low-order bits are falling edge, high-order are rising edge */
	DT4 = 4 | (7 << 4);
	TCCR4A = 0;
	TCCR4C = (1 << COM4D0) | (1 << PWM4D);
	TCCR4D = 0;
	TCCR4E = (1 << ENHC4);
	TC4H = 1;
	OCR4C = 0xFF;
	TC4H = 3;
	OCR4D = 0xE0;
	TEC_PWM_DDR |= TEC_PWM_MASK;
	TEC_FIXED_DDR |= TEC_FIXED_MASK;
	TEC_FIXED_PORT &= ~TEC_FIXED_UP;
	TEC_FIXED_PORT |= TEC_FIXED_DOWN;
	TCCR4B = (1 << CS40);

	LED_1_DDR |= (1 << LED_1_PINNUM);
	LED_1_PORT |= (1 << LED_1_PINNUM);
}
예제 #5
0
파일: bmp_image.cpp 프로젝트: r0mai/r0math
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);
}
예제 #6
0
파일: test.c 프로젝트: tlively/cs51-final
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);
}
예제 #7
0
/* Change la couleur utilisee pour les traces */
void ChangerCouleur(int couleur) {
   switch (couleur) {
      case Rouge :
         set_red(fenetreCourante); 
         break;
      case Bleu :
         set_blue(fenetreCourante); 
         break;
      case Vert:
         set_green(fenetreCourante); 
         break;
      case Jaune:
         set_yellow(fenetreCourante); 
         break;
      case Blanc:
         set_white(fenetreCourante);
         break;
      default:
         set_black(fenetreCourante); 
         break;      
   }
}
예제 #8
0
/*
 *  Insert an item in the tree, but only if it is unique
 *   otherwise, the item is returned non inserted
 *  The big trick is keeping the tree balanced after the
 *   insert. We use a parent pointer to make it simpler and
 *   to avoid recursion.
 *
 * Returns: item         if item inserted
 *          other_item   if same value already exists (item not inserted)
 */
void *rblist::insert(void *item, int compare(void *item1, void *item2))
{
   void *x, *y;
   void *last = NULL;        /* last leaf if not found */
   void *found = NULL;
   int comp = 0;

   /* Search */
   x = head;
   while (x && !found) {
      last = x;
      comp = compare(item, x);
      if (comp < 0) {
         x = left(x);
      } else if (comp > 0) {
         x = right(x);
      } else {
         found = x;
      }
   }

   if (found) {                    /* found? */
      return found;                /* yes, return item found */
   }
   set_left(item, NULL);
   set_right(item, NULL);
   set_parent(item, NULL);
   set_red(item, false);
   /* Handle empty tree */
   if (num_items == 0) {
      head = item;
      num_items++;
      return item;
   }
   x = last;
   /* Not found, so insert it on appropriate side of tree */
   if (comp < 0) {
      set_left(last, item);
   } else {
      set_right(last, item);
   }
   set_red(last, true);
   set_parent(item, last);
   num_items++;

   /* Now we must walk up the tree balancing it */
   x = last;
   while (x != head && red(parent(x))) {
      if (parent(x) == left(parent(parent(x)))) {
         /* Look at the right side of our grandparent */
         y = right(parent(parent(x)));
         if (y && red(y)) {
            /* our parent must be black */
            set_red(parent(x), false);
            set_red(y, false);
            set_red(parent(parent(x)), true);
            x = parent(parent(x));       /* move up to grandpa */
         } else {
            if (x == right(parent(x))) { /* right side of parent? */
               x = parent(x);
               left_rotate(x);
            }
            /* make parent black too */
            set_red(parent(x), false);
            set_red(parent(parent(x)), true);
            right_rotate(parent(parent(x)));
         }
      } else {
         /* Look at left side of our grandparent */
         y = left(parent(parent(x)));
         if (y && red(y)) {
            set_red(parent(x), false);
            set_red(y, false);
            set_red(parent(parent(x)), true);
            x = parent(parent(x));       /* move up to grandpa */
         } else {
            if (x == left(parent(x))) {
               x = parent(x);
               right_rotate(x);
            }
            /* make parent black too */
            set_red(parent(x), false);
            set_red(parent(parent(x)), true);
            left_rotate(parent(parent(x)));
         }
      }
   }
   /* Make sure the head is always black */
   set_red(head, false);
   return item;
}
예제 #9
0
void FixtureRGB::set_rgb(uint8_t r, uint8_t g, uint8_t b)
{
    set_red(r);
    set_green(g);
    set_blue(b);
}