Skip to content

Commit

Permalink
* ui_draw_str.c: draw_picture() doesn't clear the background
Browse files Browse the repository at this point in the history
  if ui_inline_picture_t::transparent is 1.
* ui_virtual_kbd.c, ui_sb_view.h, pixmap_engine.c: Fix with the modification
  of ui_imagelib_load_file().
* vt_parser.[ch], ui_screen.c, ui_screen_manager.c, vterm.c:
  Add 'transparent' to vt_xterm_event_listener_t::get_picture_data().
* ui_picture.[ch]: Add 'transparent' to ui_inline_picture_t.
* ui_imagelib.h, */ui_imagelib.c: Add 'transparent' to arguments of
  ui_imagelib_load_file().
* c_sixel.c: load_sixel_from_{data|file}() check whether P2 is 1 or not
  and return it by 'transparent' argument.
  • Loading branch information
arakiken committed Feb 3, 2024
1 parent 1b9f2e8 commit 5123203
Show file tree
Hide file tree
Showing 23 changed files with 272 additions and 142 deletions.
19 changes: 19 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
2024-02-03 Araki Ken <arakiken@users.sf.net>

* ui_draw_str.c: draw_picture() doesn't clear the background
if ui_inline_picture_t::transparent is 1.

* ui_virtual_kbd.c, ui_sb_view.h, pixmap_engine.c: Fix with the modification
of ui_imagelib_load_file().

* vt_parser.[ch], ui_screen.c, ui_screen_manager.c, vterm.c:
Add 'transparent' to vt_xterm_event_listener_t::get_picture_data().

* ui_picture.[ch]: Add 'transparent' to ui_inline_picture_t.

* ui_imagelib.h, */ui_imagelib.c: Add 'transparent' to arguments of
ui_imagelib_load_file().

* c_sixel.c: load_sixel_from_{data|file}() check whether P2 is 1 or not
and return it by 'transparent' argument.

2024-01-08 Araki Ken <arakiken@users.sf.net>

