Esempio n. 1
0
void parse_color(const std::wstring& text, COLORREF *color)
{
    int r = 0; int g = 0; int b = 0;
    swscanf(text.c_str(), L"%d,%d,%d", &r, &g, &b);
    unsigned char rb = 0; unsigned char gb = 0; unsigned char bb = 0;
    if (check_color(r, &rb) && check_color(g, &gb) && check_color(b, &bb))
    {
        *color = RGB(rb, gb, bb);
    }
}
Esempio n. 2
0
int				add_color(char **format)
{
	int			len;

	if ((len = check_color("black", *format)))
		ft_putstr("\033[30m");
	else if ((len = check_color("red", *format)))
		ft_putstr("\033[31m");
	else if ((len = check_color("green", *format)))
		ft_putstr("\033[32m");
	else if ((len = check_color("yellow", *format)))
		ft_putstr("\033[33m");
	else if ((len = check_color("blue", *format)))
		ft_putstr("\033[34m");
	else if ((len = check_color("magenta", *format)))
		ft_putstr("\033[35m");
	else if ((len = check_color("cyan", *format)))
		ft_putstr("\033[36m");
	else if ((len = check_color("eoc", *format)))
		ft_putstr("\033[0m");
	else
		return (len = 0);
	(*format) += len;
	return (1);
}
Esempio n. 3
0
File: main.c Progetto: Mindc0re/FdF
int		main(int ac, char **av)
{
	t_all	all;

	if (ac >= 2)
	{
		all.mlx = mlx_init();
		all.win_x = (ac >= 4 && check_arg(av[2])) ? ft_atoi(av[2]) : 500;
		all.win_y = (ac >= 4 && check_arg(av[3])) ? ft_atoi(av[3]) : 500;
		all.win = mlx_new_window(all.mlx, all.win_x, all.win_y, "FdF");
		init_all(&all);
		if (ac == 5)
			check_color(av[4], &all);
		all.fd = open(av[1], O_RDONLY);
		if (all.fd == -1)
			exit(EXIT_FAILURE);
		parser(all.fd, &all);
		mlx_hook(all.win, 2, (1L << 0), key_hook_first, &all);
		draw_map_x(&all);
		mlx_loop(all.mlx);
	}
	else
		help_main();
	return (0);
}
Esempio n. 4
0
void		parsing_light(int fd, t_env *rt)
{
	char		*line;
	char		**tab;
	int			tmp;

	tmp = 0;
	while (get_next_line(fd, &line) > 0 && line[0] != '\0')
	{
		tab = split_tab(line);
		if (!ft_strcmp(tab[0], "pos"))
			rt->light[rt->i_light].center = new_vector(ft_atof(tab[2]),
			ft_atof(tab[3]), ft_atof(tab[4]));
		else if (!ft_strcmp(tab[0], "color"))
		{
			check_color(ft_atof(tab[2]), ft_atof(tab[3]), ft_atof(tab[4]));
			rt->light[rt->i_light].color.r = ft_atof(tab[2]);
			rt->light[rt->i_light].color.g = ft_atof(tab[3]);
			rt->light[rt->i_light].color.b = ft_atof(tab[4]);
		}
		else if (!ft_strcmp(tab[0], "parallel"))
			rt->light[rt->i_light].parallel = ft_atoi(tab[2]);
		tab_free(tab);
		ft_strdel(&line);
	}
	(tmp) ? (ft_strdel(&line)) : (0);
	rt->i_light++;
}
Esempio n. 5
0
t_color		apply_refraction(t_ray *start, t_scene *scene, t_hit drawn_pixel, double noise)
{
	double	refract_indice;
	t_color	tmp_color;
	int test;
	tmp_color = drawn_pixel.color;
	if (drawn_pixel.t_max == drawn_pixel.t)
	{
		refract_indice = drawn_pixel.ref_index;
		test = -1;
	}
	else
	{
		test = 1;
		refract_indice = 1.0 / drawn_pixel.ref_index;
	}
	*start = find_refract_vect(start, drawn_pixel, refract_indice, test);
	if (get_length(start->dir) != 0)
	{
		if (scene->is_real == CARTOON && is_black_edge(&drawn_pixel))
		{
			tmp_color = init_color(0, 0, 0);
			return (tmp_color);
		}
		else
			tmp_color = add_color(tmp_color, color_render(scene, start, noise, NULL));
	}
	check_color(&tmp_color);
	return (tmp_color);
}
Esempio n. 6
0
void parse_either( char *attrs, int dft_color, int *monop, int *colorp )
{
  int value;
  while ( attrs[0] )
  {
    char *next = strchr( attrs, '+' );
    char save = 0;
    if ( next == 0 )
    {
      next = attrs + strlen( attrs );
    }
    if ( save )
      next[0] = 0;
    value = string_to_attr( attrs );
    if ( value )
      monop[0] |= value;
    else
    if ( colorp )
    {
      value = check_color( attrs, dft_color );
      if ( value != -3 )
        colorp[0] = value;
    }
    attrs = next;
    if ( save )
    {
      attrs[0] = save;
      attrs++;
    }
  }
  return;
}
Esempio n. 7
0
t_k		*luminosite(t_spot *spot, t_k *k, t_objet *obj, t_utils *utils)
{
	double	a;
	double	tmp;
	t_utils	l;
	t_objet	obj3;

	a = 0.0;
	init_new_color(k);
	trans_inv(utils, obj, 0);
	obj_rot(utils, obj, -1, 1);
	calc_coord(k, &obj3, utils);
	utils = init_norm(obj, obj3, utils);
	while (spot != NULL)
	{
		init_distance(spot, &l, obj3);
		tmp = calc_cos(utils, l);
		get_new_color(k, (tmp < 0.0 ? tmp = 0.0 : tmp), obj, spot);
		spot = spot->next;
		a++;
	}
	obj_rot(utils, obj, 1, 1);
	trans_nor(utils, obj, 0);
	check_color(k, a, utils);
	return (k);
}
Esempio n. 8
0
t_k	*luminosite(t_spot *spot, t_k *k, t_objet *obj, t_utils *utils)
{
  t_utils	L;
  t_objet	obj3;
  double	tmp;
  double	a;

  a = 0.0;
  init_new_color(k);
  trans_inv(utils, obj, 0);
  obj_rot(utils, obj, -1, 1);
  calc_coord(k, &obj3, utils);
  utils = my_init_norm(obj, obj3, utils);
  while (spot != NULL)
    {
      init_distance(spot, &L, obj3);
      tmp = calc_cos(utils, L);
      if (obj->texture == 1 || obj->texture == 2)
	k = texture(obj3, k, obj->texture);
      get_new_color(k, (tmp < 0.0 ? tmp = 0.0 : tmp), obj, spot);
      spot = spot->next;
      a++;
    }
  obj_rot(utils, obj, 1, 1);
  trans_nor(utils, obj, 0);
  check_color(k, a, utils);
  return (k);
}
Esempio n. 9
0
void Hero::move(){
    if(enable_to_move){
        check_color();
        gravity_jump();
        if(direction_x == LEFT){
            if(stucked != S_LEFT){
                stucked= NO;
                if(speed >= -6) {speed = speed - 3;}
                pos_x += speed;
                if(!tile_flipped){
                    tile_transformation = T_LEFT;
                    tile_flipped = true;
                }else{
                    tile_transformation=T_NO;
                }
            }
        }
        if(direction_x == RIGHT){
            if(stucked!= S_RIGHT){
                stucked = NO;
                if(speed <= 6) {speed = speed + 3;}
                pos_x += speed;
                if(tile_flipped){
                    tile_transformation = T_RIGHT;
                    tile_flipped = false;
                }else{
                    tile_transformation=T_NO;
                }
            }
        }
    }
}
Esempio n. 10
0
void EdgeDetector::stackfill(int x,int y)
{
    points.push(Point(x,y));
    while(points.empty()==false)
    {
        Point p=points.top();
        points.pop();
        setPixel(p);


        for(int i=-1;i<=1;i++)
        {
            for(int j=-1;j<=1;j++)
            {
                if(i==0 && j==0)
                    continue;

                Point p1=Point(p.x+i,p.y+j);
                if(check_color(p1)==true)
                {
                    points.push(p1);
                }

            }
        }
    }

}
Esempio n. 11
0
void cekGaris() {
	int a;
	motor[leftMotor] = 0;
	motor[rightMotor] = 0;
	while(1) {
		a=check_color();
	}
}
Esempio n. 12
0
/**
 * \brief Implementation of surface:set_transparency_color().
 * \param l the Lua context that is calling this function
 * \return number of values to return to Lua
 */
