1 /* 2 * Printer driver utilities header file for CUPS. 3 * 4 * Copyright 2007 by Apple Inc. 5 * Copyright 1993-2005 by Easy Software Products. 6 * 7 * These coded instructions, statements, and computer programs are the 8 * property of Apple Inc. and are protected by Federal copyright 9 * law. Distribution and use rights are outlined in the file "COPYING" 10 * which should have been included with this file. 11 */ 12 13 #ifndef _CUPS_FILTERS_DRIVER_H_ 14 # define _CUPS_FILTERS_DRIVER_H_ 15 16 # ifdef __cplusplus 17 extern "C" { 18 # endif /* __cplusplus */ 19 20 /* 21 * Include necessary headers... 22 */ 23 24 # include <stdio.h> 25 # include <stdlib.h> 26 # include <time.h> 27 # include <math.h> 28 # include <cups/ppd.h> 29 30 # if defined(WIN32) || defined(__EMX__) 31 # include <io.h> 32 # else 33 # include <unistd.h> 34 # include <fcntl.h> 35 # endif /* WIN32 || __EMX__ */ 36 37 # include <cups/cups.h> 38 # include <cups/raster.h> 39 40 41 /* 42 * Common macros... 43 */ 44 45 # ifndef min 46 # define min(a,b) ((a) < (b) ? (a) : (b)) 47 # define max(a,b) ((a) > (b) ? (a) : (b)) 48 # endif /* !min */ 49 50 51 /* 52 * Constants... 53 */ 54 55 #define CUPS_MAX_CHAN 15 /* Maximum number of color components */ 56 #define CUPS_MAX_LUT 4095 /* Maximum LUT value */ 57 #define CUPS_MAX_RGB 4 /* Maximum number of sRGB components */ 58 59 60 /* 61 * Types/structures for the various routines. 62 */ 63 64 typedef struct cups_lut_s /**** Lookup Table for Dithering ****/ 65 { 66 short intensity; /* Adjusted intensity */ 67 short pixel; /* Output pixel value */ 68 int error; /* Error from desired value */ 69 } cups_lut_t; 70 71 typedef struct cups_dither_s /**** Dithering State ****/ 72 { 73 int width; /* Width of buffer */ 74 int row; /* Current row */ 75 int errors[96]; /* Error values */ 76 } cups_dither_t; 77 78 typedef struct cups_sample_s /**** Color sample point ****/ 79 { 80 unsigned char rgb[3]; /* sRGB values */ 81 unsigned char colors[CUPS_MAX_RGB]; /* Color values */ 82 } cups_sample_t; 83 84 typedef struct cups_rgb_s /**** Color separation lookup table ****/ 85 { 86 int cube_size; /* Size of color cube (2-N) on a side */ 87 int num_channels; /* Number of colors per sample */ 88 unsigned char ****colors; /* 4-D array of sample values */ 89 int cube_index[256]; /* Index into cube for a given sRGB value */ 90 int cube_mult[256]; /* Multiplier value for a given sRGB value */ 91 int cache_init; /* Are cached values initialized? */ 92 unsigned char black[CUPS_MAX_RGB]; /* Cached black (sRGB = 0,0,0) */ 93 unsigned char white[CUPS_MAX_RGB]; /* Cached white (sRGB = 255,255,255) */ 94 } cups_rgb_t; 95 96 typedef struct cups_cmyk_s /**** Simple CMYK lookup table ****/ 97 { 98 unsigned char black_lut[256]; /* Black generation LUT */ 99 unsigned char color_lut[256]; /* Color removal LUT */ 100 int ink_limit; /* Ink limit */ 101 int num_channels; /* Number of components */ 102 short *channels[CUPS_MAX_CHAN]; 103 /* Lookup tables */ 104 } cups_cmyk_t; 105 106 107 /* 108 * Globals... 109 */ 110 111 extern const unsigned char 112 cups_srgb_lut[256]; 113 /* sRGB gamma lookup table */ 114 extern const unsigned char 115 cups_scmy_lut[256]; 116 /* sRGB gamma lookup table (inverted) */ 117 118 119 /* 120 * Prototypes... 121 */ 122 123 /* 124 * Attribute function... 125 */ 126 127 extern ppd_attr_t *cupsFindAttr(ppd_file_t *ppd, const char *name, 128 const char *colormodel, 129 const char *media, 130 const char *resolution, 131 char *spec, int specsize); 132 133 /* 134 * Byte checking functions... 135 */ 136 137 extern int cupsCheckBytes(const unsigned char *, int); 138 extern int cupsCheckValue(const unsigned char *, int, 139 const unsigned char); 140 141 /* 142 * Dithering functions... 143 */ 144 145 extern void cupsDitherLine(cups_dither_t *d, const cups_lut_t *lut, 146 const short *data, int num_channels, 147 unsigned char *p); 148 extern cups_dither_t *cupsDitherNew(int width); 149 extern void cupsDitherDelete(cups_dither_t *); 150 151 /* 152 * Lookup table functions for dithering... 153 */ 154 155 extern cups_lut_t *cupsLutNew(int num_vals, const float *vals); 156 extern void cupsLutDelete(cups_lut_t *lut); 157 extern cups_lut_t *cupsLutLoad(ppd_file_t *ppd, 158 const char *colormodel, 159 const char *media, 160 const char *resolution, 161 const char *ink); 162 163 164 /* 165 * Bit packing functions... 166 */ 167 168 extern void cupsPackHorizontal(const unsigned char *, 169 unsigned char *, int, 170 const unsigned char, const int); 171 extern void cupsPackHorizontal2(const unsigned char *, 172 unsigned char *, int, const int); 173 extern void cupsPackHorizontalBit(const unsigned char *, 174 unsigned char *, int, 175 const unsigned char, 176 const unsigned char); 177 extern void cupsPackVertical(const unsigned char *, unsigned char *, 178 int, const unsigned char, const int); 179 180 /* 181 * Color separation functions... 182 */ 183 184 extern void cupsRGBDelete(cups_rgb_t *rgb); 185 extern void cupsRGBDoGray(cups_rgb_t *rgb, 186 const unsigned char *input, 187 unsigned char *output, int num_pixels); 188 extern void cupsRGBDoRGB(cups_rgb_t *rgb, 189 const unsigned char *input, 190 unsigned char *output, int num_pixels); 191 extern cups_rgb_t *cupsRGBLoad(ppd_file_t *ppd, 192 const char *colormodel, 193 const char *media, 194 const char *resolution); 195 extern cups_rgb_t *cupsRGBNew(int num_samples, cups_sample_t *samples, 196 int cube_size, int num_channels); 197 198 /* 199 * CMYK separation functions... 200 */ 201 202 extern cups_cmyk_t *cupsCMYKNew(int num_channels); 203 extern void cupsCMYKDelete(cups_cmyk_t *cmyk); 204 extern void cupsCMYKDoBlack(const cups_cmyk_t *cmyk, 205 const unsigned char *input, 206 short *output, int num_pixels); 207 extern void cupsCMYKDoCMYK(const cups_cmyk_t *cmyk, 208 const unsigned char *input, 209 short *output, int num_pixels); 210 extern void cupsCMYKDoGray(const cups_cmyk_t *cmyk, 211 const unsigned char *input, 212 short *output, int num_pixels); 213 extern void cupsCMYKDoRGB(const cups_cmyk_t *cmyk, 214 const unsigned char *input, 215 short *output, int num_pixels); 216 extern cups_cmyk_t *cupsCMYKLoad(ppd_file_t *ppd, 217 const char *colormodel, 218 const char *media, 219 const char *resolution); 220 extern void cupsCMYKSetBlack(cups_cmyk_t *cmyk, 221 float lower, float upper); 222 extern void cupsCMYKSetCurve(cups_cmyk_t *cmyk, int channel, 223 int num_xypoints, 224 const float *xypoints); 225 extern void cupsCMYKSetGamma(cups_cmyk_t *cmyk, int channel, 226 float gamval, float density); 227 extern void cupsCMYKSetInkLimit(cups_cmyk_t *cmyk, float limit); 228 extern void cupsCMYKSetLtDk(cups_cmyk_t *cmyk, int channel, 229 float light, float dark); 230 231 232 /* 233 * Convenience macro for writing print data... 234 */ 235 236 # define cupsWritePrintData(s,n) fwrite((s), 1, (n), stdout) 237 238 # ifdef __cplusplus 239 } 240 # endif /* __cplusplus */ 241 242 #endif /* !_CUPS_FILTERS_DRIVER_H_ */ 243 244