~ubuntu-branches/ubuntu/jaunty/ghostscript/jaunty-updates

« back to all changes in this revision

Viewing changes to src/gdevvglb.c

  • Committer: Bazaar Package Importer
  • Author(s): Till Kamppeter
  • Date: 2009-01-20 16:40:45 UTC
  • mfrom: (1.1.10 upstream)
  • Revision ID: james.westby@ubuntu.com-20090120164045-lnfhi0n30o5lwhwa
Tags: 8.64.dfsg.1~svn9377-0ubuntu1
* New upstream release (SVN rev 9377)
   o Fixes many bugs concerning PDF rendering, to make the PDF printing
     workflow correctly working.
   o Fixes long-standing bugs in many drivers, like input paper tray and
     duplex options not working for the built-in PCL 4, 5, 5c, 5e, and
     6/XL drivers, PDF input not working for bjc600, bjc800, and cups
     output devices, several options not working and uninitialized
     memory with cups output device.
   o Merged nearly all patches of the Ubuntu and Debian packages upstream.
   o Fixes LP: #317810, LP: #314439, LP: #314018.
* debian/patches/03_libpaper_support.dpatch,
  debian/patches/11_gs-cjk_font_glyph_handling_fix.dpatch,
  debian/patches/12_gs-cjk_vertical_writing_metrics_fix.dpatch,
  debian/patches/13_gs-cjk_cjkps_examples.dpatch,
  debian/patches/20_bbox_segv_fix.dpatch,
  debian/patches/21_brother_7x0_gdi_fix.dpatch,
  debian/patches/22_epsn_margin_workaround.dpatch,
  debian/patches/24_gs_man_fix.dpatch,
  debian/patches/25_toolbin_insecure_tmp_usage_fix.dpatch,
  debian/patches/26_assorted_script_fixes.dpatch,
  debian/patches/29_gs_css_fix.dpatch,
  debian/patches/30_ps2pdf_man_improvement.dpatch,
  debian/patches/31_fix-gc-sigbus.dpatch,
  debian/patches/34_ftbfs-on-hurd-fix.dpatch,
  debian/patches/35_disable_libcairo.dpatch,
  debian/patches/38_pxl-duplex.dpatch,
  debian/patches/39_pxl-resolution.dpatch,
  debian/patches/42_gs-init-ps-delaybind-fix.dpatch,
  debian/patches/45_bjc600-bjc800-pdf-input.dpatch,
  debian/patches/48_cups-output-device-pdf-duplex-uninitialized-memory-fix.dpatch,
  debian/patches/50_lips4-floating-point-exception.dpatch,
  debian/patches/52_cups-device-logging.dpatch,
  debian/patches/55_pcl-input-slot-fix.dpatch,
  debian/patches/57_pxl-input-slot-fix.dpatch,
  debian/patches/60_pxl-cups-driver-pdf.dpatch,
  debian/patches/62_onebitcmyk-pdf.dpatch,
  debian/patches/65_too-big-temp-files-1.dpatch,
  debian/patches/67_too-big-temp-files-2.dpatch,
  debian/patches/70_take-into-account-data-in-stream-buffer-before-refill.dpatch:
  Removed, applied upstream.
* debian/patches/01_docdir_fix_for_debian.dpatch,
  debian/patches/02_gs_man_fix_debian.dpatch,
  debian/patches/01_docdir-fix-for-debian.dpatch,
  debian/patches/02_docdir-fix-for-debian.dpatch: Renamed patches to
  make merging with Debian easier.
* debian/patches/32_improve-handling-of-media-size-changes-from-gv.dpatch, 
  debian/patches/33_bad-params-to-xinitimage-on-large-bitmaps.dpatch:
  regenerated for new source directory structure.
* debian/rules: Corrected paths to remove cidfmap (it is in Resource/Init/
  in GS 8.64) and to install headers (source paths are psi/ and base/ now).
* debian/rules: Remove all fontmaps, as DeFoMa replaces them.
* debian/local/pdftoraster/pdftoraster.c,
  debian/local/pdftoraster/pdftoraster.convs, debian/rules: Removed
  added pdftoraster filter and use the one which comes with Ghostscript.
