bitmap.c revision 6e9aa255e3376b2da5824c09c4c62bc233463bfe
/* -*- c-basic-offset: 8 -*-
rdesktop: A Remote Desktop Protocol client.
Bitmap decompression routines
Copyright (C) Matthew Chapman <matthewc.unsw.edu.au> 1999-2008
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*
* Oracle GPL Disclaimer: For the avoidance of doubt, except that if any license choice
* other than GPL or LGPL is available it will apply instead, Oracle elects to use only
* the General Public License version 2 (GPLv2) at this time for any software where
* a choice of GPL license versions is made available with the language indicating
* that GPLv2 or any later version may be used, or where a choice of which version
* of the GPL is applied is otherwise unspecified.
*/
/* three seperate function for speed when decompressing the bitmaps
when modifing one function make the change in the others
jay.sorg@gmail.com */
/* indent is confused by this file */
/* *INDENT-OFF* */
#include "rdesktop.h"
#define CVAL(p) (*(p++))
#ifdef NEED_ALIGN
#ifdef L_ENDIAN
#define CVAL2(p, v) { v = (*(p++)); v |= (*(p++)) << 8; }
#else
#define CVAL2(p, v) { v = (*(p++)) << 8; v |= (*(p++)); }
#endif /* L_ENDIAN */
#else
#endif /* NEED_ALIGN */
{ \
\
{ \
statement; \
count--; \
x++; \
} \
}
#define MASK_UPDATE() \
{ \
mixmask <<= 1; \
if (mixmask == 0) \
{ \
mixmask = 1; \
} \
}
/* 1 byte bitmap decompress */
static RD_BOOL
{
int fom_mask = 0;
{
fom_mask = 0;
/* Handle different opcode forms */
switch (opcode)
{
case 0xc:
case 0xd:
case 0xe:
opcode -= 6;
offset = 16;
break;
case 0xf:
if (opcode < 9)
{
}
else
{
}
offset = 0;
break;
default:
opcode >>= 1;
offset = 32;
break;
}
/* Handle strange cases for counts */
if (offset != 0)
{
if (count == 0)
{
if (isfillormix)
else
}
else if (isfillormix)
{
count <<= 3;
}
}
/* Read preliminary data */
switch (opcode)
{
case 0: /* Fill */
break;
case 8: /* Bicolour */
case 3: /* Colour */
break;
opcode -= 5;
break;
case 9: /* FillOrMix_1 */
mask = 0x03;
opcode = 0x02;
fom_mask = 3;
break;
case 0x0a: /* FillOrMix_2 */
mask = 0x05;
opcode = 0x02;
fom_mask = 5;
break;
}
lastopcode = opcode;
mixmask = 0;
/* Output body */
while (count > 0)
{
if (x >= width)
{
if (height <= 0)
return False;
x = 0;
height--;
}
switch (opcode)
{
case 0: /* Fill */
if (insertmix)
{
else
count--;
x++;
}
{
}
else
{
}
break;
case 1: /* Mix */
{
}
else
{
}
break;
case 2: /* Fill or Mix */
{
(
MASK_UPDATE();
else
line[x] = 0;
)
}
else
{
(
MASK_UPDATE();
else
)
}
break;
case 3: /* Colour */
break;
case 4: /* Copy */
break;
case 8: /* Bicolour */
(
if (bicolour)
{
}
else
{
}
)
break;
case 0xd: /* White */
break;
case 0xe: /* Black */
break;
default:
return False;
}
}
}
return True;
}
/* 2 byte bitmap decompress */
static RD_BOOL
{
int fom_mask = 0;
{
fom_mask = 0;
/* Handle different opcode forms */
switch (opcode)
{
case 0xc:
case 0xd:
case 0xe:
opcode -= 6;
offset = 16;
break;
case 0xf:
if (opcode < 9)
{
}
else
{
}
offset = 0;
break;
default:
opcode >>= 1;
offset = 32;
break;
}
/* Handle strange cases for counts */
if (offset != 0)
{
if (count == 0)
{
if (isfillormix)
else
}
else if (isfillormix)
{
count <<= 3;
}
}
/* Read preliminary data */
switch (opcode)
{
case 0: /* Fill */
break;
case 8: /* Bicolour */
case 3: /* Colour */
break;
opcode -= 5;
break;
case 9: /* FillOrMix_1 */
mask = 0x03;
opcode = 0x02;
fom_mask = 3;
break;
case 0x0a: /* FillOrMix_2 */
mask = 0x05;
opcode = 0x02;
fom_mask = 5;
break;
}
lastopcode = opcode;
mixmask = 0;
/* Output body */
while (count > 0)
{
if (x >= width)
{
if (height <= 0)
return False;
x = 0;
height--;
}
switch (opcode)
{
case 0: /* Fill */
if (insertmix)
{
else
count--;
x++;
}
{
}
else
{
}
break;
case 1: /* Mix */
{
}
else
{
}
break;
case 2: /* Fill or Mix */
{
(
MASK_UPDATE();
else
line[x] = 0;
)
}
else
{
(
MASK_UPDATE();
else
)
}
break;
case 3: /* Colour */
break;
case 4: /* Copy */
break;
case 8: /* Bicolour */
(
if (bicolour)
{
}
else
{
count++;
}
)
break;
case 0xd: /* White */
break;
case 0xe: /* Black */
break;
default:
return False;
}
}
}
return True;
}
/* 3 byte bitmap decompress */
static RD_BOOL
{
int fom_mask = 0;
{
fom_mask = 0;
/* Handle different opcode forms */
switch (opcode)
{
case 0xc:
case 0xd:
case 0xe:
opcode -= 6;
offset = 16;
break;
case 0xf:
if (opcode < 9)
{
}
else
{
0xb) ? 8 : 1;
}
offset = 0;
break;
default:
opcode >>= 1;
offset = 32;
break;
}
/* Handle strange cases for counts */
if (offset != 0)
{
if (count == 0)
{
if (isfillormix)
else
}
else if (isfillormix)
{
count <<= 3;
}
}
/* Read preliminary data */
switch (opcode)
{
case 0: /* Fill */
break;
case 8: /* Bicolour */
case 3: /* Colour */
break;
opcode -= 5;
break;
case 9: /* FillOrMix_1 */
mask = 0x03;
opcode = 0x02;
fom_mask = 3;
break;
case 0x0a: /* FillOrMix_2 */
mask = 0x05;
opcode = 0x02;
fom_mask = 5;
break;
}
lastopcode = opcode;
mixmask = 0;
/* Output body */
while (count > 0)
{
if (x >= width)
{
if (height <= 0)
return False;
x = 0;
height--;
}
switch (opcode)
{
case 0: /* Fill */
if (insertmix)
{
{
}
else
{
line[x * 3] =
}
count--;
x++;
}
{
(
line[x * 3] = 0;
)
}
else
{
(
)
}
break;
case 1: /* Mix */
{
(
)
}
else
{
(
line[x * 3] =
)
}
break;
case 2: /* Fill or Mix */
{
(
MASK_UPDATE();
{
}
else
{
line[x * 3] = 0;
}
)
}
else
{
(
MASK_UPDATE();
{
line[x * 3] =
}
else
{
line[x * 3] =
prevline[x * 3];
}
)
}
break;
case 3: /* Colour */
(
)
break;
case 4: /* Copy */
(
)
break;
case 8: /* Bicolour */
(
if (bicolour)
{
}
else
{
count++;
}
)
break;
case 0xd: /* White */
(
)
break;
case 0xe: /* Black */
(
line[x * 3] = 0;
)
break;
default:
return False;
}
}
}
return True;
}
/* decompress a colour plane */
static int
{
int indexw;
int indexh;
int code;
int collen;
int replen;
int color;
int x;
int revcode;
last_line = 0;
indexh = 0;
{
color = 0;
indexw = 0;
if (last_line == 0)
{
{
{
collen = 0;
}
while (collen > 0)
{
out += 4;
indexw++;
collen--;
}
while (replen > 0)
{
out += 4;
indexw++;
replen--;
}
}
}
else
{
{
{
collen = 0;
}
while (collen > 0)
{
if (x & 1)
{
x = x >> 1;
x = x + 1;
color = -x;
}
else
{
x = x >> 1;
color = x;
}
*out = x;
out += 4;
indexw++;
collen--;
}
while (replen > 0)
{
*out = x;
out += 4;
indexw++;
replen--;
}
}
}
indexh++;
}
}
/* 4 byte bitmap decompress */
static RD_BOOL
{
int code;
int bytes_pro;
int total_pro;
if (code != 0x10)
{
return False;
}
total_pro = 1;
}
/* main decompress function */
{
switch (Bpp)
{
case 1:
break;
case 2:
break;
case 3:
break;
case 4:
break;
default:
break;
}
return rv;
}
/* *INDENT-ON* */