Tizen 2.1 base
[platform/upstream/hplip.git] / prnt / hpcups / CommonDefinitions.h
1 /*****************************************************************************\\r
2   CommonDefinitions.h : common header\r
3 \r
4   Copyright (c) 1996 - 2009, Hewlett-Packard Co.\r
5   All rights reserved.\r
6 \r
7   Redistribution and use in source and binary forms, with or without\r
8   modification, are permitted provided that the following conditions\r
9   are met:\r
10   1. Redistributions of source code must retain the above copyright\r
11      notice, this list of conditions and the following disclaimer.\r
12   2. Redistributions in binary form must reproduce the above copyright\r
13      notice, this list of conditions and the following disclaimer in the\r
14      documentation and/or other materials provided with the distribution.\r
15   3. Neither the name of Hewlett-Packard nor the names of its\r
16      contributors may be used to endorse or promote products derived\r
17      from this software without specific prior written permission.\r
18 \r
19   THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED\r
20   WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF\r
21   MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN\r
22   NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\r
23   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED\r
24   TO, PATENT INFRINGEMENT; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS\r
25   OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON\r
26   ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
27   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF\r
28   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
29 \r
30   Author: Naga Samrat Chowdary Narla,\r
31 \*****************************************************************************/\r
32 \r
33 #ifndef COMMON_DEFINITIONS_H\r
34 #define COMMON_DEFINITIONS_H\r
35 \r
36 #include <stdio.h>\r
37 #include <inttypes.h>\r
38 #include <stdint.h>\r
39 //#include <machine/types.h>\r
40 #include <fcntl.h>\r
41 #include <sys/stat.h>\r
42 #include <cups/cups.h>\r
43 #include <cups/raster.h>\r
44 #include <stdarg.h>\r
45 #include <stdio.h>\r
46 #include <stdlib.h>\r
47 #include <string.h>\r
48 #include <syslog.h>\r
49 #include <assert.h>\r
50 #include <time.h>\r
51 #include <sys/timeb.h>\r
52 #include <string.h>\r
53 \r
54 #ifndef _GNU_SOURCE\r
55 #define _GNU_SOURCE\r
56 #endif\r
57 \r
58 #define BASIC_LOG          1\r
59 #define SAVE_PCL_FILE      2\r
60 #define SAVE_INPUT_RASTERS 4\r
61 #define SEND_TO_PRINTER_ALSO    8\r
62 \r
63 #define MAX_COLORTYPE 2\r
64 #define NUMBER_PLANES 3\r
65 \r
66 #define ASSERT assert\r
67 \r
68 #define _STRINGIZE(x) #x\r
69 #define STRINGIZE(x) _STRINGIZE(x)\r
70 \r
71 #define dbglog(args...) {syslog(LOG_ERR, __FILE__ " " STRINGIZE(__LINE__) ": " args); \\r
72 fprintf(stderr, __FILE__ " " STRINGIZE(__LINE__) ": " args);}\r
73 \r
74 \r
75 typedef unsigned char     BYTE;\r
76 \r
77 #ifndef ABS\r
78     #define ABS(x)      ( ((x)<0) ? -(x) : (x) )\r
79 #endif\r
80 \r
81 #ifndef MIN\r
82     #define MIN(a,b)    (((a)>=(b))?(b):(a))\r
83 #endif\r
84 \r
85 #ifndef MAX\r
86     #define MAX(a,b)    (((a)<=(b))?(b):(a))\r
87 #endif\r
88 \r
89 #ifdef APDK_LITTLE_ENDIAN\r
90     #define GetRed(x) (((x >> 16) & 0x0FF))\r
91     #define GetGreen(x) (((x >> 8) & 0x0FF))\r
92     #define GetBlue(x) ((x & 0x0FF))\r
93  #else\r
94     #define GetRed(x) (((x >> 24) & 0x0FF))\r
95     #define GetGreen(x) (((x >> 16) & 0x0FF))\r
96     #define GetBlue(x) (((x >> 8) & 0x0FF))\r
97  #endif\r
98 \r
99 #ifdef BLACK_PEN\r
100     #undef BLACK_PEN\r
101 #endif\r
102 \r
103 #ifdef NO_ERROR\r
104     #undef NO_ERROR\r
105 #endif\r
106 \r
107 #define HIBYTE(sVar) (BYTE) ((sVar & 0xFF00) >> 8)\r
108 #define LOBYTE(sVar) (BYTE) ((sVar & 0x00FF))\r
109 #ifndef LOWORD\r
110     #define LOWORD(l)   ((unsigned short) (l))\r
111 #endif\r
112 \r
113 #ifndef HIWORD\r
114     #define HIWORD(l)   ((unsigned short) (((uint32_t) (l) >> 16) & 0xFFFF))\r
115 #endif\r
116 \r
117 #define PCL_BUFFER_SIZE    10000\r
118 \r
119 typedef unsigned short  UInt16;\r
120 typedef unsigned long   UInt32;\r
121 typedef unsigned char   UChar;\r
122 typedef unsigned int    Int16;\r
123 typedef long     Int32;\r
124 \r
125 typedef struct RASTERDATA\r
126 {\r
127     int      rastersize[MAX_COLORTYPE];\r
128     BYTE     *rasterdata[MAX_COLORTYPE];\r
129 } RASTERDATA;\r
130 \r
131 const int MAXCOLORDEPTH = 3;\r
132 \r
133 const int MAXCOLORPLANES = 6;   // current max anticipated, 6 for 690 photopen\r
134 \r
135 const int MAXCOLORROWS = 2;     // multiple of high-to-low for mixed-resolution cases\r
136 \r
137 enum HALFTONING_ALGORITHM\r
138 {\r
139     FED,\r
140     MATRIX\r
141 };\r
142 \r
143 /*\r
144  *  values of DRIVER_ERROR\r
145  *  Values < 0 are warnings\r
146  */\r
147 \r
148 typedef enum\r
149 {\r
150 \r
151 // general or system errors\r
152     NO_ERROR             =  0x00,    //!< everything okay\r
153     JOB_CANCELED         =  0x01,    //!< CANCEL chosen by user\r
154     SYSTEM_ERROR         =  0x02,    //!< something bad that should not have happened\r
155     ALLOCMEM_ERROR       =  0x03,    //!< failed to allocate memory\r
156     NO_PRINTER_SELECTED  =  0x04,    //!< indicates improper calling sequence or unidi\r
157     INDEX_OUT_OF_RANGE   =  0x05,    //!< what it says\r
158     ILLEGAL_RESOLUTION   =  0x06,    //!< tried to set resolution at unacceptable value\r
159     NULL_POINTER         =  0x07,    //!< supplied ptr was null\r
160     MISSING_PENS         =  0x08,    //!< one or more printhead/pen missing\r
161 \r
162 // build-related\r
163 // (items either absent from current build, or just bad index from client code)\r
164     UNSUPPORTED_PRINTER  =  0x10,    //!< selected printer-type unsupported in build\r
165     UNSUPPORTED_PEN      =  0x11,    //!< selected pen-type unsupported\r
166     GRAPHICS_UNSUPPORTED =  0x13,    //!< no graphics allowed in current build\r
167     ILLEGAL_COORDS       =  0x15,    //!< bad (x,y) passed to TextOut\r
168     BAD_INPUT_WIDTH      =  0x18,    //!< inputwidth is 0 and\r
169     OUTPUTWIDTH_EXCEEDS_PAGEWIDTH = 0x19, //!< inputwidth exceeds printable width\r
170     UNSUPPORTED_PRINTMODE = 0x19,    //!< requested printmode not available\r
171 \r
172 // I/O related\r
173     IO_ERROR             =  0x20,    //!< I/O error communicating with printer\r
174     BAD_DEVICE_ID        =  0x21,    //!< bad or garbled device id from printer\r
175     CONTINUE_FROM_BLOCK  =  0x22,    //!< continue from blocked state for printers with no buttons\r
176 \r
177 //  Runtime related\r
178     PLUGIN_LIBRARY_MISSING = 0x30,   //!< a required plugin (dynamic) library is missing\r
179 \r
180 // WARNINGS\r
181 // convention is that values < 0 can be ignored (at user's peril)\r
182     WARN_MODE_MISMATCH    =  -1,     //!< printmode selection incompatible with pen, tray, etc.\r
183     WARN_DUPLEX           =  -2,     //!< duplexer installed; our driver can't use it\r
184     WARN_LOW_INK_BOTH_PENS=  -3,     //!< sensor says pens below threshold\r
185     WARN_LOW_INK_BLACK    =  -4,     //!< sensor says black pen below threshold\r
186     WARN_LOW_INK_COLOR    =  -5,     //!< sensor says color pen below threshold\r
187 \r
188     WARN_LOW_INK_PHOTO    =  -10,    //!< sensor says photo pen below threshold\r
189     WARN_LOW_INK_GREY     =  -11,    //!< sensor says grey pen below threshold\r
190     WARN_LOW_INK_BLACK_PHOTO =  -12,     //!< sensor says black and photo pens below threshold\r
191     WARN_LOW_INK_COLOR_PHOTO =  -13,     //!< sensor says color and photo pens below threshold\r
192     WARN_LOW_INK_GREY_PHOTO  =  -14,     //!< sensor says grey and photo pens below threshold\r
193     WARN_LOW_INK_COLOR_GREY  =  -15,     //!< sensor says color and grey pens below threshold\r
194     WARN_LOW_INK_COLOR_GREY_PHOTO  =  -16,     //!< sensor says color, photo, and grey pens below threshold\r
195     WARN_LOW_INK_COLOR_BLACK_PHOTO  =  -17,     //!< sensor says color, photo, and black pens below threshold\r
196     WARN_LOW_INK_CYAN               = -18,      //!< sensor says cyan ink below threshold\r
197     WARN_LOW_INK_MAGENTA            = -19,      //!< sensor says magenta ink below threshold\r
198     WARN_LOW_INK_YELLOW             = -20,      //!< sensor says yellow ink below threshold\r
199     WARN_LOW_INK_MULTIPLE_PENS      = - 21,     //!< sensor says more than one pen below threshold\r
200     WARN_ILLEGAL_PAPERSIZE = -8,     //!< papersize illegal for given hardware\r
201     ILLEGAL_PAPERSIZE      = -8, \r
202     WARN_INVALID_MEDIA_SOURCE = -9,   //!< media source tray is invalid\r
203     \r
204     eCreate_Thread_Error = 128   //! Thread error creating the error....\r
205 } DRIVER_ERROR; //DRIVER_ERROR\r
206 \r
207 enum DUPLEXMODE\r
208 {\r
209     DUPLEXMODE_NONE,\r
210     DUPLEXMODE_BOOK,\r
211     DUPLEXMODE_TABLET\r
212 };\r
213 \r
214 enum ENDIAN_TYPE\r
215 {\r
216     LITTLEENDIAN,\r
217     BIGENDIAN\r
218 };\r
219 \r
220 // used to encourage consistent ordering of color planes\r
221 #define PLANE_K   0\r
222 #define PLANE_C   1\r
223 #define PLANE_M   2\r
224 #define PLANE_Y   3\r
225 #define Clight    4\r
226 #define Mlight    5\r
227 #define kWhite    0x00FFFFFE\r
228 \r
229 #define K         0\r
230 #define C         1\r
231 #define M         2\r
232 #define Y         3\r
233 #define Clight    4\r
234 #define Mlight    5\r
235 #define RANDSEED  77\r
236 \r
237 /*\r
238  *  ZJStream related definitions\r
239  */\r
240 \r
241 typedef uint32_t          DWORD;\r
242 typedef unsigned short    WORD;\r
243 typedef enum\r
244 {\r
245     ZJT_START_DOC,\r
246     ZJT_END_DOC,\r
247     ZJT_START_PAGE,\r
248     ZJT_END_PAGE,\r
249     ZJT_JBIG_BIH,\r
250     ZJT_JBIG_HID,\r
251     ZJT_END_JBIG,\r
252     ZJT_SIGNATURE,\r
253     ZJT_RAW_IMAGE,\r
254     ZJT_START_PLANE,\r
255     ZJT_END_PLANE,\r
256     ZJT_PAUSE,\r
257     ZJT_BITMAP\r
258 } CHUNK_TYPE;\r
259 \r
260 typedef enum\r
261 {\r
262 /* 0x00*/    ZJI_PAGECOUNT,\r
263 /* 0x01*/    ZJI_DMCOLLATE,\r
264 /* 0x02*/    ZJI_DMDUPLEX,\r
265 \r
266 /* 0x03*/    ZJI_DMPAPER,\r
267 /* 0x04*/    ZJI_DMCOPIES,\r
268 /* 0x05*/    ZJI_DMDEFAULTSOURCE,\r
269 /* 0x06*/    ZJI_DMMEDIATYPE,\r
270 /* 0x07*/    ZJI_NBIE,\r
271 /* 0x08*/    ZJI_RESOLUTION_X,\r
272 /* 0x09*/    ZJI_RESOLUTION_Y,\r
273 /* 0x0A */    ZJI_OFFSET_X,\r
274 /* 0x0B */    ZJI_OFFSET_Y,\r
275 /* 0x0C */    ZJI_RASTER_X,\r
276 /* 0x0D */    ZJI_RASTER_Y,\r
277 \r
278 /* 0x0E */    ZJI_COLLATE,\r
279 /* 0x0F */    ZJI_QUANTITY,\r
280 \r
281 /* 0x10 */    ZJI_VIDEO_BPP,\r
282 /* 0x11 */    ZJI_VIDEO_X,\r
283 /* 0x12 */    ZJI_VIDEO_Y,\r
284 /* 0x13 */    ZJI_INTERLACE,\r
285 /* 0x14 */    ZJI_PLANE,\r
286 /* 0x15 */    ZJI_PALETTE,\r
287 \r
288 /* 0x16 */    ZJI_RET,\r
289 /* 0x17 */    ZJI_TONER_SAVE,\r
290 \r
291 /* 0x18 */    ZJI_MEDIA_SIZE_X,\r
292 /* 0x19 */    ZJI_MEDIA_SIZE_Y,\r
293 /* 0x1A */    ZJI_MEDIA_SIZE_UNITS,\r
294 \r
295 /* 0x1B */    ZJI_CHROMATIC,\r
296 \r
297 /* 0x63 */    ZJI_PAD = 99,\r
298 \r
299 /* 0x64 */    ZJI_PROMPT,\r
300 \r
301 /* 0x65 */    ZJI_BITMAP_TYPE,\r
302 /* 0x66 */    ZJI_ENCODING_DATA,\r
303 /* 0x67 */    ZJI_END_PLANE,\r
304 \r
305 /* 0x68 */    ZJI_BITMAP_PIXELS,\r
306 /* 0x69 */    ZJI_BITMAP_LINES,\r
307 /* 0x6A */    ZJI_BITMAP_BPP,\r
308 /* 0x6B */    ZJI_BITMAP_STRIDE,\r
309 \r
310 } ZJ_ITEM;\r
311 \r
312 typedef enum\r
313 {\r
314     RET_OFF = 0,\r
315     RET_ON,\r
316     RET_AUTO,\r
317     RET_LIGHT,\r
318     RET_MEDIUM,\r
319     RET_DARK\r
320 } RET_VALUE;\r
321 \r
322 typedef enum\r
323 {\r
324     ZJIT_UINT32 = 1,\r
325     ZJIT_INT32,\r
326     ZJIT_STRING,\r
327     ZJIT_BYTELUT\r
328 } CHUNK_ITEM_TYPE;\r
329 \r
330 // very frequently used fragments made into macros for readability\r
331 #define CERRCHECK if (constructor_error != NO_ERROR) {dbglog("CERRCHECK fired\n"); return;}\r
332 #define ERRCHECK if (err != NO_ERROR) {dbglog("ERRCHECK fired\n"); return err;}\r
333 #define NEWCHECK(x) if (x==NULL) return ALLOCMEM_ERROR;\r
334 #define CNEWCHECK(x) if (x==NULL) { constructor_error=ALLOCMEM_ERROR; return; }\r
335 \r
336 #define CUSTOM_MEDIA_SIZE 101\r
337 \r
338 #define EVENT_PRINT_FAILED_MISSING_PLUGIN 502\r
339 enum COLORTYPE\r
340 {\r
341     COLORTYPE_COLOR,       // 0\r
342     COLORTYPE_BLACK,       // 1\r
343     COLORTYPE_BOTH\r
344 };\r
345 \r
346 typedef struct ColorMap_s\r
347 {\r
348     uint32_t *ulMap1;\r
349     uint32_t *ulMap2;\r
350     unsigned char *ulMap3;\r
351 } ColorMap;\r
352 \r
353 enum COMPRESS_MODE\r
354 {\r
355     COMPRESS_MODE0       = 0,\r
356     COMPRESS_MODE2       = 2, \r
357     COMPRESS_MODE9       = 9,\r
358     COMPRESS_MODE_AUTO   = 10,\r
359     COMPRESS_MODE_JPEG   = 11,\r
360     COMPRESS_MODE_LJ     = 12,\r
361     COMPRESS_MODE_GRAFIT = 16\r
362 };\r
363 \r
364 enum COMPRESSOR_TYPE\r
365 {\r
366     COMPRESSOR_JPEG_QUICKCONNECT,\r
367     COMPRESSOR_JPEG_JETREADY,\r
368     COMPRESSOR_TAOS\r
369 };\r
370 \r
371 const int QTABLE_SIZE =  64;\r
372 //  jpeglib.h declares these as UINT16, which is defined as unsigned short in jmorecfg.h\r
373 typedef struct QTableInfo_s\r
374 {\r
375     DWORD qtable0[QTABLE_SIZE];\r
376     DWORD qtable1[QTABLE_SIZE];\r
377     DWORD qtable2[QTABLE_SIZE];\r
378     unsigned int   qFactor;\r
379 } QTableInfo;\r
380 \r
381 typedef struct PrintMode_s\r
382 {\r
383     const char    *name;\r
384 // The resolutions can be different for different planes\r
385     unsigned int ResolutionX[MAXCOLORPLANES];\r
386     unsigned int ResolutionY[MAXCOLORPLANES];\r
387 \r
388     unsigned int ColorDepth[MAXCOLORPLANES];\r
389     unsigned int dyeCount;      // number of inks in the pen(s)\r
390 \r
391     HALFTONING_ALGORITHM eHT;\r
392 \r
393     ColorMap cmap;\r
394 \r
395     unsigned int BaseResX,BaseResY;\r
396     bool     MixedRes;\r
397 \r
398     const unsigned char* BlackFEDTable;\r
399     const unsigned char* ColorFEDTable;\r
400 } PrintMode;\r
401 \r
402 typedef struct\r
403 {\r
404     const char   *printer_platform_name;\r
405     PrintMode    *print_modes;\r
406     int          count;\r
407 } PrintModeTable;\r
408 \r
409 typedef struct QualityAttributes_s\r
410 {\r
411     int             media_type;\r
412     int             media_subtype;\r
413     int             print_quality;\r
414     unsigned int    horizontal_resolution;\r
415     unsigned int    vertical_resolution;\r
416     unsigned int    actual_vertical_resolution;\r
417     char            print_mode_name[32];\r
418 } QualityAttributes;\r
419 \r
420 typedef struct MediaAttributes_s\r
421 {\r
422     int        pcl_id;\r
423     int        physical_width;\r
424     int        physical_height;\r
425     int        printable_width;\r
426     int        printable_height;\r
427     int        printable_start_x;\r
428     int        printable_start_y;\r
429     int        horizontal_overspray;\r
430     int        vertical_overspray;\r
431     int        left_overspray; \r
432     int        top_overspray;\r
433 } MediaAttributes;\r
434 \r
435 typedef struct JobAttributes_s\r
436 {\r
437     int                media_source;\r
438     int                color_mode;\r
439     DUPLEXMODE         e_duplex_mode;\r
440     int                print_borderless;\r
441     int                krgb_mode;\r
442     int                mech_offset;\r
443     QualityAttributes  quality_attributes;\r
444     MediaAttributes    media_attributes;\r
445     int                job_id;\r
446     int                page_order;\r
447     int                total_pages;\r
448     char               job_title[128];\r
449     char               user_name[32];\r
450     char               host_name[32];\r
451     char               domain_name[32];\r
452     char               os_name[160];\r
453     char               driver_version[32];\r
454     char               driver_name[128];\r
455     char               printer_name[160];\r
456     char               job_start_time[32];\r
457     char               uuid[64];\r
458     char               printer_platform[32];\r
459     char               printer_language[32];\r
460     int                integer_values[16];\r
461     int                printer_platform_version;\r
462     int                pre_process_raster;\r
463 } JobAttributes;\r
464 \r
465 #endif // COMMON_DEFINITIONS_H\r
466 \r