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

« back to all changes in this revision

Viewing changes to devices/gdevtfnx.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
/* 12-bit & 24-bit RGB uncompressed TIFF driver */
 
18
 
 
19
#include "stdint_.h"   /* for tiff.h */
 
20
#include "gdevtifs.h"
 
21
#include "gdevprn.h"
 
22
#include "gscms.h"
 
23
 
 
24
#include "gstiffio.h"
 
25
 
 
26
/*
 
27
 * Thanks to Alan Barclay <alan@escribe.co.uk> for donating the original
 
28
 * version of this code to Ghostscript.
 
29
 */
 
30
 
 
31
/* ------ The device descriptors ------ */
 
32
 
 
33
/* Default X and Y resolution */
 
34
#define X_DPI 72
 
35
#define Y_DPI 72
 
36
 
 
37
static dev_proc_print_page(tiff12_print_page);
 
38
static dev_proc_print_page(tiff_rgb_print_page);
 
39
 
 
40
/* FIXME: From initial analysis this is NOT safe for bg_printing, but might be fixable */
 
41
 
 
42
static const gx_device_procs tiff12_procs =
 
43
prn_color_params_procs(tiff_open, gdev_prn_output_page_seekable, tiff_close,
 
44
                gx_default_rgb_map_rgb_color, gx_default_rgb_map_color_rgb,
 
45
                tiff_get_params, tiff_put_params);
 
46
static const gx_device_procs tiff24_procs =
 
47
prn_color_params_procs(tiff_open, gdev_prn_output_page_seekable, tiff_close,
 
48
                gx_default_rgb_map_rgb_color, gx_default_rgb_map_color_rgb,
 
49
                tiff_get_params, tiff_put_params);
 
50
 
 
51
const gx_device_tiff gs_tiff12nc_device = {
 
52
    prn_device_std_body(gx_device_tiff, tiff12_procs, "tiff12nc",
 
53
                        DEFAULT_WIDTH_10THS, DEFAULT_HEIGHT_10THS,
 
54
                        X_DPI, Y_DPI,
 
55
                        0, 0, 0, 0,
 
56
                        24, tiff12_print_page),
 
57
    arch_is_big_endian          /* default to native endian (i.e. use big endian iff the platform is so*/,
 
58
    false,                      /* default to not bigtiff */
 
59
    COMPRESSION_NONE,
 
60
    TIFF_DEFAULT_STRIP_SIZE,
 
61
    TIFF_DEFAULT_DOWNSCALE,
 
62
    0, /* Adjust size */
 
63
    1  /* MinFeatureSize */
 
64
};
 
65
 
 
66
const gx_device_tiff gs_tiff24nc_device = {
 
67
    prn_device_std_body(gx_device_tiff, tiff24_procs, "tiff24nc",
 
68
                        DEFAULT_WIDTH_10THS, DEFAULT_HEIGHT_10THS,
 
69
                        X_DPI, Y_DPI,
 
70
                        0, 0, 0, 0,
 
71
                        24, tiff_rgb_print_page),
 
72
    arch_is_big_endian          /* default to native endian (i.e. use big endian iff the platform is so*/,
 
73
    false,                      /* default to not bigtiff */
 
74
    COMPRESSION_NONE,
 
75
    TIFF_DEFAULT_STRIP_SIZE,
 
76
    TIFF_DEFAULT_DOWNSCALE,
 
77
    0, /* Adjust size */
 
78
    1  /* MinFeatureSize */
 
79
};
 
80
 
 
81
const gx_device_tiff gs_tiff48nc_device = {
 
82
    prn_device_std_body(gx_device_tiff, tiff24_procs, "tiff48nc",
 
83
                        DEFAULT_WIDTH_10THS, DEFAULT_HEIGHT_10THS,
 
84
                        X_DPI, Y_DPI,
 
85
                        0, 0, 0, 0,
 
86
                        48, tiff_rgb_print_page),
 
87
    arch_is_big_endian          /* default to native endian (i.e. use big endian iff the platform is so*/,
 
88
    false,                      /* default to not bigtiff */
 
89
    COMPRESSION_NONE,
 
90
    TIFF_DEFAULT_STRIP_SIZE,
 
91
    TIFF_DEFAULT_DOWNSCALE,
 
92
    0, /* Adjust size */
 
93
    1  /* MinFeatureSize */
 
94
};
 
95
 
 
96
/* ------ Private functions ------ */
 
97
 
 
98
static void
 
99
tiff_set_rgb_fields(gx_device_tiff *tfdev)
 
