graphics: add graphics viewer for popular image formats
- use stb_image.h to display bmp, jpeg, pmg, gif, targa and other popular image formats - disable text based image converters
This commit is contained in:
parent
7d7103ca70
commit
478a9d9f69
5 changed files with 7347 additions and 3 deletions
4
Makefile
4
Makefile
|
|
@ -155,6 +155,8 @@ ifdef CONFIG_FFMPEG
|
|||
LIBS+= -L$(FFMPEG_LIBDIR)/libavcodec -L$(FFMPEG_LIBDIR)/libavformat -lavformat -lavcodec -lz -lpthread
|
||||
DEFINES+= -I$(FFMPEG_SRCDIR)/libavcodec -I$(FFMPEG_SRCDIR)/libavformat
|
||||
TARGETS+= ffplay$(EXE)
|
||||
else
|
||||
OBJS+= stb.o
|
||||
endif
|
||||
|
||||
ifdef CONFIG_X11
|
||||
|
|
@ -308,6 +310,7 @@ $(OBJS_DIR)/fbfrender.o: fbfrender.c fbfrender.h libfbf.h
|
|||
$(OBJS_DIR)/qe.o: qe.c parser.c qeconfig.h qfribidi.h variables.h
|
||||
$(OBJS_DIR)/qfribidi.o: qfribidi.c qfribidi.h
|
||||
$(OBJS_DIR)/clang.o: clang.c rust.c swift.c icon.c groovy.c virgil.c
|
||||
$(OBJS_DIR)/stb.o: stb.c stb_image.h
|
||||
|
||||
$(XOBJS_DIR)/cfb.o: cfb.c cfb.h fbfrender.h
|
||||
$(XOBJS_DIR)/charset.o: charset.c unicode_width.h
|
||||
|
|
@ -316,6 +319,7 @@ $(XOBJS_DIR)/fbfrender.o: fbfrender.c fbfrender.h libfbf.h
|
|||
$(XOBJS_DIR)/qe.o: qe.c parser.c qeconfig.h qfribidi.h variables.h
|
||||
$(XOBJS_DIR)/qfribidi.o: qfribidi.c qfribidi.h
|
||||
$(XOBJS_DIR)/clang.o: clang.c rust.c swift.c icon.c groovy.c virgil.c
|
||||
$(XOBJS_DIR)/stb.o: stb.c stb_image.h
|
||||
|
||||
$(TOBJS_DIR)/cfb.o: cfb.c cfb.h fbfrender.h
|
||||
$(TOBJS_DIR)/charset.o: charset.c unicode_width.h
|
||||
|
|
|
|||
9
TODO.org
9
TODO.org
|
|
@ -1,7 +1,7 @@
|
|||
; TODO list for qemacs
|
||||
;
|
||||
; Author: Charles Gordon
|
||||
; Updated: 2017-05-10
|
||||
; Updated: 2017-05-15
|
||||
|
||||
* Recent bugs and ideas
|
||||
|
||||
|
|
@ -643,3 +643,10 @@ ssh: should use the host name and get files via scp syntax
|
|||
charset: set-eol-type should take a string: auto/binary/dos/unix/mac/0/1/2...
|
||||
archive: use window/buffer caption for output description
|
||||
files: handle files with embedded spaces
|
||||
dired: group symbolic links to directories with directories
|
||||
images: filtered scaling
|
||||
images: zoom, pan, rotate, describe, peek-color, histogram...
|
||||
images: multiview, wallpaper...
|
||||
images: use screen aspect-ratio...
|
||||
images: display info on modeline
|
||||
images: prevent display if not invalid
|
||||
|
|
|
|||
|
|
@ -231,8 +231,8 @@ static CompressType compress_type_array[] = {
|
|||
{ "sqlite", "SQLite format 3\0", 16, NULL, "sqlite3 $1 .dump", NULL },
|
||||
{ "bplist", "bplist00", 8, "plist", "plutil -p $1", NULL },
|
||||
// { "bplist", "bplist00", 8, "plist", "plutil -convert xml1 -o - $1", NULL },
|
||||
{ "jpeg", NULL, 0, "jpg", "jp2a --height=35 --background=dark $1", NULL, SF_COLOR },
|
||||
{ "image", NULL, 0, "bmp", "img2txt -f utf8 $1", NULL, SF_COLOR },
|
||||
// { "jpeg", NULL, 0, "jpg", "jp2a --height=35 --background=dark $1", NULL, SF_COLOR },
|
||||
// { "image", NULL, 0, "bmp", "img2txt -f utf8 $1", NULL, SF_COLOR },
|
||||
{ "pdf", NULL, 0, "pdf", "pstotext $1", NULL },
|
||||
};
|
||||
|
||||
|
|
|
|||
156
stb.c
Normal file
156
stb.c
Normal file
|
|
@ -0,0 +1,156 @@
|
|||
/*
|
||||
* QEmacs graphics mode for image files
|
||||
*
|
||||
* Copyright (c) 2017 Charlie Gordon.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "qe.h"
|
||||
|
||||
#define STB_IMAGE_IMPLEMENTATION
|
||||
#define STBI_ASSERT(x)
|
||||
#undef malloc
|
||||
#undef realloc
|
||||
#undef free
|
||||
#include "stb_image.h"
|
||||
|
||||
/*----------------------------------------------------------------*/
|
||||
|
||||
static ModeDef stb_mode;
|
||||
|
||||
typedef struct ImageState {
|
||||
QEModeData base;
|
||||
|
||||
QEPicture pic;
|
||||
|
||||
void *stb_image;
|
||||
int stb_x, stb_y, stb_channels;
|
||||
|
||||
} ImageState;
|
||||
|
||||
/*----------------*/
|
||||
|
||||
static inline ImageState *image_get_state(EditState *e, int status)
|
||||
{
|
||||
return qe_get_buffer_mode_data(e->b, &stb_mode, status ? e : NULL);
|
||||
}
|
||||
|
||||
static void image_display(EditState *s) {
|
||||
ImageState *ms = image_get_state(s, 0);
|
||||
QEColor col = qe_styles[QE_STYLE_GUTTER].bg_color;
|
||||
|
||||
if (s->display_invalid) {
|
||||
if (ms && ms->stb_image) {
|
||||
int x0, y0, w, h;
|
||||
#if 0
|
||||
/* No scaling */
|
||||
w = min(s->width, ms->pic.width);
|
||||
h = min(s->height, ms->pic.height / s->screen->dpy.yfactor);
|
||||
x0 = (s->width - w) / 2;
|
||||
y0 = (s->height - h) / 2;
|
||||
qe_draw_picture(s->screen, s->xleft + x0, s->ytop + y0, w, h,
|
||||
&ms->pic, 0, 0, w, h * s->screen->dpy.yfactor,
|
||||
0, QERGB(128, 128, 128));
|
||||
fill_border(s, x0, y0, w, h, col);
|
||||
put_status(s, "%dx%dx%d",
|
||||
ms->pic.width, ms->pic.height, ms->stb_channels * 8);
|
||||
#else
|
||||
int factor = 1024;
|
||||
|
||||
w = ms->pic.width;
|
||||
h = ms->pic.height / s->screen->dpy.yfactor;
|
||||
/* compute scaling factor for scale up or down */
|
||||
factor = min(4 * 1024, min(s->width * 1024 / w, s->height * 1024 / h));
|
||||
/* Do not scale up on text display */
|
||||
if (factor < 1024 || s->width != s->cols) {
|
||||
w = ((w * factor) + 512) / 1024;
|
||||
h = ((h * factor) + 512) / 1024;
|
||||
}
|
||||
x0 = (s->width - w) / 2;
|
||||
y0 = (s->height - h) / 2;
|
||||
qe_draw_picture(s->screen, s->xleft + x0, s->ytop + y0, w, h,
|
||||
&ms->pic, 0, 0, ms->pic.width, ms->pic.height,
|
||||
0, QERGB(128, 128, 128));
|
||||
fill_border(s, x0, y0, w, h, col);
|
||||
put_status(s, "%dx%dx%d",
|
||||
ms->pic.width, ms->pic.height, ms->stb_channels * 8);
|
||||
#endif
|
||||
} else {
|
||||
fill_rectangle(s->screen, s->xleft, s->ytop, s->width, s->height, col);
|
||||
}
|
||||
s->display_invalid = 0;
|
||||
}
|
||||
if (s->qe_state->active_window == s) {
|
||||
/* Update cursor */
|
||||
int xc = s->xleft;
|
||||
int yc = s->ytop;
|
||||
int w = s->char_width;
|
||||
int h = s->line_height;
|
||||
if (s->screen->dpy.dpy_cursor_at) {
|
||||
/* hardware cursor */
|
||||
s->screen->dpy.dpy_cursor_at(s->screen, xc, yc, w, h);
|
||||
} else {
|
||||
xor_rectangle(s->screen, xc, yc, w, h, QERGB(0xFF, 0xFF, 0xFF));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void image_display_hook(EditState *s) {
|
||||
ImageState *ms = image_get_state(s, 0);
|
||||
|
||||
if (ms && !ms->stb_image) {
|
||||
ms->stb_image = stbi_load(s->b->filename,
|
||||
&ms->stb_x, &ms->stb_y, &ms->stb_channels, 4);
|
||||
if (ms->stb_image) {
|
||||
ms->pic.width = ms->stb_x;
|
||||
ms->pic.height = ms->stb_y;
|
||||
ms->pic.format = QEBITMAP_FORMAT_BGRA32;
|
||||
ms->pic.data[0] = ms->stb_image;
|
||||
ms->pic.linesize[0] = ms->stb_x * 4;
|
||||
} else {
|
||||
put_status(s, "stbi_load error");
|
||||
}
|
||||
}
|
||||
edit_invalidate(s, 1);
|
||||
}
|
||||
|
||||
static void image_mode_free(EditBuffer *b, void *state) {
|
||||
ImageState *ms = state;
|
||||
|
||||
if (ms->stb_image) {
|
||||
stbi_image_free(ms->stb_image);
|
||||
ms->stb_image = NULL;
|
||||
ms->pic.data[0] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static ModeDef stb_mode = {
|
||||
.name = "Image file",
|
||||
.alt_name = "stb",
|
||||
.extensions = "bmp|jpg|jpeg|png|tga|psd|gif|hdr|pic|pnm|ppm|pgm",
|
||||
.buffer_instance_size = sizeof(ImageState),
|
||||
.mode_free = image_mode_free,
|
||||
.display_hook = image_display_hook,
|
||||
.display = image_display,
|
||||
};
|
||||
|
||||
static int stb_init(void)
|
||||
{
|
||||
qe_register_mode(&stb_mode, MODEF_VIEW);
|
||||
return 0;
|
||||
}
|
||||
|
||||
qe_module_init(stb_init);
|
||||
7177
stb_image.h
Normal file
7177
stb_image.h
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue