Ejemplo n.º 1
0
void ImageConverter::loadImage(LameImage image)
{
    _image = image;
    setFrameSize(_image.width(), _image.height());
    setDynamicRange();
    recolor();
}
Ejemplo n.º 2
0
static void mk_new_int(JRB l, JRB r, JRB p, int il)
{
  JRB newnode;

  newnode = (JRB) calloc(1, sizeof(struct jrb_node));
  setint(newnode);
  setred(newnode);
  setnormal(newnode);
  newnode->flink = l;
  newnode->blink = r;
  newnode->parent = p;
  setlext(newnode, l);
  setrext(newnode, r);
  l->parent = newnode;
  r->parent = newnode;
  setleft(l);
  setright(r);
  if (ishead(p)) {
    p->parent = newnode;
    setroot(newnode);
  } else if (il) {
    setleft(newnode);
    p->flink = newnode;
  } else {
    setright(newnode);
    p->blink = newnode;
  }
  recolor(newnode);
}
Ejemplo n.º 3
0
static void mk_new_int(Rb_node l, Rb_node r, Rb_node p, int il)
{
  Rb_node newnode;
 
  newnode = (Rb_node) malloc(sizeof(struct rb_node));
  setint(newnode);
  setred(newnode);
  setnormal(newnode);
  newnode->c.child.left = l;
  newnode->c.child.right = r;
  newnode->p.parent = p;
  newnode->k.lext = l;
  newnode->v.rext = r;
  l->p.parent = newnode;
  r->p.parent = newnode;
  setleft(l);
  setright(r);
  if (ishead(p)) {
    p->p.root = newnode;
    setroot(newnode);
  } else if (il) {
    setleft(newnode);
    p->c.child.left = newnode;
  } else {
    setright(newnode);
    p->c.child.right = newnode;
  }
  recolor(newnode);
}  
Ejemplo n.º 4
0
QRect RotationCropper::crop()
{
    y1 = 0;
    int tolerance = 3;
    recolor();
    for (int y = 0; y < image->height(); y ++) {
        if (checkHorzLine(y)) {
            tolerance--;
            if (tolerance == 0) {
                y1 = y;
                break;
            }

        } else
            tolerance = 3;
    }
    y2 = image->height()-1;
    tolerance = 3;
    for (int y = y2; y >= 0; y--) {
        if (checkHorzLine(y)) {
            tolerance--;
            if (tolerance == 0) {
                y2 = y;
                break;
            }

        } else
            tolerance = 3;
    }
    x1 = 0;
    tolerance = 3;
    for (int x = x1; x < image->width(); x++) {
        if (checkVertLine(x)) {
            tolerance--;
            if (tolerance == 0) {
                x1 = x;
                break;
            }

        } else
            tolerance = 3;
    }
    x2 = image->width()-1;
    tolerance = 3;
    for (int x = x2; x >= 0; x--) {
        if (checkVertLine(x)) {
            tolerance--;
            if (tolerance == 0) {
                x2 = x;
                break;
            }

        } else
            tolerance = 3;
    }
    return QRect(x1, y1, x2-x1, y2-y1);
}
Ejemplo n.º 5
0
  void RTSpheres::finishPicking(uint32_t& offset, const uint32_t val)
  {
    recolor();

    bool picked = (val >= offset) && ((val - offset) < _N);

    if (picked)
      std::cout << "You picked a sphere! with an ID of " 
		<< (val - offset) << std::endl;

    offset += _N;
  }