int LuaContext::surface_api_set_transparency_color(lua_State* l) {

    Surface& surface = check_surface(l, 1);
    Color color = check_color(l, 2);
    surface.set_transparency_color(color);

    return 0;
}
// Make sure our blits always map src==0 to a noop, and src==FF to full opaque
static void test_00_FF(skiatest::Reporter* reporter) {
    static const int W = 256;

    static const SkBitmap::Config gDstConfig[] = {
        SkBitmap::kARGB_8888_Config,
        SkBitmap::kRGB_565_Config,
//        SkBitmap::kARGB_4444_Config,
//        SkBitmap::kA8_Config,
    };

    static const struct {
        SkColor     fSrc;
        SkColor     fDst;
        SkPMColor   fResult32;
        uint16_t    fResult16;
        uint8_t     fResult8;
    } gSrcRec[] = {
        { 0,            0,          0,                                    0,      0 },
        { 0,            0xFFFFFFFF, SkPackARGB32(0xFF, 0xFF, 0xFF, 0xFF), 0xFFFF, 0xFF },
        { 0xFFFFFFFF,   0,          SkPackARGB32(0xFF, 0xFF, 0xFF, 0xFF), 0xFFFF, 0xFF },
        { 0xFFFFFFFF,   0xFFFFFFFF, SkPackARGB32(0xFF, 0xFF, 0xFF, 0xFF), 0xFFFF, 0xFF },
    };

    SkPaint paint;

    SkBitmap srcBM;
    srcBM.setConfig(SkBitmap::kARGB_8888_Config, W, 1);
    srcBM.allocPixels();

    for (size_t i = 0; i < SK_ARRAY_COUNT(gDstConfig); i++) {
        SkBitmap dstBM;
        dstBM.setConfig(gDstConfig[i], W, 1);
        dstBM.allocPixels();
        
        SkCanvas canvas(dstBM);
        for (size_t j = 0; j < SK_ARRAY_COUNT(gSrcRec); j++) {
            srcBM.eraseColor(gSrcRec[j].fSrc);
            dstBM.eraseColor(gSrcRec[j].fDst);

            for (int k = 0; k < 4; k++) {
                bool dither = (k & 1) != 0;
                bool blend = (k & 2) != 0;
                if (gSrcRec[j].fSrc != 0 && blend) {
                    // can't make a numerical promise about blending anything
                    // but 0
                 //   continue;
                }
                paint.setDither(dither);
                paint.setAlpha(blend ? 0x80 : 0xFF);
                canvas.drawBitmap(srcBM, 0, 0, &paint);
                if (!check_color(dstBM, gSrcRec[j].fResult32, gSrcRec[j].fResult16,
                                 gSrcRec[j].fResult8, reporter)) {
                    SkDebugf("--- src index %d dither %d blend %d\n", j, dither, blend);
                }
            }
        }
    }
}
Esempio n. 14
0
/**
 * \brief Implementation of text_surface:set_color().
 * \param l the Lua context that is calling this function
 * \return number of values to return to Lua
 */
