Esempio n. 1
0
void worm::render_flip(BITMAP* where, int frame, int _x, int _y)
{
  int r,g,c,R,G,B,i;
  float h1,s1,v1,h,s,v;
  for (i=0;i<skin->img[frame]->w;i++)
  {
    for (r=0;r<skin->img[frame]->h;r++)
    {
      g=getpixel(skin->img[frame],i,r);
      c=getpixel(mask->img[frame],i,r);
      if(g!=makecol(255,0,255))
      {
        if(c!=makecol(255,0,255))
        {
          c=color;
          rgb_to_hsv(getr(c), getg(c), getb(c), &h1, &s1, &v1);
          
          R = getr(g);
          G = getg(g);
          B = getb(g);
          
          rgb_to_hsv(R, G, B, &h, &s, &v);
          h = h1;
          s = s1;
          v -= (1-v1)/1.4;
          if (v<0)v=0;
          
          hsv_to_rgb(h,s,v, &R, &G, &B);
          g = makecol(R,G,B);
          putpixel(where,_x+skin->img[frame]->w-1-i,_y+r,g);
        }else putpixel(where,_x+skin->img[frame]->w-1-i,_y+r,g);
      };
    };
  };
};
Esempio n. 2
0
void draw_button(BITMAP *bmp, int x, int y, int w, int h, int col, const char *txt, bool selected, bool disabled)
{
	int col1 = makecol( minf(255,getr(col)*1.3f), minf(255,getg(col)*1.3f), minf(255,getb(col)*1.3f) );
	int col2 = makecol( getr(col)*0.7f, getg(col)*0.7f, getb(col)*0.7f );
	int col3 = makecol( minf(255,getr(col)*1.7f), minf(255,getg(col)*1.7f), minf(255,getb(col)*1.7f) );

	if(disabled)
	{
		col1 = makecol(130,130,130);
		col2 = makecol(50,50,50);
		col3 = makecol(170,170,170);
		col = makecol(100,100,100);
	}
	else if(selected)
	{
		rect(bmp, x-2,y-2, x+w+3,y+h+3, makecol(210,210,0));
		rect(bmp, x-1,y-1, x+w+2,y+h+2, makecol(255,255,0));
		col3 = makecol(255,255,255);
	}
	
	rectfill(bmp, x,y, x+w,y+h, col);
	line(bmp, x,y, x+w,y, col1);
	line(bmp, x+w,y, x+w,y+h, col1);
	line(bmp, x,y+1, x+w,y+1, col1);
	line(bmp, x+w+1,y, x+w+1,y+h, col1);	
	
	line(bmp, x,y+h, x+w,y+h, col2);
	line(bmp, x,y, x,y+h, col2);	
	line(bmp, x,y+h+1, x+w,y+h+1, col2);
	line(bmp, x+1,y, x+1,y+h, col2);

	textout_ex(bmp, font2, txt, x + (w/2) - (text_length(font2,txt)/2), y + (h/2) - (text_height(font2)/2), col3, -1);
}
Esempio n. 3
0
static uint8_t *msglen(uint8_t *p, uint16_t *l)
{
  *l = 0;
  while(!getb(p)) {
    *l += 255;
    p++;
  }
  *l += getb(p++);
  return p;
}
Esempio n. 4
0
/*
 * Interpolate between two colors
 * Pass 0.0-1.0 for 100% color1 -> 100% color2
 */ 
