Tizen 2.1 base
[platform/upstream/hplip.git] / prnt / hpijs / compression.h
1 /*****************************************************************************\
2   compression.h : Interface for BertCompress and BertUncompress
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 #ifndef APDK_COMPRESSION_H
33 #define APDK_COMPRESSION_H
34
35 APDK_BEGIN_NAMESPACE
36
37 #define kUseOldBert 0
38
39
40 #define kBertDecompressPixelSize 3
41
42 // Follows are all the masks for the command byte.
43 #define kTypeMask           0x80
44 #define kTypeShiftAmount    7
45
46 #define kCacheLiteralBitsMask 0x60
47 #define kCacheLiteralBitsShiftAmount 5
48
49 #define kCacheBitsMask 0x60
50 #define kCacheBitsShiftAmount 5
51
52 #define kRoffMask           0x18
53 #define kRoffShiftAmount    3
54
55 #define kReplace_countMask  0x07
56
57 // Now have the compiler check to make sure none of the masks overlap/underlap bits accidently.
58 #if ((kTypeMask | kCacheLiteralBitsMask | kRoffMask | kReplace_countMask) != 255)
59 #error "Your mask bits are messed up!"
60 #endif
61
62 #if ((kTypeMask | kCacheBitsMask | kRoffMask | kReplace_countMask) != 255)
63 #error "Your mask bits are messed up!"
64 #endif
65
66
67 enum
68 {
69     eLiteral = 0,
70     eRLE = 0x80
71 };
72
73 enum
74 {
75     eeNewPixel = 0x0,
76     eeWPixel = 0x20,
77     eeNEPixel = 0x40,
78     eeCachedColor = 0x60,
79 };
80
81 enum
82 {
83     eNewColor       = 0x0,
84     eWestColor      = 0x1,
85     eNorthEastColor = 0x2,
86     eCachedColor    = 0x3
87 };
88
89
90 // Literal
91 #define M10_MAX_OFFSET0         2       /* Largest unscaled value an offset can have before extra byte is needed. */
92 #define M10_MAX_COUNT0          6       /* Largest unscaled and unbiased value a count can have before extra byte is needed */
93 #define M10_COUNT_START0        1       /* What a count of zero has a value of. */
94
95 // RLE
96 #define M10_MAX_OFFSET1         2
97 #define M10_MAX_COUNT1          6
98 #define M10_COUNT_START1        2
99
100 //int BertCompress(unsigned char *currentRow,  int byteCount, unsigned char *dest,  unsigned char *seed, int pixelSizeInBytes);
101 int BertCompress(unsigned char *currentRow, unsigned char *seed, unsigned char *dest, int byteCount, int pixelSizeInBytes);
102 unsigned int decodeDataToPixel(const unsigned char *compressedDataPtr, int *CBI, const unsigned char *seedRowPtr, const int curPixel, int pixelSizeInBytes);
103 void BertUncompress(const unsigned char *compressedDataPtr,
104                     unsigned char *seedRowPtr,
105                     int numberOfCompressedBytes,
106                     int pixelSizeInBytes,
107                     int rowWidthInBytes,
108                     int *firstPixelThatChanged,
109                     int *lastPixelThatChanged);
110 /*unsigned int BertUncompress(const unsigned char *inPtr,
111                                 int ulInputBytes,
112                                 int ulOutputBytes,
113                                 unsigned char *ulSeedPtr,
114                                 unsigned char *ulOutPtr);
115 */
116
117 APDK_END_NAMESPACE
118
119 #endif //APDK_COMPRESSION_H