Gfxprim
Threads by month
- ----- 2026 -----
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- 929 discussions
[repo.or.cz] gfxprim.git branch master updated: 94726f09c80a120c03ee251338f2a2800bdaa076
by metan 20 Dec '12
by metan 20 Dec '12
20 Dec '12
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 94726f09c80a120c03ee251338f2a2800bdaa076 (commit)
from 951e4bf59ad725f05fce1600e8da2ca8f4a8f8c0 (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/94726f09c80a120c03ee251338f2a2800bda…
commit 94726f09c80a120c03ee251338f2a2800bdaa076
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Thu Dec 20 15:53:05 2012 +0100
doc: Add clear bitendian definition.
diff --git a/doc/.gitignore b/doc/.gitignore
index 4b4703c..670b96a 100644
--- a/doc/.gitignore
+++ b/doc/.gitignore
@@ -9,3 +9,7 @@ discrete_linear_convolution_alg2.png
laplacian_edge_sharpening.png
laplacian_kernel.png
+bit-endian-be-1bit.png
+bit-endian-be-2bits.png
+bit-endian-le-1bit.png
+bit-endian-le-2bits.png
diff --git a/doc/README b/doc/README
index ae93336..400ede1 100644
--- a/doc/README
+++ b/doc/README
@@ -2,4 +2,5 @@ This directory contains asciidoc documentation.
The html pages are generated by typing 'make'.
-In order to do that asciidoc and source-highlight, latex and dvipng must be installed.
+In order to do that asciidoc and source-highlight, latex and dvipng and
+graphviz must be installed.
diff --git a/doc/gen.txt b/doc/gen.txt
index 28b438d..949f585 100644
--- a/doc/gen.txt
+++ b/doc/gen.txt
@@ -38,13 +38,98 @@ per pixel. It also contains suffix that is a string used as a suffix for
functions that manipulates with this pixel size.
The 'bit_endian' determines direction of bits in bitmaps and graymaps (i.e.
-most significant bit left or right). It can be either 'BE' or 'LE'.
-
-Note that different pixels can share the same pixel size as for certain types
-of operations the function doesn't depend on actual arrangements of the color
-channels in pixel (i.e. Get/Put Pixel, Rotate buffer 90 degrees, etc...).
-
-TODO: Which bit endian is which?
+most significant bit left or right). It can be either 'BE' or 'LE'. To avoid
+confusion following two figures describes bits layout in 1 bit and 2 bits
+grayscale bitmaps. The rectangles in the figures represents bytes as they are
+in the buffer. The start of the image (i.e. topleft corner and coodinate 0,0)
+is on the left side. The numbers describes position of the bit in the byte (as
+seen by shifts and bitmask from within C language implementation).
+
+BE
+~~
+
+["graphviz", "bit-endian-be-1bit.png"]
+------------------------------------------------------------------------------
+digraph bit_endian {
+ node [shape = record];
+ rankdir = LR;
+
+ node0 [label = "{<e> ...}"];
+ node1 [label = "{7 | 6 | 5 | 4 | 3 | 2 | 1 | <e> 0}"];
+ node2 [label = "{<b> 7 | 6 | 5 | 4 | 3 | 2 | 1 | <e> 0}"];
+ node3 [label = "{<b> 7 | 6 | 5 | 4 | 3 | 2 | 1 | <e> 0}"];
+ node4 [label = "{<b> ...}"];
+
+ node0:e -> node1:b;
+ node1:e -> node2:b;
+ node2:e -> node3:b;
+ node3:e -> node4:b;
+}
+------------------------------------------------------------------------------
+
+["graphviz", "bit-endian-be-2bits.png"]
+------------------------------------------------------------------------------
+digraph bit_endian {
+ node [shape = record];
+ rankdir = LR;
+
+ node0 [label = "{<e> ...}"];
+ node1 [label = "{7 6 | 5 4 | 3 2 | <e> 1 0}"];
+ node2 [label = "{<b> 7 6 | 5 4 | 3 2 | <e> 1 0}"];
+ node3 [label = "{<b> 7 6 | 5 4 | 3 2 | <e> 1 0}"];
+ node4 [label = "{<b> ...}"];
+
+ node0:e -> node1:b;
+ node1:e -> node2:b;
+ node2:e -> node3:b;
+ node3:e -> node4:b;
+}
+------------------------------------------------------------------------------
+
+LE
+~~
+
+["graphviz", "bit-endian-le-1bit.png"]
+------------------------------------------------------------------------------
+digraph bit_endian {
+ node [shape = record];
+ rankdir = LR;
+
+ node0 [label = "{<e> ...}"];
+ node1 [label = "{0 | 1 | 2 | 3 | 4 | 5 | 6 | <e> 7}"];
+ node2 [label = "{<b> 0 | 1 | 2 | 3 | 4 | 5 | 6 | <e> 7}"];
+ node3 [label = "{<b> 0 | 1 | 2 | 3 | 4 | 5 | 6 | <e> 7}"];
+ node4 [label = "{<b> ...}"];
+
+ node0:e -> node1:b;
+ node1:e -> node2:b;
+ node2:e -> node3:b;
+ node3:e -> node4:b;
+}
+------------------------------------------------------------------------------
+
+["graphviz", "bit-endian-le-2bits.png"]
+------------------------------------------------------------------------------
+digraph bit_endian {
+ node [shape = record];
+ rankdir = LR;
+
+ node0 [label = "<e> ..."];
+ node1 [label = "{0 1 | 2 3 | 4 5 | <e> 6 7}"];
+ node2 [label = "{<b> 0 1 | 2 3 | 4 5 | <e> 6 7}"];
+ node3 [label = "{<b> 0 1 | 2 3 | 4 5 | <e> 6 7}"];
+ node4 [label = "{<b> ...}"];
+
+ node0:e -> node1:b;
+ node1:e -> node2:b;
+ node2:e -> node3:b;
+ node3:e -> node4:b;
+}
+------------------------------------------------------------------------------
+
+NOTE: Different pixels can share the same pixel size as for certain types
+ of operations the function doesn't depend on actual arrangements of the
+ color channels in pixel (i.e. Get/Put Pixel, Rotate buffer 90 degrees, etc...).
TODO: Rename size to bpp?
-----------------------------------------------------------------------
Summary of changes:
doc/.gitignore | 4 ++
doc/README | 3 +-
doc/gen.txt | 99 ++++++++++++++++++++++++++++++++++++++++++++++++++++----
3 files changed, 98 insertions(+), 8 deletions(-)
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos(a)gmail.com
if you want to unsubscribe, or site admin admin(a)repo.or.cz if you receive
no reply.
--
gfxprim.git ("A simple 2D graphics library with emphasis on correctness and well-defined operation.")
1
0
[repo.or.cz] gfxprim.git branch master updated: 951e4bf59ad725f05fce1600e8da2ca8f4a8f8c0
by metan 20 Dec '12
by metan 20 Dec '12
20 Dec '12
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 951e4bf59ad725f05fce1600e8da2ca8f4a8f8c0 (commit)
via ddbd27fd085cc515d61fdae1a159922090eb327b (commit)
from 3a66b0d92c78955b31e8b825f3b2049ffdf3487a (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/951e4bf59ad725f05fce1600e8da2ca8f4a8…
commit 951e4bf59ad725f05fce1600e8da2ca8f4a8f8c0
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Thu Dec 20 13:46:29 2012 +0100
demos: spiv: Move image listing code into separate file.
diff --git a/demos/spiv/Makefile b/demos/spiv/Makefile
index f533179..95e7560 100644
--- a/demos/spiv/Makefile
+++ b/demos/spiv/Makefile
@@ -8,7 +8,7 @@ LDLIBS+=-lrt `$(TOPDIR)/gfxprim-config --libs --libs-backends`
APPS=spiv
-spiv: cpu_timer.o image_cache.o
+spiv: cpu_timer.o image_cache.o image_list.o
include $(TOPDIR)/pre.mk
include $(TOPDIR)/app.mk
diff --git a/demos/spiv/image_list.c b/demos/spiv/image_list.c
new file mode 100644
index 0000000..390275f
--- /dev/null
+++ b/demos/spiv/image_list.c
@@ -0,0 +1,110 @@
+/*****************************************************************************
+ * 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-2012 Cyril Hrubis <metan(a)ucw.cz> *
+ * *
+ *****************************************************************************/
+
+#include <stdlib.h>
+
+#include <core/GP_Debug.h>
+
+#include "image_list.h"
+
+struct image_list {
+ /* list we got from the app */
+ const char **args;
+ unsigned int cur_arg;
+ unsigned int max_arg;
+
+ /* path to the currently loaded image */
+ char path[1024];
+ int path_loaded:1;
+};
+
+static void next_img(struct image_list *self)
+{
+ if (++self->cur_arg == self->max_arg)
+ self->cur_arg = 0;
+
+ self->path_loaded = 0;
+}
+
+static void prev_img(struct image_list *self)
+{
+ if (self->cur_arg == 0)
+ self->cur_arg = self->max_arg - 1;
+ else
+ self->cur_arg--;
+
+ self->path_loaded = 0;
+}
+
+static void load_path(struct image_list *self)
+{
+ snprintf(self->path, sizeof(self->path), "%s", self->args[self->cur_arg]);
+
+ self->path_loaded = 1;
+}
+
+const char *image_list_move(struct image_list *self, int direction)
+{
+ GP_DEBUG(2, "Moving list by %i", direction);
+
+ int i;
+
+ for (i = 0; i < direction; i++)
+ next_img(self);
+
+ for (i = 0; i > direction; i--)
+ prev_img(self);
+
+ return image_list_img_path(self);
+}
+
+struct image_list *image_list_create(const char *args[])
+{
+ struct image_list *self;
+
+ GP_DEBUG(1, "Creating image list");
+
+ self = malloc(sizeof(struct image_list));
+
+ if (self == NULL)
+ return NULL;
+
+ self->args = args;
+ self->cur_arg = 0;
+
+ self->path_loaded = 0;
+
+ self->max_arg = 0;
+ while (args[++self->max_arg] != NULL);
+
+ return self;
+}
+
+const char *image_list_img_path(struct image_list *self)
+{
+ if (!self->path_loaded)
+ load_path(self);
+
+ GP_DEBUG(2, "Returning path '%s'", self->path);
+
+ return self->path;
+}
diff --git a/demos/spiv/image_list.h b/demos/spiv/image_list.h
new file mode 100644
index 0000000..e7b299a
--- /dev/null
+++ b/demos/spiv/image_list.h
@@ -0,0 +1,50 @@
+/*****************************************************************************
+ * 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-2012 Cyril Hrubis <metan(a)ucw.cz> *
+ * *
+ *****************************************************************************/
+
+ /*
+
+ Image list.
+
+ */
+
+#ifndef __IMAGE_LIST_H__
+#define __IMAGE_LIST_H__
+
+struct image_list;
+
+/*
+ * Takes NULL-terminated array of paths as parameter
+ */
+struct image_list *image_list_create(const char *args[]);
+
+/*
+ * Returns path to the current image.
+ */
+const char *image_list_img_path(struct image_list *self);
+
+/*
+ * Moves the current image direction images and returns pointer to current
+ * path.
+ */
+const char *image_list_move(struct image_list *self, int direction);
+
+#endif /* __IMAGE_LIST_H__ */
diff --git a/demos/spiv/spiv.c b/demos/spiv/spiv.c
index 7c3dd20..82a8e75 100644
--- a/demos/spiv/spiv.c
+++ b/demos/spiv/spiv.c
@@ -37,6 +37,7 @@
#include <input/GP_InputDriverLinux.h>
#include "image_cache.h"
+#include "image_list.h"
#include "cpu_timer.h"
static GP_Pixel black_pixel;
@@ -325,7 +326,7 @@ GP_Context *load_resized_image(struct loader_params *params, GP_Size w, GP_Size
cpu_timer_stop(&timer);
}
-// img->gamma = GP_GammaAcquire(img->pixel_type, 2.2);
+// img->gamma = GP_GammaAcquire(img->pixel_type, 0.45);
cpu_timer_start(&timer, "Resampling");
callback.priv = "Resampling Image";
@@ -637,7 +638,7 @@ int main(int argc, char *argv[])
int opt, debug_level = 0;
int shift_flag;
GP_PixelType emul_type = GP_PIXEL_UNKNOWN;
-
+
struct loader_params params = {
.img_path = NULL,
@@ -730,21 +731,16 @@ int main(int argc, char *argv[])
GP_Fill(context, black_pixel);
GP_BackendFlip(backend);
- int argf = optind;
- int argn = argf;
+
+ struct image_list *list = image_list_create((const char**)argv + optind);
params.show_progress_once = 1;
- show_image(¶ms, argv[argf]);
+ show_image(¶ms, image_list_img_path(list));
for (;;) {
/* wait for event or a timeout */
- if (wait_for_event(sleep_sec * 1000)) {
- argn++;
- if (argn >= argc)
- argn = argf;
-
- show_image(¶ms, argv[argn]);
- }
+ if (wait_for_event(sleep_sec * 1000))
+ show_image(¶ms, image_list_move(list, 1));
/* Read and parse events */
GP_Event ev;
@@ -809,7 +805,7 @@ int main(int argc, char *argv[])
}
params.show_progress_once = 1;
- show_image(¶ms, argv[argn]);
+ show_image(¶ms, image_list_img_path(list));
break;
case GP_KEY_LEFT_BRACE:
if (params.resampling_method == 0)
@@ -826,13 +822,13 @@ int main(int argc, char *argv[])
}
params.show_progress_once = 1;
- show_image(¶ms, argv[argn]);
+ show_image(¶ms, image_list_img_path(list));
break;
case GP_KEY_L:
params.use_low_pass = !params.use_low_pass;
params.show_progress_once = 1;
- show_image(¶ms, argv[argn]);
+ show_image(¶ms, image_list_img_path(list));
break;
case GP_KEY_D:
image_cache_drop(params.img_resized_cache);
@@ -847,45 +843,26 @@ int main(int argc, char *argv[])
return 0;
break;
case GP_KEY_PAGE_UP:
- argn+=10;
- //TODO
- if (argn >= argc)
- argn = argf;
-
params.show_progress_once = 1;
- show_image(¶ms, argv[argn]);
+ show_image(¶ms, image_list_move(list, 10));
break;
case GP_KEY_PAGE_DOWN:
- argn-=10;
- //TODO
- if (argn < argf)
- argn = argc - 1 ;
-
params.show_progress_once = 1;
- show_image(¶ms, argv[argn]);
+ show_image(¶ms, image_list_move(list, -10));
break;
next:
case GP_KEY_RIGHT:
case GP_KEY_UP:
case GP_KEY_SPACE:
- argn++;
- if (argn >= argc)
- argn = argf;
-
params.show_progress_once = 1;
- show_image(¶ms, argv[argn]);
+ show_image(¶ms, image_list_move(list, 1));
break;
prev:
case GP_KEY_BACKSPACE:
case GP_KEY_LEFT:
case GP_KEY_DOWN:
- argn--;
-
- if (argn < argf)
- argn = argc - 1;
-
params.show_progress_once = 1;
- show_image(¶ms, argv[argn]);
+ show_image(¶ms, image_list_move(list, -1));
break;
case GP_KEY_1:
resize_backend(¶ms, 1, shift_flag);
http://repo.or.cz/w/gfxprim.git/commit/ddbd27fd085cc515d61fdae1a159922090eb…
commit ddbd27fd085cc515d61fdae1a159922090eb327b
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Thu Dec 20 13:16:51 2012 +0100
build: configure: The -lXext should be in LDFLAGS.
diff --git a/configure b/configure
index a13f914..db5733f 100755
--- a/configure
+++ b/configure
@@ -255,7 +255,7 @@ if __name__ == '__main__':
[header_exists, "X11/Xlib.h"], "", "-lX11", ["backends"]],
["X_SHM",
"MIT-SHM X Extension",
- [header_exists, "X11/extensions/XShm.h"], "-lXext", "", ["backends"]],
+ [header_exists, "X11/extensions/XShm.h"], "", "-lXext", ["backends"]],
["freetype",
"A high-quality and portable font engine",
[header_exists, "ft2build.h"], "", "`freetype-config --libs`", ["core"]],
-----------------------------------------------------------------------
Summary of changes:
configure | 2 +-
demos/spiv/Makefile | 2 +-
.../framework/tst_msg.c => demos/spiv/image_list.c | 122 +++++++++++---------
demos/spiv/{cpu_timer.h => image_list.h} | 30 +++---
demos/spiv/spiv.c | 53 +++------
5 files changed, 100 insertions(+), 109 deletions(-)
copy tests/framework/tst_msg.c => demos/spiv/image_list.c (53%)
copy demos/spiv/{cpu_timer.h => image_list.h} (77%)
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos(a)gmail.com
if you want to unsubscribe, or site admin admin(a)repo.or.cz if you receive
no reply.
--
gfxprim.git ("A simple 2D graphics library with emphasis on correctness and well-defined operation.")
1
0
[repo.or.cz] gfxprim.git branch master updated: 3a66b0d92c78955b31e8b825f3b2049ffdf3487a
by bluebear 18 Dec '12
by bluebear 18 Dec '12
18 Dec '12
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 3a66b0d92c78955b31e8b825f3b2049ffdf3487a (commit)
via 9176505d3276942f16192b028d57ca9571c81797 (commit)
from 57c57c59cd6ce43a4df21a9309cdbb7cd5e1bf16 (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/3a66b0d92c78955b31e8b825f3b2049ffdf3…
commit 3a66b0d92c78955b31e8b825f3b2049ffdf3487a
Merge: 9176505 57c57c5
Author: Jiri BlueBear Dluhos <jiri.bluebear.dluhos(a)gmail.com>
Date: Tue Dec 18 22:59:03 2012 +0100
Merge branch 'master' of ssh://repo.or.cz/srv/git/gfxprim
http://repo.or.cz/w/gfxprim.git/commit/9176505d3276942f16192b028d57ca9571c8…
commit 9176505d3276942f16192b028d57ca9571c81797
Author: Jiri BlueBear Dluhos <jiri.bluebear.dluhos(a)gmail.com>
Date: Tue Dec 18 22:58:16 2012 +0100
First stab at analytic line clipping.
diff --git a/include/gfx/GP_LineClip.h b/include/gfx/GP_LineClip.h
new file mode 100644
index 0000000..32ad6af
--- /dev/null
+++ b/include/gfx/GP_LineClip.h
@@ -0,0 +1,31 @@
+/*****************************************************************************
+ * 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-2010 Jiri "BlueBear" Dluhos *
+ * <jiri.bluebear.dluhos(a)gmail.com> *
+ * *
+ * Copyright (C) 2009-2012 Cyril Hrubis <metan(a)ucw.cz> *
+ * *
+ *****************************************************************************/
+
+#ifndef GP_LINECLIP_H
+#define GP_LINECLIP_H
+
+int GP_LineClip(int *px0, int *py0, int *px1, int *py1, int xmax, int ymax);
+
+#endif
diff --git a/libs/gfx/GP_Line.gen.c.t b/libs/gfx/GP_Line.gen.c.t
index edc5382..668d89f 100644
--- a/libs/gfx/GP_Line.gen.c.t
+++ b/libs/gfx/GP_Line.gen.c.t
@@ -36,6 +36,7 @@
#include "gfx/GP_VLine.h"
#include "gfx/GP_HLine.h"
#include "gfx/GP_Line.h"
+#include "gfx/GP_LineClip.h"
/*
* The classical Bresenham line drawing algorithm.
@@ -48,6 +49,14 @@
void GP_Line_Raw_{{ ps.suffix }}(GP_Context *context, int x0, int y0,
int x1, int y1, GP_Pixel pixval)
{
+ if (!GP_LineClip(&x0, &y0, &x1, &y1, context->w - 1, context->h - 1))
+ return;
+
+ GP_ASSERT(x0 >= 0 && x0 <= (int) context->w-1);
+ GP_ASSERT(x1 >= 0 && x1 <= (int) context->w-1);
+ GP_ASSERT(y0 >= 0 && y0 <= (int) context->h-1);
+ GP_ASSERT(y1 >= 0 && y1 <= (int) context->h-1);
+
/* special cases: vertical line, horizontal line, single point */
if (x0 == x1) {
if (y0 == y1) {
@@ -93,10 +102,10 @@ void GP_Line_Raw_{{ ps.suffix }}(GP_Context *context, int x0, int y0,
for (x = x0; x <= x1; x++) {
if (steep)
- GP_PutPixel_Raw_Clipped_{{ ps.suffix }}(context, y, x,
+ GP_PutPixel_Raw_{{ ps.suffix }}(context, y, x,
pixval);
else
- GP_PutPixel_Raw_Clipped_{{ ps.suffix }}(context, x, y,
+ GP_PutPixel_Raw_{{ ps.suffix }}(context, x, y,
pixval);
error -= deltay;
diff --git a/libs/gfx/GP_LineClip.c b/libs/gfx/GP_LineClip.c
new file mode 100644
index 0000000..6a1f76e
--- /dev/null
+++ b/libs/gfx/GP_LineClip.c
@@ -0,0 +1,129 @@
+/*****************************************************************************
+ * 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-2010 Jiri "BlueBear" Dluhos *
+ * <jiri.bluebear.dluhos(a)gmail.com> *
+ * *
+ * Copyright (C) 2009-2010 Cyril Hrubis <metan(a)ucw.cz> *
+ * *
+ *****************************************************************************/
+
+#include "core/GP_Common.h"
+#include "core/GP_Types.h"
+#include "gfx/GP_LineClip.h"
+
+int GP_LineClip(int *px0, int *py0, int *px1, int *py1, int xmax, int ymax)
+{
+ float x0 = (float) *px0;
+ float y0 = (float) *py0;
+ float x1 = (float) *px1;
+ float y1 = (float) *py1;
+
+ /* horizontal and vertical line are special cases */
+ if (y0 == y1) {
+
+ /* orient the line from left to right */
+ if (x1 < x0) {
+ GP_SWAP(x0, x1);
+ GP_SWAP(y0, y1);
+ }
+
+ /* check if it is not completely outside */
+ if (x1 < 0 || x0 > xmax || y0 < 0 || y0 > ymax)
+ return 0;
+
+ x0 = GP_MAX(x0, 0);
+ x1 = GP_MIN(x1, xmax);
+ goto give_result;
+ }
+ if (x0 == x1) {
+
+ /* orient the line from top to down */
+ if (x1 < x0) {
+ GP_SWAP(x0, x1);
+ GP_SWAP(y0, y1);
+ }
+
+ /* check if it is not completely outside */
+ if (y1 < 0 || y0 > ymax || x0 < 0 || x0 > xmax)
+ return 0;
+
+ /* clip it to the valid range */
+ y0 = GP_MAX(y0, 0);
+ y1 = GP_MIN(y1, ymax);
+ goto give_result;
+ }
+
+ /* orient the line from left to right */
+ if (x1 < x0) {
+ GP_SWAP(x0, x1);
+ GP_SWAP(y0, y1);
+ }
+
+ if (x1 < 0 || x0 > xmax || (y0 < 0 && y1 < 0) || (y0 > ymax && y1 > ymax)) {
+
+ /* the line lies completely outside the rectangle */
+ return 0;
+ }
+
+ float dx = (float)(x1 - x0);
+ float dy = (float)(y1 - y0);
+ float dyx = dy/dx;
+ float dxy = dx/dy;
+
+ /* clip the line against the left and right side of the rectangle */
+ if (x0 < 0) {
+ y0 = y0 - x0*dyx;
+ x0 = 0;
+ }
+ if (x1 > xmax) {
+ x1 = xmax;
+ y1 = y0 + (x1-x0)*dyx;
+ }
+
+ if (y0 < 0.0f) {
+ x0 = x0 - y0*dxy;
+ y0 = 0.0f;
+ } else if (y0 > ymax) {
+ x0 = x0 + (ymax-y0)*dxy;
+ y0 = ymax;
+ }
+
+ if (y1 < 0.0f) {
+ x1 = x1 - y1*dxy;
+ y1 = 0.0f;
+ }
+ else if (y1 > ymax) {
+ x1 = x1 - (y1 - ymax)*dxy;
+ y1 = ymax;
+ }
+
+ if (x0 < 0 || x0 > xmax || x1 < 0 || x1 > xmax) {
+
+ /* the line misses the clip rectangle around the corner */
+ return 0;
+ }
+
+give_result:
+
+ *px0 = (int) x0;
+ *py0 = (int) y0;
+ *px1 = (int) x1;
+ *py1 = (int) y1;
+ return 1;
+}
-----------------------------------------------------------------------
Summary of changes:
.../GP_TextStyle.c => include/gfx/GP_LineClip.h | 17 +--
libs/gfx/GP_Line.gen.c.t | 13 ++-
include/core/GP_Core.h => libs/gfx/GP_LineClip.c | 154 +++++++++++++-------
3 files changed, 120 insertions(+), 64 deletions(-)
copy libs/text/GP_TextStyle.c => include/gfx/GP_LineClip.h (85%)
copy include/core/GP_Core.h => libs/gfx/GP_LineClip.c (50%)
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos(a)gmail.com
if you want to unsubscribe, or site admin admin(a)repo.or.cz if you receive
no reply.
--
gfxprim.git ("A simple 2D graphics library with emphasis on correctness and well-defined operation.")
1
0
[repo.or.cz] gfxprim.git branch master updated: 57c57c59cd6ce43a4df21a9309cdbb7cd5e1bf16
by metan 18 Dec '12
by metan 18 Dec '12
18 Dec '12
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 57c57c59cd6ce43a4df21a9309cdbb7cd5e1bf16 (commit)
via 78c4f27c1460b40d07c59ab79a5050601756cf40 (commit)
from 6339f5f64899ddc8158072a7354703eb71ef2e49 (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/57c57c59cd6ce43a4df21a9309cdbb7cd5e1…
commit 57c57c59cd6ce43a4df21a9309cdbb7cd5e1bf16
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Tue Dec 18 19:20:58 2012 +0100
doc: backends: Update X11 API.
diff --git a/doc/backends.txt b/doc/backends.txt
index d760daf..5ee7e78 100644
--- a/doc/backends.txt
+++ b/doc/backends.txt
@@ -81,16 +81,27 @@ pixel type to match given surface).
For example usage see 'SDL' glue link:example_SDL_glue.html[example].
-X server
+X Server
~~~~~~~~
[source,c]
-------------------------------------------------------------------------------
+#include <GP.h>
+/* or */
+#include <backends/GP_X11.h>
+
enum GP_BackendX11Flags {
- /*
- * When set, w and h is ignored and root window is used
- */
- GP_X11_USE_ROOT_WIN = 0x01,
+ /* When set, w and h is ignored and root window is used */
+ GP_X11_USE_ROOT_WIN = 0x01,
+
+ /* Create new borderless window above the root window */
+ GP_X11_CREATE_ROOT_WIN = 0x02,
+
+ /* Start fullscreen */
+ GP_X11_FULLSCREEN = 0x04,
+
+ /* Do not use MIT SHM even if available */
+ GP_X11_DISABLE_SHM = 0x08,
};
GP_Backend *GP_BackendX11Init(const char *display, int x, int y,
@@ -106,8 +117,33 @@ time).
This backend feeds key events into global input queue.
-Note this is experimental version of X11 backend and will be changed to support
-more windows at a time.
+TODO: X11 backend will be changed to support more windows at a time.
+
+[source,c]
+-------------------------------------------------------------------------------
+#include <GP.h>
+/* or */
+#include <backends/GP_X11.h>
+
+/*
+ * Returns non-zero if backend is X11 backend
+ */
+int GP_BackendIsX11(GP_Backend *self);
+
+/*
+ * Changes full screen mode.
+ *
+ * 0 = off
+ * 1 = on
+ * 2 = toggle
+ */
+void GP_BackendX11RequestFullscreen(GP_Backend *self, int mode);
+-------------------------------------------------------------------------------
+
+The 'GP_BackendIsX11' functions allows us to detect if we are running using
+X11 backend.
+
+The 'GP_BackendX11RequestFullscreen' can toggle fullscreen mode at runtime.
Overall init function
~~~~~~~~~~~~~~~~~~~~~
http://repo.or.cz/w/gfxprim.git/commit/78c4f27c1460b40d07c59ab79a5050601756…
commit 78c4f27c1460b40d07c59ab79a5050601756cf40
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Tue Dec 18 19:11:04 2012 +0100
doc: pixels: Add basic docs for pixel.
diff --git a/doc/Makefile b/doc/Makefile
index cc981fb..eef29cd 100644
--- a/doc/Makefile
+++ b/doc/Makefile
@@ -1,7 +1,7 @@
SOURCES=general.txt context.txt loaders.txt filters.txt basic_types.txt drawing_api.txt backends.txt gamma.txt grabbers.txt environment_variables.txt debug.txt core.txt api.txt input.txt - gen.txt
+ gen.txt pixels.txt
EXAMPLE_SOURCES=$(wildcard example_*.txt)
diff --git a/doc/api.txt b/doc/api.txt
index cee4d1a..69d460a 100644
--- a/doc/api.txt
+++ b/doc/api.txt
@@ -11,6 +11,10 @@ Cyril Hrubis <metan(a)ucw.cz>
+
Describes functions and macros in library core.
+
+. link:pixels.html[Pixel Types]
+ +
+ Describes pixel types.
+ +
. link:debug.html[Debug Messages]
+
Interface to debug layer.
diff --git a/doc/pixels.txt b/doc/pixels.txt
new file mode 100644
index 0000000..b226453
--- /dev/null
+++ b/doc/pixels.txt
@@ -0,0 +1,87 @@
+Pixel Description
+-----------------
+
+This pages describes library core functions for handling pixels.
+
+Pixel Type
+~~~~~~~~~~
+
+Pixels are described by a pixel type, which is enumeration type. The enum is
+defined at the generated 'GP_Pixel.gen.h' header and must contain at least
+following members:
+
+[source,c]
+-------------------------------------------------------------------------------
+#include <GP.h>
+/* or */
+#include <core/GP_Pixel.h>
+
+typedef enum GP_PixelType {
+ GP_PIXEL_UNKNOWN,
+ GP_PIXEL_xRGB8888,
+ GP_PIXEL_RGBA8888,
+ GP_PIXEL_RGB888,
+ GP_PIXEL_BGR888,
+ GP_PIXEL_G1,
+ GP_PIXEL_G2,
+ GP_PIXEL_G4,
+ GP_PIXEL_G8,
+ GP_PIXEL_MAX,
+} GP_PixelType;
+
+-------------------------------------------------------------------------------
+
+Each pixel type has accompanying record in global array of pixel types
+declared as follows:
+
+[source,c]
+-------------------------------------------------------------------------------
+#include <GP.h>
+/* or */
+#include <core/GP_Pixel.h>
+
+typedef struct {
+ char name[8]; /* Channel name */
+ uint8_t offset; /* Offset in bits */
+ uint8_t size; /* Bit-size */
+} GP_PixelTypeChannel;
+
+typedef struct {
+ GP_PixelType type; /* Number of the type */
+ const char name[16]; /* Name */
+ uint8_t size; /* Size in bits */
+ GP_BIT_ENDIAN bit_endian; /* Order of pixels in a byte */
+ uint8_t numchannels; /* Number of channels */
+ /* String describing the bit-representaton (as in "RRRRRGGGGGGBBBBB")*/
+ const char bitmap[GP_PIXEL_BITS + 1];
+ /* Individual channels */
+ const GP_PixelTypeChannel channels[GP_PIXELTYPE_MAX_CHANNELS];
+} GP_PixelTypeDescription;
+
+extern const GP_PixelTypeDescription const GP_PixelTypes[];
+
+const char *GP_PixelTypeName(GP_PixelType type);
+
+uint32_t GP_PixelSize(GP_PixelType type);
+-------------------------------------------------------------------------------
+
+There are also pixel matching functions that returns pixel type given RGB
+channel masks or sizes and offsets:
+
+[source,c]
+-------------------------------------------------------------------------------
+#include <GP.h>
+/* or */
+#include <core/GP_Pixel.h>
+
+GP_PixelType GP_PixelRGBMatch(GP_Pixel rmask, GP_Pixel gmask,
+ GP_Pixel bmask, GP_Pixel amask,
+ uint8_t bits_per_pixel);
+
+GP_PixelType GP_PixelRGBLookup(uint32_t rsize, uint32_t roff,
+ uint32_t gsize, uint32_t goff,
+ uint32_t bsize, uint32_t boff,
+ uint32_t asize, uint32_t aoff,
+ uint8_t bits_per_pixel);
+-------------------------------------------------------------------------------
+
-----------------------------------------------------------------------
Summary of changes:
doc/Makefile | 2 +-
doc/api.txt | 4 ++
doc/backends.txt | 50 ++++++++++++++++++++++++++----
doc/pixels.txt | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 135 insertions(+), 8 deletions(-)
create mode 100644 doc/pixels.txt
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos(a)gmail.com
if you want to unsubscribe, or site admin admin(a)repo.or.cz if you receive
no reply.
--
gfxprim.git ("A simple 2D graphics library with emphasis on correctness and well-defined operation.")
1
0
[repo.or.cz] gfxprim.git branch master updated: 6339f5f64899ddc8158072a7354703eb71ef2e49
by metan 18 Dec '12
by metan 18 Dec '12
18 Dec '12
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 6339f5f64899ddc8158072a7354703eb71ef2e49 (commit)
from 15959b401d7f06790ed593ba0515b9502fce9502 (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/6339f5f64899ddc8158072a7354703eb71ef…
commit 6339f5f64899ddc8158072a7354703eb71ef2e49
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Tue Dec 18 18:42:47 2012 +0100
doc: input: further fixes.
diff --git a/doc/input.txt b/doc/input.txt
index cdb7cc9..35ff473 100644
--- a/doc/input.txt
+++ b/doc/input.txt
@@ -53,7 +53,7 @@ typedef struct GP_Event {
} GP_Event;
-------------------------------------------------------------------------------
-The GP_Event structure is basic block that describes input event (i.e. key was
+The 'GP_Event' structure describes an input event (i.e. key was
pressed/released, mouse was moved, window was resized by user).
[source,c]
@@ -70,9 +70,9 @@ enum GP_EventType {
The event 'type' determines highlevel nature of the event.
* Key events covers keyboard button presses, mouse buttons, etc.
-* Relative events covers mostly mouse coordinates
+* Relative events covers mouse coordinates, mouse wheel, etc.
* Absolute events covers touchscreens and tablets
-* System events are used mostly for propagating window close and window
+* System events are used for propagating window close and window
resize events
* Values greater than 'GP_EV_MAX' are free for user events
@@ -137,16 +137,16 @@ struct GP_EventSys {
};
-------------------------------------------------------------------------------
-The event value is a union that could hold different information. The right
-format of the data is known from the 'type' and 'code'. For some types of the
-events it's not used at all.
+The event 'value' is a union that could hold different information. The right
+format of the data is known from the 'type' and 'code'. Some types of the
+events has no value at all.
* The relative coordinates are used for 'GP_EV_REL_POS' and absolute coordinates
for 'GP_EV_ABS_POS'.
* The key event value is used for keypresses, additionally it holds the key
value mapped to ASCII if conversion is applicable otherwise it's set to
- zero. You should consult the header 'input/GP_Event.h' for comprehensive
+ zero. You should consult the header 'input/GP_Event.h' for the comprehensive
list of key values.
* And finally the system event is used with 'GP_EV_SYS_RESIZE' and informs you
@@ -199,7 +199,7 @@ by ev pointer.
void GP_EventDump(struct GP_Event *ev);
-------------------------------------------------------------------------------
-Dumps event in human-readable format into the 'stdout'.
+The 'GP_EventDump' dumps event in human-readable format into the 'stdout'.
[source,c]
-------------------------------------------------------------------------------
@@ -215,8 +215,6 @@ void GP_EventSetScreenCursor(uint32_t x, uint32_t y);
Sets screen size and pointer position, which is needed for calculating the
'cursor_x' and 'cursor_y' coordinates.
-void GP_EventPushRel(int32_t rx, int32_t ry, struct timeval *time);
-
[source,c]
-------------------------------------------------------------------------------
#include <GP.h>
@@ -224,6 +222,12 @@ void GP_EventPushRel(int32_t rx, int32_t ry, struct timeval *time);
#include <input/GP_Event.h>
/*
+ * Pushes relative event.
+ */
+void GP_EventPushRel(int32_t rx, int32_t ry, struct timeval *time);
+
+
+/*
* Produces relative event that moves to the point x, y
*/
void GP_EventPushRelTo(uint32_t x, uint32_t y, struct timeval *time);
-----------------------------------------------------------------------
Summary of changes:
doc/input.txt | 24 ++++++++++++++----------
1 files changed, 14 insertions(+), 10 deletions(-)
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos(a)gmail.com
if you want to unsubscribe, or site admin admin(a)repo.or.cz if you receive
no reply.
--
gfxprim.git ("A simple 2D graphics library with emphasis on correctness and well-defined operation.")
1
0
[repo.or.cz] gfxprim.git branch master updated: 15959b401d7f06790ed593ba0515b9502fce9502
by metan 18 Dec '12
by metan 18 Dec '12
18 Dec '12
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 15959b401d7f06790ed593ba0515b9502fce9502 (commit)
from 4439632f9d4310733582659f9463f979de583b4a (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/15959b401d7f06790ed593ba0515b9502fce…
commit 15959b401d7f06790ed593ba0515b9502fce9502
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Tue Dec 18 18:33:36 2012 +0100
doc: input: Clarify wording in few cases.
diff --git a/doc/input.txt b/doc/input.txt
index 6a85ebf..cdb7cc9 100644
--- a/doc/input.txt
+++ b/doc/input.txt
@@ -11,10 +11,11 @@ is created only together with graphics driver, this is the case for example
for X Window backends or SDL backends.
The basic structure is roughly modeled after Linux kernel input API. The main
-difference is that events that belongs together are delivered together. For
-example mouse coordinates are bundled in one event.
+difference is that events that belongs together are delivered together (the
+kernel input API sends one event for each value i.e. x or y coordinate and has
+sync event that finalizes the changes in the values).
-For example usage see backend link:example_input.html[example].
+For example usage see input events link:example_input.html[example].
Event Structure Description
~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -156,12 +157,12 @@ The 'dev_id' is not used at the moment and may be removed.
The timeval structure 'time' holds time when the event was created (or
received by GFXprim input driver).
-The 'cursor_x' and 'cursor_y' holds pointer coodinates merged from all input
-sources.
+The 'cursor_x' and 'cursor_y' holds current pointer coodinates. (All relative
+and absolute events are mixed together to compute current cursor position.)
The 'key_pressed' is bitflag array of currently pressed keys which is useful
-for using keys as modificators. The array holds most of the standard keyboard
-keys and mouse buttons.
+for using keys as modificators. The array always holds state of the standard
+keyboard keys and mouse buttons.
Event API
~~~~~~~~~
-----------------------------------------------------------------------
Summary of changes:
doc/input.txt | 15 ++++++++-------
1 files changed, 8 insertions(+), 7 deletions(-)
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos(a)gmail.com
if you want to unsubscribe, or site admin admin(a)repo.or.cz if you receive
no reply.
--
gfxprim.git ("A simple 2D graphics library with emphasis on correctness and well-defined operation.")
1
0
[repo.or.cz] gfxprim.git branch master updated: 4439632f9d4310733582659f9463f979de583b4a
by metan 18 Dec '12
by metan 18 Dec '12
18 Dec '12
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 4439632f9d4310733582659f9463f979de583b4a (commit)
via 0aced3a1a7a5e7031959a0ef904974ed1a06c4a4 (commit)
from 5f214b37219110e2e9051b3bfffbbd65498002b7 (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/4439632f9d4310733582659f9463f979de58…
commit 4439632f9d4310733582659f9463f979de583b4a
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Tue Dec 18 17:05:08 2012 +0100
doc: Add basic docs for templating engine.
diff --git a/doc/Makefile b/doc/Makefile
index f72b8c3..cc981fb 100644
--- a/doc/Makefile
+++ b/doc/Makefile
@@ -1,6 +1,7 @@
SOURCES=general.txt context.txt loaders.txt filters.txt basic_types.txt drawing_api.txt backends.txt gamma.txt grabbers.txt - environment_variables.txt debug.txt core.txt api.txt input.txt
+ environment_variables.txt debug.txt core.txt api.txt input.txt + gen.txt
EXAMPLE_SOURCES=$(wildcard example_*.txt)
diff --git a/doc/gen.txt b/doc/gen.txt
new file mode 100644
index 0000000..28b438d
--- /dev/null
+++ b/doc/gen.txt
@@ -0,0 +1,103 @@
+Templating Engine
+-----------------
+
+The GFXprim uses python templating engine to generate code for different pixel
+types. This is documentation to the engine internals.
+
+GFXprim Config
+~~~~~~~~~~~~~~
+
+The configuration which describes pixel layout could be found in root GFXprim
+directory under name 'gfxprim_config.py' which is used to create objects
+described below.
+
+Main Objects
+~~~~~~~~~~~~
+
+Pixel Size
+^^^^^^^^^^
+
+[source,python]
+-------------------------------------------------------------------------------
+class PixelSize(object):
+ self.size = size
+
+ self.suffix = suffix
+
+ self.bit_endian = bit_endian
+
+ def needs_bit_endian(self):
+ ...
+
+-------------------------------------------------------------------------------
+
+The Pixel Size object represents pixel as a continous block of data.
+
+The 'size' is size in bits and is sometimes called bpp which stands for bits
+per pixel. It also contains suffix that is a string used as a suffix for
+functions that manipulates with this pixel size.
+
+The 'bit_endian' determines direction of bits in bitmaps and graymaps (i.e.
+most significant bit left or right). It can be either 'BE' or 'LE'.
+
+Note that different pixels can share the same pixel size as for certain types
+of operations the function doesn't depend on actual arrangements of the color
+channels in pixel (i.e. Get/Put Pixel, Rotate buffer 90 degrees, etc...).
+
+TODO: Which bit endian is which?
+
+TODO: Rename size to bpp?
+
+Pixel Type
+^^^^^^^^^^
+
+[source,python]
+-------------------------------------------------------------------------------
+class PixelType(object):
+ self.name = name
+ self.chanslist = chanslist
+ self.chans = dict() # { chan_name: (offset, size) }
+ self.pixelsize = pixelsize # bits per pixel
+
+ def is_palette(self):
+ ...
+
+ def is_unknown(self):
+ ...
+
+ def is_rgb(self):
+ ...
+
+ def is_gray(self):
+ ...
+
+ def is_alpha(self):
+ ...
+
+-------------------------------------------------------------------------------
+
+This object represents pixel type which describes the sizes and arrangements of
+channels in a pixel. Note that it carries an instance of pixel size described
+above.
+
+The chanslist is a list of triplets describing individual channels as
+[('chan_name', 'bit_offset', 'bit_size') ] where 'chan_name' is usually one of
+R, G, B, V (value, used for grayscale), A (opacity).
+
+Templating language
+~~~~~~~~~~~~~~~~~~~
+
+GFXprim uses http://jinja.pocoo.org/[Jinja] templating engine with a few
+objects added into the environment.
+
+Added are python buildins:
+
+* 'int'
+* 'float'
+* 'round'
+* 'len'
+
+And most importantly objects generated from the configuration files:
+
+* 'pixelsizes' list of all pixel size objects
+* 'pixeltypes' list of all pixel type objects
http://repo.or.cz/w/gfxprim.git/commit/0aced3a1a7a5e7031959a0ef904974ed1a06…
commit 0aced3a1a7a5e7031959a0ef904974ed1a06c4a4
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Tue Dec 18 15:44:52 2012 +0100
backends: x11: Add fullscreen and disable SHM opts
diff --git a/demos/spiv/spiv.c b/demos/spiv/spiv.c
index 79de755..7c3dd20 100644
--- a/demos/spiv/spiv.c
+++ b/demos/spiv/spiv.c
@@ -339,6 +339,15 @@ GP_Context *load_resized_image(struct loader_params *params, GP_Size w, GP_Size
// GP_FilterEdgeSharpening(img, img, 0.2, NULL);
cpu_timer_stop(&timer);
+/*
+ if (params->rat > 1.5) {
+ cpu_timer_start(&timer, "Sharpening");
+ callback.priv = "Sharpening";
+ GP_FilterEdgeSharpening(i1, i1, 0.1, &callback);
+ cpu_timer_stop(&timer);
+ }
+*/
+
/* Free low passed context if needed */
GP_ContextFree(res);
@@ -764,6 +773,10 @@ int main(int argc, char *argv[])
continue;
switch (ev.val.key.key) {
+ case GP_KEY_F:
+ if (GP_BackendIsX11(backend))
+ GP_BackendX11RequestFullscreen(backend, 2);
+ break;
case GP_KEY_I:
params.show_info = !params.show_info;
diff --git a/include/backends/GP_X11.h b/include/backends/GP_X11.h
index 6d10928..a196a31 100644
--- a/include/backends/GP_X11.h
+++ b/include/backends/GP_X11.h
@@ -26,14 +26,17 @@
#include "GP_Backend.h"
enum GP_BackendX11Flags {
- /*
- * When set, w and h is ignored and root window is used
- */
+ /* When set, w and h is ignored and root window is used */
GP_X11_USE_ROOT_WIN = 0x01,
- /*
- * Create new borderless window above the root window.
- */
+
+ /* Create new borderless window above the root window */
GP_X11_CREATE_ROOT_WIN = 0x02,
+
+ /* Start fullscreen */
+ GP_X11_FULLSCREEN = 0x04,
+
+ /* Do not use MIT SHM even if available */
+ GP_X11_DISABLE_SHM = 0x08,
};
@@ -52,4 +55,18 @@ GP_Backend *GP_BackendX11Init(const char *display, int x, int y,
const char *caption,
enum GP_BackendX11Flags flags);
+/*
+ * Returns non-zero if backend is X11 backend
+ */
+int GP_BackendIsX11(GP_Backend *self);
+
+/*
+ * Changes full screen mode.
+ *
+ * 0 = off
+ * 1 = on
+ * 2 = toggle
+ */
+void GP_BackendX11RequestFullscreen(GP_Backend *self, int mode);
+
#endif /* BACKENDS_GP_X11_H */
diff --git a/libs/backends/GP_BackendInit.c b/libs/backends/GP_BackendInit.c
index bef0dba..e9a809c 100644
--- a/libs/backends/GP_BackendInit.c
+++ b/libs/backends/GP_BackendInit.c
@@ -138,7 +138,10 @@ static void backend_x11_help(FILE *help, const char *err)
"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");
+ " root window (w and h, if set, are ignored)n"
+ "DISABLE_SHM - disable MIT SHM even if availablen"
+ "FS - start fullscreenn");
+
}
static int x11_params_to_flags(const char *param, GP_Size *w, GP_Size *h,
@@ -154,6 +157,16 @@ static int x11_params_to_flags(const char *param, GP_Size *w, GP_Size *h,
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"
*/
diff --git a/libs/backends/GP_X11.c b/libs/backends/GP_X11.c
index e543d48..aaa363f 100644
--- a/libs/backends/GP_X11.c
+++ b/libs/backends/GP_X11.c
@@ -727,6 +727,57 @@ static void create_window(struct x11_priv *x11, int x, int y,
XMapWindow(x11->dpy, x11->win);
}
+#ifndef _NET_WM_STATE_ADD
+# define _NET_WM_STATE_ADD 1
+#endif /* _NET_WM_STATE_ADD */
+
+#ifndef _NET_WM_STATE_REMOVE
+# define _NET_WM_STATE_REMOVE 0
+#endif /* _NET_WM_STATE_REMOVE */
+
+/* Send NETWM message, most modern Window Managers should understand */
+static void request_fullscreen(struct GP_Backend *self, int mode)
+{
+ struct x11_priv *x11 = GP_BACKEND_PRIV(self);
+
+ if (mode < 0 || mode > 2) {
+ GP_WARN("Invalid fullscreen mode = %u", mode);
+ return;
+ }
+
+ GP_DEBUG(2, "Requesting fullscreen mode = %u", mode);
+
+ Atom wm_state, fullscreen;
+
+ wm_state = XInternAtom(x11->dpy, "_NET_WM_STATE", True);
+ fullscreen = XInternAtom(x11->dpy, "_NET_WM_STATE_FULLSCREEN", True);
+
+ if (wm_state == None || fullscreen == None) {
+ GP_WARN("Failed to create _NET_WM_* atoms");
+ return;
+ }
+
+ XEvent ev;
+
+ memset(&ev, 0, sizeof(ev));
+
+ ev.type = ClientMessage;
+ ev.xclient.window = x11->win;
+ ev.xclient.message_type = wm_state;
+ ev.xclient.format = 32;
+ ev.xclient.data.l[0] = mode;
+ ev.xclient.data.l[1] = fullscreen;
+ ev.xclient.data.l[2] = 0;
+ ev.xclient.data.l[3] = 1;
+
+ if (!XSendEvent(x11->dpy, XDefaultRootWindow(x11->dpy), False, SubstructureNotifyMask, &ev)) {
+ GP_WARN("Failed to send _NET_WM_STATE_FULLSCREEN event");
+ return;
+ }
+
+ XFlush(x11->dpy);
+}
+
GP_Backend *GP_BackendX11Init(const char *display, int x, int y,
unsigned int w, unsigned int h,
const char *caption,
@@ -771,10 +822,13 @@ GP_Backend *GP_BackendX11Init(const char *display, int x, int y,
GP_DEBUG(1, "Failed to create window");
goto err1;
}
-
+
+ if (flags & GP_X11_FULLSCREEN)
+ request_fullscreen(backend, 1);
+
backend->context = NULL;
- if (create_shm_ximage(backend, w, h))
+ if ((flags & GP_X11_DISABLE_SHM) || create_shm_ximage(backend, w, h))
if (create_ximage(backend, w, h))
goto err1;
@@ -800,6 +854,11 @@ err0:
return NULL;
}
+void GP_BackendX11RequestFullscreen(GP_Backend *self, int mode)
+{
+ return request_fullscreen(self, mode);
+}
+
#else
#include "GP_Backend.h"
@@ -814,4 +873,11 @@ GP_Backend *GP_BackendX11Init(const char *GP_UNUSED(display),
return NULL;
}
+void GP_BackendX11RequestFullscreen(GP_Backend *GP_UNUSED(self), int mode);
+
#endif /* HAVE_LIBX11 */
+
+int GP_BackendIsX11(GP_Backend *self)
+{
+ return !strcmp(self->name, "X11");
+}
-----------------------------------------------------------------------
Summary of changes:
demos/spiv/spiv.c | 13 +++++
doc/Makefile | 3 +-
doc/gen.txt | 103 ++++++++++++++++++++++++++++++++++++++++
include/backends/GP_X11.h | 29 +++++++++--
libs/backends/GP_BackendInit.c | 15 +++++-
libs/backends/GP_X11.c | 70 ++++++++++++++++++++++++++-
6 files changed, 223 insertions(+), 10 deletions(-)
create mode 100644 doc/gen.txt
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos(a)gmail.com
if you want to unsubscribe, or site admin admin(a)repo.or.cz if you receive
no reply.
--
gfxprim.git ("A simple 2D graphics library with emphasis on correctness and well-defined operation.")
1
0
[repo.or.cz] gfxprim.git branch master updated: 5f214b37219110e2e9051b3bfffbbd65498002b7
by gavento 18 Dec '12
by gavento 18 Dec '12
18 Dec '12
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 5f214b37219110e2e9051b3bfffbbd65498002b7 (commit)
from 910d31f9711c5e518189c5e5f47761125ef06207 (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/5f214b37219110e2e9051b3bfffbbd654980…
commit 5f214b37219110e2e9051b3bfffbbd65498002b7
Author: Tomas Gavenciak <gavento(a)ucw.cz>
Date: Tue Dec 18 14:33:22 2012 +0100
Grammar fix
diff --git a/doc/input.txt b/doc/input.txt
index 44da370..6a85ebf 100644
--- a/doc/input.txt
+++ b/doc/input.txt
@@ -38,7 +38,7 @@ typedef struct GP_Event {
struct timeval time;
/*
- * Cursor possition, possition on screen accumulated
+ * Cursor position, possition on screen accumulated
* from all pointer devices
*/
uint32_t cursor_x;
diff --git a/include/input/GP_Event.h b/include/input/GP_Event.h
index de5d93e..162a5d2 100644
--- a/include/input/GP_Event.h
+++ b/include/input/GP_Event.h
@@ -271,7 +271,7 @@ typedef struct GP_Event {
struct timeval time;
/*
- * Cursor possition, possition on screen accumulated
+ * Cursor position, position on screen accumulated
* from all pointer devices
*/
uint32_t cursor_x;
@@ -290,7 +290,7 @@ typedef struct GP_Event {
void GP_EventSetScreenSize(uint32_t w, uint32_t h);
/*
- * Sets global cursor possition, doesn't generate event.
+ * Sets global cursor position, doesn't generate an event.
*
* Use for initial cursor placement.
*/
diff --git a/include/loaders/GP_JPG.h b/include/loaders/GP_JPG.h
index 5906b11..5ee57ce 100644
--- a/include/loaders/GP_JPG.h
+++ b/include/loaders/GP_JPG.h
@@ -40,7 +40,7 @@
int GP_OpenJPG(const char *src_path, FILE **f);
/*
- * Reads JPG from an open FILE. Expects the file possition set after the eight
+ * Reads JPG from an open FILE. Expects the file position set after the eight
* bytes JPG signature.
*/
GP_Context *GP_ReadJPG(FILE *f, GP_ProgressCallback *callback);
diff --git a/include/loaders/GP_PNG.h b/include/loaders/GP_PNG.h
index 4b6e3bb..cbb4b70 100644
--- a/include/loaders/GP_PNG.h
+++ b/include/loaders/GP_PNG.h
@@ -47,13 +47,13 @@
/*
* Opens up file and checks signature. Upon successful return (zero is
- * returned) the file possition would be set to eight bytes (exactly after the
+ * returned) the file position would be set to eight bytes (exactly after the
* PNG signature).
*/
int GP_OpenPNG(const char *src_path, FILE **f);
/*
- * Reads PNG from an open FILE. Expects the file possition set after the eight
+ * Reads PNG from an open FILE. Expects the file position set after the eight
* bytes PNG signature.
*
* Upon succesfull return pointer to newly allocated context is returned.
diff --git a/libs/input/GP_Event.c b/libs/input/GP_Event.c
index cb66c4f..efd82c9 100644
--- a/libs/input/GP_Event.c
+++ b/libs/input/GP_Event.c
@@ -29,7 +29,7 @@
#include "GP_Event.h"
-/* Screen size for clipping the cursor possition */
+/* Screen size for clipping the cursor position */
static uint32_t screen_w = 0, screen_h = 0;
/* Event queue */
diff --git a/libs/loaders/GP_PNM.h b/libs/loaders/GP_PNM.h
index af59319..2ce48a3 100644
--- a/libs/loaders/GP_PNM.h
+++ b/libs/loaders/GP_PNM.h
@@ -32,7 +32,7 @@
#include <stdint.h>
/*
- * Loads image header, returns pointer to FILE* (with file possition pointing
+ * Loads image header, returns pointer to FILE* (with file position pointing
* to the start of the data stream) on success, fills image metadata into
* arguments.
*/
-----------------------------------------------------------------------
Summary of changes:
doc/input.txt | 2 +-
include/input/GP_Event.h | 4 ++--
include/loaders/GP_JPG.h | 2 +-
include/loaders/GP_PNG.h | 4 ++--
libs/input/GP_Event.c | 2 +-
libs/loaders/GP_PNM.h | 2 +-
6 files changed, 8 insertions(+), 8 deletions(-)
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos(a)gmail.com
if you want to unsubscribe, or site admin admin(a)repo.or.cz if you receive
no reply.
--
gfxprim.git ("A simple 2D graphics library with emphasis on correctness and well-defined operation.")
1
0
[repo.or.cz] gfxprim.git branch master updated: 910d31f9711c5e518189c5e5f47761125ef06207
by metan 18 Dec '12
by metan 18 Dec '12
18 Dec '12
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 910d31f9711c5e518189c5e5f47761125ef06207 (commit)
via 6812b812594d07e3a6b7543400e710424ce23597 (commit)
from 89909d1774eb1b3ac35e2e643401bab3b79c9dc2 (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/910d31f9711c5e518189c5e5f47761125ef0…
commit 910d31f9711c5e518189c5e5f47761125ef06207
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Tue Dec 18 13:55:12 2012 +0100
doc: input: Add input events docs + code cleanup.
diff --git a/build/syms/Event_symbols.txt b/build/syms/Event_symbols.txt
index 9f80506..6dc7e12 100644
--- a/build/syms/Event_symbols.txt
+++ b/build/syms/Event_symbols.txt
@@ -9,7 +9,7 @@ GP_EventDump
GP_EventPushResize
GP_EventPushRelTo
GP_EventSetScreenCursor
-GP_EventQueued
+GP_EventsQueued
GP_InputDriverLinuxRead
GP_InputDriverSDLEventPut
diff --git a/demos/c_simple/Makefile b/demos/c_simple/Makefile
index e64dda7..cce46d8 100644
--- a/demos/c_simple/Makefile
+++ b/demos/c_simple/Makefile
@@ -16,9 +16,9 @@ LDLIBS+=-lrt `$(TOPDIR)/gfxprim-config --libs --libs-backends`
APPS=backend_example loaders_example loaders filters_symmetry gfx_koch virtual_backend_example meta_data meta_data_dump tmp_file showimage- v4l2_show v4l2_grab convolution weighted_median shapetest koch input- fileview linetest randomshapetest fonttest loaders_register blittest- textaligntest
+ v4l2_show v4l2_grab convolution weighted_median shapetest koch + input_example fileview linetest randomshapetest fonttest+ loaders_register blittest textaligntest
ifeq ($(HAVE_LIBSDL),yes)
APPS+=SDL_glue
diff --git a/demos/c_simple/input.c b/demos/c_simple/input_example.c
similarity index 98%
rename from demos/c_simple/input.c
rename to demos/c_simple/input_example.c
index 6a083e2..38cc1e3 100644
--- a/demos/c_simple/input.c
+++ b/demos/c_simple/input_example.c
@@ -56,7 +56,7 @@ static void event_loop(void)
for (;;) {
GP_BackendWait(backend);
- while (GP_EventQueued()) {
+ while (GP_EventsQueued()) {
GP_Event ev;
GP_EventGet(&ev);
@@ -128,8 +128,6 @@ int main(int argc, char *argv[])
}
}
-// GP_SetDebugLevel(10);
-
backend = GP_BackendInit(backend_opts, "Input Test", stderr);
if (backend == NULL) {
diff --git a/doc/Makefile b/doc/Makefile
index 4160ae0..f72b8c3 100644
--- a/doc/Makefile
+++ b/doc/Makefile
@@ -1,6 +1,6 @@
SOURCES=general.txt context.txt loaders.txt filters.txt basic_types.txt drawing_api.txt backends.txt gamma.txt grabbers.txt - environment_variables.txt debug.txt core.txt api.txt
+ environment_variables.txt debug.txt core.txt api.txt input.txt
EXAMPLE_SOURCES=$(wildcard example_*.txt)
diff --git a/doc/api.txt b/doc/api.txt
index aff68ea..cee4d1a 100644
--- a/doc/api.txt
+++ b/doc/api.txt
@@ -49,6 +49,11 @@ Cyril Hrubis <metan(a)ucw.cz>
+
Backends API for drawing on the screen or into a window.
+
+. link:input.html[Input Events]
+ +
+ Input event handling such as key presses, mouse coordinates, touchscreens
+ and window manager events such as window close or window resize.
+ +
. link:grabbers.html[Grabbers]
+
Video grabbers interface such as V4L2.
diff --git a/doc/backends.txt b/doc/backends.txt
index 86d5d51..d760daf 100644
--- a/doc/backends.txt
+++ b/doc/backends.txt
@@ -274,3 +274,20 @@ returned. If backend size already matches w and h, nothing is done.
Note that backend->context pointer may change upon calling this function and
at least backend->context->pixels pointer will change.
+[source,c]
+-------------------------------------------------------------------------------
+#include <backends/GP_Backend.h>
+/* or */
+#include <GP.h>
+
+int GP_BackendResizeAck(GP_Backend *self);
+-------------------------------------------------------------------------------
+
+If backend is resizeable by user interaction (for example X Window) you will
+get resize event for each change of window size, however the backend context
+will not be resized untill you call this function. This is usefull in
+multithreaded application where one threads waits for events and others draws
+into the buffer so you can stop the drawing threads before the backend context
+size change.
+
+See input link:input.html[input events] for more information.
diff --git a/doc/example_input.txt b/doc/example_input.txt
new file mode 100644
index 0000000..15b7233
--- /dev/null
+++ b/doc/example_input.txt
@@ -0,0 +1,7 @@
+Input Events Example
+--------------------
+
+[source,c]
+------------------------------------------------------------------
+include::../demos/c_simple/input_example.c[]
+------------------------------------------------------------------
diff --git a/doc/input.txt b/doc/input.txt
new file mode 100644
index 0000000..44da370
--- /dev/null
+++ b/doc/input.txt
@@ -0,0 +1,271 @@
+Input Events
+------------
+
+Input events are somehow tied to the link:backends.html[backends]. Possibly in
+contrast with other libraries there is not always 1:1 correspondence between
+input driver and backend graphics driver. That means that you can, for
+example, use linux input events together with X Window without any problems.
+You can even write application that doesn't draw any graphics at all and still
+use some of the input drivers. There are, of course, cases where input driver
+is created only together with graphics driver, this is the case for example
+for X Window backends or SDL backends.
+
+The basic structure is roughly modeled after Linux kernel input API. The main
+difference is that events that belongs together are delivered together. For
+example mouse coordinates are bundled in one event.
+
+For example usage see backend link:example_input.html[example].
+
+Event Structure Description
+~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+[source,c]
+-------------------------------------------------------------------------------
+#include <GP.h>
+/* or */
+#include <input/GP_Event.h>
+
+typedef struct GP_Event {
+ /* event */
+ uint16_t type;
+ uint32_t code;
+ union GP_EventValue val;
+
+ /* input device id */
+ uint32_t dev_id;
+
+ /* event timestamp */
+ struct timeval time;
+
+ /*
+ * Cursor possition, possition on screen accumulated
+ * from all pointer devices
+ */
+ uint32_t cursor_x;
+ uint32_t cursor_y;
+
+ /*
+ * Bitmap of pressed keys including mouse buttons
+ * accumulated for all input devices.
+ */
+ uint8_t keys_pressed[GP_EVENT_KEYMAP_BYTES];
+} GP_Event;
+-------------------------------------------------------------------------------
+
+The GP_Event structure is basic block that describes input event (i.e. key was
+pressed/released, mouse was moved, window was resized by user).
+
+[source,c]
+-------------------------------------------------------------------------------
+enum GP_EventType {
+ GP_EV_KEY, /* key/button press event */
+ GP_EV_REL, /* relative event */
+ GP_EV_ABS, /* absolute event */
+ GP_EV_SYS, /* system events window close, resize... */
+ GP_EV_MAX = GP_EV_SYS, /* maximum, greater values are free */
+};
+-------------------------------------------------------------------------------
+
+The event 'type' determines highlevel nature of the event.
+
+* Key events covers keyboard button presses, mouse buttons, etc.
+* Relative events covers mostly mouse coordinates
+* Absolute events covers touchscreens and tablets
+* System events are used mostly for propagating window close and window
+ resize events
+* Values greater than 'GP_EV_MAX' are free for user events
+
+[source,c]
+-------------------------------------------------------------------------------
+enum GP_EventKeyCode {
+ GP_EV_KEY_UP,
+ GP_EV_KEY_DOWN,
+ GP_EV_KEY_REPEAT,
+};
+
+enum GP_EventRelCode {
+ GP_EV_REL_POS,
+ GP_EV_REL_WHEEL,
+};
+
+enum GP_EventAbsCode {
+ GP_EV_ABS_POS,
+};
+
+enum GP_EventSysCode {
+ GP_EV_SYS_QUIT,
+ GP_EV_SYS_RESIZE,
+};
+-------------------------------------------------------------------------------
+
+The event 'code' specifies the event nature more closely, it has different
+meaning for each event type. The names are (hopefully) self explanatory.
+
+[source,c]
+-------------------------------------------------------------------------------
+union GP_EventValue {
+ /* generic one integer value */
+ int32_t val;
+ /* key */
+ struct GP_EventKey key;
+ /* position */
+ struct GP_EventPosRel rel;
+ struct GP_EventPosAbs abs;
+ /* system event */
+ struct GP_EventSys sys;
+};
+
+struct GP_EventPosRel {
+ int32_t rx;
+ int32_t ry;
+};
+
+struct GP_EventPosAbs {
+ uint32_t x, x_max; /* the x is between 0 and x_max */
+ uint32_t y, y_max;
+ uint32_t pressure, pressure_max;
+};
+
+struct GP_EventKey {
+ uint32_t key;
+ char ascii;
+};
+
+struct GP_EventSys {
+ uint32_t w, h;
+};
+-------------------------------------------------------------------------------
+
+The event value is a union that could hold different information. The right
+format of the data is known from the 'type' and 'code'. For some types of the
+events it's not used at all.
+
+* The relative coordinates are used for 'GP_EV_REL_POS' and absolute coordinates
+ for 'GP_EV_ABS_POS'.
+
+* The key event value is used for keypresses, additionally it holds the key
+ value mapped to ASCII if conversion is applicable otherwise it's set to
+ zero. You should consult the header 'input/GP_Event.h' for comprehensive
+ list of key values.
+
+* And finally the system event is used with 'GP_EV_SYS_RESIZE' and informs you
+ of the new window size.
+
+The 'dev_id' is not used at the moment and may be removed.
+
+The timeval structure 'time' holds time when the event was created (or
+received by GFXprim input driver).
+
+The 'cursor_x' and 'cursor_y' holds pointer coodinates merged from all input
+sources.
+
+The 'key_pressed' is bitflag array of currently pressed keys which is useful
+for using keys as modificators. The array holds most of the standard keyboard
+keys and mouse buttons.
+
+Event API
+~~~~~~~~~
+
+[source,c]
+-------------------------------------------------------------------------------
+#include <GP.h>
+/* or */
+#include <input/GP_Event.h>
+
+unsigned int GP_EventsQueued(void);
+-------------------------------------------------------------------------------
+
+The 'GP_EventsQueued' returns number of queued events.
+
+[source,c]
+-------------------------------------------------------------------------------
+#include <GP.h>
+/* or */
+#include <input/GP_Event.h>
+
+int GP_EventGet(struct GP_Event *ev);
+-------------------------------------------------------------------------------
+
+The 'GP_EventGet' returns nonzero if event was copied to the structure pointed
+by ev pointer.
+
+[source,c]
+-------------------------------------------------------------------------------
+#include <GP.h>
+/* or */
+#include <input/GP_Event.h>
+
+void GP_EventDump(struct GP_Event *ev);
+-------------------------------------------------------------------------------
+
+Dumps event in human-readable format into the 'stdout'.
+
+[source,c]
+-------------------------------------------------------------------------------
+#include <GP.h>
+/* or */
+#include <input/GP_Event.h>
+
+void GP_EventSetScreenSize(uint32_t w, uint32_t h);
+
+void GP_EventSetScreenCursor(uint32_t x, uint32_t y);
+-------------------------------------------------------------------------------
+
+Sets screen size and pointer position, which is needed for calculating the
+'cursor_x' and 'cursor_y' coordinates.
+
+void GP_EventPushRel(int32_t rx, int32_t ry, struct timeval *time);
+
+[source,c]
+-------------------------------------------------------------------------------
+#include <GP.h>
+/* or */
+#include <input/GP_Event.h>
+
+/*
+ * Produces relative event that moves to the point x, y
+ */
+void GP_EventPushRelTo(uint32_t x, uint32_t y, struct timeval *time);
+
+/*
+ * Inject absolute event.
+ */
+void GP_EventPushAbs(uint32_t x, uint32_t y, uint32_t pressure,
+ uint32_t x_max, uint32_t y_max, uint32_t pressure_max,
+ struct timeval *time);
+
+/*
+ * Inject event that changes key state.
+ */
+void GP_EventPushKey(uint32_t key, uint8_t code, struct timeval *time);
+
+/*
+ * Inject common event.
+ */
+void GP_EventPush(uint16_t type, uint32_t code, int32_t value,
+ struct timeval *time);
+-------------------------------------------------------------------------------
+
+Following functions are used for adding events into the event queue. If
+pointer to the timeval structure is 'NULL' the event 'time' will be filled
+with exact time the event was added to the queue.
+
+[source,c]
+-------------------------------------------------------------------------------
+#include <GP.h>
+/* or */
+#include <input/GP_Event.h>
+
+void GP_EventSetKey(struct GP_Event *ev, uint32_t key)
+
+GP_EventGetKey(struct GP_Event *ev, uint32_t key)
+
+GP_EventResetKey(struct GP_Event *ev, uint32_t key)
+-------------------------------------------------------------------------------
+
+These functions are helpers for setting/getting key pressed bits in the
+'keys_pressed' bit array.
+
+You will mostly need the 'GP_EventGetKey' function to figure out if some of
+the modificator keys (such as Ctrl or Shift) was pressed at the time the event
+was received.
diff --git a/include/input/GP_Event.h b/include/input/GP_Event.h
index 71eef60..de5d93e 100644
--- a/include/input/GP_Event.h
+++ b/include/input/GP_Event.h
@@ -299,7 +299,7 @@ void GP_EventSetScreenCursor(uint32_t x, uint32_t y);
/*
* Returns number of queued events.
*/
-uint32_t GP_EventQueued(void);
+unsigned int GP_EventsQueued(void);
/*
* Dump event into stdout.
diff --git a/libs/input/GP_Event.c b/libs/input/GP_Event.c
index eab6b2e..cb66c4f 100644
--- a/libs/input/GP_Event.c
+++ b/libs/input/GP_Event.c
@@ -89,7 +89,7 @@ void GP_EventSetScreenCursor(uint32_t x, uint32_t y)
cur_state.cursor_y = y;
}
-uint32_t GP_EventQueued(void)
+unsigned int GP_EventsQueued(void)
{
if (queue_first <= queue_last)
return queue_last - queue_first;
http://repo.or.cz/w/gfxprim.git/commit/6812b812594d07e3a6b7543400e710424ce2…
commit 6812b812594d07e3a6b7543400e710424ce23597
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Tue Dec 18 11:49:01 2012 +0100
backends: Add GP_BackendResizeAck().
This is not yet finished but seems
to work fine. More testing is required.
diff --git a/build/syms/Backend_symbols.txt b/build/syms/Backend_symbols.txt
index 7eddbe5..abcd681 100644
--- a/build/syms/Backend_symbols.txt
+++ b/build/syms/Backend_symbols.txt
@@ -7,4 +7,5 @@ GP_BackendSDLInit
GP_ContextFromSurface
GP_BackendResize
+GP_BackendResizeAck
GP_BackendUpdateRectXYXY
diff --git a/demos/spiv/spiv.c b/demos/spiv/spiv.c
index abe7395..79de755 100644
--- a/demos/spiv/spiv.c
+++ b/demos/spiv/spiv.c
@@ -350,24 +350,6 @@ GP_Context *load_resized_image(struct loader_params *params, GP_Size w, GP_Size
return img;
}
-/*
- * This function tries to resize spiv window
- * and if succedes blits the image directly to the screen.
- */
-static int resize_backend_and_blit(struct loader_params *params)
-{
- GP_Context *img = load_image(params, 1);
-
- if (GP_BackendResize(backend, img->w, img->h))
- return 1;
-
- GP_Blit_Raw(img, 0, 0, img->w, img->h, backend->context, 0, 0);
- GP_BackendFlip(backend);
- set_caption(params->img_path, 1);
-
- return 0;
-}
-
static void *image_loader(void *ptr)
{
struct loader_params *params = ptr;
@@ -565,6 +547,23 @@ static void init_caches(struct loader_params *params)
// params->img_orig_cache = NULL;
}
+/*
+ * Ask backend to resize window. Once window is resized we will
+ * get SYS_RESIZE event, see the main event loop.
+ */
+static void resize_backend(struct loader_params *params, float ratio, int shift_flag)
+{
+ GP_Context *img = load_image(params, 1);
+
+ if (!shift_flag)
+ ratio = 1.00 / ratio;
+
+ unsigned int w = img->w * ratio + 0.5;
+ unsigned int h = img->h * ratio + 0.5;
+
+ GP_BackendResize(backend, w, h);
+}
+
static void print_help(void)
{
printf("Usage: spiv [opts] imagesnn");
@@ -601,6 +600,15 @@ static void print_help(void)
printf("Downn");
printf("BckSpc - move to the prev imagen");
printf("n");
+ printf("1 - resize spiv window to the image sizen");
+ printf("2 - resize spiv window to the half of the image sizen");
+ printf("3 - resize spiv window to the third of the image sizen");
+ printf("...n");
+ printf("9 - resize spiv window to the ninth of the image sizen");
+ printf("n");
+ printf("Shift 2 - resize spiv window twice of the image sizen");
+ printf("Shift 3 - resize spiv window three times of the image sizen");
+ printf("...nn");
printf("Some cool options to try:nn");
printf("spiv -e G1 -f imagesn");
@@ -618,6 +626,7 @@ int main(int argc, char *argv[])
const char *backend_opts = "X11";
int sleep_sec = -1;
int opt, debug_level = 0;
+ int shift_flag;
GP_PixelType emul_type = GP_PIXEL_UNKNOWN;
struct loader_params params = {
@@ -734,7 +743,10 @@ int main(int argc, char *argv[])
while (GP_EventGet(&ev)) {
GP_EventDump(&ev);
-
+
+ shift_flag = GP_EventGetKey(&ev, GP_KEY_LEFT_SHIFT) ||
+ GP_EventGetKey(&ev, GP_KEY_RIGHT_SHIFT);
+
switch (ev.type) {
case GP_EV_REL:
switch (ev.code) {
@@ -863,7 +875,31 @@ int main(int argc, char *argv[])
show_image(¶ms, argv[argn]);
break;
case GP_KEY_1:
- resize_backend_and_blit(¶ms);
+ resize_backend(¶ms, 1, shift_flag);
+ break;
+ case GP_KEY_2:
+ resize_backend(¶ms, 2, shift_flag);
+ break;
+ case GP_KEY_3:
+ resize_backend(¶ms, 3, shift_flag);
+ break;
+ case GP_KEY_4:
+ resize_backend(¶ms, 4, shift_flag);
+ break;
+ case GP_KEY_5:
+ resize_backend(¶ms, 5, shift_flag);
+ break;
+ case GP_KEY_6:
+ resize_backend(¶ms, 6, shift_flag);
+ break;
+ case GP_KEY_7:
+ resize_backend(¶ms, 7, shift_flag);
+ break;
+ case GP_KEY_8:
+ resize_backend(¶ms, 8, shift_flag);
+ break;
+ case GP_KEY_9:
+ resize_backend(¶ms, 9, shift_flag);
break;
}
break;
@@ -872,7 +908,7 @@ int main(int argc, char *argv[])
case GP_EV_SYS_RESIZE:
/* stop loader thread before resizing backend buffer */
stop_loader();
- GP_BackendResize(backend, ev.val.sys.w, ev.val.sys.h);
+ GP_BackendResizeAck(backend);
GP_Fill(backend->context, 0);
params.show_progress_once = 1;
show_image(¶ms, NULL);
diff --git a/include/backends/GP_Backend.h b/include/backends/GP_Backend.h
index 64b504d..01bf3c1 100644
--- a/include/backends/GP_Backend.h
+++ b/include/backends/GP_Backend.h
@@ -95,6 +95,13 @@ typedef struct GP_Backend {
const char *caption);
/*
+ * Resize acknowledge callback. This must be called
+ * after you got resize event in order to resize
+ * backend buffers.
+ */
+ int (*ResizeAck)(struct GP_Backend *self);
+
+ /*
* Exits the backend.
*/
void (*Exit)(struct GP_Backend *self);
@@ -207,4 +214,18 @@ static inline int GP_BackendSetCaption(GP_Backend *backend,
*/
int GP_BackendResize(GP_Backend *backend, uint32_t w, uint32_t h);
+
+/*
+ * Resize acknowledge. You must call this right after you application has
+ * received resize event.
+ *
+ * This will resize backend buffers. After this call returns the backend width
+ * height and context pointer are most likely different.
+ *
+ * This function returns zero on succes. Non zero on failure. If it fails the
+ * best action to take is to save application data and exit (as the backend
+ * may be in undefined state).
+ */
+int GP_BackendResizeAck(GP_Backend *self);
+
#endif /* BACKENDS_GP_BACKEND_H */
diff --git a/libs/backends/GP_Backend.c b/libs/backends/GP_Backend.c
index b81808e..6839187 100644
--- a/libs/backends/GP_Backend.c
+++ b/libs/backends/GP_Backend.c
@@ -83,3 +83,13 @@ int GP_BackendResize(GP_Backend *backend, uint32_t w, uint32_t h)
return backend->SetAttributes(backend, w, h, NULL);
}
+
+int GP_BackendResizeAck(GP_Backend *self)
+{
+ GP_DEBUG(2, "Calling backend %s ResizeAck()", self->name);
+
+ if (self->ResizeAck)
+ return self->ResizeAck(self);
+
+ return 0;
+}
diff --git a/libs/backends/GP_LinuxFB.c b/libs/backends/GP_LinuxFB.c
index 6d69ce4..e819ae5 100644
--- a/libs/backends/GP_LinuxFB.c
+++ b/libs/backends/GP_LinuxFB.c
@@ -324,6 +324,7 @@ GP_Backend *GP_BackendLinuxFBInit(const char *path, int flag)
backend->UpdateRect = fb_update_rect_noop;
backend->Exit = fb_exit;
backend->SetAttributes = NULL;
+ backend->ResizeAck = NULL;
backend->Poll = flag ? fb_poll : NULL;
backend->Wait = flag ? fb_wait : NULL;
backend->fd = fb->con_fd;
diff --git a/libs/backends/GP_SDL.c b/libs/backends/GP_SDL.c
index 0faff30..d3afcca 100644
--- a/libs/backends/GP_SDL.c
+++ b/libs/backends/GP_SDL.c
@@ -164,6 +164,7 @@ static struct GP_Backend backend = {
.Flip = sdl_flip,
.UpdateRect = sdl_update_rect,
.SetAttributes = sdl_set_attributes,
+ .ResizeAck = NULL,
.Exit = sdl_exit,
.fd = -1,
.Poll = sdl_poll,
diff --git a/libs/backends/GP_X11.c b/libs/backends/GP_X11.c
index afe38fd..e543d48 100644
--- a/libs/backends/GP_X11.c
+++ b/libs/backends/GP_X11.c
@@ -45,6 +45,7 @@
#include "GP_X11.h"
struct x11_priv {
+ /* Connection details */
Display *dpy;
int scr;
Screen *scr_ptr;
@@ -52,6 +53,7 @@ struct x11_priv {
Window win;
Visual *vis;
+ /* Image details */
XImage *img;
#ifdef HAVE_X_SHM
@@ -61,31 +63,27 @@ struct x11_priv {
int resized_flag:1;
int shm_flag:1;
-};
-static void destroy_ximage(GP_Backend *self);
-static void destroy_shm_ximage(GP_Backend *self);
+ /* used to store width and height from ConfigureNotify event */
+ unsigned int new_w;
+ unsigned int new_h;
+};
static int resize_ximage(GP_Backend *self, int w, int h);
static int resize_shm_ximage(GP_Backend *self, int w, int h);
-static void x11_exit(GP_Backend *self)
+static void putimage(struct GP_Backend *self, int x0, int y0, int x1, int y1)
{
struct x11_priv *x11 = GP_BACKEND_PRIV(self);
-
- XLockDisplay(x11->dpy);
+#ifdef HAVE_X_SHM
if (x11->shm_flag)
- destroy_shm_ximage(self);
+ XShmPutImage(x11->dpy, x11->win, DefaultGC(x11->dpy, x11->scr),
+ x11->img, x0, y0, x0, y0, x1-x0+1, y1-y0+1, False);
else
- destroy_ximage(self);
-
- XDestroyWindow(x11->dpy, x11->win);
- /* I wonder if this is right sequence... */
- XUnlockDisplay(x11->dpy);
- XCloseDisplay(x11->dpy);
-
- free(self);
+#endif /* HAVE_X_SHM */
+ XPutImage(x11->dpy, x11->win, DefaultGC(x11->dpy, x11->scr),
+ x11->img, x0, y0, x0, y0, x1-x0+1, y1-y0+1);
}
static void x11_update_rect(GP_Backend *self, GP_Coord x0, GP_Coord y0,
@@ -94,19 +92,15 @@ static void x11_update_rect(GP_Backend *self, GP_Coord x0, GP_Coord y0,
struct x11_priv *x11 = GP_BACKEND_PRIV(self);
GP_DEBUG(4, "Updating rect %ix%i-%ix%i", x0, y0, x1, y1);
-
+
+ if (x11->resized_flag) {
+ GP_DEBUG(4, "Ignoring update rect, waiting for resize ack");
+ return;
+ }
+
XLockDisplay(x11->dpy);
-#ifdef HAVE_X_SHM
- if (x11->shm_flag)
- XShmPutImage(x11->dpy, x11->win, DefaultGC(x11->dpy, x11->scr),
- x11->img, x0, y0, x0, y0, x1-x0+1, y1-y0+1, False);
- else
-#endif /* HAVE_X_SHM */
- XPutImage(x11->dpy, x11->win, DefaultGC(x11->dpy, x11->scr),
- x11->img, x0, y0, x0, y0, x1-x0+1, y1-y0+1);
-
- XFlush(x11->dpy);
+ putimage(self, x0, y0, x1, y1);
XUnlockDisplay(x11->dpy);
}
@@ -118,12 +112,22 @@ static void x11_flip(GP_Backend *self)
unsigned int h = self->context->h;
GP_DEBUG(4, "Flipping context");
-
+
+ if (x11->resized_flag) {
+ GP_DEBUG(4, "Ignoring flip, waiting for resize ack");
+ return;
+ }
+
XLockDisplay(x11->dpy);
- XPutImage(x11->dpy, x11->win, DefaultGC(x11->dpy, x11->scr),
- x11->img, 0, 0, 0, 0, w, h);
- XFlush(x11->dpy);
+#ifdef HAVE_X_SHM
+ if (x11->shm_flag)
+ XShmPutImage(x11->dpy, x11->win, DefaultGC(x11->dpy, x11->scr),
+ x11->img, 0, 0, 0, 0, w, h, False);
+ else
+#endif /* HAVE_X_SHM */
+ XPutImage(x11->dpy, x11->win, DefaultGC(x11->dpy, x11->scr),
+ x11->img, 0, 0, 0, 0, w, h);
XUnlockDisplay(x11->dpy);
}
@@ -138,14 +142,22 @@ static void x11_ev(GP_Backend *self, XEvent *ev)
ev->xexpose.x, ev->xexpose.y,
ev->xexpose.width, ev->xexpose.height,
ev->xexpose.count);
-
- /*
- * Ignore Expose events in case user wasn't notified
- * about change and acked image resize.
- */
+
if (x11->resized_flag)
break;
+ /* Safety measure */
+ if (ev->xexpose.x + ev->xexpose.width > (int)self->context->w) {
+ GP_WARN("Expose x + w > context->w");
+ break;
+ }
+
+ if (ev->xexpose.y + ev->xexpose.height > (int)self->context->h) {
+ GP_WARN("Expose y + h > context->h");
+ break;
+ }
+
+ /* Update the rectangle */
x11_update_rect(self, ev->xexpose.x, ev->xexpose.y,
ev->xexpose.x + ev->xexpose.width - 1,
ev->xexpose.y + ev->xexpose.height - 1);
@@ -154,10 +166,17 @@ static void x11_ev(GP_Backend *self, XEvent *ev)
if (ev->xconfigure.width == (int)self->context->w &&
ev->xconfigure.height == (int)self->context->h)
break;
-
- /*
- * Window has been resized, set flag.
- */
+
+ if (ev->xconfigure.width == (int)x11->new_w &&
+ ev->xconfigure.height == (int)x11->new_h)
+ break;
+
+ x11->new_w = ev->xconfigure.width;
+ x11->new_h = ev->xconfigure.height;
+
+ GP_DEBUG(4, "Configure Notify %ux%u", x11->new_w, x11->new_h);
+
+ /* Window has been resized, set flag. */
x11->resized_flag = 1;
default:
GP_InputDriverX11EventPut(ev);
@@ -193,6 +212,21 @@ static void x11_wait(GP_Backend *self)
XUnlockDisplay(x11->dpy);
}
+static int resize_buffer(struct GP_Backend *self, uint32_t w, uint32_t h)
+{
+ struct x11_priv *x11 = GP_BACKEND_PRIV(self);
+
+ if (x11->shm_flag) {
+ if (resize_shm_ximage(self, w, h))
+ return 1;
+ } else {
+ if (resize_ximage(self, w, h))
+ return 1;
+ }
+
+ return 0;
+}
+
static int x11_set_attributes(struct GP_Backend *self,
uint32_t w, uint32_t h,
const char *caption)
@@ -209,20 +243,7 @@ static int x11_set_attributes(struct GP_Backend *self,
if (w != 0 && h != 0) {
GP_DEBUG(3, "Setting window size to %ux%u", w, h);
-
- if (x11->shm_flag) {
- if (resize_shm_ximage(self, w, h))
- return 1;
- } else {
- if (resize_ximage(self, w, h))
- return 1;
- }
-
- /* Resize X11 window */
- // XResizeWindow(x11->dpy, x11->win, w, h);
- XFlush(x11->dpy);
-
- x11->resized_flag = 0;
+ XResizeWindow(x11->dpy, x11->win, w, h);
}
XUnlockDisplay(x11->dpy);
@@ -230,6 +251,26 @@ static int x11_set_attributes(struct GP_Backend *self,
return 0;
}
+static int x11_resize_ack(struct GP_Backend *self)
+{
+ struct x11_priv *x11 = GP_BACKEND_PRIV(self);
+ int ret;
+
+ XLockDisplay(x11->dpy);
+
+ GP_DEBUG(3, "Setting buffer size to %ux%u", x11->new_w, x11->new_h);
+
+ ret = resize_buffer(self, x11->new_w, x11->new_h);
+
+ x11->resized_flag = 0;
+
+ GP_DEBUG(3, "Done");
+
+ XUnlockDisplay(x11->dpy);
+
+ return ret;
+}
+
static void match_pixel_type(struct x11_priv *x11,
enum GP_PixelType *pixel_type, int *depth)
{
@@ -261,12 +302,16 @@ static int create_shm_ximage(GP_Backend *self, GP_Size w, GP_Size h)
return 1;
}
- GP_DEBUG(1, "Using MIT SHM Extension");
+ if (self->context == NULL)
+ GP_DEBUG(1, "Using MIT SHM Extension");
enum GP_PixelType pixel_type;
int depth;
- match_pixel_type(x11, &pixel_type, &depth);
+ if (self->context == NULL)
+ match_pixel_type(x11, &pixel_type, &depth);
+ else
+ pixel_type = self->context->pixel_type;
if (pixel_type == GP_PIXEL_UNKNOWN) {
GP_DEBUG(1, "Unknown pixel type");
@@ -283,13 +328,13 @@ static int create_shm_ximage(GP_Backend *self, GP_Size w, GP_Size h)
size_t size = x11->img->bytes_per_line * x11->img->height;
- x11->shminfo.shmid = shmget(IPC_PRIVATE, size, IPC_CREAT|0777);
+ x11->shminfo.shmid = shmget(IPC_PRIVATE, size, 0600);
if (x11->shminfo.shmid == -1) {
GP_WARN("Calling shmget() failed: %s", strerror(errno));
goto err0;
}
-
+
x11->shminfo.shmaddr = x11->img->data = shmat(x11->shminfo.shmid, 0, 0);
if (x11->shminfo.shmaddr == (void *)-1) {
@@ -297,6 +342,13 @@ static int create_shm_ximage(GP_Backend *self, GP_Size w, GP_Size h)
goto err1;
}
+ /* Mark SHM for deletion after detach */
+ if (shmctl(x11->shminfo.shmid, IPC_RMID, 0)) {
+ GP_WARN("Calling shmctl(..., IPC_RMID), 0) failed: %s",
+ strerror(errno));
+ goto err2;
+ }
+
x11->shminfo.readOnly = False;
if (XShmAttach(x11->dpy, &x11->shminfo) == False) {
@@ -311,6 +363,9 @@ static int create_shm_ximage(GP_Backend *self, GP_Size w, GP_Size h)
x11->shm_flag = 1;
+ //FIXME: Proper synchronization
+ XSync(x11->dpy, True);
+
return 0;
err2:
shmdt(x11->shminfo.shmaddr);
@@ -324,22 +379,34 @@ err0:
static void destroy_shm_ximage(GP_Backend *self)
{
struct x11_priv *x11 = GP_BACKEND_PRIV(self);
+
+ XLockDisplay(x11->dpy);
XShmDetach(x11->dpy, &x11->shminfo);
XFlush(x11->dpy);
shmdt(x11->shminfo.shmaddr);
- shmctl(x11->shminfo.shmid, IPC_RMID, 0);
XDestroyImage(x11->img);
+ XFlush(x11->dpy);
+
+ XUnlockDisplay(x11->dpy);
}
static int resize_shm_ximage(GP_Backend *self, int w, int h)
{
+ struct x11_priv *x11 = GP_BACKEND_PRIV(self);
+ int ret;
+
GP_DEBUG(4, "Resizing XShmImage %ux%u -> %ux%u",
self->context->w, self->context->h, w, h);
+ XLockDisplay(x11->dpy);
+
destroy_shm_ximage(self);
-
- return create_shm_ximage(self, w, h);
+ ret = create_shm_ximage(self, w, h);
+
+ XUnlockDisplay(x11->dpy);
+
+ return ret;
}
#else
@@ -406,7 +473,6 @@ static void destroy_ximage(GP_Backend *self)
XDestroyImage(x11->img);
}
-
static int resize_ximage(GP_Backend *self, int w, int h)
{
struct x11_priv *x11 = GP_BACKEND_PRIV(self);
@@ -423,7 +489,7 @@ static int resize_ximage(GP_Backend *self, int w, int h)
/* Resize context */
if (GP_ContextResize(self->context, w, h)) {
- XDestroyImage(img);
+ XDestroyImage(img);
return 1;
}
@@ -438,6 +504,37 @@ static int resize_ximage(GP_Backend *self, int w, int h)
return 0;
}
+static void window_close(GP_Backend *self)
+{
+ struct x11_priv *x11 = GP_BACKEND_PRIV(self);
+
+ XLockDisplay(x11->dpy);
+
+ if (x11->shm_flag)
+ destroy_shm_ximage(self);
+ else
+ destroy_ximage(self);
+
+ XDestroyWindow(x11->dpy, x11->win);
+
+ XUnlockDisplay(x11->dpy);
+}
+
+static void x11_exit(GP_Backend *self)
+{
+ struct x11_priv *x11 = GP_BACKEND_PRIV(self);
+
+ XLockDisplay(x11->dpy);
+
+ window_close(self);
+
+ /* I wonder if this is right sequence... */
+ //XUnlockDisplay(x11->dpy);
+ XCloseDisplay(x11->dpy);
+
+ free(self);
+}
+
static void create_window(struct x11_priv *x11, int x, int y,
unsigned int *w, unsigned int *h,
const char *caption, enum GP_BackendX11Flags flags)
@@ -658,6 +755,8 @@ GP_Backend *GP_BackendX11Init(const char *display, int x, int y,
if (x11->dpy == NULL)
goto err0;
+ //XSynchronize(x11->dpy, True);
+
x11->scr = DefaultScreen(x11->dpy);
x11->vis = DefaultVisual(x11->dpy, x11->scr);
x11->scr_ptr = DefaultScreenOfDisplay(x11->dpy);
@@ -673,6 +772,8 @@ GP_Backend *GP_BackendX11Init(const char *display, int x, int y,
goto err1;
}
+ backend->context = NULL;
+
if (create_shm_ximage(backend, w, h))
if (create_ximage(backend, w, h))
goto err1;
@@ -688,6 +789,7 @@ GP_Backend *GP_BackendX11Init(const char *display, int x, int y,
backend->Poll = x11_poll;
backend->Wait = x11_wait;
backend->SetAttributes = x11_set_attributes;
+ backend->ResizeAck = x11_resize_ack;
backend->fd = XConnectionNumber(x11->dpy);
return backend;
-----------------------------------------------------------------------
Summary of changes:
build/syms/Backend_symbols.txt | 1 +
build/syms/Event_symbols.txt | 2 +-
demos/c_simple/Makefile | 6 +-
demos/c_simple/{input.c => input_example.c} | 4 +-
demos/spiv/spiv.c | 78 ++++--
doc/Makefile | 2 +-
doc/api.txt | 5 +
doc/backends.txt | 17 ++
...ers_progress_callback.txt => example_input.txt} | 6 +-
doc/input.txt | 271 ++++++++++++++++++++
include/backends/GP_Backend.h | 21 ++
include/input/GP_Event.h | 2 +-
libs/backends/GP_Backend.c | 10 +
libs/backends/GP_LinuxFB.c | 1 +
libs/backends/GP_SDL.c | 1 +
libs/backends/GP_X11.c | 226 ++++++++++++-----
libs/input/GP_Event.c | 2 +-
17 files changed, 559 insertions(+), 96 deletions(-)
rename demos/c_simple/{input.c => input_example.c} (98%)
copy doc/{example_loaders_progress_callback.txt => example_input.txt} (62%)
create mode 100644 doc/input.txt
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos(a)gmail.com
if you want to unsubscribe, or site admin admin(a)repo.or.cz if you receive
no reply.
--
gfxprim.git ("A simple 2D graphics library with emphasis on correctness and well-defined operation.")
1
0
[repo.or.cz] gfxprim.git branch master updated: 89909d1774eb1b3ac35e2e643401bab3b79c9dc2
by bluebear 17 Dec '12
by bluebear 17 Dec '12
17 Dec '12
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 89909d1774eb1b3ac35e2e643401bab3b79c9dc2 (commit)
from 23a690342a49f0f96aad7ce26eb0d7290349d4f3 (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/89909d1774eb1b3ac35e2e643401bab3b79c…
commit 89909d1774eb1b3ac35e2e643401bab3b79c9dc2
Author: Jiri BlueBear Dluhos <jiri.bluebear.dluhos(a)gmail.com>
Date: Mon Dec 17 23:55:01 2012 +0100
Templatized HLine, modernized WritePixel slightly.
diff --git a/include/core/GP_WritePixel.h b/include/core/GP_WritePixel.h
index 0d1a875..d9530f9 100644
--- a/include/core/GP_WritePixel.h
+++ b/include/core/GP_WritePixel.h
@@ -50,16 +50,27 @@ void GP_WritePixels_4BPP_LE(uint8_t *start, uint8_t off,
size_t cnt, uint8_t val);
/*
- * These calls are not byte aligned, thuss needs start offset.
+ * These calls are not byte aligned, thus need start offset.
*/
-void GP_WritePixels1bpp(uint8_t *start, uint8_t off, size_t cnt, uint8_t val);
-void GP_WritePixels2bpp(uint8_t *start, uint8_t off, size_t cnt, uint8_t val);
-void GP_WritePixels4bpp(uint8_t *start, uint8_t off, size_t cnt, uint8_t val);
-void GP_WritePixels18bpp(void *start, uint8_t off, size_t count, uint32_t value);
+void GP_WritePixels_1BPP_BE(uint8_t *start, uint8_t off, size_t cnt, uint8_t val);
+void GP_WritePixels_2BPP_BE(uint8_t *start, uint8_t off, size_t cnt, uint8_t val);
+void GP_WritePixels_4BPP_BE(uint8_t *start, uint8_t off, size_t cnt, uint8_t val);
+void GP_WritePixels_18BPP_BE(void *start, uint8_t off, size_t count, uint32_t value);
-void GP_WritePixels8bpp(void *start, size_t count, uint8_t value);
-void GP_WritePixels16bpp(void *start, size_t count, uint16_t value);
-void GP_WritePixels24bpp(void *start, size_t count, uint32_t value);
-void GP_WritePixels32bpp(void *start, size_t count, uint32_t value);
+/* Byte-aligned calls. */
+void GP_WritePixels_8BPP(void *start, size_t count, uint8_t value);
+void GP_WritePixels_16BPP(void *start, size_t count, uint16_t value);
+void GP_WritePixels_24BPP(void *start, size_t count, uint32_t value);
+void GP_WritePixels_32BPP(void *start, size_t count, uint32_t value);
+
+/* aliases for older names */
+#define GP_WritePixels1bpp GP_WritePixels_1BPP_BE
+#define GP_WritePixels2bpp GP_WritePixels_2BPP_BE
+#define GP_WritePixels4bpp GP_WritePixels_4BPP_BE
+#define GP_WritePixels18bpp GP_WritePixels_18BPP_BE
+#define GP_WritePixels8bpp GP_WritePixels_8BPP
+#define GP_WritePixels16bpp GP_WritePixels_16BPP
+#define GP_WritePixels24bpp GP_WritePixels_24BPP
+#define GP_WritePixels32bpp GP_WritePixels_32BPP
#endif /* GP_WRITEPIXEL_H */
diff --git a/libs/core/GP_WritePixel.c b/libs/core/GP_WritePixel.c
index bc57ea1..a6829b0 100644
--- a/libs/core/GP_WritePixel.c
+++ b/libs/core/GP_WritePixel.c
@@ -41,40 +41,40 @@ void GP_WritePixels_1BPP_LE(uint8_t *start, uint8_t off,
break;
case 1:
GP_SET_BITS1_ALIGNED(1, 1, start, val);
-
+
if (--len == 0)
return;
case 2:
GP_SET_BITS1_ALIGNED(2, 1, start, val);
-
+
if (--len == 0)
return;
case 3:
GP_SET_BITS1_ALIGNED(3, 1, start, val);
-
+
if (--len == 0)
return;
case 4:
GP_SET_BITS1_ALIGNED(4, 1, start, val);
-
+
if (--len == 0)
return;
case 5:
GP_SET_BITS1_ALIGNED(5, 1, start, val);
-
+
if (--len == 0)
return;
case 6:
GP_SET_BITS1_ALIGNED(6, 1, start, val);
-
+
if (--len == 0)
return;
case 7:
GP_SET_BITS1_ALIGNED(7, 1, start, val);
-
+
if (--len == 0)
return;
-
+
start++;
break;
}
@@ -117,27 +117,27 @@ void GP_WritePixels_2BPP_LE(uint8_t *start, uint8_t off,
break;
case 1:
GP_SET_BITS1_ALIGNED(2, 2, start, val);
-
+
if (--len == 0)
return;
case 2:
GP_SET_BITS1_ALIGNED(4, 2, start, val);
-
+
if (--len == 0)
return;
case 3:
GP_SET_BITS1_ALIGNED(6, 2, start, val);
-
+
if (--len == 0)
return;
-
+
start++;
- break;
+ break;
}
-
+
/* Write as many bytes as possible */
memset(start, bytes_2BPP[val & 0x03], len/4);
-
+
start+=len/4;
/* And the rest */
@@ -168,17 +168,17 @@ void GP_WritePixels_4BPP_LE(uint8_t *start, uint8_t off,
break;
case 1:
GP_SET_BITS1_ALIGNED(4, 4, start, val);
-
+
if (--len == 0)
return;
-
+
start++;
- break;
+ break;
}
/* Write as many bytes as possible */
memset(start, bytes_4BPP[val & 0x0f], len/2);
-
+
start+=len/2;
/* And the rest */
@@ -193,7 +193,7 @@ static const uint8_t chunks_1bpp[8] = {
0x00, 0x80, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe,
};
-void GP_WritePixels1bpp(uint8_t *start, uint8_t off, size_t cnt, uint8_t val)
+void GP_WritePixels_1BPP_BE(uint8_t *start, uint8_t off, size_t cnt, uint8_t val)
{
uint8_t s_off = off % 8;
uint8_t e_off = (cnt + s_off) % 8;
@@ -218,7 +218,7 @@ void GP_WritePixels1bpp(uint8_t *start, uint8_t off, size_t cnt, uint8_t val)
/* write len - 2 bytes */
if (len > 1)
- GP_WritePixels8bpp(start + 1, len - 2, col);
+ GP_WritePixels_8BPP(start + 1, len - 2, col);
/* deal with the start and end */
if (val) {
@@ -236,7 +236,7 @@ static const uint8_t colors_2bpp[4] = {
#define PUT_PIXEL_2BPP(p, off, pix) *(p) = (*(p) & ~(0xc0>>(off))) | (pix<<(6 - off))
-void GP_WritePixels2bpp(uint8_t *start, uint8_t off, size_t cnt, uint8_t val)
+void GP_WritePixels_2BPP_BE(uint8_t *start, uint8_t off, size_t cnt, uint8_t val)
{
uint8_t s_off = off % 4;
uint8_t e_off = 2 * ((cnt + s_off) % 4);
@@ -252,7 +252,7 @@ void GP_WritePixels2bpp(uint8_t *start, uint8_t off, size_t cnt, uint8_t val)
for (off = s_off; off < max; off+=2)
PUT_PIXEL_2BPP(start, off, val);
-
+
if (len <= 8)
return;
@@ -264,7 +264,7 @@ void GP_WritePixels2bpp(uint8_t *start, uint8_t off, size_t cnt, uint8_t val)
/* write len - 2 bytes */
if (len > 1)
- GP_WritePixels8bpp(start + 1, len - 2, colors_2bpp[val]);
+ GP_WritePixels_8BPP(start + 1, len - 2, colors_2bpp[val]);
/* handle start and end */
start[0] = (start[0] & (0xff << (8 - s_off))) |
@@ -275,7 +275,7 @@ void GP_WritePixels2bpp(uint8_t *start, uint8_t off, size_t cnt, uint8_t val)
}
-void GP_WritePixels4bpp(uint8_t *start, uint8_t off, size_t cnt, uint8_t val)
+void GP_WritePixels_4BPP_BE(uint8_t *start, uint8_t off, size_t cnt, uint8_t val)
{
uint8_t s_off = off % 2;
uint8_t e_off = (cnt + s_off) % 2;
@@ -285,20 +285,20 @@ void GP_WritePixels4bpp(uint8_t *start, uint8_t off, size_t cnt, uint8_t val)
uint8_t col = (val << 4)& val;
if (len > 0)
- GP_WritePixels8bpp(start + s_off, len, val);
+ GP_WritePixels_8BPP(start + s_off, len, val);
/* handle start and end */
if (s_off) GP_SET_BITS(4, 4, start[0], col);
if (e_off) GP_SET_BITS(0, 4, start[len+s_off], val);
}
-void GP_WritePixels8bpp(void *start, size_t count, uint8_t value)
+void GP_WritePixels_8BPP(void *start, size_t count, uint8_t value)
{
-
+
memset(start, value, count);
}
-void GP_WritePixels16bpp(void *start, size_t count, uint16_t value)
+void GP_WritePixels_16BPP(void *start, size_t count, uint16_t value)
{
uint16_t *p = (uint16_t *) start;
size_t i;
@@ -323,12 +323,17 @@ void GP_WritePixels16bpp(void *start, size_t count, uint16_t value)
}
}
-void GP_WritePixels18bpp(void *start, uint8_t off, size_t count, uint32_t value)
+void GP_WritePixels_18BPP_LE(void *start, uint8_t off, size_t count, uint32_t value)
+{
+ #warning TODO
+}
+
+void GP_WritePixels_18BPP_BE(void *start, uint8_t off, size_t count, uint32_t value)
{
#warning TODO
}
-void GP_WritePixels24bpp(void *start, size_t count, uint32_t value)
+void GP_WritePixels_24BPP(void *start, size_t count, uint32_t value)
{
uint8_t *bytep = (uint8_t *) start;
@@ -406,7 +411,7 @@ void GP_WritePixels24bpp(void *start, size_t count, uint32_t value)
break;
}
- /*
+ /*
* Write as much of the line as possible as
* triplets of 32-bit numbers; hopefully the compiler can
* put some wide write instructions in.
@@ -448,11 +453,11 @@ void GP_WritePixels24bpp(void *start, size_t count, uint32_t value)
}
}
-void GP_WritePixels32bpp(void *start, size_t count, uint32_t value)
+void GP_WritePixels_32BPP(void *start, size_t count, uint32_t value)
{
/*
* Inspired by GNU libc's wmemset() (by Ulrich Drepper, licensed under LGPL).
- *
+ *
* Write the pixels in groups of four, allowing the compiler to use
* MMX/SSE/similar instructions if available. The last few pixels are
* copied normally one-by-one. (Speed gain is about 15% over a naive loop
diff --git a/libs/gfx/GP_HLine.c b/libs/gfx/GP_HLine.gen.c.t
similarity index 82%
rename from libs/gfx/GP_HLine.c
rename to libs/gfx/GP_HLine.gen.c.t
index 35e3e36..8fe9169 100644
--- a/libs/gfx/GP_HLine.c
+++ b/libs/gfx/GP_HLine.gen.c.t
@@ -23,18 +23,56 @@
* *
*****************************************************************************/
+%% extends "base.c.t"
+
+{% block descr %}Horizontal line drawing{% endblock %}
+
+%% block body
+
#include "core/GP_FnPerBpp.h"
#include "core/GP_WritePixel.h"
#include "core/GP_Transform.h"
-#include "algo/HLine.algo.h"
+/* #include "algo/HLine.algo.h" */
#include "gfx/GP_HLine.h"
#include "gfx/GP_VLine.h"
+%% for ps in pixelsizes
+
+void GP_HLine_Raw_{{ ps.suffix }}(GP_Context *context, int x0, int x1, int y,
+ GP_Pixel pixel)
+{
+ /* draw always from left to right, swap coords if necessary */
+ if (x0 > x1)
+ GP_SWAP(x0, x1);
+
+ /* return immediately if the line is completely out of surface */
+ if (y < 0 || y >= (int) context->h ||
+ x1 < 0 || x0 >= (int) context->w)
+ return;
+
+ /* clip the line against surface boundaries */
+ x0 = GP_MAX(x0, 0);
+ x1 = GP_MIN(x1, (int) context->w - 1);
+
+ size_t length = 1 + x1 - x0;
+ void *start = GP_PIXEL_ADDR(context, x0, y);
+
+%% if ps.needs_bit_endian()
+ GP_WritePixels_{{ ps.suffix }}(start, x0 % (8 / context->bpp), length, pixel);
+%% else
+ GP_WritePixels_{{ ps.suffix }}(start, length, pixel);
+%% endif
+
+}
+
+%% endfor
+
/* Generate drawing functions for various bit depths. */
//TODO: BIT ENDIANESS
+/*
DEF_HLINE_BU_FN(GP_HLine_Raw_1BPP_LE, GP_Context*, GP_Pixel, GP_PIXEL_ADDR, GP_WritePixels_1BPP_LE)
DEF_HLINE_BU_FN(GP_HLine_Raw_1BPP_BE, GP_Context*, GP_Pixel, GP_PIXEL_ADDR, GP_WritePixels1bpp)
DEF_HLINE_BU_FN(GP_HLine_Raw_2BPP_LE, GP_Context*, GP_Pixel, GP_PIXEL_ADDR, GP_WritePixels_2BPP_LE)
@@ -47,12 +85,13 @@ DEF_HLINE_FN(GP_HLine_Raw_8BPP, GP_Context *, GP_Pixel, GP_PIXEL_ADDR, GP_Write
DEF_HLINE_FN(GP_HLine_Raw_16BPP, GP_Context *, GP_Pixel, GP_PIXEL_ADDR, GP_WritePixels16bpp)
DEF_HLINE_FN(GP_HLine_Raw_24BPP, GP_Context *, GP_Pixel, GP_PIXEL_ADDR, GP_WritePixels24bpp)
DEF_HLINE_FN(GP_HLine_Raw_32BPP, GP_Context *, GP_Pixel, GP_PIXEL_ADDR, GP_WritePixels32bpp)
+*/
void GP_HLineXXY_Raw(GP_Context *context, GP_Coord x0, GP_Coord x1,
GP_Coord y, GP_Pixel pixel)
{
GP_CHECK_CONTEXT(context);
-
+
GP_FN_PER_BPP_CONTEXT(GP_HLine_Raw, context, context, x0, x1, y,
pixel);
}
@@ -70,7 +109,7 @@ void GP_HLineXXY(GP_Context *context, GP_Coord x0, GP_Coord x1, GP_Coord y,
GP_Pixel pixel)
{
GP_CHECK_CONTEXT(context);
-
+
if (context->axes_swap) {
GP_TRANSFORM_Y(context, x0);
GP_TRANSFORM_Y(context, x1);
@@ -92,3 +131,5 @@ void GP_HLineXYW(GP_Context *context, GP_Coord x, GP_Coord y, GP_Size w,
GP_HLineXXY(context, x, x + w - 1, y, pixel);
}
+
+%% endblock body
diff --git a/libs/gfx/Makefile b/libs/gfx/Makefile
index 145827b..d80e49a 100644
--- a/libs/gfx/Makefile
+++ b/libs/gfx/Makefile
@@ -1,6 +1,6 @@
TOPDIR=../..
CSOURCES=$(filter-out $(wildcard *.gen.c),$(wildcard *.c))
-GENSOURCES=GP_Line.gen.c GP_LineAA.gen.c GP_PutPixelAA.gen.c +GENSOURCES=GP_Line.gen.c GP_HLine.gen.c GP_LineAA.gen.c GP_PutPixelAA.gen.c GP_HLineAA.gen.c GP_VLineAA.gen.c GP_FillCircle.gen.c
LIBNAME=gfx
-----------------------------------------------------------------------
Summary of changes:
include/core/GP_WritePixel.h | 29 ++++++++----
libs/core/GP_WritePixel.c | 73 +++++++++++++++-------------
libs/gfx/{GP_HLine.c => GP_HLine.gen.c.t} | 47 +++++++++++++++++-
libs/gfx/Makefile | 2 +-
4 files changed, 104 insertions(+), 47 deletions(-)
rename libs/gfx/{GP_HLine.c => GP_HLine.gen.c.t} (82%)
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos(a)gmail.com
if you want to unsubscribe, or site admin admin(a)repo.or.cz if you receive
no reply.
--
gfxprim.git ("A simple 2D graphics library with emphasis on correctness and well-defined operation.")
1
0