~ubuntu-branches/ubuntu/vivid/ghostscript/vivid-security

« back to all changes in this revision

Viewing changes to devices/gdevpe.c

  • Committer: Package Import Robot
  • Author(s): Till Kamppeter
  • Date: 2013-08-09 20:01:36 UTC
  • mfrom: (1.1.37)
  • Revision ID: package-import@ubuntu.com-20130809200136-amb6zrr7hnjb5jq9
Tags: 9.08~rc1~dfsg-0ubuntu1
* New upstream release
   - Ghostscript 9.08rc1.
   - We are using the system's liblcms2 and libopenjpeg now.
* debian/patches/020130401-852e545-pxl-xl-driver-produced-drawing-commands-without-setting-color-space.patch:
  Removed patch backported from upstream.
* debian/patches/ojdk-8007925+8007926.patch,
  debian/patches/ojdk-8007927.patch,
  debian/patches/ojdk-8007929.patch,
  debian/patches/ojdk-8009654.patch: Removed patches on build in liblcms2, we
  use the system's liblcms2 now.
* debian/patches/2001_docdir_fix_for_debian.patch: Manually updated to new
  upstream source code.
* debian/patches/2003_support_multiarch.patch: Refreshed with quilt.
* debian/control: Added build dependencies on liblcms2-dev and
  libopenjpeg-dev.
* debian/rules: Check for removed lcms2/ and openjpeg/ subdirectories in
  the repackaging check again, also set build options for shared liblcms2
  and libopenjpeg libraries.
* debian/rules: Makefile.in and configure.ac are in the root directory of
  the source now and do not need to get linked from base/. Also there is no
  gstoraster and gstopxl CUPS filter in the package any more and no
  "install-cups" make target any more.
* debian/control, debian/rules, debian/ghostscript-cups.install,
  debian/ghostscript-cups.ppd-updater: Removed the ghostscript-cups binary
  package. The files are now provided by cups-filters.
* debian/symbols.common: Updated for new upstream source. Applied patch
  which dpkg-gensymbols generated for debian/libgs9.symbols to this file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (C) 2001-2012 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,
 
8
   modified or distributed except as expressly authorized under the terms
 
9
   of the license contained in the file LICENSE in this distribution.
 
10
 
 
11
   Refer to licensing information at http://www.artifex.com or contact
 
12
   Artifex Software, Inc.,  7 Mt. Lassen Drive - Suite A-134, San Rafael,
 
13
   CA  94903, U.S.A., +1(415)492-9861, for further information.
 
14
*/
 
15
 
 
16
 
 
17
/*
 
18
 * Private Eye display driver
 
19
 *
 
20
 * Hacked by Fran Taylor, Reflection Technology Inc.
 
21
 */
 
22
 
 
23
#include "memory_.h"
 
24
#include "gx.h"
 
25
#include "gxdevice.h"
 
26
 
 
27
char *getenv(char *name);
 
28
 
 
29
typedef struct gx_device_pe_s {
 
30
        gx_device_common;
 
31
        byte *fbaddr;
 
32
        unsigned regs;
 
33
} gx_device_pe;
 
34
#define pedev ((gx_device_pe *)dev)
 
35
 
 
36
typedef struct {
 
37
        ushort reg, val;
 
38
} regval;
 
39
 
 
40
#define XSIZE 720
 
41
#define YSIZE 280
 
42
#define BPL 90
 
43
#define XPPI 160.0
 
44
#define YPPI 96.0
 
45
#define DEFAULT_ADDRESS ((byte *) 0xb8000000)
 
46
#define DEFAULT_REGISTERS 0x3d0
 
47
 
 
48
dev_proc_open_device(pe_open);
 
49
dev_proc_close_device(pe_close);
 
50
dev_proc_fill_rectangle(pe_fill_rectangle);
 
51
dev_proc_copy_mono(pe_copy_mono);
 
52
 
 
53
static gx_device_procs pe_procs =
 
