1
/*****************************************************************************\
2
LidilCompress.cpp : Implementation of LidilCompress class
4
Copyright (c) 1996 - 2009, Hewlett-Packard Co.
7
Redistribution and use in source and binary forms, with or without
8
modification, are permitted provided that the following conditions
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.
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
\*****************************************************************************/
31
#include "CommonDefinitions.h"
32
#include "LidilCompress.h"
34
UInt16 LidilCompress::FlushImage ()
47
from_ptr = m_image_ptr;
49
command = FILL_IMAGE_CMD | (wsize-1);
52
*m_out_ptr++ = command;
53
for (UInt16 i = 0; i < wsize; i++)
55
*m_out_ptr++ = *from_ptr++;
57
bsize = ((m_image_cnt+1) * 2);
66
UInt16 LidilCompress::FlushCopy (UInt16 value)
74
UInt16 *uP = m_out_ptr++;
78
command = FILL_0000_CMD | (m_copy_cnt-1);
80
else if (value == 0xFFFF)
82
command = FILL_FFFF_CMD | (m_copy_cnt-1);
86
command = FILL_NEXT_CMD | (m_copy_cnt-1);
98
void LidilCompress::CompressData (Int16 compressionmode)
107
LDLCOMPMODE mode = IN_NOT;
114
m_out_ptr = &m_out_array[8];
115
data_length = m_data_length;
117
if ((data_length & 1) != 0)
119
// ErrorTrap((char *)"Data length is odd.");
123
in_ptr = &m_raw_data[0];
125
for (i=0; i<data_length; i+=2)
133
/* default the first entry to 'image' */
135
m_image_ptr = in_ptr;
143
#if ALLOW_FILL_NEXT_CMD
146
if ((last == in) && ((in==0xFFFF) || (in == 0)) )
171
/* revisit - could allow 2 words of copy if the data is
174
/* convert a copy cnt of 2 to an image */
175
UInt16 copy_count = m_copy_cnt;
177
if (copy_count <= m_run_length)
179
if (m_image_cnt == 0)
181
/* point the pointer to the first element */
182
m_image_ptr = in_ptr - copy_count;
184
m_image_cnt += (1+copy_count);
189
/* have enough to be a legal copy */
191
(void) FlushImage ();
193
(void) FlushCopy (copy_item);
195
m_image_ptr = in_ptr;
206
#if ALLOW_FILL_NEXT_CMD
209
if ((last == in) && ((in==0xFFFF) || (in == 0)) )
232
} /* next data - end of processing */
234
/* flush out the remainder */
240
/* have enough to be a legal copy */
241
(void) FlushImage ();
243
(void) FlushCopy (copy_item);
249
(void) FlushImage ();
256
if (m_out_cnt > 2048+16)
258
// ErrorTrap("out cnt too big");
263
bool LidilCompress::GetFrameInfo (BYTE **outdata, UInt16 *data_size)
265
*outdata = (unsigned char *) &m_out_array[0];
266
*data_size = m_out_cnt;
270
bool LidilCompress::Init (UInt16 *data, UInt16 datasize)
274
m_data_length = datasize;
276
m_run_length = MAX_RUNLENGTH;