home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
DOS/V Power Report 1997 March
/
VPR9703A.ISO
/
VPR_DATA
/
DOGA
/
SOURCES
/
REND.LZH
/
PIC1600
/
F_DISP.C
< prev
next >
Wrap
C/C++ Source or Header
|
1996-04-20
|
4KB
|
165 lines
#ifdef X68K
#include <stdio.h>
#include <stdlib.h>
#include <doslib.h>
#include <iocslib.h>
#include <string.h>
#include "piclib.h"
typedef struct {
unsigned short *p;
Pixel *pixelbuffer;
PicReduceData *reduce;
} PicWork;
#define GRAM ((unsigned short *)(0xc00000))
int PicReadHeader_Display(PicData *pd, FILE *fp, unsigned char *magic)
{
extern PicFunction PicFunction_Display;
if (strncmp(pd->filename, "_DISPLAY_", 9) != 0) {
return FALSE;
}
pd->func = &PicFunction_Display;
pd->mode = DSP;
pd->pixelX = 512;
pd->pixelY = 512;
return TRUE;
}
int PicOpen_Display(PicData *pd, FILE *fp, int flag)
{
PicWork *work;
int nowmode;
if ((work = malloc(sizeof(PicWork))) == NULL) {
return FALSE;
}
nowmode = CRTMOD(-1);
pd->work = work;
if (pd->flag == PIC_READ) {
pd->fullcolor = FALSE;
work->p = GRAM;
if (nowmode == 12 || nowmode == 13) {
pd->pixelX = pd->pixelY = 512;
} else if (nowmode == 14 || nowmode == 15) {
pd->pixelX = pd->pixelY = 256;
} else {
return FALSE;
}
} else {
if (pd->pixelX <= 256 && pd->pixelY <= 256) {
if (nowmode != 13 && nowmode != 14) {
CRTMOD(14);
G_CLR_ON();
}
} else if (pd->pixelX <= 512 && pd->pixelY <= 512) {
if (nowmode != 12 && nowmode != 13) {
CRTMOD(12);
G_CLR_ON();
}
} else {
return FALSE;
}
work->reduce = NULL;
work->pixelbuffer = NULL;
if ((work->reduce = PicColorReduceOpen(pd->pixelX, flag)) == NULL) {
return FALSE;
}
if ((work->pixelbuffer = malloc(sizeof(Pixel) * pd->pixelX)) == NULL) {
return FALSE;
}
work->p = GRAM;
}
return TRUE;
}
static inline Pixel Convert_16_24(unsigned short color)
{
/* gggg grrr rrbb bbbt*/
/* gggg gggg rrrr rrrr bbbb bbbb tttt tttt*/
/*
return ((color & 0xf800) << 16)
| ((color & 0x07c0) << 13)
| ((color & 0x003e) << 10)
| ((color & 0x0001) ? 0xff : 0);
*/
Pixel c = ((color & 0xf800) << 11)
| ((color & 0x07c0) << 8)
| ((color & 0x003e) << 5);
return (c << 5) | (c & 0x07070700);
}
static inline unsigned short Convert_24_16(Pixel p)
{
#if 0
return ((p & 0xf8000000) >> 16)
| ((p & 0x00f80000) >> 13)
| ((p & 0x0000f800) >> 10)
| ((p & 0x00000080) ? 1 : 0);
#else
return ((p & 0xf8000000) >> 16)
| ((p & 0x00f80000) >> 13)
| ((p & 0x0000f800) >> 10);
#endif
}
int PicOutput_Display(PicData *pd, Pixel *p)
{
int pixels = pd->pixelX;
int sp;
PicWork *work = pd->work;
unsigned short *gram = work->p;
Pixel *pixel = work->pixelbuffer;
PicColorReduce(work->reduce, pixel, p);
DUMMY1:
sp = SUPER(0);
for (; pixels > 0; --pixels) {
*gram++ = Convert_24_16(*pixel++);
}
gram += 512 - pd->pixelX;
work->p = gram;
DUMMY2:
SUPER(sp);
return TRUE;
}
int PicInput_Display(PicData *pd, Pixel *pixel)
{
int sp;
int pixels = pd->pixelX;
PicWork *work = pd->work;
unsigned short *gram = work->p;
DUMMY1:
sp = SUPER(0);
for (; pixels > 0; --pixels) {
*pixel++ = Convert_16_24(*gram++);
}
gram += 512 - pd->pixelX;
work->p = gram;
DUMMY2:
SUPER(sp);
return TRUE;
}
int PicClose_Display(PicData *pd)
{
PicWork *work = pd->work;
if (pd->flag == PIC_WRITE) {
PicColorReduceClose(work->reduce);
free(work->pixelbuffer);
}
free(work);
return TRUE;
}
PicFunction PicFunction_Display = {
"",
PicReadHeader_Display,
PicOpen_Display,
PicOutput_Display,
PicInput_Display,
PicClose_Display
};
#endif