示例#1
0
Word HAC_CONS(Word c, Word P)
{
  Word r,P_r,n,i,M,L,k,m,T,p,cp,I;

Step1: /* Construct empty multiplicity vector. */
  r = LELTI(c,LEVEL);
  P_r = LELTI(P,r);
  n = LENGTH(P_r);
  for(i = 0, M = NIL; i < n; i++)
    M = COMP(0,M);

Step2: /* Set non-zero entries from cells multiplicity list. */
  for(L = LELTI(c,MULSUB); L != NIL; L = RED(L)) {
    FIRST2(FIRST(L),&k,&m);

    /*-- Find p, the p.f. with index k. --*/
    for(T = P_r, i = 1; T != NIL; T = RED(T),i++) {
      p = FIRST(T);
      if (k == THIRD(LELTI(p,PO_LABEL)))
	break; }

    /*-- Proj.fac. with index k has been removed from the set. --*/
    if (T == NIL) continue;

    SLELTI(M,i,m); }

Return: /* Construct cp and return. */
  I = LELTI(c,INDX);
  cp = LIST2(I,M); 
  return cp;
}
示例#2
0
static Word comp1(Word a,Word b) {
  Word A,B,t;
  A = RED(a); B = RED(b); t = 0;
  while ( t == 0 && A != NIL ) {
    t = BDCOMP(FIRST(A),FIRST(B));
    A = RED(A); B = RED(B); }
  return (t); }
