Mail Archives: djgpp/1997/06/15/14:48:49
On Fri, 13 Jun 1997 20:17:50 +0100, Shawn Hargreaves
<Shawn AT talula DOT demon DOT co DOT uk> wrote:
>SUGANUMA yoshinori writes:
>>for(c=0;c<256;c++){
>> pallete[c].r=c;
>> pallete[c].g=c;
>> pallete[c].b=c;
>>
>>}
c's got to be under 64! But this way of accessing the palette is
right, and took me a while to deduce...
>Allegro just uses the standard VGA format, with the values ranging 0-63.
>You could just divide each intensity by four, to get 64 scales of grey
>with each color duplicated four times, or you could try doing a sort of
>dither by slightly offsetting the three color components, so they
>wouldn't all be exact greys but you would get more unique shades (it
>would need some experimenting to find the best values for this, I never
>tried it myself...)
In the end, you really can see the offset you talk about as
discernable pastel variations of hue in the greyscale... in the end, I
think I prefer plain greyscale. But it is always a little clumsy-
there is no perfectly symmetrical way to lay out 256 entries with 64
intensities; sort of a pain, so I tend to use standard palettes
already in images for their greyscale.
I wrote this little tidbit (and passed it on to Shawn) to dump
palettes from other images in to a form cut-and-pasteable in to
Allegro programs- you could just pick a greyscale image and steal it's
pallete with it. It is short enough that I think it's ok to post it
here:
______________________________________________________________
#include <stdlib.h>
#include <stdio.h>
#include "allegro.h"
BITMAP *g_image;
PALETTE g_palette;
void output_palette(void)
{
int sum,i;
printf("PALETTE your_palette = {\n");
for (i=0;i<255;i++)
{
printf("{ %d, %d, %d
},\n",g_palette[i].r,g_palette[i].g,g_palette[i].b);
}
i=255;
printf("{ %d, %d, %d
}\n};\n",g_palette[i].r,g_palette[i].g,g_palette[i].b);
}
void main(int argc, char *argv[])
{
char file_name[100], temp_char[5];
int blur_factor=0,i;
RGB temp_RGB= {0,0,0};
if (argc != 2)
{
printf("\nGET_PAL\n\n");
printf("This program takes the palette from an image file\n");
printf("of types *.BMP, *.PCX, *.TGA, or *.LBM\n");
printf("and outputs it in an Allegro PALETTE data format.\n\n");
printf("Usage: get_pal filename.[BMP, PCX, LBM, TGA] > outputfile\n");
exit(1);
}
g_image = load_bitmap(argv[1], g_palette);
if (!g_image)
{
printf("\nFor some reason I couldn't deal with the file '%s'.\n",
argv[1]);
printf("Make sure you are indicating the right path,\n");
printf("and have spelled the file properly.\n");
printf("Also make sure that the file is one of types\n");
printf("BMP, PCX, TGA, or LBM.\n");
exit(1);
}
output_palette();
exit(0);
}
__________________________________________________________________
just use it in the form "a.exe clouds.bmp > palette.txt", and then you
can paste the palette dumped in to palette.txt directly in to the
source code you want the palette to be put in. I know it isn't
beautiful, but more than once it has served a nice purpose for me.
- Raw text -