def id(self, bit_depth, interpolate, matte=None, decode=None): key = (bit_depth, decode, interpolate, matte) if key in self.registry: return self.registry[key] else: self.req_nr += 1 spec = self.doc.define_image_mask() spec.dimensions(*self.dim) if interpolate: spec.interpolate(interpolate) spec.bit_depth(bit_depth) if matte: spec.matte(matte) if decode: spec.decode(*decode) if bit_depth in self.src_img_registry: mask_data = self.src_img_registry[bit_depth] else: mask_data = imagemanip.pack_bits(self.generic, bit_depth, 1, *self.dim) self.src_img_registry[bit_depth] = mask_data if self.req_nr%2: handle, tmp_file = tempfile.mkstemp() mask_data.tofile(open(tmp_file,'wb')) os.close(handle) g_temp_files.add(tmp_file) spec.file_name(tmp_file) else: spec.data(mask_data) id = self.doc.register_image_mask(spec) self.registry[key] = id return id
def set_doc(self, doc): self.dim = 64, 64 self.doc = doc self.registry = {} generic = imagemanip.image(imagemanip.InvertedEllipseC, *self.dim) self.mask_data = imagemanip.pack_bits(generic, 1, 1, *self.dim) self.req_nr = 0 self.test_errors()
def do_masks_page(doc): def reg_spec(doc, meth_str, *args): spec = doc.image_definition() spec.format(jagpdf.IMAGE_FORMAT_PNG) spec.file_name(g_png_file) if meth_str: meth = getattr(spec, meth_str) meth(*args) return doc.image_load(spec) media = 9.3 * 72, 10 * 72 doc.page_start(*media) paint_background(doc, media) page = doc.page().canvas() page.text_font(g_font(10)) placer = imagemanip.ImageGrid(doc, (10, 10), 2, (4.5 * 72, 4.5 * 72), 12, 5) placer(reg_spec(doc, None), "original (with alpha channel)") mask_dim = 72, 72 gimg = imagemanip.image(imagemanip.InvertedEllipseC, *mask_dim) smspec = doc.define_image_mask() smspec.data(imagemanip.pack_bits(gimg, 8, 1, *mask_dim)) smspec.dimensions(*mask_dim) smspec.bit_depth(8) smid = doc.register_image_mask(smspec) placer(reg_spec(doc, "image_mask", smid), "custom soft mask") placer(reg_spec(doc, "color_key_mask", [0, 127, 0, 127, 0, 255]), "color key mask") gimg = imagemanip.image(imagemanip.InvertedEllipseC, *mask_dim) smspec = doc.define_image_mask() smspec.data(imagemanip.pack_bits(gimg, 1, 1, *mask_dim)) smspec.dimensions(*mask_dim) smspec.bit_depth(1) smid = doc.register_image_mask(smspec) placer(reg_spec(doc, "image_mask", smid), "custom mask") doc.page_end()
def do_masks_page(doc): def reg_spec(doc, meth_str, *args): spec = doc.image_definition() spec.format(jagpdf.IMAGE_FORMAT_PNG) spec.file_name(g_png_file) if meth_str: meth = getattr(spec, meth_str) meth(*args) return doc.image_load(spec) media = 9.3*72, 10*72 doc.page_start(*media) paint_background(doc, media) page = doc.page().canvas() page.text_font(g_font(10)) placer = imagemanip.ImageGrid(doc, (10,10), 2, (4.5*72,4.5*72), 12, 5) placer(reg_spec(doc, None), "original (with alpha channel)") mask_dim = 72, 72 gimg = imagemanip.image(imagemanip.InvertedEllipseC, *mask_dim) smspec = doc.define_image_mask() smspec.data(imagemanip.pack_bits(gimg, 8, 1, *mask_dim)) smspec.dimensions(*mask_dim) smspec.bit_depth(8) smid = doc.register_image_mask(smspec) placer(reg_spec(doc, "image_mask", smid), "custom soft mask") placer(reg_spec(doc, "color_key_mask", [0,127,0,127,0,255]), "color key mask") gimg = imagemanip.image(imagemanip.InvertedEllipseC, *mask_dim) smspec = doc.define_image_mask() smspec.data(imagemanip.pack_bits(gimg, 1, 1, *mask_dim)) smspec.dimensions(*mask_dim) smspec.bit_depth(1) smid = doc.register_image_mask(smspec) placer(reg_spec(doc, "image_mask", smid), "custom mask") doc.page_end()