Skip to content

Commit

Permalink
PCX: Hold shallow pointers to load_options/save_options
Browse files Browse the repository at this point in the history
  • Loading branch information
HappySeaFox committed Nov 11, 2023
1 parent 28ba681 commit b8b6572
Showing 1 changed file with 14 additions and 18 deletions.
32 changes: 14 additions & 18 deletions src/sail-codecs/pcx/pcx.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,27 +45,32 @@ static const uint8_t SAIL_PCX_RLE_COUNT_MASK = 0x3F;
*/
struct pcx_state {
struct sail_io *io;
struct sail_load_options *load_options;
struct sail_save_options *save_options;
const struct sail_load_options *load_options;
const struct sail_save_options *save_options;

struct SailPcxHeader pcx_header;
unsigned char *scanline_buffer; /* buffer to read a single plane scan line. */

bool frame_loaded;
};

static sail_status_t alloc_pcx_state(struct pcx_state **pcx_state) {
static sail_status_t alloc_pcx_state(struct sail_io *io,
const struct sail_load_options *load_options,
const struct sail_save_options *save_options,
struct pcx_state **pcx_state) {

void *ptr;
SAIL_TRY(sail_malloc(sizeof(struct pcx_state), &ptr));
*pcx_state = ptr;

(*pcx_state)->io = NULL;
(*pcx_state)->load_options = NULL;
(*pcx_state)->save_options = NULL;
**pcx_state = (struct pcx_state) {
.io = io,
.load_options = load_options,
.save_options = save_options,

(*pcx_state)->scanline_buffer = NULL;
(*pcx_state)->frame_loaded = false;
.scanline_buffer = NULL,
.frame_loaded = false,
};

return SAIL_OK;
}
Expand All @@ -76,9 +81,6 @@ static void destroy_pcx_state(struct pcx_state *pcx_state) {
return;
}

sail_destroy_load_options(pcx_state->load_options);
sail_destroy_save_options(pcx_state->save_options);

sail_free(pcx_state->scanline_buffer);

sail_free(pcx_state);
Expand All @@ -94,15 +96,9 @@ SAIL_EXPORT sail_status_t sail_codec_load_init_v8_pcx(struct sail_io *io, const

/* Allocate a new state. */
struct pcx_state *pcx_state;
SAIL_TRY(alloc_pcx_state(&pcx_state));
SAIL_TRY(alloc_pcx_state(io, load_options, NULL, &pcx_state));
*state = pcx_state;

/* Save I/O for further operations. */
pcx_state->io = io;

/* Deep copy load options. */
SAIL_TRY(sail_copy_load_options(load_options, &pcx_state->load_options));

/* Read PCX header. */
SAIL_TRY(pcx_private_read_header(pcx_state->io, &pcx_state->pcx_header));

Expand Down

0 comments on commit b8b6572

Please sign in to comment.