This commit is contained in:
Vince Weaver 2000-10-15 01:04:00 -04:00
parent 85a9115114
commit 299b372bdf
17 changed files with 624 additions and 50 deletions

View File

@ -1,3 +1,7 @@
15 October 2000
+ Added PCX Save/Load
+ Added NULL and NCURSES targets to svmwgraph. I must be insane.
6 October 2000
+ Fixed off-by-one error in paintpro 6.0 format, making a new 6.1 release
+ Made sure backwards compatability available

View File

@ -1,7 +1,7 @@
INCLUDE= -O2 -Wall -I/usr/local/include/SDL -I/usr/local/include
LIBS= -lSDL -lSDL_mixer -L/usr/X11R6/lib -lX11 -lpthread
LIBS= -lSDL -lSDL_mixer -L/usr/X11R6/lib -lX11 -lpthread -lncurses
all: tb1

1
quit.c
View File

@ -37,6 +37,7 @@ int quit(tb1_state *game_state)
}
if (barpos==0){
shutdownSound();
vmwCloseGraphics();
exit(1);
}
else return 6;

View File

@ -5,8 +5,8 @@ LIBS= -lSDL -lSDL_mixer -L/usr/X11R6/lib -lX11 -lpthread
all: libsvmwgraph.a
libsvmwgraph.a: vmw_core.o vmw_flip.o vmw_font.o vmw_paintpro.o vmw_palette.o vmw_setup.o vmw_sprite.o sdl_svmwgraph.o
ar cru libsvmwgraph.a vmw_core.o vmw_flip.o vmw_font.o vmw_paintpro.o vmw_palette.o vmw_setup.o vmw_sprite.o sdl_svmwgraph.o
libsvmwgraph.a: vmw_core.o vmw_flip.o vmw_font.o vmw_paintpro.o vmw_palette.o vmw_pcx.o vmw_setup.o vmw_sprite.o curses_svmwgraph.o null_svmwgraph.o sdl_svmwgraph.o
ar cru libsvmwgraph.a vmw_core.o vmw_flip.o vmw_font.o vmw_paintpro.o vmw_palette.o vmw_pcx.o vmw_setup.o vmw_sprite.o curses_svmwgraph.o null_svmwgraph.o sdl_svmwgraph.o
ranlib libsvmwgraph.a
vmw_core.o: vmw_core.c
@ -24,12 +24,21 @@ vmw_paintpro.o: vmw_paintpro.c
vmw_palette.o: vmw_palette.c
gcc $(INCLUDE) -c vmw_palette.c
vmw_pcx.o: vmw_pcx.c
gcc $(INCLUDE) -c vmw_pcx.c
vmw_setup.o: vmw_setup.c
gcc $(INCLUDE) -c vmw_setup.c
vmw_sprite.o: vmw_sprite.c
gcc $(INCLUDE) -c vmw_sprite.c
curses_svmwgraph.o: curses_svmwgraph.c
gcc $(INCLUDE) -c curses_svmwgraph.c
null_svmwgraph.o: null_svmwgraph.c
gcc $(INCLUDE) -c null_svmwgraph.c
sdl_svmwgraph.o: sdl_svmwgraph.c
gcc $(INCLUDE) -c sdl_svmwgraph.c

View File