* debian/ghostscript.links: s/8.63/8.64/

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (C) 2001-2006 Artifex Software, Inc.
2
 
   All Rights Reserved.
3
 
  
4
 
   This software is provided AS-IS with no warranty, either express or
5
 
   implied.
6
 
 
7
 
   This software is distributed under license and may not be copied, modified
8
 
   or distributed except as expressly authorized under the terms of that
9
 
   license.  Refer to licensing information at http://www.artifex.com/
10
 
   or contact Artifex Software, Inc.,  7 Mt. Lassen Drive - Suite A-134,
11
 
   San Rafael, CA  94903, U.S.A., +1(415)492-9861, for further information.
12
 
*/
13
 
 
14
 
/* $Id: gdevvglb.c 8250 2007-09-25 13:31:24Z giles $ */
15
 
/*
16
 
 * This is a driver for 386 PCs using vgalib for graphics on the console
17
 
 * display.  Note that this driver only works with 16-color modes.
18
 
 *
19
 
 * Written by Sigfrid Lundberg, siglun@euler.teorekol.lu.se.
20
 
 * Modified by Erik Talvola, talvola@gnu.ai.mit.edu
21
 
 * Updated 9/28/96 by L. Peter Deutsch, ghost@aladdin.com: allow setting
22
 
 *   the display mode as a device parameter.
23
 
 * Updated 2/13/97 by ghost@aladdin.com: make the device identify itself
24
 
 *   as a page device.
25
 
 * Updated 5/2/97 by ghost@aladdin.com: copy_mono computed some parameters
26
 
 *   before doing fit_copy.
27
 
 * Update 1997-06-28 by ghost@aladdin.com: get_bits wasn't implemented.
28
 
 */
29
 
 
30
 
#include "gx.h"
31
 
#include "gserrors.h"
32
 
#include "gsparam.h"
33
 
#include "gxdevice.h"
34
 
#include "gdevpccm.h"
35
 
 
36
 
#include <errno.h>
37
 
#include <vga.h>
38
 
 
39
 
typedef struct gx_device_vgalib {
40
 
    gx_device_common;
41
 
    int display_mode;
42
 
} gx_device_vgalib;
43
 
 
44
 
#define vga_dev ((gx_device_vgalib *)dev)
45
 
 
46
 
#define XDPI   60               /* to get a more-or-less square aspect ratio */
47
 
#define YDPI   60
48
 
 
49
 
#ifndef A4                      /*Letter size */
50
 
#define YSIZE (20.0 * YDPI / 2.5)
51
 
#define XSIZE (8.5 / 11)*YSIZE  /* 8.5 x 11 inch page, by default */
52
 
#else /* A4 paper */
53
 
#define XSIZE 8.27
54
 
#define YSIZE 11.69
55
 
#endif
56
 
 
57
 
static dev_proc_open_device(vgalib_open);
58
 
static dev_proc_close_device(vgalib_close);
59
 
static dev_proc_map_rgb_color(vgalib_map_rgb_color);
60
 
static dev_proc_map_color_rgb(vgalib_map_color_rgb);
61
 
static dev_proc_fill_rectangle(vgalib_fill_rectangle);
62
 
static dev_proc_tile_rectangle(vgalib_tile_rectangle);
63
 
static dev_proc_copy_mono(vgalib_copy_mono);
64
 
static dev_proc_copy_color(vgalib_copy_color);
65
 
static dev_proc_get_bits(vgalib_get_bits);
66
 
static dev_proc_get_params(vgalib_get_params);
67
 
static dev_proc_put_params(vgalib_put_params);
68
 
 
69
 
const gx_device_vgalib gs_vgalib_device =
70
 
