Add GNU LGPL headers to all .c .C and .h files
[oweals/cde.git] / cde / lib / DtHelp / il / iljpgencodedefs.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: iljpgencodedefs.h /main/3 1995/10/23 15:56:20 rswiston $ */
24 /**---------------------------------------------------------------------
25 ***     
26 ***    (c)Copyright 1992 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
41 #ifndef ILJPGENCODEDEFS_H
42 #define ILJPGENCODEDEFS_H
43
44 #include "ilint.h"
45 #include "ilerrors.h"
46
47     /*  Equate ILJPG errors to IL errors */
48 #define ILJPG_ERROR_ENCODE_MALLOC       IL_ERROR_MALLOC
49 #define ILJPG_ERROR_ENCODE_PARS         IL_ERROR_COMPRESSED_DATA
50 #define ILJPG_ERROR_ENCODE_DCAC_TABLE   IL_ERROR_COMPRESSED_DATA
51 #define ILJPG_ERROR_ENCODE_Q_TABLE      IL_ERROR_COMPRESSED_DATA
52
53
54     /*  Define a JPEG stream: "pBuffer" points to a buffer in
55         memory, "pPastEndBuffer" points to byte just past end
56         (buffer is of size "pPastEndBuffer" - "pBuffer") and
57         pDst points to the place to store the next byte.
58     */
59 typedef struct {
60     ilPtr           pBuffer;
61     ilPtr           pDst;
62     ilPtr           pPastEndBuffer;
63     } ilJPEGEncodeStream, *ilJPEGEncodeStreamPtr;
64
65 #define ILJPG_ENCODE_STREAM ilJPEGEncodeStreamPtr
66
67
68     /*  Called by ILJPG_ENCODE_PUT_BYTE() macro to reallocate the buffer 
69         defined by "pStream" so that there is space for *exactly* "nBytes" bytes
70         to be written.  Zero (0) is returned if success else an error code.
71     */
72 IL_EXTERN iljpgError _ilReallocJPEGEncode (
73     ilJPEGEncodeStreamPtr   pStream,
74     long                    nBytes
75     );
76
77
78     /*  # of bytes by which to expand the size of the output buffer
79         when realloc'ing to write one byte.  NOTE: must be >= 1!
80     */
81 #define ILJPG_REALLOC_EXTRA   1024
82
83     /*  Macro to put a byte to a stream.  Return one (1) from macro
84         if success, else return zero (0) and set "_error" to a
85         non-zero error code.
86     */
87 #define ILJPG_ENCODE_PUT_BYTE(_stream, _byte, _error) (                 \
88     ((_stream)->pDst >= (_stream)->pPastEndBuffer) ?                    \
89         ((_error = _ilReallocJPEGEncode (_stream, ILJPG_REALLOC_EXTRA)) ? 0 : \
90             (*(_stream)->pDst++ = _byte, 1)) :                          \
91         (*(_stream)->pDst++ = _byte, 1) )
92
93     /*  Macro to return position within dst buffer, like ftell() */
94 #define ILJPG_ENCODE_OFFSET(_stream) \
95     ((_stream)->pDst - (_stream)->pBuffer)
96
97 #endif
98