www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/01/06/15:26:21

To: djgpp AT delorie DOT com
Date: Sun, 5 Jan 1997 17:18:27 PST
Subject: "Remapping" Bitmaps In Allegro
Message-ID: <19970106.150910.9934.1.MSnakes@juno.com>
From: msnakes AT juno DOT com (Matt J Reiferson)

I am creating a tile based game, using the tiles makes it hard to keep
all them with the same pallete so they look right.  The main pallete is
still not final, so I set out to write a function that would take the current main pallete and "remap" it to all the tiles.  This way I would not
have to keep each individual picture updated (the program would do it for
me).  The problem is it doesn't work right, the tiles still don't display
correctly, could anyone tell me what's wrong with the following function:
 (PLEASE RESPOND WITH A DIRECT E-MAIL, I AM NO LONGER ON THE DJGPP
MAILING LIST)

void Pallete_To_Pic(BITMAP *pic, int tileset)
{
   int x,y;
   unsigned int index, bestmatch=0, cerror, besterror;
   char buf[80];
   unsigned int cur_data;
   PALLETE desired,actual;
   RGB want;

   switch(tileset)
      {
      case TILE_GRASS:
         {
         strcpy(get_filename(buf),"GRASS.DAT");
         data=load_datafile(buf);
         if(!data)
         {
            allegro_exit();
            exit(1);
         }
         set_pallete(data[GRASS_PALLETE].dat);
         get_pallete(desired);
         set_pallete(data[GAME_PALLETE].dat);
         get_pallete(actual);
         unload_datafile(data);
         break;
         }
      case TILE_SNOW:
         {
         strcpy(get_filename(buf),"SNOW.DAT");
         data=load_datafile(buf);
         if(!data)
         {
            allegro_exit();
            exit(1);
         }
         set_pallete(data[2].dat);
         get_pallete(desired);
         set_pallete(data[GAME_PALLETE].dat);
         get_pallete(actual);
         unload_datafile(data);
         break;
         }
      case TILE_DEATH:
         {
         strcpy(get_filename(buf),"GRASS.DAT");
         data=load_datafile(buf);
         if(!data)
         {
            allegro_exit();
            exit(1);
         }
         set_pallete(data[3].dat);
         get_pallete(desired);
         set_pallete(data[GAME_PALLETE].dat);
         get_pallete(actual);
         unload_datafile(data);
         break;
         }
   }

   for(y=0;y<(pic->h);y++)
      {
      for(x=0;x<(pic->w);x++)
         {
         besterror=50000;
         cur_data = pic->line[y][x];
         for(index=0;index<256;index++)
            {
            cerror = 0;
            cerror += abs(desired[cur_data].r-actual[index].r);
            cerror += abs(desired[cur_data].g-actual[index].g);
            cerror += abs(desired[cur_data].b-actual[index].b);
            if(cerror<besterror);
               {
               besterror = cerror;
               bestmatch = index;
               }
            }
         /*want.r = desired[cur_data].r;
         want.g = desired[cur_data].g;
         want.b = desired[cur_data].b;
         set_color(bestmatch, (RGB *)&want);*/
         pic->line[y][x] = bestmatch;
         }
      }
}

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019