{
71
 
    std_device_std_body(gx_device_vgalib, 0, "vgalib",
72
 
                        0, 0, 1, 1),
73
 
    {vgalib_open,
74
 
     NULL,                      /* get_initial_matrix */
75
 
     NULL,                      /* sync_output */
76
 
     NULL,                      /* output_page */
77
 
     vgalib_close,
78
 
     vgalib_map_rgb_color,
79
 
     vgalib_map_color_rgb,
80
 
     vgalib_fill_rectangle,
81
 
     vgalib_tile_rectangle,
82
 
     vgalib_copy_mono,
83
 
     vgalib_copy_color,
84
 
     NULL,                      /* draw_line (obsolete) */
85
 
     vgalib_get_bits,
86
 
     vgalib_get_params,
87
 
     vgalib_put_params,
88
 
     NULL,                      /* map_cmyk_color */
89
 
     NULL,                      /* get_xfont_procs */
90
 
     NULL,                      /* get_xfont_device */
91
 
     NULL,                      /* map_rgb_alpha_color */
92
 
     gx_page_device_get_page_device
93
 
    },
94
 
    -1                          /* display_mode */
95
 
};
96
 
 
97
 
static int
98
 
vgalib_open(gx_device * dev)
99
 
{
100
 
    int VGAMODE = vga_dev->display_mode;
101
 
    int width = dev->width, height = dev->height;
102
 
 
103
 
    if (VGAMODE == -1)
104
 
        VGAMODE = vga_getdefaultmode();
105
 
    if (VGAMODE == -1)
106
 
        vga_setmode(G640x480x16);
107
 
    else
108
 
        vga_setmode(VGAMODE);
109
 
    vga_clear();
110
 
    if (width == 0)
111
 
        width = vga_getxdim() + 1;
112
 
    if (height == 0)
113
 
        height = vga_getydim() + 1;
114
 
 
115
 
    /*vgalib provides no facilities for finding out aspect ratios */
116
 
    if (dev->y_pixels_per_inch == 1) {
117
 
        dev->y_pixels_per_inch = height / 11.0;
118
 
        dev->x_pixels_per_inch = dev->y_pixels_per_inch;
119
 
    }
120
 
    gx_device_set_width_height(dev, width, height);
121
 
 
122
 
    /* Find out if the device supports color */
123
 
    /* (default initialization is monochrome). */
124
 
    /* We only recognize 16-color devices right now. */
125
 
    if (vga_getcolors() > 1) {
126
 
        int index;
127
 
 
128
 
        static const gx_device_color_info vgalib_16color = dci_pc_4bit;
129
 
 
130
 
        dev->color_info = vgalib_16color;
131
 
 
132
 
        for (index = 0; index < 16; ++index) {
133
 
            gx_color_value rgb[3];
134
 
 
135
 
            (*dev_proc(dev, map_color_rgb)) (dev, (gx_color_index) index, rgb);
136
 
#define cv2pv(cv) ((cv) >> (gx_color_value_bits - 8))
137
 
            vga_setpalette(index, cv2pv(rgb[0]), cv2pv(rgb[1]), cv2pv(rgb[2]));
138
 
#undef cv2pv
139
 
        }
140
 
    }
141
 
    return 0;
142
 
}
143
 
 
144
 
static int
145
 
vgalib_close(gx_device * dev)
146
 
{
147
 
    vga_setmode(TEXT);
148
 
    return 0;
149
 
}
150
 
 
151
 
static gx_color_index
152
 
vgalib_map_rgb_color(gx_device * dev, gx_color_value red,
153
 
                     gx_color_value green, gx_color_value blue)
154
 
{
155
 
    return pc_4bit_map_rgb_color(dev, red, green, blue);
156
 
}
157
 
 
158
 
static int
159
 
vgalib_map_color_rgb(gx_device * dev, gx_color_index index,
160
 
                     unsigned short rgb[3])
161
 
{
162
 
    return pc_4bit_map_color_rgb(dev, index, rgb);
163
 
}
164
 
 
165
 
static int
166
 
vgalib_tile_rectangle(gx_device * dev, const gx_tile_bitmap * tile,
167
 
                      int x, int y, int w, int h, gx_color_index czero,
168
 
                      gx_color_index cone, int px, int py)
169
 
