Skip to content

Commit 7e8f092

Browse files
committed
Code comments
1 parent 7b617e7 commit 7e8f092

File tree

1 file changed

+87
-2
lines changed

1 file changed

+87
-2
lines changed

src/smol_cube.h

+87-2
Original file line numberDiff line numberDiff line change
@@ -8,42 +8,127 @@
88

99
enum class smcube_data_type
1010
{
11-
Float32 = 0,
12-
Float16,
11+
Float32 = 0, // Data is 32 bit floating point
12+
Float16, // Data is 16 bit (half-precision) float
1313
DataTypeCount
1414
};
1515

16+
// Flags used in `smcube_save_to_file_smcube`.
17+
// They can be combined together.
1618
enum smcube_save_flags
1719
{
1820
smcube_save_flag_None = 0,
21+
22+
// Apply lossless data filter to make the file more compressible.
23+
// Usually you want this if you plan to compress the file with
24+
// zlib/zstd/lz4 or similar general purpose compressors. This costs
25+
// a tiny bit of performance when loading, but makes the data 2-3x more
26+
// compressible.
1927
smcube_save_flag_FilterData = (1 << 0),
28+
29+
// Convert LUT data to half-precision (16 bit) floating point format.
2030
smcube_save_flag_ConvertToFloat16 = (1 << 1),
31+
32+
// Make the data be 4 channels (RGBA) instead of usual 3 (RGB).
33+
// The fourth channel is not really used, but LUT in this format
34+
// can be faster and more convenient to load onto GPU. Since many
35+
// 3D APIs do not support 3-channel textures directly.
2136
smcube_save_flag_ExpandTo4Channels = (1 << 2),
2237
};
2338

2439
struct smcube_luts;
2540

41+
// Load LUT(s) from a file at given path.
42+
//
43+
// If file path ends with ".smcube" assumes it is a binary smol-cube file,
44+
// and effectively calls `smcube_load_from_file_smcube`.
45+
// If file path ends with ".cube" assumes it is a Resolve/Adobe LUT file,
46+
// and effectively calls `smcube_load_from_file_resolve_cube`.
47+
//
48+
// Use the resulting opaque handle in other functions to query/inspect/save
49+
// the LUT(s). Use `smcube_free` to delete the LUT(s).
50+
//
51+
// Returns nullptr in case of failure.
2652
smcube_luts* smcube_load_from_file(const char* path);
53+
54+
// Load LUT(s) from smol-cube binaty file at path.
2755
smcube_luts* smcube_load_from_file_smcube(const char* path);
56+
57+
// Load LUT(s) from Resolve/Adobe LUT file at path.
2858
smcube_luts* smcube_load_from_file_resolve_cube(const char* path);
59+
60+
// Delete the LUT(s).
2961
void smcube_free(smcube_luts* handle);
3062

63+
// Save LUT(s) to smol-cube format file.
64+
// Flags control filtering, format and channel conversion.
65+
// Returns true if all is ok.
3166
bool smcube_save_to_file_smcube(const char* path, const smcube_luts* luts, smcube_save_flags flags = smcube_save_flag_None);
67+
68+
// Save LUT(s) to Resolve/Adobe LUT format file.
69+
//
70+
// Note that this only supports LUTs that the Resolve format can handle:
71+
// - 3 channels,
72+
// - 32 bit floating point,
73+
// - one 1D LUT, or one 3D LUT, or one 1D LUT followed by one 3D LUT,
74+
// - 3D LUT, if present, must have the same x/y/z sizes.
75+
//
76+
// Returns true if all is ok.
3277
bool smcube_save_to_file_resolve_cube(const char* path, const smcube_luts* luts);
3378

79+
// Get "title" metadata of the LUT.
80+
// Title is optional and nullptr would be returned in that case.
3481
const char* smcube_get_title(const smcube_luts* handle);
82+
83+
// Get "comment" metadata of the LUT.
84+
// Comment is optional and nullptr would be returned in that case.
3585
const char* smcube_get_comment(const smcube_luts* handle);
86+
87+
// Get number of LUTs.
88+
// Most files contain just one LUT, but some could contain more
89+
// (typical combination is 1D "shaper" LUT followed by a 3D LUT).
3690
size_t smcube_get_count(const smcube_luts* handle);
3791

92+
// Get number of channels in a LUT (3 = RGB, 4 = RGBA).
3893
int smcube_lut_get_channels(const smcube_luts* handle, size_t index);
94+
95+
// Get dimension of a LUT (1 = 1D, 2 = 2D, 3 = 3D).
3996
int smcube_lut_get_dimension(const smcube_luts* handle, size_t index);
97+
98+
// Get data type of the LUT data.
4099
smcube_data_type smcube_lut_get_data_type(const smcube_luts* handle, size_t index);
100+
101+
// Get LUT size in X dimension.
41102
int smcube_lut_get_size_x(const smcube_luts* handle, size_t index);
103+
// Get LUT size in Y dimension (only relevant for 2D/3D LUTs).
42104
int smcube_lut_get_size_y(const smcube_luts* handle, size_t index);
105+
// Get LUT size in Z dimension (only relevant for 3D LUTs).
43106
int smcube_lut_get_size_z(const smcube_luts* handle, size_t index);
107+
108+
// Get the actual data of the LUT.
109+
//
110+
// Data is laid out in row-major order, i.e. X dimension (which usually
111+
// means "red") changes the fastest, and Z dimension (which usually
112+
// means "blue") changes the slowest.
113+
//
114+
// The data is `size_x * size_y * size_z * channels` numbers in either
115+
// float (4 bytes/number) or half-float (2 bytes/number) depending on
116+
// LUT data type.
117+
//
118+
// If data is 4 channels, then the data can be directly loaded into a
119+
// 3D texture on most/all graphics APIs.
44120
const void* smcube_lut_get_data(const smcube_luts* handle, size_t index);
45121

122+
// Calculate LUT data size in bytes.
46123
size_t smcube_lut_get_data_size(const smcube_luts* handle, size_t index);
124+
125+
// Calculate byte size of the data type (4 or 2 currently).
47126
size_t smcube_data_type_get_size(smcube_data_type type);
48127

128+
// Convert LUT data into a different format or channel count.
129+
//
130+
// Note that this leaves LUT data unchanged; new data is written into
131+
// a buffer that you provided. Destination buffer must contain
132+
// space for `size_x * size_y * size_z * dst_channels` numbers of
133+
// `dst_type` format.
49134
void smcube_lut_convert_data(const smcube_luts* handle, size_t index, smcube_data_type dst_type, int dst_channels, void* dst_data);

0 commit comments

Comments
 (0)