lib/DtHelp/il: remove register keyword
[oweals/cde.git] / cde / lib / DtHelp / il / ilreadimage.c
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 libraries 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: ilreadimage.c /main/3 1995/10/23 15:59:31 rswiston $ */
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 #include "ilint.h"
41 #include "ilpipelem.h"
42 #include "ilpipeint.h"
43 #include "ilimage.h"
44 #include "ilerrors.h"
45
46
47         /*  Private structure for ilRCIExecute(). (RCI = "Read Compressed Image") */
48 typedef struct {
49     ilImagePtr          pImage;             /* ptr to src image */
50     long                strip;              /* Init(): index of next strip to write */
51     long                nLinesWritten;      /* Init(): # of lines written so far */
52     } ilRCIPrivRec, *ilRCIPrivPtr;
53
54
55     /*  ------------------------- ilRCIInit ----------------------------------- */
56     /*  Init() function for ilRCI().
57     */
58 static ilError ilRCIInit (
59     ilRCIPrivPtr        pPriv,
60     ilImageInfo        *pSrcImage,
61     ilImageInfo        *pDstImage
62     )
63 {
64     pPriv->strip = 0;                       /* init strip index, for first strip */
65     pPriv->nLinesWritten = 0;
66     return IL_OK;
67 }
68
69     /*  --------------------- ilRCIExecute -------------------------- */
70     /*  Execute() for ilReadImage() producer when the image is compressed.
71     */
72 static ilError ilRCIExecute (
73     ilExecuteData  *pData,
74     long                    dstLine,            /* ignored */
75     long                   *pNLines             /* ignored on input */
76     )
77 {
78 ilRCIPrivPtr       pPriv;
79 ilImagePtr         pImage;
80 long                        offset;
81
82     pPriv = (ilRCIPrivPtr)pData->pPrivate;
83     pImage = pPriv->pImage;
84
85         /*  Return error if image has never been written to. */
86     if (!pImage->pStripOffsets || !pImage->i.plane[0].pPixels)
87         return IL_ERROR_NULL_COMPRESSED_IMAGE;
88
89         /*  "write" current strip by patching next filter's offset to offset for
90             current strip, and setting its # bytes to size of this strip.
91         */
92     offset = pImage->pStripOffsets[pPriv->strip];
93     *pData->compressed.pDstOffset = offset;
94     pPriv->strip++;
95     *pData->compressed.pNBytesWritten = pImage->pStripOffsets[pPriv->strip] - offset;
96
97         /*  If last strip, # of lines is remaining, else is strip height */
98     if ((pPriv->nLinesWritten + pImage->stripHeight) > pImage->i.height) {
99         *pNLines = pImage->i.height - pPriv->nLinesWritten;
100         return IL_ERROR_LAST_STRIP;
101         }
102     pPriv->nLinesWritten += pImage->stripHeight;
103     *pNLines = pImage->stripHeight;
104     return IL_OK;
105 }
106
107
108         /*  ------------------------ ilReadImage ---------------------------------- */
109         /*  Public function: see spec.
110             Adds the given image as a producer of the pipe.
111         */
112 ilBool ilReadImage (
113     ilPipe              pipe,
114     ilObject            image
115     )
116 {
117 ilImagePtr     pImage;
118 ilRCIPrivPtr   pPriv;
119
120         /*  Validate that pipe and image are such, have same context and pipe empty */
121     pImage = (ilImagePtr)image;
122     if (pipe->objectType != IL_PIPE) {
123         pipe->context->error = IL_ERROR_OBJECT_TYPE;
124         return FALSE;
125         }
126
127     if ((pImage->o.p.objectType != IL_INTERNAL_IMAGE) 
128      && (pImage->o.p.objectType != IL_CLIENT_IMAGE))
129         return ilDeclarePipeInvalid (pipe, IL_ERROR_OBJECT_TYPE);
130
131     if (pImage->o.p.context != pipe->context)
132         return ilDeclarePipeInvalid (pipe, IL_ERROR_CONTEXT_MISMATCH);
133
134     if (ilGetPipeInfo (pipe, FALSE, (ilPipeInfo *)NULL, (ilImageDes *)NULL, 
135                                     (ilImageFormat *)NULL) != IL_PIPE_EMPTY) {
136         if (!pipe->context->error)
137             ilDeclarePipeInvalid (pipe, IL_ERROR_PIPE_STATE);
138         return FALSE;
139         }
140
141         /*  If uncompressed, add producer image and exit.  stripHeight = image height, 
142             need producer throttle filter before next element is added.
143         */
144     if (pImage->des.compression == IL_UNCOMPRESSED)
145         return _ilAddProducerImage (pipe, pImage, IL_PIPE_IMAGE, pImage->i.height, 
146                                    pImage->i.height, TRUE, TRUE);
147
148         /*  Image is compressed: if no stripHeight yet, allocate strip offsets array using
149             default strip height.  Add producer image: constant strips the size of the 
150             image's strip height.  Add producer throttle to feed each strip.
151         */
152     if (!pImage->pStripOffsets)
153         if (!_ilAllocStripOffsets (pImage, 0))
154             return FALSE;
155
156     if (!_ilAddProducerImage (pipe, pImage, IL_PIPE_IMAGE, pImage->i.height, 
157                              pImage->stripHeight, TRUE, FALSE))
158         return FALSE;
159
160     pPriv = (ilRCIPrivPtr)ilAddPipeElement (pipe, IL_FILTER, sizeof (ilRCIPrivRec), 
161         IL_ADD_PIPE_NO_DST, (ilSrcElementData *)NULL, (ilDstElementData *)NULL, 
162         ilRCIInit, IL_NPF, IL_NPF, ilRCIExecute, 0);
163     if (!pPriv)
164         return FALSE;
165     pPriv->pImage = pImage;
166
167     return TRUE;
168 }
169