fixed linewidth, added linewidth/background to png

pull/32/head
tatarize 2018-10-03 18:08:27 -07:00 zatwierdzone przez GitHub
rodzic 332201f16e
commit 210ace88c4
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
4 zmienionych plików z 29 dodań i 7 usunięć

Wyświetl plik

@ -37,7 +37,7 @@ def color_hex(hex_string):
if size == 6 or size == 8:
return int(h[:6], 16)
elif size == 4 or size == 3:
return int(h[2] + h[2] + h[1] + h[1] + h[0] + h[0], 16)
return int(h[0] + h[0] + h[1] + h[1] + h[2] + h[2], 16)
def color_distance_red_mean(

Wyświetl plik

@ -2,6 +2,7 @@ import struct
import zlib
from .EmbConstant import *
from .EmbThread import EmbThread
SEQUIN_CONTINGENCY = CONTINGENCY_SEQUIN_STITCH
FULL_JUMP = True
@ -32,6 +33,14 @@ class PngBuffer:
self.green = 0
self.blue = 0
self.alpha = 0
self.line_width = 3
def background(self, red, green, blue, alpha):
for i in range(0, len(self.buf), 4):
self.buf[i] = red
self.buf[i + 1] = green
self.buf[i + 2] = blue
self.buf[i + 3] = alpha
def plot(self, x, y):
try:
@ -86,14 +95,14 @@ class PngBuffer:
self.line_for_point(x0, y0, True)
def line_for_point(self, x, y, dy):
w = 3
w = self.line_width
left = w >> 1
right = w - left
if dy:
for pos in range(left, right):
for pos in range(-left, right):
self.plot(x + pos, y)
else:
for pos in range(left, right):
for pos in range(-left, right):
self.plot(x, y + pos)
@ -103,6 +112,15 @@ def write(pattern, f, settings=None):
width = int(extends[2] - extends[0])
height = int(extends[3] - extends[1])
draw_buff = PngBuffer(width, height)
if settings is not None:
background = settings.get("background", None)
linewidth = settings.get("linewidth", None)
if background is not None:
b = EmbThread()
b.set(background)
draw_buff.background(b.get_red(), b.get_green(), b.get_blue(), 0xFF)
if linewidth is not None and isinstance(linewidth, int):
draw_buff.line_width = linewidth
for stitchblock in pattern.get_as_stitchblock():
block = stitchblock[0]

Wyświetl plik

@ -376,11 +376,15 @@ def supported_formats():
"writer": PmvWriter
})
yield ({
"description": "PNG image file",
"description": "PNG Format, Portable Network Graphics",
"extension": "png",
"mimetype": "image/png",
"category": "image",
"writer": PngWriter
"writer": PngWriter,
"options": {
"background": (0x000000, 0xFFFFFF),
"linewidth": (1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
},
})

Wyświetl plik

@ -13,7 +13,7 @@ class TestWrites(unittest.TestCase):
def test_write_png(self):
file1 = "file.png"
write_png(get_shift_pattern(), file1)
write_png(get_shift_pattern(), file1, {"background": "#F00", "linewidth": 5})
self.addCleanup(os.remove, file1)
def test_write_dst_read_dst(self):