Sync with trunk (r49303)
[reactos.git] / subsystems / win32 / win32k / eng / rlecomp.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
4 * PURPOSE: RLE compression
5 * FILE: subsystems/win32k/eng/rlecomp.c
6 * PROGRAMER: Jason Filby
7 */
8
9 #include <win32k.h>
10
11 #define NDEBUG
12 #include <debug.h>
13
14 enum Rle_EscapeCodes
15 {
16 RLE_EOL = 0, /* End of line */
17 RLE_END = 1, /* End of bitmap */
18 RLE_DELTA = 2 /* Delta */
19 };
20
21 VOID DecompressBitmap(SIZEL Size, BYTE *CompressedBits, BYTE *UncompressedBits, LONG Delta, ULONG Format)
22 {
23 INT x = 0;
24 INT y = Size.cy - 1;
25 INT c;
26 INT length;
27 INT width;
28 INT height = Size.cy - 1;
29 BYTE *begin = CompressedBits;
30 BYTE *bits = CompressedBits;
31 BYTE *temp;
32 INT shift = 0;
33
34 if (Format == BMF_4RLE)
35 shift = 1;
36 else if(Format != BMF_8RLE)
37 return;
38
39 width = ((Size.cx + shift) >> shift);
40
41 _SEH2_TRY
42 {
43 while (y >= 0)
44 {
45 length = (*bits++) >> shift;
46 if (length)
47 {
48 c = *bits++;
49 while (length--)
50 {
51 if (x >= width) break;
52 temp = UncompressedBits + (((height - y) * Delta) + x);
53 x++;
54 *temp = c;
55 }
56 }
57 else
58 {
59 length = *bits++;
60 switch (length)
61 {
62 case RLE_EOL:
63 x = 0;
64 y--;
65 break;
66 case RLE_END:
67 _SEH2_YIELD(return);
68 case RLE_DELTA:
69 x += (*bits++) >> shift;
70 y -= (*bits++) >> shift;
71 break;
72 default:
73 length = length >> shift;
74 while (length--)
75 {
76 c = *bits++;
77 if (x < width)
78 {
79 temp = UncompressedBits + (((height - y) * Delta) + x);
80 x++;
81 *temp = c;
82 }
83 }
84 if ((bits - begin) & 1)
85 {
86 bits++;
87 }
88 }
89 }
90 }
91 }
92 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
93 {
94 DPRINT1("Decoding error\n");
95 }
96 _SEH2_END;
97
98 return;
99 }