int LuaContext::text_surface_api_set_color(lua_State* l) {

  TextSurface& text_surface = check_text_surface(l, 1);
  const Color& color = check_color(l, 2);

  text_surface.set_text_color(color);

  return 0;
}
Esempio n. 15
0
void cekSimpang(Queue *Q) {
	if(checkLine(right)) {
		int heuristic = check_color();
		node n = {right,heuristic};
		addToQueue(Q,right);
	}
	if(checkLine(left)) {
		int heuristic = check_color();
		node n = {right,heuristic};
		addToQueue(Q,straight);
	}
	if(checkLine(left)) {
		int heuristic = check_color();
		node n = {right,heuristic};
		addToQueue(Q,left);
	}
	turn(right,90);
}
Esempio n. 16
0
File: color.c Progetto: skn/tasknc
int parse_color(const char *name) /* {{{ */
{
	/* parse a color from a string */
	unsigned int i;
	int ret;
	struct color_map
	{
		const int color;
		const char *name;
	};

	/* color map */
	static const struct color_map colors_map[] =
	{
		{COLOR_BLACK,   "black"},
		{COLOR_RED,     "red"},
		{COLOR_GREEN,   "green"},
		{COLOR_YELLOW,  "yellow"},
		{COLOR_BLUE,    "blue"},
		{COLOR_MAGENTA, "magenta"},
		{COLOR_CYAN,    "cyan"},
		{COLOR_WHITE,   "white"},
	};

	/* try for int */
	ret = sscanf(name, "%d", &i);
	if (ret == 1)
		return check_color(i);

	/* try for colorNNN */
	ret = sscanf(name, "color%3d", &i);
	if (ret == 1)
		return check_color(i);

	/* look for mapped color */
	for (i=0; i<sizeof(colors_map)/sizeof(struct color_map); i++)
	{
		if (str_eq(colors_map[i].name, name))
			return check_color(colors_map[i].color);
	}

	return -2;
} /* }}} */
Esempio n. 17
0
void fill_circle(void)
{
    _circle* c;

    c = POP(_circle);
    check_color();
    fprintf(output_file, "\\pscircle*");
    put_local();
    fprintf(output_file, "(%.4f,%.4f){%.4f}\n", c->x, c->y, c->r);
}
Esempio n. 18
0
void fill_polygon(void)
{
    _set* s;

    s = POP(_set);
    if (s == NULL) return;
    check_color();
    fprintf(output_file, "\\pspolygon*");
    put_local();
    put_set(s);
}
Esempio n. 19
0
void draw_point(void)
{
    _point *A;

    A = POP(_point);
    check_color();
    check_shape();
    check_dotsize();
    fprintf(output_file, "\\psdots");
    put_local();
    fprintf(output_file, "(%.4f,%.4f)\n", A->x, A->y);
}
Esempio n. 20
0
/**
 * \brief Implementation of surface:fill_color().
 * \param l the Lua context that is calling this function
 * \return number of values to return to Lua
 */