100
{
 
101
    /* Put in a switch statement in case we want to have others */
 
102
    switch (tfdev->icc_struct->device_profile[0]->data_cs) {
 
103
        case gsRGB:
 
104
            TIFFSetField(tfdev->tif, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB);
 
105
            break;
 
106
        case gsCIELAB:
 
107
            TIFFSetField(tfdev->tif, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_ICCLAB);
 
108
            break;
 
109
        default:
 
110
            TIFFSetField(tfdev->tif, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB);
 
111
            break;
 
112
    }
 
113
    TIFFSetField(tfdev->tif, TIFFTAG_FILLORDER, FILLORDER_MSB2LSB);
 
114
    TIFFSetField(tfdev->tif, TIFFTAG_SAMPLESPERPIXEL, 3);
 
115
 
 
116
    tiff_set_compression((gx_device_printer *)tfdev, tfdev->tif,
 
117
                         tfdev->Compression, tfdev->MaxStripSize);
 
118
}
 
119
 
 
120
static int
 
121
tiff12_print_page(gx_device_printer * pdev, FILE * file)
 
122
{
 
123
    gx_device_tiff *const tfdev = (gx_device_tiff *)pdev;
 
124
    int code;
 
125
 
 
126
    /* open the TIFF device */
 
127
    if (gdev_prn_file_is_new(pdev)) {
 
128
        tfdev->tif = tiff_from_filep(pdev, pdev->dname, file, tfdev->BigEndian, tfdev->UseBigTIFF);
 
129
        if (!tfdev->tif)
 
130
            return_error(gs_error_invalidfileaccess);
 
131
    }
 
132
 
 
133
    code = gdev_tiff_begin_page(tfdev, file);
 
134
    if (code < 0)
 
135
        return code;
 
136
 
 
137
    TIFFSetField(tfdev->tif, TIFFTAG_BITSPERSAMPLE, 4);
 
138
    tiff_set_rgb_fields(tfdev);
 
139
 
 
140
    TIFFCheckpointDirectory(tfdev->tif);
 
141
 
 
142
    /* Write the page data. */
 
143
    {
 
144
        int y;
 
145
        int size = gdev_prn_raster(pdev);
 
146
        byte *data = gs_alloc_bytes(pdev->memory, size, "tiff12_print_page");
 
147
 
 
148
        if (data == 0)
 
149
            return_error(gs_error_VMerror);
 
150
 
 
151
        memset(data, 0, size);
 
152
 
 
153
        for (y = 0; y < pdev->height; ++y) {
 
154
            const byte *src;
 
155
            byte *dest;
 
156
            int x;
 
157
 
 
158
            code = gdev_prn_copy_scan_lines(pdev, y, data, size);
 
159
            if (code < 0)
 
160
                break;
 
161
 
 
162
            for (src = data, dest = data, x = 0; x < size;
 
163
                 src += 6, dest += 3, x += 6
 
164
                ) {
 
165
                dest[0] = (src[0] & 0xf0) | (src[1] >> 4);
 
166
                dest[1] = (src[2] & 0xf0) | (src[3] >> 4);
 
167
                dest[2] = (src[4] & 0xf0) | (src[5] >> 4);
 
168
            }
 
169
            TIFFWriteScanline(tfdev->tif, data, y, 0);
 
170
        }
 
171
        gs_free_object(pdev->memory, data, "tiff12_print_page");
 
172
 
 
173
        TIFFWriteDirectory(tfdev->tif);
 
174
    }
 
175
 
 
176
    return code;
 
177
}
 
178
 
 
179
static int
 
180
tiff_rgb_print_page(gx_device_printer * pdev, FILE * file)
 
181
{
 
182
    gx_device_tiff *const tfdev = (gx_device_tiff *)pdev;
 
183
    int code;
 
184
 
 
185
    /* open the TIFF device */
 
186
    if (gdev_prn_file_is_new(pdev)) {
 
187
        tfdev->tif = tiff_from_filep(pdev, pdev->dname, file, tfdev->BigEndian, tfdev->UseBigTIFF);
 
188
        if (!tfdev->tif)
 
189
            return_error(gs_error_invalidfileaccess);
 
190
    }
 
191
 
 
192
    code = gdev_tiff_begin_page(tfdev, file);
 
193
    if (code < 0)
 
194
        return code;
 
195
 
 
196
    TIFFSetField(tfdev->tif, TIFFTAG_BITSPERSAMPLE,
 
197
                 pdev->color_info.depth / pdev->color_info.num_components);
 
198
    tiff_set_rgb_fields(tfdev);
 
199
 
 
200
    /* Write the page data. */
 
201
    return tiff_print_page(pdev, tfdev->tif, 0);
 
202
}