Skip to content

Commit

Permalink
Remove unnecessary function pointer typedef
Browse files Browse the repository at this point in the history
Some people might argue that typedefs make function pointers more
readable. What's worse, those people might be right.
But in the end, this repository doesn't use typedefs anywhere, and
creating one just for this return value to avoid a longer signature
doesn't seem correct.
Besides, removing the typedef makes the callback's signature visible
at the caller's site, since it is assigned to a variable.
  • Loading branch information
aaaaaa123456789 committed Jan 14, 2022
1 parent e6c6614 commit a2ec4a0
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
5 changes: 3 additions & 2 deletions src/jpegcomponents.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ unsigned get_JPEG_component_count (uint32_t components) {
return 4;
}

JPEG_component_transfer_function * get_JPEG_component_transfer_function (struct context * context, const struct JPEG_marker_layout * layout, uint32_t components) {
void (* get_JPEG_component_transfer_function (struct context * context, const struct JPEG_marker_layout * layout, uint32_t components))
(uint64_t * restrict, size_t, unsigned, const double **) {
/* The JPEG standard has a very large deficiency: it specifies how to encode an arbitrary set of components of an
image, but it doesn't specify what those components mean. Components have a single byte ID to identify them, but
beyond that, the standard just hopes that applications can somehow figure it all out.
Expand Down Expand Up @@ -130,7 +131,7 @@ JPEG_component_transfer_function * get_JPEG_component_transfer_function (struct
}
}

void append_JPEG_color_depth_metadata (struct context * context, JPEG_component_transfer_function * transfer, unsigned bitdepth) {
void append_JPEG_color_depth_metadata (struct context * context, void (* transfer) (uint64_t * restrict, size_t, unsigned, const double **), unsigned bitdepth) {
if (transfer == &JPEG_transfer_grayscale)
add_color_depth_metadata(context, 0, 0, 0, 0, bitdepth);
else if (transfer == &JPEG_transfer_alpha_grayscale)
Expand Down
2 changes: 1 addition & 1 deletion src/jpegread.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
void load_JPEG_data (struct context * context, unsigned flags, size_t limit) {
struct JPEG_marker_layout * layout = load_JPEG_marker_layout(context);
uint32_t components = determine_JPEG_components(context, layout -> hierarchical ? layout -> hierarchical : *layout -> frames);
JPEG_component_transfer_function * transfer = get_JPEG_component_transfer_function(context, layout, components);
void (* transfer) (uint64_t * restrict, size_t, unsigned, const double **) = get_JPEG_component_transfer_function(context, layout, components);
context -> image -> type = PLUM_IMAGE_JPEG;
context -> image -> frames = 1;
size_t p;
Expand Down
5 changes: 3 additions & 2 deletions src/proto.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,9 @@ internal unsigned next_JPEG_arithmetic_bit(struct context *, size_t * restrict,
// jpegcomponents.c
internal uint32_t determine_JPEG_components(struct context *, size_t);
internal unsigned get_JPEG_component_count(uint32_t);
internal JPEG_component_transfer_function * get_JPEG_component_transfer_function(struct context *, const struct JPEG_marker_layout *, uint32_t);
internal void append_JPEG_color_depth_metadata(struct context *, JPEG_component_transfer_function *, unsigned);
internal void (* get_JPEG_component_transfer_function(struct context *, const struct JPEG_marker_layout *, uint32_t))
(uint64_t * restrict, size_t, unsigned, const double **);
internal void append_JPEG_color_depth_metadata(struct context *, void (*) (uint64_t * restrict, size_t, unsigned, const double **), unsigned);
internal void JPEG_transfer_RGB(uint64_t * restrict, size_t, unsigned, const double **);
internal void JPEG_transfer_BGR(uint64_t * restrict, size_t, unsigned, const double **);
internal void JPEG_transfer_ABGR(uint64_t * restrict, size_t, unsigned, const double **);
Expand Down
2 changes: 0 additions & 2 deletions src/struct.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

#include "../header/libplum.h"

typedef void JPEG_component_transfer_function(uint64_t * restrict, size_t, unsigned, const double **);

union allocator_node {
max_align_t alignment;
struct {
Expand Down

0 comments on commit a2ec4a0

Please sign in to comment.