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

« back to all changes in this revision

Viewing changes to base/gxdcconv.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: gxdcconv.c 8022 2007-06-05 22:23:38Z giles $ */
 
15
/* Conversion between device color spaces for Ghostscript */
 
16
#include "gx.h"
 
17
#include "gsdcolor.h"           /* for gxcmap.h */
 
18
#include "gxdcconv.h"           /* interface */
 
19
#include "gxdevice.h"           /* for gxcmap.h */
 
20
#include "gxcmap.h"
 
21
#include "gxfarith.h"
 
22
#include "gxlum.h"
 
23
#include "gxistate.h"
 
24
 
 
25
extern bool CPSI_mode;          /* not worth polluting a header file */
 
26
 
 
27
/*
 
28
 * The CMYK to RGB algorithms specified by Adobe are, e.g.,
 
29
 *      R = 1.0 - min(1.0, C + K)
 
30
 *      C = max(0.0, min(1.0, 1 - R - UCR))
 
31
 * We got better results on displays with
 
32
 *      R = (1.0 - C) * (1.0 - K)
 
33
 *      C = max(0.0, min(1.0, 1 - R / (1 - UCR)))
 
34
 * For PLRM compatibility, we use the Adobe algorithms by default,
 
35
 * but what Adobe says and what they do are two different things.
 
36
 * Testing on CPSI shows that they use the 'better' algorithm.
 
37
 */
 
38
 
 
39
/* ------ Color space conversion ------ */
 
40
 
 
41
/* Only 4 of the 6 conversions are implemented here; */
 
42
/* the other 2 (Gray to RGB/CMYK) are trivial. */
 
43
 
 
44
/* Convert RGB to Gray. */
 
45
frac
 
46
color_rgb_to_gray(frac r, frac g, frac b, const gs_imager_state * pis)
 
47
{
 
48
    return (r * (unsigned long)lum_red_weight +
 
49
            g * (unsigned long)lum_green_weight +
 
50
            b * (unsigned long)lum_blue_weight +
 
51
            (lum_all_weights / 2))
 
52
        / lum_all_weights;
 
53
}
 
54
 
 
55
/* Convert RGB to CMYK. */
 
56
/* Note that this involves black generation and undercolor removal. */
 
57
void
 
58
color_rgb_to_cmyk(frac r, frac g, frac b, const gs_imager_state * pis,
 
59
                  frac cmyk[4])
 
60
{
 
61
    frac c = frac_1 - r, m = frac_1 - g, y = frac_1 - b;
 
62
    frac k = (c < m ? min(c, y) : min(m, y));
 
63
 
 
64
    /*
 
65
     * The default UCR and BG functions are pretty arbitrary,
 
66
     * but they must agree with the ones in gs_init.ps.
 
67
     */
 
68
    frac bg =
 
69
        (pis == NULL ? k : pis->black_generation == NULL ? frac_0 :
 
70
         gx_map_color_frac(pis, k, black_generation));
 
71
    signed_frac ucr =
 
72
        (pis == NULL ? k : pis->undercolor_removal == NULL ? frac_0 :
 
73
         gx_map_color_frac(pis, k, undercolor_removal));
 
74
 
 
75
    if (ucr == frac_1)
 
76
        cmyk[0] = cmyk[1] = cmyk[2] = 0;
 
77
    else if (ucr == frac_0)
 
78
        cmyk[0] = c, cmyk[1] = m, cmyk[2] = y;
 
79
    else {
 
80
        if (! CPSI_mode) {
 
81
            /* C = max(0.0, min(1.0, 1 - R - UCR)), etc. */
 
82
            signed_frac not_ucr = (ucr < 0 ? frac_1 + ucr : frac_1);
 
83
 
 
84
            cmyk[0] = (c < ucr ? frac_0 : c > not_ucr ? frac_1 : c - ucr);
 
85
            cmyk[1] = (m < ucr ? frac_0 : m > not_ucr ? frac_1 : m - ucr);
 
86
            cmyk[2] = (y < ucr ? frac_0 : y > not_ucr ? frac_1 : y - ucr);
 
87
        } else {
 
88
            /* Adobe CPSI method */
 
89
            /* C = max(0.0, min(1.0, 1 - R / (1 - UCR))), etc. */
 
90
            float denom = frac2float(frac_1 - ucr);             /* unscaled */
 
91
            float v;
 
92
 
 
93
            v = (float)frac_1 - r / denom;      /* unscaled */
 
94
            cmyk[0] =
 
95
                (is_fneg(v) ? frac_0 : v >= (float)frac_1 ? frac_1 : (frac) v);
 
96
            v = (float)frac_1 - g / denom;      /* unscaled */
 
97
            cmyk[1] =
 
98
                (is_fneg(v) ? frac_0 : v >= (float)frac_1 ? frac_1 : (frac) v);
 
99
            v = (float)frac_1 - b / denom;      /* unscaled */
 
100
            cmyk[2] =
 
101
                (is_fneg(v) ? frac_0 : v >= (float)frac_1 ? frac_1 : (frac) v);
 
102
        }
 
103
    }
 
104
    cmyk[3] = bg;
 
105
    if_debug7('c', "[c]RGB 0x%x,0x%x,0x%x -> CMYK 0x%x,0x%x,0x%x,0x%x\n",
 
106
              r, g, b, cmyk[0], cmyk[1], cmyk[2], cmyk[3]);
 
107
}
 
