Fixing the creation of raster files, closes #1
This commit is contained in:
@@ -35,7 +35,12 @@ def main():
|
||||
|
||||
logging.basicConfig(level=args.loglevel)
|
||||
|
||||
qlr = BrotherQLRaster(args.model)
|
||||
device_pixel_width = qlr.get_pixel_width()
|
||||
|
||||
im = Image.open(args.image)
|
||||
hsize = int(im.size[1] / im.size[0] * device_pixel_width)
|
||||
im = im.resize((device_pixel_width, hsize), Image.ANTIALIAS)
|
||||
im = im.convert("L")
|
||||
arr = np.asarray(im, dtype=np.uint8)
|
||||
arr.flags.writeable = True
|
||||
@@ -44,7 +49,7 @@ def main():
|
||||
arr[white_idx] = 1
|
||||
arr[black_idx] = 0
|
||||
|
||||
qlr = BrotherQLRaster(args.model)
|
||||
|
||||
qlr.set_mode()
|
||||
qlr.set_clear_command_buffer()
|
||||
qlr.set_initialize()
|
||||
|
||||
@@ -124,19 +124,23 @@ class BrotherQLRaster(object):
|
||||
self.data += b'\x4D'
|
||||
self.data += bytes([compression << 1])
|
||||
|
||||
def set_raster_data(self, np_array):
|
||||
""" np_array: numpy array of 1-bit values """
|
||||
np_array = np.fliplr(np_array)
|
||||
def get_pixel_width(self):
|
||||
try:
|
||||
nbpr = number_bytes_per_row[self.model]
|
||||
except:
|
||||
nbpr = number_bytes_per_row['default']
|
||||
return nbpr*8
|
||||
|
||||
def set_raster_data(self, np_array):
|
||||
""" np_array: numpy array of 1-bit values """
|
||||
np_array = np.fliplr(np_array)
|
||||
logger.info("raster_image_size: {1}x{0}".format(*np_array.shape))
|
||||
if np_array.shape[1] != self.get_pixel_width():
|
||||
fmt = 'Wrong pixel width: {}, expected {}'
|
||||
raise BrotherQLRasterError(fmt.format(np_array.shape[0], self.get_pixel_width()))
|
||||
for row in np_array:
|
||||
self.data += b'\x67\x00'
|
||||
row = bytes(np.packbits(row))
|
||||
if len(row) != nbpr:
|
||||
fmt = 'Wrong number of bytes per row: {}, expected {}'
|
||||
raise BrotherQLRasterError(fmt.format(len(row), nbpr))
|
||||
if self._compression:
|
||||
row = packbits.encode(row)
|
||||
self.data += bytes([len(row)])
|
||||
|
||||
Reference in New Issue
Block a user