int aWgtInterpolateColor(float ratio, int color1, int color2)
{
	int r1 = getr(color1);
	int g1 = getg(color1);
	int b1 = getb(color1);
	int r = +(int)(r1 + ((getr(color2) - r1) * ratio));
	int g = +(int)(g1 + ((getg(color2) - g1) * ratio));
	int b = +(int)(b1 + ((getb(color2) - b1) * ratio));

	return makecol(r, g, b);
}
Esempio n. 5
0
int blend_color(int from, int to, double t)
{
  int r = getr(from) + static_cast<int>((getr(to) - getr(from)) * t);
  int g = getg(from) + static_cast<int>((getg(to) - getg(from)) * t);
  int b = getb(from) + static_cast<int>((getb(to) - getb(from)) * t);
  int a = geta(from) + static_cast<int>((geta(to) - geta(from)) * t);
  return makeacol(MID(0, r, 255),
		  MID(0, g, 255),
		  MID(0, b, 255),
		  MID(0, a, 255));
}
/*----------------------------------------------------------------------------*/
void get_time(void)
{  time_t t;                           /* Current system time                 */
   int c;                              /* Input character                     */
   do                                  /* Until end of message                */
   {  Serial.println("?T");            /* Send time query to host via USB     */
      t = 0;                           /* Initialize time value               */
      while ('T' != getb()) ;          /* Watch for start of time response    */
      while (('0' <= (c = getb())) && (c <= '9')) /* Is this a decimal digit? */
      {  t = 10 * t + (c & 0x0F);      /* If so, build time value             */
      }                                /*  end: building time value           */
   }  while (c != '!');                /* Until a valid time is received      */
   set_time(ss(t));                    /* Calculate and save reset time       */
}                                      /*  end: set_time()                    */
Esempio n. 7
0
/* FIXME: for version 2 games they swapped the 1 markers for length bytes
   with an odd hack where a 0 length means 255 + nextbyte (unless 0 if so
   repeat */
