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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
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;
34 while(next_in < in_buf + len) {
35 if(next_in + 1 < in_buf + len) {
36 if(*next_in == *(next_in + 1)) {
39 while(next_in < in_buf + len && *next_in == *(next_in - 1) && rl < 128) {
43 *next_out++ = 257 - rl;
44 *next_out++ = *(next_in - 1);
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))
53 *next_out++ = *next_in++;
56 *(next_out - rl - 1) = rl - 1;
58 } else { /* special case: begin of run on last byte */
60 *next_out++ = *next_in;
65 return next_out - out_buf;
68 DWORD ASCII85_encode(BYTE *in_buf, DWORD len, BYTE *out_buf)
71 BYTE *next_in = in_buf, *next_out = out_buf;
74 while(next_in + 3 < in_buf + len) {
75 number = (next_in[0] << 24) |
83 for(i = 4; i >= 0; i--) {
84 next_out[i] = number % 85 + '!';
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++)
101 for(i = len % 4; i >= 0; i--) {
102 next_out[i] = number % 85 + '!';
105 next_out += len % 4 + 1;
108 return next_out - out_buf;