~ubuntu-branches/ubuntu/oneiric/ghostscript/oneiric

« back to all changes in this revision

Viewing changes to base/gdevpe.c

  • Committer: Bazaar Package Importer
  • Author(s): Till Kamppeter
  • Date: 2011-07-15 16:49:55 UTC
  • mfrom: (1.1.23 upstream)
  • Revision ID: james.westby@ubuntu.com-20110715164955-uga6qibao6kez05c
Tags: 9.04~dfsg~20110715-0ubuntu1
* New upstream release
   - GIT snapshot from Jult, 12 2011.
* debian/patches/020110406~a54df2d.patch,
  debian/patches/020110408~0791cc8.patch,
  debian/patches/020110408~507cbee.patch,
  debian/patches/020110411~4509a49.patch,
  debian/patches/020110412~78bb9a6.patch,
  debian/patches/020110418~a05ab8a.patch,
  debian/patches/020110420~20b6c78.patch,
  debian/patches/020110420~4ddefa2.patch: Removed upstream patches.
* debian/rules: Generate ABI version number (variable "abi") correctly,
  cutting off repackaging and pre-release parts.
* debian/rules: Added ./lcms2/ directory to DEB_UPSTREAM_REPACKAGE_EXCLUDES.
* debian/copyright: Added lcms2/* to the list of excluded files.
* 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
1
/* Copyright (C) 2001-2006 Artifex Software, Inc.
2
2
   All Rights Reserved.
3
 
  
 
3
 
4
4
   This software is provided AS-IS with no warranty, either express or
5
5
   implied.
6
6
 
11
11
   San Rafael, CA  94903, U.S.A., +1(415)492-9861, for further information.
12
12
*/
13
13
 
14
 
/* $Id: gdevpe.c 11176 2010-05-04 18:47:12Z robin $*/
 
14
/* $Id$*/
15
15
/*
16
16
 * Private Eye display driver
17
17
 *
25
25
char *getenv(char *name);
26
26
 
27
27
typedef struct gx_device_pe_s {
28
 
        gx_device_common;
29
 
        byte *fbaddr;
30
 
        unsigned regs;
 
28
        gx_device_common;
 
29
        byte *fbaddr;
 
30
        unsigned regs;
31
31
} gx_device_pe;
32
32
#define pedev ((gx_device_pe *)dev)
33
33
 
34
34
typedef struct {
35
 
        ushort reg, val;
 
35
        ushort reg, val;
36
36
} regval;
37
37
 
38
38
#define XSIZE 720
50
50
 
51
51
static gx_device_procs pe_procs =
52
52
{       pe_open,
53
 
        NULL,                   /* get_initial_matrix */
54
 
        NULL,                   /* sync_output */
55
 
        NULL,                   /* output_page */
56
 
        pe_close,
57
 
        NULL,                   /* map_rgb_color */
58
 
        NULL,                   /* map_color_rgb */
59
 
        pe_fill_rectangle,
60
 
        NULL,                   /* tile_rectangle */
61
 
        pe_copy_mono,
62
 
        NULL                    /* copy_color */
 
53
        NULL,                   /* get_initial_matrix */
 
54
        NULL,                   /* sync_output */
 
55
        NULL,                   /* output_page */
 
56
        pe_close,
 
57
        NULL,                   /* map_rgb_color */
 
58
        NULL,                   /* map_color_rgb */
 
59
        pe_fill_rectangle,
 
60
        NULL,                   /* tile_rectangle */
 
61
        pe_copy_mono,
 
62
        NULL                    /* copy_color */
63
63
};
64
64
 
65
 
gx_device_pe far_data gs_pe_device = 
 
65
gx_device_pe far_data gs_pe_device =
66
66
{       std_device_std_body(gx_device_pe, &pe_procs, "pe",
67
 
          XSIZE, YSIZE, XPPI, YPPI),
68
 
         { 0 },         /* std_procs */
69
 
        DEFAULT_ADDRESS, DEFAULT_REGISTERS
 
67
          XSIZE, YSIZE, XPPI, YPPI),
 
68
         { 0 },         /* std_procs */
 
69
        DEFAULT_ADDRESS, DEFAULT_REGISTERS
