예제 #1
0
파일: video.c 프로젝트: oitofelix/mininim
bool
color_eq (ALLEGRO_COLOR c0, ALLEGRO_COLOR c1)
{
  unsigned char r0, g0, b0, r1, g1, b1;
  al_unmap_rgb (c0, &r0, &g0, &b0);
  al_unmap_rgb (c1, &r1, &g1, &b1);
  return r0 == r1 && g0 == g1 && b0 == b1;
}
예제 #2
0
static void draw_pattern(ALLEGRO_BITMAP *b)
{
   int w = al_get_bitmap_width(b);
   int h = al_get_bitmap_height(b);
   int x, y;
   int format = ALLEGRO_PIXEL_FORMAT_BGR_888;
   ALLEGRO_COLOR light = al_map_rgb_f(1, 1, 1);
   ALLEGRO_COLOR dark = al_map_rgb_f(1, 0.9, 0.8);
   ALLEGRO_LOCKED_REGION *lock;
   lock = al_lock_bitmap(b, format, ALLEGRO_LOCK_WRITEONLY);
   for (y = 0; y < h; y++) {
      for (x = 0; x < w; x++) {
         ALLEGRO_COLOR c = (x + y) & 1 ? light : dark;
         unsigned char r, g, b;
         unsigned char *data = lock->data;
         al_unmap_rgb(c, &r, &g, &b);
         data += y * lock->pitch;
         data += x * 3;
         data[0] = r;
         data[1] = g;
         data[2] = b;
      }
   }
   al_unlock_bitmap(b);
}
예제 #3
0
void shal_unmap_rgb(float color_r,
                    float color_g,
                    float color_b,
                    float color_a,
                    unsigned char * r,
                    unsigned char * g,
                    unsigned char * b)
{
    ALLEGRO_COLOR color;
    color.r = color_r;
    color.g = color_g;
    color.b = color_b;
    color.a = color_a;
    return al_unmap_rgb(color, r, g, b);
}
예제 #4
0
static mrb_value
color_unmap_rgb(mrb_state *mrb, mrb_value self)
{
  ALLEGRO_COLOR *c;
  unsigned char r;
  unsigned char g;
  unsigned char b;
  mrb_value ary;
  c = mrb_data_get_ptr(mrb, self, &mrbal_color_data_type);
  al_unmap_rgb(*c, &r, &g, &b);
  ary = mrb_ary_new_capa(mrb, 3);
  mrb_ary_push(mrb, ary, mrb_fixnum_value(r));
  mrb_ary_push(mrb, ary, mrb_fixnum_value(g));
  mrb_ary_push(mrb, ary, mrb_fixnum_value(b));
  return ary;
}
예제 #5
0
// unused
void convert_grayscale(ALLEGRO_BITMAP *bmp) {
	ALLEGRO_BITMAP *dispbuf = al_get_target_bitmap();
	int x, y, w, h, lum;
	unsigned char r, g, b;
	w = al_get_bitmap_width(bmp);
	h = al_get_bitmap_height(bmp);

	al_set_target_bitmap(bmp);
	al_lock_bitmap(bmp, ALLEGRO_PIXEL_FORMAT_ABGR_8888, ALLEGRO_LOCK_READWRITE);

	for (y = 0; y < h; y++) {
		for (x = 0; x < w; x++) {
			al_unmap_rgb(al_get_pixel(bmp, x, y), &r, &g, &b);
			lum = (0.299*r + 0.587*g + 0.114*b)/2; // dividing by two makes it darker, default should be not dividing
			al_put_pixel(x, y, al_map_rgb(lum, lum, lum)); // RGB to grayscale
		}
	}
	al_unlock_bitmap(bmp);
	al_set_target_bitmap(dispbuf);
}
예제 #6
0
int furthest_left(ALLEGRO_BITMAP *bmp)
{
	int f = SUBW-1;
	for (int y = 0; y < SUBH; y++) {
		int thisf = SUBW-1;
		for (int x = 0; x < SUBW; x++) {
			ALLEGRO_COLOR pixel = al_get_pixel(bmp, x, y);
			unsigned char r, g, b;
			al_unmap_rgb(pixel, &r, &g, &b);
			if (r == 255 && g == 0 && b == 255)
				continue;
			thisf = x;
			break;
		}
		if (thisf < f)
			f = thisf;
	}

	return f;
}
예제 #7
0
int main(void)
{
int X_ROOMS=13;
int Y_ROOMS=16;
int X_ROOM_SIZE=256;
int Y_ROOM_SIZE=128;
int SCALE_FACTOR=4;
int X_TILE_SIZE=8;
int Y_TILE_SIZE=8;
int LAST_OBJECT=0;
int actid=0;
int error=0;
ALLEGRO_CONFIG *cfg;
ALLEGRO_BITMAP *bmp,*virt,*tmp=NULL;
ALLEGRO_DISPLAY *display;
ALLEGRO_KEYBOARD_STATE key;
ALLEGRO_FONT *font;
signed int xcursor=0;
signed int ycursor=0;
signed char x=0;
signed char y=0;
signed char finex=0;
signed char finey=0;
char finish=0;
ALLEGRO_COLOR black,white,red,color;
int scale_cursor_x=0;
int scale_cursor_y=0;
int i=0;
int a=0;
unsigned char r,g,b=0;
char pngfilename[20];
char *tmpbuf;
char buf[5];
char buf2[5];

	/* Iniciar el rollo */
	tmpbuf=(char *)malloc(sizeof(char)*X_ROOM_SIZE*Y_ROOM_SIZE);
	memset(tmpbuf,0,sizeof(char)*X_ROOM_SIZE*Y_ROOM_SIZE);
	al_init();
	al_init_image_addon();
	al_init_primitives_addon();
	al_init_font_addon();
	al_init_ttf_addon();
	cfg=al_load_config_file("sacagraf.cfg");
	if (cfg==NULL)
	{
		cfg=al_create_config();
		al_add_config_section(cfg,"Ajustes");
		al_add_config_section(cfg,"Objetos");
		al_set_config_value(cfg,"Ajustes","Habitaciones en horizontal","13");
		al_set_config_value(cfg,"Ajustes","Habitaciones en vertical","16");
		al_set_config_value(cfg,"Ajustes","Ancho de la habitacion original en pixels","256");
		al_set_config_value(cfg,"Ajustes","Alto de la habitacion original en pixels","128");
		al_set_config_value(cfg,"Ajustes","Ancho minimo del caracter original","8");
		al_set_config_value(cfg,"Ajustes","Alto minimo del caracter original","8");
		al_set_config_value(cfg,"Ajustes","Factor de escalado","4");
		al_set_config_value(cfg,"Objetos","Ultimo","0");
		al_save_config_file("sacagraf.cfg",cfg);
	}

	X_ROOMS=atoi(al_get_config_value(cfg,"Ajustes","Habitaciones en horizontal"));
	Y_ROOMS=atoi(al_get_config_value(cfg,"Ajustes","Habitaciones en vertical"));
	X_ROOM_SIZE=atoi(al_get_config_value(cfg,"Ajustes","Ancho de la habitacion original en pixels"));
	Y_ROOM_SIZE=atoi(al_get_config_value(cfg,"Ajustes","Alto de la habitacion original en pixels"));
	SCALE_FACTOR=atoi(al_get_config_value(cfg,"Ajustes","Factor de escalado"));
	X_TILE_SIZE=atoi(al_get_config_value(cfg,"Ajustes","Alto minimo del caracter original"));
	Y_TILE_SIZE=atoi(al_get_config_value(cfg,"Ajustes","Ancho minimo del caracter original"));
	LAST_OBJECT=atoi(al_get_config_value(cfg,"Objetos","Ultimo"));
	actid=LAST_OBJECT;

	al_set_new_display_flags(ALLEGRO_OPENGL | ALLEGRO_WINDOWED);
	display=al_create_display(X_ROOM_SIZE*SCALE_FACTOR,192*SCALE_FACTOR);
	bmp=al_load_bitmap("map.png");
	virt=al_create_bitmap(X_ROOM_SIZE*SCALE_FACTOR,Y_ROOM_SIZE*SCALE_FACTOR);
	font=al_load_ttf_font("proggy.ttf",6*SCALE_FACTOR,0);
	al_install_keyboard();
	black=al_map_rgb(0,0,0);
	white=al_map_rgba_f(1,1,1,1);
	red=al_map_rgba_f(1,0,0,0.7);

	/* Que empiece la fiesta */
	while(!finish)
	{
		al_get_keyboard_state(&key);
		if (al_key_down(&key,ALLEGRO_KEY_ESCAPE))
		{
			finish=1;
		}

		if (al_key_down(&key,ALLEGRO_KEY_LCTRL))
		{
			finex=0;
			finey=0;
			if (al_key_down(&key,ALLEGRO_KEY_RIGHT))
			{
				x++;
				if (x==X_ROOMS) x=X_ROOMS-1;
			}
			if (al_key_down(&key,ALLEGRO_KEY_LEFT))
			{
				x--;
				if (x<0) x=0;
			}
			if (al_key_down(&key,ALLEGRO_KEY_UP))
			{
				y--;
				if (y<0) y=0;
			}
			if (al_key_down(&key,ALLEGRO_KEY_DOWN))
			{
				y++;
				if (y>Y_ROOMS-1) y=Y_ROOMS-1;
			}
		}
		else if (al_key_down(&key,ALLEGRO_KEY_LSHIFT))
		{
			if (al_key_down(&key,ALLEGRO_KEY_RIGHT))
			{
				finex++;
				if (finex>X_TILE_SIZE) finex=X_TILE_SIZE;
			}
			if (al_key_down(&key,ALLEGRO_KEY_LEFT))
			{
				finex--;
				if (finex<-X_TILE_SIZE) finex=-X_TILE_SIZE;
			}
			if (al_key_down(&key,ALLEGRO_KEY_UP))
			{
				finey--;
				if (finey<-Y_TILE_SIZE) finey=-Y_TILE_SIZE;
			}
			if (al_key_down(&key,ALLEGRO_KEY_DOWN))
			{
				finey++;
				if (finey>Y_TILE_SIZE) finey=Y_TILE_SIZE;
			}
		}
		else if (al_key_down(&key,ALLEGRO_KEY_ALT))
		{
			if (al_key_down(&key,ALLEGRO_KEY_RIGHT))
			{
				scale_cursor_x++;
				//if (finex>8) finex=8;
			}
			if (al_key_down(&key,ALLEGRO_KEY_LEFT))
			{
				scale_cursor_x--;
				//if (finex<0) finex=0;
			}
			if (al_key_down(&key,ALLEGRO_KEY_UP))
			{
				scale_cursor_y--;
				//if (finey<0) finey=0;
			}
			if (al_key_down(&key,ALLEGRO_KEY_DOWN))
			{
				scale_cursor_y++;
				//if (finey>8) finey=8;
			}
		}
		else
		{
			if (al_key_down(&key,ALLEGRO_KEY_RIGHT))
			{
				xcursor+=X_TILE_SIZE*SCALE_FACTOR;
			}
			if (al_key_down(&key,ALLEGRO_KEY_LEFT))
			{
				xcursor-=X_TILE_SIZE*SCALE_FACTOR;
			}
			if (al_key_down(&key,ALLEGRO_KEY_UP))
			{
				ycursor-=Y_TILE_SIZE*SCALE_FACTOR;
			}
			if (al_key_down(&key,ALLEGRO_KEY_DOWN))
			{
				ycursor+=Y_TILE_SIZE*SCALE_FACTOR;
			}
		}

		al_clear_to_color(black);
		al_set_target_bitmap(virt);
		//al_set_blender(ALLEGRO_ALPHA,ALLEGRO_INVERSE_ALPHA,white);
		al_draw_bitmap_region(bmp,0+(x*X_ROOM_SIZE)+finex,0+(y*Y_ROOM_SIZE)+finey,X_ROOM_SIZE,Y_ROOM_SIZE,0,0,0);
		al_set_target_bitmap(al_get_backbuffer(display));
		al_draw_scaled_bitmap(virt,0,0,X_ROOM_SIZE,Y_ROOM_SIZE,0,0,X_ROOM_SIZE*SCALE_FACTOR,Y_ROOM_SIZE*SCALE_FACTOR,0);
		al_draw_line(0,512,1024,512,white,0);
		al_draw_textf(font,al_map_rgba(200,200,200,200),0,520,0,"mapa x: %d  mapa y: %d  habitacion nº: %d  ajuste fino x: %d  ajuste fijo y: %d",x,y,x+(y*13),finex,finey);
		if (error)
		{
			al_draw_textf(font,al_map_rgba(200,200,200,200),0,540,0,"Patron repetido");
			al_flip_display();
			al_rest(1);
			error=0;
		}


		if (al_key_down(&key,ALLEGRO_KEY_ENTER))
		{
			tmp=al_create_bitmap((X_TILE_SIZE*SCALE_FACTOR)+(X_TILE_SIZE*SCALE_FACTOR*scale_cursor_x),(Y_TILE_SIZE*SCALE_FACTOR)+(Y_TILE_SIZE*SCALE_FACTOR*scale_cursor_y));
			al_set_target_bitmap(tmp);
			al_draw_bitmap_region(al_get_backbuffer(display),xcursor,ycursor,(X_TILE_SIZE*SCALE_FACTOR*scale_cursor_x)+(X_TILE_SIZE*SCALE_FACTOR),(Y_TILE_SIZE*SCALE_FACTOR*scale_cursor_y)+(Y_TILE_SIZE*SCALE_FACTOR),0,0,0);

			memset(tmpbuf,0,sizeof(char)*X_ROOM_SIZE*Y_ROOM_SIZE);
			memset(buf,0,5);

			for (i=0;i<(Y_TILE_SIZE*scale_cursor_y*SCALE_FACTOR)+(Y_TILE_SIZE*SCALE_FACTOR);i+=SCALE_FACTOR)
			{
				for (a=0;a<(X_TILE_SIZE*scale_cursor_x*SCALE_FACTOR)+(X_TILE_SIZE*SCALE_FACTOR);a+=SCALE_FACTOR)
				{
					color=al_get_pixel(tmp,a,i);
					al_unmap_rgb(color,&r,&g,&b);
					if (!r && !g && !b)
					{
						strcat(tmpbuf,"0");
					}
					else
					{
						strcat(tmpbuf,"1");
					}
				}
			}

			/* Ya está la secuencia del gráfico en tmpbuf, examinamos todas las secuencias anteriores */

			error=0;
			for (i=0;i<actid;i++)
			{
				memset(buf2,0,5);
				sprintf(buf2,"%d",i);

				if (!strcmp(al_get_config_value(cfg,"Objetos",buf2),tmpbuf))
				{
					error=i;
				}
			}

			/* Si no hay secuencias repetidas lo grabamos */
			if (!error)
			{
				sprintf(buf,"%d",actid);
				al_set_config_value(cfg,"Objetos",buf,tmpbuf);
				memset(pngfilename,0,20);
				sprintf(pngfilename,"dec%d.png",actid);
				al_save_bitmap(pngfilename,tmp);
				actid++;
			}

			al_destroy_bitmap(tmp);
		}

		al_set_target_bitmap(al_get_backbuffer(display));
		//al_set_blender(ALLEGRO_ALPHA,ALLEGRO_INVERSE_ALPHA,red);
		al_draw_filled_rectangle(xcursor,ycursor,xcursor+((X_TILE_SIZE*SCALE_FACTOR)+(X_TILE_SIZE*SCALE_FACTOR*scale_cursor_x)),ycursor+((Y_TILE_SIZE*SCALE_FACTOR)+(Y_TILE_SIZE*SCALE_FACTOR*scale_cursor_y)),red);
		al_flip_display();
		al_rest(0.1);
	}

	memset(buf,0,5);
	sprintf(buf,"%d",actid);
	al_set_config_value(cfg,"Objetos","Ultimo",buf);
	al_save_config_file("sacagraf.cfg",cfg);
	al_destroy_font(font);
	al_uninstall_keyboard();
	al_destroy_bitmap(bmp);
	al_destroy_bitmap(virt);
	al_destroy_display(display);
	al_destroy_config(cfg);
	al_shutdown_ttf_addon();
	al_shutdown_font_addon();
	al_shutdown_image_addon();
	al_shutdown_primitives_addon();
	free(tmpbuf);
	return 0;
}