Codebase list rastertosag-gdi / 1a2f744
rastertosag-gdi-python3 Didier Raboud 6 years ago
1 changed file(s) with 12 addition(s) and 12 deletion(s). Raw diff Collapse all Expand all
0 #!/usr/bin/python -u
0 #!/usr/bin/python3 -u
11 #coding=utf8
22
33 # CUPS raster filter for Ricoh Aficio SP1000s
2525 if len(sys.argv)>6:
2626 filename=sys.argv[6]
2727 if filename=='.' or filename=='-':
28 input=sys.stdin
28 input=sys.stdin.buffer
2929 else:
30 input = open(sys.argv[6],'r')
31 output = sys.stdout
30 input = open(sys.argv[6],'rb')
31 output = sys.stdout.buffer
3232
3333 def print_stderr(s,newline=True):
3434 sys.stderr.write(str(s)+('\n' if newline else ''))
3838 cups = input.read() # Read all bytes from stdin
3939
4040 sync_word=cups[0:4] # length of sync-word is 4 bytes: "3SaR"
41 version=int(cups[0])
41 version=cups[0]-48
4242 cups=cups[4:]
4343
4444 dtype={
5454 }
5555
5656 def make_unpack_format(format,begin,end,split_count=1):
57 return '<'+(str((end-begin+1)/dtype[format]['size']/split_count)+dtype[format]['b'])*split_count
57 return '<'+(str((end-begin+1)//dtype[format]['size']//split_count)+dtype[format]['b'])*split_count
5858
5959 hdr={
6060 1: {}, # version 1 header
158158 line=unpack('<'+str(numbytes)+'B',page_data[y*numbytes:(y+1)*numbytes])
159159 ret=[]
160160 extend=ret.extend
161 for x in range(0,w/8):
161 for x in range(0,w//8):
162162 extend(bytes[line[x]])
163163 if w%8:
164 extend(bytes[line[w/8]][:w%8])
164 extend(bytes[line[w//8]][:w%8])
165165 return ret
166166
167167 FORMAT_WIDTH=0
184184 def begin_document():
185185 output.write(pack(
186186 '>76sbbHHI',
187 ') SAG-GDI RL;0;0;Comment Copyright Sagem Communication 2005. Version 1.0.0.0',
187 b') SAG-GDI RL;0;0;Comment Copyright Sagem Communication 2005. Version 1.0.0.0',
188188 0x0D,0x0A,
189189 0x1000,0x0200,
190190 0
216216 current_line_length=0
217217 def begin_block():
218218 global current_block_data
219 current_block_data=''
219 current_block_data=b''
220220
221221 def get_block_size():
222222 return len(current_block_data)
231231 color = 1 if col else 0
232232 color_bit = color << 6
233233 first_byte = length%64
234 second_byte = length/64
234 second_byte = length//64
235235 two_bytes_bit = 0b10000000 if second_byte else 0b00000000
236236
237237 px_data=pack('>B', two_bytes_bit | color_bit | first_byte)
256256 w,h=min(hdr[1]['cupsWidth'],formats[format][FORMAT_WIDTH]),min(hdr[1]['cupsHeight'],formats[format][FORMAT_HEIGHT])
257257 t=time()
258258 for y in range(h):
259 if y%(h/15)==0:
259 if y%(h//15)==0:
260260 print_stderr('%d%% '%(int(float(y)/h*100),),False)
261261
262262 yline=get_cups_line(y)