static void decompress(uint8_t *p, uint16_t m)
{
  uint8_t d;
  /* Walk the table looking for 1 bytes and counting off our
     input */
  while(m--)
    while(getb(p++) != 1);
  while((d = getb(p++)) > 2) {
    if (d < 0x5E)
      print_char(d + 0x1d);
    else
      decompress(worddict, d - 0x5E);
  }
}
Esempio n. 8
0
static void lookup_exit(void)
{
  uint8_t l = variables[getb(pc++)];
  uint8_t d = variables[getb(pc++)];
  uint8_t *p = exitmap;
  uint8_t v;
  uint8_t ls = l;

  /* Scan through the table finding 0x80 end markers */
  l--;		/* No entry 0 */
  while (l--) {
    do {
      v = getb(p);
      p += 2;
    } while (!(v & 0x80));
  }
  /* Now find our exit */
  /* Basically each entry is a word in the form
     [Last.1][BiDir.1][Flags.2][Exit.4][Target.8] */
  do {
    v = getb(p);
    if ((v & 0x0F) == d) {
      variables[getb(pc++)] = ((getb(p++)) >> 4) & 7;	/* Flag bits */
      variables[getb(pc++)] = getb(p++);
      return;
    }
    p+=2;
  } while(!(v & 0x80));
Esempio n. 9
0
static int usb_get_status(const struct usb_ctrlrequest *ctrl)
{
	__le16 status = cpu_to_le16(fw.usb.device_feature);

	if ((ctrl->bRequestType & USB_DIR_MASK) != USB_DIR_IN)
		return -1;

	switch (ctrl->bRequestType & USB_RECIP_MASK) {
	case USB_RECIP_DEVICE:
		status &= cpu_to_le16(~USB_DEVICE_SELF_POWERED);
		status &= cpu_to_le16(~USB_DEVICE_REMOTE_WAKEUP);
		break;

	case USB_RECIP_INTERFACE:
		/* USB spec: This is reserved for future use. */
		status = cpu_to_le16(0);
		break;

	case USB_RECIP_ENDPOINT: {
		unsigned int ep = le16_to_cpu(ctrl->wIndex) & 0xf;
		unsigned int dir = le16_to_cpu(ctrl->wIndex) & USB_DIR_MASK;

		if (ep == 0) {
			status = !!(getb(AR9170_USB_REG_CX_CONFIG_STATUS) & BIT(2));
		} else {
			unsigned int addr;

			if (dir == USB_DIR_IN)
				addr = AR9170_USB_REG_EP_IN_MAX_SIZE_HIGH;
			else
				addr = AR9170_USB_REG_EP_OUT_MAX_SIZE_HIGH;

			addr += (ep << 1);

			/*
			 * AR9170_USB_EP_OUT_STALL == AR9170_USB_EP_IN_STALL
			 * so it doesn't matter which one we use
			 */
			status = !!(getb(addr) & AR9170_USB_EP_OUT_STALL);
		}
		break;
		}
	case USB_RECIP_OTHER:
	default:
		break;
	}

	return usb_ep0tx_data((const void *) &status, sizeof(status));
}
void CrayonLine(BITMAP* bmp, Vector start, Vector end, int colour, float wobble, float amplitude, int inner_radius, int outer_radius, float hardness)
{
    Vector line_tangent = end - start;
    if (rand()%2 == 0) // If the normal is a randomised then it should result in the lines starting off on different direction wobbles
        crayon_line_normal = Vector(-line_tangent.Y(), line_tangent.X());
    else
        crayon_line_normal = Vector(line_tangent.Y(), -line_tangent.X());

    crayon_line_normal *= (1/crayon_line_normal.Mag());
    prev_crayon_x = start.XInt();
    prev_crayon_y = start.YInt();
    crayon_line_wobble = wobble;
    crayon_line_wobble_amplitude = amplitude;
    crayon_line_inner_radius = inner_radius;
    crayon_line_outer_radius = outer_radius;

    int fg_r = getr(colour), fg_g = getg(colour), fg_b = getb(colour);
    int bg_r = (256 - fg_r)*hardness + fg_r, bg_g = (256 - fg_g)*hardness + fg_g, bg_b = (256 - fg_b)*hardness + fg_b;

    crayon_fade_colour = makecol(bg_r, bg_g, bg_b);

    points_down_line = 0;
    do_line(bmp, start.XInt(), start.YInt(), end.XInt(), end.YInt(), colour, CrayonBackLine);
    points_down_line = 0;
    prev_crayon_x = start.XInt();
    prev_crayon_y = start.YInt();
    do_line(bmp, start.XInt(), start.YInt(), end.XInt(), end.YInt(), colour, CrayonFrontLine);
}
Esempio n. 11
0
void RotatingLaser::calculate()
{
	STACKTRACE;
	if ( !(mother && mother->exists()) ) {
		state = 0;
		mother = 0;

		return;
	}

	relangle += laser_turn_rate * frame_time;
	relative_angle = relangle;
	rel_pos = rotate(relpos, relangle);

	angle = normalize(mother->angle + mother->turn_step + relangle, PI2);
	//	pos = mother->pos + rotate(relpos, angle+relangle-PI/2);
	//	vel = mother->vel;

	double a = 1.0 - double(frame) / frame_count;
	length = default_length * a;

	int r, g, b;
	r = getr(default_color);
	g = getg(default_color);
	b = getb(default_color);
	r *= iround(a);
	b *= iround(a);
	color = makecol(r,g,b);

	Laser::calculate();
}
Esempio n. 12
0
File: bullcow.c Progetto: mazonka/w
vect process(const vect * n, int g, int b, int c)
{
	int i,k;
	vect r;
	vect rm;

	const char * s2 = mks[g].x;

	r.sz = rm.sz = 0;

	for( i=0; i<n->sz; i++ )
	{
		int mb, mc;
		getb(n->x[i],s2,&mb);
		if( mb!=b ){ rm.x[rm.sz++]=i; continue; }
		
		getbc(n->x[i],g,&mb,&mc);
		if( mb!=b || mc!=c ) rm.x[rm.sz++]=i;
	}

	{
		for( k=0,i=0; i<n->sz; i++ )
		{
			if( k<rm.sz && rm.x[k]==i ) k++;
			else r.x[r.sz++] = n->x[i];
		}
	}

	return r;
}
Esempio n. 13
0
/*
 * Make a color darker
 */
int aWgtDarken(int color)
{
	int r = MAX(0, getr(color) - frameDarkenAmount);
	int g = MAX(0, getg(color) - frameDarkenAmount);
	int b = MAX(0, getb(color) - frameDarkenAmount);
	return makecol(r, g, b);
}
Esempio n. 14
0
/* photon_clear_to_color:
 *  Accelerated screen clear routine.
 */
static void photon_clear_to_color(BITMAP *bmp, int color)
{
   struct Ph_rect dest_rect = {
      { bmp->cl + bmp->x_ofs,
        bmp->ct + bmp->y_ofs },
      { bmp->x_ofs + bmp->cr,
        bmp->y_ofs + bmp->cb }
   };

   struct BITMAP *parent;

   /* find parent */
   parent = bmp;
   while (parent->id & BMP_ID_SUB)
      parent = (BITMAP *)parent->extra;

   /* set fill color */
   /* if (bmp->vtable->color_depth == 8)
      PgSetFillColor(color);
   else */
      PgSetFillColor(PgRGB(getr(color), getg(color), getb(color)));
      
   PhDCSetCurrent(BMP_EXTRA(parent)->context);
   PgDrawRect(&dest_rect, Pg_DRAW_FILL);

   if (parent == pseudo_screen)
      ph_update_window(&dest_rect);
   else
      PgFlush();
}
Esempio n. 15
0
void main()
{
	int color[4], myset[4], pix, d;
	BITMAP * caixa;
	allegro_init();
	install_keyboard();
	set_color_depth(32);
 
	set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0);
 

	myset[0] = 130;
	myset[1] = 195;
	myset[2] = 195;
	caixa = load_bitmap( "Default.bmp", NULL);
	for (int y = 0; y < caixa->h; y++)
         for (int x = 0; x < caixa->w; x++)
		{
			d = 0;
			pix = getpixel(caixa, x, y);
			color[0] = getr(pix);
			color[1] = getg(pix);
			color[2] = getb(pix);
			for (int i = 0; i<3; i++)
				d+=(color[i]-myset[i])*(color[i]-myset[i]);
			if (d<100)
			  putpixel(caixa, x, y, 0);
		}

	draw_sprite(screen, caixa, 0, 0);

	while(!key[KEY_ESC])    
        rest(50);
}
Esempio n. 16
0
  /* ************************************************************************* */
  VectorValues GaussianConditional::solve(const VectorValues& x) const
  {
    // Concatenate all vector values that correspond to parent variables
    Vector xS = x.vector(FastVector<Key>(beginParents(), endParents()));

    // Update right-hand-side
    xS = getb() - get_S() * xS;

    // Solve matrix
    Vector soln = get_R().triangularView<Eigen::Upper>().solve(xS);

    // Check for indeterminant solution
    if(soln.hasNaN()) throw IndeterminantLinearSystemException(keys().front());

    // TODO, do we not have to scale by sigmas here? Copy/paste bug

    // Insert solution into a VectorValues
    VectorValues result;
    DenseIndex vectorPosition = 0;
    for(const_iterator frontal = beginFrontals(); frontal != endFrontals(); ++frontal) {
      result.insert(*frontal, soln.segment(vectorPosition, getDim(frontal)));
      vectorPosition += getDim(frontal);
    }

    return result;
  }
