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
/
gdevsun.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-01-27
|
21KB
|
691 lines
/* Copyright (C) 1989, 1992 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. */
/* gdevsun.c */
/* SunView driver for Ghostscript */
#include "gx.h" /* for gx_bitmap; includes std.h */
#include <suntool/sunview.h>
#include <suntool/canvas.h>
#include <sunwindow/cms_mono.h>
#include <stdio.h>
#include "gsmatrix.h" /* needed for gxdevice.h */
#include "gxdevice.h"
#include "malloc_.h"
#ifndef DEFAULT_DPI
# define DEFAULT_DPI 75 /* Sun standard monitor */
#endif
#ifdef A4
# define PAPER_X 8.27 /* A4 paper */
# define PAPER_Y 11.69
#endif
#ifndef PAPER_X
# define PAPER_X 8.5 /* US letter paper */
# define PAPER_Y 11
#endif
/* Procedures */
dev_proc_open_device(sun_open);
dev_proc_sync_output(sun_sync);
dev_proc_close_device(sun_close);
dev_proc_map_rgb_color(sun_map_rgb_color);
dev_proc_map_color_rgb(sun_map_color_rgb);
dev_proc_fill_rectangle(sun_fill_rectangle);
dev_proc_copy_mono(sun_copy_mono);
dev_proc_copy_color(sun_copy_color);
dev_proc_draw_line(sun_draw_line);
/* The device descriptor */
private gx_device_procs sun_procs = {
sun_open,
gx_default_get_initial_matrix,
sun_sync,
gx_default_output_page,
sun_close,
sun_map_rgb_color,
sun_map_color_rgb,
sun_fill_rectangle,
gx_default_tile_rectangle,
sun_copy_mono,
sun_copy_color,
sun_draw_line,
gx_default_get_bits,
gx_default_get_props,
gx_default_put_props
};
#define CMSNAME "GHOSTVIEW" /* SunView colormap name */
/* Define the SunView device */
typedef struct gx_device_sun {
gx_device_common;
Frame frame;
Canvas canvas;
Pixwin *pw;
struct mpr_data mpr;
Pixrect pr;
int truecolor; /* use truecolor mapping */
int freecols; /* unallocated colors */
byte *red, *green, *blue; /* colormap */
char cmsname[sizeof(CMSNAME)+9];/* color map name */
#if !arch_is_big_endian /* need to swap bits & bytes */
# define BUF_WIDTH_BYTES (((int)(8.5*DEFAULT_DPI)+15)/16*2)
byte swap_buf[BUF_WIDTH_BYTES];
#endif
} gx_device_sun;
#if !arch_is_big_endian
/* Define a table for reversing bit order. */
static byte reverse_bits[256] = {
0, 128, 64, 192, 32, 160, 96, 224, 16, 144, 80, 208, 48, 176, 112, 240,
8, 136, 72, 200, 40, 168, 104, 232, 24, 152, 88, 216, 56, 184, 120, 248,
4, 132, 68, 196, 36, 164, 100, 228, 20, 148, 84, 212, 52, 180, 116, 244,
12, 140, 76, 204, 44, 172, 108, 236, 28, 156, 92, 220, 60, 188, 124, 252,
2, 130, 66, 194, 34, 162, 98, 226, 18, 146, 82, 210, 50, 178, 114, 242,
10, 138, 74, 202, 42, 170, 106, 234, 26, 154, 90, 218, 58, 186, 122, 250,
6, 134, 70, 198, 38, 166, 102, 230, 22, 150, 86, 214, 54, 182, 118, 246,
14, 142, 78, 206, 46, 174, 110, 238, 30, 158, 94, 222, 62, 190, 126, 254,
1, 129, 65, 193, 33, 161, 97, 225, 17, 145, 81, 209, 49, 177, 113, 241,
9, 137, 73, 201, 41, 169, 105, 233, 25, 153, 89, 217, 57, 185, 121, 249,
5, 133, 69, 197, 37, 165, 101, 229, 21, 149, 85, 213, 53, 181, 117, 245,
13, 141, 77, 205, 45, 173, 109, 237, 29, 157, 93, 221, 61, 189, 125, 253,
3, 131, 67, 195, 35, 163, 99, 227, 19, 147, 83, 211, 51, 179, 115, 243,
11, 139, 75, 203, 43, 171, 107, 235, 27, 155, 91, 219, 59, 187, 123, 251,
7, 135, 71, 199, 39, 167, 103, 231, 23, 151, 87, 215, 55, 183, 119, 247,
15, 143, 79, 207, 47, 175, 111, 239, 31, 159, 95, 223, 63, 191, 127, 255
};
#endif
/* The instance is public. */
gx_device_sun gs_sunview_device = {
sizeof(gx_device_sun),
&sun_procs,
"sunview",
(int)(PAPER_X*DEFAULT_DPI), (int)(PAPER_Y*DEFAULT_DPI), /* x and y extent */
DEFAULT_DPI, DEFAULT_DPI, /* x and y density */
no_margins,
dci_color(0,0,0), /* fill in later from display depth */
0, /* connection not initialized */
};
/* Macro for casting gx_device argument */
#define xdev ((gx_device_sun *)dev)
/*
* The macros below define the colormap configuration used on 8-bit
* pseudo-color displays.
*/
/*
* The following macros define the number of bits used to represent rgb colors.
* The total must not exceed the display depth.
* Note that the RGB dimensions could have an uneven number of bits assigned
* to them, but that will cause dithering to not work very well, since
* gs assumes the dither ramp is the same for all 3 color dimensions.
*
* Setting RED_BITS to n will pre-allocate a color-cube of 2^(3n) entries.
* The remaining entries are allocated on demand for colors requested by
* sun_map_rgb_color(), until the color map is full. At that point gs will
* fall back onto dithering using the pre-allocated colors.
* As a special case, if RED_BITS = GREEN_BITS = BLUE_BITS = 0, only
* black and white are pre-allocated.
*/
#define RED_BITS 2 /* everything depends on this one */
#define GREEN_BITS RED_BITS
#define BLUE_BITS RED_BITS
#define DEPTH 8 /* don't change this */
#define RGB_BITS (RED_BITS + GREEN_BITS + BLUE_BITS)
/*
* Smallest # bits per dimension
*/
#define MAX_BITS RED_BITS
#if (GREEN_BITS > MAX_BITS)
#undef MAX_BITS
#define MAX_BITS GREEN_BITS
#endif
#if (BLUE_BITS > MAX_BITS)
#undef MAX_BITS
#define MAX_BITS BLUE_BITS
#endif
/*
* masks to pull out rgb components
*/
#define BLUE_MASK ((1 << BLUE_BITS) - 1)
#define GREEN_MASK ((1 << (BLUE_BITS + GREEN_BITS)) - 1 - BLUE_MASK)
#define RED_MASK ((1 << (BLUE_BITS + GREEN_BITS + RED_BITS)) - 1 \
- BLUE_MASK - GREEN_MASK)
/*
* number of colors on rgb dimensions
*/
#define RED_COLS (1 << RED_BITS)
#define GREEN_COLS (1 << GREEN_BITS)
#define BLUE_COLS (1 << BLUE_BITS)
#define RGB_COLS (RED_COLS * GREEN_COLS * BLUE_COLS)
#define MAX_COLS (1 << MAX_BITS)
/*
* maximum number of colors in map
*/
#define ALL_COLS (1 << DEPTH) /* 256 */
#define CMS_SIZE ALL_COLS /* cut down to 64 or 128 for
more cooperative behaviour */
#if (RGB_COLS > CMS_SIZE) /* one is reserved for the scrollbar */
CMS_SIZE_too_small_for_color_cube
#endif
#if (RGB_BITS < 0) || (RGB_BITS > DEPTH)
Display_does_not_support_this_many_colors
#endif
/*
* The macros below define the color mapping used on 24-bit true-color
* displays.
* FAKE_TRUE_COLOR is used for debugging only. It simulates a true-color
* type mapping on an 8-bit pseudo-color display.
#define FAKE_TRUE_COLOR
*/
#ifdef FAKE_TRUE_COLOR
# define TRUE_RED_BITS 3 /* everything depends on this one */
# define TRUE_GREEN_BITS 2
# define TRUE_BLUE_BITS (DEPTH - TRUE_RED_BITS - TRUE_GREEN_BITS)
#else
# define TRUE_RED_BITS 8 /* everything depends on this one */
# define TRUE_GREEN_BITS TRUE_RED_BITS
# define TRUE_BLUE_BITS TRUE_RED_BITS
#endif ./* FAKE_TRUE_COLOR */
#define TRUE_DEPTH (TRUE_RED_BITS + TRUE_GREEN_BITS + TRUE_BLUE_BITS)
/*
* Masks to pull out rgb components. Note that the bit order is BGR from
* high to low order bits.
*/
#define TRUE_RED_MASK ((1 << TRUE_RED_BITS) - 1)
#define TRUE_GREEN_MASK ((1 << (TRUE_RED_BITS + TRUE_GREEN_BITS)) - 1 \
- TRUE_RED_MASK)
#define TRUE_BLUE_MASK ((1 << (TRUE_RED_BITS + TRUE_GREEN_BITS \
+ TRUE_BLUE_BITS)) - 1 \
- TRUE_GREEN_MASK - TRUE_RED_MASK)
/*
* number of colors on rgb dimensions
*/
#define TRUE_RED_COLS (1 << TRUE_RED_BITS)
#define TRUE_GREEN_COLS (1 << TRUE_GREEN_BITS)
#define TRUE_BLUE_COLS (1 << TRUE_BLUE_BITS)
/* Initialize the device. */
private Notify_value destroy_func();
int
sun_open(register gx_device *dev)
{
#ifdef gs_DEBUG
if ( gs_debug['X'] )
{ extern int _Xdebug;
_Xdebug = 1;
}
#endif
if (xdev->frame == (Frame)0)
xdev->frame =
window_create(NULL, FRAME, FRAME_LABEL, "ghostscript",
WIN_WIDTH, min(xd