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 librararies 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: ilcodec.c /main/6 1996/06/19 12:24:18 ageorge $ */
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 /* ------------------------ ilReallocCompressedBuffer ------------------------ */
48 /* Realloc (or alloc the first time) the pixel buffer for plane "plane" of the
49 compressed image "*pImage", so that its "bufferSize" is a minimum of
50 "minNewSize" bytes in size.
52 IL_PRIVATE ilBool _ilReallocCompressedBuffer (
55 unsigned long minNewSize
58 register ilImagePlaneInfo *pPlane;
60 pPlane = &pImage->plane[plane];
61 pPlane->bufferSize = minNewSize + 10000; /* A GUESS - DO SOMETHING SMARTER !!!!! */
63 if (!pPlane->pPixels) pPlane->pPixels = (ilPtr)IL_MALLOC (pPlane->bufferSize);
64 else pPlane->pPixels = (ilPtr)IL_REALLOC (pPlane->pPixels, pPlane->bufferSize);
65 if (!pPlane->pPixels) {
66 pPlane->bufferSize = 0;
73 /* ------------------------ ilCopyCompressedExecute ------------------------ */
74 /* Execute() function for ilInsertCompressedCopyFilter() to copy compressed images.
75 Copies one strip of compressed data.
77 static ilError ilCopyCompressedExecute (
78 register ilExecuteData *pData,
83 register ilImagePlaneInfo *pSrcPlane, *pDstPlane;
84 long nBytes, dstOffset, requiredBufferSize;
86 nBytes = pData->compressed.nBytesToRead; /* # of bytes to write */
87 pSrcPlane = &pData->pSrcImage->plane[0];
88 if (!pSrcPlane->pPixels || (nBytes <= 0)) /* nothing to copy; exit */
91 dstOffset = *pData->compressed.pDstOffset; /* byte offset into dst buffer */
92 pDstPlane = &pData->pDstImage->plane[0];
93 requiredBufferSize = nBytes + dstOffset; /* # bytes needed in dst buffer */
95 /* Check for space in output buffer; realloc/malloc if not enough */
96 if (requiredBufferSize > pDstPlane->bufferSize) {
97 pDstPlane->pPixels = (pDstPlane->pPixels) ?
98 (ilPtr)IL_REALLOC (pDstPlane->pPixels, requiredBufferSize) :
99 (ilPtr)IL_MALLOC (requiredBufferSize);
100 if (!pDstPlane->pPixels) {
101 pDstPlane->bufferSize = 0;
102 return IL_ERROR_MALLOC;
104 pDstPlane->bufferSize = requiredBufferSize;
107 /* Copy nBytes from src to dst buffer, using offsets from *pData */
108 bcopy ((char *)(pSrcPlane->pPixels + pData->compressed.srcOffset),
109 (char *)(pDstPlane->pPixels + dstOffset), nBytes);
110 *pData->compressed.pNBytesWritten = nBytes;
116 /* ------------------- ilInsertCompressedCopyFilter ------------------------- */
117 /* Insert a "filter" which copies the compressed pipe image to the dest image.
118 This is the equivalent to ilInsertCopyFilter(), except for compressed images.
120 IL_PRIVATE ilBool _ilInsertCompressedCopyFilter (
124 /* Add a filter which copies src to dst. No private needed; the Execute()
125 function does all necessary setup.
127 return (ilAddPipeElement (pipe, IL_FILTER, 0, 0,
128 (ilSrcElementData *)NULL, (ilDstElementData *)NULL,
129 IL_NPF, IL_NPF, IL_NPF, ilCopyCompressedExecute, NULL, 0)) ? TRUE : FALSE;