54
{       pe_open,
 
55
        NULL,                   /* get_initial_matrix */
 
56
        NULL,                   /* sync_output */
 
57
        NULL,                   /* output_page */
 
58
        pe_close,
 
59
        NULL,                   /* map_rgb_color */
 
60
        NULL,                   /* map_color_rgb */
 
61
        pe_fill_rectangle,
 
62
        NULL,                   /* tile_rectangle */
 
63
        pe_copy_mono,
 
64
        NULL                    /* copy_color */
 
65
};
 
66
 
 
67
gx_device_pe far_data gs_pe_device =
 
68
{       std_device_std_body(gx_device_pe, &pe_procs, "pe",
 
69
          XSIZE, YSIZE, XPPI, YPPI),
 
70
         { 0 },         /* std_procs */
 
71
        DEFAULT_ADDRESS, DEFAULT_REGISTERS
 
72
};
 
73
 
 
74
static regval peinit[] = {{0x04, 0x1e}, {0x05, 0x00},
 
75
                          {0x04, 0x0c}, {0x05, 0x21},
 
76
                          {0x04, 0x0d}, {0x05, 0x98},
 
77
                          {0x08, 0x00}, {0x08, 0x1e},
 
78
                          {0x04, 0x1e}, {0x05, 0x01}};
 
79
 
 
80
static regval pedone[] = {{0x04, 0x1e}, {0x05, 0x10},
 
81
                          {0x04, 0x0a}, {0x05, 0x00},
 
82
                          {0x04, 0x0b}, {0x05, 0x07},
 
83
                          {0x04, 0x0c}, {0x05, 0x00},
 
84
                          {0x04, 0x0d}, {0x05, 0x00},
 
85
                          {0x04, 0x0e}, {0x05, 0x00},
 
86
                          {0x04, 0x0f}, {0x05, 0x00},
 
87
                          {0x08, 0x00}, {0x08, 0x29}};
 
88
 
 
89
int pe_open(gx_device *dev)
 
90
{
 
91
        char *str;
 
92
        int i;
 
93
 
 
94
        if ((str = getenv("PEFBADDR")) != 0)
 
95
        {
 
96
                if (!sscanf(str, "%lx", &(pedev->fbaddr)))
 
97
                {
 
98
                        emprintf(dev->memory,
 
99
                                 "Private Eye: PEFBADDR environment string format error\n");
 
100
                        exit(1);
 
101
                }
 
102
        }
 
103
 
 
104
        if ((str = getenv("PEREGS")) != 0)
 
105
        {
 
106
                if (!sscanf(str, "%x", &(pedev->regs)))
 
107
                {
 
108
                        emprintf(dev->memory,
 
109
                                 "Private Eye: PEREGS environment string format error\n");
 
110
                        exit(1);
 
111
                }
 
112
        }
 
113
 
 
114
        for (i = 0; i < 10; i++)
 
115
                outportb(pedev->regs + peinit[i].reg, peinit[i].val);
 
116
 
 
117
        return 0;
 
118
}
 
119
 
 
120
int pe_close(gx_device *dev)
 
121
{
 
122
        int i;
 
123
 
 
124
        /* restore the screen */
 
125
        for (i = 0; i < 16; i++)
 
126
                outportb(pedev->regs + pedone[i].reg, pedone[i].val);
 
127
 
 
128
        /* clear the frame buffer */
 
129
        memset(pedev->fbaddr, 0, 4000);
 
130
 
 
131
        return 0;
 
132
}
 
133
 
 
134
int pe_fill_rectangle(gx_device *dev, int x1, int y1, int w, int h,
 
135
                      gx_color_index color)
 
