tb1/tb1_linux/tools/ppro_view.c

127 lines
3.5 KiB
C
Raw Normal View History

2000-10-07 06:39:00 +00:00
/* Views paintpro files */
/* Also will re-save them */
#include <stdio.h>
2000-10-28 02:09:00 +00:00
#include "svmwgraph.h"
2000-10-07 06:39:00 +00:00
#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;
vmwPaintProHeader *ppro_header;
char *filename;
char ch=0;
char save_string[BUFSIZ];
2000-10-15 05:04:00 +00:00
char *extension,*temp_string1,*temp_string2;
int xsize,ysize;
2000-10-28 02:09:00 +00:00
int is_pcx=0,target=VMW_SDLTARGET;
2000-10-07 06:39:00 +00:00
vmwSVMWGraphState *graph_state;
2000-10-28 02:09:00 +00:00
printf("HI %i\n\n",argc);
2000-10-07 06:39:00 +00:00
if (argc<2) {
2000-10-28 02:09:00 +00:00
printf("\nUsage: [-curses] %s filename\n\n",argv[0]);
2000-10-07 06:39:00 +00:00
return -1;
}
2000-10-28 02:09:00 +00:00
filename=strdup(argv[argc-1]);
if (!strncmp(argv[1],"-curses",10)) {
target=VMW_CURSESTARGET;
}
2000-10-07 06:39:00 +00:00
2000-10-15 05:04:00 +00:00
/* 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;
2000-10-07 06:39:00 +00:00
}
2000-10-15 05:04:00 +00:00
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);
2000-10-07 06:39:00 +00:00
2000-10-15 05:04:00 +00:00
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;
2000-10-07 06:39:00 +00:00
}
2000-10-15 05:04:00 +00:00
2000-10-07 06:39:00 +00:00
/* Setup Graphics */
2000-10-28 02:09:00 +00:00
if ( (graph_state=vmwSetupSVMWGraph(target,
2000-10-15 05:04:00 +00:00
xsize,
ysize,
0,scale,fullscreen,1))==NULL) {
2000-10-07 06:39:00 +00:00
fprintf(stderr,"ERROR: Couldn't get display set up properly.\n");
return VMW_ERROR_DISPLAY;
}
/* Allocate Virtual screen */
2000-10-15 05:04:00 +00:00
if ((virtual_1=vmwSetupVisual(xsize,ysize))==NULL) {
2000-10-07 06:39:00 +00:00
fprintf(stderr,"ERROR: Couldn't get RAM for virtual screen 1!\n");
return VMW_ERROR_MEM;
}
2000-10-15 05:04:00 +00:00
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);
}
2000-10-07 06:39:00 +00:00
vmwBlitMemToDisplay(graph_state,virtual_1);
while ((ch!='Q') && (ch!='q') && (ch!=VMW_ESCAPE)) {
while ( (ch=vmwGetInput())==0) usleep(100);
if (ch=='s') {
printf("\nEnter file name to save as:\n");
scanf("%s",save_string);
vmwSavePicPacked(0,0,320,200,virtual_1,
graph_state->palette_size,
graph_state->actual_pal,save_string);
}
2000-10-15 05:04:00 +00:00
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);
}
2000-10-07 06:39:00 +00:00
}
2000-10-15 05:04:00 +00:00
vmwCloseGraphics();
2000-10-07 06:39:00 +00:00
return 0;
}