mirror of
https://github.com/KrisKennaway/ii-pix.git
synced 2024-11-19 08:30:48 +00:00
Oops, don't use python to cast to long
This commit is contained in:
parent
31446cb457
commit
3e7cb37253
@ -7,9 +7,6 @@ from typing import Tuple
|
|||||||
|
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import pyximport;
|
|
||||||
|
|
||||||
pyximport.install(language_level=3)
|
|
||||||
import dither_apply
|
import dither_apply
|
||||||
|
|
||||||
|
|
||||||
@ -438,8 +435,6 @@ def dither_image(
|
|||||||
image_4bit = np.empty(
|
image_4bit = np.empty(
|
||||||
(image_rgb.shape[0], image_rgb.shape[1]), dtype=np.uint8)
|
(image_rgb.shape[0], image_rgb.shape[1]), dtype=np.uint8)
|
||||||
|
|
||||||
# pattern = dither.PATTERN
|
|
||||||
|
|
||||||
for y in range(screen.Y_RES):
|
for y in range(screen.Y_RES):
|
||||||
print(y)
|
print(y)
|
||||||
output_pixel_4bit = np.uint8(0)
|
output_pixel_4bit = np.uint8(0)
|
||||||
@ -456,7 +451,7 @@ def dither_image(
|
|||||||
image_4bit[y, x] = output_pixel_4bit
|
image_4bit[y, x] = output_pixel_4bit
|
||||||
image_rgb[y, x, :] = output_pixel_rgb
|
image_rgb[y, x, :] = output_pixel_rgb
|
||||||
quant_error = input_pixel_rgb - output_pixel_rgb
|
quant_error = input_pixel_rgb - output_pixel_rgb
|
||||||
dither.apply(screen, image_rgb, x, y, quant_error)
|
dither_apply.apply(dither, screen, x, y, image_rgb, quant_error)
|
||||||
|
|
||||||
return image_4bit, image_rgb
|
return image_4bit, image_rgb
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ cdef void apply_one_line(float[:, :, ::1] pattern, int xl, int xr, float[:, ::1]
|
|||||||
for i in range(xr - xl):
|
for i in range(xr - xl):
|
||||||
for j in range(3):
|
for j in range(3):
|
||||||
error = pattern[0, i, 0] * quant_error[j]
|
error = pattern[0, i, 0] * quant_error[j]
|
||||||
image[xl+i, j] = clip(image[xl + i, j] + error, 0, 255)
|
image[xl + i, j] = clip(image[xl + i, j] + error, 0, 255)
|
||||||
|
|
||||||
|
|
||||||
@cython.boundscheck(False)
|
@cython.boundscheck(False)
|
||||||
@ -96,13 +96,12 @@ def dither_lookahead(
|
|||||||
for j in range(xxr - x):
|
for j in range(xxr - x):
|
||||||
for k in range(3):
|
for k in range(3):
|
||||||
lah_image_rgb[i, j, k] = image_rgb[y, x+j, k]
|
lah_image_rgb[i, j, k] = image_rgb[y, x+j, k]
|
||||||
# lah_image_rgb[:, 0:xxr - x, :] = image_rgb[y, x:xxr, :]
|
|
||||||
# Leave enough space at right of image so we can dither the last of our lookahead pixels.
|
# Leave enough space at right of image so we can dither the last of our lookahead pixels.
|
||||||
for j in range(xxr - x, lookahead + xr - xl):
|
for j in range(xxr - x, lookahead + xr - xl):
|
||||||
for k in range(3):
|
for k in range(3):
|
||||||
lah_image_rgb[i, j, k] = 0
|
lah_image_rgb[i, j, k] = 0
|
||||||
cdef float[3] quant_error
|
|
||||||
|
|
||||||
|
cdef float[3] quant_error
|
||||||
# Iterating by row then column is faster for some reason?
|
# Iterating by row then column is faster for some reason?
|
||||||
for i in range(xxr - x):
|
for i in range(xxr - x):
|
||||||
xl, xr = x_dither_bounds(pattern, dither_x_origin, x_res, i)
|
xl, xr = x_dither_bounds(pattern, dither_x_origin, x_res, i)
|
||||||
@ -129,9 +128,9 @@ def dither_lookahead(
|
|||||||
total_error = 0
|
total_error = 0
|
||||||
for j in range(lookahead):
|
for j in range(lookahead):
|
||||||
# Clip lah_image_rgb into 0..255 range to prepare for computing colour distance
|
# Clip lah_image_rgb into 0..255 range to prepare for computing colour distance
|
||||||
r = long(clip(lah_image_rgb[i, j, 0], 0, 255))
|
r = <long>clip(lah_image_rgb[i, j, 0], 0, 255)
|
||||||
g = long(clip(lah_image_rgb[i, j, 1], 0, 255))
|
g = <long>clip(lah_image_rgb[i, j, 1], 0, 255)
|
||||||
b = long(clip(lah_image_rgb[i, j, 2], 0, 255))
|
b = <long>clip(lah_image_rgb[i, j, 2], 0, 255)
|
||||||
|
|
||||||
flat = (r << 16) + (g << 8) + b
|
flat = (r << 16) + (g << 8) + b
|
||||||
bit4 = options_4bit[i, j]
|
bit4 = options_4bit[i, j]
|
||||||
|
Loading…
Reference in New Issue
Block a user