This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project gfxprim.git.
The branch, generate has been updated via 298530749895f3e6eb2805c4cb422e217e85586a (commit) via 4bf88545a7e86d3a925a83e19ba7c92920a14cb5 (commit) via 48642159e541d480d808e876239566e8b1077de5 (commit) from 859d22427003b1d4be3f536075d48a847bcd2c8a (commit)
Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below.
- Log ----------------------------------------------------------------- http://repo.or.cz/w/gfxprim.git/commit/298530749895f3e6eb2805c4cb422e217e855...
commit 298530749895f3e6eb2805c4cb422e217e85586a Author: Cyril Hrubis metan@ucw.cz Date: Tue Oct 25 12:51:00 2011 +0000
Fix merge.
diff --git a/demos/fbshow/fbshow.c b/demos/fbshow/fbshow.c index 12d4626..e6c6212 100644 --- a/demos/fbshow/fbshow.c +++ b/demos/fbshow/fbshow.c @@ -48,7 +48,7 @@ static GP_Context *image_to_display(GP_Context *img, uint32_t w, uint32_t h) { float rat = calc_img_size(img->w, img->h, w, h);
- return GP_FilterResize(img, NULL, GP_INTER_CUBIC, img->w * rat, img->h * rat); + return GP_FilterResize(img, NULL, GP_INTERP_CUBIC, img->w * rat, img->h * rat); }
static int show_image(GP_Framebuffer *fb, const char *img_path, int clear)
http://repo.or.cz/w/gfxprim.git/commit/4bf88545a7e86d3a925a83e19ba7c92920a14...
commit 4bf88545a7e86d3a925a83e19ba7c92920a14cb5 Merge: 4864215 859d224 Author: Cyril Hrubis metan@ucw.cz Date: Tue Oct 25 12:31:24 2011 +0000
Merge branch 'generate' of git://repo.or.cz/gfxprim into generate
http://repo.or.cz/w/gfxprim.git/commit/48642159e541d480d808e876239566e8b1077...
commit 48642159e541d480d808e876239566e8b1077de5 Author: Cyril Hrubis metan@ucw.cz Date: Mon Oct 24 17:56:37 2011 +0200
Base for framebuffer image viewer.
diff --git a/demos/Makefile b/demos/Makefile index 571580a..eddfa9f 100644 --- a/demos/Makefile +++ b/demos/Makefile @@ -1,3 +1,3 @@ TOPDIR=.. -SUBDIRS=grinder +SUBDIRS=grinder fbshow include $(TOPDIR)/include.mk diff --git a/demos/fbshow/Makefile b/demos/fbshow/Makefile new file mode 100644 index 0000000..2ca7439 --- /dev/null +++ b/demos/fbshow/Makefile @@ -0,0 +1,11 @@ +TOPDIR=../.. + +CSOURCES=$(shell echo *.c) + +INCLUDE= +LDLIBS+=-lGP -L$(TOPDIR)/build/ -lpng + +APPS=fbshow + +include $(TOPDIR)/include.mk +include $(TOPDIR)/app.mk diff --git a/demos/fbshow/fbshow.c b/demos/fbshow/fbshow.c new file mode 100644 index 0000000..12d4626 --- /dev/null +++ b/demos/fbshow/fbshow.c @@ -0,0 +1,214 @@ +/***************************************************************************** + * This file is part of gfxprim library. * + * * + * Gfxprim 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.1 of the License, or (at your option) any later version. * + * * + * Gfxprim 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 gfxprim; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, * + * Boston, MA 02110-1301 USA * + * * + * Copyright (C) 2009-2011 Cyril Hrubis metan@ucw.cz * + * * + *****************************************************************************/ + + /* + + Simple framebuffer image viewer. + + */ + +#include <unistd.h> + +#include <GP.h> +#include <backends/GP_Framebuffer.h> +#include <input/GP_InputDriverLinux.h> + +static GP_Pixel black_pixel; +static GP_Pixel white_pixel; + +static float calc_img_size(uint32_t img_w, uint32_t img_h, + uint32_t src_w, uint32_t src_h) +{ + float w_rat = 1.00 * src_w / img_w; + float h_rat = 1.00 * src_h / img_h; + + return GP_MIN(w_rat, h_rat); +} + +static GP_Context *image_to_display(GP_Context *img, uint32_t w, uint32_t h) +{ + float rat = calc_img_size(img->w, img->h, w, h); + + return GP_FilterResize(img, NULL, GP_INTER_CUBIC, img->w * rat, img->h * rat); +} + +static int show_image(GP_Framebuffer *fb, const char *img_path, int clear) +{ + GP_Context *img; + + if (clear) { + char buf[100]; + snprintf(buf, sizeof(buf), "Loading '%s'", img_path); + GP_Fill(&fb->context, black_pixel); + GP_BoxCenteredText(&fb->context, NULL, 0, 0, + fb->context.w, fb->context.h, + buf, white_pixel); + } + + if (GP_LoadImage(img_path, &img) == 0) { + GP_Context *img2 = image_to_display(img, fb->context.w, fb->context.h); + + GP_ContextFree(img); + + if (img2 == NULL) + return 1; + + uint32_t cx = (fb->context.w - img2->w)/2; + uint32_t cy = (fb->context.h - img2->h)/2; + + GP_Fill(&fb->context, black_pixel); + + GP_Blit(img2, 0, 0, img2->w, img2->h, &fb->context, cx, cy); + + GP_ContextFree(img2); + } + + return 0; +} + +int main(int argc, char *argv[]) +{ + GP_Framebuffer *fb; + GP_InputDriverLinux *drv = NULL; + char *input_dev = NULL; + int sleep_sec = 0; + + int opt; + + while ((opt = getopt(argc, argv, "i:s:")) != -1) { + switch (opt) { + case 'i': + input_dev = optarg; + break; + case 's': + sleep_sec = atoi(optarg); + break; + default: + fprintf(stderr, "Invalid paramter '%c'n", opt); + } + } + + GP_SetDebugLevel(10); + + if (input_dev == NULL) { + sleep_sec = 1; + } else { + drv = GP_InputDriverLinuxOpen(input_dev); + + if (drv == NULL) { + fprintf(stderr, "Failed to initalize input device '%s'n", + input_dev); + return 1; + } + } + + fb = GP_FramebufferInit("/dev/fb0"); + + if (fb == NULL) { + fprintf(stderr, "Failed to initalize framebuffern"); + return 1; + } + + GP_EventSetScreenSize(fb->context.w, fb->context.h); + + black_pixel = GP_ColorToContextPixel(GP_COL_BLACK, &fb->context); + white_pixel = GP_ColorToContextPixel(GP_COL_WHITE, &fb->context); + + int argf = optind; + int argn = argf; + + show_image(fb, argv[argf], 1); + + /* Initalize select */ + fd_set rfds; + FD_ZERO(&rfds); + FD_SET(drv->fd, &rfds); + struct timeval tv = {.tv_sec = sleep_sec, .tv_usec = 0}; + + for (;;) { + int ret; + + if (drv != NULL) { + ret = select(drv->fd + 1, &rfds, NULL, NULL, &tv); + + switch (ret) { + case -1: + GP_FramebufferExit(fb); + return 0; + break; + case 0: + argn++; + if (argn >= argc) + argn = argf; + + show_image(fb, argv[argn], 0); + break; + default: + while (GP_InputDriverLinuxRead(drv)); + } + + FD_SET(drv->fd, &rfds); + } else { + sleep(sleep_sec); + + argn++; + if (argn >= argc) + argn = argf; + + show_image(fb, argv[argn], 0); + } + + /* Read and parse events */ + GP_Event ev; + + while (GP_EventGet(&ev)) { + + GP_EventDump(&ev); + + switch (ev.type) { + case GP_EV_KEY: + if (ev.code != GP_EV_KEY_DOWN) + continue; + + switch (ev.val.key.key) { + case GP_KEY_ENTER: + GP_FramebufferExit(fb); + return 0; + break; + case GP_KEY_ESC: + case GP_KEY_SPACE: + case GP_KEY_Q: + argn++; + if (argn >= argc) + argn = argf; + show_image(fb, argv[argn], 1); + break; + } + break; + } + } + } + + GP_FramebufferExit(fb); + + return 0; +} diff --git a/demos/fbshow/runtest.sh b/demos/fbshow/runtest.sh new file mode 100755 index 0000000..163c76c --- /dev/null +++ b/demos/fbshow/runtest.sh @@ -0,0 +1,10 @@ +#!/bin/bash +# +# Run dynamically linked test. +# + +PROG="$1" +shift + +echo "LD_LIBRARY_PATH=../../build/ ./$PROG $@" +LD_LIBRARY_PATH=../../build/ ./$PROG "$@"
-----------------------------------------------------------------------
Summary of changes: demos/Makefile | 2 +- demos/{grinder => fbshow}/Makefile | 6 +- demos/fbshow/fbshow.c | 214 ++++++++++++++++++++++++++++++++ {tests/SDL => demos/fbshow}/runtest.sh | 2 +- 4 files changed, 218 insertions(+), 6 deletions(-) copy demos/{grinder => fbshow}/Makefile (68%) create mode 100644 demos/fbshow/fbshow.c copy {tests/SDL => demos/fbshow}/runtest.sh (72%)
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos@gmail.com if you want to unsubscribe, or site admin admin@repo.or.cz if you receive no reply.