@ -0,0 +1,201 @@
/* The SDL hooks for the Super VMW graphics library */
#include <stdio.h>
#include <unistd.h>
#include <ctype.h>
#include "ncurses.h"
#include "svmwgraph.h"
#include <stdlib.h> /* For atexit() */
typedef struct {
int color;
int bold;
char character;
} our_color_t;
our_color_t our_colors[256];
/* Setup the Graphics */
/* Pass '0' to auto-detect bpp */
void *curses_setupGraphics(int *xsize,int *ysize,int *bpp, int fullscreen,int verbose)
{
initscr();
start_color();
cbreak();
noecho();
nodelay(stdscr,TRUE);
nonl();
keypad(stdscr,TRUE);
init_pair(0,COLOR_BLACK,COLOR_BLACK);
init_pair(1,COLOR_BLUE,COLOR_BLACK);
init_pair(2,COLOR_GREEN,COLOR_BLACK);
init_pair(3,COLOR_CYAN,COLOR_BLACK);
init_pair(4,COLOR_RED,COLOR_BLACK);
init_pair(5,COLOR_MAGENTA,COLOR_BLACK);
init_pair(6,COLOR_YELLOW,COLOR_BLACK);
init_pair(7,COLOR_WHITE,COLOR_BLACK);
init_pair(8,COLOR_BLACK,COLOR_BLACK);
init_pair(9,COLOR_BLACK,COLOR_BLUE);
init_pair(10,COLOR_BLACK,COLOR_GREEN);
init_pair(11,COLOR_BLACK,COLOR_CYAN);
init_pair(12,COLOR_BLACK,COLOR_RED);
init_pair(13,COLOR_BLACK,COLOR_MAGENTA);
init_pair(14,COLOR_BLACK,COLOR_YELLOW);
init_pair(15,COLOR_BLACK,COLOR_WHITE);
return NULL;
}
void lookup_color(int r,int g,int b,int i) {
int bitmask;
if ((r<64) && (g<64) && (b<64)) {
our_colors[i].color=0;
our_colors[i].bold=0;
our_colors[i].character=' ';
return;
}
if ((r>64) && (g<64) && (b<64)) {
our_colors[i].color=12;
our_colors[i].bold=0;
our_colors[i].character=' ';
return;
}
if ((g>64) && (r<64) && (b<64)) {
our_colors[i].color=10;
our_colors[i].bold=0;
our_colors[i].character=' ';
return;
}
if ((b>64) && (r<64) && (g<64)) {
our_colors[i].color=9;
our_colors[i].bold=0;
our_colors[i].character=' ';
return;
}
if ((r>64) && (g>64) && (b<64)) {
our_colors[i].color=14;
our_colors[i].bold=0;
our_colors[i].character=' ';
return;
}
if ((r>64) && (b>64) && (g<64)) {
our_colors[i].color=13;
our_colors[i].bold=0;
our_colors[i].character=' ';
return;
}
if ((g>64) && (b>64) && (r<64)) {
our_colors[i].color=11;
our_colors[i].bold=0;
our_colors[i].character=' ';
return;
}
bitmask=0;
if (r>64) bitmask|=0x4;
if (g>64) bitmask|=0x2;
if (b>64) bitmask|=0x1;
our_colors[i].color=bitmask;
if ((r>128) &&
(g>128) &&
(b>128)) our_colors[i].bold=1;
else our_colors[i].bold=0;
our_colors[i].character='#';
return;
}
void curses_flushPalette(vmwSVMWGraphState *state) {
int i;
int r,g,b;
for(i=0;i<256;i++) {
r=(state->palette[i]>>11)<<3;
g=((state->palette[i]>>5)&0x3f)<<2;
b=(state->palette[i]&0x1f)<<3;
// printf("%i %i %i\n",r,g,b);
lookup_color(r,g,b,i);
}
}
void curses_BlitMem(vmwSVMWGraphState *target_p, vmwVisual *source) {
int x,y,temp_color;
unsigned char *s_pointer;
/* FILE *fff;
fff=fopen("temp.temp","w");
for (y=0;y<255;y++) {
fprintf(fff,"%i: %i %i\n",y,our_colors[y].color,our_colors[y].bold);
}
*/
move(0,0);
for (y=0;y<25;y++) {
s_pointer=source->memory+(y*8*320);
for(x=0;x<80;x++) {
//move(y,x);
temp_color=*(s_pointer);
if (our_colors[temp_color].bold)
attrset(COLOR_PAIR(our_colors[temp_color].color)|A_BOLD);
else
attrset(COLOR_PAIR(our_colors[temp_color].color)|A_NORMAL);
addch(our_colors[temp_color].character);
// printf("#");
s_pointer+=4;
}
}
}
void curses_clearKeyboardBuffer() {
// while(getch()!=ERR) usleep(100);
}
int curses_getInput() {
int ch;
ch=getch();
if (ch==ERR) return 0;
switch(ch) {
case KEY_BACKSPACE: return VMW_BACKSPACE;
case 27 : return VMW_ESCAPE;
case '\n' :
case '\r':
case KEY_ENTER : return VMW_ENTER;
case KEY_UP : return VMW_UP;
case KEY_DOWN : return VMW_DOWN;
case KEY_RIGHT : return VMW_RIGHT;
case KEY_LEFT : return VMW_LEFT;
case KEY_F(1) : return VMW_F1;
case KEY_F(2) : return VMW_F2;
case KEY_F(3) : return VMW_F3;
case KEY_PPAGE : return VMW_PGUP;
case KEY_NPAGE : return VMW_PGDN;
default: return ch;
}
return 0;
}
void curses_closeGraphics(void) {
clear();
refresh();
nocbreak();
echo();
endwin();
}