108
 
 
109
/* Convert CMYK to Gray. */
 
110
frac
 
111
color_cmyk_to_gray(frac c, frac m, frac y, frac k, const gs_imager_state * pis)
 
112
{
 
113
    frac not_gray = color_rgb_to_gray(c, m, y, pis);
 
114
 
 
115
    return (not_gray > frac_1 - k ?     /* gray + k > 1.0 */
 
116
            frac_0 : frac_1 - (not_gray + k));
 
117
}
 
118
 
 
119
/* Convert CMYK to RGB. */
 
120
void
 
121
color_cmyk_to_rgb(frac c, frac m, frac y, frac k, const gs_imager_state * pis,
 
122
                  frac rgb[3])
 
123
{
 
124
    switch (k) {
 
125
        case frac_0:
 
126
            rgb[0] = frac_1 - c;
 
127
            rgb[1] = frac_1 - m;
 
128
            rgb[2] = frac_1 - y;
 
129
            break;
 
130
        case frac_1:
 
131
            rgb[0] = rgb[1] = rgb[2] = frac_0;
 
132
            break;
 
133
        default:
 
134
            if (! CPSI_mode) {
 
135
                /* R = 1.0 - min(1.0, C + K), etc. */
 
136
                frac not_k = frac_1 - k;
 
137
 
 
138
                rgb[0] = (c > not_k ? frac_0 : not_k - c);
 
139
                rgb[1] = (m > not_k ? frac_0 : not_k - m);
 
140
                rgb[2] = (y > not_k ? frac_0 : not_k - y);
 
141
            } else {
 
142
                /* R = (1.0 - C) * (1.0 - K), etc. */
 
143
                ulong not_k = frac_1 - k;
 
144
 
 
145
                /* Compute not_k * (frac_1 - v) / frac_1 efficiently. */
 
146
                ulong prod;
 
147
 
 
148
#define deduct_black(v)\
 
149
  (prod = (frac_1 - (v)) * not_k, frac_1_quo(prod))
 
150
                rgb[0] = deduct_black(c);
 
151
                rgb[1] = deduct_black(m);
 
152
                rgb[2] = deduct_black(y);
 
153
#undef deduct_black
 
154
            }
 
155
    }
 
156
    if_debug7('c', "[c]CMYK 0x%x,0x%x,0x%x,0x%x -> RGB 0x%x,0x%x,0x%x\n",
 
157
              c, m, y, k, rgb[0], rgb[1], rgb[2]);
 
158
}