示例#3
0
/* ESPCAD cell triple and polynomial index list of strong necessary conditions. */
Word ESPCADCTPILSNC(Word c1,Word c2, Word c3, Word i, Word j,Word k, Word P)
{
  Word Lt,Lf,C,c,A,tt,tf,L,Lp,Ls;

Step1: /* Classify cells as true or false. */
  C = LIST3(c1,c2,c3);
  for(Lt = NIL, Lf = NIL; C != NIL; C = RED(C)) {
    c = FIRST(C);
    switch(LELTI(c,SC_TMPM)) {
    case TRUE:  Lt = COMP(c,Lt); break;
    case FALSE: Lf = COMP(c,Lf); break;
    default: break; } }

Step2: /* Need a true cell and a false cell to continue. */
  if (Lt == NIL || Lf == NIL) {
    L = NIL;
    goto Return; }

Step3: /* Weed out conditions that are not strong & necessary. */
  Ls = FMAAFPIRN(i,j,k);
  for(L = NIL; Ls != NIL; Ls = RED(Ls)) {
    A = FIRST(Ls);
    for(tt = 1, Lp = Lt; tt && Lp != NIL; Lp = RED(Lp))
      tt = FMACELLEVAL(A,FIRST(Lp),P);
    for(tf = 1, Lp = Lf; tf && Lp != NIL; Lp = RED(Lp))
      tf = FMACELLEVAL(A,FIRST(Lp),P);
    if (tt && !tf)
      L = COMP(A,L); }

Return: /* */
  return L;
}
示例#4
0
Word VECTOR_LTEQ(Word u, Word v)
{
  for(; u != NIL; u = RED(u), v = RED(v))
    if (FIRST(u) > FIRST(v))
      return 0;
  return 1;
}
示例#5
0
文件: compose.c 项目: jvesely/helenos
pixel_t compose_over(pixel_t fg, pixel_t bg)
{
	double mul;
	double mul_cmp;

	double res_a;
	double res_r;
	double res_g;
	double res_b;

	if (ALPHA(bg) == 255) {
		res_a = 1;
		mul = ((double) ALPHA(fg)) / 255.0;
		mul_cmp = 1 - mul;
	} else {
		double fg_a = ((double) ALPHA(fg)) / 255.0;
		double bg_a = ((double) ALPHA(bg)) / 255.0;

		res_a = 1 - (1 - fg_a) * (1 - bg_a);
		mul = fg_a / res_a;
		mul_cmp = 1 - mul;
	}

	res_r = mul * ((double) RED(fg)) + mul_cmp * ((double) RED(bg));
	res_g = mul * ((double) GREEN(fg)) + mul_cmp * ((double) GREEN(bg));
	res_b = mul * ((double) BLUE(fg)) + mul_cmp * ((double) BLUE(bg));

	return PIXEL((unsigned) (res_a * 255),
	    (unsigned) res_r, (unsigned) res_g, (unsigned) res_b);
}
void PointSet::Draw ( float* view_mat, float rad )
{
	char* dat;
	Point* p;
	glEnable ( GL_NORMALIZE );	

	if ( m_Param[PNT_DRAWMODE] == 0 ) {
		glLoadMatrixf ( view_mat );
		dat = mBuf[0].data;	
		for (int n = 0; n < NumPoints(); n++) {
			p = (Point*) dat;
			glPushMatrix ();
			glTranslatef ( p->pos.x, p->pos.y, p->pos.z );		
			glScalef ( 0.2, 0.2, 0.2 );	
			if(p->type == 0)
			glColor4f ( 0.1,0.3,1.0,1.0 );//glColor4f ( RED(p->clr), GRN(p->clr), BLUE(p->clr), ALPH(p->clr) );
			else
            glColor4f ( RED(p->clr), GRN(p->clr), BLUE(p->clr), 0.0 );
			drawSphere ();
			glPopMatrix ();		
			dat += mBuf[0].stride;
		}	
	} else if ( m_Param[PNT_DRAWMODE] == 1 ) {
		glLoadMatrixf ( view_mat );
		dat = mBuf[0].data;
		glBegin ( GL_POINTS );
		for (int n=0; n < NumPoints(); n++) {
			p = (Point*) dat;
			glColor3f ( RED(p->clr), GRN(p->clr), BLUE(p->clr) );			
			glVertex3f ( p->pos.x, p->pos.y, p->pos.z );			
			dat += mBuf[0].stride;
		}
		glEnd ();
	}
}
示例#7
0
Word QepcadCls::ACCCVBCR(Word k, Word c, Word B1, Word b, Word* B1h)
{
  Word d, nnf, dV, IV, cp, i, I_i, d_i, c_i, L, Q, Qb, Qbs, F, Fp, a;

Step1: /* Initialization **********************************************/
  a = NIL; /* this is the pseudo-sample point we're building up *******/
  F = NIL; /* Useless now, could be usefull later. ********************/
  d = 0;   /* dimension of cell c_i. **********************************/
  nnf = 0; /* number of variables not fixed. **************************/
  dV = CINV(RED(PDEGV(k+1,B1))); /* vector of degrees of first k ******
				    variables of B1. ******************/
  IV = LELTI(c,INDX);            /* vector of indices of cell c. ******/


Step2: /* Loop over each level from 1 to k ****************************/
  c_i = GVPC;
  for(i = 1; i <= k; i++) {
    I_i = LELTI(IV,i);
    d_i = LELTI(dV,i);
    c_i = LELTI(LELTI(c_i,CHILD),I_i);
    
Step3: /* c_i is a section over a 0-dimensional cell ******************/
    if ((I_i % 2 == 0) && d == 0) {
      a = SUFFIX(a,LELTI(b,i));
      continue; }
    
Step4: /* c_i is a section over a cell of dimension greater than zero */
    if ((I_i % 2 == 0) && d > 0) {
      for(L=SECTIONPOLS(i,c_i,GVPF),Qbs=1,Fp=NIL; L != NIL; L=RED(L)) {
	Q = RPFIP(i,LELTI(FIRST(L),PO_POLY));
	Qb = SPECIALSUBSR(i,a,Q); /* Qb can't be zero, by definition of 
				     SECTIONPOLS */
	Qbs = RPEMV(nnf + 1,Qb,LELTI(b,i));
	if (Qbs == 0) {
	  a = SUFFIX(a,LELTI(b,i));
	  break; }
	else
	  Fp = COMP(Qb,Fp); }
      if (L == NIL) {
	F = CCONC(F,Fp);
	nnf++;
	a = SUFFIX(a,NIL);
      } }
    
Step5: /* c_i is a sector *********************************************/
    if (I_i % 2 == 1) {
      d++;
      nnf++;
      a = SUFFIX(a,NIL); }
  }

/*Step6: a is the psuedo-sample point, check that B1 is univariate at a. */
  bool uniq = true;
  Word B1b = SPECIALSUBSR(k+1,a,RPFIP(k+1,B1));
  for(Word B1s = B1b; uniq && B1s != 0; B1s = PRED(B1s))
    uniq = IPCONST(nnf,PLDCF(B1s));
  if (B1h != 0) *B1h = B1b;

  return uniq ? TRUE : UNDET;
}
示例#8
0
Word ADJ_2D1(Word c, Word c_l, Word P, Word J)
{
  Word U,V,v_l,Sol,S,A,Ap,a,b;
  /*
init();
sa_send("[");
  */
Step1: /* Initialization. */
  v_l = LDCOEFMASK(c,P,J);
  U = AD2DS_CONS(c_l,P);
  V = AD2DS_CONS(c,P);

Step2: /* Get Adjacencies. */
  /* Sol = ADJ_2D1_SIMPLE(U,V,v_l,FIRST(LELTI(c,INDX))); */
  Sol = ADJ_2D1P1(U,V,v_l,FIRST(LELTI(c,INDX)));

Step3: /* If c_l is to the right of c, reverse order of pairs. */
  if (FIRST(LELTI(c,INDX)) < FIRST(LELTI(c_l,INDX))) {
    for(S = NIL; Sol != NIL; Sol = RED(Sol)) {
      for(A = NIL, Ap = FIRST(Sol); Ap != NIL; Ap = RED(Ap)) {
	FIRST2(FIRST(Ap),&a,&b);
	A = COMP(LIST2(b,a),A); }
      S = COMP(A,S); }
    Sol = S; }

Return: /* Prepare to return. */
  /*
  sa_send("]\n");
  uninit();
  */
  return Sol;
}
示例#9
0
Word PCADCSV(Word cs, Word Ps)
{
      Word c,l,S,s,I,V,Vs;

Step1: /* */
      c = LELTI(cs,SC_REP);
      l = LELTI(c,LEVEL);
      if (l == 0) {
	Vs = NIL; goto Return; }
      S = LELTI(Ps,l);

      for(I = NIL; S != NIL; S = RED(S)) {
	s = FIRST(S);
	I = COMP(THIRD(LELTI(s,PO_LABEL)),I); }

      LBIBMS(I);
      I = CINV(I);

      V = FIRST(LELTI(c,SIGNPF));
      for(Vs = NIL;I != NIL; I = RED(I))
	Vs = COMP(LELTI(V,FIRST(I)),Vs);      

Return: /* Prepare to return. */
      return (Vs);
}
示例#10
0
Word CADFPCAD(Word D, Word P, Word S, Word I, Word Pb)
{
      Word Db,Is,N,Sb,Pb_N,Ts,L,p,i,is,Q,Ms,C,Cs,Ds,Ss;
      Word Mb,mb;

Step1: /* Is D the root cell? */
      Db = LELTI(D,SC_REP);
      if (LELTI(D,SC_PAR) == NIL) {
	Is = NIL;
	Ss = NIL;
	Ms = NIL; }

      else {
Step2: /* D is not the root cell. */
	Is = CINV(COMP(LELTI(D,SC_INX),CINV(I)));
	N = LENGTH(Is);

Step3: /* Signiture & multiplicity information. */
	Sb = FIRST(LELTI(Db,SIGNPF));
	Pb_N = LELTI(Pb,N);
	Ts = NIL; Ms = NIL; is = 0;

 /* Loop over each level N polynomial in P. */
	for(L = CINV(LELTI(P,N)); L != NIL; L = RED(L)) {
	  p = FIRST(L); i = 1; is++;

 /* Set i so that p is the ith level N pol in Pb. */
	  i = PFPIPFL(p,Pb_N);
	  if (i == 0) { SWRITE("CAPFPCAD: Can't find the polynomial!\n"); }
	  Ts = COMP(LELTI(Sb,i),Ts);

 /* Set the multiplicity list if necessary */
	  for (Mb = LELTI(Db,MULSUB); Mb != NIL; Mb = RED(Mb)) {
	    mb = FIRST(Mb);
	    if (FIRST(mb) == THIRD(LELTI(p,PO_LABEL))) {
	      Ms = COMP(mb,Ms); } } }
	/*	Ms = CINV(Ms); */
	Ss = COMP(Ts,S); }

Step4: /* Children. */
	C = LELTI(D,SC_CDTV);
	if ( ISATOM(C) ) {
	  Cs = NIL; }
	else {
	  for(Cs = NIL; C != NIL; C = RED(C)) {
	    Cs = COMP(CADFPCAD(FIRST(C),P,Ss,Is,Pb),Cs); }
	  Cs = CINV(Cs); }

Step5: /*  */
	Ds = LCOPY(Db);
	SLELTI(Ds,CHILD,Cs);
	SLELTI(Ds,INDX,Is);
	SLELTI(Ds,SIGNPF,Ss);
	SLELTI(Ds,HOWTV,NOTDET); /* Might want to change. */
	SLELTI(Ds,MULSUB,Ms);

Return: /* Prepare to return. */
	return (Ds);
}
示例#11
0
static Word comp(Word a, Word b) {
      Word ap,bp,t,q;
      ap = a; bp = b;
      t =  BDCOMP(LENGTH(ap),LENGTH(bp));
      while ((t == 0) && (bp != NIL) && (ap != NIL)) { 
	 t = BDCOMP(FIRST(ap),FIRST(bp)); ap = RED(ap); bp = RED(bp); }
      if (t == 0) { t = BDCOMP(ap,bp); }
      return (t); }
