Add GNU LGPL headers to all .c .C and .h files
[oweals/cde.git] / cde / lib / DtHelp / il / ilint.h
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these librararies and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 /* $XConsortium: ilint.h /main/4 1996/01/08 12:14:49 lehors $ */
24 /**---------------------------------------------------------------------
25 ***     
26 ***    (c)Copyright 1991 Hewlett-Packard Co.
27 ***    
28 ***                             RESTRICTED RIGHTS LEGEND
29 ***    Use, duplication, or disclosure by the U.S. Government is subject to
30 ***    restrictions as set forth in sub-paragraph (c)(1)(ii) of the Rights in
31 ***    Technical Data and Computer Software clause in DFARS 252.227-7013.
32 ***                             Hewlett-Packard Company
33 ***                             3000 Hanover Street
34 ***                             Palo Alto, CA 94304 U.S.A.
35 ***    Rights for non-DOD U.S. Government Departments and Agencies are as set
36 ***    forth in FAR 52.227-19(c)(1,2).
37 ***
38 ***-------------------------------------------------------------------*/
39
40 #ifndef ILINT_H
41 #define ILINT_H
42
43         /*  General internal definitions for Image Library (IL).
44         */
45
46 #include <stddef.h>        /* for size_t declaration */
47 #ifndef IL_H
48 #include "il.h"
49 #endif
50 #ifndef ILPIPELEM_H
51 #include "ilpipelem.h"
52 #endif
53
54 #ifdef TRUE
55 #undef TRUE
56 #endif
57 #ifdef FALSE
58 #undef FALSE
59 #endif
60 #define FALSE 0
61 #define TRUE 1
62
63 #ifndef __STDC__
64 #ifdef NULL
65 #undef NULL
66 #endif
67 #define NULL 0
68 #endif
69
70     /*  IL_EXTERN is declared in place of "extern" for functions / data
71         that are external (in other another source file) but not public
72         (meant to be accessed by callers).  ilall.c redefines to null
73         so that external references are not generated.
74     */
75 #ifndef IL_EXTERN
76 #define IL_EXTERN extern
77 #endif
78
79     /*  IL_PRIVATE is declared for functions / data that are private
80         to the IL but need to be referenced by other source modules.
81         ilall.c redefines to "static" so external symbol is not generated.
82     */
83 #ifndef IL_PRIVATE
84 #define IL_PRIVATE
85 #endif
86
87     /*  New definitions for JPEG.  These may be moved to il.h and exposed
88         to users in the future ...
89     */
90
91         /*  ilImageDes.compInfo.JPEG.flags masks.  All other bits must be 0 */
92 #define IL_JPEGM_RAW         (1<<0)
93
94 typedef struct {
95     short               QTableIndex;
96     short               DCTableIndex;
97     short               ACTableIndex;
98     short               reserved;           /* must be zero (0) */
99     } ilJPEGSampleData;
100
101 typedef struct {
102     ilPtr               QTables[4];
103     ilPtr               DCTables[4];
104     ilPtr               ACTables[4];
105     int                 restartInterval;
106     ilJPEGSampleData    sample[IL_MAX_SAMPLES];
107     } ilJPEGData;
108
109
110         /*  Maximums that correspond to defines in /ilinc/il.h .
111             WARNING: MUST CHANGE THESE IF IL.H DEFINES CHANGE.
112             (These defines are here rather than in the public file to discourage
113             public use of "max" defines, which would break if more codes were added
114             (for example if application has a table of size MAX_?).
115         */
116 #define IL_MAX_TYPE         4           /* IL_BITONAL, etc. */
117 #define IL_MAX_COMPRESSION  5           /* IL_UNCOMPRESSED, etc. */
118 #define IL_MAX_OBJECT_TYPE  7           /* IL_NULL_OBJECT, etc. */
119 #define IL_MAX_BYTE_ORDER   1           /* IL_MSB_FIRST, etc. */
120 #define IL_MAX_SAMPLE_ORDER 2           /* IL_SAMPLE_PIXELS, etc. */
121
122
123         /*  First part of all IL objects.  More object-specific data may follow.  Notes:
124
125             refCount        reference count.  Code which "attaches" to an object (e.g.
126                             when an object is referenced in a pipe) should increment
127                             refCount, and should call ilDestroyObject() when detaching
128                             from the object.  The caller must have the same number of
129                             calls to ilDestroyObject() as inc's of refCount for object.
130         */
131
132 typedef struct {
133     ilObjectPublicRec   p;                  /* /ilinc/il.h , e.g. "context" */
134     unsigned long       refCount;           /* see notes */
135     ilPtr               pNext, pPrev;       /* private to /ilc/ilobject.c */
136     void                (*Destroy)();       /* private to /ilc/ilobject.c */
137     } ilObjectRec, *ilObjectPtr;
138
139
140         /*  From /ilc/ilobject.c : */
141         /*  Creates an object of size "sizeInBytes" and returns a ptr to it, or null
142             if failure (the error code in "context" is set in either case).  The object
143             is added to the given "context". "sizeInBytes" must be a minimum of
144             "sizeof(ilObjectRec)".
145                 The function "Destroy" will be called by ilDestroyObject(), as:
146                     Destroy (ilObjectPtr pObject);
147             Before destroying this object.  The Destroy() function must free any 
148             object-specific data etc.  It MUST not touch the fields in the object header
149             (ilObjectRec) or free *pObject.
150         */
151
152 IL_EXTERN ilObjectPtr _ilCreateObject (
153     ilContext           context,                /* context to add object to */
154     int                 objectType,             /* code for object, e.g. IL_PIPE */
155     void                (*Destroy)(),           /* destroy function; see above */
156 /* Use the portable(correct) type for sizeof() operator, bug report OSF_QAR#32082 */
157     size_t              sizeInBytes             /* size of object to create */
158     );
159
160         /*  From /ilc/ilimage.c : */
161         /*  Validate the given image descriptor at "pDes" and the image format at 
162             "pFormat" if it is non-null and validate that they are compatible 
163             with each other.
164                 If "allowPrivateTypes" is true, private image type codes are allowed;
165             otherwise an error is declared.  Should be true for client images.
166                 Return 0 (IL_OK) if valid, else error code.
167             NOTE: this function defines valid compressions and nBitsPerSample.
168         */
169 IL_EXTERN ilError _ilValidateDesFormat (
170     ilBool                  allowPrivateTypes,
171     register const ilImageDes     *pDes,
172     register const ilImageFormat  *pFormat
173     );
174
175
176         /*  From /ilc/ilcontext.c : */
177         /*  Intersect the rectangle "*pSrcRect" with the rect "*pDstRect",
178             storing the result in "*pDstRect".
179         */
180 IL_EXTERN void _ilIntersectRect (
181     ilRect             *pSrcRect,
182     ilRect             *pDstRect
183     );
184
185
186         /*  Table of shift values, indexed by YCbCr subsample values (1, 2 or 4) */
187 IL_EXTERN const int _ilSubsampleShift [];
188
189
190         /*  Allocate _nBytes from heap and return a ptr to it.
191             If IL_GARBAGE_MALLOC defined, init the alloc'd space with garbage
192             to help find unit'd vars/image errors.
193         */
194 #ifdef IL_GARBAGE_MALLOC
195
196     IL_EXTERN void *_ilMallocAndInitWithGarbage (unsigned long nBytes);
197 #   define IL_MALLOC(_nBytes)  (_ilMallocAndInitWithGarbage (_nBytes))
198
199 #else
200
201 #   define IL_MALLOC(_nBytes)  (malloc (_nBytes))
202
203 #endif
204
205         /*  Allocate _nBytes from heap, zero it, and return a ptr to it.
206         */
207 #define IL_MALLOC_ZERO(_nBytes)  (calloc ((_nBytes), 1))
208
209         /*  Reallocate the given _ptr to be of size _nBytes.
210         */
211 #define IL_REALLOC(_ptr, _nBytes)  (realloc ((_ptr), (_nBytes)))
212
213         /*  Free given block (*_ptr), allocated by IL_MALLOC[_ZERO]().
214         */
215 #define IL_FREE(_ptr)       (free (_ptr))
216
217         /*  Print the given message if debug msgs enabled.
218         */
219 #ifdef IL_DEBUG_MSGS
220 #   define IL_DEBUG(_msg)                (printf (stderr, _msg))
221 #   define IL_DEBUG_DEC(_msg, _decValue) (printf (stderr, _msg, _decValue))
222 #else
223 #   define IL_DEBUG(_msg)
224 #   define IL_DEBUG_DEC(_msg, _decValue)
225 #endif
226
227
228 #endif