hi!
I've a problem wit a program that loads a palette from a file(RGB a 1Byte).
ggiMapColor always returns 0.
can anyone help me please?
bye
/* testpal.c */
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <ggi/ggi.h>
#define SUCCESS 0x00
#define ERROR -1
#define FIL_PAL_NAM "palette.dat"
#define PALENT 256
typedef struct {
char r;
char g;
char b;
} pal_fmt;
int main(int argc, char **argv)
{
ggi_visual_t vis;
ggi_mode mode = {
1,
{GGI_AUTO, GGI_AUTO},
{GGI_AUTO, GGI_AUTO},
{0, 0},
GT_AUTO,
{GGI_AUTO, GGI_AUTO}
};
ggi_color pal[PALENT];
ggi_pixel ppal[PALENT];
pal_fmt palf[PALENT];
FILE *fil_pal;
int nd = 0;
if((fil_pal = open(FIL_PAL_NAM, O_RDWR)) == -1) {
fprintf(stderr, "could not open file %s", FIL_PAL_NAM);
exit(1);
}
if (ggiInit() != 0) {
fprintf(stderr, "unable to init ggi\n");
return ERROR;
};
vis = ggiOpen(NULL);
if (vis == NULL) {
fprintf(stderr, "unable to open visible\n");
return ERROR;
};
ggiSetFlags(vis, GGIFLAG_ASYNC);
ggiCheckMode(vis, &mode);
ggiSetMode(vis, &mode);
read(fil_pal, &palf[0], PALENT*3);
close(fil_pal);
for(nd = 0; nd < PALENT; nd++) {
pal[nd].r = (uint16) palf[nd].r;
pal[nd].g = (uint16) palf[nd].g;
pal[nd].b = (uint16) palf[nd].b;
ppal[nd] = ggiMapColor(vis, &(pal[nd]));
fprintf(stderr, "color 0x%2X: palf: 0x%2X 0x%2X 0x%2X - pal: 0x%2X 0x%2X 0x%2X ---
ppal: 0x%2X\n",
nd,
palf[nd].r,
palf[nd].g,
palf[nd].b,
pal[nd].r,
pal[nd].g,
pal[nd].b,
ppal[nd]
);
}
ggiSetGCForeground(vis, ppal[0]);
ggiFillscreen(vis);
ggiFlush(vis);
for(nd = 0; nd < PALENT; nd++) {
ggiSetGCForeground(vis, ppal[nd]);
ggiDrawHLine(vis, 0, nd, 500);
}
ggiFlush(vis);
ggiGetc(vis);
ggiClose(vis);
ggiExit();
}