示例#12
0
Word DOPFSUFF(Word P, Word K)
{
      Word t,L,Kp,Lp,T,F,N,Lpp,tp;

Step1: /* Initialize. */
      if (LELTI(FIRST(K),LEVEL) == 0 && LELTI(FIRST(K),CHILD) == NIL) {
	t = LELTI(FIRST(K),TRUTH);
	goto Return; }
      else
	t = NIL;

Step3: /* List cells of level r, sorted by signiture. */
      L = NIL;
      for(Kp = K; Kp != NIL; Kp = RED(Kp)) {
	L = CCONC(LELTI(FIRST(Kp),CHILD),L); }
      L = GMSL(L,comp);

Step4: /* Loop over each block of cells with same signiture. */
      while (L != NIL) {
	Lp = NIL;
	do {
	  Lp = COMP(FIRST(L),Lp);
	  L = RED(L);
	} while (L != NIL && comp(FIRST(Lp),FIRST(L)) == 0);

Step5: /* Get the number of TRUE leaf cells and FALSE leaf cells. */
	T = 0; F = 0; N = 0;
	for(Lpp = Lp; Lpp != NIL; Lpp = RED(Lpp)) {
	  switch( LELTI(FIRST(Lpp),TRUTH) ) {
	  case TRUE : T++; break;
	  case FALSE: F++; break;
	  case NA:    N++; break; } }

Step6: /* Case:  All cells are leaf cells. */
	if (T + F + N == LENGTH(Lp)) {
	  if ( T == 0 && F == 0 ) { tp = NA; goto Step8; }
	  if ( T > 0 && F == 0 )  { tp = TRUE; goto Step8; }
	  if ( F > 0 && T == 0 )  { tp = FALSE; goto Step8; }
	  t = NIL; goto Return; }

Step7: /* Case:  Not all cells are leaf cells. */
	tp = DOPFSUFF(P,Lp);
	if ( ( F == 0 && T == 0 && tp != NIL) ||
	     ( F == 0 && T > 0 && tp == TRUE ) ||
	     ( F > 0 && T == 0 && tp == FALSE ) )
	  goto Step8;
	t = NIL; goto Return;

Step8: /* Set t to the proper value.  t = NIL at this step only if
	  it is the first time through the loop. */
	if (t == NIL || t == NA) 
	  t = tp;
	else if (tp != NA && t != tp)
	  t = UNDET; }

Return: /* Prepare to return. */
      return (t);
}
示例#13
0
Word VECTOR_SUM(Word u, Word v)
{
  Word s,w;

  for(s = NIL; u != NIL; u = RED(u), v = RED(v))
    s = COMP(FIRST(u) + FIRST(v),s);
  w = INV(s);

  return w;
}
示例#14
0
Word LDCOEFMASK(Word c, Word P, Word J)
{
  Word *A,P_2,n,i,M,P_1,L,m,j,p,Lp,h,q,v,l;

Step1: /* Set up A to be a characteristic vector for the set of
level 2 proj fac's whose leading coefficients vanish in c. */
  P_2 = LELTI(P,2);
  n = THIRD(LELTI(LAST(P_2),PO_LABEL));
  A = GETARRAY(n + 1);
  for(i = 1; i <= n; i++)
    A[i] = 0;

Step2: /* Set L to be the list of projection factors which vanish in c. */
  M = LELTI(c,MULSUB);
  P_1 = LELTI(P,1);
  L = NIL;
  while(M != NIL) {
    ADV(M,&m,&M);
    j = FIRST(m); 
    do
      ADV(P_1,&p,&P_1);
    while(j != THIRD(LELTI(p,PO_LABEL)));
    L = COMP(p,L); }

Step3: /* Set Lp to the list of projection polynomials with factors in L. */
  Lp = NIL;
  while(L != NIL) {
    ADV(L,&p,&L);
    for(h = LELTI(p,PO_PARENT); h != NIL; h = RED(h))
      Lp = COMP(THIRD(FIRST(h)),Lp); }

Step4: /* Run through the histories of each polynomial in Lp.  If the 
polynomial is the leading coefficient of some bivariate projection factor,
set A at the index for that projection factor to 1. */
  while(Lp != NIL) {
    ADV(Lp,&p,&Lp);
    for(h = LELTI(p,PO_PARENT); h != NIL; h = RED(h)) {
      q = FIRST(h);
      if (FIRST(q) == PO_LCO) {
	l = LELTI(THIRD(q),PO_LABEL);
	if (SECOND(l) == 2)
	  A[ THIRD(l) ] = 1; } } }

Step5: /* Create the vector itself! */
  v = NIL;
  while(P_2 != NIL) {
    ADV(P_2,&p,&P_2);
    j = THIRD(LELTI(p,PO_LABEL));
    v = COMP(A[j],v); }
  v = INV(v);

Return: /* Prepare to return. */
  FREEARRAY(A);
  return v;
}
示例#15
0
ColorARGB GifTranscoder::computeAverage(ColorARGB c1, ColorARGB c2, ColorARGB c3, ColorARGB c4) {
    char avgAlpha = (char)(((int) ALPHA(c1) + (int) ALPHA(c2) +
                            (int) ALPHA(c3) + (int) ALPHA(c4)) / 4);
    char avgRed =   (char)(((int) RED(c1) + (int) RED(c2) +
                            (int) RED(c3) + (int) RED(c4)) / 4);
    char avgGreen = (char)(((int) GREEN(c1) + (int) GREEN(c2) +
                            (int) GREEN(c3) + (int) GREEN(c4)) / 4);
    char avgBlue =  (char)(((int) BLUE(c1) + (int) BLUE(c2) +
                            (int) BLUE(c3) + (int) BLUE(c4)) / 4);
    return MAKE_COLOR_ARGB(avgAlpha, avgRed, avgGreen, avgBlue);
}
示例#16
0
int normalize(int width, int height, unsigned char* rgb)
{
	int
		x,y,
		red_min=255, red_max=0, 
		blue_min=255, blue_max=0, 
		green_min=255, green_max=0;
	double
		min, max, amplify; 

	/* determine min and max per color... */

	for( y=0; y<height; y++){
		for( x=0; x<width; x++ ){
			MINMAX( RED(rgb,x,y,width), red_min,   red_max  );
			MINMAX( GREEN(rgb,x,y,width), green_min, green_max);
			MINMAX( BLUE(rgb,x,y,width), blue_min,  blue_max );
		}
	}

	/* determine min and max per color... */

	for( y=0; y<height; y++){
		for( x=0; x<width; x++ ){
			MINMAX( RED(rgb,x,y,width), red_min,   red_max  );
			MINMAX( GREEN(rgb,x,y,width), green_min, green_max);
			MINMAX( BLUE(rgb,x,y,width), blue_min,  blue_max );
		}
	}

	/* Normalize brightness ... */

	max = MAX( MAX( red_max, green_max ), blue_max);
	min = MIN( MIN( red_min, green_min ), blue_min);
	amplify = 255.0/(max-min);


	printf("min=%f max=%f amplify=%f\n",min,max,amplify);
	if (max == 255)
		printf("max is already max'ed at 255. Exiting from normalize()\n");
		return 0;



	for( y=0; y<height; y++){
		for( x=0; x<width; x++ ){
			RED(rgb,x,y,width)= MIN(amplify*(double)(RED(rgb,x,y,width)-min),255);
			GREEN(rgb,x,y,width)= MIN(amplify*(double)(GREEN(rgb,x,y,width)-min),255);
			BLUE(rgb,x,y,width)= MIN(amplify*(double)(BLUE(rgb,x,y,width)-min),255);
		}
	}

	return 0;
}
示例#17
0
static node_t *
rb_single(node_t *root, int dir)
{
	node_t *save = root->link[!dir];

	root->link[!dir] = save->link[dir];
	save->link[dir] = root;

	RED(root) = 1;
	RED(save) = 0;
	return save;
}
示例#18
0
internal void
PT_CopyBlend(u32 *destPixels, PT_Rect *destRect, u32 destPixelsPerRow,
             u32 *srcPixels, PT_Rect *srcRect, u32 srcPixelsPerRow,
             u32 *newColor)
{
    // If src and dest rects are not the same size ==> bad things
    assert(destRect->w == srcRect->w && destRect->h == srcRect->h);

    // For each pixel in the destination rect, alpha blend to it the 
    // corresponding pixel in the source rect.
    // ref: https://en.wikipedia.org/wiki/Alpha_compositing

    u32 stopX = destRect->x + destRect->w;
    u32 stopY = destRect->y + destRect->h;

    for (u32 dstY = destRect->y, srcY = srcRect->y; 
         dstY < stopY; 
         dstY++, srcY++) {
        for (u32 dstX = destRect->x, srcX = srcRect->x; 
             dstX < stopX; 
             dstX++, srcX++) {

            u32 srcColor = srcPixels[(srcY * srcPixelsPerRow) + srcX];
            u32 *destPixel = &destPixels[(dstY * destPixelsPerRow) + dstX];
            u32 destColor = *destPixel;

            // Colorize our source pixel before we blend it
            srcColor = PT_ColorizePixel(srcColor, *newColor);

            if (ALPHA(srcColor) == 0) {
                // Source is transparent - so do nothing
                continue;
            } else if (ALPHA(srcColor) == 255) {
                // Just copy the color, no blending necessary
                *destPixel = srcColor;
            } else {
                // Do alpha blending
                float srcA = ALPHA(srcColor) / 255.0;
                float invSrcA = (1.0 - srcA);
                float destA = ALPHA(destColor) / 255.0;

                float outAlpha = srcA + (destA * invSrcA);
                u8 fRed = ((RED(srcColor) * srcA) + (RED(destColor) * destA * invSrcA)) / outAlpha;
                u8 fGreen = ((GREEN(srcColor) * srcA) + (GREEN(destColor) * destA * invSrcA)) / outAlpha;
                u8 fBlue = ((BLUE(srcColor) * srcA) + (BLUE(destColor) * destA * invSrcA)) / outAlpha;
                u8 fAlpha = outAlpha * 255;

                *destPixel = COLOR_FROM_RGBA(fRed, fGreen, fBlue, fAlpha);
            }
        }
    }
}
示例#19
0
/*! Rebalance the tree after insertion of a node. */
void GsTreeBase::_rebalance ( GsTreeNode *x )
 {
   GS_TRACE1("Rebalance");

   GsTreeNode *y;

   while ( x!=_root && RED(x->parent) )
    { // if ( !x->parent->parent ) REPORT_ERROR
      if ( x->parent==x->parent->parent->left )
       { y = x->parent->parent->right;
         if ( RED(y) )
          { // handle case 1 (see CLR book, pp. 269)
            x->parent->color = GsTreeNode::Black;
            y->color = GsTreeNode::Black;
            x->parent->parent->color = GsTreeNode::Red;
            x = x->parent->parent;
          }
         else
          { if ( x==x->parent->right )
             { // transform case 2 into case 3 (see CLR book, pp. 269)
               x = x->parent;
               _rotate_left ( x );
             }
            // handle case 3 (see CLR book, pp. 269)
            x->parent->color = GsTreeNode::Black;
            x->parent->parent->color = GsTreeNode::Red;
            _rotate_right ( x->parent->parent );
          }
       }
      else
       { y = x->parent->parent->left;
         if ( RED(y) )
          { // handle case 1 (see CLR book, pp. 269)
            x->parent->color = GsTreeNode::Black;
            y->color = GsTreeNode::Black;
            x->parent->parent->color = GsTreeNode::Red;
            x = x->parent->parent;
          }
         else
          { if ( x==x->parent->left )
             { // transform case 2 into case 3 (see CLR book, pp. 269)
               x = x->parent;
               _rotate_right ( x );
             }
            // handle case 3 (see CLR book, pp. 269)
            x->parent->color = GsTreeNode::Black;
            x->parent->parent->color = GsTreeNode::Red;
            _rotate_left ( x->parent->parent );
          }
       }
    }
 }
