format working (mostly i think)
This commit is contained in:
parent
c1486c4c1a
commit
7f65ce824a
76
ctif.py
76
ctif.py
@ -206,21 +206,21 @@ class CTIF:
|
||||
logging.debug(f'Rendering CITF Image with Dim: ({self.width}, {self.height})')
|
||||
for (color, char) in zip(self.colors, self.text):
|
||||
h, s, v = color
|
||||
if char in EDGE_CHARS:
|
||||
v = 255
|
||||
else:
|
||||
v = (NEW_CHARS.find(char) + 1) * (255/len(NEW_CHARS))
|
||||
if char not in EDGE_CHARS:
|
||||
v = (NEW_CHARS.find(char) + 1) * (255/len(NEW_CHARS))/255
|
||||
|
||||
logging.debug(f'HSV Color: {h, s, v/255}')
|
||||
r, g, b = colorsys.hsv_to_rgb(h, s, v/255)
|
||||
logging.debug(f'HSV Color: {h, s, v}')
|
||||
r, g, b = colorsys.hsv_to_rgb(h, s, v)
|
||||
|
||||
|
||||
logging.debug(f'RGB Color Before: {r, g, b}')
|
||||
r *= 255
|
||||
g *= 255
|
||||
b *= 255
|
||||
|
||||
r = min(r, 255)
|
||||
g = min(g, 255)
|
||||
b = min(b, 255)
|
||||
logging.debug(f'RGB Color: {r, g, b}')
|
||||
rendered_char = font.render(char, ANTI_ALIASING, (int(r), int(g), int(b)))
|
||||
window.blit(rendered_char, (x * TEXT_WIDTH, y * TEXT_HEIGHT))
|
||||
@ -277,10 +277,10 @@ class CTIF:
|
||||
|
||||
h, s, v = color
|
||||
|
||||
h = int((h * 360) / (360/255))
|
||||
h = min(int(h * 255), 255)
|
||||
bin += h.to_bytes(1, 'big')
|
||||
|
||||
s = int((s*100) / (100/255))
|
||||
s = min(int(s * 255), 255)
|
||||
bin += s.to_bytes(1, 'big')
|
||||
|
||||
# for n in (h, s):
|
||||
@ -288,7 +288,12 @@ class CTIF:
|
||||
|
||||
# bin += i.to_bytes(1, 'big')
|
||||
|
||||
bin += (NEW_CHARS + EDGE_CHARS).index(char).to_bytes(1, 'big')
|
||||
char_index = (NEW_CHARS + EDGE_CHARS).index(char)
|
||||
|
||||
bin += char_index.to_bytes(1, 'big')
|
||||
if char in EDGE_CHARS:
|
||||
v = min(int(v * 255), 255)
|
||||
bin += v.to_bytes(1, 'big')
|
||||
|
||||
with open(f'{filename}.citf', 'wb+') as file:
|
||||
file.write(bin)
|
||||
@ -306,20 +311,43 @@ class CTIF:
|
||||
|
||||
data = data[4:]
|
||||
|
||||
# Read colors and characters
|
||||
char = None
|
||||
h, s = None, None
|
||||
for n in data:
|
||||
if not h:
|
||||
h = n
|
||||
elif not s:
|
||||
s = n
|
||||
else:
|
||||
print(n)
|
||||
char = (NEW_CHARS + EDGE_CHARS)[n]
|
||||
if len(data) % 3 != 0:
|
||||
logging.error(f"File is bad size. {len(data)}")
|
||||
|
||||
if h and s and char:
|
||||
logging.debug(f'H: {h}, S: {s}, Char: {char}')
|
||||
self.text += char
|
||||
# Read colors and characters
|
||||
i = 0
|
||||
for n in range(1, (int(len(data)/3)) + 1):
|
||||
|
||||
d = data[i:i + 3]
|
||||
|
||||
print(f'index: {i}')
|
||||
print(f'index end: {i + 3}')
|
||||
print(f'data: {d}')
|
||||
|
||||
h = d[0:1]
|
||||
h = int.from_bytes(h, 'big')
|
||||
|
||||
s = d[1:2]
|
||||
s = int.from_bytes(s, 'big')
|
||||
|
||||
|
||||
char_n = d[2:3]
|
||||
char_n = int.from_bytes(char_n, 'big')
|
||||
print(char_n)
|
||||
char = (NEW_CHARS + EDGE_CHARS)[char_n]
|
||||
|
||||
logging.debug(f'H: {h}, S: {s}, Char: {char}')
|
||||
self.text += char
|
||||
|
||||
if char in EDGE_CHARS:
|
||||
v = d[i+3:i+4]
|
||||
|
||||
v = int.from_bytes(v, 'big')
|
||||
|
||||
self.colors.append((h/255, s/255, v/255))
|
||||
|
||||
i += 4
|
||||
|
||||
else:
|
||||
self.colors.append((h/255, s/255, 255))
|
||||
h, s, char = None, None, None
|
||||
i += 3
|
||||
|
||||
BIN
engine.citf
BIN
engine.citf
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user