View File

@ -0,0 +1,6 @@
void *curses_setupGraphics(int *xsize,int *ysize,int *bpp, int fullscreen,int verbose);
void curses_flushPalette(vmwSVMWGraphState *state);
void curses_BlitMem(vmwSVMWGraphState *target_p, vmwVisual *source);
void curses_clearKeyboardBuffer();
int curses_getInput();
void curses_closeGraphics(void);

View File

@ -0,0 +1,32 @@
/* The NULL target, for when we don't have an actual output */
#include <stdio.h>
#include "svmwgraph.h"
void *null_setupGraphics(int *xsize,int *ysize,int *bpp,
int fullscreen,int verbose)
{
return NULL;
}
void null_flushPalette(vmwSVMWGraphState *state) {
}
void null_BlitMem(vmwSVMWGraphState *target_p, vmwVisual *source) {
}
void null_clearKeyboardBuffer() {
}
int null_getInput() {
return 0;
}
void null_closeGraphics() {
}

View File

@ -0,0 +1,10 @@
/* The NULL target, for when we don't have an actual output */
void *null_setupGraphics(int *xsize,int *ysize,int *bpp,
int fullscreen,int verbose);
void null_flushPalette(vmwSVMWGraphState *state);
void null_BlitMem(vmwSVMWGraphState *target_p, vmwVisual *source);
void null_clearKeyboardBuffer();
int null_getInput();
void null_closeGraphics();

View File