int LuaContext::surface_api_fill_color(lua_State* l) {

    Surface& surface = check_surface(l, 1);
    Color color = check_color(l, 2);

    if (lua_gettop(l) >= 3) {
        int x = luaL_checkint(l, 3);
        int y = luaL_checkint(l, 4);
        int width = luaL_checkint(l, 5);
        int height = luaL_checkint(l, 6);
        Rectangle where(x, y, width, height);
        surface.fill_with_color(color, where);
    }
    else {
        surface.fill_with_color(color);
    }

    return 0;
}
Esempio n. 21
0
static void	parsing_options(char **tab, t_env *rt, int i)
{
	if (!tab[0] || !tab[1])
		ft_exit("\033[31mWrong format for an object\n");
	missing_parameter_obj(tab);
	if (!ft_strcmp(tab[0], "radius"))
	{
		if (ATOF(2) <= 0 && rt->object[i].name != PLANE &&
		rt->object[i].name != HYPERBOL)
			ft_exit("\033[31mRadius must be positive\n");
		rt->object[i].radius = ATOF(2);
	}
	else if (!ft_strcmp(tab[0], "pos"))
		rt->object[i].center = new_vector(ATOF(2), ATOF(3), ATOF(4));
	else if (!ft_strcmp(tab[0], "color"))
	{
		check_color(ATOF(2), ATOF(3), ATOF(4));
		rt->object[i].color = new_color(ATOF(2), ATOF(3), ATOF(4));
	}
}
SM_CrossStitchEssentialMaterialInfo *
SM_CrossStitchEssentialMaterialInfo_New(size_t size, 
                                        char *color) {
  size_t color_len = strlen(color);
  if (color_len == 0) {
    color = "#ffffff";
    color_len = strlen(color);
  }
  if (!check_color(color)) {
    return NULL;
  }
  if (size == 0) {
    return NULL;
  }
  SM_CrossStitchEssentialMaterialInfo *ret = 
      malloc(sizeof(SM_CrossStitchEssentialMaterialInfo));
  ret->canvas.size = size;
  ret->canvas.color = malloc(color_len + 1);
  memcpy(ret->canvas.color, color, color_len + 1);
  return ret;
}
Esempio n. 23
0
int checkLine(int dir) {
	int a,degmax=0;
	int incdegree=dir==right?10:-10;
	int rightpower=dir==right?-50:50;
	int rightdegree=dir==right?-10:10;
	while((degmax<2300&&dir==right) || (degmax>-2300&&dir==left)) {
		a=check_color();
		switch(a) {
 		case 0:
 			moveMotorTarget(leftMotor,-rightdegree,-rightpower);
  			moveMotorTarget(rightMotor,rightdegree,rightpower);
  			while(getMotorMoving(leftMotor) && getMotorMoving(rightMotor))
    			sleep(1);
    		degmax+=incdegree;
    		break;
    case 1:
    		motor[leftMotor]=0;
    		motor[rightMotor]=0;
    		sleep(100);
    		return 1;
  	}
 	}
}
Esempio n. 24
0
int searchSpot() {
//menelusuri garis hitam sampai menemukan "color"
	int a;
	while(1)
	{
		a=check_color();
  	switch(a){
    case 0:	//Putih_Arena -> Belok Kanan
				motor[leftMotor]  = 15;
      			motor[rightMotor] = 55;
      			break;
    case 1: //Hitam_Garis -> Belok Kiri
    				motor[leftMotor]  = 55;
      			motor[rightMotor] = 15;
      			break;
    case 3: //Ijo_Simpang -> diem
    				//moveMotorTarget(leftMotor,180,50);
    				//moveMotorTarget(rightMotor,-180,-50);
    				motor[leftMotor] =0;
    				motor[rightMotor] =0;
    				sleep(10);
    				while(getMotorMoving(leftMotor) && getMotorMoving(rightMotor))
    					sleep(1);
      			break;
    case 4: //Merah_ujung -> Balik kanan
    				motor[leftMotor] = 100;
    				motor[rightMotor] = -100;
    				sleep(500);
      			break;

     default:
     				//motor[leftMotor]  = 0;
      			//motor[rightMotor] = 0;
    }
	}
	return a;
}
Esempio n. 25
0
task main()
{
  while(true)
  {
  	//cekGaris();
  	int a=check_color();
  	switch(a){
    case 0:	//Putih_Arena -> Belok Kanan
    				motor[leftMotor]  = -20;
      			motor[rightMotor] = 40;
      			break;
    case 1: //Hitam_Garis -> Belok Kiri
    				motor[leftMotor]  = 40;
      			motor[rightMotor] = -20;
      			break;
    case 3: //Ijo_Simpang -> diem
    				//moveMotorTarget(leftMotor,40,50);
    				//moveMotorTarget(rightMotor,40,50);
    				motor[leftMotor] =0;
    				motor[rightMotor] =0;
    				sleep(1000);
    				//while(getMotorMoving(leftMotor) && getMotorMoving(rightMotor))
    					//sleep(1);
      			break;
    case 4: //Merah_ujung -> Balik kanan
    				motor[leftMotor] =0;
    				motor[rightMotor] =0;
    				sleep(1000);
      			break;

     default:
     				//motor[leftMotor]  = 0;
      			//motor[rightMotor] = 0;
    }
  }
}
Esempio n. 26
0
void label_angle(void)
{
    double a, b, r, s, t,x1, y1, x2, y2;
    _point *A, *B, *C;

    check_color();
    C = POP(_point);
    B = POP(_point);
    A = POP(_point);
    a = argument(B, A);
    b = argument(B, C);
    r = SIZE(.5);
    s = .08/scale;
    fprintf(output_file, "\\pscustom");
    put_local();
    fprintf(output_file, "{\n");
    switch (local_angle) {
	case SIMPLE:
	    draw_mark("", B, r, a, b);
	    if (local_dec == DOTTED) {
		set_xy(A, B, C, SIZE(M_SQRT2/8), &x1, &y1, &x2, &y2);
		fprintf(output_file, "  \\Dot{%.4f}{%.4f}{%.4f}\n",
			B->x + x1 + x2, B->y + y1 + y2, SIZE(.05));
	    }
	    if (local_dec == DASHED) {
		fprintf(output_file, "  \\Dash{%.4f}{%.4f}{%.4f}{%.4f}{%.4f}\n",
			 B->x, B->y, (a + b)/2, r - s, r + s);
	    }
	    break;
	case DOUBLE:
	    if (local_dec == DASHED) {
		draw_mark("", B, r, a, b);
		t = 8/local_size;
		fprintf(output_file, "  \\DoubleDash"
			"{%.4f}{%.4f}{%.4f}{%.4f}{%.4f}{%.4f}\n",
			B->x, B->y, r - s, r + s, (a + b)/2 - t/2, t);
	    } else {
		fprintf(output_file, "  \\DoubleArc"
			"{%.4f}{%.4f}{%.4f}{%.4f}{%.4f}{%.4f}\n",
			B->x, B->y, r - s/2, r + s/2, a, b);
	    }
	    break;
	case TRIPLE:
	    if (local_dec == DASHED) {
		draw_mark("", B, r, a, b);
		t = 8/local_size;
		fprintf(output_file, "  \\TripleDash"
			"{%.4f}{%.4f}{%.4f}{%.4f}{%.4f}{%.4f}\n",
			B->x, B->y, r - s, r + s, (a + b)/2 - t, t);
	    } else {
		fprintf(output_file, "  \\TripleArc"
			"{%.4f}{%.4f}{%.4f}{%.4f}{%.4f}{%.4f}{%.4f}\n",
			B->x, B->y, r - s, r, r + s, a, b);
	    }
	    break;
	case RIGHT:
	    set_xy(A, B, C, SIZE(.35), &x1, &y1, &x2, &y2);
	    fprintf(output_file, "  \\Right{%.4f}{%.4f}{%.4f}{%.4f}{%.4f}{%.4f}\n",
		    B->x + x1, B->y + y1, x2, y2, -x1, -y1);
	    if (local_dec == DOTTED) {
		fprintf(output_file, "  \\Dot{%.4f}{%.4f}{%.4f}\n",
			B->x + (x1 + x2)/2, B->y + (y1 + y2)/2, SIZE(.05));
	    }
	    break;
	case FORTH:
	    draw_mark("{->}", B, r, a, b);
	    break;
	case BACK:
	    draw_mark("{<-}", B, r, a, b);
	    break;
    }
    fprintf(output_file, "}\n");
}
Esempio n. 27
0
static GLboolean
intelTryReadPixels( GLcontext *ctx,
		  GLint x, GLint y, GLsizei width, GLsizei height,
		  GLenum format, GLenum type,
		  const struct gl_pixelstore_attrib *pack,
		  GLvoid *pixels )
{
   intelContextPtr intel = INTEL_CONTEXT(ctx);
   GLint size = 0; /* not really used */
   GLint pitch = pack->RowLength ? pack->RowLength : width;

   if (INTEL_DEBUG & DEBUG_PIXEL)
      fprintf(stderr, "%s\n", __FUNCTION__);

   /* Only accelerate reading to agp buffers.
    */
   if ( !intelIsAgpMemory(intel, pixels, 
			pitch * height * intel->intelScreen->cpp ) ) {
      if (INTEL_DEBUG & DEBUG_PIXEL)
	 fprintf(stderr, "%s: dest not agp\n", __FUNCTION__);
      return GL_FALSE;
   }

   /* Need GL_PACK_INVERT_MESA to cope with upsidedown results from
    * blitter:
    */
   if (!pack->Invert) {
      if (INTEL_DEBUG & DEBUG_PIXEL)
	 fprintf(stderr, "%s: MESA_PACK_INVERT not set\n", __FUNCTION__);
      return GL_FALSE;
   }

   if (!check_color(ctx, type, format, pack, pixels, size, pitch))
      return GL_FALSE;

   switch ( intel->intelScreen->cpp ) {
   case 4:
      break;
   default:
      return GL_FALSE;
   }


   /* Although the blits go on the command buffer, need to do this and
    * fire with lock held to guarentee cliprects and drawing offset are
    * correct.
    *
    * This is an unusual situation however, as the code which flushes
    * a full command buffer expects to be called unlocked.  As a
    * workaround, immediately flush the buffer on aquiring the lock.
    */
   intelFlush( &intel->ctx );
   LOCK_HARDWARE( intel );
   {
      __DRIdrawablePrivate *dPriv = intel->driDrawable;
      int nbox = dPriv->numClipRects;
      int src_offset = intel->readRegion->offset;
      int src_pitch = intel->intelScreen->front.pitch;
      int dst_offset = intelAgpOffsetFromVirtual( intel, pixels);
      drm_clip_rect_t *box = dPriv->pClipRects;
      int i;

      assert(dst_offset != ~0);  /* should have been caught above */

      if (!clip_pixelrect(ctx, ctx->ReadBuffer, &x, &y, &width, &height)) {
	 UNLOCK_HARDWARE( intel );
	 if (INTEL_DEBUG & DEBUG_PIXEL)
	    fprintf(stderr, "%s totally clipped -- nothing to do\n",
		    __FUNCTION__);
	 return GL_TRUE;
      }

      /* convert to screen coords (y=0=top) */
      y = dPriv->h - y - height;
      x += dPriv->x;
      y += dPriv->y;

      if (INTEL_DEBUG & DEBUG_PIXEL)
	 fprintf(stderr, "readpixel blit src_pitch %d dst_pitch %d\n",
		 src_pitch, pitch);

      /* We don't really have to do window clipping for readpixels.
       * The OpenGL spec says that pixels read from outside the
       * visible window region (pixel ownership) have undefined value.
       */
      for (i = 0 ; i < nbox ; i++)
      {
         GLint bx, by, bw, bh;
         if (intersect_region(box+i, x, y, width, height,
                              &bx, &by, &bw, &bh)) {
            intelEmitCopyBlitLocked( intel,
                                     intel->intelScreen->cpp,
                                     src_pitch, src_offset,
                                     pitch, dst_offset,
                                     bx, by,
                                     bx - x, by - y,
                                     bw, bh );
         }
      }
   }
   UNLOCK_HARDWARE( intel );
   intelFinish( &intel->ctx );

   return GL_TRUE;
}
Esempio n. 28
0
static GLboolean
intelTryDrawPixels( GLcontext *ctx,
		  GLint x, GLint y, GLsizei width, GLsizei height,
		  GLenum format, GLenum type,
		  const struct gl_pixelstore_attrib *unpack,
		  const GLvoid *pixels )
{
   intelContextPtr intel = INTEL_CONTEXT(ctx);
   GLint pitch = unpack->RowLength ? unpack->RowLength : width;
   GLuint dest;
   GLuint cpp = intel->intelScreen->cpp;
   GLint size = width * pitch * cpp;

   if (INTEL_DEBUG & DEBUG_PIXEL)
      fprintf(stderr, "%s\n", __FUNCTION__);

   switch (format) {
   case GL_RGB:
   case GL_RGBA:
   case GL_BGRA:
      dest = intel->drawRegion->offset;

      /* Planemask doesn't have full support in blits.
       */
      if (!ctx->Color.ColorMask[RCOMP] ||
	  !ctx->Color.ColorMask[GCOMP] ||
	  !ctx->Color.ColorMask[BCOMP] ||
	  !ctx->Color.ColorMask[ACOMP]) {
	 if (INTEL_DEBUG & DEBUG_PIXEL)
	    fprintf(stderr, "%s: planemask\n", __FUNCTION__);
	 return GL_FALSE;	
      }

      /* Can't do conversions on agp reads/draws. 
       */
      if ( !intelIsAgpMemory( intel, pixels, size ) ) {
	 if (INTEL_DEBUG & DEBUG_PIXEL)
	    fprintf(stderr, "%s: not agp memory\n", __FUNCTION__);
	 return GL_FALSE;
      }

      if (!check_color(ctx, type, format, unpack, pixels, size, pitch)) {
	 return GL_FALSE;
      }
      if (!check_color_per_fragment_ops(ctx)) {
	 return GL_FALSE;
      }

      if (ctx->Pixel.ZoomX != 1.0F ||
	  ctx->Pixel.ZoomY != -1.0F)
	 return GL_FALSE;
      break;

   default:
      return GL_FALSE;
   }

   if ( intelIsAgpMemory(intel, pixels, size) )
   {
      do_draw_pix( ctx, x, y, width, height, pitch, pixels, dest );
      return GL_TRUE;
   }
   else if (0)
   {
      /* Pixels is in regular memory -- get dma buffers and perform
       * upload through them.  No point doing this for regular uploads
       * but once we remove some of the restrictions above (colormask,
       * pixelformat conversion, zoom?, etc), this could be a win.
       */
   }
   else
      return GL_FALSE;

   return GL_FALSE;
}
Esempio n. 29
0
static GLboolean
r200TryReadPixels( GLcontext *ctx,
                   GLint x, GLint y, GLsizei width, GLsizei height,
                   GLenum format, GLenum type,
                   const struct gl_pixelstore_attrib *pack,
                   GLvoid *pixels )
{
    r200ContextPtr rmesa = R200_CONTEXT(ctx);
    GLint pitch = pack->RowLength ? pack->RowLength : width;
    GLint blit_format;
    GLuint cpp = rmesa->r200Screen->cpp;
    GLint size = width * height * cpp;

    if (R200_DEBUG & DEBUG_PIXEL)
        fprintf(stderr, "%s\n", __FUNCTION__);

    /* Only accelerate reading to GART buffers.
     */
    if ( !r200IsGartMemory(rmesa, pixels,
                           pitch * height * rmesa->r200Screen->cpp ) ) {
        if (R200_DEBUG & DEBUG_PIXEL)
            fprintf(stderr, "%s: dest not GART\n", __FUNCTION__);
        return GL_FALSE;
    }

    /* Need GL_PACK_INVERT_MESA to cope with upsidedown results from
     * blitter:
     */
    if (!pack->Invert) {
        if (R200_DEBUG & DEBUG_PIXEL)
            fprintf(stderr, "%s: MESA_PACK_INVERT not set\n", __FUNCTION__);
        return GL_FALSE;
    }

    if (!check_color(ctx, type, format, pack, pixels, size, pitch))
        return GL_FALSE;

    switch ( rmesa->r200Screen->cpp ) {
    case 4:
        blit_format = R200_CP_COLOR_FORMAT_ARGB8888;
        break;
    default:
        return GL_FALSE;
    }


    /* Although the blits go on the command buffer, need to do this and
     * fire with lock held to guarentee cliprects and drawOffset are
     * correct.
     *
     * This is an unusual situation however, as the code which flushes
     * a full command buffer expects to be called unlocked.  As a
     * workaround, immediately flush the buffer on aquiring the lock.
     */
    LOCK_HARDWARE( rmesa );

    if (rmesa->store.cmd_used)
        r200FlushCmdBufLocked( rmesa, __FUNCTION__ );

    if (!clip_pixelrect(ctx, ctx->ReadBuffer, &x, &y, &width, &height,
                        &size)) {
        UNLOCK_HARDWARE( rmesa );
        if (R200_DEBUG & DEBUG_PIXEL)
            fprintf(stderr, "%s totally clipped -- nothing to do\n",
                    __FUNCTION__);
        return GL_TRUE;
    }

    {
        __DRIdrawablePrivate *dPriv = rmesa->dri.drawable;
        driRenderbuffer *drb = (driRenderbuffer *) ctx->ReadBuffer->_ColorReadBuffer;
        int nbox = dPriv->numClipRects;
        int src_offset = drb->offset
                         + rmesa->r200Screen->fbLocation;
        int src_pitch = drb->pitch * drb->cpp;
        int dst_offset = r200GartOffsetFromVirtual( rmesa, pixels );
        int dst_pitch = pitch * rmesa->r200Screen->cpp;
        drm_clip_rect_t *box = dPriv->pClipRects;
        int i;

        r200EmitWait( rmesa, RADEON_WAIT_3D );

        y = dPriv->h - y - height;
        x += dPriv->x;
        y += dPriv->y;


        if (R200_DEBUG & DEBUG_PIXEL)
            fprintf(stderr, "readpixel blit src_pitch %d dst_pitch %d\n",
                    src_pitch, dst_pitch);

        for (i = 0 ; i < nbox ; i++)
        {
            GLint bx = box[i].x1;
            GLint by = box[i].y1;
            GLint bw = box[i].x2 - bx;
            GLint bh = box[i].y2 - by;

            if (bx < x) bw -= x - bx, bx = x;
            if (by < y) bh -= y - by, by = y;
            if (bx + bw > x + width) bw = x + width - bx;
            if (by + bh > y + height) bh = y + height - by;
            if (bw <= 0) continue;
            if (bh <= 0) continue;

            r200EmitBlit( rmesa,
                          blit_format,
                          src_pitch, src_offset,
                          dst_pitch, dst_offset,
                          bx, by,
                          bx - x, by - y,
                          bw, bh );
        }

        r200FlushCmdBufLocked( rmesa, __FUNCTION__ );
    }
    UNLOCK_HARDWARE( rmesa );

    r200Finish( ctx ); /* required by GL */

    return GL_TRUE;
}
Esempio n. 30
0
static GLboolean
r200TryDrawPixels( GLcontext *ctx,
                   GLint x, GLint y, GLsizei width, GLsizei height,
                   GLenum format, GLenum type,
                   const struct gl_pixelstore_attrib *unpack,
                   const GLvoid *pixels )
{
    r200ContextPtr rmesa = R200_CONTEXT(ctx);
    GLint pitch = unpack->RowLength ? unpack->RowLength : width;
    GLuint planemask;
    GLuint cpp = rmesa->r200Screen->cpp;
    GLint size = width * pitch * cpp;

    if (R200_DEBUG & DEBUG_PIXEL)
        fprintf(stderr, "%s\n", __FUNCTION__);

    /* check that we're drawing to exactly one color buffer */
    if (ctx->DrawBuffer->_NumColorDrawBuffers[0] != 1)
        return GL_FALSE;

    switch (format) {
    case GL_RGB:
    case GL_RGBA:
    case GL_BGRA:
        planemask = r200PackColor(cpp,
                                  ctx->Color.ColorMask[RCOMP],
                                  ctx->Color.ColorMask[GCOMP],
                                  ctx->Color.ColorMask[BCOMP],
                                  ctx->Color.ColorMask[ACOMP]);

        if (cpp == 2)
            planemask |= planemask << 16;

        if (planemask != ~0)
            return GL_FALSE;	/* fix me -- should be possible */

        /* Can't do conversions on GART reads/draws.
         */
        if ( !r200IsGartMemory( rmesa, pixels, size ) ) {
            if (R200_DEBUG & DEBUG_PIXEL)
                fprintf(stderr, "%s: not GART memory\n", __FUNCTION__);
            return GL_FALSE;
        }

        if (!check_color(ctx, type, format, unpack, pixels, size, pitch)) {
            return GL_FALSE;
        }
        if (!check_color_per_fragment_ops(ctx)) {
            return GL_FALSE;
        }

        if (ctx->Pixel.ZoomX != 1.0F ||
                ctx->Pixel.ZoomY != -1.0F)
            return GL_FALSE;
        break;

    default:
        return GL_FALSE;
    }

    if ( r200IsGartMemory(rmesa, pixels, size) )
    {
        do_draw_pix( ctx, x, y, width, height, pitch, pixels, planemask );
        return GL_TRUE;
    }
    else if (0)
    {
        /* Pixels is in regular memory -- get dma buffers and perform
         * upload through them.
         */
    }
    else
        return GL_FALSE;
}