diff --git a/dither_pattern.py b/dither_pattern.py index d69095b..8cb8e84 100644 --- a/dither_pattern.py +++ b/dither_pattern.py @@ -11,7 +11,7 @@ class DitherPattern: class NoDither(DitherPattern): """No dithering.""" PATTERN = np.array(((0, 0), (0, 0)), - dtype=np.float32).reshape(2, 2) / np.float(16) + dtype=np.float32).reshape(2, 2) / np.float32(16) ORIGIN = (0, 1) @@ -20,7 +20,7 @@ class FloydSteinbergDither(DitherPattern): # 0 * 7 # 3 5 1 PATTERN = np.array(((0, 0, 7), (3, 5, 1)), - dtype=np.float32).reshape(2, 3) / np.float(16) + dtype=np.float32).reshape(2, 3) / np.float32(16) ORIGIN = (0, 1) @@ -31,7 +31,7 @@ class FloydSteinbergDither2(DitherPattern): PATTERN = np.array( ((0, 0, 0, 0, 0, 7), (3, 5, 1, 0, 0, 0)), - dtype=np.float32).reshape(2, 6) / np.float(16) + dtype=np.float32).reshape(2, 6) / np.float32(16) ORIGIN = (0, 2) diff --git a/dither_shr.pyx b/dither_shr.pyx index aff880d..dc8b61e 100644 --- a/dither_shr.pyx +++ b/dither_shr.pyx @@ -315,13 +315,15 @@ cdef (unsigned char)[:, ::1] _convert_cam16ucs_to_rgb12_iigs(float[:, ::1] point rgb = colour.convert(point_cam, "CAM16UCS", "RGB").astype(np.float32) # TODO: precompute this conversion matrix since it's static. This accounts for about 10% of the CPU time here. - rgb12_iigs = np.clip( - # Convert to Rec.601 R'G'B' - colour.YCbCr_to_RGB( - # Gamma correct and convert Rec.709 R'G'B' to YCbCr - colour.RGB_to_YCbCr( - linear_to_srgb_array(rgb), K=colour.WEIGHTS_YCBCR['ITU-R BT.709']), - K=colour.WEIGHTS_YCBCR['ITU-R BT.601']), 0, 1).astype(np.float32) * 15 + rgb12_iigs = np.ascontiguousarray( + np.clip( + # Convert to Rec.601 R'G'B' + colour.YCbCr_to_RGB( + # Gamma correct and convert Rec.709 R'G'B' to YCbCr + colour.RGB_to_YCbCr( + linear_to_srgb_array(rgb), K=colour.WEIGHTS_YCBCR['ITU-R BT.709']), + K=colour.WEIGHTS_YCBCR['ITU-R BT.601']), 0, 1) + ).astype(np.float32) * 15 return np.round(rgb12_iigs).astype(np.uint8) # Wrapper around _convert_cam16ucs_to_rgb12_iigs to allow calling from python while retaining fast path for cython diff --git a/precompute_conversion.py b/precompute_conversion.py index 857c715..abb3b9e 100644 --- a/precompute_conversion.py +++ b/precompute_conversion.py @@ -30,7 +30,8 @@ def main(): rgb24_to_cam16ucs = colour.convert(all_rgb24, "RGB", "CAM16UCS").astype( np.float32) del all_rgb24 - np.save("data/rgb24_to_cam16ucs.npy", rgb24_to_cam16ucs) + np.save("data/rgb24_to_cam16ucs.npy", np.ascontiguousarray( + rgb24_to_cam16ucs)) del rgb24_to_cam16ucs print("Precomputing conversion matrix from 12-bit //gs RGB to CAM16UCS " @@ -60,7 +61,8 @@ def main(): rgb12_iigs_to_cam16ucs = colour.convert( rgb12_iigs, "RGB", "CAM16UCS").astype(np.float32) del rgb12_iigs - np.save("data/rgb12_iigs_to_cam16ucs.npy", rgb12_iigs_to_cam16ucs) + np.save("data/rgb12_iigs_to_cam16ucs.npy", np.ascontiguousarray( + rgb12_iigs_to_cam16ucs)) del rgb12_iigs_to_cam16ucs diff --git a/screen.py b/screen.py index 8a51d45..7c69142 100644 --- a/screen.py +++ b/screen.py @@ -161,7 +161,8 @@ class DHGRScreen: # Apply effect of saturation yuv_to_rgb = np.array( - ((1, 0, 0), (0, saturation, 0), (0, 0, saturation)), dtype=np.float) + ((1, 0, 0), (0, saturation, 0), (0, 0, saturation)), + dtype=np.float32) # Apply hue phase rotation yuv_to_rgb = np.matmul(np.array( ((1, 0, 0), (0, np.cos(hue), np.sin(hue)), (0, -np.sin(hue),