示例#20
0
void
hippo_cairo_set_source_rgba32(cairo_t *cr,
                              guint32  color)
{
    /* trying to avoid alpha 255 becoming a double alpha that isn't quite opaque ?
     * not sure this is needed.
     */
    if ((color & 0xff) == 0xff) {
        cairo_set_source_rgb(cr, RED(color), GREEN(color), BLUE(color));
    } else {
        cairo_set_source_rgba(cr, RED(color), GREEN(color), BLUE(color), ALPHA(color));
    }
}
示例#21
0
Word QepcadCls::SFCFULLDf(Word D, Word P, Word J, Word n)
{
      Word t,SF,Dp,Pp,Lt,Lf,LA,Q,D1,P1,D0,P0,J0,i,Lp,pflag, L;
      char e,s,m,c;

Step1: /* Space is either empty or R^n. */
      t = DOPFSUFF_FULLD(P,LIST1(D));
      if (t == TRUE) {       
        SF = LIST1(TRUE);  /* CAD is identically TRUE. */
        goto Return; }
      else if (t == FALSE) {
        SF = LIST1(FALSE); /* CAD is identically FALSE. */
        goto Return; }

Step2: /* Extended language. */
      /* Dp,Pp are a simplified CAD for D,P (based only on full-dimensional cells!) */
      CCADCONmod(n,P,D,&Pp,&Dp); 
      Dp = PCAD2ESPCAD(P,Pp,Dp,NIL);

      /* Get list of all the true and false cells. */
      LTFOCALWTV(Dp,n,&Lt,&Lf);

      /* Filter out all but the full-dimensional true/false cells. */
      for(L = NIL; Lt != NIL; Lt = RED(Lt))
	if (LELTI(LELTI(FIRST(Lt),SC_REP),LEVEL) == CELLDIM(LELTI(FIRST(Lt),SC_REP)))
	  L = COMP(FIRST(Lt),L);
      Lt = L;
      for(L = NIL; Lf != NIL; Lf = RED(Lf))
	if (LELTI(LELTI(FIRST(Lf),SC_REP),LEVEL) == CELLDIM(LELTI(FIRST(Lf),SC_REP)))
	  L = COMP(FIRST(Lf),L);
      Lf = L;
	

      if (Lt == NIL && Lf == NIL) {
	SWRITE("No cells have truth values!\n");
	goto Return; }
      t = ESPCADDOPFSUFF(Pp,LIST1(Dp));
      LA = LISTOETAmod(Pp,n,t==NIL);

      /* Construct formula */
      SF = NECCONDS(Lt,Lf,LA,Pp); 
      SF = FMASORT(SF);
      SF = FMA_REMCONST(SF);
      SF = FMASMOOTH(SF);
      SF = FMAOPCOMBINE(SF);

 Return: /* Prepare to return. */
      return SF;
}
示例#22
0
Word CF(Word L,Word F,Word P)
{
  Word Fp,A,Ap,f;

  switch(FIRST(F)) {
  case (TRUE)  : Fp = F; break;
  case (FALSE) : Fp = F; break;
  case (ANDOP) : 
    A = RED(F);
    for(Ap = NIL; A != NIL; A = RED(A)) {
      f = CF(L,FIRST(A),P);
      if (FIRST(f) == FALSE) {
	Fp = f;
	goto Return; }
      if (FIRST(f) != TRUE)
	Ap = COMP(f,Ap); }
    if (Ap == NIL)
      Fp = LIST1(TRUE);
    else if (LENGTH(Ap) == 1)
      Fp = FIRST(Ap);
    else
      Fp = COMP(ANDOP,Ap);
    break;
  case (OROP) :
    A = RED(F);
    for(Ap = NIL; A != NIL; A = RED(A)) {
      f = CF(L,FIRST(A),P);
      if (FIRST(f) == TRUE) {
	Fp = f;
	goto Return; }
      if (FIRST(f) != FALSE)
	Ap = COMP(f,Ap); }
    if (Ap == NIL)
      Fp = LIST1(FALSE);
    else if (LENGTH(Ap) == 1)
      Fp = FIRST(Ap);
    else
      Fp = COMP(OROP,Ap);
    break;
  default:
    f = UNIFORMTV(L,F,P);
    if (f == UNDET)
      Fp = F;
    else
      Fp = LIST1(f);
    break; }
Return:
  return Fp;
}
示例#23
0
uint32_t getBilinearInterpolatedPixel(const void *pixels, int width, int height, int stride, float x, float y) {
	int x1 = (int) x;
	int x2 = x1+1;
	int y1 = (int) y;
	int y2 = y1+1;
	
	uint32_t pixel1 = getPixelRGBA(pixels, stride, x1%width, y1%height);
	uint32_t pixel2 = getPixelRGBA(pixels, stride, x2%width, y1%height);
	uint32_t pixel3 = getPixelRGBA(pixels, stride ,x1%width, y2%height);
	uint32_t pixel4 = getPixelRGBA(pixels, stride, x2%width, y2%height);
	
	int red1 = RED(pixel1);
	int green1 = GREEN(pixel1);
	int blue1 = BLUE(pixel1);
	
	int red2 = RED(pixel2);
	int green2 = GREEN(pixel2);
	int blue2 = BLUE(pixel2);
	
	int red3 = RED(pixel3);
	int green3 = GREEN(pixel3);
	int blue3 = BLUE(pixel3);
	
	int red4 = RED(pixel4);
	int green4 = GREEN(pixel4);
	int blue4 = BLUE(pixel4);
	
	float w1 = x2-x;
	float w2 = x-x1; 
	
	float red1_2 = w1*red1 + w2*red2;
	float red2_3 = w1*red3 + w2*red4;
	
	float green1_2 = w1*green1 + w2*green2;
	float green2_3 = w1*green3 + w2*green4;
	
	float blue1_2 = w1*blue1 + w2*blue2;
	float blue2_3 = w1*blue3 + w2*blue4;
	
	w1 = y2-y;
	w2 = y-y1;
	
	int red = (int) (w1*red1_2 + w2*red2_3 + 0.5);
	int green = (int) (w1*green1_2 + w2*green2_3 + 0.5);
	int blue = (int) (w1*blue1_2 + w2*blue2_3 + 0.5);

	return createRGBAPixel(red, green, blue, 0);
}
示例#24
0
Word STACKMULT(Word c)
{
	Word d,i,m,p,M,S;

Step1: /* Get the stack over c. */
	S = LELTI(c,CHILD);

Step2: /* Construct the stack multiplicity list. */
	M = NIL;
	if (S == NIL)
	   goto Return;
	S = RED(S);
	if (S == NIL)
	   goto Return;
	i = 2;
	while (S != NIL) {
	   d = FIRST(S);
	   m = LELTI(d,MULSUB);
	   p = LIST2(i,m);
	   M = COMP(p,M);
	   i = i + 2;
	   S = RED2(S); }
	M = INV(M);

Return: /* Return M. */
	return (M);
}
void worker(void)
{
	EMQ::Client client(ADDR, EMQ_DEFAULT_PORT);
	const std::string &test_message = "Hello EagleMQ";
	EMQ::Message message((void*)test_message.c_str(), test_message.length() + 1, true);
	bool status;
	int i;

	if (client.connected())
	{
		std::cout << YELLOW("[Success]") << " [Worker] Connected to "
			<< ADDR << ":" << EMQ_DEFAULT_PORT << std::endl;

		status = client.auth("eagle", "eagle");
		CHECK_STATUS("[Worker] Auth", status);

		for (i = 0; i < MESSAGES / 2; i++)
		{
			status = client.channel.publish(".channel-test", "world.russia.moscow", message);
			CHECK_STATUS("[Worker] Channel publish", status);
			status = client.channel.publish(".channel-test", "world.belarus.minsk", message);
			CHECK_STATUS("[Worker] Channel publish", status);
			sleep(1);
		}

		client.disconnect();
	}
	else
	{
		std::cout << RED("[Error]") << " Error connect to " << ADDR << ":" << EMQ_DEFAULT_PORT << std::endl;
	}
}
	bool RGBLinearQuantizationFilter::Apply(til::Image &image) const
	{
		if (image.GetBitDepth() != til::Image::BPP_32B_R8G8B8) return false;

		til::uint32 *image_pixels = reinterpret_cast<til::uint32*>(image.GetPixels());

		std::vector<til::byte> palette[3] = { 
			std::vector<til::byte>(max(((til::byte)(_palette_quants)),       1), 0x00),
			std::vector<til::byte>(max(((til::byte)(_palette_quants >>  8)), 1), 0x00),
			std::vector<til::byte>(max(((til::byte)(_palette_quants >> 16)), 1), 0x00)
		};

		til::byte index[] = { 
			static_cast<til::byte>(0x100 / palette[0].size()) + (palette[0].size() % 2 * static_cast<til::byte>(palette[0].size() > 1)), 
			static_cast<til::byte>(0x100 / palette[1].size()) + (palette[1].size() % 2 * static_cast<til::byte>(palette[1].size() > 1)), 
			static_cast<til::byte>(0x100 / palette[2].size()) + (palette[2].size() % 2 * static_cast<til::byte>(palette[2].size() > 1)) 
		};

		for(std::vector<til::byte>::size_type i = 0, max = palette[0].size(); i < max; ++i) palette[0][i] = static_cast<til::byte>(i * index[0]);
		for(std::vector<til::byte>::size_type i = 0, max = palette[1].size(); i < max; ++i) palette[1][i] = static_cast<til::byte>(i * index[1]);
		for(std::vector<til::byte>::size_type i = 0, max = palette[2].size(); i < max; ++i) palette[2][i] = static_cast<til::byte>(i * index[2]);

		for (til::uint64 i = 0, max = image.GetWidth() * image.GetHeight(); i < max; ++i)
		{
			image_pixels[i] = RGB(
					palette[0][index[0] == 0x00 ? 0 : RED(image_pixels[i])   / index[0]],
					palette[1][index[1] == 0x00 ? 0 : GREEN(image_pixels[i]) / index[1]],
					palette[2][index[2] == 0x00 ? 0 : BLUE(image_pixels[i])  / index[2]]
				);
		}

		return true;
	}
