2021-03-02 19:09:07 +01:00
|
|
|
# distutils: language=c++
|
2020-10-13 14:15:56 +02:00
|
|
|
# cython: boundscheck=False
|
|
|
|
# cython: cdivision=True
|
|
|
|
# cython: wraparound=False
|
2021-03-02 19:09:07 +01:00
|
|
|
# cython: c_string_type=unicode, c_string_encoding=ascii
|
|
|
|
|
|
|
|
from libcpp.string cimport string
|
2020-10-13 14:15:56 +02:00
|
|
|
|
2021-02-25 19:57:46 +01:00
|
|
|
cpdef str cy_gbfi(image):
|
2020-10-13 14:15:56 +02:00
|
|
|
cdef int width, height, x, y
|
2021-03-02 19:09:07 +01:00
|
|
|
cdef string bits = b''
|
2020-10-25 19:04:04 +01:00
|
|
|
cdef (int, int, int) pixel
|
2020-10-13 14:15:56 +02:00
|
|
|
|
|
|
|
width, height = image.size
|
|
|
|
|
|
|
|
px = image.load()
|
|
|
|
|
|
|
|
for y in range(height):
|
|
|
|
for x in range(width):
|
|
|
|
pixel = px[x, y]
|
|
|
|
|
2020-10-28 15:49:09 +01:00
|
|
|
# if the white difference is smaller (comparison part 1), that means the pixel is closer
|
|
|
|
# to white, otherwise, the pixel must be black
|
2021-03-02 19:09:07 +01:00
|
|
|
bits.append(b'1' 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) else b'0')
|
2020-10-13 14:15:56 +02:00
|
|
|
|
|
|
|
return bits
|
2021-02-25 19:57:46 +01:00
|
|
|
|
|
|
|
cpdef str cy_gbfi_h265(image):
|
|
|
|
cdef int width, height, x, y
|
2021-03-02 19:09:07 +01:00
|
|
|
cdef string bits = b''
|
2021-02-25 19:57:46 +01:00
|
|
|
|
|
|
|
width, height = image.size
|
|
|
|
|
|
|
|
px = image.load()
|
|
|
|
|
|
|
|
for y in range(height):
|
|
|
|
for x in range(width):
|
2021-03-02 19:09:07 +01:00
|
|
|
bits.append(b'1' if px[x, y] == 255 else b'0')
|
2021-02-25 19:57:46 +01:00
|
|
|
|
|
|
|
return bits
|