136
{
 
137
        int x2, y2, xlen;
 
138
        byte led, red, d;
 
139
        byte *ptr;
 
140
 
 
141
        /* cull */
 
142
 
 
143
        if ((w <= 0) || (h <= 0) || (x1 > XSIZE) || (y1 > YSIZE))
 
144
                return 0;
 
145
 
 
146
        x2 = x1 + w - 1;
 
147
        y2 = y1 + h - 1;
 
148
 
 
149
        /* cull some more */
 
150
 
 
151
        if ((x2 < 0) || (y2 < 0))
 
152
                return 0;
 
153
 
 
154
        /* clip */
 
155
 
 
156
        if (x1 < 0) x1 = 0;
 
157
        if (x2 > XSIZE-1) x2 = XSIZE-1;
 
158
        if (y1 < 0) y1 = 0;
 
159
        if (y2 > YSIZE-1) y2 = YSIZE-1;
 
160
 
 
161
        w = x2 - x1 + 1;
 
162
        h = y2 - y1 + 1;
 
163
        xlen = (x2 >> 3) - (x1 >> 3) - 1;
 
164
        led = 0xff >> (x1 & 7);
 
165
        red = 0xff << (7 - (x2 & 7));
 
166
 
 
167
        ptr = pedev->fbaddr + (y1 * BPL) + (x1 >> 3);
 
168
 
 
169
        if (color)
 
170
        {
 
171
                /* here to set pixels */
 
172
 
 
173
                if (xlen == -1)
 
174
                {
 
175
                        /* special for rectangles that fit in a byte */
 
176
 
 
177
                        d = led & red;
 
178
                        for(; h >= 0; h--, ptr += BPL)
 
179
                                *ptr |= d;
 
180
                        return 0;
 
181
                }
 
182
 
 
183
                /* normal fill */
 
184
 
 
185
                for(; h >= 0; h--, ptr += BPL)
 
186
                {       register int x = xlen;
 
187
                        register byte *p = ptr;
 
188
                        *p++ |= led;
 
189
                        while ( x-- ) *p++ = 0xff;
 
190
                        *p |= red;
 
191
                }
 
192
        }
 
193
 
 
194
        /* here to clear pixels */
 
195
 
 
196
        led = ~led;
 
197
        red = ~red;
 
198
 
 
199
        if (xlen == -1)
 
200
        {
 
201
                /* special for rectangles that fit in a byte */
 
202
 
 
203
                d = led | red;
 
204
                for(; h >= 0; h--, ptr += BPL)
 
205
                        *ptr &= d;
 
206
                return 0;
 
207
        }
 
208
 
 
209
        /* normal fill */
 
210
 
 
211
        for(; h >= 0; h--, ptr += BPL)
 
212
        {       register int x = xlen;
 
213
                register byte *p = ptr;
 
214
                *p++ &= led;
 
215
                while ( x-- ) *p++ = 0x00;
 
216
                *p &= red;
 
217
        }
 
218
        return 0;
 
219
}
 
220
 
 
221
int pe_copy_mono(gx_device *dev,
 
222
                 const byte *base, int sourcex, int raster, gx_bitmap_id id,
 
223
                 int x, int y, int w, int h,
 
224
                 gx_color_index zero, gx_color_index one)
 