* README, man/mlterm.1, README.ja: Updated.
Expand Down
2 changes: 1 addition & 1 deletion common/c_imagelib.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ static GdkPixbuf *gdk_pixbuf_new_from_sixel(const char *path) {
u_int width;
u_int height;

if (!(pixels = load_sixel_from_file(path, &width, &height))) {
if (!(pixels = load_sixel_from_file(path, &width, &height, NULL))) {
return NULL;
}

Expand Down
36 changes: 26 additions & 10 deletions common/c_sixel.c
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,8 @@ static void correct_height(pixel_t *pixels, int width, int *height /* multiple o
* the actual image size is less than it.
* It is the caller that should shrink (realloc) it.
*/
static u_char *load_sixel_from_data(const char *file_data, u_int *width_ret, u_int *height_ret) {
static u_char *load_sixel_from_data(const char *file_data, u_int *width_ret, u_int *height_ret,
int *transparent) {
const char *p = file_data;
u_char *pixels;
int params[6];
Expand Down Expand Up @@ -375,6 +376,11 @@ static u_char *load_sixel_from_data(const char *file_data, u_int *width_ret, u_i
}
#endif

/* Place here this in case 'goto end' or 'goto body'. */
if (transparent) {
*transparent = 0; /* can be changed in processing P2. */
}

restart:
while (1) {
if (*p == '\0') {
Expand Down Expand Up @@ -465,25 +471,34 @@ static u_char *load_sixel_from_data(const char *file_data, u_int *width_ret, u_i
switch (*p) {
case 'q':
goto body;

#ifdef SIXEL_ORMODE
case '5':
ormode = 1;
break;
#endif
#if 0
case '0':
case '2':
...

case '1':
if (transparent) {
*transparent = 1;
}
break;

default:
#else
case '\0':
#endif
#ifdef DEBUG
bl_debug_printf(BL_DEBUG_TAG " Illegal format.\n.");
#endif
goto end;

#if 0
case '0':
case '2':
#endif
default:
#ifdef DEBUG
bl_debug_printf(BL_DEBUG_TAG " Illegal format.\n.");
#endif
break;
}

if (p[1] == ';') {
Expand Down Expand Up @@ -956,12 +971,13 @@ static u_char *load_sixel_from_data(const char *file_data, u_int *width_ret, u_i

#if !defined(SIXEL_1BPP) && !defined(SIXEL_SHAREPALETTE)

static u_char *load_sixel_from_file(const char *path, u_int *width_ret, u_int *height_ret) {
static u_char *load_sixel_from_file(const char *path, u_int *width_ret, u_int *height_ret,
int *transparent) {
char *file_data;
u_char *pixels;

if ((file_data = read_sixel_file(path))) {
pixels = load_sixel_from_data(file_data, width_ret, height_ret);
pixels = load_sixel_from_data(file_data, width_ret, height_ret, transparent);
free(file_data);

return pixels;
Expand Down
2 changes: 1 addition & 1 deletion contrib/scrollbar/pixmap_engine/pixmap_engine.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ static void load_image(ui_display_t *disp, ui_sb_view_conf_t *conf, const char *
path = malloc(sizeof(char) * (len + 1));
sprintf(path, "%s/%s.png", conf->dir, file);

if (!(*conf->load_image)(disp, path, NULL, pixmap, mask, width, height, 0)) {
if (!(*conf->load_image)(disp, path, 0, NULL, pixmap, mask, width, height, NULL)) {
#ifdef __DEBUG
printf("ui_imagelib_load_file() failed\n");
;
Expand Down
3 changes: 3 additions & 0 deletions drcssixel/DRCS-SIXEL-v2
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ from the top-left corner cell.
which consists of 96 characters is next to 0x7f of 0x7e set which
consists of 94 characters.

(*3) P2=1 (Pixel positions specified as 0 remain at their current color) is
not supported for now.

[Appendix]
<Original DRCS-SIXEL (rlogin 2.23.0 or before)>
o The number of columns and rows of sixel graphic image are calculated
Expand Down
9 changes: 7 additions & 2 deletions libvterm/vterm.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,8 @@ static vt_char_t *xterm_get_picture_data(void *p, char *file_path,
int *num_rows, /* If *num_rows > 0, ignored. */
int *num_cols_small /* set only if drcs_sixel is 1. */,
int *num_rows_small /* set only if drcs_sixel is 1. */,
u_int32_t **sixel_palette, int drcs_sixel) {
u_int32_t **sixel_palette, int *transparent,
int keep_aspect, int drcs_sixel) {
static int old_drcs_sixel = -1;
VTerm *vterm = p;
u_int width;
Expand Down Expand Up @@ -293,6 +294,10 @@ static vt_char_t *xterm_get_picture_data(void *p, char *file_path,
}
}

if (transparent) {
*transparent = 0;
}

if (sscanf(data_p, "\"%d;%d;%d;%d", &x, &y, &width, &height) != 4 ||
width == 0 || height == 0) {
struct stat st;
Expand All @@ -308,7 +313,7 @@ static vt_char_t *xterm_get_picture_data(void *p, char *file_path,
len += fread(all_data + len, 1, st.st_size - len, fp);
all_data[len] = '\0';

if (!(picture = load_sixel_from_data_1bpp(all_data, &width, &height))) {
if (!(picture = load_sixel_from_data_1bpp(all_data, &width, &height, transparent))) {
free(all_data);

goto error_closing_fp;
Expand Down
56 changes: 43 additions & 13 deletions uitoolkit/beos/ui_imagelib.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,15 @@ static int check_has_alpha(u_char *image, u_int width, u_int height) {
}

static int load_file(char *path, /* must be UTF-8 */
u_int *width, u_int *height, ui_picture_modifier_t *pic_mod, Pixmap *pixmap,
PixmapMask *mask) {
u_int *width, u_int *height, ui_picture_modifier_t *pic_mod,
Pixmap *pixmap, PixmapMask *mask, int *transparent) {
char *suffix;
u_char *image;

suffix = path + strlen(path) - 4;
#ifdef BUILTIN_SIXEL
if (strcasecmp(suffix, ".six") == 0 && *width == 0 && *height == 0 &&
(image = load_sixel_from_file(path, width, height))) {
(image = load_sixel_from_file(path, width, height, transparent))) {
adjust_pixmap(image, *width, *height, pic_mod);
*pixmap = beos_create_image(image, (*width) * (*height) * 4, *width, *height);
} else
Expand All @@ -163,19 +163,48 @@ static int load_file(char *path, /* must be UTF-8 */
return 0;
}

if (transparent) {
*transparent = 0;
}

if (!ui_picture_modifier_is_normal(pic_mod)) {
Pixmap new_pixmap;
u_char *image2;

image = beos_get_bits(*pixmap);
adjust_pixmap2(image, *width, *height, pic_mod);
new_pixmap = beos_create_image(image, (*width) * (*height) * 4, *width, *height);
beos_destroy_image(*pixmap);
*pixmap = new_pixmap;
if ((image2 = malloc((*width) * (*height) * 4))) {
image = memcpy(image2, image, (*width) * (*height) * 4);
beos_destroy_image(*pixmap);
adjust_pixmap2(image, *width, *height, pic_mod);
new_pixmap = beos_create_image(image, (*width) * (*height) * 4, *width, *height);
free(image);
*pixmap = new_pixmap;
}
}
}

if (mask) {
*mask = None;
if (transparent && *transparent) {
dummy_mask:
if (mask) {
/* dummy (If cur_pic->mask is non-zero, need_clear = 1 in draw_picture() in ui_draw_str.c) */
*mask = 1;
}
} else {
int x, y;
u_int32_t *p = (u_int32_t*)image;

for (y = 0; y < *height; y++) {
for (x = 0; x < *width; x++) {
if ((((*p) >> 24) & 0xff) <= 0x7f) { /* alpha */
goto dummy_mask;
}
p ++;
}
}

if (mask) {
*mask = None;
}
}

return 1;
Expand All @@ -193,7 +222,7 @@ Pixmap ui_imagelib_load_file_for_background(ui_window_t *win, char *path,
u_int width = 0;
u_int height = 0;

if (!load_file(path, &width, &height, pic_mod, &pixmap, NULL)) {
if (!load_file(path, &width, &height, pic_mod, &pixmap, NULL, NULL)) {
return None;
}

Expand All @@ -210,16 +239,17 @@ Pixmap ui_imagelib_get_transparent_background(ui_window_t *win, ui_picture_modif
return None;
}

int ui_imagelib_load_file(ui_display_t *disp, char *path, u_int32_t **cardinal, Pixmap *pixmap,
PixmapMask *mask, u_int *width, u_int *height, int keep_aspect) {
int ui_imagelib_load_file(ui_display_t *disp, char *path, int keep_aspect, u_int32_t **cardinal,
Pixmap *pixmap, PixmapMask *mask, u_int *width, u_int *height,
int *transparent) {
u_int pix_width = 0;
u_int pix_height = 0;

if (cardinal) {
return 0;
}

if (!load_file(path, &pix_width, &pix_height, NULL, pixmap, mask)) {
if (!load_file(path, &pix_width, &pix_height, NULL, pixmap, mask, transparent)) {
return 0;
}

Expand Down
18 changes: 12 additions & 6 deletions uitoolkit/console/ui_imagelib.c
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ static int resize_sixel(Pixmap pixmap, u_int width, u_int height, u_int bytes_pe

static int load_file(Display *display, char *path, u_int width, u_int height, int keep_aspect,
ui_picture_modifier_t *pic_mod, u_int depth, Pixmap *pixmap,
PixmapMask *mask) {
PixmapMask *mask, int *transparent) {
pid_t pid;
int fds[2];
ssize_t size;
Expand All @@ -270,7 +270,8 @@ static int load_file(Display *display, char *path, u_int width, u_int height, in
width == 0 && height == 0 &&
#endif
(*pixmap = calloc(1, sizeof(**pixmap)))) {
if (((*pixmap)->image = load_sixel_from_file(path, &(*pixmap)->width, &(*pixmap)->height)) &&
if (((*pixmap)->image = load_sixel_from_file(path, &(*pixmap)->width, &(*pixmap)->height,
NULL)) &&
/* resize_sixel() frees pixmap->image in failure. */
resize_sixel(*pixmap, width, height, 4)) {
goto loaded;
Expand All @@ -280,6 +281,10 @@ static int load_file(Display *display, char *path, u_int width, u_int height, in
}
#endif

if (transparent) {
*transparent = 0;
}

#ifdef __ANDROID__
if (!(*pixmap = calloc(1, sizeof(**pixmap)))) {
return 0;
Expand Down Expand Up @@ -415,7 +420,7 @@ Pixmap ui_imagelib_load_file_for_background(ui_window_t *win, char *path,
Pixmap pixmap;

if (!load_file(win->disp->display, path, ACTUAL_WIDTH(win), ACTUAL_HEIGHT(win), 0, pic_mod,
win->disp->depth, &pixmap, NULL)) {
win->disp->depth, &pixmap, NULL, NULL)) {
pixmap = None;
}

Expand All @@ -428,14 +433,15 @@ Pixmap ui_imagelib_get_transparent_background(ui_window_t *win, ui_picture_modif
return None;
}

int ui_imagelib_load_file(ui_display_t *disp, char *path, u_int32_t **cardinal, Pixmap *pixmap,
PixmapMask *mask, u_int *width, u_int *height, int keep_aspect) {
int ui_imagelib_load_file(ui_display_t *disp, char *path, int keep_aspect, u_int32_t **cardinal,
Pixmap *pixmap, PixmapMask *mask, u_int *width, u_int *height,
int *transparent) {
if (cardinal) {
return 0;
}

if (!load_file(disp->display, path, *width, *height, keep_aspect, NULL,
disp->depth, pixmap, mask)) {
disp->depth, pixmap, mask, transparent)) {
return 0;
}

Expand Down
Loading

0 comments on commit 5123203

Please sign in to comment.