2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
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)
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
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
23 /* $XConsortium: ilreadimage.c /main/3 1995/10/23 15:59:31 rswiston $ */
24 /**---------------------------------------------------------------------
26 *** (c)Copyright 1991 Hewlett-Packard Co.
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).
38 ***-------------------------------------------------------------------*/
41 #include "ilpipelem.h"
42 #include "ilpipeint.h"
47 /* Private structure for ilRCIExecute(). (RCI = "Read Compressed Image") */
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;
55 /* ------------------------- ilRCIInit ----------------------------------- */
56 /* Init() function for ilRCI().
58 static ilError ilRCIInit (
60 ilImageInfo *pSrcImage,
61 ilImageInfo *pDstImage
64 pPriv->strip = 0; /* init strip index, for first strip */
65 pPriv->nLinesWritten = 0;
69 /* --------------------- ilRCIExecute -------------------------- */
70 /* Execute() for ilReadImage() producer when the image is compressed.
72 static ilError ilRCIExecute (
74 long dstLine, /* ignored */
75 long *pNLines /* ignored on input */
82 pPriv = (ilRCIPrivPtr)pData->pPrivate;
83 pImage = pPriv->pImage;
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;
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.
92 offset = pImage->pStripOffsets[pPriv->strip];
93 *pData->compressed.pDstOffset = offset;
95 *pData->compressed.pNBytesWritten = pImage->pStripOffsets[pPriv->strip] - offset;
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;
102 pPriv->nLinesWritten += pImage->stripHeight;
103 *pNLines = pImage->stripHeight;
108 /* ------------------------ ilReadImage ---------------------------------- */
109 /* Public function: see spec.
110 Adds the given image as a producer of the pipe.
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;
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);
131 if (pImage->o.p.context != pipe->context)
132 return ilDeclarePipeInvalid (pipe, IL_ERROR_CONTEXT_MISMATCH);
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);
141 /* If uncompressed, add producer image and exit. stripHeight = image height,
142 need producer throttle filter before next element is added.
144 if (pImage->des.compression == IL_UNCOMPRESSED)
145 return _ilAddProducerImage (pipe, pImage, IL_PIPE_IMAGE, pImage->i.height,
146 pImage->i.height, TRUE, TRUE);
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.
152 if (!pImage->pStripOffsets)
153 if (!_ilAllocStripOffsets (pImage, 0))
156 if (!_ilAddProducerImage (pipe, pImage, IL_PIPE_IMAGE, pImage->i.height,
157 pImage->stripHeight, TRUE, FALSE))
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);
165 pPriv->pImage = pImage;