Use interpolated LAB table.

* Saves about 100KBs.
This commit is contained in:
iabdalkader 2021-01-21 22:53:28 +02:00
parent eccaeb111b
commit 690a39c0cb
3 changed files with 8214 additions and 16397 deletions

View File

@ -274,13 +274,13 @@ color_thresholds_list_lnk_data_t;
(__rb_pixel * 0x0801) + ((__pixel << 3) & 0x7E0); \ (__rb_pixel * 0x0801) + ((__pixel << 3) & 0x7E0); \
}) })
extern const int8_t lab_table[196608]; extern const int8_t lab_table[196608/2];
extern const int8_t yuv_table[196608]; extern const int8_t yuv_table[196608];
#ifdef IMLIB_ENABLE_LAB_LUT #ifdef IMLIB_ENABLE_LAB_LUT
#define COLOR_RGB565_TO_L(pixel) lab_table[(pixel) * 3] #define COLOR_RGB565_TO_L(pixel) lab_table[((pixel>>1) * 3) + 0]
#define COLOR_RGB565_TO_A(pixel) lab_table[((pixel) * 3) + 1] #define COLOR_RGB565_TO_A(pixel) lab_table[((pixel>>1) * 3) + 1]
#define COLOR_RGB565_TO_B(pixel) lab_table[((pixel) * 3) + 2] #define COLOR_RGB565_TO_B(pixel) lab_table[((pixel>>1) * 3) + 2]
#else #else
#define COLOR_RGB565_TO_L(pixel) imlib_rgb565_to_l(pixel) #define COLOR_RGB565_TO_L(pixel) imlib_rgb565_to_l(pixel)
#define COLOR_RGB565_TO_A(pixel) imlib_rgb565_to_a(pixel) #define COLOR_RGB565_TO_A(pixel) imlib_rgb565_to_a(pixel)
@ -596,15 +596,15 @@ extern const int kernel_high_pass_3[9];
#define IM_RGB5652L(p) \ #define IM_RGB5652L(p) \
({ __typeof__ (p) _p = (p); \ ({ __typeof__ (p) _p = (p); \
lab_table[_p * 3]; }) lab_table[((_p>>1) * 3) + 0]; })
#define IM_RGB5652A(p) \ #define IM_RGB5652A(p) \
({ __typeof__ (p) _p = (p); \ ({ __typeof__ (p) _p = (p); \
lab_table[(_p * 3) + 1]; }) lab_table[((_p>>1) * 3) + 1]; })
#define IM_RGB5652B(p) \ #define IM_RGB5652B(p) \
({ __typeof__ (p) _p = (p); \ ({ __typeof__ (p) _p = (p); \
lab_table[(_p * 3) + 2]; }) lab_table[((_p>>1) * 3) + 2]; })
// Grayscale maxes // Grayscale maxes
#define IM_MAX_GS (255) #define IM_MAX_GS (255)

File diff suppressed because it is too large Load Diff

View File

@ -13,10 +13,12 @@
def lin(c): def lin(c):
return 100 * ((c/12.92) if (c<=0.04045) else pow((c+0.055)/1.055, 2.4)) return 100 * ((c/12.92) if (c<=0.04045) else pow((c+0.055)/1.055, 2.4))
import sys import sys, math
sys.stdout.write("#include <stdint.h>\n") sys.stdout.write("#include <stdint.h>\n")
l_list = []
sys.stdout.write("const int8_t lab_table[196608] = {\n") # 65536 * 3 a_list = []
b_list = []
sys.stdout.write("const int8_t lab_table[98304] = {\n") # 65536 * 3 / 2
for i in range(65536): for i in range(65536):
r = ((((i >> 11) & 31) * 255) + 15.5) // 31 r = ((((i >> 11) & 31) * 255) + 15.5) // 31
@ -45,10 +47,17 @@ for i in range(65536):
a = int(round(500 * (x-y))); a = int(round(500 * (x-y)));
b = int(round(200 * (y-z))); b = int(round(200 * (y-z)));
sys.stdout.write(" %4d, %4d, %4d" % (l, a, b)) l_list.append(int(round(116 * y)) - 16)
a_list.append(int(round(500 * (x-y))))
b_list.append(int(round(200 * (y-z))))
lab = list(zip(l_list, a_list, b_list))
for i, (x, y) in enumerate(zip(lab[0::2], lab[1::2])):
out = [(i1 + i2)/2.0 for i1, i2 in zip(x, y)]
sys.stdout.write(" %4d, %4d, %4d" % (out[0], out[1], out[2]))
if (i + 1) % 4: if (i + 1) % 4:
sys.stdout.write(", ") sys.stdout.write(", ")
elif i != 65535: elif i != 65535//2:
sys.stdout.write(",\n") sys.stdout.write(",\n")
else: else:
sys.stdout.write("\n};\n") sys.stdout.write("\n};\n")