Ejemplo n.º 6
0
void ColoredTreeModel::recolor(const QModelIndex &parent)
{
  const QModelIndex topLeft = index(0, 0, parent);
  const int _rowCount = rowCount(parent);
  const QModelIndex bottomRight = index(_rowCount - 1, columnCount(parent) -1, parent );
  emit dataChanged(topLeft, bottomRight);

  static const int column = 0;
  QModelIndex idx;
  for (int row = 0; row < _rowCount; ++row)
  {
    idx = index(row, column, parent);
    if (hasChildren(idx))
      recolor(idx);
  }
}
Ejemplo n.º 7
0
static void
despeckle_iteration (/* in */     int    level,
                     /* in */     double adaptive_tightness,
                     /* in */     double noise_max,
                     /* in */     int    width,
                     /* in */     int    height,
                     /* in/out */ unsigned char *bitmap)
{
  unsigned char *mask;
  int    x, y;
  int    current_size;
  int    tightness;

  /* Size doubles each iteration level, so current_size = 2^level */
  current_size = 1 << level;
  tightness = (int) (noise_max / (1.0 + adaptive_tightness * level));

  mask = (unsigned char *) calloc (width * height, sizeof(unsigned char));
  for (y = 0; y < height; y++)
    {
      for (x = 0; x < width; x++)
        {
          if (mask[y * width + x] == 0)
            {
              int size;

              size = find_size (&bitmap[3 * (y * width + x)], x, y,
                                width, height, bitmap, mask);

              assert (size > 0);

              if (size < current_size)
                {
                  if (recolor (tightness,
                               x, y, width, height,
                               bitmap, mask))
                    x--;
                }
              else
                ignore (x, y, width, height, mask);
            }
        }
    }

  free (mask);
}
Ejemplo n.º 8
0
int
waitrays(void)					/* finish up pending rays */
{
	int	nwaited = 0;
	int	rval;
	RAY	raydone;

	if (!ray_pnprocs)			/* immediate mode? */
		return(0);
	while ((rval = ray_presult(&raydone, 0)) > 0) {
		PNODE  *p = (PNODE *)raydone.rno;
		copycolor(p->v, raydone.rcol);
		scalecolor(p->v, exposure);
		recolor(p);
		nwaited++;
	}
	if (rval < 0)
		return(-1);
	return(nwaited);
}
Ejemplo n.º 9
0
  void 
  RTSpheres::sortTick(const magnet::GL::Camera& camera)
  {
    cl_float4 campos = getclVec(camera.getEyeLocation());
    cl_float4 camdir = getclVec(camera.getCameraDirection());
    cl_float4 camup = getclVec(camera.getCameraUp());
  
    //Generate the sort data
    _sortDataKernelFunc(_spherePositions, _sortKeys, _sortData,
			campos, camdir, camup,
			(cl_float)camera.getAspectRatio(),
			(cl_float)camera.getZNear(),
			(cl_float)camera.getFOVY(),
			_N);
  
    if ((_renderDetailLevels.size() > 2) 
	|| (_renderDetailLevels.front()._nSpheres != _N))
      sortFunctor(_sortKeys, _sortData);
  
    recolor();
  }
