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

« back to all changes in this revision

Viewing changes to src/gdevm16.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
 
/* $Id: gdevm16.c 8250 2007-09-25 13:31:24Z giles $ */
14
 
/* 16-bit-per-pixel "memory" (stored bitmap) device */
15
 
#include "memory_.h"
16
 
#include "gx.h"
17
 
#include "gxdevice.h"
18
 
#include "gxdevmem.h"           /* semi-public definitions */
19
 
#include "gdevmem.h"            /* private definitions */
20
 
 
21
 
#undef chunk
22
 
#define chunk byte
23
 
 
24
 
/* The 16 bits are divided 5 for red, 6 for green, and 5 for blue. */
25
 
/* Note that the bits must always be kept in big-endian order. */
26
 
 
27
 
/* Procedures */
28
 
declare_mem_map_procs(mem_true16_map_rgb_color, mem_true16_map_color_rgb);
29
 
declare_mem_procs(mem_true16_copy_mono, mem_true16_copy_color, mem_true16_fill_rectangle);
30
 
 
31
 
/* The device descriptor. */
32
 
const gx_device_memory mem_true16_device =
33
 
    mem_device("image16", 16, 0,
34
 
               mem_true16_map_rgb_color, mem_true16_map_color_rgb,
35
 
               mem_true16_copy_mono, mem_true16_copy_color,
36
 
               mem_true16_fill_rectangle, mem_default_strip_copy_rop);
37
 
 
38
 
/* Map a r-g-b color to a color index. */
39
 
static gx_color_index
40
 
mem_true16_map_rgb_color(gx_device * dev, const gx_color_value cv[])
41
 
{
42
 
    return ((cv[0] >> (gx_color_value_bits - 5)) << 11) +
43
 
        ((cv[1] >> (gx_color_value_bits - 6)) << 5) +
44
 
        (cv[2] >> (gx_color_value_bits - 5));
45
 
}
46
 
 
47
 
/* Map a color index to a r-g-b color. */
48
 
static int
49
 
mem_true16_map_color_rgb(gx_device * dev, gx_color_index color,
50
 
                         gx_color_value prgb[3])
51
 
{
52
 
    ushort value = color >> 11;
53
 
 
54
 
    prgb[0] = ((value << 11) + (value << 6) + (value << 1) + (value >> 4))
55
 
                      >> (16 - gx_color_value_bits);
56
 
    value = (color >> 5) & 0x3f;
57
 
    prgb[1] = ((value << 10) + (value << 4) + (value >> 2))
58
 
                      >> (16 - gx_color_value_bits);
59
 
    value = color & 0x1f;
60
 
    prgb[2] = ((value << 11) + (value << 6) + (value << 1) + (value >> 4))
61
 
                      >> (16 - gx_color_value_bits);
62
 
    return 0;
63
 
}
64
 
 
65
 
/* Convert x coordinate to byte offset in scan line. */
66
 
#undef x_to_byte
67
 
#define x_to_byte(x) ((x) << 1)
68
 
 
69
 
/* Fill a rectangle with a color. */
70
 
static int
71
 
mem_true16_fill_rectangle(gx_device * dev,
72
 
                          int x, int y, int w, int h, gx_color_index color)
73
 
{
74
 
    gx_device_memory * const mdev = (gx_device_memory *)dev;
75
 
#if arch_is_big_endian
76
 
    const ushort color16 = (ushort)color;
77
 
#else
78
 
    const ushort color16 = (ushort)((color << 8) | (color >> 8));
79
 
#endif
80
 
    declare_scan_ptr(dest);
81
 
 
82
 
    fit_fill(dev, x, y, w, h);
83
 
    setup_rect(dest);
84
 
    if (w == 1) {
85
 
        while (h-- > 0) {
86
 
            *(ushort *)dest = color16;
87
 
            inc_ptr(dest, draster);
88
 
        }
89
 
    } else if ((color16 >> 8) == (color16 & 0xff)) {
90
 
        bytes_fill_rectangle(scan_line_base(mdev, y) + (x << 1), draster,
91
 
                             (byte)color, w << 1, h);
92
 
    } else {
93
 
        while (h-- > 0) {
94
 
            ushort *pptr = (ushort *) dest;
95
 
            int cnt = w;
96
 
 
97
 
            for (; cnt >= 4; pptr += 4, cnt -= 4)
98
 
                pptr[3] = pptr[2] = pptr[1] = pptr[0] = color16;
99
 
            switch (cnt) {
100
 
            case 3: pptr[2] = color16;
101
 
            case 2: pptr[1] = color16;
102
 
            case 1: pptr[0] = color16;
103
 
            case 0: DO_NOTHING;
104
 
            }
105
 
            inc_ptr(dest, draster);
106
 
        }
107
 
    }
108
 
    return 0;
109
 
}
110
 
 
111
 
/* Copy a monochrome bitmap. */
112
 
static int
113
 
mem_true16_copy_mono(gx_device * dev,
114
 
                     const byte * base, int sourcex, int sraster,
115
 
                     gx_bitmap_id id, int x, int y, int w, int h,
116
 
                     gx_color_index zero, gx_color_index one)
117
 
{
118
 
    gx_device_memory * const mdev = (gx_device_memory *)dev;
119
 
#if arch_is_big_endian
120
 
    const ushort zero16 = (ushort)zero;
121
 
    const ushort one16 = (ushort)one;
122
 
#else
123
 
    ushort zero16 = ((uint) (byte) zero << 8) + ((ushort) zero >> 8);
124
 
    ushort one16 = ((uint) (byte) one << 8) + ((ushort) one >> 8);
125
 
#endif
126
 
    const byte *line;
127
 
    int first_bit;
128
 
 
129
 
    declare_scan_ptr(dest);
130
 
    fit_copy(dev, base, sourcex, sraster, id, x, y, w, h);
131
 
    setup_rect(dest);
132
 
    line = base + (sourcex >> 3);
133
 
    first_bit = 0x80 >> (sourcex & 7);
134
 
    while (h-- > 0) {
135
 
        register ushort *pptr = (ushort *) dest;
136
 
        const byte *sptr = line;
137
 
        register int sbyte = *sptr++;
138
 
        register int bit = first_bit;
139
 
        int count = w;
140
 
 
141
 
        do {
142
 
            if (sbyte & bit) {
143
 
                if (one != gx_no_color_index)
144
 
                    *pptr = one16;
145
 
            } else {
146
 
                if (zero != gx_no_color_index)
147
 
                    *pptr = zero16;
148
 
            }
149
 
            if ((bit >>= 1) == 0)
150
 
                bit = 0x80, sbyte = *sptr++;
151
 
            pptr++;
152
 
        }
153
 
        while (--count > 0);
154
 
        line += sraster;
155
 
        inc_ptr(dest, draster);
156
 
    }
157
 
    return 0;
158
 
}
159
 
 
160
 
/* Copy a color bitmap. */
161
 
static int
162
 
mem_true16_copy_color(gx_device * dev,
163
 
               const byte * base, int sourcex, int sraster, gx_bitmap_id id,
164
 
                      int x, int y, int w, int h)
165
 
{
166
 
    gx_device_memory * const mdev = (gx_device_memory *)dev;
167
 
 
168
 
    fit_copy(dev, base, sourcex, sraster, id, x, y, w, h);
169
 
    mem_copy_byte_rect(mdev, base, sourcex, sraster, x, y, w, h);
170
 
    return 0;
171
 
}