From 76f4677c12f4b16efaa0f0ad94c339a8ee5f8722 Mon Sep 17 00:00:00 2001 From: Philipp Klaus Date: Sat, 10 Dec 2016 15:23:57 +0100 Subject: [PATCH] create/reader: Removing remaining traces of the numpy package --- brother_ql/brother_ql_create.py | 1 - brother_ql/reader.py | 25 ++++++++++++++----------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/brother_ql/brother_ql_create.py b/brother_ql/brother_ql_create.py index 43f472c..c810900 100755 --- a/brother_ql/brother_ql_create.py +++ b/brother_ql/brother_ql_create.py @@ -4,7 +4,6 @@ from __future__ import division import sys, argparse, logging -import numpy as np from PIL import Image from brother_ql.raster import BrotherQLRaster diff --git a/brother_ql/reader.py b/brother_ql/reader.py index 79db956..f85ac08 100755 --- a/brother_ql/reader.py +++ b/brother_ql/reader.py @@ -8,6 +8,8 @@ import sys from PIL import Image import numpy as np +from builtins import bytes + logger = logging.getLogger(__name__) OPCODES = { @@ -118,6 +120,7 @@ def chunker(data, raise_exception=False): returns: list of bytes objects """ instructions = [] + data = bytes(data) while True: if len(data) == 0: break try: @@ -247,25 +250,25 @@ class BrotherQLReader(object): if opcode_def[0] == 'compression': self.compression = payload[0] == 0x02 if opcode_def[0] == 'raster': - rpl = payload[2:] # raster payload - index = 0 - row = [] + rpl = bytes(payload[2:]) # raster payload if self.compression: + row = bytes() + index = 0 while True: num = rpl[index] if num & 0x80: num = num - 0x100 if num < 0: num = -num + 1 - for i in range(num): row.append(rpl[index+1]) + row += bytes([rpl[index+1]] * num) index += 2 else: num = num + 1 - for i in range(num): row.append(rpl[index+1+i]) + row += rpl[index+1:index+1+num] index += 1 + num if index >= len(rpl): break else: - row.append(list(rpl)) + row = rpl self.rows.append(row) if opcode_def[0] == 'media/quality': self.raster_no = struct.unpack(' Monocolor and invert + size = (len(self.rows[0])*8, len(self.rows)) + data = bytes(b''.join(self.rows)) + data = bytes([2**8 + ~byte for byte in data]) # invert b/w + im = Image.frombytes("1", size, data, decoder_name='raw') + im = im.transpose(Image.FLIP_LEFT_RIGHT) img_name = 'page{:04d}.png'.format(self.page) im.save(img_name) print('Page saved as {}'.format(img_name))