Skip to content

Commit

Permalink
PSD: 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 d89806f commit d566068
Showing 1 changed file with 19 additions and 23 deletions.
42 changes: 19 additions & 23 deletions src/sail-codecs/psd/psd.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ static const unsigned SAIL_PSD_MAGIC = 0x38425053;
*/
struct psd_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;

bool frame_loaded;

Expand All @@ -51,24 +51,29 @@ struct psd_state {
struct sail_palette *palette;
};

static sail_status_t alloc_psd_state(struct psd_state **psd_state) {
static sail_status_t alloc_psd_state(struct sail_io *io,
const struct sail_load_options *load_options,
const struct sail_save_options *save_options,
struct psd_state **psd_state) {

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

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

(*psd_state)->frame_loaded = false;
.frame_loaded = false,

(*psd_state)->channels = 0;
(*psd_state)->depth = 0;
(*psd_state)->compression = SAIL_PSD_COMPRESSION_NONE;
(*psd_state)->bytes_per_channel = 0;
(*psd_state)->scan_buffer = NULL;
(*psd_state)->palette = NULL;
.channels = 0,
.depth = 0,
.compression = SAIL_PSD_COMPRESSION_NONE,
.bytes_per_channel = 0,
.scan_buffer = NULL,
.palette = NULL,
};

return SAIL_OK;
}
Expand All @@ -81,9 +86,6 @@ static void destroy_psd_state(struct psd_state *psd_state) {

sail_free(psd_state->scan_buffer);

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

sail_destroy_palette(psd_state->palette);

sail_free(psd_state);
Expand All @@ -99,15 +101,9 @@ SAIL_EXPORT sail_status_t sail_codec_load_init_v8_psd(struct sail_io *io, const

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

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

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

/* Init decoder. PSD spec: https://www.adobe.com/devnet-apps/photoshop/fileformatashtml/#50577409_89817 */
uint32_t magic;
SAIL_TRY(psd_private_get_big_endian_uint32_t(psd_state->io, &magic));
Expand Down

0 comments on commit d566068

Please sign in to comment.