From 351d5eb0ddabc7c922c9884d3b47039066e0fce4 Mon Sep 17 00:00:00 2001 From: Theelgirl <43764914+Theelgirl@users.noreply.github.com> Date: Wed, 28 Oct 2020 14:49:09 +0000 Subject: [PATCH] Remove unnecessary logic Tiny speedup for Cython, but it'll be a huge speed for the Python version. --- fvid/fvid_cython.pyx | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/fvid/fvid_cython.pyx b/fvid/fvid_cython.pyx index 97cffa9..c708f9f 100644 --- a/fvid/fvid_cython.pyx +++ b/fvid/fvid_cython.pyx @@ -19,18 +19,10 @@ cpdef str cy_get_bits_from_image(image): pixel_bin_rep = "0" - # for exact matches, indexing each pixel individually is faster in cython for some reason - if pixel[0] == 255 and pixel[1] == 255 and pixel[2] == 255: + # if the white difference is smaller (comparison part 1), that means the pixel is closer + # to white, otherwise, the pixel must be black + if abs(pixel[0] - 255) < abs(pixel[0] - 0) and abs(pixel[1] - 255) < abs(pixel[1] - 0) and abs(pixel[2] - 255) < abs(pixel[2] - 0): pixel_bin_rep = "1" - elif pixel[0] == 0 and pixel[1] == 0 and pixel[2] == 0: - pixel_bin_rep = "0" - else: - # if the white difference is smaller (comparison part 1), that means the pixel is closer - # to white, otherwise, the pixel must be black - if abs(pixel[0] - 255) < abs(pixel[0] - 0) and abs(pixel[1] - 255) < abs(pixel[1] - 0) and abs(pixel[2] - 255) < abs(pixel[2] - 0): - pixel_bin_rep = "1" - else: - pixel_bin_rep = "0" # adding bits bits += pixel_bin_rep