Skip to content

Commit

Permalink
all: major 0.4.0 commit
Browse files Browse the repository at this point in the history
A number of changes made:
- switching to float internally (should be faster & more accurate)
- deduplicated some code
- API/ABI break as usual
- bump version to 0.4
  • Loading branch information
Traneptora committed Jan 20, 2024
1 parent 74c71d9 commit 1a58f1a
Show file tree
Hide file tree
Showing 8 changed files with 147 additions and 224 deletions.
8 changes: 5 additions & 3 deletions meson.build
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
project('hydrium', 'c',
license: ['BSD-2-Clause'],
version : '0.3.0',
version : '0.4.0',
default_options: [
'buildtype=minsize',
'c_std=c99',
Expand Down Expand Up @@ -38,7 +38,6 @@ libhydrium_sources = files(
'src/libhydrium/entropy.c',
'src/libhydrium/libhydrium.c',
'src/libhydrium/memory.c',
'src/libhydrium/xyb.c',
)

hydrium_sources = files(
Expand All @@ -47,17 +46,20 @@ hydrium_sources = files(

libhydrium_includes = include_directories('src/include')

m_dep = cc.find_library('m')

libhydrium = library('hydrium',
sources: libhydrium_sources,
soversion : '0',
c_args: cflags,
link_args: ldflags,
install: true,
include_directories: libhydrium_includes,
dependencies: [m_dep],
)

libhydrium_dep = declare_dependency(include_directories: libhydrium_includes, link_with: libhydrium)
libspng_dep = dependency('spng', fallback : ['spng', 'spng_dep'], default_options: ['default_library=static'])
libspng_dep = dependency('spng', fallback : ['spng', 'spng_dep'])

hydrium = executable('hydrium',
sources: [hydrium_sources],
Expand Down
18 changes: 8 additions & 10 deletions src/hydrium.c
Original file line number Diff line number Diff line change
Expand Up @@ -224,13 +224,13 @@ int main(int argc, const char *argv[]) {
for (uint32_t x = 0; x < tile_width; x++) {
if (ihdr.bit_depth > 8) {
const uint16_t *tile_buffer = ((const uint16_t *)buffer) + x * tile_size_x * 4;
const uint16_t *const rgb[3] = {tile_buffer, tile_buffer + 1, tile_buffer + 2};
const void *const rgb[3] = {tile_buffer, tile_buffer + 1, tile_buffer + 2};
// We divide by 2 because spng_stride is in bytes, not in uint16_t units
ret = hyd_send_tile(encoder, rgb, x, y, spng_stride / 2, 4, -1);
ret = hyd_send_tile(encoder, rgb, x, y, spng_stride / 2, 4, -1, HYD_UINT16);
} else {
const uint8_t *tile_buffer = ((const uint8_t *)buffer) + x * tile_size_x * 3;
const uint8_t *const rgb[3] = {tile_buffer, tile_buffer + 1, tile_buffer + 2};
ret = hyd_send_tile8(encoder, rgb, x, y, spng_stride, 3, -1);
const void *const rgb[3] = {tile_buffer, tile_buffer + 1, tile_buffer + 2};
ret = hyd_send_tile(encoder, rgb, x, y, spng_stride, 3, -1, HYD_UINT8);
}
if (ret != HYD_NEED_MORE_OUTPUT && ret < HYD_ERROR_START)
goto done;
Expand All @@ -255,18 +255,16 @@ int main(int argc, const char *argv[]) {
spng_ctx_free(spng_context);
error_msg = hyd_error_message_get(encoder);
hyd_encoder_destroy(encoder);
if (buffer)
free(buffer);
if (output_buffer)
free(output_buffer);
free(buffer);
free(output_buffer);
hyd_profiling_allocator_destroy(allocator);
if (ret < HYD_ERROR_START)
fprintf(stderr, "Hydrium error occurred. Error code: %d\n", ret);
if (error_msg && *error_msg)
fprintf(stderr, "Error message: %s\n", error_msg);
if (!ret)
fprintf(stderr, "Total libhydrium heap memory: %llu bytes\nMax libhydrium heap memory: %llu bytes\n",
(long long unsigned)profiler.total_alloced, (long long unsigned)profiler.max_alloced);
fprintf(stderr, "Total libhydrium heap memory: %zu bytes\nMax libhydrium heap memory: %zu bytes\n",
profiler.total_alloced, profiler.max_alloced);

return ret;
}
29 changes: 12 additions & 17 deletions src/include/libhydrium/libhydrium.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
* 0x1XXXYYYZZZ where XXX is the major version, YYY is the minor version,
* and ZZZ is the point release.
*/
#define HYDRIUM_VERSION_INT 0x1000003000
#define HYDRIUM_VERSION_STRING "0.3.0"
#define HYDRIUM_VERSION_INT 0x1000004000
#define HYDRIUM_VERSION_STRING "0.4.0"

#ifdef _WIN32
#ifdef HYDRIUM_INTERNAL_BUILD
Expand Down Expand Up @@ -68,6 +68,12 @@ typedef enum HYDStatusCode {
HYD_INTERNAL_ERROR = -15,
} HYDStatusCode;

typedef enum HYDSampleFormat {
HYD_UINT8,
HYD_UINT16,
HYD_FLOAT32,
} HYDSampleFormat;

typedef struct HYDAllocator {
void *opaque;
void *(*malloc_func)(size_t size, void *opaque);
Expand Down Expand Up @@ -168,7 +174,7 @@ HYDRIUM_EXPORT HYDStatusCode hyd_set_metadata(HYDEncoder *encoder, const HYDImag
HYDRIUM_EXPORT HYDStatusCode hyd_provide_output_buffer(HYDEncoder *encoder, uint8_t *buffer, size_t buffer_len);

/**
* @brief Provide a buffer of 16-bit RGB pixel data to the hydrium encoder for it to encode.
* @brief Provide a buffer of RGB pixel data to the hydrium encoder for it to encode.
*
* By default, hydrium encodes one tile at a time, and no tile references any other tile. A tile is 256x256,
* unless tile_size_shift_x and/or tile_size_shift_y are set to something positive. In that case, the size of a
Expand Down Expand Up @@ -223,20 +229,9 @@ HYDRIUM_EXPORT HYDStatusCode hyd_provide_output_buffer(HYDEncoder *encoder, uint
* @param row_stride The line size of the pixel buffer.
* @param pixel_stride The inter-pixel stride of the buffer.
*/
HYDRIUM_EXPORT HYDStatusCode hyd_send_tile(HYDEncoder *encoder, const uint16_t *const buffer[3],
uint32_t tile_x, uint32_t tile_y,
ptrdiff_t row_stride, ptrdiff_t pixel_stride, int is_last);

/**
* @brief A convenience function to send 8-bit pixel data instead of 16-bit pixel data. Each sample
* will be multiplied by 257. (65535 = 255 * 257)
*
* @see hyd_send_tile
*/
HYDRIUM_EXPORT HYDStatusCode hyd_send_tile8(HYDEncoder *encoder, const uint8_t *const buffer[3],
uint32_t tile_x, uint32_t tile_y,
ptrdiff_t row_stride, ptrdiff_t pixel_stride, int is_last);

HYDRIUM_EXPORT HYDStatusCode hyd_send_tile(HYDEncoder *encoder, const void *const buffer[3],
uint32_t tile_x, uint32_t tile_y, ptrdiff_t row_stride,
ptrdiff_t pixel_stride, int is_last, HYDSampleFormat sample_fmt);

/**
* @brief Release the output buffer that was previously provided by hyd_provide_output_buffer.
Expand Down
Loading

0 comments on commit 1a58f1a

Please sign in to comment.