diff --git a/CHANGES b/CHANGES index 6f51610..9bcc015 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,10 @@ +27 October 2004 ++ Of course instead of finishing things up, used the library to display + pcx files so I can give presentations using an old 486 laptop. + (Convert pdf's which are slow to display to 8-bit 640x480 .pcx files + which render plenty fast on a 75MHz 486). + + 29 Septemer 2004 + Backed out the half-baked "generalized level 2" changes. They made things 10 times as complicated for no good reason. Pre-mature diff --git a/Makefile b/Makefile index e99dd40..7247f06 100644 --- a/Makefile +++ b/Makefile @@ -74,3 +74,4 @@ tblib.o: tblib.c clean: rm -f tb1 *.o *~ cd svmwgraph && make clean + cd tools && make clean diff --git a/svmwgraph/svmwgraph.h b/svmwgraph/svmwgraph.h index 7730527..698f410 100644 --- a/svmwgraph/svmwgraph.h +++ b/svmwgraph/svmwgraph.h @@ -132,6 +132,12 @@ void vmwUnFade(vmwSVMWGraphState *state,vmwVisual *source); /* From vmw_pcx.c */ + +#define PCX_UNKNOWN 0 +#define PCX_8BITPAL 1 +#define PCX_24BIT 2 + +int vmwGetPCXInfo(char *FileName, int *xsize, int *ysize, int *type); int vmwLoadPCX(int x1,int y1,vmwVisual *target, int LoadPal,int LoadPic,char *FileName, vmwSVMWGraphState *graph_state); diff --git a/svmwgraph/vmw_pcx.c b/svmwgraph/vmw_pcx.c index 696e2a1..4079b8c 100644 --- a/svmwgraph/vmw_pcx.c +++ b/svmwgraph/vmw_pcx.c @@ -15,13 +15,89 @@ #include /* for file modes */ +int vmwGetPCXInfo(char *FileName, int *xsize, int *ysize, int *type) { + + unsigned char pcx_header[128]; + int xmin,ymin,xmax,ymax,version=PCX_UNKNOWN,bpp,debug=1,pcx_fd; + + /* Open the file */ + pcx_fd=open(FileName,O_RDONLY); + + if (pcx_fd<0) { + printf("ERROR! File \"%s\" not found!\n",FileName); + return VMW_ERROR_FILE; + } + + lseek(pcx_fd,0,SEEK_SET); + + read(pcx_fd,&pcx_header,128); + + xmin=(pcx_header[5]<<8)+pcx_header[4]; + ymin=(pcx_header[7]<<8)+pcx_header[6]; + + xmax=(pcx_header[9]<<8)+pcx_header[8]; + ymax=(pcx_header[11]<<8)+pcx_header[10]; + + version=pcx_header[1]; + bpp=pcx_header[3]; + + if (debug) { + + printf("Manufacturer: "); + if (pcx_header[0]==10) printf("Zsoft\n"); + else printf("Unknown %i\n",pcx_header[0]); + + printf("Version: "); + + switch(version) { + case 0: printf("2.5\n"); break; + case 2: printf("2.8 w palette\n"); break; + case 3: printf("2.8 w/o palette\n"); break; + case 4: printf("Paintbrush for Windows\n"); break; + case 5: printf("3.0+\n"); break; + default: printf("Unknown %i\n",version); + } + printf("Encoding: "); + if (pcx_header[2]==1) printf("RLE\n"); + else printf("Unknown %i\n",pcx_header[2]); + + printf("BitsPerPixelPerPlane: %i\n",bpp); + printf("File goes from %i,%i to %i,%i\n",xmin,ymin,xmax,ymax); + + printf("Horizontal DPI: %i\n",(pcx_header[13]<<8)+pcx_header[12]); + printf("Vertical DPI: %i\n",(pcx_header[15]<<8)+pcx_header[14]); + + printf("Number of colored planes: %i\n",pcx_header[65]); + printf("Bytes per line: %i\n",(pcx_header[67]<<8)+pcx_header[66]); + printf("Palette Type: %i\n",(pcx_header[69]<<8)+pcx_header[68]); + printf("Hscreen Size: %i\n",(pcx_header[71]<<8)+pcx_header[70]); + printf("Vscreen Size: %i\n",(pcx_header[73]<<8)+pcx_header[72]); + + } + +// *xsize=(xmax-xmin+1); +// *ysize=(ymax-ymin+1); + *xsize=(xmax-xmin+1); + *ysize=(ymax-ymin+1); + + if ((version==5) && (bpp==8) && (pcx_header[65]==3)) *type=PCX_24BIT; + else if (version==5) *type=PCX_8BITPAL; + else *type=PCX_UNKNOWN; + + close(pcx_fd); + + return 0; +} + int vmwLoadPCX(int x1,int y1,vmwVisual *target, int LoadPal,int LoadPic,char *FileName, vmwSVMWGraphState *graph_state) { - int pcx_fd,x,y,i,r,g,b,numacross,xsize,ysize; + int pcx_fd,x,y,i,numacross,xsize,ysize,xmin,ymin; + unsigned int r,g,b; + int bpp,planes,bpl,xmax,ymax,version; unsigned char pcx_header[128]; unsigned char temp_byte; @@ -33,51 +109,98 @@ int vmwLoadPCX(int x1,int y1,vmwVisual *target, return VMW_ERROR_FILE; } - read(pcx_fd,&pcx_header,128); - xsize=(pcx_header[9]<<8)+pcx_header[8]; - ysize=(pcx_header[11]<<8)+pcx_header[10]; - printf("Loading %ix%i pcx file\n",xsize,ysize); + + /*************** DECODE THE HEADER *************************/ + read(pcx_fd,&pcx_header,128); + + xmin=(pcx_header[5]<<8)+pcx_header[4]; + ymin=(pcx_header[7]<<8)+pcx_header[6]; + + xmax=(pcx_header[9]<<8)+pcx_header[8]; + ymax=(pcx_header[11]<<8)+pcx_header[10]; + + version=pcx_header[1]; + bpp=pcx_header[3]; + planes=pcx_header[65]; + bpl=(pcx_header[67]<<8)+pcx_header[66]; + + xsize=((xmax-xmin)+1); + ysize=((ymax-ymin)+1); /* Possibly add some sanity checking in the header at some point... */ /* Or actually even get the proper VALUES from the header. Some day... */ if (LoadPic) { - + + + unsigned char *pointer=target->memory; + x=0; y=0; - while (y=192) && (temp_byte<=255)) { - numacross=temp_byte-192; + if (0xc0 == (temp_byte&0xc0)) { + numacross=temp_byte&0x3f; read(pcx_fd,&temp_byte,1); - vmwDrawHLine(x,y,numacross,temp_byte,target); - x+=numacross; +// y++; if (y%2) temp_byte=0xff; +// temp_byte=0xff; +// printf("%i pixels of %i\n",numacross,temp_byte); + for(i=0;ixsize) { - x=0; - y++; - } + /* why is this needed? */ + if (x%xsize==0) { + pointer++; + } + + //printf("WARNING! X=%i\n",x); +// x=0; +// y++; + // } } } /*Load Palette*/ if (LoadPal) { - lseek(pcx_fd,-768,SEEK_END); + lseek(pcx_fd,-769,SEEK_END); + read(pcx_fd,&temp_byte,1); + if (temp_byte!=12) { + printf("Error! No palette found!\n"); + } + else + for(i=0;i<255;i++) { - read(pcx_fd,&r,1); - read(pcx_fd,&g,1); - read(pcx_fd,&b,1); + read(pcx_fd,&temp_byte,1); + r=temp_byte; + read(pcx_fd,&temp_byte,1); + g=temp_byte; + read(pcx_fd,&temp_byte,1); + b=temp_byte; vmwLoadPalette(graph_state, r, g, b,i); + // printf("%i: 0x%x %x %x\n",i,r,g,b); } vmwFlushPalette(graph_state); } diff --git a/tools/Makefile b/tools/Makefile index e330bb4..7c0d104 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -3,34 +3,40 @@ include ../Makefile.inc INCLUDE= $(INCLUDE_GLOBAL) -I../svmwgraph LIBS= $(LIBS_GLOBAL) -all: ppro_view pcx2ppp level2_editor +all: ppro_view pcx2ppp level2_editor pcx_slideshow level2_editor: level2_editor.o ../svmwgraph/libsvmwgraph.a - gcc -o level2_editor level2_editor.o ../svmwgraph/libsvmwgraph.a $(LIBS) + $(CC) -o level2_editor level2_editor.o ../svmwgraph/libsvmwgraph.a $(LIBS) benchmark: benchmark.o ../svmwgraph/libsvmwgraph.a - gcc -o benchmark benchmark.o ../svmwgraph/libsvmwgraph.a $(LIBS) + $(CC) -o benchmark benchmark.o ../svmwgraph/libsvmwgraph.a $(LIBS) ppro_view: ppro_view.o ../svmwgraph/libsvmwgraph.a - gcc -o ppro_view ppro_view.o ../svmwgraph/libsvmwgraph.a $(LIBS) + $(CC) -o ppro_view ppro_view.o ../svmwgraph/libsvmwgraph.a $(LIBS) + +pcx_slideshow: pcx_slideshow.o ../svmwgraph/libsvmwgraph.a + $(CC) -o pcx_slideshow pcx_slideshow.o ../svmwgraph/libsvmwgraph.a $(LIBS) pcx2ppp: pcx2ppp.o ../svmwgraph/libsvmwgraph.a - gcc -o pcx2ppp pcx2ppp.o ../svmwgraph/libsvmwgraph.a $(LIBS) + $(CC) -o pcx2ppp pcx2ppp.o ../svmwgraph/libsvmwgraph.a $(LIBS) ../svmwgraph/libsvmwgraph.a: cd ../svmwgraph && make level2_editor.o: level2_editor.c - gcc -c level2_editor.c $(INCLUDE) + $(CC) -c level2_editor.c $(INCLUDE) benchmark.o: benchmark.c - gcc -c benchmark.c $(INCLUDE) + $(CC) -c benchmark.c $(INCLUDE) pcx2ppp.o: pcx2ppp.c - gcc -c pcx2ppp.c $(INCLUDE) + $(CC) -c pcx2ppp.c $(INCLUDE) ppro_view.o: ppro_view.c - gcc -c ppro_view.c $(INCLUDE) + $(CC) -c ppro_view.c $(INCLUDE) + +pcx_slideshow.o: pcx_slideshow.c + $(CC) -c pcx_slideshow.c $(INCLUDE) clean: - rm -f ppro_view pcx2ppp benchmark level2_editor *.o *~ + rm -f pcx_slideshow ppro_view pcx2ppp benchmark level2_editor *.o *~ diff --git a/tools/pcx_slideshow.c b/tools/pcx_slideshow.c new file mode 100644 index 0000000..8f92655 --- /dev/null +++ b/tools/pcx_slideshow.c @@ -0,0 +1,125 @@ +/* Views paintpro files */ +/* Also will re-save them */ + +#include +#include /* for strdup */ +#include /* for usleep() */ +#include /* for exit() */ + +#include "svmwgraph.h" + + +int main(int argc,char **argv) +{ + int grapherror; + int scale=1,fullscreen=0; + vmwVisual *virtual_1; + vmwPaintProHeader *ppro_header; + char *filename; + char ch=0; + char save_string[BUFSIZ]; + char *extension,*temp_string1,*temp_string2; + int xsize,ysize,type; + int is_pcx=0,target=VMW_SDLTARGET; + int whichfile; + + vmwSVMWGraphState *graph_state; + + + if (argc<2) { + printf("\nUsage: %s filename ...\n\n",argv[0]); + return -1; + } + + whichfile=1; + + while(whichfileppro_string,"PAINTPRO",8)) { + printf("ERROR! Not in paintpro format!\n"); + return 0; + } + if (strncmp(ppro_header->version,"V6.",3)) { + printf("ERROR! Not a version 6.x file!\n"); + return 0; + } + printf(" + Verified PaintPro v%c.%c file.\n",ppro_header->version[1], + ppro_header->version[3]); + printf(" + Picture is %ix%i with %i colors.\n", + ppro_header->xsize,ppro_header->ysize,ppro_header->num_colors); + + + if (ppro_header->version[3]=='0') { + /* broken ppro 6.0 files sometimes were saved as 319x199 */ + ppro_header->xsize=320; + ppro_header->ysize=205; + } + xsize=ppro_header->xsize; + ysize=ppro_header->ysize; + } + + /* Setup Graphics */ + + if ( (graph_state=vmwSetupSVMWGraph(target, + xsize, + ysize, + 0,scale,fullscreen,1))==NULL) { + fprintf(stderr,"ERROR: Couldn't get display set up properly.\n"); + return VMW_ERROR_DISPLAY; + } + + /* Allocate Virtual screen */ + if ((virtual_1=vmwSetupVisual(xsize,ysize))==NULL) { + fprintf(stderr,"ERROR: Couldn't get RAM for virtual screen 1!\n"); + return VMW_ERROR_MEM; + } + + if (is_pcx) { + grapherror=vmwLoadPCX(0,0,virtual_1,1,1,argv[whichfile],graph_state); + } + else { /* Paintpro */ + grapherror=vmwLoadPicPacked(0,0,virtual_1,1,1, + argv[whichfile], + graph_state); + } + + vmwBlitMemToDisplay(graph_state,virtual_1); + + + while ( (ch=vmwGetInput())==0) usleep(100); + + if ((ch=='Q') || (ch=='q') || (ch==VMW_ESCAPE)) break; + + whichfile++; + if (whichfile>=argc) whichfile=1; + } + + + vmwCloseGraphics(); + return 0; +}