225
{
 
226
        const byte *line;
 
227
        int sleft, dleft;
 
228
        int mask, rmask;
 
229
        int invert, zmask, omask;
 
230
        byte *dest;
 
231
        int offset;
 
232
 
 
233
#define izero (int)zero
 
234
#define ione (int)one
 
235
 
 
236
if ( ione == izero )            /* vacuous case */
 
237
                return pe_fill_rectangle(dev, x, y, w, h, zero);
 
238
 
 
239
        /* clip */
 
240
 
 
241
        if ((x > XSIZE) || (y > YSIZE) || ((x + w) < 0) || ((y + h) < 0))
 
242
                return 0;
 
243
 
 
244
        offset = x >> 3;
 
245
        dest = pedev->fbaddr + (y * BPL) + offset;
 
246
        line = base + (sourcex >> 3);
 
247
        sleft = 8 - (sourcex & 7);
 
248
        dleft = 8 - (x & 7);
 
249
        mask = 0xff >> (8 - dleft);
 
250
        if ( w < dleft )
 
251
                mask -= mask >> w;
 
252
        else
 
253
                rmask = 0xff00 >> ((w - dleft) & 7);
 
254
 
 
255
        /* Macros for writing partial bytes. */
 
256
        /* bits has already been inverted by xor'ing with invert. */
 
257
 
 
258
#define write_byte_masked(ptr, bits, mask)\
 
259
  *ptr = ((bits | ~mask | zmask) & *ptr | (bits & mask & omask))
 
260
 
 
261
#define write_byte(ptr, bits)\
 
262
  *ptr = ((bits | zmask) & *ptr | (bits & omask))
 
263
 
 
264
/*      if ( dev->invert )
 
265
        {
 
266
                if ( izero != (int)gx_no_color_index ) zero ^= 1;
 
267
                if ( ione != (int)gx_no_color_index ) one ^= 1;
 
268
        } */
 
269
        invert = (izero == 1 || ione == 0 ? -1 : 0);
 
270
        zmask = (izero == 0 || ione == 0 ? 0 : -1);
 
271
        omask = (izero == 1 || ione == 1 ? -1 : 0);
 
272
 
 
273
#undef izero
 
274
#undef ione
 
275
 
 
276
        if (sleft == dleft)             /* optimize the aligned case */
 
277
        {
 
278
                w -= dleft;
 
279
                while ( --h >= 0 )
 
280
                {
 
281
                        register const byte *bptr = line;
 
282
                        int count = w;
 
283
                        register byte *optr = dest;
 
284
                        register int bits = *bptr ^ invert;     /* first partial byte */
 
285
 
 
286
                        write_byte_masked(optr, bits, mask);
 
287
 
 
288
                        /* Do full bytes. */
 
289
 
 
290
                        while ((count -= 8) >= 0)
 
291
                        {
 
292
                                bits = *++bptr ^ invert;
 
293
                                ++optr;
 
294
                                write_byte(optr, bits);
 
295
                        }
 
296
 
 
297
                        /* Do last byte */
 
298
 
 
299
                        if (count > -8)
 
300
                        {
 
301
                                bits = *++bptr ^ invert;
 
302
                                ++optr;
 
303
                                write_byte_masked(optr, bits, rmask);
 
304
                        }
 
305
                        dest += BPL;
 
306
                        line += raster;
 
307
                }
 
308
        }
 
309
        else
 
310
        {
 
311
                int skew = (sleft - dleft) & 7;
 
312
                int cskew = 8 - skew;
 
313
 
 
314
                while (--h >= 0)
 
315
                {
 
316
                        const byte *bptr = line;
 
317
                        int count = w;
 
318
                        byte *optr = dest;
 
319
                        register int bits;
 
320
 
 
321
                        /* Do the first partial byte */
 
322
 
 
323
                        if (sleft >= dleft)
 
324
                        {
 
325
                                bits = *bptr >> skew;
 
326
                        }
 
327
                        else /* ( sleft < dleft ) */
 
328
                        {
 
329
                                bits = *bptr++ << cskew;
 
330
                                if (count > sleft)
 
331
                                        bits += *bptr >> skew;
 
332
                        }
 
333
                        bits ^= invert;
 
334
                        write_byte_masked(optr, bits, mask);
 
335
                        count -= dleft;
 
336
                        optr++;
 
337
 
 
338
                        /* Do full bytes. */
 
339
 
 
340
                        while ( count >= 8 )
 
341
                        {
 
342
                                bits = *bptr++ << cskew;
 
343
                                bits += *bptr >> skew;
 
344
                                bits ^= invert;
 
345
                                write_byte(optr, bits);
 
346
                                count -= 8;
 
347
                                optr++;
 
348
                        }
 
349
 
 
350
                        /* Do last byte */
 
351
 
 
352
                        if (count > 0)
 
353
                        {
 
354
                                bits = *bptr++ << cskew;
 
355
                                if (count > skew)
 
356
                                        bits += *bptr >> skew;
 
357
                                bits ^= invert;
 
358
                                write_byte_masked(optr, bits, rmask);
 
359
                        }
 
360
                        dest += BPL;
 
361
                        line += raster;
 
362
                }
 
363
        }
 
364
        return 0;
 
365
}