advapi32: Make some variables static and/or const.
[wine/multimedia.git] / dlls / wineps.drv / encode.c
blob5fb129afb7becd7aec73fbf0df4a91c97867f49d
1 /*
2 * PostScript filter functions
4 * Copyright 2003 Huw D M Davies
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #include <ctype.h>
21 #include <stdio.h>
22 #include <string.h>
24 #include "psdrv.h"
25 #include "wine/debug.h"
27 WINE_DEFAULT_DEBUG_CHANNEL(psdrv);
29 DWORD RLE_encode(BYTE *in_buf, DWORD len, BYTE *out_buf)
31 BYTE *next_in = in_buf, *next_out = out_buf;
32 DWORD rl;
34 while(next_in < in_buf + len) {
35 if(next_in + 1 < in_buf + len) {
36 if(*next_in == *(next_in + 1)) {
37 next_in += 2;
38 rl = 2;
39 while(next_in < in_buf + len && *next_in == *(next_in - 1) && rl < 128) {
40 next_in++;
41 rl++;
43 *next_out++ = 257 - rl;
44 *next_out++ = *(next_in - 1);
45 } else {
46 rl = 0;
47 next_out++;
48 while(next_in < in_buf + len && rl < 128) {
49 if(next_in + 2 < in_buf + len && *next_in == *(next_in + 1)) {
50 if(rl == 127 || *next_in == *(next_in + 2))
51 break;
53 *next_out++ = *next_in++;
54 rl++;
56 *(next_out - rl - 1) = rl - 1;
58 } else { /* special case: begin of run on last byte */
59 *next_out++ = 0;
60 *next_out++ = *next_in;
61 break;
64 *next_out++ = 128;
65 return next_out - out_buf;
68 DWORD ASCII85_encode(BYTE *in_buf, DWORD len, BYTE *out_buf)
70 DWORD number;
71 BYTE *next_in = in_buf, *next_out = out_buf;
72 int i;
74 while(next_in + 3 < in_buf + len) {
75 number = (next_in[0] << 24) |
76 (next_in[1] << 16) |
77 (next_in[2] << 8) |
78 (next_in[3] );
79 next_in += 4;
80 if(number == 0)
81 *next_out++ = 'z';
82 else {
83 for(i = 4; i >= 0; i--) {
84 next_out[i] = number % 85 + '!';
85 number /= 85;
87 next_out += 5;
91 if(next_in != in_buf + len) {
92 number = (*next_in++ << 24) & 0xff000000;
93 if(next_in < in_buf + len)
94 number |= ((*next_in++ << 16) & 0x00ff0000);
95 if(next_in < in_buf + len)
96 number |= ((*next_in++ << 8) & 0x0000ff00);
98 for(i = len % 4 + 1; i < 5; i++)
99 number /= 85;
101 for(i = len % 4; i >= 0; i--) {
102 next_out[i] = number % 85 + '!';
103 number /= 85;
105 next_out += len % 4 + 1;
108 return next_out - out_buf;