Esempio n. 17
0
/*
 * Make a color brighter
 */
int aWgtHighlight(int color)
{
	int r = MIN(255, getr(color) + frameHighlightAmount);
	int g = MIN(255, getg(color) + frameHighlightAmount);
	int b = MIN(255, getb(color) + frameHighlightAmount);
	return makecol(r, g, b);
}
Esempio n. 18
0
void PremultipleChannels()
{
    for (int i = 0; i < skin.iWidth * skin.iHeight; i++)
        skin.colBits[i] = rgba(	getr(skin.colBits[i])*geta(skin.colBits[i])/255,
                                getg(skin.colBits[i])*geta(skin.colBits[i])/255,
                                getb(skin.colBits[i])*geta(skin.colBits[i])/255,
                                geta(skin.colBits[i]));
}
Esempio n. 19
0
int to_system(Color color)
{
  if (is_transparent(color))
    return -1;
  else
    return makecol(getr(color),
                   getg(color),
                   getb(color));
}
Esempio n. 20
0
BITMAP* Resource::getBitmap(const std::string &filename, unsigned int color)
{
	std::string key = filename + toString(color);

	if (mBitmaps.find(key) == mBitmaps.end())
    {
	    BITMAP* bitmap = load_bitmap(getRealFilename(filename).c_str(), NULL);
		
		if (bitmap == NULL) 
		{
			throw std::string("Unable to load: ") + getRealFilename(filename);
		}

		unsigned int colorR = getr(color);
		unsigned int colorG = getg(color);
		unsigned int colorB = getb(color);
		unsigned int magicPink = makecol(255, 0, 255);

		for(int y = 0; y < bitmap->h; ++y) {
			for(int x = 0; x < bitmap->w; ++x) {
				unsigned int c = getpixel(bitmap, x, y);
				if(c != magicPink) {
					unsigned int r = getr(c);
					unsigned int g = getg(c);
					unsigned int b = getb(c);

					r = (colorR * r) / 255;
					g = (colorG * g) / 255;
					b = (colorB * b) / 255;
					c = makecol(r, g, b);

					putpixel(bitmap, x, y, c);
				}
			}
		}



        mBitmaps[key] = bitmap;
    }

    return mBitmaps[key];
}
Esempio n. 21
0
void naomi_m1_board::enc_reset()
{
	gb_reset();
	stream_ended = false;
	has_history = false;
	buffer_actual_size = 0;

	for(int i=0; i<111; i++)
		dict[i] = getb(8);
}
Esempio n. 22
0
void foreground_set_color_from_rgb  ( guint color )
{
   foreground_color.red   = getr(color);
   foreground_color.red   <<= 8;
   foreground_color.green = getg(color);
   foreground_color.green <<= 8;
   foreground_color.blue  = getb(color);
   foreground_color.blue  <<= 8;
   foreground_show ();
   /*g_debug("%s %d", __FILE__, __LINE__);*/
}
Esempio n. 23
0
void fnt_ttf_draw_bitmap_blend( FT_Bitmap* fbitmap, BITMAP *b, FT_Int x, FT_Int y, int color) {
   
   // Simple render
   
   FT_Int  i, j, p, q;
   FT_Int  x_max = x + fbitmap->width;
   FT_Int  y_max = y + fbitmap->rows;
   int pix;
   int bmc, bmr, bmg, bmb;
//   int bgr, bgg, bgb, fac;
   int pnr, png, pnb, opr, opg, opb, opc;
   
   pnr=getr(color);
   png=getg(color);
   pnb=getb(color);
   
   for ( i = x, p = 0; i < x_max; i++, p++ ) {
      for ( j = y, q = 0; j < y_max; j++, q++ ) {
//	 if ( i >= WIDTH || j >= HEIGHT )
//	   continue;

	 bmc=getpixel(b,i,j);
	 bmr=getr(bmc);	 bmg=getg(bmc);	 bmb=getb(bmc);
	 
	 pix = fbitmap->buffer[q * fbitmap->width + p];

	 if(pix>0) {
	    opr=fnt_blendfunc(bmr,pnr,pix);
	    opg=fnt_blendfunc(bmg,png,pix);
	    opb=fnt_blendfunc(bmb,pnb,pix);
	    
	    opc=makecol(opr,opg,opb);
	    putpixel(b,i,j,opc);
	 }
      }	
   }   
//#ifdef USESDL
////   if(b==screen)
//     SDL_UpdateRect(b,x,y,x_max-x,y_max-y);
//#endif
}
Esempio n. 24
0
void Tanque::MovaCima(BITMAP *db)
	{
   // iden ...
   int r =  getr(getpixel(db, col-velocidade, lin));
   int g =  getg(getpixel(db, col-velocidade, lin));
   int b =  getb(getpixel(db, col-velocidade, lin));

   lin-=velocidade;
   //evia que o tanque saia  da tela por cima
   if ( lin <= 50 )
      lin = 50;
}
Esempio n. 25
0
void Tanque::MovaDireita(BITMAP *db)
{   

//aqui a mesma coisa ... so qe nao funciona nao  pq nao tem o maldito if ;;
   int r =  getr(getpixel(db, col+velocidade, lin));
   int g =  getg(getpixel(db, col+velocidade, lin));
   int b =  getb(getpixel(db, col+velocidade, lin));
    // Verifica colisão com lateral
   col+=velocidade;
   if ( col >= (SCREEN_W - img->w + 4) )
      col = SCREEN_W - img->w + 4; 
}
Esempio n. 26
0
void ColorizeBitmap()
{
    if (!skin.colBits)
        return;

    GdiFlush();

    int w = skin.iWidth;
    int h = skin.iHeight;

    // we should swap B and R channels when working with win32 COLORREF
    float koef1r = (255 - getb(opt.colBg)) / 128.0;
    float koef1g = (255 - getg(opt.colBg)) / 128.0;
    float koef1b = (255 - getr(opt.colBg)) / 128.0;

    int br = - 255 + 2 * getb(opt.colBg);
    int bg = - 255 + 2 * getg(opt.colBg);
    int bb = - 255 + 2 * getr(opt.colBg);

    float koef2r = (getb(opt.colBg)) / 128.0;
    float koef2g = (getg(opt.colBg)) / 128.0;
    float koef2b = (getr(opt.colBg)) / 128.0;

    for (int i = 0; i < w * h; i++) {
        long alpha = geta(skin.colBits[i]);
        COLOR32 cl = alpha ? getr(skin.colBits[i])*255/alpha : 0;

        skin.colBits[i] = (cl > 128) ?
                          rgba(
                              PU_DIV255((koef1r * cl + br)*alpha),
                              PU_DIV255((koef1g * cl + bg)*alpha),
                              PU_DIV255((koef1b * cl + bb)*alpha),
                              alpha):
                          rgba(
                              PU_DIV255(koef2r * cl * alpha),
                              PU_DIV255(koef2g * cl * alpha),
                              PU_DIV255(koef2b * cl * alpha),
                              alpha);
    }
}
Esempio n. 27
0
int main()
{
	std::cout << "j:" << j << std::endl;
	std::cout << "k:" << k << std::endl;
	std::cout << "b:" << b << std::endl;
	std::cout << "getb()" << getb() << std::endl;

	for(int i = 0; i < 10; i++) {
		run();
	}

	return 0;
}
Esempio n. 28
0
File: misc.c Progetto: arvidfm/fiend
void make_pickup_message(char *string,BITMAP *pic,int time)
{
	int i,j;
	int color;
	int val;
	int r,g,b;

	if(pickup.buffer==NULL)
	{
		pickup.buffer = create_bitmap(480, 50);
	}
	
	clear_to_color(pickup.buffer, makecol(255,0,255));

	//text_mode(-1);
	textprintf_centre_ex(pickup.buffer, font_avalon->dat,241,1,makecol(0,0,0),-1,"%s",string);
	textprintf_centre_ex(pickup.buffer, font_avalon->dat,240,0,makecol(255,255,255),-1,"%s",string);
	
	pickup.ready = 1;
	
	pickup.alpha = PICKUP_MESSAGE_ALPHA;
	pickup.time = time;

	if(pic!=NULL)
	{
		if(pickup.pic!=NULL) destroy_bitmap(pickup.pic);
		
		pickup.pic = create_bitmap(pic->w,pic->h);
		clear_to_color(pickup.pic,makecol(255,0,255));
		
		for(i=0;i<pic->w;i++)
			for(j=0;j<pic->h;j++)
			{
				color = getpixel(pic,i,j);
				
				r = getr(color);g = getg(color);b = getb(color);
				if(color==MASK_COLOR_16)
				{
				}
				else
				{
					val = ((r+g+b)/3);
					putpixel(pickup.pic,i,j,makecol(val,val,val));
				}
			}
	}
	else
	{
		pickup.pic = NULL;
	}
}
Esempio n. 29
0
void Tanque::MovaEsquerda(BITMAP *db)
{
     //o tanqu nao sai da agua pelo lado esquerdo ..
     

   int r =  getr(getpixel(db, col-velocidade, lin)); 
   int g =  getg(getpixel(db, col-velocidade, lin));
   int b =  getb(getpixel(db, col-velocidade, lin));
   //essas 3 ultimas linhas ficam verificando a cor do lado do tanque ,,
   //se nao for o azul, nao deixa o tanque andar mais 

   if (r != 131 || g != 255 || b != 255)
     col-=velocidade;
}
Esempio n. 30
0
File: undo.c Progetto: jwillia3/wse2
static Line *getlines(Buf *b, int lo, int hi) {

	Line	*dat, *first;
	wchar_t	*txt;
	int	i;
	
	dat=first= malloc(sizeof (Line) * (hi-lo+1));
	for (i=lo; i<=hi; i++, dat++) {
		txt = getb(b, i, &dat->len);
		dat->dat = wcsdup(txt);
		dat->max = dat->len;
	}
	return first;
}