Tizen 2.1 base
[platform/upstream/hplip.git] / prnt / hpijs / hpijsfax.h
1 /*****************************************************************************\
2     hpijsfax.h : HP Inkjet Server
3
4     Copyright (c) 2001 - 2002, Hewlett-Packard Co.
5     All rights reserved.
6
7     Redistribution and use in source and binary forms, with or without
8     modification, are permitted provided that the following conditions
9     are met:
10     1. Redistributions of source code must retain the above copyright
11        notice, this list of conditions and the following disclaimer.
12     2. Redistributions in binary form must reproduce the above copyright
13        notice, this list of conditions and the following disclaimer in the
14        documentation and/or other materials provided with the distribution.
15     3. Neither the name of the Hewlett-Packard nor the names of its
16        contributors may be used to endorse or promote products derived
17        from this software without specific prior written permission.
18
19     THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20     IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21     OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22     IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24     NOT LIMITED TO, PATENT INFRINGEMENT; PROCUREMENT OF SUBSTITUTE GOODS OR
25     SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26     HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
27     STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
28     IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29     POSSIBILITY OF SUCH DAMAGE.
30 \*****************************************************************************/
31
32 #ifdef  HAVE_LIBHPIP
33
34 #ifndef HPIJSFAX_H
35 #define HPIJSFAX_H
36
37 #define IJS_MAX_PARAM 256
38
39 #include "bug.h"
40
41 /*
42  * Raster data encoding methods
43  */
44
45 #define RASTER_BITMAP      0
46 #define RASTER_GRAYMAP     1
47 #define RASTER_MH          2
48 #define RASTER_MR          3
49 #define RASTER_MMR         4
50 #define RASTER_RGB         5
51 #define RASTER_YCC411      6
52 #define RASTER_JPEG        7
53 #define RASTER_PCL         8
54 #define RASTER_NOT         9
55 #define RASTER_AUTO        99
56
57 #define HPLIPFAX_MONO   1
58 #define HPLIPFAX_COLOR  2
59
60 #define HPLIPPUTINT32(bytearr, val) \
61                 bytearr[0] = (val & 0xFF000000) >> 24; \
62                 bytearr[1] = (val & 0x00FF0000) >> 16; \
63                 bytearr[2] = (val & 0x0000FF00) >> 8;  \
64                 bytearr[3] = (val & 0x000000FF)
65
66 #define HPLIPPUTINT16(bytearr, val) \
67                 bytearr[0] = (val & 0x0000FF00) >> 8; \
68                 bytearr[1] = (val & 0x000000FF)
69
70 /*
71 typedef struct
72 {
73     char                szHeader[8];
74     uint32_t    uiVersion;
75         uint32_t        uiNumPages;                             // >= 1
76         uint32_t        uiHorzRes;                              // 200 or 300
77         uint32_t        uiVertRes;                              // 100, 200 or 300
78         uint32_t        uiPageSize;                             // Letter - 1, A4 - 2, Legal - 3
79         uint32_t        uiOutputQuality;                // Standard - 1, Fine - 2 or Super Fine - 3
80         uint32_t        uiReserved;
81 } HPLIPFaxFileHeader;
82
83 typedef struct
84 {
85         uint32_t        uiPageNum;
86         uint32_t        uiPixelsPerRow;
87         uint32_t        uiNumOfRowsThisPage;
88         uint32_t        uiImageSize;                    // Size of fax data only, in bytes
89         uint32_t        uiReserved;
90 } HPLIPFaxPageHeader;
91 */
92
93 class HPIJSFax
94 {
95
96 public:
97         HPIJSFax ()
98         {
99                 iQuality = 2;
100                 iColorMode = 1;
101                 iMediaType = 0;
102                 iPaperSize = 1;
103                 iFirstRaster = 1;
104                 iFaxEncoding = RASTER_MH;
105                 fPaperWidth = 8.5;
106                 fPaperHeight = 11.0;
107         strcpy (m_szDeviceName, "HPFax");
108         }
109         char    *GetDeviceName ()
110     {
111         return m_szDeviceName;
112     }
113     void    SetDeviceName (char *szDeviceName)
114     {
115         strcpy (m_szDeviceName, szDeviceName);
116     }
117         void    SetOutputPath (int fd)
118         {
119                 iOutputPath = fd;
120         }
121         void    SetPaperSize (float w, float h)
122         {
123                 fPaperWidth = w;
124                 fPaperHeight = h;
125                 if (fabs (8.5 - w) < 0.05 && fabs (11.0 - w) < 0.05)
126                 {
127                     iPaperSize = 1;
128                 }
129                 else if (fabs (8.27 - w) < 0.05 && fabs (11.69 - h) < 0.05)
130                 {
131                     iPaperSize = 2;
132                 }
133                 else if (fabs (8.5 - w) < 0.05 && fabs (14.0 - h) < 0.05)
134                 {
135                     iPaperSize = 3;
136                 }
137         }
138         void    SetPaperWidth (float w)
139         {
140             fPaperWidth = w;
141         }
142         void    SetPaperHeight (float h)
143         {
144                 fPaperHeight = h;
145         }
146         int             GetQuality ()
147         {
148                 return iQuality;
149         }
150         void    SetQuality (int iQ)
151         {
152             iQuality = iQ;
153         }
154         void    SetMediaType (int iM)
155         {
156             iMediaType = iM;
157         }
158         void    SetColorMode (int iCm)
159         {
160                 iColorMode = iCm; // 1 - Monochrome, 2 - Color
161                 if (iCm == HPLIPFAX_COLOR)
162                 {
163                     iFaxEncoding = RASTER_JPEG;
164                 }
165         }
166         void    SetFirstRaster (int iFirst)
167         {
168                 iFirstRaster = iFirst;
169         }
170         void    SetFaxEncoding (int iVal)
171         {
172             iFaxEncoding = iVal;
173                 if (iColorMode == HPLIPFAX_COLOR)
174                 {
175                     iFaxEncoding = RASTER_JPEG;
176                         return;
177                 }
178                 if (iVal == RASTER_AUTO)
179                 {
180                     char        *pDev = getenv ("DEVICE_URI");
181                         iFaxEncoding = RASTER_MH;
182                         if (pDev == NULL)
183                         {
184                             return;
185                         }
186                         if ((strstr (pDev, "Laser") || strstr (pDev, "laser")))
187                         {
188                             iFaxEncoding = RASTER_MMR;
189                         }
190                 }
191         }
192
193         int             GetFaxEncoding ()
194         {
195                 return iFaxEncoding;
196         }
197         int             GetColorMode ()
198         {
199                 return iColorMode;
200         }
201         int             GetMediaType ()
202         {
203                 return iMediaType;
204         }
205         int             GetPaperSize ()
206         {
207                 return iPaperSize;
208         }
209         float   GetPaperWidth ()
210         {
211                 return fPaperHeight;
212         }
213         float   GetPaperHeight ()
214         {
215                 return fPaperHeight;
216         }
217         int             IsFirstRaster ()
218         {
219                 return iFirstRaster;
220         }
221         float   PrintableStartX ()
222         {
223                 //return (float) 0.25;
224                 return (float) 0.125;
225         }
226         float   PrintableStartY ()
227         {
228                 return (float) 0.125;
229         }
230         float   PrintableWidth ()
231         {
232                 return fPaperWidth - (2.0 * 0.125);
233         }
234         float   PrintableHeight ()
235         {
236                 return fPaperHeight - (2.0 * 0.125);
237         }
238         float   PhysicalPageSizeX ()
239         {
240                 return fPaperWidth;
241         }
242         float   PhysicalPageSizeY ()
243         {
244                 return fPaperHeight;
245         }
246         int             EffectiveResolutionX ()
247         {
248                 if (iQuality == 3)
249                 {
250                     return 300;
251                 }
252                 return 200;
253         }
254         int             EffectiveResolutionY ()
255         {
256                 if (iQuality == 2)
257                 {
258                     return 200;
259                 }
260                 if (iQuality == 3)
261                 {
262                     return 300;
263                 }
264                 return 100;
265         }
266
267     IjsPageHeader       ph;
268         int                             iOutputPath;
269 private:
270     int         iQuality;
271         int             iColorMode;
272         int             iMediaType;
273         int             iPaperSize;
274         int             iFaxEncoding;
275         float   fPaperWidth;
276         float   fPaperHeight;
277         int             iFirstRaster;
278         char    m_szDeviceName[64];
279 };
280
281 void RGB2Gray (BYTE *pRGBData, int iNumPixels, BYTE *pBWData);
282
283 #endif        /* HPIJSFAX_H */
284
285 #endif // HAVE_LIBHPIP
286