home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
DOS/V Power Report 1997 March
/
VPR9703A.ISO
/
VPR_DATA
/
DOGA
/
SOURCES
/
REND.LZH
/
PIC1600
/
PICLIB.C
< prev
next >
Wrap
C/C++ Source or Header
|
1996-04-19
|
3KB
|
134 lines
#include <stdio.h>
#include <stdlib.h>
#ifdef X68K
#include <doslib.h>
#endif
#include "piclib.h"
int PicOutputLine(PicData *pd, Pixel *pixel)
{
return pd->func->PicOutputLine(pd, pixel);
}
int PicInputLine(PicData *pd, Pixel *pixel)
{
return pd->func->PicInputLine(pd, pixel);
}
int PicClose(PicData *pd)
{
return pd->func->PicClose(pd);
}
#ifdef X68K
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) | ((color & 0x0001) ? 0xff : 0);
}
static inline unsigned short Convert_24_16(Pixel p)
{
return ((p & 0xf8000000) >> 16)
| ((p & 0x00f80000) >> 13)
| ((p & 0x0000f800) >> 10)
| ((p & 0x00000080) ? 1 : 0);
}
int PicDisplay(PicData *pd, int x, int y, int scale, int mode)
{
int ssp;
int i, j;
int sizex, sizey;
unsigned short *gram = (unsigned short*)0xc00000;
PicReduceData *reduce;
Pixel *pixel;
if (x < 0 ) {
/* x = pd->picheader.positionX;*/
x = 0;
}
if (y < 0) {
/* y = pd->picheader.positionY;*/
y = 0;
}
gram += x * 512 + y;
sizex = pd->pixelX;
sizey = pd->pixelY;
if ((pixel = malloc(sizeof(Pixel) * pd->pixelX))==NULL) {
return FALSE;
}
if ((reduce = PicColorReduceOpen(pd->pixelX, mode)) == NULL) {
free(pixel);
return FALSE;
}
label1:
ssp = SUPER(0);
label2:
for (j = sizey; j > 0; --j) {
PicInputLine(pd, pixel);
PicColorReduce(reduce, pixel, pixel);
for (i = 0; i < sizex; ++i) {
*gram++ = Convert_24_16(pixel[i]);
}
gram += 512-sizex;
}
label3:
SUPER(ssp);
label4:
PicColorReduceClose(reduce);
free(pixel);
return TRUE;
}
int PicSave(PicData *pd, int x, int y, int scale)
{
int ssp;
int i, j;
int sizex, sizey;
unsigned short *gram = (unsigned short*)0xc00000;
Pixel *pixel;
if (x < 0 ) {
/* x = pd->picheader.positionX;*/
x = 0;
}
if (y < 0) {
/* y = pd->picheader.positionY;*/
y = 0;
}
gram += x * 512 + y;
sizex = pd->pixelX;
sizey = pd->pixelY;
if ((pixel = malloc(sizeof(Pixel) * pd->pixelX))==NULL) {
return FALSE;
}
label1:
ssp = SUPER(0);
label2:
for (j = sizey; j > 0; --j) {
for (i = 0; i < sizex; ++i) {
pixel[i] = Convert_16_24(*gram++);
}
PicOutputLine(pd, pixel);
gram += 512-sizex;
}
label3:
SUPER(ssp);
label4:
free(pixel);
return TRUE;
}
#endif