Cores optional param, change to BytesIO and code cleanup.
This commit is contained in:
@@ -35,7 +35,7 @@ def main():
|
|||||||
parser.add_argument('--model', '-m', default='QL-500', help='The printer model to use. Check available ones with `brother_ql_info list-models`.')
|
parser.add_argument('--model', '-m', default='QL-500', help='The printer model to use. Check available ones with `brother_ql_info list-models`.')
|
||||||
parser.add_argument('--label-size', '-s', default='62', help='The label size (and kind) to use. Check available ones with `brother_ql_info list-label-sizes`.')
|
parser.add_argument('--label-size', '-s', default='62', help='The label size (and kind) to use. Check available ones with `brother_ql_info list-label-sizes`.')
|
||||||
parser.add_argument('--rotate', '-r', choices=('0', '90', '180', '270'), default='auto', help='Rotate the image (counterclock-wise) by this amount of degrees.')
|
parser.add_argument('--rotate', '-r', choices=('0', '90', '180', '270'), default='auto', help='Rotate the image (counterclock-wise) by this amount of degrees.')
|
||||||
parser.add_argument('--threshold', '-t', type=float, default=30.0, help='The threshold value (in percent) to discriminate between black and white pixels.')
|
parser.add_argument('--threshold', '-t', type=float, default=70.0, help='The threshold value (in percent) to discriminate between black and white pixels.')
|
||||||
parser.add_argument('--no-cut', dest='cut', action='store_false', help="Don't cut the tape after printing the label.")
|
parser.add_argument('--no-cut', dest='cut', action='store_false', help="Don't cut the tape after printing the label.")
|
||||||
parser.add_argument('--loglevel', type=lambda x: getattr(logging, x), default=logging.WARNING, help='Set to DEBUG for verbose debugging output to stderr.')
|
parser.add_argument('--loglevel', type=lambda x: getattr(logging, x), default=logging.WARNING, help='Set to DEBUG for verbose debugging output to stderr.')
|
||||||
parser.add_argument('--cores', '-c', type=int, default=defaultCores, help='The number of cores to use on creating the bin file.')
|
parser.add_argument('--cores', '-c', type=int, default=defaultCores, help='The number of cores to use on creating the bin file.')
|
||||||
@@ -65,7 +65,7 @@ def main():
|
|||||||
|
|
||||||
args.outfile.write(qlr.data)
|
args.outfile.write(qlr.data)
|
||||||
|
|
||||||
def create_label(qlr, image, label_size, cores, threshold=30, cut=True, **kwargs):
|
def create_label(qlr, image, label_size, cores, threshold=70, cut=True, **kwargs):
|
||||||
|
|
||||||
label_specs = label_type_specs[label_size]
|
label_specs = label_type_specs[label_size]
|
||||||
dots_printable = label_specs['dots_printable']
|
dots_printable = label_specs['dots_printable']
|
||||||
@@ -111,6 +111,8 @@ def create_label(qlr, image, label_size, cores, threshold=30, cut=True, **kwargs
|
|||||||
im = new_im
|
im = new_im
|
||||||
|
|
||||||
im = PIL.ImageOps.invert(im)
|
im = PIL.ImageOps.invert(im)
|
||||||
|
|
||||||
|
threshold = 100.0 - threshold
|
||||||
threshold = min(255, max(0, int(threshold/100.0 * 255))) # from percent to pixel val
|
threshold = min(255, max(0, int(threshold/100.0 * 255))) # from percent to pixel val
|
||||||
im = im.point(lambda x: 0 if x < threshold else 255, mode="1")
|
im = im.point(lambda x: 0 if x < threshold else 255, mode="1")
|
||||||
|
|
||||||
|
|||||||
+6
-11
@@ -20,11 +20,11 @@ from .devicedependent import models, \
|
|||||||
|
|
||||||
from . import BrotherQLError, BrotherQLUnsupportedCmd, BrotherQLUnknownModel, BrotherQLRasterError
|
from . import BrotherQLError, BrotherQLUnsupportedCmd, BrotherQLUnknownModel, BrotherQLRasterError
|
||||||
|
|
||||||
import multiprocessing, ctypes
|
import multiprocessing
|
||||||
|
|
||||||
from multiprocessing import Process, Manager, Array
|
from multiprocessing import Process, Manager
|
||||||
|
|
||||||
from cStringIO import StringIO
|
from io import BytesIO
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@@ -175,7 +175,7 @@ class BrotherQLRaster(object):
|
|||||||
nbpr = number_bytes_per_row['default']
|
nbpr = number_bytes_per_row['default']
|
||||||
return nbpr*8
|
return nbpr*8
|
||||||
|
|
||||||
def add_raster_data(self, image, cores):
|
def add_raster_data(self, image, cores=1):
|
||||||
""" image: Pillow Image() """
|
""" image: Pillow Image() """
|
||||||
logger.info("raster_image_size: {0}x{1}".format(*image.size))
|
logger.info("raster_image_size: {0}x{1}".format(*image.size))
|
||||||
image = image.transpose(Image.FLIP_LEFT_RIGHT)
|
image = image.transpose(Image.FLIP_LEFT_RIGHT)
|
||||||
@@ -189,9 +189,7 @@ class BrotherQLRaster(object):
|
|||||||
row_len = image.size[0]//8
|
row_len = image.size[0]//8
|
||||||
start = 0
|
start = 0
|
||||||
|
|
||||||
file_str = StringIO()
|
file_str = BytesIO()
|
||||||
|
|
||||||
logger.debug("Frame " + str(frame_len) + " Row " + str(row_len))
|
|
||||||
|
|
||||||
if cores > 1:
|
if cores > 1:
|
||||||
|
|
||||||
@@ -242,12 +240,9 @@ class BrotherQLRaster(object):
|
|||||||
while start + row_len <= frame_len:
|
while start + row_len <= frame_len:
|
||||||
row = frame[start:start+row_len]
|
row = frame[start:start+row_len]
|
||||||
start += row_len
|
start += row_len
|
||||||
#self.data += b'\x67\x00' # g 0x00
|
|
||||||
file_str.write(b'\x67\x00')
|
file_str.write(b'\x67\x00')
|
||||||
if self._compression:
|
if self._compression:
|
||||||
row = packbits.encode(row)
|
row = packbits.encode(row)
|
||||||
#self.data += bytes([len(row)])
|
|
||||||
#self.data += row
|
|
||||||
file_str.write(bytes([len(row)]))
|
file_str.write(bytes([len(row)]))
|
||||||
file_str.write(row)
|
file_str.write(row)
|
||||||
|
|
||||||
@@ -262,7 +257,7 @@ class BrotherQLRaster(object):
|
|||||||
|
|
||||||
def processFrame(self, start, row_len, frame_len, frame, index, g_data):
|
def processFrame(self, start, row_len, frame_len, frame, index, g_data):
|
||||||
|
|
||||||
file_str = StringIO()
|
file_str = BytesIO()
|
||||||
while start + row_len <= frame_len:
|
while start + row_len <= frame_len:
|
||||||
row = frame[start:start+row_len]
|
row = frame[start:start+row_len]
|
||||||
start += row_len
|
start += row_len
|
||||||
|
|||||||
Reference in New Issue
Block a user