70
70
};
71
71
 
72
72
static regval peinit[] = {{0x04, 0x1e}, {0x05, 0x00},
73
 
                          {0x04, 0x0c}, {0x05, 0x21},
74
 
                          {0x04, 0x0d}, {0x05, 0x98},
75
 
                          {0x08, 0x00}, {0x08, 0x1e},
76
 
                          {0x04, 0x1e}, {0x05, 0x01}};
 
73
                          {0x04, 0x0c}, {0x05, 0x21},
 
74
                          {0x04, 0x0d}, {0x05, 0x98},
 
75
                          {0x08, 0x00}, {0x08, 0x1e},
 
76
                          {0x04, 0x1e}, {0x05, 0x01}};
77
77
 
78
78
static regval pedone[] = {{0x04, 0x1e}, {0x05, 0x10},
79
 
                          {0x04, 0x0a}, {0x05, 0x00},
80
 
                          {0x04, 0x0b}, {0x05, 0x07},
81
 
                          {0x04, 0x0c}, {0x05, 0x00},
82
 
                          {0x04, 0x0d}, {0x05, 0x00},
83
 
                          {0x04, 0x0e}, {0x05, 0x00},
84
 
                          {0x04, 0x0f}, {0x05, 0x00},
85
 
                          {0x08, 0x00}, {0x08, 0x29}};
 
79
                          {0x04, 0x0a}, {0x05, 0x00},
 
80
                          {0x04, 0x0b}, {0x05, 0x07},
 
81
                          {0x04, 0x0c}, {0x05, 0x00},
 
82
                          {0x04, 0x0d}, {0x05, 0x00},
 
83
                          {0x04, 0x0e}, {0x05, 0x00},
 
84
                          {0x04, 0x0f}, {0x05, 0x00},
 
85
                          {0x08, 0x00}, {0x08, 0x29}};
86
86
 