Ejemplo n.º 10
0
int main(string param) {
   string command = "", arg = "";
   string warcry = this_player()->query_env_var("warcry");
   string myName = this_player()->query_cap_name();
   set_actor(this_player());
   set_target(this_player());
   if(!param) {
      if( warcry ) {
         int check;
		 object warcry_ob;
		 // can't already be in combat
		 if( this_player()->query_in_combat() ) {
		    notify_fail("You cannot shout your warcry once battle has been joined!\n");
			return 0;
		 }
		 // can't already have a warcry active
		 if( present_clone("/battle/warcry_object",this_player()) ) {
		    notify_fail("You have already shouted your warcry, hurry up and kill something!\n");
			return 0;
		 }
         // must have endurance
		 if( this_player()->query_endurance() < 10 ) {
            notify_fail("You don't have enough endurance to shout your warcry.\n");
			return 0;
		 }
		 // determine strength of cry
		 check = this_player()->get_skill_roll("combat.tactics");
		 //practice is handled by the object so they don't get free pracs for shouting outside
		 //of combat ;)
		 //this_player()->practice_skill( "combat.tactics", min(1, check / 25) );
		 // debit endurance
		 this_player()->add_endurance( -2 - check/10 );
		 if( this_player()->query_endurance() < 1 ) {
            check += this_player()->query_endurance() * 10;
			this_player()->set_endurance( 1 );
		 }
		 // give them the object
		 warcry_ob = clone_object("/battle/warcry_object");
		 warcry_ob->do_setup( this_player(), check );
		 // issue message
	     warcry = recolor(warcry);
         if(!this_player()->query_toad())
            this_player()->msg_local("~[010~Name ~verbshout ~poss warcry: ~CDEF" + warcry);
      } else {
         msg("You whimper like a puppy. Perhaps you should set a warcry first?");
	  }
   } else {
      if(sscanf(param, "%s %s", command, arg) != 2) {
         command = param;
      }
      switch(command) {
	     case "check":
            if(warcry != 0) {
               msg("Your warcry is: " + warcry);
            } else {
               msg("Sorry, you haven't set a warcry yet.");
            }
            break;
         case "set":
            this_player()->set_env_var("warcry", arg);
            msg("Warcry set to: " + arg);
            break;
         default:
            msg("Please read ~CREFhelp warcry~CDEF for the correct usage of this verb.");
      }
   }
   return 1;
}
Ejemplo n.º 11
0
int
paint(			/* compute and paint a rectangle */
	PNODE  *p
)
{
	static RAY  thisray;
	double  h, v;

	if ((p->xmax <= p->xmin) | (p->ymax <= p->ymin)) {	/* empty */
		p->x = p->xmin;
		p->y = p->ymin;
		setcolor(p->v, 0.0, 0.0, 0.0);
		return(0);
	}
						/* jitter ray direction */
	p->x = h = p->xmin + (p->xmax-p->xmin)*frandom();
	p->y = v = p->ymin + (p->ymax-p->ymin)*frandom();
	
	if ((thisray.rmax = viewray(thisray.rorg, thisray.rdir, &ourview,
			h/hresolu, v/vresolu)) < -FTINY) {
		setcolor(thisray.rcol, 0.0, 0.0, 0.0);
	} else if (!ray_pnprocs) {		/* immediate mode */
		ray_trace(&thisray);
	} else {				/* queuing mode */
		int	rval;
		rayorigin(&thisray, PRIMARY, NULL, NULL);
		thisray.rno = (RNUMBER)p;
		rval = ray_pqueue(&thisray);
		if (!rval)
			return(0);
		if (rval < 0)
			return(-1);
						/* get node for returned ray */
		p = (PNODE *)thisray.rno;
	}

	copycolor(p->v, thisray.rcol);
	scalecolor(p->v, exposure);

	recolor(p);				/* paint it */

	if (dev->flush != NULL) {		/* shall we check for input? */
		static RNUMBER	lastflush = 0;
		RNUMBER		counter = raynum;
		int		flushintvl;
		if (!ray_pnprocs) {
			counter = nrays;
			flushintvl = WFLUSH1;
		} else if (ambounce == 0)
			flushintvl = ray_pnprocs*WFLUSH;
		else if (niflush < WFLUSH)
			flushintvl = ray_pnprocs*niflush/(ambounce+1);
		else
			flushintvl = ray_pnprocs*WFLUSH/(ambounce+1);
		if (lastflush > counter)
			lastflush = 0;		/* counter wrapped */

		if (counter - lastflush >= flushintvl) {
			lastflush = counter;
			(*dev->flush)();
			niflush++;
		}
	}
	return(1);
}
Ejemplo n.º 12
0
rbtree_node_t*
rbtree_remove(rbtree_t                 *tree,
              rbtree_node_t            *node,
              rbtree_node_destructor_t destructor)
{
  rbtree_color_t color;
  rbtree_node_t  *child, *parent, *original = node;
  rbtree_node_t  *next;

  next = rbtree_node_next(node);

  if(node->child[LEFT] != NULL && node->child[RIGHT] != NULL)
  {
    rbtree_node_t *old = node;

    node = node->child[RIGHT];
    while(node->child[LEFT] != NULL)
      node = node->child[LEFT];

    parent = get_parent(old);
    if(parent != NULL)
    {
      if(parent->child[LEFT] == old)
        parent->child[LEFT] = node;
      else
        parent->child[RIGHT] = node;
    }
    else
      tree->root = node;

    child  = node->child[RIGHT];
    parent = get_parent(node);
    color  = get_color(node);

    if(parent == old)
      parent = node;
    else
    {
      if(child != NULL)
        set_parent(child, parent);
      parent->child[LEFT] = child;

      node->child[RIGHT] = old->child[RIGHT];
      set_parent(old->child[RIGHT], node);
    }

    node->parent_color = old->parent_color;
    node->child[LEFT] = old->child[LEFT];
    set_parent(old->child[LEFT], node);
  }
  else
  {
    if(node->child[LEFT] == NULL)
      child = node->child[RIGHT];
    else
      child = node->child[LEFT];

    parent = get_parent(node);
    color  = get_color(node);

    if(child != NULL)
      set_parent(child, parent);
    if(parent != NULL)
    {
      if(parent->child[LEFT] == node)
        parent->child[LEFT] = child;
      else
        parent->child[RIGHT] = child;
    }
    else
      tree->root = child;
  }

  if(color == BLACK)
    recolor(tree, parent, child);

  if(destructor != NULL)
    (*destructor)(original);

  tree->size -= 1;

  return next;
}
Ejemplo n.º 13
0
	void repair(Node* n) 
	{
		while (n != _root               && 
			   n->_color == RED         && 
			   n->_parent->_color == RED)
		{
			// Case A
			if (n->_parent->isLeftChild())
			{
				if (n->isLeftChild() )
				{
					if (n->uncle() == 0 || n->uncle()->_color == BLACK)
					{
						// Case A.1
						Node* p = n->_parent;
						Node* g = p->_parent;
						rotateRight(g);
						n = p;
					}
					else
					{
						// Case A.4
						Node* g = n->_parent->_parent;
						recolor(g);
						n = g;
					}
				}
				else 
				{
					Node* u = n->uncle();
					// Case A.2
					if (u != 0 && u->_color == RED)
					{
						recolor(n->_parent->_parent);
						n = n->_parent->_parent;						
					}
					else 
					{
						// Case A.3
						Node* g = n->_parent->_parent;
						rotateLeft(n->_parent);
						rotateRight(g);
					}
				}
			}
			else  // Case B
			{
				if (!n->isLeftChild() )
				{
					if (n->uncle() == 0 || n->uncle()->_color == BLACK)
					{
						// Case B.1
						Node* p = n->_parent;
						Node* g = p->_parent;
						rotateLeft(g);
						n = p;
					}
					else
					{
						// Case B.4
						Node* g = n->_parent->_parent;
						recolor(g);
						n = g;
					}
				}
				else 
				{
					Node* u = n->uncle();
					// CASE B.2
					if (u != 0 && u->_color == RED)
					{
						recolor(n->_parent->_parent);
						n = n->_parent->_parent;						
					}
					else 
					{
						// Case B.3
						Node* g = n->_parent->_parent;
						rotateRight(n->_parent);
						rotateLeft(g);
					}
				}
			}
		}
		_root->_color = BLACK;
	}
