mirror of https://github.com/AlfredoSequeida/fvid
Speedup 35-40% over the previous speedup
Removing a python call to all(), which forced conversion of a ctuple to a python tuple, and removing white_diff and black_diff ctuple creation because I can fit all of their use cases into a single if statement.
This commit is contained in:
parent
59ccb531e5
commit
87ccfb535f
|
@ -6,8 +6,7 @@
|
||||||
cpdef cy_get_bits_from_image(image):
|
cpdef cy_get_bits_from_image(image):
|
||||||
cdef int width, height, x, y
|
cdef int width, height, x, y
|
||||||
cdef str pixel_bin_rep
|
cdef str pixel_bin_rep
|
||||||
cdef (int, int, int) pixel, white_diff, black_diff
|
cdef (int, int, int) pixel#, white_diff, black_diff
|
||||||
cdef (bint, bint, bint) truth_tuple
|
|
||||||
|
|
||||||
width, height = image.size
|
width, height = image.size
|
||||||
|
|
||||||
|
@ -26,14 +25,9 @@ cpdef cy_get_bits_from_image(image):
|
||||||
elif pixel[0] == 0 and pixel[1] == 0 and pixel[2] == 0:
|
elif pixel[0] == 0 and pixel[1] == 0 and pixel[2] == 0:
|
||||||
pixel_bin_rep = <str>"0"
|
pixel_bin_rep = <str>"0"
|
||||||
else:
|
else:
|
||||||
white_diff = (abs(pixel[0] - 255), abs(pixel[1] - 255), abs(pixel[2] - 255))
|
# if the white difference is smaller (comparison part 1), that means the pixel is closer
|
||||||
# min_diff = white_diff
|
|
||||||
black_diff = (abs(pixel[0] - 0), abs(pixel[1] - 0), abs(pixel[2] - 0))
|
|
||||||
|
|
||||||
# if the white difference is smaller, that means the pixel is closer
|
|
||||||
# to white, otherwise, the pixel must be black
|
# to white, otherwise, the pixel must be black
|
||||||
truth_tuple = (white_diff[0] < black_diff[0], white_diff[1] < black_diff[1], white_diff[2] < black_diff[2])
|
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):
|
||||||
if all(truth_tuple):
|
|
||||||
pixel_bin_rep = <str>"1"
|
pixel_bin_rep = <str>"1"
|
||||||
else:
|
else:
|
||||||
pixel_bin_rep = <str>"0"
|
pixel_bin_rep = <str>"0"
|
||||||
|
|
Loading…
Reference in New Issue