home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 5
/
FreshFish_July-August1994.bin
/
bbs
/
gnu
/
gs-2.6.1.4-src.lha
/
src
/
amiga
/
gs-2.6.1.4
/
gdevpcfb.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-01-27
|
22KB
|
858 lines
/* Copyright (C) 1989, 1992, 1993 Aladdin Enterprises. All rights reserved.
This file is part of Ghostscript.
Ghostscript is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY. No author or distributor accepts responsibility
to anyone for the consequences of using it or for whether it serves any
particular purpose or works at all, unless he says so in writing. Refer
to the Ghostscript General Public License for full details.
Everyone is granted permission to copy, modify and redistribute
Ghostscript, but only under the conditions described in the Ghostscript
General Public License. A copy of this license is supposed to have been
given to you along with Ghostscript so you can know your rights and
responsibilities. It should be in a file named COPYING. Among other
things, the copyright notice and this notice must be preserved on all
copies. */
/* gdevpcfb.c */
/* IBM PC EGA and VGA display drivers for Ghostscript */
/* This is fundamentally an EGA driver with some parameters */
/* that allow it to drive larger displays. */
#include "memory_.h"
#include "gx.h"
#include "gserrors.h"
#include "gxdevice.h"
#include "gdevpcfb.h"
/* Macro for casting gx_device argument */
#define fb_dev ((gx_device_ega *)dev)
/* Define the color spectrum */
#define black 0
#define blue 1
#define green 2
#define cyan 3
#define red 4
#define magenta 5
#define brown 6
#define white 7
#define dgray 8 /* dark gray is not very usable */
#define lblue 9
#define lgreen 10
#define lcyan 11
#define lred 12
#define lmagenta 13
#define yellow 14
#define bwhite 15
/* Procedure record */
private gx_device_procs ega_procs = {
ega_open,
gx_default_get_initial_matrix,
gx_default_sync_output,
gx_default_output_page,
ega_close,
ega_map_rgb_color,
ega_map_color_rgb,
ega_fill_rectangle,
ega_tile_rectangle,
ega_copy_mono,
ega_copy_color,
gx_default_draw_line,
ega_get_bits,
gx_default_get_props,
gx_default_put_props
};
/* All the known instances */
/* EGA */
gx_device_ega gs_ega_device =
ega_device("ega", ega_procs, 80, 350, 48.0/35.0, 0x10);
/* VGA */
gx_device_ega gs_vga_device =
ega_device("vga", ega_procs, 80, 480, 1.0, 0x12);
/* ATI Wonder SuperVGA, 800x600, 16-color mode */
gx_device_ega gs_atiw16_device =
ega_device("atiw16", ega_procs, 100, 600, 1.0, 0x54);
/* Trident SuperVGA, 800x600, 16-color mode */
gx_device_ega gs_tvga16_device =
ega_device("tvga16", ega_procs, 100, 600, 1.0, 0x5b);
/* Tseng Labs SuperVGA, 800x600, 16-color mode */
gx_device_ega gs_tseng16_device =
ega_device("tseng16", ega_procs, 100, 600, 1.0, 0x29);
/* Save the EGA mode */
private int ega_save_mode = -1;
/* Initialize the EGA for graphics mode */
int
ega_open(gx_device *dev)
{ /* Adjust the device resolution. */
/* This is a hack, pending refactoring of the put_props machinery. */
switch ( fb_dev->video_mode )
{
case 0x10: /* EGA */
gx_device_adjust_resolution(dev, 640, 350, 1); break;
case 0x12: /* VGA */
gx_device_adjust_resolution(dev, 640, 480, 1); break;
case 0x54: /* ATI Wonder */
case 0x5b: /* Trident */
case 0x29: /* Tseng */
gx_device_adjust_resolution(dev, 800, 600, 1); break;
}
if ( ega_save_mode < 0 )
ega_save_mode = ega_get_mode();
/* Do implementation-specific initialization */
ega_set_signals(dev);
ega_set_mode(fb_dev->video_mode);
set_s_map(-1); /* enable all maps */
return 0;
}
/* Reinitialize the EGA for text mode */
int
ega_close(gx_device *dev)
{ if ( ega_save_mode >= 0 )
ega_set_mode(ega_save_mode);
return 0;
}
/* Map a r-g-b color to an EGA color code. */
gx_color_index
ega_map_rgb_color(gx_device *dev, gx_color_value r, gx_color_value g,
gx_color_value b)
{
#define c12 (gx_max_color_value / 2)
#define c13 (gx_max_color_value / 3)
#define c23 (gx_max_color_value - c13)
#define cmono() ((gx_color_index)mono_color[r >> (gx_color_value_bits - 2)])
#if ega_bits_of_color == 0 /* monochrome */
static const byte mono_color[4] = { black, white, white, bwhite };
return cmono();
#else
# if ega_bits_of_color == 1
static const byte mono_color[4] = { black, white, white, bwhite };
if ( r == g && g == b )
return cmono();
return (gx_color_index)
((r > c12 ? 4 : 0) |
(g > c12 ? 10 : 0) |
(b > c12 ? 1 : 0));
# else
static const byte g0[3][3] =
{{black,blue,lblue},{red,magenta,lmagenta},{lred,lmagenta,lmagenta}};
static const byte g1[3][3] =
{{green,cyan,lcyan},{brown,white,lcyan},{yellow,yellow,lmagenta}};
static const byte g2[3][3] =
{{lgreen,lgreen,lcyan},{lgreen,lgreen,lcyan},{yellow,yellow,bwhite}};
return (gx_color_index)
((g >= c23 ? g2 : g >= c13 ? g1 : g0)
[r >= c23 ? 2 : r >= c13 ? 1 : 0]
[b >= c23 ? 2 : b >= c13 ? 1 : 0]);
# endif
#endif
#undef c12
#undef c13
#undef c23
}
/* Map a color code to r-g-b. */
int
ega_map_color_rgb(gx_device *dev, gx_color_index color,
gx_color_value prgb[3])
{
#define icolor (int)color
#if rgb_max > 1
gx_color_value one =
(icolor & 8 ? gx_max_color_value : gx_max_color_value / 3);
#else
# define one (gx_max_color_value / 2 + 1)
#endif
prgb[0] = (icolor & 4 ? one : 0);
prgb[1] = (icolor & 2 ? one : 0);
prgb[2] = (icolor & 1 ? one : 0);
return 0;
#undef one
#undef icolor
}
/* ------ Internal routines ------ */
/* Structure for operation parameters. */
/* Note that this structure is known to assembly code. */
/* Not all parameters are used for every operation. */
typedef struct rop_params_s {
fb_ptr dest; /* pointer to frame buffer */
int draster; /* raster of frame buffer */
const byte *src; /* pointer to source data */
int sraster; /* source raster */
int width; /* width in bytes */
int height; /* height in scan lines */
int shift; /* amount to right shift source */
int invert; /* 0 or -1 to invert source */
int data; /* data for fill */
} rop_params;
typedef rop_params _ss *rop_ptr;
/* Assembly language routines */
#if USE_ASM
void memsetcol(P1(rop_ptr)); /* dest, draster, height, data */
#else
#define memsetcol cmemsetcol
private void
cmemsetcol(rop_ptr rop)
{ byte *addr = rop->dest;
int yc = rop->height;
byte data = rop->data;
int draster = rop->draster;
while ( yc-- )
{ byte_discard(*addr);
*addr = data;
addr += draster;
}
}
#endif
#if USE_ASM
void memsetrect(P1(rop_ptr)); /* dest, draster, width, height, data */
#else
#define memsetrect cmemsetrect
private void
cmemsetrect(rop_ptr rop)
{ int yc = rop->height;
int width = rop->width;
if ( yc <= 0 || width <= 0 ) return;
{ byte *addr = rop->dest;
byte data = rop->data;
if ( width > 5 ) /* use memset */
{ int skip = rop->draster;
do
{ memset(addr, data, width);
addr += skip;
}
while ( --yc );
}
else /* avoid the fixed overhead */
{ int skip = rop->draster - width;
do
{ int cnt = width;
do { *addr++ = data; } while ( --cnt );
addr += skip;
}
while ( --yc );
}
}
}
#endif
#if USE_ASM
void memrwcol(P1(rop_ptr)); /* dest, draster, src, sraster, height, shift, invert */
# define memrwcol0(rop) memrwcol(rop) /* same except shift = 0 */
#else
# define memrwcol cmemrwcol
# define memrwcol0 cmemrwcol0
private void
cmemrwcol(rop_ptr rop)
{ byte *dp = rop->dest;
const byte *sp = rop->src;
int yc = rop->height;
int shift = rop->shift;
byte invert = rop->invert;
int sraster = rop->sraster, draster = rop->draster;
while ( yc-- )
{ byte_discard(*dp);
*dp = ((*sp >> shift) + (*sp << (8 - shift))) ^ invert;
dp += draster, sp += sraster;
}
}
private void
cmemrwcol0(rop_ptr rop)
{ byte *dp = rop->dest;
const byte *sp = rop->src;
int yc = rop->height;
byte invert = rop->invert;
int sraster = rop->sraster, draster = rop->draster;
if ( yc > 0 ) do
{ byte_discard(*dp);
*dp = *sp ^ invert;
dp += draster, sp += sraster;
}
while ( --yc );
}
#endif
#if USE_ASM
void memrwcol2(P1(rop_ptr)); /* dest, draster, src, sraster, height, shift, invert */
#else
#define memrwcol2 cmemrwcol2
private void
cmemrwcol2(rop_ptr rop)
{ byte *dp = rop->dest;
const byte *sp = rop->src;
int yc = rop->height;
int shift = rop->shift;
byte invert = rop->invert;
int sraster = rop->sraster, draster = rop->draster;
while ( yc-- )
{