Skip to content

Commit

Permalink
Use mintty's standard types defined in std.h/config.h (pointed in min…
Browse files Browse the repository at this point in the history
…tty#593)

uint8_t -> uchar
uint32_t -> uint
int32_t for palette -> colour
  • Loading branch information
saitoha committed Sep 27, 2016
1 parent 7b6bf81 commit a664ed8
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 47 deletions.
34 changes: 17 additions & 17 deletions src/sixel.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
#include "sixel_hls.h"
#include "winpriv.h"

#define SIXEL_RGB(r, g, b) (((r) << 16) + ((g) << 8) + (b))
#define SIXEL_RGB(r, g, b) ((r) + ((g) << 8) + ((b) << 16))
#define PALVAL(n,a,m) (((n) * (a) + ((m) / 2)) / (m))
#define SIXEL_XRGB(r,g,b) SIXEL_RGB(PALVAL(r, 255, 100), PALVAL(g, 255, 100), PALVAL(b, 255, 100))

static int32_t const sixel_default_color_table[] = {
static colour const sixel_default_color_table[] = {
SIXEL_XRGB(0, 0, 0), /* 0 Black */
SIXEL_XRGB(20, 20, 80), /* 1 Blue */
SIXEL_XRGB(80, 13, 13), /* 2 Red */
Expand Down Expand Up @@ -52,18 +52,18 @@ set_default_color(sixel_image_t *image)
for (r = 0; r < 6; r++) {
for (g = 0; g < 6; g++) {
for (b = 0; b < 6; b++) {
image->palette[n++] = SIXEL_RGB(r * 51, g * 51, b * 51);
image->palette[n++] = make_colour(r * 51, g * 51, b * 51);
}
}
}

/* colors 233-256 are a grayscale ramp, intentionally leaving out */
for (i = 0; i < 24; i++) {
image->palette[n++] = SIXEL_RGB(i * 11, i * 11, i * 11);
image->palette[n++] = make_colour(i * 11, i * 11, i * 11);
}

for (; n < DECSIXEL_PALETTE_MAX; n++) {
image->palette[n] = SIXEL_RGB(255, 255, 255);
image->palette[n] = make_colour(255, 255, 255);
}

return (0);
Expand Down Expand Up @@ -180,8 +180,8 @@ sixel_image_deinit(sixel_image_t *image)

int
sixel_parser_init(sixel_state_t *st,
int32_t fgcolor, int32_t bgcolor,
uint8_t use_private_register)
colour fgcolor, colour bgcolor,
uchar use_private_register)
{
int status = (-1);

Expand Down Expand Up @@ -214,15 +214,15 @@ sixel_parser_set_default_color(sixel_state_t *st)
}

int
sixel_parser_finalize(sixel_state_t *st, uint8_t *pixels)
sixel_parser_finalize(sixel_state_t *st, uchar *pixels)
{
int status = (-1);
int sx;
int sy;
sixel_image_t *image = &st->image;
int x, y;
sixel_color_no_t *src;
uint8_t *dst;
uchar *dst;
int color;

if (++st->max_x < st->attributed_ph) {
Expand Down Expand Up @@ -255,27 +255,27 @@ sixel_parser_finalize(sixel_state_t *st, uint8_t *pixels)
for (y = 0; y < st->image.height; ++y) {
for (x = 0; x < st->image.width; ++x) {
color = st->image.palette[*src++];
*dst++ = color >> 0 & 0xff; /* r */
*dst++ = color >> 8 & 0xff; /* g */
*dst++ = color >> 16 & 0xff; /* b */
*dst++ = color >> 8 & 0xff; /* g */
*dst++ = color >> 0 & 0xff; /* r */
dst++; /* a */
}
/* fill right padding with bgcolor */
for (; x < st->image.width; ++x) {
color = st->image.palette[0]; /* bgcolor */
*dst++ = color >> 0 & 0xff; /* r */
*dst++ = color >> 8 & 0xff; /* g */
*dst++ = color >> 16 & 0xff; /* b */
*dst++ = color >> 8 & 0xff; /* g */
*dst++ = color >> 0 & 0xff; /* r */
dst++; /* a */
}
}
/* fill bottom padding with bgcolor */
for (; y < st->image.height; ++y) {
for (x = 0; x < st->image.width; ++x) {
color = st->image.palette[0]; /* bgcolor */
*dst++ = color >> 0 & 0xff; /* r */
*dst++ = color >> 8 & 0xff; /* g */
*dst++ = color >> 16 & 0xff; /* b */
*dst++ = color >> 8 & 0xff; /* g */
*dst++ = color >> 0 & 0xff; /* r */
dst++; /* a */
}
}
Expand All @@ -288,7 +288,7 @@ sixel_parser_finalize(sixel_state_t *st, uint8_t *pixels)

/* convert sixel data into indexed pixel bytes and palette data */
int
sixel_parser_parse(sixel_state_t *st, uint8_t *p, size_t len)
sixel_parser_parse(sixel_state_t *st, uchar *p, size_t len)
{
int status = (-1);
int n;
Expand All @@ -301,7 +301,7 @@ sixel_parser_parse(sixel_state_t *st, uint8_t *p, size_t len)
int sy;
int c;
int pos;
uint8_t *p0 = p;
uchar *p0 = p;
sixel_image_t *image = &st->image;

if (!image->data)
Expand Down
52 changes: 26 additions & 26 deletions src/sixel.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@
#define DECSIXEL_WIDTH_MAX 4096
#define DECSIXEL_HEIGHT_MAX 4096

typedef uint16_t sixel_color_no_t;
typedef ushort sixel_color_no_t;

typedef struct sixel_image_buffer {
sixel_color_no_t *data;
int32_t width;
int32_t height;
int32_t palette[DECSIXEL_PALETTE_MAX];
int16_t ncolors;
int8_t palette_modified;
int8_t use_private_register;
int width;
int height;
colour palette[DECSIXEL_PALETTE_MAX];
sixel_color_no_t ncolors;
int palette_modified;
int use_private_register;
} sixel_image_t;

typedef enum parse_state {
Expand All @@ -31,29 +31,29 @@ typedef enum parse_state {

typedef struct parser_context {
parse_state_t state;
int32_t pos_x;
int32_t pos_y;
int32_t max_x;
int32_t max_y;
int32_t attributed_pan;
int32_t attributed_pad;
int32_t attributed_ph;
int32_t attributed_pv;
int32_t repeat_count;
int32_t color_index;
int32_t bgindex;
int32_t grid_width;
int32_t grid_height;
int32_t param;
int32_t nparams;
int32_t params[DECSIXEL_PARAMS_MAX];
int pos_x;
int pos_y;
int max_x;
int max_y;
int attributed_pan;
int attributed_pad;
int attributed_ph;
int attributed_pv;
int repeat_count;
int color_index;
int bgindex;
int grid_width;
int grid_height;
int param;
int nparams;
int params[DECSIXEL_PARAMS_MAX];
sixel_image_t image;
} sixel_state_t;

int sixel_parser_init(sixel_state_t *st, int32_t fgcolor, int32_t bgcolor, uint8_t use_private_register);
int sixel_parser_parse(sixel_state_t *st, uint8_t *p, size_t len);
int sixel_parser_init(sixel_state_t *st, colour fgcolor, colour bgcolor, uchar use_private_register);
int sixel_parser_parse(sixel_state_t *st, uchar *p, size_t len);
int sixel_parser_set_default_color(sixel_state_t *st);
int sixel_parser_finalize(sixel_state_t *st, uint8_t *pixels);
int sixel_parser_finalize(sixel_state_t *st, uchar *pixels);
void sixel_parser_deinit(sixel_state_t *st);

#endif
5 changes: 1 addition & 4 deletions src/termout.c
Original file line number Diff line number Diff line change
Expand Up @@ -1125,10 +1125,7 @@ do_dcs(void)
st = term.imgs.parser_state = calloc(1, sizeof(sixel_state_t));
sixel_parser_set_default_color(st);
}
status = sixel_parser_init(st,
(fg & 0xff) << 16 | (fg & 0xff00) | (fg & 0xff0000) >> 16,
(bg & 0xff) << 16 | (bg & 0xff00) | (bg & 0xff0000) >> 16,
term.private_color_registers);
status = sixel_parser_init(st, fg, bg, term.private_color_registers);
if (status < 0)
return;
}
Expand Down

0 comments on commit a664ed8

Please sign in to comment.