87
87
int pe_open(gx_device *dev)
88
88
{
89
 
        char *str;
90
 
        int i;
 
89
        char *str;
 
90
        int i;
91
91
 
92
 
        if ((str = getenv("PEFBADDR")) != 0)
93
 
        {
94
 
                if (!sscanf(str, "%lx", &(pedev->fbaddr)))
95
 
                {
96
 
                        emprintf(dev->memory,
 
92
        if ((str = getenv("PEFBADDR")) != 0)
 
93
        {
 
94
                if (!sscanf(str, "%lx", &(pedev->fbaddr)))
 
95
                {
 
96
                        emprintf(dev->memory,
97
97
                                 "Private Eye: PEFBADDR environment string format error\n");
98
 
                        exit(1);
99
 
                }
100
 
        }
 
98
                        exit(1);
 
99
                }
 
100
        }
101
101
 
102
 
        if ((str = getenv("PEREGS")) != 0)
103
 
        {
104
 
                if (!sscanf(str, "%x", &(pedev->regs)))
105
 
                {
106
 
                        emprintf(dev->memory,
 
102
        if ((str = getenv("PEREGS")) != 0)
 
103
        {
 
104
                if (!sscanf(str, "%x", &(pedev->regs)))
 
105
                {
 
106
                        emprintf(dev->memory,
107
107
                                 "Private Eye: PEREGS environment string format error\n");
108
 
                        exit(1);
109
 
                }
110
 
        }
111
 
 
112
 
        for (i = 0; i < 10; i++)
113
 
                outportb(pedev->regs + peinit[i].reg, peinit[i].val);
114
 
 
115
 
        return 0;
 
108
                        exit(1);
 
109
                }
 
110
        }
 
111
 
 
112
        for (i = 0; i < 10; i++)
 
113
                outportb(pedev->regs + peinit[i].reg, peinit[i].val);
 
114
 
 
115
        return 0;
116
116
}
117
117
 
118
118
int pe_close(gx_device *dev)
119
119
{
120
 
        int i;
121
 
 
122
 
        /* restore the screen */
123
 
        for (i = 0; i < 16; i++)
124
 
                outportb(pedev->regs + pedone[i].reg, pedone[i].val);
125
 
 
126
 
        /* clear the frame buffer */
127
 
        memset(pedev->fbaddr, 0, 4000);
128
 
 
129
 
        return 0;
 
120
        int i;
 
121
 
 
122
        /* restore the screen */
 
123
        for (i = 0; i < 16; i++)
 
124
                outportb(pedev->regs + pedone[i].reg, pedone[i].val);
 
125
 
 
126
        /* clear the frame buffer */
 
127
        memset(pedev->fbaddr, 0, 4000);
 
128
 
 
129
        return 0;
130
130
}
131
131
 
132
132
int pe_fill_rectangle(gx_device *dev, int x1, int y1, int w, int h,
133
133
                      gx_color_index color)
134
134
{
135
 
        int x2, y2, xlen;
136
 
        byte led, red, d;
137
 
        byte *ptr;
138
 
 
139
 
        /* cull */
140
 
 
141
 
        if ((w <= 0) || (h <= 0) || (x1 > XSIZE) || (y1 > YSIZE))
142
 
                return 0;
143
 
 
144
 
        x2 = x1 + w - 1;
145
 
        y2 = y1 + h - 1;
146
 
 
147
 
        /* cull some more */
148
 
 
149
 
        if ((x2 < 0) || (y2 < 0))
150
 
                return 0;
151
 
 
152
 
        /* clip */
153
 
 
154
 
        if (x1 < 0) x1 = 0;
155
 
        if (x2 > XSIZE-1) x2 = XSIZE-1;
156
 
        if (y1 < 0) y1 = 0;
157
 
        if (y2 > YSIZE-1) y2 = YSIZE-1;
158
 
 
159
 
        w = x2 - x1 + 1;
160
 
        h = y2 - y1 + 1;
161
 
        xlen = (x2 >> 3) - (x1 >> 3) - 1;
162
 
        led = 0xff >> (x1 & 7);
163
 
        red = 0xff << (7 - (x2 & 7));
164
 
 
165
 
        ptr = pedev->fbaddr + (y1 * BPL) + (x1 >> 3);
166
 
 
167
 
        if (color)
168
 
        {
169
 
                /* here to set pixels */
170
 
                
171
 
                if (xlen == -1)
172
 
                {
173
 
                        /* special for rectangles that fit in a byte */
174
 
                        
175
 
                        d = led & red;
176
 
                        for(; h >= 0; h--, ptr += BPL)
177
 
                                *ptr |= d;
178
 
                        return 0;
179
 
                }
180
 
                
181
 
                /* normal fill */
182
 
                
183
 
                for(; h >= 0; h--, ptr += BPL)
184
 
                {       register int x = xlen;
185
 
                        register byte *p = ptr;
186
 
                        *p++ |= led;
187
 
                        while ( x-- ) *p++ = 0xff;
188
 
                        *p |= red;
189
 
                }
190
 
        }
191
 
 
192
 
        /* here to clear pixels */
193
 
 
194
 
        led = ~led;
195
 
        red = ~red;
196
 
 
197
 
        if (xlen == -1)
198
 
        {
199
 
                /* special for rectangles that fit in a byte */
200
 
                
201
 
                d = led | red;
202
 
                for(; h >= 0; h--, ptr += BPL)
203
 
                        *ptr &= d;
204
 
                return 0;
205
 
        }
206
 
 
207
 
        /* normal fill */
208
 
                
209
 
        for(; h >= 0; h--, ptr += BPL)
210
 
        {       register int x = xlen;
211
 
                register byte *p = ptr;
212
 
                *p++ &= led;
213
 
                while ( x-- ) *p++ = 0x00;
214
 
                *p &= red;
215
 
        }
216
 
        return 0;
 
135
        int x2, y2, xlen;
 
136
        byte led, red, d;
 
137
        byte *ptr;
 
138
 
 
139
        /* cull */
 
140
 
 
141
        if ((w <= 0) || (h <= 0) || (x1 > XSIZE) || (y1 > YSIZE))
 
142
                return 0;
 
143
 
 
144
        x2 = x1 + w - 1;
 
145
        y2 = y1 + h - 1;
 
146
 
 
147
        /* cull some more */
 
148
 
 
149
        if ((x2 < 0) || (y2 < 0))
 
150
                return 0;
 
151
 
 
152
        /* clip */
 
153
 
 
154
        if (x1 < 0) x1 = 0;
 
155
        if (x2 > XSIZE-1) x2 = XSIZE-1;
 
156
        if (y1 < 0) y1 = 0;
 
157
        if (y2 > YSIZE-1) y2 = YSIZE-1;
 
158
 
 
159
        w = x2 - x1 + 1;
 
160
        h = y2 - y1 + 1;
 
161
        xlen = (x2 >> 3) - (x1 >> 3) - 1;
 
162
        led = 0xff >> (x1 & 7);
 
163
        red = 0xff << (7 - (x2 & 7));
 
164
 
 
165
        ptr = pedev->fbaddr + (y1 * BPL) + (x1 >> 3);
 
166
 
 
167
        if (color)
 
168
        {
 
169
                /* here to set pixels */
 
170
 
 
171
                if (xlen == -1)
 
172
                {
 
173
                        /* special for rectangles that fit in a byte */
 
174
 
 
175
                        d = led & red;
 
176
                        for(; h >= 0; h--, ptr += BPL)
 
177
                                *ptr |= d;
 
178
                        return 0;
 
179
                }
 
180
 
 
181
                /* normal fill */
 
182
 
 
183
                for(; h >= 0; h--, ptr += BPL)
 
184
                {       register int x = xlen;
 
185
                        register byte *p = ptr;
 
186
                        *p++ |= led;
 
187
                        while ( x-- ) *p++ = 0xff;
 
188
                        *p |= red;
 
189
                }
 
190
        }
 
191
 
 
192
        /* here to clear pixels */
 
193
 
 
194
        led = ~led;
 
195
        red = ~red;
 
196
 
 
197
        if (xlen == -1)
 
198
        {
 
199
                /* special for rectangles that fit in a byte */
 
200
 
 
201
                d = led | red;
 
202
                for(; h >= 0; h--, ptr += BPL)
 
203
                        *ptr &= d;
 
204
                return 0;
 
205
        }
 
206
 
 
207
        /* normal fill */
 
208
 
 
209
        for(; h >= 0; h--, ptr += BPL)
 
210
        {       register int x = xlen;
 
211
                register byte *p = ptr;
 
212
                *p++ &= led;
 
213
                while ( x-- ) *p++ = 0x00;
 
214
                *p &= red;
 
215
        }
 
216
        return 0;
217
217
}
218
218
 
219
219
int pe_copy_mono(gx_device *dev,
220
 
                 const byte *base, int sourcex, int raster, gx_bitmap_id id,
221
 
                 int x, int y, int w, int h, 
222
 
                 gx_color_index zero, gx_color_index one)
 
220
                 const byte *base, int sourcex, int raster, gx_bitmap_id id,
 
221
                 int x, int y, int w, int h,
 
222
                 gx_color_index zero, gx_color_index one)
223
223
{
224
 
        const byte *line;
225
 
        int sleft, dleft;
226
 
        int mask, rmask;
227
 
        int invert, zmask, omask;
228
 
        byte *dest;
229
 
        int offset;
 
224
        const byte *line;
 
225
        int sleft, dleft;
 
226
        int mask, rmask;
 
227
        int invert, zmask, omask;
 
228
        byte *dest;
 
229
        int offset;
230
230
 
231
231
#define izero (int)zero
232
232
#define ione (int)one
233
233
 
234
234
if ( ione == izero )            /* vacuous case */
235
 
                return pe_fill_rectangle(dev, x, y, w, h, zero);
236
 
 
237
 
        /* clip */
238
 
 
239
 
        if ((x > XSIZE) || (y > YSIZE) || ((x + w) < 0) || ((y + h) < 0))
240
 
                return 0;
241
 
 
242
 
        offset = x >> 3;
243
 
        dest = pedev->fbaddr + (y * BPL) + offset;
244
 
        line = base + (sourcex >> 3);
245
 
        sleft = 8 - (sourcex & 7);
246
 
        dleft = 8 - (x & 7);
247
 
        mask = 0xff >> (8 - dleft);
248
 
        if ( w < dleft )
249
 
                mask -= mask >> w;
250
 
        else
251
 
                rmask = 0xff00 >> ((w - dleft) & 7);
252
 
 
253
 
        /* Macros for writing partial bytes. */
254
 
        /* bits has already been inverted by xor'ing with invert. */
 
235
                return pe_fill_rectangle(dev, x, y, w, h, zero);
 
236
 
 
237
        /* clip */
 
238
 
 
239
        if ((x > XSIZE) || (y > YSIZE) || ((x + w) < 0) || ((y + h) < 0))
 
240
                return 0;
 
241
 
 
242
        offset = x >> 3;
 
243
        dest = pedev->fbaddr + (y * BPL) + offset;
 
244
        line = base + (sourcex >> 3);
 
245
        sleft = 8 - (sourcex & 7);
 
246
        dleft = 8 - (x & 7);
 
247
        mask = 0xff >> (8 - dleft);
 
248
        if ( w < dleft )
 
249
                mask -= mask >> w;
 
250
        else
 
251
                rmask = 0xff00 >> ((w - dleft) & 7);
 
252
 
 
253
        /* Macros for writing partial bytes. */
 
254
        /* bits has already been inverted by xor'ing with invert. */
255
255
 
256
256
#define write_byte_masked(ptr, bits, mask)\
257
257
  *ptr = ((bits | ~mask | zmask) & *ptr | (bits & mask & omask))
260
260
  *ptr = ((bits | zmask) & *ptr | (bits & omask))
261
261
 
262
262
/*      if ( dev->invert )
263
 
        {
264
 
                if ( izero != (int)gx_no_color_index ) zero ^= 1;
265
 
                if ( ione != (int)gx_no_color_index ) one ^= 1;
266
 
        } */
267
 
        invert = (izero == 1 || ione == 0 ? -1 : 0);
268
 
        zmask = (izero == 0 || ione == 0 ? 0 : -1);
269
 
        omask = (izero == 1 || ione == 1 ? -1 : 0);
 
263
        {
 
264
                if ( izero != (int)gx_no_color_index ) zero ^= 1;
 
265
                if ( ione != (int)gx_no_color_index ) one ^= 1;
 
266
        } */
 
267
        invert = (izero == 1 || ione == 0 ? -1 : 0);
 
268
        zmask = (izero == 0 || ione == 0 ? 0 : -1);
 
269
        omask = (izero == 1 || ione == 1 ? -1 : 0);
270
270
 
271
271
#undef izero
272
272
#undef ione
273
273
 
274
 
        if (sleft == dleft)             /* optimize the aligned case */
275
 
        {
276
 
                w -= dleft;
277
 
                while ( --h >= 0 )
278
 
                {
279
 
                        register const byte *bptr = line;
280
 
                        int count = w;
281
 
                        register byte *optr = dest;
282
 
                        register int bits = *bptr ^ invert;     /* first partial byte */
283
 
                        
284
 
                        write_byte_masked(optr, bits, mask);
285
 
                        
286
 
                        /* Do full bytes. */
287
 
                        
288
 
                        while ((count -= 8) >= 0)
289
 
                        {
290
 
                                bits = *++bptr ^ invert;
291
 
                                ++optr;
292
 
                                write_byte(optr, bits);
293
 
                        }
294
 
                        
295
 
                        /* Do last byte */
296
 
                        
297
 
                        if (count > -8)
298
 
                        {
299
 
                                bits = *++bptr ^ invert;
300
 
                                ++optr;
301
 
                                write_byte_masked(optr, bits, rmask);
302
 
                        }
303
 
                        dest += BPL;
304
 
                        line += raster;
305
 
                }
306
 
        }
307
 
        else
308
 
        {
309
 
                int skew = (sleft - dleft) & 7;
310
 
                int cskew = 8 - skew;
311
 
                
312
 
                while (--h >= 0)
313
 
                {
314
 
                        const byte *bptr = line;
315
 
                        int count = w;
316
 
                        byte *optr = dest;
317
 
                        register int bits;
318
 
                        
319
 
                        /* Do the first partial byte */
320
 
                        
321
 
                        if (sleft >= dleft)
322
 
                        {
323
 
                                bits = *bptr >> skew;
324
 
                        }       
325
 
                        else /* ( sleft < dleft ) */
326
 
                        {
327
 
                                bits = *bptr++ << cskew;
328
 
                                if (count > sleft)
329
 
                                        bits += *bptr >> skew;
330
 
                        }
331
 
                        bits ^= invert;
332
 
                        write_byte_masked(optr, bits, mask);
333
 
                        count -= dleft;
334
 
                        optr++;
335
 
                        
336
 
                        /* Do full bytes. */
337
 
                        
338
 
                        while ( count >= 8 )
339
 
                        {
340
 
                                bits = *bptr++ << cskew;
341
 
                                bits += *bptr >> skew;
342
 
                                bits ^= invert;
343
 
                                write_byte(optr, bits);
344
 
                                count -= 8;
345
 
                                optr++;
346
 
                        }
347
 
                        
348
 
                        /* Do last byte */
349
 
                        
350
 
                        if (count > 0)
351
 
                        {
352
 
                                bits = *bptr++ << cskew;
353
 
                                if (count > skew)
354
 
                                        bits += *bptr >> skew;
355
 
                                bits ^= invert;
356
 
                                write_byte_masked(optr, bits, rmask);
357
 
                        }
358
 
                        dest += BPL;
359
 
                        line += raster;
360
 
                }
361
 
        }
362
 
        return 0;
 
274
        if (sleft == dleft)             /* optimize the aligned case */
 
275
        {
 
276
                w -= dleft;
 
277
                while ( --h >= 0 )
 
278
                {
 
279
                        register const byte *bptr = line;
 
280
                        int count = w;
 
281
                        register byte *optr = dest;
 
282
                        register int bits = *bptr ^ invert;     /* first partial byte */
 
283
 
 
284
                        write_byte_masked(optr, bits, mask);
 
285
 
 
286
                        /* Do full bytes. */
 
287
 
 
288
                        while ((count -= 8) >= 0)
 
289
                        {
 
290
                                bits = *++bptr ^ invert;
 
291
                                ++optr;
 
292
                                write_byte(optr, bits);
 
293
                        }
 
294
 
 
295
                        /* Do last byte */
 
296
 
 
297
                        if (count > -8)
 
298
                        {
 
299
                                bits = *++bptr ^ invert;
 
300
                                ++optr;
 
301
                                write_byte_masked(optr, bits, rmask);
 
302
                        }
 
303
                        dest += BPL;
 
304
                        line += raster;
 
305
                }
 
306
        }
 
307
        else
 
308
        {
 
309
                int skew = (sleft - dleft) & 7;
 
310
                int cskew = 8 - skew;
 
311
 
 
312
                while (--h >= 0)
 
313
                {
 
314
                        const byte *bptr = line;
 
315
                        int count = w;
 
316
                        byte *optr = dest;
 
317
                        register int bits;
 
318
 
 
319
                        /* Do the first partial byte */
 
320
 
 
321
                        if (sleft >= dleft)
 
322
                        {
 
323
                                bits = *bptr >> skew;
 
324
                        }
 
325
                        else /* ( sleft < dleft ) */
 
326
                        {
 
327
                                bits = *bptr++ << cskew;
 
328
                                if (count > sleft)
 
329
                                        bits += *bptr >> skew;
 
330
                        }
 
331
                        bits ^= invert;
 
332
                        write_byte_masked(optr, bits, mask);
 
333
                        count -= dleft;
 
334
                        optr++;
 
335
 
 
336
                        /* Do full bytes. */
 
337
 
 
338
                        while ( count >= 8 )
 
339
                        {
 
340
                                bits = *bptr++ << cskew;
 
341
                                bits += *bptr >> skew;
 
342
                                bits ^= invert;
 
343
                                write_byte(optr, bits);
 
344
                                count -= 8;
 
345
                                optr++;
 
346
                        }
 
347
 
 
348
                        /* Do last byte */
 
349
 
 
350
                        if (count > 0)
 
351
                        {
 
352
                                bits = *bptr++ << cskew;
 
353
                                if (count > skew)
 
354
                                        bits += *bptr >> skew;
 
355
                                bits ^= invert;
 
356
                                write_byte_masked(optr, bits, rmask);
 
357
                        }
 
358
                        dest += BPL;
 
359
                        line += raster;
 
360
                }
 
361
        }
 
362
        return 0;
363
363
}