Ejemplo n.º 14
0
/* Fill the sentence with new words: in "page" mode, fills the page
   with text; in "scroll" mode, just makes one long horizontal sentence.
   The sentence might have *no* words in it, if no text is currently
   available.
 */
static void
populate_sentence (state *s, sentence *se)
{
  int i = 0;
  int left, right, top, x, y;
  int space = 0;
  int line_start = 0;
  Bool done = False;

  int array_size = 100;

  se->move_chars_p = (s->mode == SCROLL ? False :
                      (random() % 3) ? False : True);
  se->alignment = (random() % 3);

  recolor (s, se);

  if (se->words)
    {
      for (i = 0; i < se->nwords; i++)
        free_word (s, se->words[i]);
      free (se->words);
    }

  se->words = (word **) calloc (array_size, sizeof(*se->words));
  se->nwords = 0;

  switch (s->mode)
    {
    case PAGE:
      left  = random() % (s->xgwa.width / 3);
      right = s->xgwa.width - (random() % (s->xgwa.width / 3));
      top = random() % (s->xgwa.height * 2 / 3);
      break;
    case SCROLL:
      left = 0;
      right = s->xgwa.width;
      top = random() % s->xgwa.height;
      break;
    default:
      abort();
      break;
    }

  x = left;
  y = top;

  while (!done)
    {
      char *txt = get_word_text (s);
      word *w;
      if (!txt)
        {
          if (se->nwords == 0)
            return;		/* If the stream is empty, bail. */
          else
            break;		/* If EOF after some words, end of sentence. */
        }

      if (! se->font)           /* Got a word: need a font now */
        {
          pick_font (s, se);
          if (y < se->font->ascent)
            y += se->font->ascent;
          space = XTextWidth (se->font, " ", 1);
        }

      w = new_word (s, se, txt, !se->move_chars_p);

      /* If we have a few words, let punctuation terminate the sentence:
         stop gathering more words if the last word ends in a period, etc. */
      if (se->nwords >= 4)
        {
          char c = w->text[strlen(w->text)-1];
          if (c == '.' || c == '?' || c == '!')
            done = True;
        }

      /* If the sentence is kind of long already, terminate at commas, etc. */
      if (se->nwords >= 12)
        {
          char c = w->text[strlen(w->text)-1];
          if (c == ',' || c == ';' || c == ':' || c == '-' ||
              c == ')' || c == ']' || c == '}')
            done = True;
        }

      if (se->nwords >= 25)  /* ok that's just about enough out of you */
        done = True;

      if (s->mode == PAGE &&
          x + w->rbearing > right)			/* wrap line */
        {
          align_line (s, se, line_start, x, right);
          line_start = se->nwords;

          x = left;
          y += se->font->ascent;

          /* If we're close to the bottom of the screen, stop, and 
             unread the current word.  (But not if this is the first
             word, otherwise we might just get stuck on it.)
           */
          if (se->nwords > 0 &&
              y + se->font->ascent > s->xgwa.height)
            {
              unread_word (s, w);
              /* done = True; */
              break;
            }
        }

      w->target_x = x + w->lbearing;
      w->target_y = y - w->ascent;

      x += w->rbearing + space;
      se->width = x;

      if (se->nwords >= (array_size - 1))
        {
          array_size += 100;
          se->words = (word **) realloc (se->words,
                                         array_size * sizeof(*se->words));
          if (!se->words)
            {
              fprintf (stderr, "%s: out of memory (%d words)\n",
                       progname, array_size);
              exit (1);
            }
        }

      se->words[se->nwords++] = w;
    }

  se->width -= space;

  switch (s->mode)
    {
    case PAGE:
      align_line (s, se, line_start, x, right);
      if (se->move_chars_p)
        split_words (s, se);
      scatter_sentence (s, se);
      shuffle_words (s, se);
      break;
    case SCROLL:
      aim_sentence (s, se);
      break;
    default:
      abort();
      break;
    }

# ifdef DEBUG
  if (s->debug_p)
    {
      fprintf (stderr, "%s: sentence %d:", progname, se->id);
      for (i = 0; i < se->nwords; i++)
        fprintf (stderr, " %s", se->words[i]->text);
      fprintf (stderr, "\n");
    }
# endif
}
Ejemplo n.º 15
0
void ColoredTreeModel::setSelectionModel(QItemSelectionModel *selectionModel)
{
  m_selectionModel = selectionModel;
  connect(selectionModel, SIGNAL(selectionChanged(QItemSelection,QItemSelection)), SLOT(recolor()));
}