1 /* libhpojip -- HP OfficeJet image-processing library. */
3 /* Copyright (C) 1995-2002 Hewlett-Packard Company
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of the
8 * License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful, but
11 * is provided AS IS, WITHOUT ANY WARRANTY; without even the implied
12 * warranty of MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, and
13 * NON-INFRINGEMENT. See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
20 * In addition, as a special exception, Hewlett-Packard Company
21 * gives permission to link the code of this program with any
22 * version of the OpenSSL library which is distributed under a
23 * license identical to that listed in the included LICENSE.OpenSSL
24 * file, and distribute linked combinations including the two.
25 * You must obey the GNU General Public License in all respects
26 * for all of the code used other than OpenSSL. If you modify
27 * this file, you may extend this exception to your version of the
28 * file, but you are not obligated to do so. If you do not wish to
29 * do so, delete this exception statement from your version.
32 /* Original author: Mark Overton and others.
34 * Ported to Linux by David Paschal.
37 /******************************************************************************\
39 * xskel.c - A skeleton xform driver on which new xforms can be based
41 * You must change "skel" and "SKEL" to your actual xform name.
43 ******************************************************************************
45 * Name of Global Jump-Table:
49 * Items in aXformInfo array passed into setXformSpec:
51 * aXformInfo[IP_SKEL_SPEC_1] = fully describe these options here, if any
52 * aXformInfo[IP_SKEL_SPEC_2] =
54 * Capabilities and Limitations:
56 * What does this xform do? What limitations of data types, ranges, etc?
58 * Default Input Traits, and Output Traits:
60 * Describe what you do with the default input traits, and how the
61 * output traits are determined.
63 * trait default input output
64 * ------------------- --------------------- ------------------------
65 * iPixelsPerRow * passed into output same as default input
66 * iBitsPerPixel * passed into output same as default input
67 * iComponentsPerPixel * passed into output same as default input
68 * lHorizDPI passed into output same as default input
69 * lVertDPI passed into output same as default input
70 * lNumRows passed into output same as default input
71 * iNumPages passed into output same as default input
72 * iPageNum passed into output same as default input
74 * Above, a "*" by an item indicates it must be valid (not negative).
76 \******************************************************************************/
78 // Use the #define below if this transform will exist in a dll outside of the
79 // image pipeline. This will allow the functions to be exported.
80 // #define EXPORT_TRANFORM 1
84 #include "string.h" /* for memset and memcpy */
90 #define PRINT(msg,arg1,arg2) \
91 _ftprintf(stderr, msg, (int)arg1, (int)arg2)
93 #define PRINT(msg,arg1,arg2)
96 #define CHECK_VALUE 0x4ba1dace
98 #ifdef EXPORT_TRANSFORM
99 #define FUNC_STATUS __declspec (dllexport)
101 #define FUNC_STATUS static
105 IP_IMAGE_TRAITS traits; /* traits of the input and output image */
106 DWORD dwBytesPerRow; /* # of bytes in each row */
107 DWORD dwRowsDone; /* number of rows converted so far */
108 DWORD dwInNextPos; /* file pos for subsequent input */
109 DWORD dwOutNextPos; /* file pos for subsequent output */
110 DWORD dwValidChk; /* struct validity check value */
111 } SKEL_INST, *PSKEL_INST;
115 /*****************************************************************************\
117 * skel_openXform - Creates a new instance of the transformer
119 *****************************************************************************
121 * This returns a handle for the new instance to be passed into
122 * all subsequent calls.
124 * Return value: IP_DONE=success; IP_FATAL_ERROR=misc error.
126 \*****************************************************************************/
128 FUNC_STATUS WORD skel_openXform (
129 IP_XFORM_HANDLE *pXform) /* out: returned handle */
133 INSURE (pXform != NULL);
134 IP_MEM_ALLOC (sizeof(SKEL_INST), g);
136 memset (g, 0, sizeof(SKEL_INST));
137 g->dwValidChk = CHECK_VALUE;
141 return IP_FATAL_ERROR;
146 /*****************************************************************************\
148 * skel_setDefaultInputTraits - Specifies default input image traits
150 *****************************************************************************
152 * The header of the file-type handled by the transform probably does
153 * not include *all* the image traits we'd like to know. Those not
154 * specified in the file-header are filled in from info provided by
157 * Return value: IP_DONE=success; IP_FATAL_ERROR=misc error.
159 \*****************************************************************************/
161 FUNC_STATUS WORD skel_setDefaultInputTraits (
162 IP_XFORM_HANDLE hXform, /* in: handle for xform */
163 PIP_IMAGE_TRAITS pTraits) /* in: default image traits */
167 HANDLE_TO_PTR (hXform, g);
169 /* insure that traits we care about are known */
170 INSURE (pTraits->iPixelsPerRow>0 && pTraits->iBitsPerPixel>0);
171 g->traits = *pTraits; /* a structure copy */
172 g->dwBytesPerRow = (g->traits.iPixelsPerRow*g->traits.iBitsPerPixel + 7) / 8;
176 return IP_FATAL_ERROR;
181 /*****************************************************************************\
183 * skel_setXformSpec - Provides xform-specific information
185 \*****************************************************************************/
187 FUNC_STATUS WORD skel_setXformSpec (
188 IP_XFORM_HANDLE hXform, /* in: handle for xform */
189 DWORD_OR_PVOID aXformInfo[]) /* in: xform information */
193 HANDLE_TO_PTR (hXform, g);
195 /* Check your options in aXformInfo here, and save them.
196 * Use the INSURE macro like you'd use assert. INSURE jumps to
197 * fatal_error below if it fails.
203 return IP_FATAL_ERROR;
208 /*****************************************************************************\
210 * skel_getHeaderBufSize- Returns size of input buf needed to hold header
212 \*****************************************************************************/
214 FUNC_STATUS WORD skel_getHeaderBufSize (
215 IP_XFORM_HANDLE hXform, /* in: handle for xform */
216 DWORD *pdwInBufLen) /* out: buf size for parsing header */
218 /* since input is raw pixels, there is no header, so set it to zero */
225 /*****************************************************************************\
227 * skel_getActualTraits - Parses header, and returns input & output traits
229 \*****************************************************************************/
231 FUNC_STATUS WORD skel_getActualTraits (
232 IP_XFORM_HANDLE hXform, /* in: handle for xform */
233 DWORD dwInputAvail, /* in: # avail bytes in input buf */
234 PBYTE pbInputBuf, /* in: ptr to input buffer */
235 PDWORD pdwInputUsed, /* out: # bytes used from input buf */
236 PDWORD pdwInputNextPos,/* out: file-pos to read from next */
237 PIP_IMAGE_TRAITS pInTraits, /* out: input image traits */
238 PIP_IMAGE_TRAITS pOutTraits) /* out: output image traits */
242 HANDLE_TO_PTR (hXform, g);
244 /* Since there is no header, we'll report no usage of input */
246 *pdwInputNextPos = 0;
249 *pInTraits = g->traits; /* structure copies */
250 *pOutTraits = g->traits;
252 return IP_DONE | IP_READY_FOR_DATA;
255 return IP_FATAL_ERROR;
260 /****************************************************************************\
262 * skel_getActualBufSizes - Returns buf sizes needed for remainder of job
264 \****************************************************************************/
266 FUNC_STATUS WORD skel_getActualBufSizes (
267 IP_XFORM_HANDLE hXform, /* in: handle for xform */
268 PDWORD pdwMinInBufLen, /* out: min input buf size */
269 PDWORD pdwMinOutBufLen) /* out: min output buf size */
273 HANDLE_TO_PTR (hXform, g);
275 *pdwMinInBufLen = *pdwMinOutBufLen = g->dwBytesPerRow;
279 return IP_FATAL_ERROR;
284 /*****************************************************************************\
286 * skel_convert - Converts one row
288 \*****************************************************************************/
290 FUNC_STATUS WORD skel_convert (
291 IP_XFORM_HANDLE hXform,
292 DWORD dwInputAvail, /* in: # avail bytes in in-buf */
293 PBYTE pbInputBuf, /* in: ptr to in-buffer */
294 PDWORD pdwInputUsed, /* out: # bytes used from in-buf */
295 PDWORD pdwInputNextPos, /* out: file-pos to read from next */
296 DWORD dwOutputAvail, /* in: # avail bytes in out-buf */
297 PBYTE pbOutputBuf, /* in: ptr to out-buffer */
298 PDWORD pdwOutputUsed, /* out: # bytes written in out-buf */
299 PDWORD pdwOutputThisPos) /* out: file-pos to write the data */
305 HANDLE_TO_PTR (hXform, g);
307 /**** Check if we were told to flush ****/
309 if (pbInputBuf == NULL) {
310 PRINT (_T("skel_convert: Told to flush.\n"), 0, 0);
311 *pdwInputUsed = *pdwOutputUsed = 0;
312 *pdwInputNextPos = g->dwInNextPos;
313 *pdwOutputThisPos = g->dwOutNextPos;
317 /**** Output a Row ****/
319 nBytes = g->dwBytesPerRow;
320 INSURE (dwInputAvail >= (DWORD)nBytes );
321 INSURE (dwOutputAvail >= (DWORD)nBytes);
326 /* At this point, pIn is your input buffer, and pOut is your output buffer.
327 * Do whatever you are going to do here.
329 memcpy(pOut,pIn,nBytes);
331 *pdwInputUsed = nBytes;
332 g->dwInNextPos += nBytes;
333 *pdwInputNextPos = g->dwInNextPos;
335 *pdwOutputUsed = nBytes;
336 *pdwOutputThisPos = g->dwOutNextPos;
337 g->dwOutNextPos += nBytes;
341 return IP_CONSUMED_ROW | IP_PRODUCED_ROW | IP_READY_FOR_DATA;
344 return IP_FATAL_ERROR;
349 /*****************************************************************************\
351 * skel_insertedData - client inserted into our output stream
353 \*****************************************************************************/
355 FUNC_STATUS WORD skel_insertedData (
356 IP_XFORM_HANDLE hXform,
360 return IP_FATAL_ERROR; /* must never be called (can't insert data) */
365 /*****************************************************************************\
367 * skel_newPage - Tells us to flush this page, and start a new page
369 \*****************************************************************************/
371 FUNC_STATUS WORD skel_newPage (
372 IP_XFORM_HANDLE hXform)
376 HANDLE_TO_PTR (hXform, g);
377 /* todo: return fatal error if convert is called again? */
378 return IP_DONE; /* can't insert page-breaks, so ignore this call */
381 return IP_FATAL_ERROR;
387 /*****************************************************************************\
389 * skel_closeXform - Destroys this instance
391 \*****************************************************************************/
393 FUNC_STATUS WORD skel_closeXform (IP_XFORM_HANDLE hXform)
397 HANDLE_TO_PTR (hXform, g);
400 IP_MEM_FREE (g); /* free memory for the instance */
405 return IP_FATAL_ERROR;
410 /*****************************************************************************\
412 * skelTbl - Jump-table for transform driver
414 \*****************************************************************************/
415 #ifdef EXPORT_TRANSFORM
416 __declspec (dllexport)
418 IP_XFORM_TBL skelTbl = {
420 skel_setDefaultInputTraits,
422 skel_getHeaderBufSize,
423 skel_getActualTraits,
424 skel_getActualBufSizes,
434 /*****************************************************************************\
436 * ipGetXformTable - Returns pointer to the jump table
438 \*****************************************************************************/
440 #ifdef EXPORT_TRANSFORM
441 EXPORT(WORD) ipGetXformTable (LPIP_XFORM_TBL pXform)
451 wRet = IP_FATAL_ERROR;