Add libraries: astc and stb_image_resize.

This commit is contained in:
Alberto Torres 2024-09-03 15:31:00 +02:00
parent e31d416f94
commit 0949e1bf99
6 changed files with 10807 additions and 0 deletions

3
.gitmodules vendored
View file

@ -13,3 +13,6 @@
[submodule "libs/nglfw"]
path = libs/nglfw
url = https://github.com/DiThi/nglfw
[submodule "libs/astc/astc-encoder"]
path = libs/astc/astc-encoder
url = https://github.com/ARM-software/astc-encoder

@ -0,0 +1 @@
Subproject commit 6d5e58f3643abd11e863dd897d576bd16c33d7b1

166
libs/astc/astc.nim Normal file
View file

@ -0,0 +1,166 @@
# We need this for the extern "C", not for exposing symbols
{.passC:"-DASTCENC_DYNAMIC_LIBRARY".}
{.compile:"astc-encoder/Source/astcenc_averages_and_directions.cpp",
compile:"astc-encoder/Source/astcenc_block_sizes.cpp",
compile:"astc-encoder/Source/astcenc_color_quantize.cpp",
compile:"astc-encoder/Source/astcenc_color_unquantize.cpp",
compile:"astc-encoder/Source/astcenc_compress_symbolic.cpp",
compile:"astc-encoder/Source/astcenc_compute_variance.cpp",
compile:"astc-encoder/Source/astcenc_decompress_symbolic.cpp",
compile:"astc-encoder/Source/astcenc_diagnostic_trace.cpp",
compile:"astc-encoder/Source/astcenc_entry.cpp",
compile:"astc-encoder/Source/astcenc_find_best_partitioning.cpp",
compile:"astc-encoder/Source/astcenc_ideal_endpoints_and_weights.cpp",
compile:"astc-encoder/Source/astcenc_image.cpp",
compile:"astc-encoder/Source/astcenc_integer_sequence.cpp",
compile:"astc-encoder/Source/astcenc_mathlib.cpp",
compile:"astc-encoder/Source/astcenc_mathlib_softfloat.cpp",
compile:"astc-encoder/Source/astcenc_partition_tables.cpp",
compile:"astc-encoder/Source/astcenc_percentile_tables.cpp",
compile:"astc-encoder/Source/astcenc_pick_best_endpoint_format.cpp",
compile:"astc-encoder/Source/astcenc_quantization.cpp",
compile:"astc-encoder/Source/astcenc_symbolic_physical.cpp",
compile:"astc-encoder/Source/astcenc_weight_align.cpp",
compile:"astc-encoder/Source/astcenc_weight_quant_xfer_tables.cpp".}
type AstcencContext* = object
type AstcencError* {.size:4.} = enum
ASTCENC_SUCCESS = 0, ASTCENC_ERR_OUT_OF_MEM, ASTCENC_ERR_BAD_CPU_FLOAT,
ASTCENC_ERR_BAD_PARAM, ASTCENC_ERR_BAD_BLOCK_SIZE, ASTCENC_ERR_BAD_PROFILE,
ASTCENC_ERR_BAD_QUALITY, ASTCENC_ERR_BAD_SWIZZLE, ASTCENC_ERR_BAD_FLAGS,
ASTCENC_ERR_BAD_CONTEXT, ASTCENC_ERR_NOT_IMPLEMENTED,
ASTCENC_ERR_BAD_DECODE_MODE, ASTCENC_ERR_DTRACE_FAILURE
template astc_assert*(err: AstcencError) =
assert err == ASTCENC_SUCCESS, "ASTC error: " & $err
type AstcencProfile* {.size:4.} = enum
ASTCENC_PRF_LDR_SRGB = 0, ASTCENC_PRF_LDR, ASTCENC_PRF_HDR_RGB_LDR_A,
ASTCENC_PRF_HDR
let ASTCENC_PRE_FASTEST*: float32 = 0.0f
let ASTCENC_PRE_FAST*: float32 = 10.0f
let ASTCENC_PRE_MEDIUM*: float32 = 60.0f
let ASTCENC_PRE_THOROUGH*: float32 = 98.0f
let ASTCENC_PRE_VERYTHOROUGH*: float32 = 99.0f
let ASTCENC_PRE_EXHAUSTIVE*: float32 = 100.0f
type AstcencSwz* {.size:4.} = enum
SWZ_R = 0, SWZ_G = 1, SWZ_B = 2, SWZ_A = 3,
SWZ_0 = 4, SWZ_1 = 5, SWZ_Z = 6
type AstcencSwizzle* {.bycopy.} = object
r*: AstcencSwz
g*: AstcencSwz
b*: AstcencSwz
a*: AstcencSwz
type AstcencType* {.size:4.} = enum
ASTCENC_TYPE_U8 = 0, ASTCENC_TYPE_F16 = 1, ASTCENC_TYPE_F32 = 2
type AstcencProgressCallback* = proc(p: float32) {.cdecl.}
let ASTCENC_FLG_MAP_NORMAL*: uint32 = 1 shl 0
let ASTCENC_FLG_USE_DECODE_UNORM8*: uint32 = 1 shl 1
let ASTCENC_FLG_USE_ALPHA_WEIGHT*: uint32 = 1 shl 2
let ASTCENC_FLG_USE_PERCEPTUAL*: uint32 = 1 shl 3
let ASTCENC_FLG_DECOMPRESS_ONLY*: uint32 = 1 shl 4
let ASTCENC_FLG_SELF_DECOMPRESS_ONLY*: uint32 = 1 shl 5
let ASTCENC_FLG_MAP_RGBM*: uint32 = 1 shl 6
let ASTCENC_ALL_FLAGS*: uint32 = ASTCENC_FLG_MAP_NORMAL or ASTCENC_FLG_MAP_RGBM or
ASTCENC_FLG_USE_ALPHA_WEIGHT or ASTCENC_FLG_USE_PERCEPTUAL or
ASTCENC_FLG_USE_DECODE_UNORM8 or ASTCENC_FLG_DECOMPRESS_ONLY or
ASTCENC_FLG_SELF_DECOMPRESS_ONLY
type AstcencConfig* {.bycopy.} = object
profile*: AstcencProfile
flags*: uint32
block_x*: uint32
block_y*: uint32
block_z*: uint32
cw_r_weight*: float32
cw_g_weight*: float32
cw_b_weight*: float32
cw_a_weight*: float32
a_scale_radius*: uint32
rgbm_m_scale*: float32
tune_partition_count_limit*: uint32
tune_2partition_index_limit*: uint32
tune_3partition_index_limit*: uint32
tune_4partition_index_limit*: uint32
tune_block_mode_limit*: uint32
tune_refinement_limit*: uint32
tune_candidate_limit*: uint32
tune_2partitioning_candidate_limit*: uint32
tune_3partitioning_candidate_limit*: uint32
tune_4partitioning_candidate_limit*: uint32
tune_db_limit*: float32
tune_mse_overshoot*: float32
tune_2partition_early_out_limit_factor*: float32
tune_3partition_early_out_limit_factor*: float32
tune_2plane_early_out_limit_correlation*: float32
tune_search_mode0_enable*: float32
progress_callback*: AstcencProgressCallback
when defined(ASTCENC_DIAGNOSTICS):
trace_file_path*: cstring
type AstcencImage* {.bycopy.} = object
dim_x*: uint32
dim_y*: uint32
dim_z*: uint32
data_type*: AstcencType
data*: ptr pointer
type AstcencBlockInfo* {.bycopy.} = object
profile*: AstcencProfile
block_x*: uint32
block_y*: uint32
block_z*: uint32
texel_count*: uint32
is_error_block*: bool
is_constant_block*: bool
is_hdr_block*: bool
is_dual_plane_block*: bool
partition_count*: uint32
partition_index*: uint32
dual_plane_component*: uint32
color_endpoint_modes*: array[4, uint32]
color_level_count*: uint32
weight_level_count*: uint32
weight_x*: uint32
weight_y*: uint32
weight_z*: uint32
color_endpoints*: array[4, array[2, array[4, float32]]]
weight_values_plane1*: array[216, float32]
weight_values_plane2*: array[216, float32]
partition_assignment*: array[216, uint8]
proc astcenc_config_init*(profile: AstcencProfile; block_x: uint32; block_y: uint32;
block_z: uint32; quality: float32; flags: uint32;
config: ptr AstcencConfig): AstcencError {.cdecl,
importc: "astcenc_config_init".}
proc astcenc_context_alloc*(config: ptr AstcencConfig; thread_count: uint32;
context: var ptr AstcencContext): AstcencError {.cdecl,
importc: "astcenc_context_alloc".}
proc astcenc_compress_image*(context: ptr AstcencContext; image: ptr AstcencImage;
swizzle: ptr AstcencSwizzle; data_out: ptr uint8;
data_len: csize_t; thread_index: uint32): AstcencError {.
cdecl, importc: "astcenc_compress_image".}
proc astcenc_compress_reset*(context: ptr AstcencContext): AstcencError {.cdecl,
importc: "astcenc_compress_reset".}
proc astcenc_decompress_image*(context: ptr AstcencContext; data: ptr uint8;
data_len: csize_t; image_out: ptr AstcencImage;
swizzle: ptr AstcencSwizzle; thread_index: uint32): AstcencError {.
cdecl, importc: "astcenc_decompress_image".}
proc astcenc_decompress_reset*(context: ptr AstcencContext): AstcencError {.cdecl,
importc: "astcenc_decompress_reset".}
proc astcenc_context_free*(context: ptr AstcencContext) {.cdecl,
importc: "astcenc_context_free".}
proc astcenc_get_block_info*(context: ptr AstcencContext; data: array[16, uint8];
info: ptr AstcencBlockInfo): AstcencError {.cdecl,
importc: "astcenc_get_block_info".}
proc astcenc_get_error_string*(status: AstcencError): cstring {.cdecl,
importc: "astcenc_get_error_string".}

