diff --git a/brother_ql/brother_ql_create.py b/brother_ql/brother_ql_create.py index d5c1516..631fd96 100755 --- a/brother_ql/brother_ql_create.py +++ b/brother_ql/brother_ql_create.py @@ -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('--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('--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('--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.') @@ -65,7 +65,7 @@ def main(): 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] 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 = PIL.ImageOps.invert(im) + + threshold = 100.0 - threshold 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") diff --git a/brother_ql/raster.py b/brother_ql/raster.py index 86a1820..da85f07 100644 --- a/brother_ql/raster.py +++ b/brother_ql/raster.py @@ -20,11 +20,11 @@ from .devicedependent import models, \ 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__) @@ -175,7 +175,7 @@ class BrotherQLRaster(object): nbpr = number_bytes_per_row['default'] return nbpr*8 - def add_raster_data(self, image, cores): + def add_raster_data(self, image, cores=1): """ image: Pillow Image() """ logger.info("raster_image_size: {0}x{1}".format(*image.size)) image = image.transpose(Image.FLIP_LEFT_RIGHT) @@ -189,9 +189,7 @@ class BrotherQLRaster(object): row_len = image.size[0]//8 start = 0 - file_str = StringIO() - - logger.debug("Frame " + str(frame_len) + " Row " + str(row_len)) + file_str = BytesIO() if cores > 1: @@ -242,12 +240,9 @@ class BrotherQLRaster(object): while start + row_len <= frame_len: row = frame[start:start+row_len] start += row_len - #self.data += b'\x67\x00' # g 0x00 file_str.write(b'\x67\x00') if self._compression: row = packbits.encode(row) - #self.data += bytes([len(row)]) - #self.data += row file_str.write(bytes([len(row)])) file_str.write(row) @@ -262,7 +257,7 @@ class BrotherQLRaster(object): def processFrame(self, start, row_len, frame_len, frame, index, g_data): - file_str = StringIO() + file_str = BytesIO() while start + row_len <= frame_len: row = frame[start:start+row_len] start += row_len