Skip to content

Commit

Permalink
CODECS: memcpy static palette
Browse files Browse the repository at this point in the history
  • Loading branch information
HappySeaFox committed Nov 16, 2023
1 parent 3e0e63c commit a0378b4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 29 deletions.
13 changes: 3 additions & 10 deletions src/sail-codecs/pcx/helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
/* 256-color palette signature. */
static const unsigned SAIL_PCX_PALETTE_SIGNATURE = 0x0C;

static const unsigned char SAIL_PCX_MONO_PALETTE[] = { 0, 0, 0, 255, 255, 255 };

sail_status_t pcx_private_read_header(struct sail_io *io, struct SailPcxHeader *header) {

SAIL_TRY(io->strict_read(io->stream, &header->id, sizeof(header->id)));
Expand Down Expand Up @@ -93,16 +95,7 @@ sail_status_t pcx_private_build_palette(enum SailPixelFormat pixel_format, struc
switch (pixel_format) {
case SAIL_PIXEL_FORMAT_BPP1_INDEXED: {
SAIL_TRY(sail_alloc_palette_for_data(SAIL_PIXEL_FORMAT_BPP24_RGB, 2, palette));

unsigned char *palette_data = (*palette)->data;

*palette_data++ = 0;
*palette_data++ = 0;
*palette_data++ = 0;
*palette_data++ = 255;
*palette_data++ = 255;
*palette_data++ = 255;

memcpy((*palette)->data, SAIL_PCX_MONO_PALETTE, 6);
break;
}
case SAIL_PIXEL_FORMAT_BPP4_INDEXED: {
Expand Down
14 changes: 4 additions & 10 deletions src/sail-codecs/psd/psd.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,16 @@
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <sail-common/sail-common.h>

#include "helpers.h"

static const unsigned SAIL_PSD_MAGIC = 0x38425053;

static const unsigned char SAIL_PSD_MONO_PALETTE[] = { 255, 255, 255, 0, 0, 0 };

/*
* Codec-specific state.
*/
Expand Down Expand Up @@ -172,16 +175,7 @@ SAIL_EXPORT sail_status_t sail_codec_load_seek_next_frame_v8_psd(void *state, st
}
} else if (mode == SAIL_PSD_MODE_BITMAP) {
SAIL_TRY(sail_alloc_palette_for_data(SAIL_PIXEL_FORMAT_BPP24_RGB, 2, &psd_state->palette));

unsigned char *palette_data = psd_state->palette->data;

*palette_data++ = 255;
*palette_data++ = 255;
*palette_data++ = 255;

*palette_data++ = 0;
*palette_data++ = 0;
*palette_data++ = 0;
memcpy(psd_state->palette->data, SAIL_PSD_MONO_PALETTE, 6);
}

/* Skip the image resources. */
Expand Down
12 changes: 3 additions & 9 deletions src/sail-codecs/xbm/xbm.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@

#include "helpers.h"

static const unsigned char SAIL_XBM_MONO_PALETTE[] = { 255, 255, 255, 0, 0, 0 };

enum SailXbmVersion {
SAIL_XBM_VERSION_10 = 10,
SAIL_XBM_VERSION_11 = 11,
Expand Down Expand Up @@ -176,15 +178,7 @@ SAIL_EXPORT sail_status_t sail_codec_load_seek_next_frame_v8_xbm(void *state, st
SAIL_TRY_OR_CLEANUP(sail_alloc_palette_for_data(SAIL_PIXEL_FORMAT_BPP24_RGB, 2, &image_local->palette),
/* cleanup */ sail_destroy_image(image_local));

unsigned char *palette = image_local->palette->data;

*palette++ = 255;
*palette++ = 255;
*palette++ = 255;

*palette++ = 0;
*palette++ = 0;
*palette++ = 0;
memcpy(image_local->palette->data, SAIL_XBM_MONO_PALETTE, 6);

*image = image_local;

Expand Down

0 comments on commit a0378b4

Please sign in to comment.