home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
DOS/V Power Report 1997 March
/
VPR9703A.ISO
/
VPR_DATA
/
DOGA
/
SOURCES
/
REND.LZH
/
PIC1600
/
FILE.C
< prev
next >
Wrap
C/C++ Source or Header
|
1996-07-16
|
3KB
|
146 lines
#include <stdio.h>
#include <stdlib.h>
#ifdef X68K
#include <doslib.h>
#endif
#include <ctype.h>
#include <string.h>
#include "piclib.h"
#ifndef SEEK_SET
#define SEEK_SET 0
#endif
extern PicFunction PicFunction_16_16;
extern PicFunction PicFunction_25_7;
extern PicFunction PicFunction_RGB888;
extern PicFunction PicFunction_RGBT8888;
extern PicFunction PicFunction_PIC;
extern PicFunction PicFunction_BMP;
#ifdef X68K
extern PicFunction PicFunction_Display;
#endif
PicFunction *function[] = {
#ifdef X68K
&PicFunction_Display,
#endif
&PicFunction_16_16,
&PicFunction_25_7,
&PicFunction_RGB888,
&PicFunction_RGBT8888,
&PicFunction_PIC,
&PicFunction_BMP,
};
INLINE void putlong(int i, FILE *fp)
{
fputc( i >> 24 , fp);
fputc((i >> 16) & 0xff, fp);
fputc((i >> 8) & 0xff, fp);
fputc( i & 0xff, fp);
}
PicData *PicWriteOpen(char *filename, int sizex, int sizey, int mode)
{
PicData *pd;
FILE *fp;
int i;
char *ext;
if ((ext = strrchr(filename, '.')) == NULL) {
ext = filename + strlen(filename);
} else {
ext++;
}
if (pd = malloc(sizeof(PicData)), pd == NULL) {
return NULL;
}
pd->flag = PIC_WRITE;
pd->pixelX = (unsigned short)sizex;
pd->pixelY = (unsigned short)sizey;
strcpy(pd->filename, filename);
pd->func = NULL;
#ifdef X68K
if (strncmp(filename, "_DISPLAY_", 9) == 0) {
pd->func = &PicFunction_Display;
pd->func->PicOpen(pd, NULL, mode);
return pd;
}
#endif
if (fp = fopen(filename, "wb"), fp == NULL) {
free(pd);
return FALSE;
}
for (i = 0; i < (sizeof(function)/sizeof(function[0])); ++i) {
/* if (function[i]->ext[0] && strcmpi(function[i]->ext, ext) == 0) {*/
if (function[i]->ext[0]) {
char *pext, fext[8];
int j;
pext = function[i]->ext;
j = 0;
while (1) {
if (*pext == '\0' || *pext == '|') {
fext[j] = '\0';
if (fext[0]
&& toupper(fext[0]) == toupper(ext[0])
&& toupper(fext[1]) == toupper(ext[1])
&& (ext[1] == '\0' || toupper(fext[2]) == toupper(ext[2]))) {
pd->func = function[i];
break;
}
j = 0;
if (*pext == '\0') break;
} else {
fext[j++] = *pext;
}
pext++;
}
if (pd->func != NULL) break;
}
}
if (pd->func == NULL) {
free(pd);
return FALSE;
}
pd->func->PicOpen(pd, fp, mode);
return pd;
}
PicData *PicReadOpen(char *filename)
{
FILE *fp;
PicData *pd;
int i;
unsigned char magic[32];
if (pd = malloc(sizeof(PicData)), pd == NULL) {
return NULL;
}
if (fp = fopen(filename, "rb"), fp != NULL) {
fread(magic, 1, 32, fp);
fseek(fp, 0, SEEK_SET);
}
strcpy(pd->filename, filename);
pd->flag = PIC_READ;
pd->fullcolor = TRUE;
for (i = 0; i < (sizeof(function)/sizeof(function[0])); ++i) {
if (function[i]->PicReadHeader(pd, fp, magic) != FALSE) {
break;
}
}
if (i == (sizeof(function)/sizeof(function[0]))) {
free(pd);
return NULL;
}
if (pd->func->PicOpen(pd, fp, 0) == FALSE) {
free(pd);
return NULL;
}
return pd;
}