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, master has been updated via cfa164fc6f9a5e7e97bd501dce67b6d7665504ec (commit) via 7d1c136443984e20f8fb05008fe63f66ca165767 (commit) via 48c629b8a273d8e72d4e381fc86f930fc8bf14a7 (commit) from 442c7288654c4fd015c2a77f52b3b38ce9a82d0e (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/cfa164fc6f9a5e7e97bd501dce67b6d766550...
commit cfa164fc6f9a5e7e97bd501dce67b6d7665504ec Author: Cyril Hrubis metan@ucw.cz Date: Sun Dec 22 21:01:12 2013 +0100
doc: Add RGB tripplet to pixel conversion docs.
Signed-off-by: Cyril Hrubis metan@ucw.cz
diff --git a/doc/Makefile b/doc/Makefile index 28cc670..2b0721b 100644 --- a/doc/Makefile +++ b/doc/Makefile @@ -1,10 +1,11 @@ SOURCES=index.html about.txt context.txt loaders.txt filters.txt - basic_types.txt gfx.txt backends.txt gamma.txt grabbers.txt + basic_types.txt gfx.txt backends.txt gamma.txt grabbers.txt environment_variables.txt debug.txt core.txt input.txt gen.txt pixels.txt coordinate_system.txt coding_style.txt get_put_pixel.txt blits.txt progress_callback.txt text.txt event_queue.txt compilation.txt filters_resize.txt filters_dithering.txt filters_python.txt spiv.txt core_common.txt + convert.txt
SOURCES+=core_python.txt gfx_python.txt loaders_python.txt backends_python.txt
diff --git a/doc/basic_types.txt b/doc/basic_types.txt index 2d9b342..11ff214 100644 --- a/doc/basic_types.txt +++ b/doc/basic_types.txt @@ -18,6 +18,7 @@ be changed at compile time to support colors with more than 10 bits per channel. The 'GP_Pixel' is thus used as opaque value big enough to hold any supported pixel value.
+[[Color]] Color ~~~~~
diff --git a/doc/convert.txt b/doc/convert.txt new file mode 100644 index 0000000..9191805 --- /dev/null +++ b/doc/convert.txt @@ -0,0 +1,39 @@ +Pixel Conversions +----------------- + +This page describes RGB tripplet to pixels conversions. + +See also link:basic_types.html#Color[colors]. + +[source,c] +------------------------------------------------------------------------------- +#include <GP.h> +/* or */ +#include <core/GP_Convert.h> + +GP_Pixel GP_RGBToPixel(uint8_t r, uint8_t g, uint8_t b, GP_PixelType type); + +GP_Pixel GP_RGBAToPixel(uint8_t r, uint8_t g, uint8_t b, uint8_t a, + GP_PixelType type); + +GP_Pixel GP_RGBToContextPixel(uint8_t r, uint8_t g, uint8_t b, + const GP_Context *context); + +GP_Pixel GP_RGBAToContextPixel(uint8_t r, uint8_t g, uint8_t b, uint8_t a, + const GP_Context *context); +------------------------------------------------------------------------------- + +Simple functions to convert RGB or RGBA 8 bit values into the specific +link:pixels.html[pixel types]. + +[source,c] +------------------------------------------------------------------------------- +#include <GP.h> +/* or */ +#include <core/GP_Convert.h> + +GP_Pixel GP_ConvertPixel(GP_Pixel pixel, GP_PixelType from, GP_PixelType to); +------------------------------------------------------------------------------- + +Converts pixel value. The conversion currently converts by converting the +value to RGBA8888 and then to the resulting value. diff --git a/doc/gfx.txt b/doc/gfx.txt index c311dbf..14cb7d8 100644 --- a/doc/gfx.txt +++ b/doc/gfx.txt @@ -6,6 +6,8 @@ as lines, circles, etc.
You may want to see the link:coordinate_system.html[coordinate system] first.
+See also RGB tripplet to pixel link:convert.html[conversions]. + Rotation Flags ~~~~~~~~~~~~~~
http://repo.or.cz/w/gfxprim.git/commit/7d1c136443984e20f8fb05008fe63f66ca165...
commit 7d1c136443984e20f8fb05008fe63f66ca165767 Author: Cyril Hrubis metan@ucw.cz Date: Sun Dec 22 20:40:39 2013 +0100
demos: Fix and cleanup GP_BackendInit() + docs.
Signed-off-by: Cyril Hrubis metan@ucw.cz
diff --git a/demos/c_simple/backend_example.c b/demos/c_simple/backend_example.c index ecf82cc..6bb97f1 100644 --- a/demos/c_simple/backend_example.c +++ b/demos/c_simple/backend_example.c @@ -56,7 +56,7 @@ int main(int argc, char *argv[]) backend_opts = optarg; break; case 'h': - GP_BackendInit(NULL, NULL, stderr); + GP_BackendInit(NULL, NULL); return 0; break; default: @@ -68,7 +68,7 @@ int main(int argc, char *argv[]) /* Turn on debug messages */ GP_SetDebugLevel(10);
- backend = GP_BackendInit(backend_opts, "Backend Example", stderr); + backend = GP_BackendInit(backend_opts, "Backend Example");
if (backend == NULL) { fprintf(stderr, "Failed to initialize backendn"); diff --git a/demos/c_simple/backend_timers_example.c b/demos/c_simple/backend_timers_example.c index e31075c..8a592be 100644 --- a/demos/c_simple/backend_timers_example.c +++ b/demos/c_simple/backend_timers_example.c @@ -54,7 +54,7 @@ int main(void) GP_Backend *backend; const char *backend_opts = "X11:100x100";
- backend = GP_BackendInit(backend_opts, "Backend Timers Example", stderr); + backend = GP_BackendInit(backend_opts, "Backend Timers Example");
if (backend == NULL) { fprintf(stderr, "Failed to initialize backendn"); diff --git a/demos/c_simple/blittest.c b/demos/c_simple/blittest.c index 3aaf45e..02b374b 100644 --- a/demos/c_simple/blittest.c +++ b/demos/c_simple/blittest.c @@ -161,7 +161,7 @@ int main(void) return 1; }
- win = GP_BackendInit(backend_opts, "Blit Test", stderr); + win = GP_BackendInit(backend_opts, "Blit Test");
if (win == NULL) { fprintf(stderr, "Failed to initalize backend '%s'n", diff --git a/demos/c_simple/fileview.c b/demos/c_simple/fileview.c index f0608c7..2d06dae 100644 --- a/demos/c_simple/fileview.c +++ b/demos/c_simple/fileview.c @@ -253,7 +253,7 @@ int main(int argc, char *argv[]) if (!read_file_head(argv[1])) return 1;
- backend = GP_BackendInit(backend_opts, "File View", stderr); + backend = GP_BackendInit(backend_opts, "File View");
if (backend == NULL) { fprintf(stderr, "Failed to initalize backend '%s'n", diff --git a/demos/c_simple/fonttest.c b/demos/c_simple/fonttest.c index 2ecfa05..fb888e2 100644 --- a/demos/c_simple/fonttest.c +++ b/demos/c_simple/fonttest.c @@ -271,7 +271,7 @@ int main(int argc, char *argv[]) font = GP_FontFaceLoad(argv[1], 0, font_h); }
- win = GP_BackendInit(backend_opts, "Font Test", stderr); + win = GP_BackendInit(backend_opts, "Font Test");
if (win == NULL) { fprintf(stderr, "Failed to initalize backend '%s'n", diff --git a/demos/c_simple/input_example.c b/demos/c_simple/input_example.c index 5243c82..3b94ce3 100644 --- a/demos/c_simple/input_example.c +++ b/demos/c_simple/input_example.c @@ -131,7 +131,7 @@ int main(int argc, char *argv[]) backend_opts = optarg; break; case 'h': - GP_BackendInit(NULL, NULL, stderr); + GP_BackendInit("help", NULL); return 0; break; default: @@ -140,7 +140,7 @@ int main(int argc, char *argv[]) } }
- backend = GP_BackendInit(backend_opts, "Input Test", stderr); + backend = GP_BackendInit(backend_opts, "Input Test");
if (backend == NULL) { fprintf(stderr, "Failed to initalize backend '%s'n", diff --git a/demos/c_simple/koch.c b/demos/c_simple/koch.c index 6325e35..335815d 100644 --- a/demos/c_simple/koch.c +++ b/demos/c_simple/koch.c @@ -128,7 +128,7 @@ int main(void) { const char *backend_opts = "X11";
- backend = GP_BackendInit(backend_opts, "Koch", stderr); + backend = GP_BackendInit(backend_opts, "Koch");
if (backend == NULL) { fprintf(stderr, "Failed to initalize backend '%s'n", diff --git a/demos/c_simple/linetest.c b/demos/c_simple/linetest.c index 1069a7e..1df6e6e 100644 --- a/demos/c_simple/linetest.c +++ b/demos/c_simple/linetest.c @@ -127,7 +127,7 @@ int main(int argc, char *argv[]) } }
- win = GP_BackendInit(backend_opts, "Line Test", stderr); + win = GP_BackendInit(backend_opts, "Line Test");
if (win == NULL) { fprintf(stderr, "Failed to initalize backend '%s'n", diff --git a/demos/c_simple/randomshapetest.c b/demos/c_simple/randomshapetest.c index bf53204..f3dbaa1 100644 --- a/demos/c_simple/randomshapetest.c +++ b/demos/c_simple/randomshapetest.c @@ -260,7 +260,7 @@ int main(void) { const char *backend_opts = "X11";
- win = GP_BackendInit(backend_opts, "Random Shape Test", stderr); + win = GP_BackendInit(backend_opts, "Random Shape Test");
if (win == NULL) { fprintf(stderr, "Failed to initalize backend '%s'n", diff --git a/demos/c_simple/shapetest.c b/demos/c_simple/shapetest.c index 314be26..db32938 100644 --- a/demos/c_simple/shapetest.c +++ b/demos/c_simple/shapetest.c @@ -491,7 +491,7 @@ int main(int argc, char *argv[]) } }
- backend = GP_BackendInit(backend_opts, "Shapetest", stderr); + backend = GP_BackendInit(backend_opts, "Shapetest");
if (backend == NULL) { fprintf(stderr, "Failed to initalize backend '%s'n", diff --git a/demos/c_simple/textaligntest.c b/demos/c_simple/textaligntest.c index 99a6a3f..1e8a77d 100644 --- a/demos/c_simple/textaligntest.c +++ b/demos/c_simple/textaligntest.c @@ -142,7 +142,7 @@ int main(int argc, char *argv[])
print_instructions();
- win = GP_BackendInit(backend_opts, "Font Align Test", stderr); + win = GP_BackendInit(backend_opts, "Font Align Test");
if (win == NULL) { fprintf(stderr, "Failed to initalize backend '%s'n", diff --git a/demos/c_simple/virtual_backend_example.c b/demos/c_simple/virtual_backend_example.c index d149bc8..925a3d6 100644 --- a/demos/c_simple/virtual_backend_example.c +++ b/demos/c_simple/virtual_backend_example.c @@ -54,7 +54,7 @@ int main(int argc, char *argv[]) } break; case 'h': - GP_BackendInit(NULL, NULL, stderr); + GP_BackendInit("help", NULL); return 0; break; default: @@ -66,7 +66,7 @@ int main(int argc, char *argv[]) /* Turn on debug messages */ GP_SetDebugLevel(10);
- backend = GP_BackendInit(backend_opts, "Virtual Backend Example", stderr); + backend = GP_BackendInit(backend_opts, "Virtual Backend Example");
if (emul_type != GP_PIXEL_UNKNOWN) { GP_Backend *emul; diff --git a/demos/particle/particle_demo.c b/demos/particle/particle_demo.c index cc9a4a2..2b902a0 100644 --- a/demos/particle/particle_demo.c +++ b/demos/particle/particle_demo.c @@ -51,7 +51,7 @@ static void sighandler(int signo)
static void init_backend(const char *backend_opts) { - backend = GP_BackendInit(backend_opts, "Particles", stderr); + backend = GP_BackendInit(backend_opts, "Particles");
if (backend == NULL) { fprintf(stderr, "Failed to initalize backend '%s'n", backend_opts); diff --git a/demos/py_simple/backends.py b/demos/py_simple/backends.py index f6d9e40..31fb59d 100755 --- a/demos/py_simple/backends.py +++ b/demos/py_simple/backends.py @@ -32,7 +32,7 @@ def main(): sys.exit(1)
# Create backend window - bk = backends.BackendInit(backend_string, "Backend Example", sys.stderr) + bk = backends.BackendInit(backend_string, "Backend Example") assert(bk)
redraw(bk) diff --git a/demos/spiv/spiv.c b/demos/spiv/spiv.c index 33b0971..ca37408 100644 --- a/demos/spiv/spiv.c +++ b/demos/spiv/spiv.c @@ -638,7 +638,7 @@ static void sighandler(int signo)
static void init_backend(const char *backend_opts) { - backend = GP_BackendInit(backend_opts, "Spiv", stderr); + backend = GP_BackendInit(backend_opts, "Spiv");
if (backend == NULL) { fprintf(stderr, "Failed to initalize backend '%s'n", backend_opts); diff --git a/demos/spiv/spiv_help.c b/demos/spiv/spiv_help.c index 736756d..0f9e222 100644 --- a/demos/spiv/spiv_help.c +++ b/demos/spiv/spiv_help.c @@ -95,9 +95,9 @@ static const struct examples examples[] = { "Copies currently loaded image into directory 'sorted/' on pressing F1"}, {"spiv -e G1 -d images/", "Emulates 1-bit Grayscale display and turns on Floyd-Steinberg dithering"}, - {"spiv -b 'X11:ROOT_WIN' -t 10 images/", + {"spiv -b 'X11:use_root' -t 10 images/", "Runs slideshow using X root window as backend window"}, - {"spiv -b 'X11:CREATE_ROOT' -t 10 images/", + {"spiv -b 'X11:create_root' -t 10 images/", "Same as abowe but works in KDEn"} };
diff --git a/doc/backends.txt b/doc/backends.txt index 46a631a..4196c8f 100644 --- a/doc/backends.txt +++ b/doc/backends.txt @@ -206,19 +206,22 @@ it. ------------------------------------------------------------------------------- #include <GP.h>
-GP_Backend *GP_BackendInit(const char *params, const char *caption, FILE *help); -------------------------------------------------------------------------------- - -This function takes a params string as an parameter which is used for -determining backend-dependent parameters. The format is -'backend_name:backend_parameters' where backend parameters may be window size -(either 'WxH' or 'FS' in case of 'SDL' backend). The caption is window caption -(which is ignored in some of the cases) and the 'FILE' is file, where an error -is printed in case of failure, you should mostly use 'stderr' for that -purpose. If params is set to 'NULL' the the call only prints help into the -passed help 'FILE'. If initialization was successful pointer to allocated and -initialized backend is returned otherwise 'NULL' is returned and some helpful -information should be printed into the passed help 'FILE'. +GP_Backend *GP_BackendInit(const char *params, const char *caption); +------------------------------------------------------------------------------- + +The 'params' string composes of backend name and backend dependend parameters. +The format is 'backend_name:backend_params' for example +'fb:new_console:/dev/fb1'. + +The 'caption' string is used for window caption, in case of X11 backend or may +be ignored completly in case of framebuffer backend. + +If 'params' is set to '"help"' help for all backends is printed into the +'stderr'. + +If initialization was successful pointer to allocated and initialized backend +is returned otherwise 'NULL' is returned and some helpful information should +be printed into the 'stderr'.
General Backend API diff --git a/doc/backends_python.txt b/doc/backends_python.txt index a5c2206..183b4c1 100644 --- a/doc/backends_python.txt +++ b/doc/backends_python.txt @@ -57,7 +57,7 @@ import gfxprim.backends as backends backend_string = "X11:100x100"
# Initialize backend by init string - bk = backends.BackendInit(backend_string, "Window title", stderr) + bk = backends.BackendInit(backend_string, "Window title")
# Assert that inicialization was successful assert(bk) @@ -82,7 +82,7 @@ import gfxprim.gfx as gfx import gfxprim.backends as backends
# Initialize backend - bk = backends.BackendInit("X11:100x100", "Window title", stderr) + bk = backends.BackendInit("X11:100x100", "Window title")
# Assert that inicialization was successful assert(bk) @@ -109,7 +109,7 @@ import gfxprim.backends as backends
# Initialize backend - bk = backends.BackendInit("X11:100x100", "Window title", stderr) + bk = backends.BackendInit("X11:100x100", "Window title")
# Assert that inicialization was successful assert(bk) diff --git a/include/backends/GP_BackendInit.h b/include/backends/GP_BackendInit.h index db9fdda..9b89975 100644 --- a/include/backends/GP_BackendInit.h +++ b/include/backends/GP_BackendInit.h @@ -16,7 +16,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, * * Boston, MA 02110-1301 USA * * * - * Copyright (C) 2009-2012 Cyril Hrubis metan@ucw.cz * + * Copyright (C) 2009-2013 Cyril Hrubis metan@ucw.cz * * * *****************************************************************************/
@@ -38,7 +38,7 @@ * * "backend_name:backend_params" * - * For example "SDL:FS" is string for fullscreen SDL backend. + * For example "SDL:fs" is string for fullscreen SDL backend. * * The caption parameter may, or may not be used. For example in windowed * enviroment caption will become caption of a window. When running on @@ -46,9 +46,8 @@ * * Returns initalized backend or NULL in case of failure. * - * If initialization has failed or params is NULL and help is not NULL, help - * text is printed to a given file. + * If help is passed as a backend name a help is printed into the stderr. */ -GP_Backend *GP_BackendInit(const char *params, const char *caption, FILE *help); +GP_Backend *GP_BackendInit(const char *params, const char *caption);
#endif /* BACKENDS_GP_BACKEND_INIT_H */ diff --git a/libs/backends/GP_BackendInit.c b/libs/backends/GP_BackendInit.c index a9c887f..c9f8e8b 100644 --- a/libs/backends/GP_BackendInit.c +++ b/libs/backends/GP_BackendInit.c @@ -28,322 +28,322 @@ #include "GP_Backends.h" #include "GP_BackendInit.h"
-static void backend_sdl_help(FILE *help, const char *err) +static char *next_param(char *params) { - if (help == NULL) - return; - - if (err != NULL) - fprintf(help, "ERROR: %sn", err); - - fprintf(help, "libSDL backendn" - "--------------n" - "SDL:[FS]:[8]:[16]:[24]:[32]:[WxH]n" - " FS - Full Screen moden" - " 8 - Sets 8bppn" - " 16 - Sets 16bppn" - " 24 - Sets 24bppn" - " 32 - Sets 32bppn" - " WxH - Display Sizen"); + for (;;) { + switch (*params) { + case ':': + *params = '0'; + return params + 1; + break; + case '0': + return NULL; + break; + } + params++; + } }
-static int sdl_params_to_flags(const char *param, GP_Size *w, GP_Size *h, - GP_Size *bpp, uint8_t *flags, FILE *help) +static int parse_x11_params(char *params, GP_Size *w, GP_Size *h, + enum GP_BackendX11Flags *flags) { - if (!strcasecmp(param, "FS")) { - *flags |= GP_SDL_FULLSCREEN; - return 0; - } + char *param;
- if (!strcmp(param, "8")) { - *bpp = 8; + if (!params) return 0; - }
- if (!strcmp(param, "16")) { - *bpp = 16; - return 0; - } + do { + param = params; + params = next_param(params);
- if (!strcmp(param, "24")) { - *bpp = 24; - return 0; - } + if (!strcasecmp(param, "use_root")) { + *flags |= GP_X11_USE_ROOT_WIN; + GP_DEBUG(1, "X11: Using root window"); + continue; + }
- if (!strcmp(param, "32")) { - *bpp = 32; - return 0; - } + if (!strcasecmp(param, "create_root")) { + *flags |= GP_X11_CREATE_ROOT_WIN; + GP_DEBUG(1, "X11: Creating root window"); + continue; + } + + if (!strcasecmp(param, "disable_shm")) { + *flags |= GP_X11_DISABLE_SHM; + GP_DEBUG(1, "X11: Disabling SHM"); + continue; + }
- /* - * Accepts only string with format "intxint" or "intXint" - */ - int sw, sh; - unsigned int n; + if (!strcasecmp(param, "fs")) { + *flags |= GP_X11_FULLSCREEN; + GP_DEBUG(1, "X11: Enabling fullscreen"); + continue; + }
- if (sscanf(param, "%i%*[xX]%i%n", &sw, &sh, &n) == 2 && n == strlen(param)) { - *w = sw; - *h = sh; - return 0; - } + /* + * Accepts only string with format "intxint" or "intXint" + */ + int sw, sh; + unsigned int n; + + if (sscanf(param, "%i%*[xX]%i%n", &sw, &sh, &n) == 2 && n == strlen(param)) { + *w = sw; + *h = sh; + continue; + }
- backend_sdl_help(help, "SDL: Invalid parameters"); - errno = EINVAL; - return 1; + GP_WARN("X11: Invalid parameters '%s'", param); + errno = EINVAL; + return 1; + } while (params); + + return 0; }
-static GP_Backend *backend_sdl_init(char *params, const char *caption, - FILE *help) +static GP_Backend *x11_init(char *params, const char *caption) { - if (params == NULL) - return GP_BackendSDLInit(0, 0, 0, 0, caption); + GP_Size w = 640, h = 480; + enum GP_BackendX11Flags flags = 0;
- GP_Size w = 0, h = 0, bpp = 0; - uint8_t flags = GP_SDL_RESIZABLE; + if (parse_x11_params(params, &w, &h, &flags)) + return NULL;
- char *s = params; + return GP_BackendX11Init(NULL, 0, 0, w, h, caption, flags); +}
- for (;;) { - switch (*s) { - case ':': - (*s) = '0'; - if (sdl_params_to_flags(params, &w, &h, &bpp, &flags, help)) - return NULL; - s++; - params = s; - break; - case '0': - if (sdl_params_to_flags(params, &w, &h, &bpp, &flags, help)) - return NULL; +static int parse_sdl_params(char *params, GP_Size *w, GP_Size *h, + GP_Size *bpp, uint8_t *flags) +{ + char *param;
- return GP_BackendSDLInit(w, h, bpp, flags, caption); - break; + if (!params) + return 0; + + do { + param = params; + params = next_param(params); + + if (!strcasecmp(param, "FS")) { + *flags |= GP_SDL_FULLSCREEN; + GP_DEBUG(1, "SDL fullscreen enabled"); + continue; } - s++; - } -}
-static void backend_fb_help(FILE *help, const char *err) -{ - if (help == NULL) - return; + if (!strcmp(param, "8")) { + *bpp = 8; + GP_DEBUG(1, "SDL depth set to 8"); + continue; + }
- if (err != NULL) - fprintf(help, "ERROR: %sn", err); + if (!strcmp(param, "16")) { + *bpp = 16; + GP_DEBUG(1, "SDL depth set to 16"); + continue; + }
- fprintf(help, "LinuxFB backendn" - "--------------n" - "FB:NO_SHADOW:USE_CON:[/dev/fbX]n"); -} + if (!strcmp(param, "24")) { + *bpp = 24; + GP_DEBUG(1, "SDL depth set to 24"); + continue; + }
-static GP_Backend *backend_fb_init(char *params, const char *caption, - FILE *help) -{ - const char *fb = "/dev/fb0"; + if (!strcmp(param, "32")) { + *bpp = 32; + GP_DEBUG(1, "SDL depth set to 32"); + continue; + }
- (void) help; - (void) caption; + /* + * Accepts only string with format "intxint" or "intXint" + */ + int sw, sh; + unsigned int n;
- if (params != NULL) - fb = params; + if (sscanf(param, "%i%*[xX]%i%n", &sw, &sh, &n) == 2 && n == strlen(param)) { + *w = sw; + *h = sh; + continue; + } + + GP_WARN("SDL: Invalid parameters '%s'", param); + errno = EINVAL; + return 1; + } while (params);
- return GP_BackendLinuxFBInit(fb, 3); + return 0; }
-static void backend_x11_help(FILE *help, const char *err) +static GP_Backend *sdl_init(char *params, const char *caption) { - if (help == NULL) - return; - - if (err != NULL) - fprintf(help, "ERROR: %sn", err); - - fprintf(help, "X11 backendn" - "--------------n" - "X11:[WxH]:[ROOT_WIN]:[CREATE_ROOT]nn" - "ROOT_WIN - starts the backend in the root windown" - " (w and h, if set, are ignored)n" - "CREATE_ROOT - starts the backend in newly createdn" - " root window (w and h, if set, are ignored)n" - "DISABLE_SHM - disable MIT SHM even if availablen" - "FS - start fullscreenn"); + GP_Size w = 0, h = 0, bpp = 0; + uint8_t flags = GP_SDL_RESIZABLE; + + if (parse_sdl_params(params, &w, &h, &bpp, &flags)) + return NULL;
+ return GP_BackendSDLInit(w, h, bpp, flags, caption); }
-static int x11_params_to_flags(const char *param, GP_Size *w, GP_Size *h, - enum GP_BackendX11Flags *flags, FILE *help) +static int parse_fb_params(char *params, int *flags, const char **fb) { - if (!strcasecmp(param, "ROOT_WIN")) { - *flags |= GP_X11_USE_ROOT_WIN; - return 0; - } + char *param;
- if (!strcasecmp(param, "CREATE_ROOT")) { - *flags |= GP_X11_CREATE_ROOT_WIN; + if (!params) return 0; - } - - if (!strcasecmp(param, "DISABLE_SHM")) { - *flags |= GP_X11_DISABLE_SHM; - return 0; - } - - if (!strcasecmp(param, "FS")) { - *flags |= GP_X11_FULLSCREEN; - return 0; - } - - /* - * Accepts only string with format "intxint" or "intXint" - */ - int sw, sh; - unsigned int n;
- if (sscanf(param, "%i%*[xX]%i%n", &sw, &sh, &n) == 2 && n == strlen(param)) { - *w = sw; - *h = sh; - return 0; - } + do { + param = params; + params = next_param(params);
- backend_x11_help(help, "X11: Invalid parameters"); - errno = EINVAL; - return 1; -} + if (!strcasecmp(param, "no_shadow")) { + *flags &= ~GP_FB_SHADOW; + GP_DEBUG(1, "Shadow framebuffer disabled"); + continue; + }
+ if (!strcasecmp(param, "new_console")) { + *flags |= GP_FB_ALLOC_CON; + GP_DEBUG(1, "Console allocation enabled"); + continue; + }
-static GP_Backend *backend_x11_init(char *params, const char *caption, - FILE *help) -{ - GP_Size w = 640, h = 480; - enum GP_BackendX11Flags flags = 0; + *fb = param;
- if (params == NULL) - return GP_BackendX11Init(NULL, 0, 0, w, h, caption, 0); + if (strncmp(*fb, "/dev/", 5)) + GP_WARN("Console dev set to '%s', are you sure?", *fb);
- char *s = params; + GP_DEBUG(1, "Framebuffer console set to '%s'", *fb);
- for (;;) { - switch (*s) { - case ':': - (*s) = '0'; - if (x11_params_to_flags(params, &w, &h, &flags, help)) - return NULL; - s++; - params = s; - break; - case '0': - if (x11_params_to_flags(params, &w, &h, &flags, help)) - return NULL; + } while (params);
- return GP_BackendX11Init(NULL, 0, 0, w, h, caption, flags); - break; - } - s++; - } + return 0; }
-static void backend_aa_help(FILE *help, const char *err) +static GP_Backend *fb_init(char *params, const char *caption) { - if (help == NULL) - return; + const char *fb = "/dev/fb0";
- if (err != NULL) - fprintf(help, "ERROR: %sn", err); + (void) caption; + + int flags = GP_FB_INPUT_KBD | GP_FB_SHADOW; + + parse_fb_params(params, &flags, &fb);
- fprintf(help, "AALib backendn" - "--------------n" - "AAn"); + return GP_BackendLinuxFBInit(fb, flags); }
-static GP_Backend *backend_aa_init(char *params, const char *caption, - FILE *help) +static GP_Backend *aa_init(char *params, const char *caption) { - (void) help; (void) caption; (void) params;
return GP_BackendAALibInit(); }
- -static const char *backend_names[] = { - "SDL", /* libSDL */ - "FB", /* Linux Framebuffer */ - "X11", /* X11 window system */ - "AA", /* AALib */ - NULL, -}; - -static GP_Backend *(*backend_inits[])(char *, const char *, FILE *) = { - backend_sdl_init, - backend_fb_init, - backend_x11_init, - backend_aa_init, - NULL, +struct backend_init { + const char *name; + GP_Backend *(*init)(char *params, const char *caption); + const char *usage; + const char *help[10]; };
-static void (*backend_helps[])(FILE *help, const char *err) = { - backend_sdl_help, - backend_fb_help, - backend_x11_help, - backend_aa_help, - NULL, +static GP_Backend *do_help(char *params, const char *caption); + +static struct backend_init backends[] = { + {.name = "X11", + .init = x11_init, + .usage = "X11:[WxH]:[use_root]:[create_root]:[disable_shm]", + .help = {"use_root - starts the backend in the root window", + " (w and h, if set, are ignored)", + "create_root - starts the backend in newly created", + " root window (w and h, if set, are ignored)", + "disable_shm - disable MIT SHM even if available", + "fs - start fullscreen", + NULL} + }, + {.name = "SDL", + .init = sdl_init, + .usage = "SDL:[fs]:[8]:[16]:[24]:[32]:[WxH]", + .help = {"fs - Full Screen mode", + "8 - Sets 8bpp", + "16 - Sets 16bpp", + "24 - Sets 24bpp", + "32 - Sets 32bpp", + "WxH - Display Size", + NULL} + }, + {.name = "FB", + .init = fb_init, + .usage = "fb:[no_shadow]:[new_console]:[/dev/fbX]", + .help = {"no_shadow - turns off shadow buffer", + "new_console - allocate new console", + NULL} + }, + {.name = "AA", + .init = aa_init, + .usage = "AA", + .help = {NULL} + }, + {.name = "help", + .init = do_help + }, + {.name = NULL} };
-static void print_help(FILE *help, char *err) +static GP_Backend *do_help(char *params, const char *caption) { - int i; + struct backend_init *i; + unsigned int j;
- if (help == NULL) - return; + (void) params; + (void) caption;
- if (err != NULL) { - fprintf(help, "ERROR: %sn", err); - fprintf(help, "n"); + for (i = backends; (i+1)->name; i++) { + fprintf(stderr, "Backend %snn %snn", + i->name, i->usage); + if (i->help[0]) { + for (j = 0; i->help[j]; j++) + fprintf(stderr, " %sn", i->help[j]); + fprintf(stderr, "n"); + } }
- fprintf(help, "Backends usagen" - "--------------nn"); - - for (i = 0; backend_helps[i] != NULL; i++) { - backend_helps[i](help, NULL); - fprintf(help, "n"); - } + return NULL; }
-static int get_backend(const char *name) +static struct backend_init *get_backend(const char *name) { - int i; + struct backend_init *i;
- for (i = 0; backend_names[i] != 0; i++) - if (!strcasecmp(name, backend_names[i])) + for (i = backends; i->name; i++) { + if (!strcasecmp(name, i->name)) return i; + }
- return -1; + return NULL; }
static GP_Backend *init_backend(const char *name, char *params, - const char *caption, FILE *help) + const char *caption) { - int i = get_backend(name); + struct backend_init *init = get_backend(name); GP_Backend *ret;
- if (i < 0) { - GP_DEBUG(1, "Invalid backend name '%s'", name); - print_help(help, "Invalid backend name"); + if (!init) { + GP_WARN("Invalid backend name '%s'", name); errno = EINVAL; return NULL; }
- ret = backend_inits[i](params, caption, help); + ret = init->init(params, caption);
return ret; }
-GP_Backend *GP_BackendInit(const char *params, const char *caption, FILE *help) +GP_Backend *GP_BackendInit(const char *params, const char *caption) { if (params == NULL) { - print_help(help, NULL); + do_help(NULL, NULL); return NULL; }
@@ -363,5 +363,5 @@ GP_Backend *GP_BackendInit(const char *params, const char *caption, FILE *help)
GP_DEBUG(1, "Have backend name '%s' params '%s'", buf, backend_params);
- return init_backend(buf, backend_params, caption, help); + return init_backend(buf, backend_params, caption); } diff --git a/pylib/gfxprim/backends/backends.i b/pylib/gfxprim/backends/backends.i index e893674..319129d 100644 --- a/pylib/gfxprim/backends/backends.i +++ b/pylib/gfxprim/backends/backends.i @@ -51,36 +51,7 @@ ERROR_ON_NULL(GP_BackendLinuxX11Init); %newobject GP_BackendX11Init; %include "GP_X11.h"
-/* - * Backend Init with a typemap for FILE* for the last parameter - * - * This is a ugly hack because Python 3 uses its own I/O buffers for file - * objects. - * - */ -%typemap(in) FILE* { - if ($input != Py_None) { - int fd = PyObject_AsFileDescriptor($input); - - if (fd < 0) { - PyErr_SetString(PyExc_TypeError, "$1_name must be a file type."); - return NULL; - } - - $1 = fdopen(dup(fd), "w"); - } -} - -%exception GP_BackendInit { -$action - - //HACK: fclose the FILE* - fclose(arg3); - - if (result == NULL) - return PyErr_SetFromErrno(PyExc_OSError); -} - %newobject GP_BackendInit; +ERROR_ON_NULL(GP_BackendInit); %include "GP_BackendInit.h"
http://repo.or.cz/w/gfxprim.git/commit/48c629b8a273d8e72d4e381fc86f930fc8bf1...
commit 48c629b8a273d8e72d4e381fc86f930fc8bf14a7 Author: Cyril Hrubis metan@ucw.cz Date: Sun Dec 22 18:54:51 2013 +0100
spiv: Print backend help if only '-b help' was passed
Signed-off-by: Cyril Hrubis metan@ucw.cz
diff --git a/demos/spiv/spiv.c b/demos/spiv/spiv.c index b3139d9..33b0971 100644 --- a/demos/spiv/spiv.c +++ b/demos/spiv/spiv.c @@ -752,6 +752,12 @@ int main(int argc, char *argv[]) params.sleep_ms = 1000 * config.slideshow_delay + 0.5;
if (opts >= argc) { + + if (!strcmp(config.backend_init, "help")) { + init_backend(config.backend_init); + return 0; + } + fprintf(stderr, "Requires path to at least one imagenn"); print_help(); return 1;
-----------------------------------------------------------------------
Summary of changes: demos/c_simple/backend_example.c | 4 +- demos/c_simple/backend_timers_example.c | 2 +- demos/c_simple/blittest.c | 2 +- demos/c_simple/fileview.c | 2 +- demos/c_simple/fonttest.c | 2 +- demos/c_simple/input_example.c | 4 +- demos/c_simple/koch.c | 2 +- demos/c_simple/linetest.c | 2 +- demos/c_simple/randomshapetest.c | 2 +- demos/c_simple/shapetest.c | 2 +- demos/c_simple/textaligntest.c | 2 +- demos/c_simple/virtual_backend_example.c | 4 +- demos/particle/particle_demo.c | 2 +- demos/py_simple/backends.py | 2 +- demos/spiv/spiv.c | 8 +- demos/spiv/spiv_help.c | 4 +- doc/Makefile | 3 +- doc/backends.txt | 29 +- doc/backends_python.txt | 6 +- doc/basic_types.txt | 1 + doc/convert.txt | 39 +++ doc/gfx.txt | 2 + include/backends/GP_BackendInit.h | 9 +- libs/backends/GP_BackendInit.c | 456 +++++++++++++++--------------- pylib/gfxprim/backends/backends.i | 31 +-- 25 files changed, 322 insertions(+), 300 deletions(-) create mode 100644 doc/convert.txt
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.