From: halfwolf (halfwolf@imneverwrong.com)
Date: Thu 14 Dec 2000 - 16:52:18 IST
Hey ! I have a program that draws pcx files on the screen (With svgalib -> svgalib.org).I want to make a color transparent.Is this possible ? Are there any tutorials/examples for this ? Well , here is the source code of the program that loads pcx files. #include <stdio.h> #include <unistd.h> #include <vga.h> #include <vgagl.h> #include <vgakeyboard.h> #include <stdlib.h> #include <string.h> // Structures typedef struct { char signature; char version; char encoding; char bytes_per_pixel; unsigned short int xmin; unsigned short int ymin; unsigned short int xmax; unsigned short int ymax; unsigned short int vres; unsigned short int hres; char palette[48]; char reserved; char color_layers; unsigned short int bytes_per_line; unsigned short int palette_type; char unused[58]; } PCX_Header; // Prototyping void *readpcx (FILE *file,char *palette,unsigned short int *length,unsigned short int *height); void init_svgalib (GraphicsContext *gc); void init_svgalib (GraphicsContext *physicalscreen); void init_svgalib (GraphicsContext *virtualscreen); void exit_svgalib(); void prepare_font(void); // Globals GraphicsContext *physicalscreen; GraphicsContext *virtualscreen; int main(void) { FILE *file; void *image; int i; char ch; unsigned short int length, height; unsigned char palette[768]; int x; char *keymap; int i2, j, b, y, c; if ((file=fopen("thepcxfile.pcx","r"))==NULL) { printf("Can't open file! frank\n"); } if ((image=readpcx(file,palette,&length,&height))==NULL) { printf ("File load failure.\n"); } fclose (file); vga_init(); vga_setmode(5); gl_setcontextvga(5); physicalscreen = gl_allocatecontext(); gl_setcontextvgavirtual(5); virtualscreen = gl_allocatecontext(); init_svgalib (virtualscreen); printf("Image is %dx%d sized.\n",length,height); if ((length>320) || (height>200)) { printf ("Image is too big!\n"); exit (1); } keyboard_init(); // Enter main loop while( 1 ) { keyboard_update(); if(keyboard_keypressed(SCANCODE_ESCAPE)) { vga_setmode(0); exit_svgalib(); keyboard_close(); return(0); } gl_putbox(0,0,40,30,image); gl_copyscreen(virtualscreen); vga_waitretrace(); } return (0); } void readpcximage(FILE * file,void * target,int size) { unsigned char buf; unsigned int counter; int i=1; while (i <= size) { fread(&buf,1,1,file); if ((buf&192)==192) { counter=(buf&63); fread(&buf,1,1,file); for(;counter>0;counter--) { ((char*)target)[i]=buf; i++; if (i >= size) break; } } else { ((char*)target)[i]=buf; i++; } } } void *readpcx(FILE *file, char *palette,unsigned short int *length, unsigned short int *height) { PCX_Header header; void *target; fseek(file,0,SEEK_SET); fread(&header,sizeof(PCX_Header),1,file); *length=header.xmax+1-header.xmin; *height=header.ymax+1-header.ymin; if((header.signature!=0x0a)||(header.version!=5)) return(NULL); else { target=(void *)malloc((*length)*(*height)); readpcximage(file,target,(*length)*(*height)); fseek(file,-768,SEEK_END); fread(palette,6,768,file); return(target); } } void init_svgalib (GraphicsContext *gc) { if (vga_init()!=0) { printf("Error initialising svgalib!\n"); exit(1); } if (vga_setmode(G320x200x256)!=0) { printf("Can't set mode 320x200x256!\n"); exit(1); } if (gl_setcontextvga(G320x200x256)!=0) { printf("Error setting context!\n"); exit(1); } gl_getcontext(gc); if (gl_setcontextvgavirtual(G320x200x256)!=0) { printf("Error setting virtual context!\n"); exit(1); } } void exit_svgalib() { vga_setmode(TEXT); } _____________________________________________ Free email with personality! Over 200 domains! http://www.MyOwnEmail.com ------------------------------------------------------------------ Unsubscribe: To: listbot@svgalib.org Body: unsubscribe linux-svgalib
This archive was generated by hypermail 2.1.4 : Wed 21 Jan 2004 - 22:10:23 IST