예제 #1
0
/**
 * Decompress pcx file and convert to 8 bits (no change),
 * or 16 bits or 24 bits
 * @param filename the file which should be loaded
 * @param buffer pointer to the buffer where data are stored
 * @return TRUE if it completed successfully or FALSE otherwise
 */
bool
load_pcx_into_buffer (const char *filename, char *buffer)
{
  Uint32 i;
  char *data;
  bitmap_desc *gfx = load_pcx (filename);
  if (gfx == NULL)
    {
      return FALSE;
    }
  if (bytes_per_pixel > 0)
    {
      if (!convert_16_or_24 (gfx))
        {
          LOG_ERR ("convert_16_or_24() failed!");
          return TRUE;
        }
    }
  data = gfx->pixel;
  for (i = 0; i < gfx->size; i++)
    {
      buffer[i] = data[i];
    }
  free_memory (data);
  free_memory ((char *) gfx);
  return TRUE;
}
예제 #2
0
void pcx_fade_decomp(void **p,long *s)
  {
  char *buff;
  load_pcx(*p,*s,A_FADE_PAL,&buff,mglob.fade_r,mglob.fade_g,mglob.fade_b);
  *s=_msize(buff);
  free(*p);
  *p=buff;
  }
예제 #3
0
void pcx_8bit_decomp(void **p,long *s)
  {
  char *buff;
  load_pcx(*p,*s,A_8BIT,&buff);
  *s=_msize(buff);
  free(*p);
  *p=buff;
  }
예제 #4
0
void pcx_15bit_autofade(void **p,long *s)
  {
  char *buff;
  load_pcx(*p,*s,A_16BIT,&buff);
  *s=_msize(buff);
  free(*p);
  *p=buff;
  buff[5]=0x80;
  }
예제 #5
0
void pcx_8bit_nopal(void **p,long *s)
  {
  char *buff;

  if (*p!=NULL)
     {
     load_pcx(*p,*s,A_8BIT_NOPAL,&buff);
     *s=_msize(buff);
     free(*p);
     *p=buff;
     }
  }
예제 #6
0
void pcx_15bit_backgrnd(void **p,long *s)
  {
  char *buff;
  long i;long *z;

  if (*p!=NULL)
     {
     load_pcx(*p,*s,A_16BIT,&buff);
     z=(long *)buff;
     *s=_msize(buff);
     for(i=*s;i>0;i-=4,z++) *z|=0x80008000;
     free(*p);
     *p=buff;
     }
  }
예제 #7
0
/** 
 * Decompress pcx file and convert to 8 bits (no change),
 * or 16 bits or 24 bits
 * @param filename the file which should be loaded
 * @return file data buffer pointer
 */
char *
load_pcx_file (const char *filename)
{
  char *buffer;
  bitmap_desc *gfx = load_pcx (filename);
  if (gfx == NULL)
    {
      return NULL;
    }
  if (bytes_per_pixel > 0)
    {
      if (!convert_16_or_24 (gfx))
        {
          LOG_ERR ("convert_16_or_24() failed!");
          return NULL;
        }
    }
  buffer = gfx->pixel;
  free_memory ((char *) gfx);
  return buffer;
}
예제 #8
0
int main(int argc, char *argv[])
{
   PALETTE my_palette;
   BITMAP *scr_buffer;
   char pcx_name[256];

   if (allegro_init() != 0)
      return 1;
   install_keyboard();

   if (set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0) != 0) {
      if (set_gfx_mode(GFX_SAFE, 640, 480, 0, 0) != 0) {
	 set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
	 allegro_message("Unable to set any graphic mode\n%s\n", allegro_error);
	 return 1;
      }
   }

   replace_filename(pcx_name, argv[0], "mysha.pcx", sizeof(pcx_name));
   scr_buffer = load_pcx(pcx_name, my_palette);
   if (!scr_buffer) {
      set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
      allegro_message("Error loading %s!\n", pcx_name);
      return 1;
   }

   set_palette(my_palette);
   blit(scr_buffer, screen, 0, 0, 0, 0, scr_buffer->w, scr_buffer->h);

   while (!keypressed()) {
      stretch_blit(scr_buffer, screen, 0, 0, AL_RAND()%scr_buffer->w,
		   AL_RAND()%scr_buffer->h, AL_RAND()%SCREEN_W, AL_RAND()%SCREEN_H,
		   AL_RAND()%SCREEN_W, AL_RAND()%SCREEN_H);
      vsync();
   }

   destroy_bitmap(scr_buffer);
   return 0;
}
예제 #9
0
/**
 * qdgdfv_load_pcx_pal_set - Loads a graphic in PCX format setting its palette.
 * @pcx: the buffer where the graphic will be stored
 * @pcxfile: the file containing the graphic
 * @size: the size in bytes of the graphic data
 *
 * This function does the same as qdgdfv_load_pcx(), but setting the palette
 * store inside the file as the default.
 * [Video Functions]
 */
void qdgdfv_load_pcx_pal_set(unsigned char *pcx, char *pcxfile, int size)
{
	load_pcx(pcx, pcxfile, size, 2);
}
예제 #10
0
/**
 * qdgdfv_load_pcx - Loads a graphic in PCX format.
 * @pcx: the buffer where the graphic will be stored
 * @pcxfile: the file containing the graphic
 * @size: the size in bytes of the graphic data
 *
 * Loads a graphic into the supplied @pcx buffer. The file must be
 * in 256 color PCX format. The palette included inside the file
 * is not used.
 * [Video Functions]
 */