示例#27
0
	void llvm_print(const char *userfile, int lineno, T &obj, const char* tag,
			ADDON addon = ADDON())
	{

		std::string unformatted = llvm_to_str(obj);
		std::string formatted = dlog_format_string_to_html(unformatted);

		if (outputmode == DLOG_OUTPUT_BOTH || outputmode == DLOG_OUTPUT_FILE)

		{
			tag_handler(tag);
			fdata << DIV(
					tag) << BOLD("<br>Tag : ") << RED(tag) << NBSP << br << CALLINFO
			<< BROWN(addon.getString()) << NBSP << NBSP
			<< BOLD(" Data : <br>") << formatted << EDIV;
		}
		if (outputmode == DLOG_OUTPUT_BOTH || outputmode == DLOG_OUTPUT_STDOUT)
		{
			std::cout << "Tag : " << tag << "\t";
			if (addon.getString().length() != 0)
			std::cout << "\t Addon: " << addon.getString() << "\n";
			std::cout << unformatted << "\n";
		}

		fdata.flush();
	}
示例#28
0
char *region_of_interest (NEURON_LAYER *nl_input, int x_center, int y_center, int width, int height)
{
	int xi, yi, wi, hi, xo, yo, wo, ho;
	NEURON_OUTPUT value;
	
	char * output = malloc(width * height * 3 * sizeof(char));
	
	wi = nl_input->dimentions.x;
	hi = nl_input->dimentions.y;
	
	wo = width;
	ho = height;
	
	for (yo = 0; yo < ho; yo++)
	{
		for (xo = 0; xo < wo; xo++)
		{			
			xi = (int) ((double) xo + .5) + x_center - wo/2;
			yi = (int) ((double) yo + .5) + y_center - ho/2;
			
			if (xi >= 0 && xi < wi && yi >= 0 && yi < hi)
				value = nl_input->neuron_vector[xi + wi * yi].output;
			else
				value.ival = 0;
			
			output[3 * (yo * wo + xo) + 0] = RED(value.ival);
			output[3 * (yo * wo + xo) + 1] = GREEN(value.ival);
			output[3 * (yo * wo + xo) + 2] = BLUE(value.ival);
		}
	}
	
	return output;
}
示例#29
0
int Mmi::Choose()
{
   const char TAB[]        = "   ";

   char BUF[1024] = {0x00,};

   GetInput("Choose", BUF, sizeof(BUF));

   int len = strlen(BUF);
   if (0 == len) {
      return 0;
   }

   for (int idx = 0; idx < len; ++idx) {
      if (!isdigit(BUF[idx] & 0xFF)) {
         STDOUT(" ");
         STDOUT(RED(TAB << "Invalid Input : " << BUF));
         STDOUT(" ");
         return 0;
      }
   }

   int value = atoi(BUF);

   return ((0 == value) ? -1 : value);
}
示例#30
0
Word MINHITSETSRDR(Word A, Word B)
{
      Word n,*N,i,L,Ap;

Step1: /* Quick decisions. */
      if (A == NIL) return (NIL);
      if ((B == 0) || (FIRST(A) == NIL)) return (MC_FAIL);

Step2: /* Sort Rows. */
      n = LENGTH(A);
      N = GETARRAY(n);
      i = 0;
      for(L = A; L != NIL; L = RED(L))
	N[i++] = FIRST(L);
      n = GMSDS(N,n,comp);
      
Step3: /* Reconstruct list. */
      Ap = NIL;
      for(i = n - 1; i >= 0; i--)
	Ap = COMP(N[i],Ap);

Return: /* Return. */
      FREEARRAY(N);
      return (MINHITSET(Ap,B));
}