/
vTech
/
FcApps
Обзор
Документация
Войти
/
vTech
/
FcApps
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
FcLibs/FcFont/src/FcFont_Math.h
243 строки
10 KB
vTech
alpha_00
03 дек 2025, 17:45
03 дек 2025, 17:45
ab8382d
Код
Авторство
О чём код?
#ifndef __FCFONT_MATH_H__ #define __FCFONT_MATH_H__ #include "FcFont_Setting.h" #define _USE_MATH_DEFINES #include <math.h> #ifndef max #define max(x, y) (((x) < (y)) ? (y) : (x)) #endif #ifndef min #define min(x, y) (((x) > (y)) ? (y) : (x)) #endif #define ALIGN16(size) ((((size) - 1) | 15) + 1u) #define ALIGN64(size) ((((size) - 1) | 63) + 1u) #ifndef ALIGNED64 #ifdef __GNUC__ #define ALIGNED64(str, x)str x __attribute__ ((aligned (64))) #else #define ALIGNED64(str, x) str __declspec(align(64)) x #endif #endif #ifndef ALIGNED32 #ifdef __GNUC__ #define ALIGNED32(str, x)str x __attribute__ ((aligned (32))) #else #define ALIGNED32(str, x) str __declspec(align(32)) x #endif #endif #ifndef ALIGNED16 #ifdef __GNUC__ #define ALIGNED16(str, x)str x __attribute__ ((aligned (16))) #else #define ALIGNED16(str, x) str __declspec(align(16)) x #endif #endif #ifndef ALIGNED8 #ifdef __GNUC__ #define ALIGNED8(str, x) str x __attribute__ ((aligned (8))) #else #define ALIGNED8(str, x) str __declspec(align(8)) x #endif #endif #ifndef ALIGNED #ifdef __GNUC__ #define ALIGNED(value, str, x) str x __attribute__ ((aligned(value))) #else #define ALIGNED(value, str, x) str __declspec(align(value)) x #endif #endif #define SWAP_BYTE_16(value) \ ((((value) >> (uint16_t)8) & (uint16_t)0xff) | \ (((value) & (uint16_t)0xff) << (uint16_t)8)) #define SWAP_BYTE_32(value) \ (((((value)&0xff000000) >> 24) | (((value)&0x00ff0000) >> 8) | \ ((value)&0x0000ff00) << 8) | \ (((value)&0x000000ff) << 24)) #define SWAP_BYTE_64(value) \ (((value & 0x00000000000000ffull) << 56) | \ ((value & 0x000000000000ff00ull) << 40) | \ ((value & 0x0000000000ff0000ull) << 24) | \ ((value & 0x00000000ff000000ull) << 8) | \ ((value & 0x000000ff00000000ull) >> 8) | \ ((value & 0x0000ff0000000000ull) >> 24) | \ ((value & 0x00ff000000000000ull) >> 40) | \ ((value & 0xff00000000000000ull) >> 56)) #define swap32_byte_16(value) \ ((((value)&0x0000ff00) >> 8) | (((value)&0x000000ff) << 8) | \ ((((value)&0xff000000) >> 8) | (((value)&0x00ff0000) << 8))) #define swap64_byte_16(value) \ ((((value)&0x000000000000ff00ull) >> 8) | \ (((value)&0x00000000000000ffull) << 8) | \ ((((value)&0x00000000ff000000ull) >> 8) | \ (((value)&0x0000000000ff0000ull) << 8)) | \ ((((value)&0x0000ff0000000000ull) >> 8) | \ (((value)&0x000000ff00000000ull) << 8)) | \ ((((value)&0xff00000000000000ull) >> 8) | \ (((value)&0x00ff000000000000ull) << 8))) #define all64_flag8(ptr, byte_offset, flag) \ (*(uint64_t *)(ptr + byte_offset) & \ ((uint64_t)flag | ((uint64_t)flag << 8) | ((uint64_t)flag << 16) | \ ((uint64_t)flag << 24) | ((uint64_t)flag << 32) | ((uint64_t)flag << 40) | \ ((uint64_t)flag << 48) | ((uint64_t)flag << 56))) #define MIX(a, b, t) (a * (1 - t) + (b * t)) #define CLAMP(minVal, maxVal, x) (min(max(x, minVal), maxVal)) #define LERP(a, b, t) (a + (b - a) * t) #define LENGTH(x0, y0, x1, y1) (sqrt((x0 - x1) * (x0 - x1) + (y0 - y1) * (y0 - y1))) FCFONTDEF uint8_t* align64(const uint8_t* ptr) { return (uint8_t*)((uintptr_t)(ptr + 63) & ~(uintptr_t)63); } FCFONTDEF uint8_t* align16(const uint8_t* ptr) { return (uint8_t*)((uintptr_t)(ptr + 15) & ~(uintptr_t)15); } FCFONTDEF uint64_t swap_byte_64(_In_ uint64_t value) { return (((value & 0x00000000000000ffull) << (uintptr_t)56) | ((value & 0x000000000000ff00ull) << (uintptr_t)40) | ((value & 0x0000000000ff0000ull) << (uintptr_t)24) | ((value & 0x00000000ff000000ull) << (uintptr_t)8) | ((value & 0x000000ff00000000ull) >> (uintptr_t)8) | ((value & 0x0000ff0000000000ull) >> (uintptr_t)24) | ((value & 0x00ff000000000000ull) >> (uintptr_t)40) | ((value & 0xff00000000000000ull) >> (uintptr_t)56)); } FCFONTDEF uint32_t swap_byte_32(_In_ uint32_t value) { return (((((value) & 0xff000000) >> (uintptr_t)24) | ((value & 0x00ff0000u) >> (uintptr_t)8) | ((value & 0x0000ff00u) << (uintptr_t)8)) | ((value & 0x000000ffu) << (uintptr_t)24)); } FCFONTDEF uint16_t swap_byte_16(_In_ uint16_t value) { return ((uint16_t)((uint16_t)((value >> 8u) & 0xffu) | (((uint16_t)(value & 0xffu) << 8u)))); } FCFONTDEF uint32_t check_checksum_swapByte(_In_reads_bytes_(length) uint32_t* table, _In_ uint32_t length) { size_t i, iEnd = (((length + 3) & ~3u)) / 4; uint32_t mSum = 0; for (i = 0; i < iEnd; i++) mSum += swap_byte_32(table[i]); return mSum; } #define REPEAT_COPY2(array_0, i_0, f, array_1, i_1) array_0[i_0 + 0] = f(array_1[i_1 + 0]); \ array_0[i_0 + 1] = f(array_1[i_1 + 1]); #define REPEAT_COPY4(array_0, i_0, f, array_1, i_1) REPEAT_COPY2(array_0, i_0, f, array_1, i_1) \ REPEAT_COPY2(array_0, i_0 + 2, f, array_1, i_1 + 2) #define REPEAT_COPY8(array_0, i_0, f, array_1, i_1) REPEAT_COPY4(array_0, i_0, f, array_1, i_1) \ REPEAT_COPY4(array_0, i_0 + 4, f, array_1, i_1 + 4) #define REPEAT_COPY16(array_0, i_0, f, array_1, i_1) REPEAT_COPY8(array_0, i_0, f, array_1, i_1) \ REPEAT_COPY8(array_0, i_0 + 8, f, array_1, i_1 + 8) #define COPY1_SWITCH(array_0, i_0, f, array_1, i_1, id) case (id + 1): array_0[i_0 + id] = f(array_1[i_1 + id]); #define COPY2_SWITCH(array_0, i_0, f, array_1, i_1, id) COPY1_SWITCH(array_0, i_0, f, array_1, i_1, id + 1) \ COPY1_SWITCH(array_0, i_0, f, array_1, i_1, id + 0) #define COPY4_SWITCH(array_0, i_0, f, array_1, i_1, id) COPY2_SWITCH(array_0, i_0, f, array_1, i_1, id + 2) \ COPY2_SWITCH(array_0, i_0, f, array_1, i_1, id + 0) #define COPY8_SWITCH(array_0, i_0, f, array_1, i_1, id) COPY4_SWITCH(array_0, i_0, f, array_1, i_1, id + 4) \ COPY4_SWITCH(array_0, i_0, f, array_1, i_1, id + 0) #define COPY16_SWITCH(array_0, i_0, f, array_1, i_1, id) COPY8_SWITCH(array_0, i_0, f, array_1, i_1, id + 8) \ COPY8_SWITCH(array_0, i_0, f, array_1, i_1, id + 0) #define COPY32_SWITCH(array_0, i_0, f, array_1, i_1, id) COPY16_SWITCH(array_0, i_0, f, array_1, i_1, id + 16) \ COPY16_SWITCH(array_0, i_0, f, array_1, i_1, id + 0) #define COPY64_SWITCH(array_0, i_0, f, array_1, i_1, id) COPY32_SWITCH(array_0, i_0, f, array_1, i_1, id + 32) \ COPY32_SWITCH(array_0, i_0, f, array_1, i_1, id + 0) #define COPY2_DATA_SWITCH(array_0, i_0, f, array_1, i_1, id) switch(id){\ default:;\ COPY2_SWITCH(array_0, i_0, f, array_1, i_1, 0);\ case 0:;\ } #define COPY4_DATA_SWITCH(array_0, i_0, f, array_1, i_1, id) switch(id){\ default:;\ COPY4_SWITCH(array_0, i_0, f, array_1, i_1, 0)\ case 0:;\ } #define COPY8_DATA_SWITCH(array_0, i_0, f, array_1, i_1, id) switch(id){\ default:;\ COPY8_SWITCH(array_0, i_0, f, array_1, i_1, 0)\ case 0:;\ } #define COPY16_DATA_SWITCH(array_0, i_0, f, array_1, i_1, id) switch(id){\ default:;\ COPY16_SWITCH(array_0, i_0, f, array_1, i_1, 0)\ case 0:;\ } #define COPY32_DATA_SWITCH(array_0, i_0, f, array_1, i_1, id) switch(id){\ default:;\ COPY32_SWITCH(array_0, i_0, f, array_1, i_1, 0)\ case 0:;\ } #define COPY64_DATA_SWITCH(array_0, i_0, f, array_1, i_1, id) switch(id){\ default:;\ COPY64_SWITCH(array_0, i_0, f, array_1, i_1, 0)\ case 0:;\ } #define REPEAT_COPY32_SWITCH(type_0, type_1, array_0, f, array_1, j, j_end, i) \ {type_0* ptr_0 = array_0; type_1* ptr_1 = array_1; i = (j_end) / 32; j = (j_end) & 0x1f;\ do{ \ COPY32_DATA_SWITCH(ptr_0, 0, f, ptr_1, 0, (i * 32 > j ? i * 32 : j)); \ ptr_0 += 32; ptr_1 += 32;\ }while(i--);} #define REPEAT_COPY2_ARRAY(type_0, type_1, array_0, f, array_1, j, j_end, i)\ {type_0* ptr_0 = array_0; const type_1* ptr_1 = array_1;\ for (j = 0; j + 1 < j_end; j += 2, ptr_0 += 2, ptr_1 += 2)\ for (i = 0; i < 2; i++)\ ptr_0[i] = f(ptr_1[i]);\ if (j < j_end) array_0[j] = f(array_1[j]);} #define REPEAT_COPY4_ARRAY(type_0, type_1, array_0, f, array_1, j, j_end, i)\ {type_0* ptr_0 = array_0; const type_1* ptr_1 = array_1;\ for (j = 0; j + 3 < j_end; j += 4, ptr_0 += 4, ptr_1 += 4)\ for (i = 0; i < 4; i++)\ ptr_0[i] = f(ptr_1[i]);\ COPY4_DATA_SWITCH(ptr_0, 0, f, ptr_1, 0, ((j_end) & 0x3));} #define REPEAT_COPY8_ARRAY(type_0, type_1, array_0, f, array_1, j, j_end, i)\ {type_0* ptr_0 = array_0; const type_1* ptr_1 = array_1;\ for (j = 0; j + 7 < j_end; j += 8, ptr_0 += 8, ptr_1 += 8)\ for (i = 0; i < 8; i++)\ ptr_0[i] = f(ptr_1[i]);\ COPY8_DATA_SWITCH(ptr_0, 0, f, ptr_1, 0, ((j_end) & 0x7));} #define REPEAT_COPY16_ARRAY(type_0, type_1, array_0, f, array_1, j, j_end, i) \ {type_0* ptr_0 = array_0; const type_1* ptr_1 = array_1;\ for (j = 0; j + 15 < j_end; j += 16, ptr_0 += 16, ptr_1 += 16)\ for (i = 0; i < 16; i++)\ ptr_0[i] = f(ptr_1[i]);\ COPY16_DATA_SWITCH(ptr_0, 0, f, ptr_1, 0, ((j_end) & 0xf));} #define REPEAT_COPY32_ARRAY(type_0, type_1, array_0, f, array_1, j, j_end, i) \ {type_0* ptr_0 = array_0; type_1* ptr_1 = array_1;\ for (j = 0; j + 31 < j_end; j += 32, ptr_0 += 32, ptr_1 += 32)\ for (i = 0; i < 32; i++)\ ptr_0[i] = f(ptr_1[i]);\ COPY32_DATA_SWITCH(ptr_0, 0, f, ptr_1, 0, ((j_end) & 0x1f));} #define REPEAT_COPY64_ARRAY(type_0, type_1, array_0, f, array_1, j, j_end, i) \ {type_0* ptr_0 = array_0; type_1* ptr_1 = array_1;\ for (j = 0; j + 63 < j_end; j += 64, ptr_0 += 64, ptr_1 += 64)\ for (i = 0; i < 64; i++)\ ptr_0[i] = f(ptr_1[i]);\ COPY64_DATA_SWITCH(ptr_0, 0, f, ptr_1, 0, ((j_end) & 0x1f));} #endif //__FCFONT_MATH_H__