{
170
 
    if (czero != gx_no_color_index && cone != gx_no_color_index) {
171
 
        vgalib_fill_rectangle(dev, x, y, w, h, czero);
172
 
        czero = gx_no_color_index;
173
 
    }
174
 
    return gx_default_tile_rectangle(dev, tile, x, y, w, h, czero, cone, px,
175
 
                                     py);
176
 
}
177
 
 
178
 
static int
179
 
vgalib_fill_rectangle(gx_device * dev, int x, int y, int w, int h,
180
 
                      gx_color_index color)
181
 
{
182
 
    int i, j;
183
 
 
184
 
    fit_fill(dev, x, y, w, h);
185
 
    vga_setcolor((int)color);
186
 
    if ((w | h) > 3) {          /* Draw larger rectangles as lines. */
187
 
        if (w > h)
188
 
            for (i = y; i < y + h; ++i)
189
 
                vga_drawline(x, i, x + w - 1, i);
190
 
        else
191
 
            for (j = x; j < x + w; ++j)
192
 
                vga_drawline(j, y, j, y + h - 1);
193
 
    } else {                    /* Draw small rectangles point-by-point. */
194
 
        for (i = y; i < y + h; i++)
195
 
            for (j = x; j < x + w; j++)
196
 
                vga_drawpixel(j, i);
197
 
    }
198
 
    return 0;
199
 
}
200
 
 
201
 
static int
202
 
vgalib_copy_mono(gx_device * dev, const byte * base, int sourcex,
203
 
                 int raster, gx_bitmap_id id, int x, int y, int width,
204
 
                 int height, gx_color_index zero, gx_color_index one)
205
 
{
206
 
    const byte *ptr_line;
207
 
    int left_bit, dest_y, end_x;
208
 
    int invert = 0;
209
 
    int color;
210
 
 
211
 
    fit_copy(dev, base, sourcex, raster, id, x, y, width, height);
212
 
    ptr_line = base + (sourcex >> 3);
213
 
    left_bit = 0x80 >> (sourcex & 7);
214
 
    dest_y = y, end_x = x + width;
215
 
 
216
 
    if (zero == gx_no_color_index) {
217
 
        if (one == gx_no_color_index)
218
 
            return 0;
219
 
        color = (int)one;
220
 
    } else {
221
 
        if (one == gx_no_color_index) {
222
 
            color = (int)zero;
223
 
            invert = -1;
224
 
        } else {                /* Pre-clear the rectangle to zero */
225
 
            vgalib_fill_rectangle(dev, x, y, width, height, zero);
226
 
            color = (int)one;
227
 
        }
228
 
    }
229
 
 
230
 
    vga_setcolor(color);
231
 
    while (height--) {          /* for each line */
232
 
        const byte *ptr_source = ptr_line;
233
 
        register int dest_x = x;
234
 
        register int bit = left_bit;
235
 
 
236
 
        while (dest_x < end_x) {        /* for each bit in the line */
237
 
            if ((*ptr_source ^ invert) & bit)
238
 
                vga_drawpixel(dest_x, dest_y);
239
 
            dest_x++;
240
 
            if ((bit >>= 1) == 0)
241
 
                bit = 0x80, ptr_source++;
242
 
        }
243
 
 
244
 
        dest_y++;
245
 
        ptr_line += raster;
246
 
    }
247
 
    return 0;
248
 
}
249
 
 
250
 
 
251
 
/* Copy a color pixel map.  This is just like a bitmap, except that */
252
 
/* each pixel takes 4 bits instead of 1 when device driver has color. */
253
 
static int
254
 
vgalib_copy_color(gx_device * dev, const byte * base, int sourcex,
255
 
                  int raster, gx_bitmap_id id, int x, int y,
256
 
                  int width, int height)
257
 