@ -50,7 +50,7 @@ void *SDL_setupGraphics(int *xsize,int *ysize,int *bpp,
}
void SDL_FlushPalette(vmwSVMWGraphState *state) {
void SDL_flushPalette(vmwSVMWGraphState *state) {
SDL_Surface *target;
SDL_Color temp_col[256];
@ -238,3 +238,6 @@ int SDL_getInput() {
}
return 0;
}
void SDL_closeGraphics() {
}

View File

@ -4,9 +4,10 @@
void *SDL_setupGraphics(int *xsize,int *ysize,int *bpp,int fullscreen,
int verbose);
void SDL_FlushPalette(vmwSVMWGraphState *state);
void SDL_flushPalette(vmwSVMWGraphState *state);
void SDL_NoScale16bpp_BlitMem(vmwSVMWGraphState *target, vmwVisual *source);
void SDL_Double16bpp_BlitMem(vmwSVMWGraphState *target_p, vmwVisual *source);
void SDL_NoScale8bpp_BlitMem(vmwSVMWGraphState *target, vmwVisual *source);
void SDL_clearKeyboardBuffer();
int SDL_getInput();
void SDL_closeGraphics();

View File

@ -49,7 +49,9 @@ typedef struct {
/* Constants */
/* Display Target Constants */
#define VMW_NULLTARGET 0
#define VMW_SDLTARGET 1
#define VMW_CURSESTARGET 2 /* Yes I am insane */
/* Error Constants */
@ -69,8 +71,9 @@ typedef struct {
#define VMW_LEFT 1029
#define VMW_F1 1030
#define VMW_F2 1031
#define VMW_PGUP 1032
#define VMW_PGDN 1033
#define VMW_F3 1032
#define VMW_PGUP 1050
#define VMW_PGDN 1051
/* Function declarations */
@ -123,6 +126,19 @@ void vmwLoadPalette(vmwSVMWGraphState *state,unsigned char r,
void vmwFadeToBlack(vmwSVMWGraphState *state,vmwVisual *source,int justLoadPal);
void vmwUnFade(vmwSVMWGraphState *state,vmwVisual *source);
/* From vmw_pcx.c */
int vmwLoadPCX(int x1,int y1,vmwVisual *target,
int LoadPal,int LoadPic,char *FileName,
vmwSVMWGraphState *graph_state);
int vmwSavePCX(int x1,int y1,int xsize,int ysize,
vmwVisual *source,
int num_colors,
vmw24BitPal *palette,
char *FileName);
/* From vmw_setup.c */
@ -137,6 +153,8 @@ vmwSVMWGraphState *vmwSetupSVMWGraph(int display_type,int xsize,int ysize,
int verbose);
vmwVisual *vmwSetupVisual(int xsize,int ysize);
extern void (*vmwCloseGraphics)(void);
/* From vmw_sprite.c */
vmwSprite *vmwGetSprite(int x, int y,

179
svmwgraph/vmw_pcx.c Normal file
View File

@ -0,0 +1,179 @@
/* WARNING! These functions only work at 320x200x8bpp right now */
/* It is easy to obtain the docs to make this load/save arbitrary */
/* PCX files. However, I don't have the time nor the inclination */
/* To do it right now ;) */
/* Routines to Load/Save PCX graphics files. */
#include "svmwgraph.h"
#include <stdio.h> /* For FILE I/O */
#include <string.h> /* For strncmp */
#include <fcntl.h> /* for open() */
#include <unistd.h> /* for lseek() */
#include <sys/stat.h> /* for file modes */
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;
unsigned char pcx_header[128];
unsigned char temp_byte;
/* 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;
}
read(pcx_fd,&pcx_header,128);
/* 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) {
x=0; y=0;
while (y<200) {
read(pcx_fd,&temp_byte,1);
if ((temp_byte>=192) && (temp_byte<=255)) {
numacross=temp_byte-192;
read(pcx_fd,&temp_byte,1);
vmwDrawHLine(x,y,numacross,temp_byte,target);
x+=numacross;
}
else {
vmwPutPixel(x,y,temp_byte,target);
x++;
}
if (x>319) {
x=0;
y++;
}
}
}
/*Load Palette*/
if (LoadPal) {
lseek(pcx_fd,-768,SEEK_END);
for(i=0;i<255;i++) {
read(pcx_fd,&r,1);
read(pcx_fd,&g,1);
read(pcx_fd,&b,1);
vmwLoadPalette(graph_state,
r,
g,
b,i);
}
vmwFlushPalette(graph_state);
}
close(pcx_fd);
return 0;
}
int vmwSavePCX(int x1,int y1,int xsize,int ysize,
vmwVisual *source,
int num_colors,
vmw24BitPal *palette,
char *FileName) {
int pcx_fd,x,y,oldcolor,color,numacross,i;
unsigned char *pcx_header;
unsigned char temp_byte;
pcx_fd=open(FileName,O_WRONLY|O_CREAT|O_TRUNC,S_IRUSR|S_IWUSR);
if (pcx_fd<0) {
printf("Error opening \"%s\" for writing!\n",FileName);
return VMW_ERROR_FILE;
}
pcx_header=calloc(1,128);
/* Faked from a proper 320x200x256 pcx created with TheGIMP */
/* and read with 'od -t x1 -N 128' */
/* Values verified from PCGPE .pcx documentation */
pcx_header[0]=0x0a; /* Manufacturer ID-- A=ZSoft .pcx */
pcx_header[1]=0x05; /* Version # */
pcx_header[2]=0x01; /* Encoding. 1=RLE */
pcx_header[3]=0x08; /* Bits Per Pixel */
pcx_header[8]=0x3f; /* 4-11 Window. XminXmin YminYmin XmaxXmax YmaxYmax*/
pcx_header[9]=0x01; /* Little Endian, so 0000 0000 013f 00c7= 319x199 */
pcx_header[10]=0xc7; /* " */
pcx_header[12]=0x2c; /* Horizontal DPI */
pcx_header[13]=0x01; /* " .. so 0x12c=300dpi */
pcx_header[14]=0x2c; /* Vertical DPI */
pcx_header[15]=0x01; /* " .. so 0x12c=300dpi */
pcx_header[65]=0x01; /* Number of color planes */
pcx_header[66]=0x40; /* bytes per line. */
pcx_header[67]=0x01; /* "" .. so 0x140=320 */
pcx_header[68]=0x01; /* Color Palette */
/* 128 byte PCX Header */
write(pcx_fd,pcx_header,128);
/* All we support right now */
xsize=320;
ysize=200;
y=y1;
x=x1;
numacross=1;
/* Set up initial conditions */
oldcolor=vmwGetPixel(x,y,source);
while (y<y1+ysize) {
color=vmwGetPixel(x,y,source);
if ( (color==oldcolor)&&(numacross<63)&&(x<(x1+xsize-1)) ) numacross++;
else { /* This pixel not the same color as previous */
// printf("G: %i,%i N=%i C=%i\n",x,y,numacross,color);
if ((numacross==1) && (oldcolor<192)) {
write(pcx_fd,&oldcolor,1);
}
else {
temp_byte=numacross+192;
write(pcx_fd,&temp_byte,1);
write(pcx_fd,&oldcolor,1);
numacross=1;
}
}
oldcolor=color;
x++;
if (x>=x1+xsize) {
x=0;
y++;
numacross=1;
// printf("%i %i %i\n",x,y,numacross);
// fflush(stdout);
}
}
/* Urgh obscure */
temp_byte=12;
write(pcx_fd,&temp_byte,1);
/* Write num_colors r,g,b */
for(i=0;i<256;i++) {
temp_byte=palette[i].r;
write(pcx_fd,&temp_byte,1);
temp_byte=palette[i].g;
write(pcx_fd,&temp_byte,1);
temp_byte=palette[i].b;
write(pcx_fd,&temp_byte,1);
}
close(pcx_fd);
return 0;
}

View File

@ -2,6 +2,8 @@
#include "svmwgraph.h"
#include "sdl_svmwgraph.h" /* Make this dynamic somehow? */
#include "null_svmwgraph.h"
#include "curses_svmwgraph.h"
#include <stdio.h> /* For printf */
#include <stdlib.h> /* For Memory Allocation */
@ -13,6 +15,7 @@ void (*vmwFlushPalette)(vmwSVMWGraphState *state);
void (*vmwClearKeyboardBuffer)(void);
int (*vmwGetInput)(void);
void (*vmwCloseGraphics)(void);
vmwSVMWGraphState *vmwSetupSVMWGraph(int display_type,int xsize,int ysize,
int bpp,int scale,int fullscreen,
@ -26,8 +29,12 @@ vmwSVMWGraphState *vmwSetupSVMWGraph(int display_type,int xsize,int ysize,
}
/* Setup Setup routines */
switch (display_type) {
case VMW_SDLTARGET: vmwSetupGraphics=SDL_setupGraphics;
break;
case VMW_NULLTARGET: vmwSetupGraphics=null_setupGraphics;
break;
case VMW_CURSESTARGET: vmwSetupGraphics=curses_setupGraphics;
break;
case VMW_SDLTARGET: vmwSetupGraphics=SDL_setupGraphics;
break;
default: printf("ERROR! Unknown Display Target %i.\n",display_type);
return NULL;
}
@ -52,11 +59,25 @@ vmwSVMWGraphState *vmwSetupSVMWGraph(int display_type,int xsize,int ysize,
/* Attempt to get desired graphics state */
temp_state->output_screen=vmwSetupGraphics(&temp_state->xsize,
&temp_state->ysize,
&temp_state->bpp,
fullscreen,verbose);
&temp_state->ysize,
&temp_state->bpp,
fullscreen,verbose);
/* Setup proper blitter and others*/
switch (display_type) {
case VMW_NULLTARGET:
vmwFlushPalette=null_flushPalette;
vmwClearKeyboardBuffer=null_clearKeyboardBuffer;
vmwBlitMemToDisplay=null_BlitMem;
vmwGetInput=null_getInput;
vmwCloseGraphics=null_closeGraphics;
break;
case VMW_CURSESTARGET:
vmwFlushPalette=curses_flushPalette;
vmwClearKeyboardBuffer=curses_clearKeyboardBuffer;
vmwBlitMemToDisplay=curses_BlitMem;
vmwGetInput=curses_getInput;
vmwCloseGraphics=curses_closeGraphics;
break;
case VMW_SDLTARGET:
if (temp_state->bpp==8) {
vmwBlitMemToDisplay=SDL_NoScale8bpp_BlitMem;
@ -68,16 +89,15 @@ vmwSVMWGraphState *vmwSetupSVMWGraph(int display_type,int xsize,int ysize,
vmwBlitMemToDisplay=SDL_Double16bpp_BlitMem;
}
}
vmwFlushPalette=SDL_FlushPalette;
vmwFlushPalette=SDL_flushPalette;
vmwClearKeyboardBuffer=SDL_clearKeyboardBuffer;
vmwGetInput=SDL_getInput;
vmwCloseGraphics=SDL_closeGraphics;
break;
default: printf("ERROR! Unknown Display Target %i.\n",display_type);
return NULL;
}
return temp_state;
}

2
tb1.c
View File

@ -216,7 +216,7 @@ int main(int argc,char **argv)
if (scale==1) {
if ( (game_state->graph_state=
vmwSetupSVMWGraph(VMW_SDLTARGET,
vmwSetupSVMWGraph(VMW_CURSESTARGET,
320,200,
0,scale,fullscreen,1))==NULL) {
fprintf(stderr,"ERROR: Couldn't get display set up properly.\n");

View File

@ -1,18 +1,24 @@
INCLUDE= -O2 -Wall -I/usr/local/include/SDL -I/usr/local/include -I..
LIBS= -lSDL -L/usr/X11R6/lib -lX11 -lpthread
LIBS= -lSDL -L/usr/X11R6/lib -lX11 -lpthread -lncurses
all: ppro_view
all: ppro_view pcx2ppp
ppro_view: ppro_view.o ../svmwgraph/libsvmwgraph.a
gcc -o ppro_view ppro_view.o ../svmwgraph/libsvmwgraph.a $(LIBS)
pcx2ppp: pcx2ppp.o ../svmwgraph/libsvmwgraph.a
gcc -o pcx2ppp pcx2ppp.o ../svmwgraph/libsvmwgraph.a $(LIBS)
../svmwgraph/libsvmwgraph.a:
cd ../svmwgraph && make
pcx2ppp.o: pcx2ppp.c
gcc -c pcx2ppp.c $(INCLUDE)
ppro_view.o: ppro_view.c
gcc -c ppro_view.c $(INCLUDE)
clean:
rm -f ppro_view *.o *~
rm -f ppro_view pcx2ppp *.o *~

View File

@ -0,0 +1,54 @@
/* Views paintpro files */
/* Also will re-save them */
#include <stdio.h>
#include "svmwgraph/svmwgraph.h"
#include <string.h> /* for strdup */
#include <unistd.h> /* for usleep() */
int main(int argc,char **argv)
{
int grapherror;
int scale=1,fullscreen=0;
vmwVisual *virtual_1;
char *filename,*outfile;
vmwSVMWGraphState *graph_state;
if (argc<3) {
printf("\nUsage: %s pcx_file ppro_file\n\n",argv[0]);
return -1;
}
filename=strdup(argv[1]);
outfile=strdup(argv[2]);
/* Setup Graphics */
if ( (graph_state=vmwSetupSVMWGraph(VMW_NULLTARGET,
320,
200,
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(320,
200))==NULL) {
fprintf(stderr,"ERROR: Couldn't get RAM for virtual screen 1!\n");
return VMW_ERROR_MEM;
}
/* Load palette */
grapherror=vmwLoadPCX(0,0,virtual_1,1,1,
filename,
graph_state);
vmwSavePicPacked(0,0,320,200,virtual_1,
graph_state->palette_size,
graph_state->actual_pal,outfile);
return 0;
}

View File

@ -15,6 +15,9 @@ int main(int argc,char **argv)
char *filename;
char ch=0;
char save_string[BUFSIZ];
char *extension,*temp_string1,*temp_string2;
int xsize,ysize;
int is_pcx=0;
vmwSVMWGraphState *graph_state;
@ -24,52 +27,71 @@ int main(int argc,char **argv)
}
filename=strdup(argv[1]);
ppro_header=vmwGetPaintProHeader(filename);
printf("\nLoading file: %s\n",filename);
if (strncmp(ppro_header->ppro_string,"PAINTPRO",8)) {
printf("ERROR! Not in paintpro format!\n");
return 0;
/* Hacky way to grab the extension. I am sure this is a cleaner way */
temp_string1=strdup(filename);
temp_string2=strtok(temp_string1,".");
extension=temp_string2;
while( ( temp_string2=strtok(NULL,"."))!=NULL)
extension=temp_string2;
if (!strncmp(extension,"pcx",4)) {
printf("\nAttempting to load %s as a 320x200x8bpp PCX file\n",filename);
xsize=320; ysize=200;
is_pcx=1;
}
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);
else { /* We assume paintpro file */
ppro_header=vmwGetPaintProHeader(filename);
printf("\nLoading file: %s\n",filename);
if (strncmp(ppro_header->ppro_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;
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(VMW_SDLTARGET,
ppro_header->xsize,
ppro_header->ysize,
0,scale,fullscreen,1))==NULL) {
if ( (graph_state=vmwSetupSVMWGraph(VMW_CURSESTARGET,
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(ppro_header->xsize,
ppro_header->ysize))==NULL) {
if ((virtual_1=vmwSetupVisual(xsize,ysize))==NULL) {
fprintf(stderr,"ERROR: Couldn't get RAM for virtual screen 1!\n");
return VMW_ERROR_MEM;
}
/* Load palette */
grapherror=vmwLoadPicPacked(0,0,virtual_1,1,1,
filename,
graph_state);
if (is_pcx) {
grapherror=vmwLoadPCX(0,0,virtual_1,1,1,filename,graph_state);
}
else { /* Paintpro */
grapherror=vmwLoadPicPacked(0,0,virtual_1,1,1,
filename,
graph_state);
}
vmwBlitMemToDisplay(graph_state,virtual_1);
while ((ch!='Q') && (ch!='q') && (ch!=VMW_ESCAPE)) {
@ -83,7 +105,15 @@ int main(int argc,char **argv)
graph_state->actual_pal,save_string);
}
if (ch=='p') {
printf("\nEnter file name to save .pcx as:\n");
scanf("%s",save_string);
vmwSavePCX(0,0,320,200,virtual_1,
graph_state->palette_size,
graph_state->actual_pal,save_string);
}
}
vmwCloseGraphics();
return 0;
}