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

« back to all changes in this revision

Viewing changes to base/gshsb.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: gshsb.c 8250 2007-09-25 13:31:24Z giles $ */
 
15
/* HSB color operators for Ghostscript library */
 
16
#include "gx.h"
 
17
#include "gscolor.h"
 
18
#include "gshsb.h"              /* interface definition */
 
19
#include "gxfrac.h"
 
20
 
 
21
/* Forward references */
 
22
static void color_hsb_to_rgb(floatp h, floatp s, floatp b, float rgb[3]);
 
23
static void color_rgb_to_hsb(floatp r, floatp g, floatp b, float hsb[3]);
 
24
 
 
25
/* Force a parameter into the range [0.0..1.0]. */
 
26
#define force_unit(p) (p < 0.0 ? 0.0 : p > 1.0 ? 1.0 : p)
 
27
 
 
28
/* sethsbcolor */
 
29
int
 
30
gs_sethsbcolor(gs_state * pgs, floatp h, floatp s, floatp b)
 
31
{
 
32
    float rgb[3];
 
33
 
 
34
    color_hsb_to_rgb(force_unit(h), force_unit(s), force_unit(b), rgb);
 
35
    return gs_setrgbcolor(pgs, rgb[0], rgb[1], rgb[2]);
 
36
}
 
37
 
 
38
/* currenthsbcolor */
 
39
int
 
40
gs_currenthsbcolor(const gs_state * pgs, float pr3[3])
 
41
{
 
42
    float rgb[3];
 
43
 
 
44
    gs_currentrgbcolor(pgs, rgb);
 
45
    color_rgb_to_hsb(rgb[0], rgb[1], rgb[2], pr3);
 
46
    return 0;
 
47
}
 
48
 
 
49
/* ------ Internal routines ------ */
 
50
 
 
51
/* Note: the color model conversion algorithms are taken from */
 
52
/* Rogers, Procedural Elements for Computer Graphics, pp. 401-403. */
 
53
 
 
54
/* Convert RGB to HSB. */
 
55
static void
 
56
color_rgb_to_hsb(floatp r, floatp g, floatp b, float hsb[3])
 
57
{
 
58
    frac red = float2frac(r), green = float2frac(g), blue = float2frac(b);
 
59
 
 
60
#define rhue hsb[0]
 
61
#define rsat hsb[1]
 
62
#define rbri hsb[2]
 
63
    if (red == green && green == blue) {
 
64
        rhue = 0;               /* arbitrary */
 
65
        rsat = 0;
 
66
        rbri = r;               /* pick any one */
 
67
    } else {                    /* Convert rgb to hsb */
 
68
        frac V, Temp, diff;
 
69
        long H;
 
70
 
 
71
        V = (red > green ? red : green);
 
72
        if (blue > V)
 
73
            V = blue;
 
74
        Temp = (red > green ? green : red);
 
75
        if (blue < Temp)
 
76
            Temp = blue;
 
77
        diff = V - Temp;
 
78
        if (V == red)
 
79
            H = (green - blue) * frac_1_long / diff;
 
80
        else if (V == green)
 
81
            H = (blue - red) * frac_1_long / diff + 2 * frac_1_long;
 
82
        else                    /* V == blue */
 
83
            H = (red - green) * frac_1_long / diff + 4 * frac_1_long;
 
84
        if (H < 0)
 
85
            H += 6 * frac_1_long;
 
86
        rhue = H / (frac_1 * 6.0);
 
87
        rsat = diff / (float)V;
 
88
        rbri = frac2float(V);
 
89
    }
 
90
#undef rhue
 
91
#undef rsat
 
92
#undef rbri
 
93
}
 
94
 
 
95
/* Convert HSB to RGB. */
 
96
static void
 
97
color_hsb_to_rgb(floatp hue, floatp saturation, floatp brightness, float rgb[3])
 
98
{
 
99
    if (saturation == 0) {
 
100
        rgb[0] = rgb[1] = rgb[2] = brightness;
 
101
    } else {                    /* Convert hsb to rgb. */
 
102
        /* We rely on the fact that the product of two */
 
103
        /* fracs fits into an unsigned long. */
 
104
        floatp h6 = hue * 6;
 
105
        ulong V = float2frac(brightness);       /* force arithmetic to long */
 
106
        frac S = float2frac(saturation);
 
107
        int I = (int)h6;
 
108
        ulong F = float2frac(h6 - I);   /* ditto */
 
109
 
 
110
        /* M = V*(1-S), N = V*(1-S*F), K = V*(1-S*(1-F)) = M-N+V */
 
111
        frac M = V * (frac_1_long - S) / frac_1_long;
 
112
        frac N = V * (frac_1_long - S * F / frac_1_long) / frac_1_long;
 
113
        frac K = M - N + V;
 
114
        frac R, G, B;
 
115
 
 
116
        switch (I) {
 
117
            default:
 
118
                R = V;
 
119
                G = K;
 
120
                B = M;
 
121
                break;
 
122
            case 1:
 
123
                R = N;
 
124
                G = V;
 
125
                B = M;
 
126
                break;
 
127
            case 2:
 
128
                R = M;
 
129
                G = V;
 
130
                B = K;
 
131
                break;
 
132
            case 3:
 
133
                R = M;
 
134
                G = N;
 
135
                B = V;
 
136
                break;
 
137
            case 4:
 
138
                R = K;
 
139
                G = M;
 
140
                B = V;
 
141
                break;
 
142
            case 5:
 
143
                R = V;
 
144
                G = M;
 
145
                B = N;
 
146
                break;
 
147
        }
 
148
        rgb[0] = frac2float(R);
 
149
        rgb[1] = frac2float(G);
 
150
        rgb[2] = frac2float(B);
 
151
#ifdef DEBUG
 
152
        if (gs_debug_c('c')) {
 
153
            dlprintf7("[c]hsb(%g,%g,%g)->VSFI(%ld,%d,%ld,%d)->\n",
 
154
                      hue, saturation, brightness, V, S, F, I);
 
155
            dlprintf6("   RGB(%d,%d,%d)->rgb(%g,%g,%g)\n",
 
156
                      R, G, B, rgb[0], rgb[1], rgb[2]);
 
157
        }
 
158
#endif
 
159
    }
 
160
}