{
258
 
 
259
 
    fit_copy(dev, base, sourcex, raster, id, x, y, width, height);
260
 
 
261
 
    if (gx_device_has_color(dev)) {     /* color device, four bits per pixel */
262
 
        const byte *line = base + (sourcex >> 1);
263
 
        int dest_y = y, end_x = x + width;
264
 
 
265
 
        if (width <= 0)
266
 
            return 0;
267
 
        while (height--) {      /* for each line */
268
 
            const byte *source = line;
269
 
            register int dest_x = x;
270
 
 
271
 
            if (sourcex & 1) {  /* odd nibble first */
272
 
                int color = *source++ & 0xf;
273
 
 
274
 
                vga_setcolor(color);
275
 
                vga_drawpixel(dest_x, dest_y);
276
 
                dest_x++;
277
 
            }
278
 
            /* Now do full bytes */
279
 
            while (dest_x < end_x) {
280
 
                int color = *source >> 4;
281
 
 
282
 
                vga_setcolor(color);
283
 
                vga_drawpixel(dest_x, dest_y);
284
 
                dest_x++;
285
 
 
286
 
                if (dest_x < end_x) {
287
 
                    color = *source++ & 0xf;
288
 
                    vga_setcolor(color);
289
 
                    vga_drawpixel(dest_x, dest_y);
290
 
                    dest_x++;
291
 
                }
292
 
            }
293
 
 
294
 
            dest_y++;
295
 
            line += raster;
296
 
        }
297
 
    } else {                    /* monochrome device: one bit per pixel */
298
 
        /* bitmap is the same as bgi_copy_mono: one bit per pixel */
299
 
        vgalib_copy_mono(dev, base, sourcex, raster, id, x, y, width, height,
300
 
                         (gx_color_index) 0, (gx_color_index) 7);
301
 
    }
302
 
 
303
 
    return 0;
304
 
}
305
 
 
306
 
/* Read bits back from the device. */
307
 
static int
308
 
vgalib_get_bits(gx_device * dev, int y, byte * data, byte ** actual_data)
309
 
{
310
 
    int x;
311
 
    byte *dest = data;
312
 
    int b = 0;
313
 
    int depth = dev->color_info.depth;  /* 1 or 4 */
314
 
    int mask = (1 << depth) - 1;
315
 
    int left = 8;
316
 
 
317
 
    if (actual_data)
318
 
        *actual_data = data;
319
 
    for (x = 0; x < dev->width; ++x) {
320
 
        int color = vga_getpixel(x, y);
321
 
 
322
 
        if ((left -= depth) < 0)
323
 
            *dest++ = b, b = 0, left += 8;
324
 
        b += (color & mask) << left;
325
 
    }
326
 
    if (left < 8)
327
 
        *dest = b;
328
 
    return 0;
329
 
}
330
 
 
331
 
/* Get/put the display mode parameter. */
332
 
static int
333
 
vgalib_get_params(gx_device * dev, gs_param_list * plist)
334
 
{
335
 
    int code = gx_default_get_params(dev, plist);
336
 
 
337
 
    if (code < 0)
338
 
        return code;
339
 
    return param_write_int(plist, "DisplayMode", &vga_dev->display_mode);
340
 
}
341
 
static int
342
 
vgalib_put_params(gx_device * dev, gs_param_list * plist)
343
 
{
344
 
    int ecode = 0;
345
 
    int code;
346
 
    int imode = vga_dev->display_mode;
347
 
    const char *param_name;
348
 
 
349
 
    switch (code = param_read_int(plist, (param_name = "DisplayMode"), &imode)) {
350
 
        default:
351
 
            ecode = code;
352
 
            param_signal_error(plist, param_name, ecode);
353
 
        case 0:
354
 
        case 1:
355
 
            break;
356
 
    }
357
 
 
358
 
    if (ecode < 0)
359
 
        return ecode;
360
 
    code = gx_default_put_params(dev, plist);
361
 
    if (code < 0)
362
 
        return code;
363
 
 
364
 
    if (imode != vga_dev->display_mode) {
365
 
        if (dev->is_open)
366
 
            gs_closedevice(dev);
367
 
        vga_dev->display_mode = imode;
368
 
    }
369
 
    return 0;
370
 
}
371
 
 
372
 
#ifdef GS_DEVS_SHARED
373
 
extern void gs_lib_register_device(const gx_device *dev);
374
 
void
375
 
gs_shared_init(void)
376
 
{
377
 
  gs_lib_register_device(&gs_vgalib_device);
378
 
}
379
 
#endif