|
0 |
Index: rastertosag-gdi-0.1/rastertosag-gdi
|
|
1 |
===================================================================
|
|
2 |
--- rastertosag-gdi-0.1.orig/rastertosag-gdi
|
|
3 |
+++ rastertosag-gdi-0.1/rastertosag-gdi
|
|
4 |
@@ -1,4 +1,4 @@
|
|
5 |
-#!/usr/bin/python -u
|
|
6 |
+#!/usr/bin/python3 -u
|
|
7 |
#coding=utf8
|
|
8 |
|
|
9 |
# CUPS raster filter for Ricoh Aficio SP1000s
|
|
10 |
@@ -26,10 +26,10 @@ filename='-'
|
|
11 |
if len(sys.argv)>6:
|
|
12 |
filename=sys.argv[6]
|
|
13 |
if filename=='.' or filename=='-':
|
|
14 |
- input=sys.stdin
|
|
15 |
+ input=sys.stdin.buffer
|
|
16 |
else:
|
|
17 |
- input = open(sys.argv[6],'r')
|
|
18 |
-output = sys.stdout
|
|
19 |
+ input = open(sys.argv[6],'rb')
|
|
20 |
+output = sys.stdout.buffer
|
|
21 |
|
|
22 |
def print_stderr(s,newline=True):
|
|
23 |
sys.stderr.write(str(s)+('\n' if newline else ''))
|
|
24 |
@@ -39,7 +39,7 @@ def print_stderr(s,newline=True):
|
|
25 |
cups = input.read() # Read all bytes from stdin
|
|
26 |
|
|
27 |
sync_word=cups[0:4] # length of sync-word is 4 bytes: "3SaR"
|
|
28 |
-version=int(cups[0])
|
|
29 |
+version=cups[0]-48
|
|
30 |
cups=cups[4:]
|
|
31 |
|
|
32 |
dtype={
|
|
33 |
@@ -55,7 +55,7 @@ header_length={ # length of page header
|
|
34 |
}
|
|
35 |
|
|
36 |
def make_unpack_format(format,begin,end,split_count=1):
|
|
37 |
- return '<'+(str((end-begin+1)/dtype[format]['size']/split_count)+dtype[format]['b'])*split_count
|
|
38 |
+ return '<'+(str((end-begin+1)//dtype[format]['size']//split_count)+dtype[format]['b'])*split_count
|
|
39 |
|
|
40 |
hdr={
|
|
41 |
1: {}, # version 1 header
|
|
42 |
@@ -159,10 +159,10 @@ def get_cups_line(y):
|
|
43 |
line=unpack('<'+str(numbytes)+'B',page_data[y*numbytes:(y+1)*numbytes])
|
|
44 |
ret=[]
|
|
45 |
extend=ret.extend
|
|
46 |
- for x in range(0,w/8):
|
|
47 |
+ for x in range(0,w//8):
|
|
48 |
extend(bytes[line[x]])
|
|
49 |
if w%8:
|
|
50 |
- extend(bytes[line[w/8]][:w%8])
|
|
51 |
+ extend(bytes[line[w//8]][:w%8])
|
|
52 |
return ret
|
|
53 |
|
|
54 |
FORMAT_WIDTH=0
|
|
55 |
@@ -185,7 +185,7 @@ formats = {
|
|
56 |
def begin_document():
|
|
57 |
output.write(pack(
|
|
58 |
'>76sbbHHI',
|
|
59 |
- ') SAG-GDI RL;0;0;Comment Copyright Sagem Communication 2005. Version 1.0.0.0',
|
|
60 |
+ b') SAG-GDI RL;0;0;Comment Copyright Sagem Communication 2005. Version 1.0.0.0',
|
|
61 |
0x0D,0x0A,
|
|
62 |
0x1000,0x0200,
|
|
63 |
0
|
|
64 |
@@ -217,7 +217,7 @@ current_block_data=''
|
|
65 |
current_line_length=0
|
|
66 |
def begin_block():
|
|
67 |
global current_block_data
|
|
68 |
- current_block_data=''
|
|
69 |
+ current_block_data=b''
|
|
70 |
|
|
71 |
def get_block_size():
|
|
72 |
return len(current_block_data)
|
|
73 |
@@ -232,7 +232,7 @@ def write_px_data(col,length):
|
|
74 |
color = 1 if col else 0
|
|
75 |
color_bit = color << 6
|
|
76 |
first_byte = length%64
|
|
77 |
- second_byte = length/64
|
|
78 |
+ second_byte = length//64
|
|
79 |
two_bytes_bit = 0b10000000 if second_byte else 0b00000000
|
|
80 |
|
|
81 |
px_data=pack('>B', two_bytes_bit | color_bit | first_byte)
|
|
82 |
@@ -257,7 +257,7 @@ def write_cups():
|
|
83 |
w,h=min(hdr[1]['cupsWidth'],formats[format][FORMAT_WIDTH]),min(hdr[1]['cupsHeight'],formats[format][FORMAT_HEIGHT])
|
|
84 |
t=time()
|
|
85 |
for y in range(h):
|
|
86 |
- if y%(h/15)==0:
|
|
87 |
+ if y%(h//15)==0:
|
|
88 |
print_stderr('%d%% '%(int(float(y)/h*100),),False)
|
|
89 |
|
|
90 |
yline=get_cups_line(y)
|