Oops, don't use python to cast to long

This commit is contained in:
kris 2021-01-12 00:27:03 +00:00
parent 31446cb457
commit 3e7cb37253
3 changed files with 15 additions and 12 deletions

View File

@ -7,9 +7,6 @@ from typing import Tuple
from PIL import Image
import numpy as np
import pyximport;
pyximport.install(language_level=3)
import dither_apply
@ -438,8 +435,6 @@ def dither_image(
image_4bit = np.empty(
(image_rgb.shape[0], image_rgb.shape[1]), dtype=np.uint8)
# pattern = dither.PATTERN
for y in range(screen.Y_RES):
print(y)
output_pixel_4bit = np.uint8(0)
@ -456,7 +451,7 @@ def dither_image(
image_4bit[y, x] = output_pixel_4bit
image_rgb[y, x, :] = 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

View File

@ -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 j in range(3):
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)
@ -96,13 +96,12 @@ def dither_lookahead(
for j in range(xxr - x):
for k in range(3):
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.
for j in range(xxr - x, lookahead + xr - xl):
for k in range(3):
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?
for i in range(xxr - x):
xl, xr = x_dither_bounds(pattern, dither_x_origin, x_res, i)
@ -129,9 +128,9 @@ def dither_lookahead(
total_error = 0
for j in range(lookahead):
# 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))
g = long(clip(lah_image_rgb[i, j, 1], 0, 255))
b = long(clip(lah_image_rgb[i, j, 2], 0, 255))
r = <long>clip(lah_image_rgb[i, j, 0], 0, 255)
g = <long>clip(lah_image_rgb[i, j, 1], 0, 255)
b = <long>clip(lah_image_rgb[i, j, 2], 0, 255)
flat = (r << 16) + (g << 8) + b
bit4 = options_4bit[i, j]

9
setup.py Normal file
View File

@ -0,0 +1,9 @@
from setuptools import setup
from Cython.Build import cythonize
import Cython.Compiler.Options
Cython.Compiler.Options.annotate = True
setup(
ext_modules=cythonize(["dither_apply.pyx"], annotate=True)
)