View file

@ -0,0 +1,63 @@
{.compile:"stb_image_resize2.cpp".}
type StbirPixelLayout* {.size:4.} = enum
StbirBgr = 0 # 3-chan, with order specified (for channel flipping)
Stbir1channel = 1
Stbir2channel = 2
StbirRgb = 3 # 3-chan, with order specified (for channel flipping)
StbirRgba = 4
Stbir4channel = 5
# StbirRgba = 4 # alpha formats, where alpha is NOT premultiplied into color channels
StbirBgra = 6
StbirArgb = 7
StbirAbgr = 8
StbirRa = 9
StbirAr = 10
StbirRgbaPm = 11 # alpha formats, where alpha is premultiplied into color channels
StbirBgraPm = 12
StbirArgbPm = 13
StbirAbgrPm = 14
StbirRaPm = 15
StbirArPm = 16
# StbirRgbaNoAw = 11 # alpha formats, where NO alpha weighting is applied at all!
# StbirBgraNoAw = 12 # these are just synonyms for the _PM flags (which also do
# StbirArgbNoAw = 13 # no alpha weighting). These names just make it more clear
# StbirAbgrNoAw = 14 # for some folks).
# StbirRaNoAw = 15
# StbirArNoAw = 16
type StbirEdge* {.size:4.} = enum
STBIR_EDGE_CLAMP = 0,
STBIR_EDGE_REFLECT = 1,
STBIR_EDGE_WRAP = 2, # this edge mode is slower and uses more memory
STBIR_EDGE_ZERO = 3,
type StbirFilter* {.size:4.} = enum
STBIR_FILTER_DEFAULT = 0, # use same filter type that easy-to-use API chooses
STBIR_FILTER_BOX = 1, # A trapezoid w/1-pixel wide ramps, same result as box for integer scale ratios
STBIR_FILTER_TRIANGLE = 2, # On upsampling, produces same results as bilinear texture filtering
STBIR_FILTER_CUBICBSPLINE = 3, # The cubic b-spline (aka Mitchell-Netrevalli with B=1,C=0), gaussian-esque
STBIR_FILTER_CATMULLROM = 4, # An interpolating cubic spline
STBIR_FILTER_MITCHELL = 5, # Mitchell-Netrevalli filter with B=1/3, C=1/3
STBIR_FILTER_POINT_SAMPLE = 6, # Simple point sampling
STBIR_FILTER_OTHER = 7, # User callback specified
type StbirDatatype* {.size:4.} = enum
STBIR_TYPE_UINT8 = 0,
STBIR_TYPE_UINT8_SRGB = 1,
STBIR_TYPE_UINT8_SRGB_ALPHA = 2, # alpha channel, when present, should also be SRGB (this is very unusual)
STBIR_TYPE_UINT16 = 3,
STBIR_TYPE_FLOAT = 4,
STBIR_TYPE_HALF_FLOAT = 5
proc stbir_resize*(input_pixels: pointer; input_w, input_h, input_stride_in_bytes: int32;
output_pixels: pointer; output_w, output_h, output_stride_in_bytes: int32;
pixel_layout: StbirPixelLayout, data_type: StbirDatatype,
edge: StbirEdge, filter: StbirFilter) {.importc,cdecl.}

View file

@ -0,0 +1,2 @@
#define STB_IMAGE_RESIZE_IMPLEMENTATION
#include "stb_image_resize2.h"

File diff suppressed because it is too large Load diff