Tizen 2.1 base
[platform/upstream/hplip.git] / ip / ipdefs.h
1 /* libhpojip -- HP OfficeJet image-processing library. */
2
3 /* Copyright (C) 1995-2002 Hewlett-Packard Company
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License as
7  * published by the Free Software Foundation; either version 2 of the
8  * License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * is provided AS IS, WITHOUT ANY WARRANTY; without even the implied
12  * warranty of MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, and
13  * NON-INFRINGEMENT.  See the GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
18  * MA 02111-1307, USA.
19  *
20  * In addition, as a special exception, Hewlett-Packard Company
21  * gives permission to link the code of this program with any
22  * version of the OpenSSL library which is distributed under a
23  * license identical to that listed in the included LICENSE.OpenSSL
24  * file, and distribute linked combinations including the two.
25  * You must obey the GNU General Public License in all respects
26  * for all of the code used other than OpenSSL.  If you modify
27  * this file, you may extend this exception to your version of the
28  * file, but you are not obligated to do so.  If you do not wish to
29  * do so, delete this exception statement from your version.
30  */
31
32 /* Original author: Mark Overton and others.
33  *
34  * Ported to Linux by David Paschal.
35  */
36
37 /*****************************************************************************\
38  *
39  * ipdefs.h - Definitions common among image processor files
40  *
41  * Mark Overton, Jan 1998
42  *
43 \*****************************************************************************/
44
45 #if ! defined IPDEFS_INC
46 #define IPDEFS_INC
47
48 #ifdef EXPORT_TRANSFORM
49 #define fatalBreakPoint()   assert(0);
50 #else
51 extern void fatalBreakPoint(void);
52 #endif
53
54 #define INSURE(must_be_true)                                \
55 do {                                                        \
56     if (! (must_be_true)) {                                 \
57         fatalBreakPoint();                                  \
58         goto fatal_error;                                   \
59     }                                                       \
60 } while (0)
61
62
63 #define HANDLE_TO_PTR(hJob_macpar, inst_macpar)             \
64 do {                                                        \
65     inst_macpar = (void*)hJob_macpar;                       \
66     INSURE (inst_macpar->dwValidChk == CHECK_VALUE);        \
67 } while (0)
68
69
70 #define IP_MEM_ALLOC(nBytes_macpar, ptr_macpar)                 \
71 do {                                                            \
72     /* the weirdness below is equivalent to a type cast */      \
73     /* the 12 below is buffer-overrun allowance */              \
74 /*    *(void**)&(ptr_macpar) = (void*) malloc(nBytes_macpar+12); */ \
75     (ptr_macpar) = malloc(nBytes_macpar+12);  \
76     INSURE (ptr_macpar != NULL);                                \
77 } while (0)
78
79
80 #define IP_MEM_FREE(ptr_macpar)                             \
81 do {                                                        \
82     if (ptr_macpar != NULL)                                 \
83         free (ptr_macpar);                                  \
84 } while (0)
85
86
87 #define IP_MAX(valOne,valTwo)  \
88     ((valOne)>(valTwo) ? (valOne) : (valTwo))
89
90 #define IP_MIN(valOne,valTwo)  \
91     ((valOne)<(valTwo) ? (valOne) : (valTwo))
92
93
94 /* We use approx NTSC weights of 5/16, 9/16, 2/16 for R, G and B respectively. */
95 #define NTSC_LUMINANCE(Rval,Gval,Bval)  \
96     ((((Rval)<<2) + (Rval) + ((Gval)<<3) + (Gval) + ((Bval)<<1)) >> 4)
97
98
99 /* The MUL32HIHALF macro does a signed 32x32->64 multiply, and then
100  * discards the low 32 bits, giving you the high 32 bits.  The way
101  * this is done is compiler-dependent.
102  */
103 #if 0
104 #define MUL32HIHALF(firstpar, secondpar, hihalfresult) {    \
105     __int64 prod64;                                            \
106     prod64 = (__int64)(firstpar) * (secondpar);                \
107     hihalfresult = ((int*)&prod64)[1];                        \
108     /* above, use a [0] for big endian */                    
109 #endif
110 #define MUL32HIHALF(firstpar, secondpar, hihalfresult) {       \
111     hihalfresult = ((__int64)(firstpar) * (secondpar)) >> 32;  \
112 }
113
114 #endif
115
116 /* End of File */