void qdgdfv_load_pcx(unsigned char *pcx, char *pcxfile, int size)
{
	load_pcx(pcx, pcxfile, size, 0);
}
예제 #11
0
/* This demonstrates writing. It simply saves the two bitmaps into a binary
 * file.
 */
static void stdio_write_test(void)
{
   FILE *fp;
   PACKFILE *f;
   BITMAP *bmp, *bmp2;

   /* Read the bitmaps. */
   bmp = load_pcx("allegro.pcx", NULL);
   CHECK(bmp, "load_pcx");
   bmp2 = load_pcx("mysha.pcx", NULL);
   CHECK(bmp2, "load_pcx");

   /* Write them with out custom vtable. */
   fp = fopen("expackf.out", "wb");
   CHECK(fp, "writing expackf.out");
   f = pack_fopen_vtable(&stdio_vtable, fp);
   CHECK(f, "writing with stdio");

   save_tga_pf(f, bmp, NULL);
   save_bmp_pf(f, bmp2, NULL);

   destroy_bitmap(bmp);
   destroy_bitmap(bmp2);
   pack_fclose(f);

   /* Now read them in again with our custom vtable. */
   fp = fopen("expackf.out", "rb");
   CHECK(fp, "fopen");
   f = pack_fopen_vtable(&stdio_vtable, fp);
   CHECK(f, "reading from stdio");

   /* Note: in general you would need to implement a "chunking" system
    * that knows where the boundary of each file is. Many file format
    * loaders will happily read everything to the end of the file,
    * whereas others stop reading as soon as they have all the essential
    * data (e.g. there may be some metadata at the end of the file).
    * Concatenating bare files together only works in examples programs.
    */
   bmp = load_tga_pf(f, NULL);
   CHECK(bmp, "load_tga_pf");
   bmp2 = load_bmp_pf(f, NULL);
   CHECK(bmp2, "load_bmp_pf");

   blit(bmp, screen, 0, 0, 0, 0, bmp->w, bmp->h);
   textprintf_ex(screen, font, bmp2->w + 8, 8, -1, -1,
      "\"allegro.pcx\" (as tga)");
   textprintf_ex(screen, font, bmp2->w + 8, 8 + 20, -1, -1,
      "wrote with stdio functions");

   blit(bmp2, screen, 0, 0, 0, bmp->h + 8, bmp2->w, bmp2->h);
   textprintf_ex(screen, font, bmp2->w + 8, bmp->h + 8, -1, -1,
      "\"mysha.pcx\" (as bmp)");
   textprintf_ex(screen, font, bmp2->w + 8, bmp->h + 8 + 20, -1, -1,
      "wrote with stdio functions");

   destroy_bitmap(bmp);
   destroy_bitmap(bmp2);
   pack_fclose(f);

   next();
}
예제 #12
0
int main(void)
{
	allegro_init();
	install_keyboard();
	install_mouse();
	set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0);
	buffer = create_bitmap(640, 480);
	vpic[0] = load_pcx("antivirus.dat#virus_red.pcx", pal);
	vpic[1] = load_pcx("antivirus.dat#virus_yellow.pcx", NULL);
	vpic[2] = load_pcx("antivirus.dat#virus_blue.pcx", NULL);
	map = create_bitmap(8, 16);
	clear_bitmap(map);
	set_palette(pal);
	set_mouse_sprite(NULL);
	while(!done)
	{
		if(key[KEY_ESC])
		{
			done = 1;
		}
		if(key[KEY_1])
		{
			virus = 16;
		}
		else if(key[KEY_2])
		{
			virus = 17;
		}
		else if(key[KEY_3])
		{
			virus = 18;
		}
		if(key[KEY_F2])
		{
			if(file_select_ex("Save:", filename, "pcx", 1024, 320, 240))
			{
				save_pcx(filename, map, pal);
			}
			clear_keybuf();
		}
		if(key[KEY_F3])
		{
			if(file_select_ex("Load:", filename, "pcx", 1024, 320, 240))
			{
				destroy_bitmap(map);
				map = load_pcx(filename, NULL);
			}
			clear_keybuf();
		}
		mx = mouse_x;
		my = mouse_y;
		if(mouse_b & 1 && mx / 16 < 8 && my / 16 < 16)
		{
			map->line[my / 16][mx / 16] = virus;
		}
		else if(mouse_b & 2 && mx / 16 < 8 && my / 16 < 16)
		{
			map->line[my / 16][mx / 16] = 0;
		}
		clear_bitmap(buffer);
		for(int i = 0; i < 16; i++)
		{
			for(int j = 0; j < 8; j++)
			{
				if(map->line[i][j])
				{
					draw_sprite(buffer, vpic[map->line[i][j] - 16], j * 16, i * 16);
				}
			}
		}
		draw_sprite(buffer, mouse_sprite, mouse_x, mouse_y);
		blit(buffer, screen, 0, 0, 0, 0, buffer->w, buffer->h);
	}
	return 0;
}