mirror of
https://github.com/deater/dos33fsprogs.git
synced 2024-11-01 01:06:33 +00:00
Update pcx2hgr to compile
This commit is contained in:
parent
1c016a8de7
commit
b10bc5746b
11
Makefile
11
Makefile
@ -3,7 +3,7 @@ CFLAGS = -O2 -Wall
|
||||
LFLAGS =
|
||||
|
||||
all: dos33 asoft_detoken mkdos33fs make_b tokenize_asoft \
|
||||
dos33_text2ascii integer_detoken char2hex
|
||||
dos33_text2ascii integer_detoken char2hex pcx2hgr
|
||||
|
||||
|
||||
|
||||
@ -25,6 +25,13 @@ tokenize_asoft: tokenize_asoft.o
|
||||
tokenize_asoft.o: tokenize_asoft.c
|
||||
$(CC) $(CFLAGS) -c tokenize_asoft.c
|
||||
|
||||
|
||||
pcx2hgr: pcx2hgr.o
|
||||
$(CC) $(LFLAGS) -o pcx2hgr pcx2hgr.o
|
||||
|
||||
pcx2hgr.o: pcx2hgr.c
|
||||
$(CC) $(CFLAGS) -c pcx2hgr.c
|
||||
|
||||
char2hex: char2hex.o
|
||||
$(CC) $(LFLAGS) -o char2hex char2hex.o
|
||||
|
||||
@ -61,5 +68,5 @@ install:
|
||||
cp dos33 asoft_detoken mkdos33fs tokenize_asoft make_b dos33_text2ascii integer_detoken /usr/local/bin
|
||||
|
||||
clean:
|
||||
rm -f *~ *.o asoft_detoken dos33 make_b mkdos33fs tokenize_asoft dos33_text2ascii integer_detoken char2hex
|
||||
rm -f *~ *.o asoft_detoken dos33 make_b mkdos33fs tokenize_asoft dos33_text2ascii integer_detoken char2hex pcx2hgr
|
||||
cd tests && make clean
|
||||
|
@ -1,37 +1,40 @@
|
||||
/* WARNING! These functions only work at 320x200x8bpp right now */
|
||||
/* Converts 280x160 8-bit PCX file with correct palette to Apple II HGR */
|
||||
|
||||
/* 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 <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 vmwGetPCXInfo(char *FileName, int *xsize, int *ysize, int *type) {
|
||||
#define PCX_UNKNOWN 0
|
||||
#define PCX_8BIT 1
|
||||
#define PCX_24BIT 2
|
||||
|
||||
int debug=1;
|
||||
|
||||
static 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;
|
||||
int result;
|
||||
|
||||
/* Open the file */
|
||||
pcx_fd=open(FileName,O_RDONLY);
|
||||
pcx_fd=open(filename,O_RDONLY);
|
||||
|
||||
if (pcx_fd<0) {
|
||||
printf("ERROR! File \"%s\" not found!\n",FileName);
|
||||
return VMW_ERROR_FILE;
|
||||
fprintf(stderr,"ERROR! File \"%s\" not found!\n",filename);
|
||||
return -1;
|
||||
}
|
||||
|
||||
lseek(pcx_fd,0,SEEK_SET);
|
||||
|
||||
read(pcx_fd,&pcx_header,128);
|
||||
|
||||
result=read(pcx_fd,&pcx_header,128);
|
||||
if (result<0) {
|
||||
fprintf(stderr,"Error! Could not read header from file %s\n",filename);
|
||||
return -1;
|
||||
}
|
||||
|
||||
xmin=(pcx_header[5]<<8)+pcx_header[4];
|
||||
ymin=(pcx_header[7]<<8)+pcx_header[6];
|
||||
|
||||
@ -75,13 +78,11 @@ int vmwGetPCXInfo(char *FileName, int *xsize, int *ysize, int *type) {
|
||||
|
||||
}
|
||||
|
||||
// *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 if (version==5) *type=PCX_8BIT;
|
||||
else *type=PCX_UNKNOWN;
|
||||
|
||||
close(pcx_fd);
|
||||
@ -89,27 +90,26 @@ int vmwGetPCXInfo(char *FileName, int *xsize, int *ysize, int *type) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int vmwLoadPCX(int x1,int y1,vmwVisual *target,
|
||||
int LoadPal,int LoadPic,char *FileName,
|
||||
vmwSVMWGraphState *graph_state)
|
||||
static int vmwLoadPCX(char *filename, unsigned char *framebuffer) {
|
||||
|
||||
{
|
||||
|
||||
int pcx_fd,x,y,i,numacross,xsize,ysize,xmin,ymin;
|
||||
int pcx_fd;
|
||||
/*
|
||||
int 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;
|
||||
|
||||
*/
|
||||
|
||||
/* Open the file */
|
||||
pcx_fd=open(FileName,O_RDONLY);
|
||||
pcx_fd=open(filename,O_RDONLY);
|
||||
|
||||
if (pcx_fd<0) {
|
||||
printf("ERROR! File \"%s\" not found!\n",FileName);
|
||||
return VMW_ERROR_FILE;
|
||||
fprintf(stderr,"ERROR! File \"%s\" not found!\n",filename);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
#if 0
|
||||
|
||||
/*************** DECODE THE HEADER *************************/
|
||||
read(pcx_fd,&pcx_header,128);
|
||||
@ -204,103 +204,28 @@ int vmwLoadPCX(int x1,int y1,vmwVisual *target,
|
||||
}
|
||||
vmwFlushPalette(graph_state);
|
||||
}
|
||||
|
||||
#endif
|
||||
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);
|
||||
}
|
||||
int main(int argc, char **argv) {
|
||||
|
||||
int xsize=0,ysize=0,type;
|
||||
unsigned char *framebuffer;
|
||||
|
||||
vmwGetPCXInfo("vince.pcx",&xsize,&ysize,&type);
|
||||
|
||||
framebuffer=calloc(xsize*ysize,sizeof(unsigned char));
|
||||
if (framebuffer==NULL) {
|
||||
fprintf(stderr,"Error allocating memory!\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
vmwLoadPCX("vince.pcx",framebuffer);
|
||||
|
||||
return 0;
|
||||
|
||||
close(pcx_fd);
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user