Tizen 2.1 base
[platform/upstream/hplip.git] / prnt / hpijs / ernieplatform.h
1 /*****************************************************************************\
2   ernieplatform.h : Interface for ernie
3
4   Copyright (c) 1996 - 2001, 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 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 IMPLIED
20   WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21   MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN
22   NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
24   TO, PATENT INFRINGEMENT; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
25   OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26   ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 \*****************************************************************************/
30
31
32 APDK_BEGIN_NAMESPACE
33
34 // Endianess of the architecture we're on
35 #ifdef APDK_LITTLE_ENDIAN
36     #define bigEndian       0
37     #define littleEndian    1
38     #define GetRed(x) (((x >> 16) & 0x0FF))
39     #define GetGreen(x) (((x >> 8) & 0x0FF))
40     #define GetBlue(x) ((x & 0x0FF))
41 #else
42     #define bigEndian       1
43     #define littleEndian    0
44     #define GetRed(x) (((x >> 24) & 0x0FF))
45     #define GetGreen(x) (((x >> 16) & 0x0FF))
46     #define GetBlue(x) (((x >> 8) & 0x0FF))
47 #endif
48
49 /*#define GetRed(x) (((x >> 24) & 0x0FF))
50 #define GetGreen(x) (((x >> 16) & 0x0FF))
51 #define GetBlue(x) (((x >> 8) & 0x0FF))*/
52
53 // Slow down the system and gather stats or not.
54 #define kGatherStats    0
55 #define kDecompressStats 0
56
57 // ********** THIS IS NOT TRUE **************
58 // While it may seem like the need to be both
59 // big endian and little endian versions of
60 // these macros, due to the face that the
61 // shift command in general knows about the
62 // endian order, you get the same result
63 // from these commands no matter what order
64 // the bytes are in.  Strange isn't it.
65 //#define GetRed(x) (((x >> 16) & 0x0FF))
66 //#define GetRed(x) (((x >> 24) & 0x0FF))
67 //#define GetGreen(x) (((x >> 8) & 0x0FF))
68 //#define GetGreen(x) (((x >> 16) & 0x0FF))
69 //#define GetBlue(x) ((x & 0x0FF))
70 //#define GetBlue(x) (((x >> 8) & 0x0FF))
71 // ******************************************
72
73 #ifndef MIN
74 #define MIN(a,b)    (((a)>=(b))?(b):(a))
75 #endif
76 #ifndef MAX
77 #define MAX(a,b)    (((a)<=(b))?(b):(a))
78 #endif
79
80 #define kWhite 0x00FFFFFE
81
82 //inline unsigned int get4Pixel(unsigned char *pixAddress);
83 //inline unsigned int get4Pixel(unsigned char *pixAddress)
84 //inline uint32_t get4Pixel(unsigned char *pixAddress);
85
86 inline uint32_t get4Pixel(unsigned char *pixAddress)
87 {
88 //  slower simple code
89 //  unsigned int toReturn = *((unsigned int*)pixAddress); // load toReturn with XRGB
90 //  toReturn &= kWhite; // Strip off unwanted X. EGW stripped lsb blue.
91 //
92 //  return toReturn;
93
94 #ifdef APDK_LITTLE_ENDIAN
95     return (((unsigned int*)pixAddress)[0]) & kWhite;
96 #else
97     return (((unsigned int*)pixAddress)[0]) & 0xFFFFFF00;
98 #endif
99 }
100
101
102 //inline unsigned int get4Pixel(unsigned char *pixAddress, int pixelOffset);
103 //inline unsigned int get4Pixel(unsigned char *pixAddress, int pixelOffset)
104 //inline uint32_t get4Pixel(unsigned char *pixAddress, int pixelOffset);
105
106 inline uint32_t get4Pixel(unsigned char *pixAddress, int pixelOffset)
107 {
108 //  slower simple code
109 //  unsigned int *uLongPtr = (unsigned int *)pixAddress;
110 //  uLongPtr += pixelOffset;
111 //
112 //  return *uLongPtr & kWhite;
113
114 #ifdef APDK_LITTLE_ENDIAN
115     return ((unsigned int*)pixAddress)[pixelOffset] & kWhite;
116 #else
117     return ((unsigned int*)pixAddress)[pixelOffset] & 0xFFFFFF00;
118 #endif
119 }
120
121 //void put3Pixel(unsigned char *pixAddress, int pixelOffset, unsigned int pixel);
122 void put3Pixel(unsigned char *pixAddress, int pixelOffset, uint32_t pixel);
123
124 //inline void put4Pixel(unsigned char *pixAddress, int pixelOffset, unsigned int pixel);
125 //inline void put4Pixel(unsigned char *pixAddress, int pixelOffset, unsigned int pixel)
126 //inline void put4Pixel(unsigned char *pixAddress, int pixelOffset, uint32_t pixel);
127
128 inline void put4Pixel(unsigned char *pixAddress, int pixelOffset, uint32_t pixel)
129 {
130 #ifdef APDK_LITTLE_ENDIAN
131     (((unsigned int*)pixAddress)[pixelOffset] = pixel & kWhite);
132 #else
133     (((unsigned int*)pixAddress)[pixelOffset] = pixel & 0xFFFFFF00);
134 #endif
135 }
136
137 APDK_END_NAMESPACE