Gfxprim
Threads by month
- ----- 2026 -----
- February
- 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
June 2012
- 2 participants
- 35 discussions
[repo.or.cz] gfxprim.git branch master updated: 5e2e627e16c613ffee331d5ac32071caca27a369
by metan 08 Jun '12
by metan 08 Jun '12
08 Jun '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 5e2e627e16c613ffee331d5ac32071caca27a369 (commit)
via 43ae478827afcbdb94f4ce3d46a0881c6e2f9c01 (commit)
via 5073ef02014ec1f3d2ca23e50951a6db7785c23e (commit)
via cdf48d7342a48c7a5225403bfc371ba0ec7e74d5 (commit)
via 7831f900a2f1ad24e66b999a6ddb7d664236d0d7 (commit)
via ea3d8a3b3ff7deca52c6320bcbc30f3115f5aa32 (commit)
via f027b0f012e6ea1e694dd0618be0d9c18c840dc5 (commit)
from b45098c71ca5dab7345e2b2f704ae6452a7b52cb (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/5e2e627e16c613ffee331d5ac32071caca27…
commit 5e2e627e16c613ffee331d5ac32071caca27a369
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Fri Jun 8 20:21:18 2012 +0200
spiv: Temporarily fix the bussy loop.
diff --git a/demos/spiv/spiv.c b/demos/spiv/spiv.c
index 28ae50d..ec5a656 100644
--- a/demos/spiv/spiv.c
+++ b/demos/spiv/spiv.c
@@ -416,6 +416,7 @@ static int wait_for_event(int sleep_msec)
if (sleep_msec < 0) {
GP_BackendPoll(backend);
+ usleep(10000);
return 0;
}
http://repo.or.cz/w/gfxprim.git/commit/43ae478827afcbdb94f4ce3d46a0881c6e2f…
commit 43ae478827afcbdb94f4ce3d46a0881c6e2f9c01
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Fri Jun 8 20:12:06 2012 +0200
spiv: image_cache: Add elevator count, drop cache on d.
diff --git a/demos/spiv/image_cache.c b/demos/spiv/image_cache.c
index 3f26474..4a8c2b7 100644
--- a/demos/spiv/image_cache.c
+++ b/demos/spiv/image_cache.c
@@ -30,6 +30,9 @@ struct image {
struct image *prev;
struct image *next;
+ /* number of elevated get calls */
+ unsigned int elevated;
+
/* this identifies an image */
long cookie1;
long cookie2;
@@ -172,6 +175,8 @@ GP_Context *image_cache_get(struct image_cache *self, const char *path,
remove_img(self, i, size);
add_img(self, i, size);
+
+ i->elevated++;
}
return i->ctx;
@@ -184,8 +189,8 @@ void image_cache_print(struct image_cache *self)
printf("Image cache size %u used %un", self->max_size, self->cur_size);
for (i = self->root; i != NULL; i = i->next)
- printf(" Image '%s:%10li:%10li' size %zun", i->path,
- i->cookie1, i->cookie2, image_size(i));
+ printf(" Image '%s:%10li:%10li' size %10zu elevated %un", i->path,
+ i->cookie1, i->cookie2, image_size(i), i->elevated);
}
static int assert_size(struct image_cache *self, size_t size)
@@ -227,6 +232,7 @@ int image_cache_put(struct image_cache *self, GP_Context *ctx, const char *path,
img->ctx = ctx;
img->cookie1 = cookie1;
img->cookie2 = cookie2;
+ img->elevated = 0;
strcpy(img->path, path);
add_img(self, img, size);
@@ -234,6 +240,16 @@ int image_cache_put(struct image_cache *self, GP_Context *ctx, const char *path,
return 0;
}
+void image_cache_drop(struct image_cache *self)
+{
+ GP_DEBUG(1, "Dropping images in cache");
+
+ while (self->end != NULL)
+ remove_img_free(self, self->end, 0);
+
+ self->cur_size = sizeof(struct image_cache);
+}
+
void image_cache_destroy(struct image_cache *self)
{
GP_DEBUG(1, "Destroying image cache");
diff --git a/demos/spiv/image_cache.h b/demos/spiv/image_cache.h
index 38efb0d..e946709 100644
--- a/demos/spiv/image_cache.h
+++ b/demos/spiv/image_cache.h
@@ -55,6 +55,11 @@ int image_cache_put(struct image_cache *self, GP_Context *img,
const char *path, long cookie1, long cookie2);
/*
+ * Drop all image in cache.
+ */
+void image_cache_drop(struct image_cache *self);
+
+/*
* Destroys image cache and all it's images.
*/
void image_cache_destroy(struct image_cache *self);
diff --git a/demos/spiv/spiv.c b/demos/spiv/spiv.c
index e4a6747..28ae50d 100644
--- a/demos/spiv/spiv.c
+++ b/demos/spiv/spiv.c
@@ -596,6 +596,9 @@ int main(int argc, char *argv[])
params.show_progress_once = 1;
show_image(¶ms, NULL);
break;
+ case GP_KEY_D:
+ image_cache_drop(params.image_cache);
+ break;
case GP_KEY_ESC:
case GP_KEY_ENTER:
case GP_KEY_Q:
http://repo.or.cz/w/gfxprim.git/commit/5073ef02014ec1f3d2ca23e50951a6db7785…
commit 5073ef02014ec1f3d2ca23e50951a6db7785c23e
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Fri Jun 8 20:00:36 2012 +0200
spiv: image_cache: Add elevate parameter to get function.
diff --git a/demos/spiv/image_cache.c b/demos/spiv/image_cache.c
index 759febc..3f26474 100644
--- a/demos/spiv/image_cache.c
+++ b/demos/spiv/image_cache.c
@@ -148,8 +148,8 @@ static void add_img(struct image_cache *self, struct image *img, size_t size)
self->end = img;
}
-GP_Context *image_cache_get(struct image_cache *self,
- const char *path, long cookie1, long cookie2)
+GP_Context *image_cache_get(struct image_cache *self, const char *path,
+ long cookie1, long cookie2, int elevate)
{
struct image *i;
@@ -164,12 +164,15 @@ GP_Context *image_cache_get(struct image_cache *self,
return NULL;
/* Push the image to the root of the list */
- size_t size = image_size(i);
+ if (elevate) {
+ size_t size = image_size(i);
- GP_DEBUG(2, "Refreshing image '%s:%10li:%10li", path, cookie1, cookie2);
+ GP_DEBUG(2, "Refreshing image '%s:%10li:%10li",
+ path, cookie1, cookie2);
- remove_img(self, i, size);
- add_img(self, i, size);
+ remove_img(self, i, size);
+ add_img(self, i, size);
+ }
return i->ctx;
}
diff --git a/demos/spiv/image_cache.h b/demos/spiv/image_cache.h
index d2e3019..38efb0d 100644
--- a/demos/spiv/image_cache.h
+++ b/demos/spiv/image_cache.h
@@ -42,11 +42,11 @@ struct image_cache *image_cache_create(unsigned int max_size);
/*
* Returns cached image, or NULL.
*
- * Also image, if found, is rotated to the top, so recently touched images have
- * lesser chance of being freed.
+ * If elevate set and image is found, the image is elevated to the top so
+ * it has lesser chance of being freed.
*/
-GP_Context *image_cache_get(struct image_cache *self,
- const char *path, long cookie1, long cookie2);
+GP_Context *image_cache_get(struct image_cache *self, const char *path,
+ long cookie1, long cookie2, int elevate);
/*
* Puts an image into a cache.
diff --git a/demos/spiv/spiv.c b/demos/spiv/spiv.c
index 93c066f..e4a6747 100644
--- a/demos/spiv/spiv.c
+++ b/demos/spiv/spiv.c
@@ -126,7 +126,7 @@ static void set_caption(const char *path, float rat)
/*
* Loads image
*/
-GP_Context *load_image(struct loader_params *params)
+GP_Context *load_image(struct loader_params *params, int elevate)
{
struct cpu_timer timer;
GP_Context *img, *context = backend->context;
@@ -134,7 +134,7 @@ GP_Context *load_image(struct loader_params *params)
GP_ProgressCallback callback = {.callback = image_loader_callback,
.priv = "Loading image"};
- img = image_cache_get(params->image_cache, params->img_path, 0, 0);
+ img = image_cache_get(params->image_cache, params->img_path, 0, 0, elevate);
/* Image not cached, load it */
if (img == NULL) {
@@ -176,13 +176,13 @@ GP_Context *load_resized_image(struct loader_params *params, GP_Size w, GP_Size
GP_ProgressCallback callback = {.callback = image_loader_callback};
/* Try to get resized cached image */
- img = image_cache_get(params->image_cache, params->img_path, cookie, resampling_method);
+ img = image_cache_get(params->image_cache, params->img_path, cookie, resampling_method, 1);
if (img != NULL)
return img;
/* Otherwise load image and resize it */
- if ((img = load_image(params)) == NULL)
+ if ((img = load_image(params, 1)) == NULL)
return NULL;
/* Do low pass filter */
@@ -222,7 +222,7 @@ GP_Context *load_resized_image(struct loader_params *params, GP_Size w, GP_Size
*/
static int resize_backend_and_blit(struct loader_params *params)
{
- GP_Context *img = load_image(params);
+ GP_Context *img = load_image(params, 1);
if (GP_BackendResize(backend, img->w, img->h))
return 1;
@@ -260,7 +260,7 @@ static void *image_loader(void *ptr)
break;
}
- if ((img = load_image(params)) == NULL)
+ if ((img = load_image(params, 0)) == NULL)
return NULL;
float rat = calc_img_size(img->w, img->h, w, h);
http://repo.or.cz/w/gfxprim.git/commit/cdf48d7342a48c7a5225403bfc371ba0ec7e…
commit cdf48d7342a48c7a5225403bfc371ba0ec7e74d5
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Fri Jun 8 19:50:50 2012 +0200
spiv: image_cache: Count image size more properly.
diff --git a/demos/spiv/image_cache.c b/demos/spiv/image_cache.c
index 7ff0c56..759febc 100644
--- a/demos/spiv/image_cache.c
+++ b/demos/spiv/image_cache.c
@@ -67,6 +67,20 @@ static size_t read_total_memory(void)
return ret * 1024 / 10;
}
+/*
+ * Reports correct image record size.
+ */
+static size_t image_size2(GP_Context *ctx, const char *path)
+{
+ return ctx->bytes_per_row * ctx->h + sizeof(GP_Context) +
+ sizeof(struct image) + strlen(path) + 1;
+}
+
+static size_t image_size(struct image *img)
+{
+ return image_size2(img->ctx, img->path);
+}
+
struct image_cache *image_cache_create(unsigned int max_size)
{
struct image_cache *self;
@@ -77,7 +91,7 @@ struct image_cache *image_cache_create(unsigned int max_size)
return NULL;
self->max_size = max_size ? max_size : read_total_memory();
- self->cur_size = 0;
+ self->cur_size = sizeof(struct image_cache);
self->root = NULL;
self->end = NULL;
@@ -87,10 +101,8 @@ struct image_cache *image_cache_create(unsigned int max_size)
return self;
}
-static void remove_img(struct image_cache *self, struct image *img)
+static void remove_img(struct image_cache *self, struct image *img, size_t size)
{
- size_t size = img->ctx->bytes_per_row * img->ctx->h;
-
if (img == self->end)
self->end = img->prev;
@@ -106,13 +118,13 @@ static void remove_img(struct image_cache *self, struct image *img)
self->cur_size -= size;
}
-static void remove_img_free(struct image_cache *self, struct image *img)
+static void remove_img_free(struct image_cache *self,
+ struct image *img, size_t size)
{
- GP_DEBUG(2, "Freeing image '%s:%10li:%10li' size %u",
- img->path, img->cookie1, img->cookie2,
- img->ctx->bytes_per_row * img->ctx->h);
+ GP_DEBUG(2, "Freeing image '%s:%10li:%10li' size %zu",
+ img->path, img->cookie1, img->cookie2, size);
- remove_img(self, img);
+ remove_img(self, img, size);
GP_ContextFree(img->ctx);
free(img);
}
@@ -120,10 +132,8 @@ static void remove_img_free(struct image_cache *self, struct image *img)
/*
* Adds image to the start of the double linked list
*/
-static void add_img(struct image_cache *self, struct image *img)
+static void add_img(struct image_cache *self, struct image *img, size_t size)
{
- size_t size = img->ctx->bytes_per_row * img->ctx->h;
-
img->next = self->root;
if (img->next)
@@ -154,9 +164,12 @@ GP_Context *image_cache_get(struct image_cache *self,
return NULL;
/* Push the image to the root of the list */
+ size_t size = image_size(i);
+
GP_DEBUG(2, "Refreshing image '%s:%10li:%10li", path, cookie1, cookie2);
- remove_img(self, i);
- add_img(self, i);
+
+ remove_img(self, i, size);
+ add_img(self, i, size);
return i->ctx;
}
@@ -168,8 +181,8 @@ void image_cache_print(struct image_cache *self)
printf("Image cache size %u used %un", self->max_size, self->cur_size);
for (i = self->root; i != NULL; i = i->next)
- printf(" Image '%s:%10li:%10li' size %un", i->path, i->cookie1, i->cookie2,
- i->ctx->bytes_per_row * i->ctx->h);
+ printf(" Image '%s:%10li:%10li' size %zun", i->path,
+ i->cookie1, i->cookie2, image_size(i));
}
static int assert_size(struct image_cache *self, size_t size)
@@ -184,7 +197,7 @@ static int assert_size(struct image_cache *self, size_t size)
return 1;
}
- remove_img_free(self, self->end);
+ remove_img_free(self, self->end, image_size(self->end));
}
return 0;
@@ -193,7 +206,7 @@ static int assert_size(struct image_cache *self, size_t size)
int image_cache_put(struct image_cache *self, GP_Context *ctx, const char *path,
long cookie1, long cookie2)
{
- size_t size = ctx->bytes_per_row * ctx->h;
+ size_t size = image_size2(ctx, path);
if (assert_size(self, size))
return 1;
@@ -213,7 +226,8 @@ int image_cache_put(struct image_cache *self, GP_Context *ctx, const char *path,
img->cookie2 = cookie2;
strcpy(img->path, path);
- add_img(self, img);
+ add_img(self, img, size);
+
return 0;
}
@@ -222,7 +236,7 @@ void image_cache_destroy(struct image_cache *self)
GP_DEBUG(1, "Destroying image cache");
while (self->end != NULL)
- remove_img_free(self, self->end);
+ remove_img_free(self, self->end, 0);
free(self);
}
diff --git a/demos/spiv/image_cache.h b/demos/spiv/image_cache.h
index fc008ed..d2e3019 100644
--- a/demos/spiv/image_cache.h
+++ b/demos/spiv/image_cache.h
@@ -34,13 +34,16 @@ struct image_cache;
/*
* Creates an image cache with maximal memory size.
*
- * When memory size is set to zero, the size is read from /proc/meminfo
- * as 10% of total memory.
+ * When memory size is set to zero it's set to 10% of total machine memory
+ * (as reported by /proc/meminfo).
*/
struct image_cache *image_cache_create(unsigned int max_size);
/*
* Returns cached image, or NULL.
+ *
+ * Also image, if found, is rotated to the top, so recently touched images have
+ * lesser chance of being freed.
*/
GP_Context *image_cache_get(struct image_cache *self,
const char *path, long cookie1, long cookie2);
http://repo.or.cz/w/gfxprim.git/commit/7831f900a2f1ad24e66b999a6ddb7d664236…
commit 7831f900a2f1ad24e66b999a6ddb7d664236d0d7
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Fri Jun 8 19:30:58 2012 +0200
spiv: Fix low pass filtering, edhance cache.
diff --git a/demos/spiv/image_cache.c b/demos/spiv/image_cache.c
index f252013..7ff0c56 100644
--- a/demos/spiv/image_cache.c
+++ b/demos/spiv/image_cache.c
@@ -26,11 +26,13 @@
struct image {
GP_Context *ctx;
- int cookie;
struct image *prev;
struct image *next;
+ /* this identifies an image */
+ long cookie1;
+ long cookie2;
char path[];
};
@@ -106,8 +108,8 @@ static void remove_img(struct image_cache *self, struct image *img)
static void remove_img_free(struct image_cache *self, struct image *img)
{
- GP_DEBUG(2, "Freeing image '%s:%i' size %u",
- img->path, img->cookie,
+ GP_DEBUG(2, "Freeing image '%s:%10li:%10li' size %u",
+ img->path, img->cookie1, img->cookie2,
img->ctx->bytes_per_row * img->ctx->h);
remove_img(self, img);
@@ -137,21 +139,22 @@ static void add_img(struct image_cache *self, struct image *img)
}
GP_Context *image_cache_get(struct image_cache *self,
- const char *path, int cookie)
+ const char *path, long cookie1, long cookie2)
{
struct image *i;
- GP_DEBUG(2, "Looking for image '%s:%i'", path, cookie);
+ GP_DEBUG(2, "Looking for image '%s:%10li:%10li'", path, cookie1, cookie2);
for (i = self->root; i != NULL; i = i->next)
- if (!strcmp(path, i->path) && i->cookie == cookie)
+ if (!strcmp(path, i->path) &&
+ i->cookie1 == cookie1 && i->cookie2 == cookie2)
break;
if (i == NULL)
return NULL;
/* Push the image to the root of the list */
- GP_DEBUG(2, "Refreshing image '%s:%i", path, cookie);
+ GP_DEBUG(2, "Refreshing image '%s:%10li:%10li", path, cookie1, cookie2);
remove_img(self, i);
add_img(self, i);
@@ -165,7 +168,7 @@ void image_cache_print(struct image_cache *self)
printf("Image cache size %u used %un", self->max_size, self->cur_size);
for (i = self->root; i != NULL; i = i->next)
- printf(" Image '%s:%i' size %un", i->path, i->cookie,
+ printf(" Image '%s:%10li:%10li' size %un", i->path, i->cookie1, i->cookie2,
i->ctx->bytes_per_row * i->ctx->h);
}
@@ -187,8 +190,8 @@ static int assert_size(struct image_cache *self, size_t size)
return 0;
}
-int image_cache_put(struct image_cache *self,
- GP_Context *ctx, const char *path, int cookie)
+int image_cache_put(struct image_cache *self, GP_Context *ctx, const char *path,
+ long cookie1, long cookie2)
{
size_t size = ctx->bytes_per_row * ctx->h;
@@ -202,11 +205,12 @@ int image_cache_put(struct image_cache *self,
return 1;
}
- GP_DEBUG(2, "Adding image '%s:%i' size %zu",
- img->path, img->cookie, size);
+ GP_DEBUG(2, "Adding image '%s:%10li:%10li' size %zu",
+ img->path, img->cookie1, img->cookie2, size);
img->ctx = ctx;
- img->cookie = cookie;
+ img->cookie1 = cookie1;
+ img->cookie2 = cookie2;
strcpy(img->path, path);
add_img(self, img);
diff --git a/demos/spiv/image_cache.h b/demos/spiv/image_cache.h
index ad3ecdd..fc008ed 100644
--- a/demos/spiv/image_cache.h
+++ b/demos/spiv/image_cache.h
@@ -43,13 +43,13 @@ struct image_cache *image_cache_create(unsigned int max_size);
* Returns cached image, or NULL.
*/
GP_Context *image_cache_get(struct image_cache *self,
- const char *path, int cookie);
+ const char *path, long cookie1, long cookie2);
/*
* Puts an image into a cache.
*/
-int image_cache_put(struct image_cache *self,
- GP_Context *img, const char *path, int cookie);
+int image_cache_put(struct image_cache *self, GP_Context *img,
+ const char *path, long cookie1, long cookie2);
/*
* Destroys image cache and all it's images.
diff --git a/demos/spiv/spiv.c b/demos/spiv/spiv.c
index c1ec6d2..93c066f 100644
--- a/demos/spiv/spiv.c
+++ b/demos/spiv/spiv.c
@@ -134,7 +134,7 @@ GP_Context *load_image(struct loader_params *params)
GP_ProgressCallback callback = {.callback = image_loader_callback,
.priv = "Loading image"};
- img = image_cache_get(params->image_cache, params->img_path, 0);
+ img = image_cache_get(params->image_cache, params->img_path, 0, 0);
/* Image not cached, load it */
if (img == NULL) {
@@ -160,7 +160,7 @@ GP_Context *load_image(struct loader_params *params)
img = tmp;
}
- image_cache_put(params->image_cache, img, params->img_path, 0);
+ image_cache_put(params->image_cache, img, params->img_path, 0, 0);
cpu_timer_stop(&timer);
}
@@ -171,33 +171,33 @@ GP_Context *load_image(struct loader_params *params)
GP_Context *load_resized_image(struct loader_params *params, GP_Size w, GP_Size h, float rat)
{
long cookie = (w & 0xffff) | (h & 0xffff)<<16;
- GP_Context *img;
+ GP_Context *img, *res = NULL;
struct cpu_timer timer;
GP_ProgressCallback callback = {.callback = image_loader_callback};
/* Try to get resized cached image */
- img = image_cache_get(params->image_cache, params->img_path, cookie);
+ img = image_cache_get(params->image_cache, params->img_path, cookie, resampling_method);
if (img != NULL)
return img;
/* Otherwise load image and resize it */
- img = load_image(params);
-
- if (img == NULL)
+ if ((img = load_image(params)) == NULL)
return NULL;
/* Do low pass filter */
- if (resampling_method != GP_INTERP_LINEAR_LF_INT) {
- if (rat < 1) {
- cpu_timer_start(&timer, "Blur");
- callback.priv = "Blurring Image";
- //TODO: We can't blur saved image!
- if (GP_FilterGaussianBlur(img, img, 0.4/rat, 0.4/rat,
- &callback) == NULL)
- return NULL;
- cpu_timer_stop(&timer);
- }
+ if (resampling_method != GP_INTERP_LINEAR_LF_INT && rat < 1) {
+ cpu_timer_start(&timer, "Blur");
+ callback.priv = "Blurring Image";
+
+ res = GP_FilterGaussianBlur(img, NULL, 0.4/rat, 0.4/rat, &callback);
+
+ if (res == NULL)
+ return NULL;
+
+ img = res;
+
+ cpu_timer_stop(&timer);
}
cpu_timer_start(&timer, "Resampling");
@@ -205,11 +205,14 @@ GP_Context *load_resized_image(struct loader_params *params, GP_Size w, GP_Size
img = GP_FilterResize(img, NULL, resampling_method, w, h, &callback);
cpu_timer_stop(&timer);
+ /* Free low passed context if needed */
+ GP_ContextFree(res);
+
if (img == NULL)
return NULL;
- image_cache_put(params->image_cache, img, params->img_path, cookie);
-
+ image_cache_put(params->image_cache, img, params->img_path, cookie, resampling_method);
+
return img;
}
@@ -270,6 +273,8 @@ static void *image_loader(void *ptr)
if (img == NULL)
return NULL;
+ image_cache_print(params->image_cache);
+
switch (rotate) {
case 0:
break;
http://repo.or.cz/w/gfxprim.git/commit/ea3d8a3b3ff7deca52c6320bcbc30f3115f5…
commit ea3d8a3b3ff7deca52c6320bcbc30f3115f5aa32
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Fri Jun 8 18:59:27 2012 +0200
spiv: Cache resized images too, not optimal yet though.
diff --git a/demos/spiv/spiv.c b/demos/spiv/spiv.c
index 26eb45b..c1ec6d2 100644
--- a/demos/spiv/spiv.c
+++ b/demos/spiv/spiv.c
@@ -168,6 +168,51 @@ GP_Context *load_image(struct loader_params *params)
return img;
}
+GP_Context *load_resized_image(struct loader_params *params, GP_Size w, GP_Size h, float rat)
+{
+ long cookie = (w & 0xffff) | (h & 0xffff)<<16;
+ GP_Context *img;
+ struct cpu_timer timer;
+ GP_ProgressCallback callback = {.callback = image_loader_callback};
+
+ /* Try to get resized cached image */
+ img = image_cache_get(params->image_cache, params->img_path, cookie);
+
+ if (img != NULL)
+ return img;
+
+ /* Otherwise load image and resize it */
+ img = load_image(params);
+
+ if (img == NULL)
+ return NULL;
+
+ /* Do low pass filter */
+ if (resampling_method != GP_INTERP_LINEAR_LF_INT) {
+ if (rat < 1) {
+ cpu_timer_start(&timer, "Blur");
+ callback.priv = "Blurring Image";
+ //TODO: We can't blur saved image!
+ if (GP_FilterGaussianBlur(img, img, 0.4/rat, 0.4/rat,
+ &callback) == NULL)
+ return NULL;
+ cpu_timer_stop(&timer);
+ }
+ }
+
+ cpu_timer_start(&timer, "Resampling");
+ callback.priv = "Resampling Image";
+ img = GP_FilterResize(img, NULL, resampling_method, w, h, &callback);
+ cpu_timer_stop(&timer);
+
+ if (img == NULL)
+ return NULL;
+
+ image_cache_put(params->image_cache, img, params->img_path, cookie);
+
+ return img;
+}
+
/*
* This function tries to resize spiv window
* and if succedes blits the image directly to the screen.
@@ -189,26 +234,12 @@ static int resize_backend_and_blit(struct loader_params *params)
static void *image_loader(void *ptr)
{
struct loader_params *params = ptr;
- struct cpu_timer timer;
- struct cpu_timer sum_timer;
+ struct cpu_timer timer, sum_timer;
GP_Context *img, *context = backend->context;
GP_ProgressCallback callback = {.callback = image_loader_callback};
cpu_timer_start(&sum_timer, "sum");
- /* Load Image */
- img = load_image(params);
-
- if (img == NULL)
- return NULL;
-
- /*
- if (img->w < 320 && img->h < 240) {
- if (!resize_backend_and_blit(img, params))
- return NULL;
- }
- */
-
/* Figure out rotation */
GP_Size w, h;
@@ -226,32 +257,17 @@ static void *image_loader(void *ptr)
break;
}
+ if ((img = load_image(params)) == NULL)
+ return NULL;
+
float rat = calc_img_size(img->w, img->h, w, h);
w = img->w;
h = img->h;
- GP_Context *ret;
-
- /* Do low pass filter */
- if (resampling_method != GP_INTERP_LINEAR_LF_INT) {
- if (rat < 1) {
- cpu_timer_start(&timer, "Blur");
- callback.priv = "Blurring Image";
- //TODO: We can't blur saved image!
- if (GP_FilterGaussianBlur(img, img, 0.4/rat, 0.4/rat,
- &callback) == NULL)
- return NULL;
- cpu_timer_stop(&timer);
- }
- }
-
- cpu_timer_start(&timer, "Resampling");
- callback.priv = "Resampling Image";
- ret = GP_FilterResize(img, NULL, resampling_method, img->w * rat, img->h * rat, &callback);
- cpu_timer_stop(&timer);
+ img = load_resized_image(params, img->w * rat + 0.5, img->h * rat + 0.5, rat);
- if (ret == NULL)
+ if (img == NULL)
return NULL;
switch (rotate) {
@@ -259,28 +275,23 @@ static void *image_loader(void *ptr)
break;
case 90:
callback.priv = "Rotating image (90)";
- img = GP_FilterRotate90_Alloc(ret, &callback);
+ img = GP_FilterRotate90_Alloc(img, &callback);
break;
case 180:
callback.priv = "Rotating image (180)";
- img = GP_FilterRotate180_Alloc(ret, &callback);
+ img = GP_FilterRotate180_Alloc(img, &callback);
break;
case 270:
callback.priv = "Rotating image (270)";
- img = GP_FilterRotate270_Alloc(ret, &callback);
+ img = GP_FilterRotate270_Alloc(img, &callback);
break;
}
-
- if (rotate) {
- GP_ContextFree(ret);
- ret = img;
- }
-
+
if (img == NULL)
return NULL;
- uint32_t cx = (context->w - ret->w)/2;
- uint32_t cy = (context->h - ret->h)/2;
+ uint32_t cx = (context->w - img->w)/2;
+ uint32_t cy = (context->h - img->h)/2;
GP_Context sub_display;
@@ -288,21 +299,23 @@ static void *image_loader(void *ptr)
if (dithering) {
callback.priv = "Dithering";
- GP_ContextSubContext(context, &sub_display, cx, cy, ret->w, ret->h);
+ GP_ContextSubContext(context, &sub_display, cx, cy, img->w, img->h);
// GP_FilterFloydSteinberg_RGB888(ret, &sub_display, NULL);
- GP_FilterHilbertPeano_RGB888(ret, &sub_display, NULL);
+ GP_FilterHilbertPeano_RGB888(img, &sub_display, NULL);
} else {
- GP_Blit_Raw(ret, 0, 0, ret->w, ret->h, context, cx, cy);
+ GP_Blit_Raw(img, 0, 0, img->w, img->h, context, cx, cy);
}
cpu_timer_stop(&timer);
- GP_ContextFree(ret);
+
+ if (rotate)
+ GP_ContextFree(img);
/* clean up the rest of the display */
GP_FillRectXYWH(context, 0, 0, cx, context->h, black_pixel);
GP_FillRectXYWH(context, 0, 0, context->w, cy, black_pixel);
- GP_FillRectXYWH(context, ret->w+cx, 0, context->w - ret->w - cx, context->h, black_pixel);
- GP_FillRectXYWH(context, 0, ret->h+cy, context->w, context->h - ret->h - cy, black_pixel);
+ GP_FillRectXYWH(context, img->w + cx, 0, context->w - img->w - cx, context->h, black_pixel);
+ GP_FillRectXYWH(context, 0, img->h + cy, context->w, context->h - img->h - cy, black_pixel);
cpu_timer_stop(&sum_timer);
http://repo.or.cz/w/gfxprim.git/commit/f027b0f012e6ea1e694dd0618be0d9c18c84…
commit f027b0f012e6ea1e694dd0618be0d9c18c840dc5
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Fri Jun 8 18:40:43 2012 +0200
spiv: Add image cache.
diff --git a/demos/spiv/Makefile b/demos/spiv/Makefile
index 13b416c..431e6ce 100644
--- a/demos/spiv/Makefile
+++ b/demos/spiv/Makefile
@@ -9,7 +9,7 @@ LDLIBS+=-lGP -lGP_backends -lSDL -L$(TOPDIR)/build/
APPS=spiv
-spiv: cpu_timer.o
+spiv: cpu_timer.o image_cache.o
include $(TOPDIR)/pre.mk
include $(TOPDIR)/app.mk
diff --git a/demos/spiv/image_cache.c b/demos/spiv/image_cache.c
new file mode 100644
index 0000000..f252013
--- /dev/null
+++ b/demos/spiv/image_cache.c
@@ -0,0 +1,224 @@
+/*****************************************************************************
+ * 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 <string.h>
+#include <GP.h>
+#include "image_cache.h"
+
+struct image {
+ GP_Context *ctx;
+ int cookie;
+
+ struct image *prev;
+ struct image *next;
+
+ char path[];
+};
+
+struct image_cache {
+ unsigned int max_size;
+ unsigned int cur_size;
+
+ struct image *root;
+ struct image *end;
+};
+
+static size_t read_total_memory(void)
+{
+ FILE *f;
+ size_t ret;
+
+ f = fopen("/proc/meminfo", "r");
+
+ if (f == NULL) {
+ GP_WARN("Failed to read /proc/meminfo");
+ return 0;
+ }
+
+ if (fscanf(f, "MemTotal: %zu", &ret) != 1) {
+ fclose(f);
+ GP_WARN("Failed to read /proc/meminfo");
+ return 0;
+ }
+
+ fclose(f);
+
+ return ret * 1024 / 10;
+}
+
+struct image_cache *image_cache_create(unsigned int max_size)
+{
+ struct image_cache *self;
+
+ self = malloc(sizeof(struct image_cache));
+
+ if (self == NULL)
+ return NULL;
+
+ self->max_size = max_size ? max_size : read_total_memory();
+ self->cur_size = 0;
+
+ self->root = NULL;
+ self->end = NULL;
+
+ GP_DEBUG(1, "Created image cache size %u bytes", self->max_size);
+
+ return self;
+}
+
+static void remove_img(struct image_cache *self, struct image *img)
+{
+ size_t size = img->ctx->bytes_per_row * img->ctx->h;
+
+ if (img == self->end)
+ self->end = img->prev;
+
+ if (img->prev)
+ img->prev->next = img->next;
+
+ if (img->next)
+ img->next->prev = img->prev;
+
+ if (img == self->root)
+ self->root = img->next;
+
+ self->cur_size -= size;
+}
+
+static void remove_img_free(struct image_cache *self, struct image *img)
+{
+ GP_DEBUG(2, "Freeing image '%s:%i' size %u",
+ img->path, img->cookie,
+ img->ctx->bytes_per_row * img->ctx->h);
+
+ remove_img(self, img);
+ GP_ContextFree(img->ctx);
+ free(img);
+}
+
+/*
+ * Adds image to the start of the double linked list
+ */
+static void add_img(struct image_cache *self, struct image *img)
+{
+ size_t size = img->ctx->bytes_per_row * img->ctx->h;
+
+ img->next = self->root;
+
+ if (img->next)
+ img->next->prev = img;
+
+ img->prev = NULL;
+
+ self->root = img;
+ self->cur_size += size;
+
+ if (self->end == NULL)
+ self->end = img;
+}
+
+GP_Context *image_cache_get(struct image_cache *self,
+ const char *path, int cookie)
+{
+ struct image *i;
+
+ GP_DEBUG(2, "Looking for image '%s:%i'", path, cookie);
+
+ for (i = self->root; i != NULL; i = i->next)
+ if (!strcmp(path, i->path) && i->cookie == cookie)
+ break;
+
+ if (i == NULL)
+ return NULL;
+
+ /* Push the image to the root of the list */
+ GP_DEBUG(2, "Refreshing image '%s:%i", path, cookie);
+ remove_img(self, i);
+ add_img(self, i);
+
+ return i->ctx;
+}
+
+void image_cache_print(struct image_cache *self)
+{
+ struct image *i;
+
+ printf("Image cache size %u used %un", self->max_size, self->cur_size);
+
+ for (i = self->root; i != NULL; i = i->next)
+ printf(" Image '%s:%i' size %un", i->path, i->cookie,
+ i->ctx->bytes_per_row * i->ctx->h);
+}
+
+static int assert_size(struct image_cache *self, size_t size)
+{
+ if (self->cur_size + size < self->max_size)
+ return 0;
+
+ while (self->cur_size + size > self->max_size) {
+
+ if (self->end == NULL) {
+ GP_WARN("Cache too small for image size %zu", size);
+ return 1;
+ }
+
+ remove_img_free(self, self->end);
+ }
+
+ return 0;
+}
+
+int image_cache_put(struct image_cache *self,
+ GP_Context *ctx, const char *path, int cookie)
+{
+ size_t size = ctx->bytes_per_row * ctx->h;
+
+ if (assert_size(self, size))
+ return 1;
+
+ struct image *img = malloc(sizeof(struct image) + strlen(path) + 1);
+
+ if (img == NULL) {
+ GP_WARN("Malloc failed :(");
+ return 1;
+ }
+
+ GP_DEBUG(2, "Adding image '%s:%i' size %zu",
+ img->path, img->cookie, size);
+
+ img->ctx = ctx;
+ img->cookie = cookie;
+ strcpy(img->path, path);
+
+ add_img(self, img);
+ return 0;
+}
+
+void image_cache_destroy(struct image_cache *self)
+{
+ GP_DEBUG(1, "Destroying image cache");
+
+ while (self->end != NULL)
+ remove_img_free(self, self->end);
+
+ free(self);
+}
diff --git a/demos/spiv/image_cache.h b/demos/spiv/image_cache.h
new file mode 100644
index 0000000..ad3ecdd
--- /dev/null
+++ b/demos/spiv/image_cache.h
@@ -0,0 +1,64 @@
+/*****************************************************************************
+ * 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 loader chache.
+
+ */
+
+#ifndef __IMAGE_CACHE_H__
+#define __IMAGE_CACHE_H__
+
+struct image_cache;
+
+/*
+ * Creates an image cache with maximal memory size.
+ *
+ * When memory size is set to zero, the size is read from /proc/meminfo
+ * as 10% of total memory.
+ */
+struct image_cache *image_cache_create(unsigned int max_size);
+
+/*
+ * Returns cached image, or NULL.
+ */
+GP_Context *image_cache_get(struct image_cache *self,
+ const char *path, int cookie);
+
+/*
+ * Puts an image into a cache.
+ */
+int image_cache_put(struct image_cache *self,
+ GP_Context *img, const char *path, int cookie);
+
+/*
+ * Destroys image cache and all it's images.
+ */
+void image_cache_destroy(struct image_cache *self);
+
+/*
+ * Print the image cache content.
+ */
+void image_cache_print(struct image_cache *self);
+
+#endif /* __IMAGE_CACHE_H__ */
diff --git a/demos/spiv/spiv.c b/demos/spiv/spiv.c
index 6e03531..26eb45b 100644
--- a/demos/spiv/spiv.c
+++ b/demos/spiv/spiv.c
@@ -36,6 +36,7 @@
#include <backends/GP_Backends.h>
#include <input/GP_InputDriverLinux.h>
+#include "image_cache.h"
#include "cpu_timer.h"
static GP_Pixel black_pixel;
@@ -88,8 +89,8 @@ struct loader_params {
int show_progress_once;
int show_info;
- /* cached loaded image */
- GP_Context *img;
+ /* cached loaded images */
+ struct image_cache *image_cache;
};
static float calc_img_size(uint32_t img_w, uint32_t img_h,
@@ -125,46 +126,46 @@ static void set_caption(const char *path, float rat)
/*
* Loads image
*/
-int load_image(struct loader_params *params)
+GP_Context *load_image(struct loader_params *params)
{
struct cpu_timer timer;
GP_Context *img, *context = backend->context;
-
- if (params->img != NULL) {
- fprintf(stderr, "Image cached!n");
- return 0;
- }
GP_ProgressCallback callback = {.callback = image_loader_callback,
.priv = "Loading image"};
-
- show_progress = params->show_progress || params->show_progress_once;
- params->show_progress_once = 0;
- fprintf(stderr, "Loading '%s'n", params->img_path);
+ img = image_cache_get(params->image_cache, params->img_path, 0);
- cpu_timer_start(&timer, "Loading");
- if ((img = GP_LoadImage(params->img_path, &callback)) == NULL) {
- GP_Fill(context, black_pixel);
- GP_Print(context, NULL, context->w/2, context->h/2,
- GP_ALIGN_CENTER|GP_VALIGN_CENTER, white_pixel, black_pixel,
- "Failed to load image :( (%s)", strerror(errno));
- GP_BackendFlip(backend);
- return 1;
- }
+ /* Image not cached, load it */
+ if (img == NULL) {
+ show_progress = params->show_progress || params->show_progress_once;
+ params->show_progress_once = 0;
+
+ fprintf(stderr, "Loading '%s'n", params->img_path);
+
+ cpu_timer_start(&timer, "Loading");
+ if ((img = GP_LoadImage(params->img_path, &callback)) == NULL) {
+ GP_Fill(context, black_pixel);
+ GP_Print(context, NULL, context->w/2, context->h/2,
+ GP_ALIGN_CENTER|GP_VALIGN_CENTER, white_pixel, black_pixel,
+ "Failed to load image :( (%s)", strerror(errno));
+ GP_BackendFlip(backend);
+ return NULL;
+ }
+
+ /* Workaround */
+ if (img->pixel_type != GP_PIXEL_RGB888) {
+ GP_Context *tmp = GP_ContextConvert(img, GP_PIXEL_RGB888);
+ GP_ContextFree(img);
+ img = tmp;
+ }
- /* Workaround */
- if (img->pixel_type != GP_PIXEL_RGB888) {
- GP_Context *tmp = GP_ContextConvert(img, GP_PIXEL_RGB888);
- GP_ContextFree(img);
- img = tmp;
+ image_cache_put(params->image_cache, img, params->img_path, 0);
+
+ cpu_timer_stop(&timer);
}
-
- cpu_timer_stop(&timer);
-
- params->img = img;
- return 0;
+ return img;
}
/*
@@ -173,7 +174,7 @@ int load_image(struct loader_params *params)
*/
static int resize_backend_and_blit(struct loader_params *params)
{
- GP_Context *img = params->img;
+ GP_Context *img = load_image(params);
if (GP_BackendResize(backend, img->w, img->h))
return 1;
@@ -196,10 +197,10 @@ static void *image_loader(void *ptr)
cpu_timer_start(&sum_timer, "sum");
/* Load Image */
- if (load_image(params))
- return NULL;
+ img = load_image(params);
- img = params->img;
+ if (img == NULL)
+ return NULL;
/*
if (img->w < 320 && img->h < 240) {
@@ -351,13 +352,8 @@ static void show_image(struct loader_params *params, const char *path)
abort_flag = 0;
}
- /* invalidate cached image if path has changed */
- if (params->img_path == NULL ||
- (path != NULL && strcmp(params->img_path, path))) {
- GP_ContextFree(params->img);
- params->img = NULL;
+ if (path != NULL)
params->img_path = path;
- }
ret = pthread_create(&loader_thread, NULL, image_loader, (void*)params);
@@ -465,10 +461,12 @@ int main(int argc, char *argv[])
GP_Context *context = NULL;
const char *backend_opts = "X11";
int sleep_sec = -1;
- struct loader_params params = {NULL, 0, 0, 0, .img = NULL};
+ struct loader_params params = {NULL, 0, 0, 0, NULL};
int opt, debug_level = 0;
GP_PixelType emul_type = GP_PIXEL_UNKNOWN;
+ params.image_cache = image_cache_create(0);
+
while ((opt = getopt(argc, argv, "b:cd:e:fIPs:r:")) != -1) {
switch (opt) {
case 'I':
-----------------------------------------------------------------------
Summary of changes:
demos/spiv/Makefile | 2 +-
demos/spiv/image_cache.c | 261 ++++++++++++++++++++
.../loaders/GP_JPG.h => demos/spiv/image_cache.h | 49 ++--
demos/spiv/spiv.c | 196 ++++++++-------
4 files changed, 398 insertions(+), 110 deletions(-)
create mode 100644 demos/spiv/image_cache.c
copy include/loaders/GP_JPG.h => demos/spiv/image_cache.h (61%)
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: b45098c71ca5dab7345e2b2f704ae6452a7b52cb
by metan 05 Jun '12
by metan 05 Jun '12
05 Jun '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 b45098c71ca5dab7345e2b2f704ae6452a7b52cb (commit)
from 40459eab2c4a3af4a5eccd1b3cbe1bd94353f9c7 (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/b45098c71ca5dab7345e2b2f704ae6452a7b…
commit b45098c71ca5dab7345e2b2f704ae6452a7b52cb
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Tue Jun 5 15:18:09 2012 +0200
filters: Add noise filter.
diff --git a/demos/grinder/grinder.c b/demos/grinder/grinder.c
index abdf546..1bc7360 100644
--- a/demos/grinder/grinder.c
+++ b/demos/grinder/grinder.c
@@ -16,7 +16,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, *
* Boston, MA 02110-1301 USA *
* *
- * Copyright (C) 2009-2011 Cyril Hrubis <metan(a)ucw.cz> *
+ * Copyright (C) 2009-2012 Cyril Hrubis <metan(a)ucw.cz> *
* *
*****************************************************************************/
@@ -354,6 +354,28 @@ static GP_RetCode contrast(GP_Context **c, const char *params)
return GP_ESUCCESS;
}
+/* noise */
+static struct param noise_params[] = {
+ {"ratio", PARAM_FLOAT, "noise", NULL, NULL},
+ {NULL, 0, NULL, NULL, NULL}
+};
+
+static GP_RetCode noise(GP_Context **c, const char *params)
+{
+ float rat;
+
+ if (param_parse(params, noise_params, "noise", param_err, &rat))
+ return GP_EINVAL;
+
+ GP_FILTER_PARAMS((*c)->pixel_type, filter_params);
+
+ GP_FilterParamSetFloatAll(filter_params, rat);
+
+ GP_FilterNoise(*c, *c, filter_params, progress_callback);
+
+ return GP_ESUCCESS;
+}
+
/* invert */
static struct param invert_params[] = {
@@ -675,6 +697,7 @@ static struct filter filter_table[] = {
{"contrast", "alter image contrast", contrast_params, contrast},
{"invert", "inverts image", invert_params, invert},
{"add_noise", "adds noise", add_noise_params, add_noise},
+ {"noise", "adds noise", noise_params, noise},
{"blur", "gaussian blur", blur_params, blur},
{"dither", "dithers bitmap", dither_params, dither},
{"arithmetic", "arithmetic operation", arithmetic_params, arithmetic},
diff --git a/include/filters/GP_Point.h b/include/filters/GP_Point.h
index 1ab3756..31e9747 100644
--- a/include/filters/GP_Point.h
+++ b/include/filters/GP_Point.h
@@ -72,6 +72,12 @@ GP_Context *GP_FilterInvert(const GP_Context *src, GP_Context *dst,
GP_ProgressCallback *callback);
/*
+ * Noise filter.
+ */
+GP_Context *GP_FilterNoise(const GP_Context *src, GP_Context *dst,
+ GP_FilterParam ratio[], GP_ProgressCallback *callback);
+
+/*
* Generic slow point filter.
*
* The filter_callback[] is expected to be filled with pointers
diff --git a/libs/filters/GP_Noise.gen.c.t b/libs/filters/GP_Noise.gen.c.t
new file mode 100644
index 0000000..7afca65
--- /dev/null
+++ b/libs/filters/GP_Noise.gen.c.t
@@ -0,0 +1,34 @@
+%% extends "filter.point.c.t"
+
+{% block descr %}Noise filter -- Adds noise to an image.{% endblock %}
+
+%% block body
+
+{{ filter_point_include() }}
+
+%% macro filter_op(chann_name, chann_size)
+{{ chann_name }} = {{ chann_name }} + (random() % ({{ chann_name }}_max * 2)) - {{ chann_name }}_max;
+{{ filter_clamp_val(chann_name, chann_size) }}
+%% endmacro
+
+/*
+ * Generated noise filters.
+ */
+%% call(pt) filter_point_per_channel('Noise', 'GP_FilterParam ratio[]', filter_op)
+{{ filter_params(pt, 'ratio', 'float ', '_rat', 'f') }}
+%% for chann in pt.chanslist
+ int {{ chann[0] }}_max = {{ chann[0] }}_rat * {{ 2 ** chann[2] - 1}} + 0.5;
+%% endfor
+%% endcall
+
+/*
+ * Generated noise filters for pixels with one channel.
+ */
+%% call(ps) filter_point_per_bpp('Noise', 'GP_FilterParam ratio[]', filter_op)
+{{ filter_param(ps, 'ratio', 'float ', '_rat', 'f') }}
+ int pix_max = pix_rat * {{ 2 ** ps.size - 1}} + 0.5;
+%% endcall
+
+{{ filter_functions('Noise', 'GP_FilterParam ratio[]', 'ratio') }}
+
+%% endblock body
diff --git a/libs/filters/Makefile b/libs/filters/Makefile
index 4bed64a..49993aa 100644
--- a/libs/filters/Makefile
+++ b/libs/filters/Makefile
@@ -3,7 +3,7 @@ TOPDIR=../..
STATS_FILTERS=GP_Histogram.gen.c
POINT_FILTERS=GP_Contrast.gen.c GP_Brightness.gen.c GP_Invert.gen.c- GP_Point.gen.c
+ GP_Point.gen.c GP_Noise.gen.c
ARITHMETIC_FILTERS=GP_Difference.gen.c GP_Addition.gen.c GP_Min.gen.c GP_Max.gen.c GP_Multiply.gen.c
-----------------------------------------------------------------------
Summary of changes:
demos/grinder/grinder.c | 25 ++++++++++++++++++++++++-
include/filters/GP_Point.h | 6 ++++++
libs/filters/GP_Noise.gen.c.t | 34 ++++++++++++++++++++++++++++++++++
libs/filters/Makefile | 2 +-
4 files changed, 65 insertions(+), 2 deletions(-)
create mode 100644 libs/filters/GP_Noise.gen.c.t
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: 40459eab2c4a3af4a5eccd1b3cbe1bd94353f9c7
by metan 04 Jun '12
by metan 04 Jun '12
04 Jun '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
discards 9c0d7122590ec63c4a9cb6e5b019f373e84a6106 (commit)
via 40459eab2c4a3af4a5eccd1b3cbe1bd94353f9c7 (commit)
This update added new revisions after undoing existing revisions. That is
to say, the old revision is not a strict subset of the new revision. This
situation occurs when you --force push a change and generate a repository
containing something like this:
* -- * -- B -- O -- O -- O (9c0d7122590ec63c4a9cb6e5b019f373e84a6106)
N -- N -- N (40459eab2c4a3af4a5eccd1b3cbe1bd94353f9c7)
When this happens we assume that you've already had alert emails for all
of the O revisions, and so we here report only the revisions in the N
branch from the common base, B.
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/40459eab2c4a3af4a5eccd1b3cbe1bd94353…
commit 40459eab2c4a3af4a5eccd1b3cbe1bd94353f9c7
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Mon Jun 4 16:22:41 2012 +0200
pywrap: Fix error reporting.
The python headers define _GNU_SOURCE so the
strerror_r variant is GNU one, which may use the passed
buffer to, but that is not guaranted it also may return
pointer to some statically allocated buffer.
Also make sure _GNU_SOURCE is defined in pywrap.mk.
diff --git a/pylib/gfxprim/common.i b/pylib/gfxprim/common.i
index 66b37b0..bc99ff3 100644
--- a/pylib/gfxprim/common.i
+++ b/pylib/gfxprim/common.i
@@ -23,11 +23,9 @@
%exception funcname {
$action
if (result == NULL) {
- int errno0 = errno;
- const int errbuf_len = 128;
- char errbuf[errbuf_len];
- strerror_r(errno0, errbuf, errbuf_len);
- PyErr_Format(PyExc_RuntimeError, "Error in function %s: %s", "$name", errbuf);
+ char errbuf[128];
+ char *errmsg = strerror_r(errno, errbuf, sizeof(errbuf));
+ PyErr_Format(PyExc_RuntimeError, "Error in function %s: %s", "$name", errmsg);
return NULL;
}
}
@@ -42,11 +40,9 @@
%exception funcname {
$action
if (result != 0) {
- int errno0 = errno;
- const int errbuf_len = 128;
- char errbuf[errbuf_len];
- strerror_r(errno0, errbuf, errbuf_len);
- PyErr_Format(PyExc_RuntimeError, "Error in function %s: %s", "$name", errbuf);
+ char errbuf[128];
+ char *errmsg = strerror_r(errno, errbuf, sizeof(errbuf));
+ PyErr_Format(PyExc_RuntimeError, "Error in function %s: %s", "$name", errmsg);
return NULL;
}
}
diff --git a/pywrap.mk b/pywrap.mk
index 0ec5602..03d22cf 100644
--- a/pywrap.mk
+++ b/pywrap.mk
@@ -23,10 +23,10 @@ endif # VERBOSE
$(SWIG_LIB): $(SWIG_C)
ifdef VERBOSE
- $(CC) $< $(CFLAGS) $(LDFLAGS) -I$(PYTHON_INCLUDE) --shared -lGP $(LDLIBS) -L$(TOPDIR)/build/ -o $@
+ $(CC) $< $(CFLAGS) -D_GNU_SOURCE=1 $(LDFLAGS) -I$(PYTHON_INCLUDE) --shared -lGP $(LDLIBS) -L$(TOPDIR)/build/ -o $@
else # VERBOSE
@echo "LD $@"
- @$(CC) $< $(CFLAGS) $(LDFLAGS) -I$(PYTHON_INCLUDE) --shared -lGP $(LDLIBS) -L$(TOPDIR)/build/ -o $@
+ @$(CC) $< $(CFLAGS) -D_GNU_SOURCE=1 $(LDFLAGS) -I$(PYTHON_INCLUDE) --shared -lGP $(LDLIBS) -L$(TOPDIR)/build/ -o $@
endif # VERBOSE
endif # ifneq ($(SWIG),)
-----------------------------------------------------------------------
Summary of changes:
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: 9c0d7122590ec63c4a9cb6e5b019f373e84a6106
by metan 04 Jun '12
by metan 04 Jun '12
04 Jun '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 9c0d7122590ec63c4a9cb6e5b019f373e84a6106 (commit)
via 1d12df083de4555dbd7aaba94980ca96c71988b8 (commit)
from 0243aecd593c5c712078dfa1fbcf8bba1187a736 (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/9c0d7122590ec63c4a9cb6e5b019f373e84a…
commit 9c0d7122590ec63c4a9cb6e5b019f373e84a6106
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Mon Jun 4 16:22:41 2012 +0200
pywrap: Fix error reporting.
The python headers define _GNU_SOURCE so the
strerror_r variant is GNU one, which uses the passed
buffer to create it's data structure and returns pointer
to the message.
Also make sure _GNU_SOURCE is defined in pywrap.mk.
diff --git a/pylib/gfxprim/common.i b/pylib/gfxprim/common.i
index 66b37b0..bc99ff3 100644
--- a/pylib/gfxprim/common.i
+++ b/pylib/gfxprim/common.i
@@ -23,11 +23,9 @@
%exception funcname {
$action
if (result == NULL) {
- int errno0 = errno;
- const int errbuf_len = 128;
- char errbuf[errbuf_len];
- strerror_r(errno0, errbuf, errbuf_len);
- PyErr_Format(PyExc_RuntimeError, "Error in function %s: %s", "$name", errbuf);
+ char errbuf[128];
+ char *errmsg = strerror_r(errno, errbuf, sizeof(errbuf));
+ PyErr_Format(PyExc_RuntimeError, "Error in function %s: %s", "$name", errmsg);
return NULL;
}
}
@@ -42,11 +40,9 @@
%exception funcname {
$action
if (result != 0) {
- int errno0 = errno;
- const int errbuf_len = 128;
- char errbuf[errbuf_len];
- strerror_r(errno0, errbuf, errbuf_len);
- PyErr_Format(PyExc_RuntimeError, "Error in function %s: %s", "$name", errbuf);
+ char errbuf[128];
+ char *errmsg = strerror_r(errno, errbuf, sizeof(errbuf));
+ PyErr_Format(PyExc_RuntimeError, "Error in function %s: %s", "$name", errmsg);
return NULL;
}
}
diff --git a/pywrap.mk b/pywrap.mk
index 0ec5602..03d22cf 100644
--- a/pywrap.mk
+++ b/pywrap.mk
@@ -23,10 +23,10 @@ endif # VERBOSE
$(SWIG_LIB): $(SWIG_C)
ifdef VERBOSE
- $(CC) $< $(CFLAGS) $(LDFLAGS) -I$(PYTHON_INCLUDE) --shared -lGP $(LDLIBS) -L$(TOPDIR)/build/ -o $@
+ $(CC) $< $(CFLAGS) -D_GNU_SOURCE=1 $(LDFLAGS) -I$(PYTHON_INCLUDE) --shared -lGP $(LDLIBS) -L$(TOPDIR)/build/ -o $@
else # VERBOSE
@echo "LD $@"
- @$(CC) $< $(CFLAGS) $(LDFLAGS) -I$(PYTHON_INCLUDE) --shared -lGP $(LDLIBS) -L$(TOPDIR)/build/ -o $@
+ @$(CC) $< $(CFLAGS) -D_GNU_SOURCE=1 $(LDFLAGS) -I$(PYTHON_INCLUDE) --shared -lGP $(LDLIBS) -L$(TOPDIR)/build/ -o $@
endif # VERBOSE
endif # ifneq ($(SWIG),)
http://repo.or.cz/w/gfxprim.git/commit/1d12df083de4555dbd7aaba94980ca96c719…
commit 1d12df083de4555dbd7aaba94980ca96c71988b8
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Mon Jun 4 16:05:49 2012 +0200
pywrap: Add make dependency for common.i.
diff --git a/pylib/gfxprim/core/Makefile b/pylib/gfxprim/core/Makefile
index 0ee5e15..3be0466 100644
--- a/pylib/gfxprim/core/Makefile
+++ b/pylib/gfxprim/core/Makefile
@@ -3,6 +3,9 @@ LIBNAME=core
include $(TOPDIR)/pre.mk
include $(TOPDIR)/pywrap.mk
+
+$(SWIG_C): ../common.i
+
include $(TOPDIR)/post.mk
include ../silence_swig_warnings.mk
diff --git a/pylib/gfxprim/loaders/Makefile b/pylib/gfxprim/loaders/Makefile
index 791fc74..dd23e98 100644
--- a/pylib/gfxprim/loaders/Makefile
+++ b/pylib/gfxprim/loaders/Makefile
@@ -4,6 +4,9 @@ INCLUDE=core
include $(TOPDIR)/pre.mk
include $(TOPDIR)/pywrap.mk
+
+$(SWIG_C): ../common.i
+
include $(TOPDIR)/post.mk
include ../silence_swig_warnings.mk
-----------------------------------------------------------------------
Summary of changes:
pylib/gfxprim/common.i | 16 ++++++----------
pylib/gfxprim/core/Makefile | 3 +++
pylib/gfxprim/loaders/Makefile | 3 +++
pywrap.mk | 4 ++--
4 files changed, 14 insertions(+), 12 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: 0243aecd593c5c712078dfa1fbcf8bba1187a736
by gavento 04 Jun '12
by gavento 04 Jun '12
04 Jun '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 0243aecd593c5c712078dfa1fbcf8bba1187a736 (commit)
via 6d342080a27ffc532abb09f4d34485a2b44b46bd (commit)
via 975521142bd84de4a192d418325cb1b47a642a60 (commit)
via 524cd8c33aab67f7c64ea54ee8ab194dbee1df53 (commit)
from 9270ef0f3556aa8a1bd8f4e7191d0813ec5708dc (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/0243aecd593c5c712078dfa1fbcf8bba1187…
commit 0243aecd593c5c712078dfa1fbcf8bba1187a736
Author: Tomas Gavenciak <gavento(a)ucw.cz>
Date: Mon Jun 4 14:01:16 2012 +0200
pywrap: error checking for some modules
Done for:
core (except for GP_ContextDump - legacy)
backends
gfx (none needed)
loaders (except for GP_P?M.h - legacy)
Not done:
filters
input
text
diff --git a/pylib/gfxprim/backends/backends.i b/pylib/gfxprim/backends/backends.i
index 1c909e1..fb3fb7d 100644
--- a/pylib/gfxprim/backends/backends.i
+++ b/pylib/gfxprim/backends/backends.i
@@ -27,20 +27,31 @@
%immutable GP_Backend::name;
%ignore GP_BackendFD;
+ERROR_ON_NONZERO(GP_BackendSetCaption);
+ERROR_ON_NONZERO(GP_BackendResize);
+
%include "GP_Backend.h"
-/*
- * Particular backends. We need to list every header separately.
- */
-/* Overall backend init header */
+ERROR_ON_NULL(GP_BackendInit);
%newobject GP_BackendInit;
%include "GP_BackendInit.h"
+/*
+ * Particular backends.
+ */
+
+ERROR_ON_NULL(GP_BackendVirtualInit);
+%newobject GP_BackendVirtualInit;
+%include "GP_BackendVirtual.h"
+
+ERROR_ON_NULL(GP_BackendLinuxFBInit);
%newobject GP_BackendLinuxFBInit;
%include "GP_LinuxFB.h"
+ERROR_ON_NULL(GP_BackendLinuxSDLInit);
%newobject GP_BackendSDLInit;
%include "GP_SDL.h"
+ERROR_ON_NULL(GP_BackendLinuxX11Init);
%newobject GP_BackendX11Init;
%include "GP_X11.h"
diff --git a/pylib/gfxprim/core/core.i b/pylib/gfxprim/core/core.i
index 3e1bea5..86b0233 100644
--- a/pylib/gfxprim/core/core.i
+++ b/pylib/gfxprim/core/core.i
@@ -9,6 +9,8 @@
* Basic types and common methods
*/
+ERROR_ON_NULL(GP_GetCounter);
+
%include "GP_Common.h"
%include "GP_Core.h"
%include "GP_Debug.h"
@@ -25,6 +27,8 @@
* Color and pixel types
*/
+ERROR_ON_NULL(GP_ColorToColorName);
+
%include "GP_Color.h"
%include "GP_Pixel.h"
%include "GP_Pixel.gen.h" /* Includes enum GP_PixelType definition */
@@ -83,6 +87,13 @@ and self.thisown.") GP_Context;
}
};
+/* Error handling */
+ERROR_ON_NONZERO(GP_ContextResize);
+ERROR_ON_NULL(GP_ContextAlloc);
+ERROR_ON_NULL(GP_ContextCopy);
+ERROR_ON_NULL(GP_ContextSubContext);
+ERROR_ON_NULL(GP_ContextConvert);
+
/* Indicate new wrapper-owned GP_Context */
%newobject GP_ContextAlloc;
%newobject GP_ContextCopy;
diff --git a/pylib/gfxprim/loaders/loaders.i b/pylib/gfxprim/loaders/loaders.i
index bcfcaef..2e54d41 100644
--- a/pylib/gfxprim/loaders/loaders.i
+++ b/pylib/gfxprim/loaders/loaders.i
@@ -8,11 +8,45 @@
%import ../core/core.i
+ERROR_ON_NULL(GP_LoadImage);
+ERROR_ON_NONZERO(GP_LoadMetaData);
+ERROR_ON_NONZERO(GP_SaveImage);
+
%include "GP_Loaders.h"
+ERROR_ON_NONZERO(GP_OpenJPG);
+ERROR_ON_NULL(GP_ReadJPG);
+ERROR_ON_NULL(GP_LoadJPG);
+ERROR_ON_NONZERO(GP_ReadJPGMetaData);
+ERROR_ON_NONZERO(GP_LoadJPGMetaData);
+ERROR_ON_NONZERO(GP_SaveJPG);
+
%include "GP_JPG.h"
+
+ERROR_ON_NONZERO(GP_OpenBMP);
+ERROR_ON_NULL(GP_ReadBMP);
+ERROR_ON_NULL(GP_LoadBMP);
+
+%include "GP_BMP.h"
+
+ERROR_ON_NONZERO(GP_OpenGIF);
+ERROR_ON_NULL(GP_ReadGIF);
+ERROR_ON_NULL(GP_LoadGIF);
+
+%include "GP_GIF.h"
+
+ERROR_ON_NONZERO(GP_OpenPNG);
+ERROR_ON_NULL(GP_ReadPNG);
+ERROR_ON_NULL(GP_LoadPNG);
+ERROR_ON_NONZERO(GP_ReadPNGMetaData);
+ERROR_ON_NONZERO(GP_LoadPNGMetaData);
+ERROR_ON_NONZERO(GP_SavePNG);
+
+%include "GP_PNG.h"
+
+/* TODO: No error checking - legacy GP_RetCode form */
%include "GP_PBM.h"
%include "GP_PGM.h"
%include "GP_PPM.h"
-%include "GP_PNG.h"
+
http://repo.or.cz/w/gfxprim.git/commit/6d342080a27ffc532abb09f4d34485a2b44b…
commit 6d342080a27ffc532abb09f4d34485a2b44b46bd
Merge: 9755211 9270ef0
Author: Tomas Gavenciak <gavento(a)ucw.cz>
Date: Mon Jun 4 13:53:02 2012 +0200
Merge branch 'master' of ssh://repo.or.cz/srv/git/gfxprim
http://repo.or.cz/w/gfxprim.git/commit/975521142bd84de4a192d418325cb1b47a64…
commit 975521142bd84de4a192d418325cb1b47a642a60
Author: Tomas Gavenciak <gavento(a)ucw.cz>
Date: Mon Jun 4 13:28:46 2012 +0200
pywrap: add error-checking wrappers
diff --git a/pylib/gfxprim/common.i b/pylib/gfxprim/common.i
index 0734e1a..66b37b0 100644
--- a/pylib/gfxprim/common.i
+++ b/pylib/gfxprim/common.i
@@ -10,3 +10,44 @@
%nodefaultctor;
+/*
+ * Error handling declarations
+ */
+
+/*
+ * Wrapped function is executed and the return value is checked.
+ * If NULL, errno is checked and an exception raised.
+ */
+
+%define ERROR_ON_NULL(funcname)
+%exception funcname {
+ $action
+ if (result == NULL) {
+ int errno0 = errno;
+ const int errbuf_len = 128;
+ char errbuf[errbuf_len];
+ strerror_r(errno0, errbuf, errbuf_len);
+ PyErr_Format(PyExc_RuntimeError, "Error in function %s: %s", "$name", errbuf);
+ return NULL;
+ }
+}
+%enddef
+
+/*
+ * Wrapped function is executed and the return value is checked.
+ * If non-zero, errno is checked and an exception raised
+ */
+
+%define ERROR_ON_NONZERO(funcname)
+%exception funcname {
+ $action
+ if (result != 0) {
+ int errno0 = errno;
+ const int errbuf_len = 128;
+ char errbuf[errbuf_len];
+ strerror_r(errno0, errbuf, errbuf_len);
+ PyErr_Format(PyExc_RuntimeError, "Error in function %s: %s", "$name", errbuf);
+ return NULL;
+ }
+}
+%enddef
http://repo.or.cz/w/gfxprim.git/commit/524cd8c33aab67f7c64ea54ee8ab194dbee1…
commit 524cd8c33aab67f7c64ea54ee8ab194dbee1df53
Author: Tomas Gavenciak <gavento(a)ucw.cz>
Date: Mon Jun 4 13:28:02 2012 +0200
Relocate some common SWIG code
diff --git a/pylib/gfxprim/backends/backends.i b/pylib/gfxprim/backends/backends.i
index dd1394d..1c909e1 100644
--- a/pylib/gfxprim/backends/backends.i
+++ b/pylib/gfxprim/backends/backends.i
@@ -1,3 +1,4 @@
+%include "../common.i"
%module(package="gfxprim.backends") backends_c
%{
@@ -6,11 +7,6 @@
#include "core/GP_Debug.h"
%}
-#define __attribute__(X)
-%include <stdint.i>
-
-%feature("autodoc");
-
%import ../core/core.i
diff --git a/pylib/gfxprim/common.i b/pylib/gfxprim/common.i
new file mode 100644
index 0000000..0734e1a
--- /dev/null
+++ b/pylib/gfxprim/common.i
@@ -0,0 +1,12 @@
+/*
+ * common SWIG declarations for all modules
+ */
+
+#define __attribute__(X)
+
+%include <stdint.i>
+
+%feature("autodoc");
+
+%nodefaultctor;
+
diff --git a/pylib/gfxprim/core/core.i b/pylib/gfxprim/core/core.i
index 3668c2f..3e1bea5 100644
--- a/pylib/gfxprim/core/core.i
+++ b/pylib/gfxprim/core/core.i
@@ -1,17 +1,10 @@
+%include "../common.i"
%module(package="gfxprim.core") core_c
%{
#include "core/GP_Core.h"
%}
-#define __attribute__(X)
-
-%include <stdint.i>
-
-%feature("autodoc");
-
-%nodefaultctor;
-
/*
* Basic types and common methods
*/
@@ -42,7 +35,6 @@
%import "GP_FnPerBpp.h"
%import "GP_FnPerBpp.gen.h"
-
/*
* GP_Context wrapping
*/
@@ -99,7 +91,6 @@ and self.thisown.") GP_Context;
%include "GP_Context.h"
-
/*
* Context manipulation
*/
@@ -108,3 +99,4 @@ and self.thisown.") GP_Context;
%import "GP_GetPutPixel.gen.h"
%include "GP_WritePixel.h"
%include "GP_Blit.h"
+
diff --git a/pylib/gfxprim/filters/filters.i b/pylib/gfxprim/filters/filters.i
index b617508..9d3e070 100644
--- a/pylib/gfxprim/filters/filters.i
+++ b/pylib/gfxprim/filters/filters.i
@@ -1,17 +1,12 @@
+%include "../common.i"
%module(package="gfxprim.filters") filters_c
%{
#include "filters/GP_Filters.h"
%}
-#define __attribute__(X)
-
%import ../core/core.i
-%include <stdint.i>
-
-%nodefaultctor;
-
%include "GP_Filters.h"
/* Listed in GP_Filters.h: */
diff --git a/pylib/gfxprim/gfx/gfx.i b/pylib/gfxprim/gfx/gfx.i
index 1f59443..eb684da 100644
--- a/pylib/gfxprim/gfx/gfx.i
+++ b/pylib/gfxprim/gfx/gfx.i
@@ -1,17 +1,12 @@
+%include "../common.i"
%module(package="gfxprim.gfx") gfx_c
%{
#include "gfx/GP_Gfx.h"
%}
-#define __attribute__(X)
-
%import ../core/core.i
-%include <stdint.i>
-
-%nodefaultctor;
-
%include "GP_Gfx.h"
/* Listed in GP_Gfx.h: */
diff --git a/pylib/gfxprim/input/input.i b/pylib/gfxprim/input/input.i
index f870e10..a9899a3 100644
--- a/pylib/gfxprim/input/input.i
+++ b/pylib/gfxprim/input/input.i
@@ -1,3 +1,4 @@
+%include "../common.i"
%module(package="gfxprim.input") input_c
%{
diff --git a/pylib/gfxprim/loaders/loaders.i b/pylib/gfxprim/loaders/loaders.i
index 7939dd8..bcfcaef 100644
--- a/pylib/gfxprim/loaders/loaders.i
+++ b/pylib/gfxprim/loaders/loaders.i
@@ -1,3 +1,4 @@
+%include "../common.i"
%module(package="gfxprim.loaders") loaders_c
%{
@@ -5,14 +6,8 @@
#include "loaders/GP_Loaders.h"
%}
-#define __attribute__(X)
-
%import ../core/core.i
-%include <stdint.i>
-
-%nodefaultctor;
-
%include "GP_Loaders.h"
%include "GP_JPG.h"
diff --git a/pylib/gfxprim/text/text.i b/pylib/gfxprim/text/text.i
index 94f8baf..fe40996 100644
--- a/pylib/gfxprim/text/text.i
+++ b/pylib/gfxprim/text/text.i
@@ -1,3 +1,4 @@
+%include "../common.i"
%module(package="gfxprim.text") text_c
%{
@@ -5,14 +6,8 @@
#include "text/GP_Font.h"
%}
-#define __attribute__(X)
-
%import ../core/core.i
-%include <stdint.i>
-
-%nodefaultctor;
-
%ignore GP_GlyphBitmap::bitmap;
%ignore GP_FontFace::glyph_offsets;
%include "GP_Text.h"
-----------------------------------------------------------------------
Summary of changes:
pylib/gfxprim/backends/backends.i | 25 +++++++++++------
pylib/gfxprim/common.i | 53 +++++++++++++++++++++++++++++++++++++
pylib/gfxprim/core/core.i | 23 +++++++++-------
pylib/gfxprim/filters/filters.i | 7 +----
pylib/gfxprim/gfx/gfx.i | 7 +----
pylib/gfxprim/input/input.i | 1 +
pylib/gfxprim/loaders/loaders.i | 41 ++++++++++++++++++++++++----
pylib/gfxprim/text/text.i | 7 +----
8 files changed, 121 insertions(+), 43 deletions(-)
create mode 100644 pylib/gfxprim/common.i
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: 9270ef0f3556aa8a1bd8f4e7191d0813ec5708dc
by metan 03 Jun '12
by metan 03 Jun '12
03 Jun '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 9270ef0f3556aa8a1bd8f4e7191d0813ec5708dc (commit)
from a2a5ee04d3fbbdc6fdcc4c7a932a5b11f3edee49 (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/9270ef0f3556aa8a1bd8f4e7191d0813ec57…
commit 9270ef0f3556aa8a1bd8f4e7191d0813ec5708dc
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Sun Jun 3 21:26:05 2012 +0200
backends: X11, Add CREATE_ROOT mode.
diff --git a/include/backends/GP_X11.h b/include/backends/GP_X11.h
index e03baf4..6d10928 100644
--- a/include/backends/GP_X11.h
+++ b/include/backends/GP_X11.h
@@ -30,6 +30,10 @@ enum GP_BackendX11Flags {
* 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,
};
diff --git a/libs/backends/GP_BackendInit.c b/libs/backends/GP_BackendInit.c
index 316b137..31fd3bf 100644
--- a/libs/backends/GP_BackendInit.c
+++ b/libs/backends/GP_BackendInit.c
@@ -147,6 +147,11 @@ static int x11_params_to_flags(const char *param, GP_Size *w, GP_Size *h,
return 0;
}
+ if (!strcasecmp(param, "CREATE_ROOT")) {
+ *flags |= GP_X11_CREATE_ROOT_WIN;
+ 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 ffc7dca..8b12562 100644
--- a/libs/backends/GP_X11.c
+++ b/libs/backends/GP_X11.c
@@ -29,6 +29,8 @@
#include <X11/Xlib.h>
#include <X11/Xutil.h>
+#include <X11/Xatom.h>
+#include <X11/Xmd.h>
#include "input/GP_InputDriverX11.h"
#include "GP_X11.h"
@@ -264,7 +266,7 @@ void create_window(struct x11_priv *x11, int x, int y,
unsigned long attr_mask = 0;
/* Set event mask */
- attrs.event_mask = ExposureMask | StructureNotifyMask |KeyPressMask |
+ attrs.event_mask = ExposureMask | StructureNotifyMask | KeyPressMask |
KeyReleaseMask | PointerMotionMask;
attr_mask |= CWEventMask;
@@ -281,18 +283,149 @@ void create_window(struct x11_priv *x11, int x, int y,
*w, *h);
XChangeWindowAttributes(x11->dpy, x11->win, attr_mask, &attrs);
-
+
return;
}
- GP_DEBUG(2, "Opening window '%s' %ix%i-%ux%u",
- caption, x, y, *w, *h);
-
/*
* For some reason reading mouse button clicks on root win are not
* allowed...
*/
- attrs.event_mask |= ButtonPressMask | ButtonReleaseMask ;
+ attrs.event_mask |= ButtonPressMask | ButtonReleaseMask;
+
+ /*
+ * Create undecoreated root window on background
+ */
+ if (flags & GP_X11_CREATE_ROOT_WIN) {
+ Atom xa;
+
+ *w = DisplayWidth(x11->dpy, x11->scr);
+ *h = DisplayHeight(x11->dpy, x11->scr);
+
+ GP_DEBUG(2, "Creating a window above root, owerriding size to %ux%u",
+ *w, *h);
+
+ x11->win = XCreateWindow(x11->dpy, DefaultRootWindow(x11->dpy),
+ 0, 0, *w, *h, 0, CopyFromParent,
+ InputOutput, CopyFromParent, attr_mask, &attrs);
+
+ /* Set empty WM_PROTOCOLS */
+ GP_DEBUG(2, "Setting empty MW_PROTOCOLS");
+ XSetWMProtocols(x11->dpy, x11->win, NULL, 0);
+
+ /* Set window type to desktop */
+ xa = XInternAtom(x11->dpy, "_NET_WM_WINDOW_TYPE", False);
+
+ if (xa != None) {
+ GP_DEBUG(2, "Setting Atom _NET_WM_WINDOW_TYPE to _NET_WM_WINDOW_TYPE_DESKTOP");
+
+ Atom xa_prop = XInternAtom(x11->dpy, "_NET_WM_WINDOW_TYPE_DESKTOP", False);
+
+ XChangeProperty(x11->dpy, x11->win, xa, XA_ATOM, 32,
+ PropModeReplace, (unsigned char *) &xa_prop, 1);
+ }
+
+ /* Turn off window decoration */
+ xa = XInternAtom(x11->dpy, "_MOTIF_WM_HINTS", False);
+
+ if (xa != None) {
+ GP_DEBUG(2, "Setting Atom _MOTIF_WM_HINTS to 2, 0, 0, 0, 0");
+
+ long prop[5] = {2, 0, 0, 0, 0};
+
+ XChangeProperty(x11->dpy, x11->win, xa, xa, 32,
+ PropModeReplace, (unsigned char *) prop, 5);
+ }
+
+ /* Set below other windows */
+ xa = XInternAtom(x11->dpy, "_WIN_LAYER", False);
+
+ if (xa != None) {
+ GP_DEBUG(2, "Setting Atom _WIN_LAYER to 6");
+
+ long prop = 6;
+
+ XChangeProperty(x11->dpy, x11->win, xa, XA_CARDINAL, 32,
+ PropModeAppend, (unsigned char *) &prop, 1);
+ }
+
+ xa = XInternAtom(x11->dpy, "_NET_WM_STATE", False);
+
+ if (xa != None) {
+ GP_DEBUG(2, "Setting Atom _NET_WM_STATE to _NET_WM_STATE_BELOW");
+
+ Atom xa_prop = XInternAtom(x11->dpy, "_NET_WM_STATE_BELOW", False);
+
+ XChangeProperty(x11->dpy, x11->win, xa, XA_ATOM, 32,
+ PropModeAppend, (unsigned char *) &xa_prop, 1);
+ }
+
+ /* Set sticky */
+ xa = XInternAtom(x11->dpy, "_NET_WM_DESKTOP", False);
+
+ if (xa != None) {
+ GP_DEBUG(2, "Setting Atom _NET_WM_DESKTOP to 0xffffffff");
+
+ CARD32 xa_prop = 0xffffffff;
+
+ XChangeProperty(x11->dpy, x11->win, xa, XA_CARDINAL, 32,
+ PropModeAppend, (unsigned char *) &xa_prop, 1);
+ }
+
+ xa = XInternAtom(x11->dpy, "_NET_WM_STATE", False);
+
+ if (xa != None) {
+ GP_DEBUG(2, "Appending to Atom _NET_WM_STATE atom _NET_WM_STATE_STICKY");
+
+ Atom xa_prop = XInternAtom(x11->dpy, "_NET_WM_STATE_STICKY", False);
+
+ XChangeProperty(x11->dpy, x11->win, xa, XA_ATOM, 32,
+ PropModeAppend, (unsigned char *) &xa_prop, 1);
+ }
+
+ /* Skip taskbar */
+ xa = XInternAtom(x11->dpy, "_NET_WM_STATE", False);
+
+ if (xa != None) {
+ GP_DEBUG(2, "Appending to Atom _NET_WM_STATE atom _NET_STATE_SKIP_TASKBAR");
+
+ Atom xa_prop = XInternAtom(x11->dpy, "_NET_WM_STATE_SKIP_TASKBAR", False);
+
+ XChangeProperty(x11->dpy, x11->win, xa, XA_ATOM, 32,
+ PropModeAppend, (unsigned char *) &xa_prop, 1);
+ }
+
+ /* Skip pager */
+ xa = XInternAtom(x11->dpy, "_NET_WM_STATE", False);
+
+ if (xa != None) {
+ GP_DEBUG(2, "Appending to Atom _NET_WM_STATE atom _NET_STATE_SKIP_PAGER");
+
+ Atom xa_prop = XInternAtom(x11->dpy, "_NET_WM_STATE_SKIP_PAGER", False);
+
+ XChangeProperty(x11->dpy, x11->win, xa, XA_ATOM, 32,
+ PropModeAppend, (unsigned char *) &xa_prop, 1);
+ }
+
+ /* Set 100% opacity */
+ xa = XInternAtom(x11->dpy, "_NET_WM_WINDOW_OPACITY", False);
+
+ if (xa != None) {
+ GP_DEBUG(2, "Setting Atom _NET_WM_WINDOW_OPACITY to 0xffffffff");
+
+ long prop = 0xffffffff;
+
+ XChangeProperty(x11->dpy, x11->win, xa, XA_CARDINAL, 32,
+ PropModeAppend, (unsigned char *) &prop, 1);
+ }
+
+ /* Show window */
+ XMapWindow(x11->dpy, x11->win);
+ return;
+ }
+
+ GP_DEBUG(2, "Opening window '%s' %ix%i-%ux%u",
+ caption, x, y, *w, *h);
x11->win = XCreateWindow(x11->dpy, DefaultRootWindow(x11->dpy),
x, y, *w, *h, 0, CopyFromParent,
-----------------------------------------------------------------------
Summary of changes:
include/backends/GP_X11.h | 4 +
libs/backends/GP_BackendInit.c | 5 ++
libs/backends/GP_X11.c | 145 ++++++++++++++++++++++++++++++++++++++--
3 files changed, 148 insertions(+), 6 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: a2a5ee04d3fbbdc6fdcc4c7a932a5b11f3edee49
by metan 03 Jun '12
by metan 03 Jun '12
03 Jun '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 a2a5ee04d3fbbdc6fdcc4c7a932a5b11f3edee49 (commit)
from 1ef7dcb59e9b7b131e59c4965e3ce775e8b26de5 (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/a2a5ee04d3fbbdc6fdcc4c7a932a5b11f3ed…
commit a2a5ee04d3fbbdc6fdcc4c7a932a5b11f3edee49
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Sun Jun 3 15:51:08 2012 +0200
doc: Add meta-data examples.
diff --git a/doc/examples.txt b/doc/examples.txt
index 5c426f0..ec356e2 100644
--- a/doc/examples.txt
+++ b/doc/examples.txt
@@ -23,6 +23,19 @@ Example in C utilizing progress callback
include::../demos/c_simple/loaders.c[]
------------------------------------------------------------------
+Example in C using image meta-data interface
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+[source,c]
+------------------------------------------------------------------
+include::../demos/c_simple/meta_data.c[]
+------------------------------------------------------------------
+
+[source,c]
+------------------------------------------------------------------
+include::../demos/c_simple/meta_data_dump.c[]
+------------------------------------------------------------------
+
Example in Python
~~~~~~~~~~~~~~~~~
-----------------------------------------------------------------------
Summary of changes:
doc/examples.txt | 13 +++++++++++++
1 files changed, 13 insertions(+), 0 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: 1ef7dcb59e9b7b131e59c4965e3ce775e8b26de5
by metan 03 Jun '12
by metan 03 Jun '12
03 Jun '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 1ef7dcb59e9b7b131e59c4965e3ce775e8b26de5 (commit)
from c67470e8571d4b391c9c0440b96a9cd1d578fe10 (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/1ef7dcb59e9b7b131e59c4965e3ce775e8b2…
commit 1ef7dcb59e9b7b131e59c4965e3ce775e8b26de5
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Sun Jun 3 15:37:50 2012 +0200
pywrap: Update GP_FilterParam pywrap.
diff --git a/pylib/gfxprim/filters/filters.i b/pylib/gfxprim/filters/filters.i
index 274c765..e12ca55 100644
--- a/pylib/gfxprim/filters/filters.i
+++ b/pylib/gfxprim/filters/filters.i
@@ -15,13 +15,22 @@
%include "GP_Filters.h"
/* Listed in GP_Filters.h: */
-%include "GP_FilterParam.h"
%include "GP_Point.h"
%ignore GP_Histogram::hist;
%include "GP_Stats.h"
%include "GP_Linear.h"
%include "GP_Resize.h"
+%extend GP_FilterParam {
+ ~GP_FilterParam() {
+ GP_DEBUG(2, "[wrapper] GP_FilterParamFree");
+ GP_FilterParamDestroy($self);
+ }
+}
+
+%newobject GP_FilterParamCreate;
+%include "GP_FilterParam.h"
+
/* Functions returning new allocated context */
%immutable GP_FilterSymmetryNames;
-----------------------------------------------------------------------
Summary of changes:
pylib/gfxprim/filters/filters.i | 11 ++++++++++-
1 files changed, 10 insertions(+), 1 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: c67470e8571d4b391c9c0440b96a9cd1d578fe10
by metan 03 Jun '12
by metan 03 Jun '12
03 Jun '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 c67470e8571d4b391c9c0440b96a9cd1d578fe10 (commit)
via a5f35c8236697c090110f3c00875dcec810655f6 (commit)
via 5815d5e6aec94722550bf2a5eb9da1bf3dd8abdf (commit)
from 9ba3f4f318081d8fc506b58a782375d3b36e19b2 (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/c67470e8571d4b391c9c0440b96a9cd1d578…
commit c67470e8571d4b391c9c0440b96a9cd1d578fe10
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Sun Jun 3 15:33:59 2012 +0200
doc: Add GP_FilterParam into filters.
diff --git a/doc/filters.txt b/doc/filters.txt
index 32c9fe0..1abf977 100644
--- a/doc/filters.txt
+++ b/doc/filters.txt
@@ -69,6 +69,148 @@ int GP_FilterFoo_Raw(const GP_Context *src, GP_Context *dst,
GP_ProgressCallback *callback);
-------------------------------------------------------------------------------
+Filter Parameters
+~~~~~~~~~~~~~~~~~
+
+In order to pass, per-channel, filter parameters to a filter, structure called
+GP_FilterParams was created.
+
+[source,c]
+-------------------------------------------------------------------------------
+#include <GP.h>
+/* or */
+#include <filters/GP_FilterParam.h>
+
+typedef union GP_FilterParamVal {
+ float f;
+ uint32_t ui;
+ int32_t i;
+ void *ptr;
+} GP_FilterParamVal;
+
+typedef struct GP_FilterParam {
+ char channel_name[2];
+ union GP_FilterParamVal val;
+} GP_FilterParam;
+-------------------------------------------------------------------------------
+
+Some filters do take an empty channel_name terminated (empty channel_name is
+empty string i.e. "0") array of GP_FilterParam, which is used to describe
+per-channel parameters.
+
+
+There are two methods how to construct GP_FilterParam structure. First one is
+to use macro that expands to a code which declares and initializes the array on
+the stack second uses memory allocated by a malloc(). In both cases the
+structure is has initialized channel names and terminator.
+
+[source,c]
+-------------------------------------------------------------------------------
+#include <GP.h>
+/* or */
+#include <filters/GP_FilterParam.h>
+
+#define GP_FILTER_PARAMS(pixel_type, name) + GP_FilterParam name[GP_PixelTypes[pixel_type].numchannels + 1]; + GP_FilterParamInitChannels(name, pixel_type);
+-------------------------------------------------------------------------------
+
+Macro that declares and initializes GP_FilterParam structure for a given
+pixel_type.
+
+[source,c]
+-------------------------------------------------------------------------------
+#include <GP.h>
+/* or */
+#include <filters/GP_FilterParam.h>
+
+GP_FilterParam *GP_FilterParamCreate(GP_PixelType pixel_type);
+
+void GP_FilterParamDestroy(GP_FilterParam *self);
+-------------------------------------------------------------------------------
+
+Second possible way allocates memory using malloc().
+
+Functions for manipulating and querying existing GP_FilterParam follows.
+
+[source,c]
+-------------------------------------------------------------------------------
+#include <GP.h>
+/* or */
+#include <filters/GP_FilterParam.h>
+
+void GP_FilterParamInitChannels(GP_FilterParam params[],
+ GP_PixelType pixel_type);
+-------------------------------------------------------------------------------
+
+Initializes filter param array channel names (accordingly to pixel type) and
+terminator. The params array must be large enough to hold number of pixel type
+channels plus one.
+
+[source,c]
+-------------------------------------------------------------------------------
+#include <GP.h>
+/* or */
+#include <filters/GP_FilterParam.h>
+
+GP_FilterParam *GP_FilterParamChannel(GP_FilterParam params[],
+ const char *channel_name);
+-------------------------------------------------------------------------------
+
+Does lookup for a given channel name and returns, if found, corresponding
+GP_FilterParam, otherwise 'NULL' is returned.
+
+This function is primary used in filters, where filter, at the start, resolves
+all it's parameters.
+
+[source,c]
+-------------------------------------------------------------------------------
+#include <GP.h>
+/* or */
+#include <filters/GP_FilterParam.h>
+
+int GP_FilterParamCheckPixelType(GP_FilterParam params[],
+ GP_PixelType pixel_type);
+-------------------------------------------------------------------------------
+
+Matches param structure against pixel_type. Returns zero if params describes
+exactly same channels like pixel_type, non-zero otherwise.
+
+[source,c]
+-------------------------------------------------------------------------------
+#include <GP.h>
+/* or */
+#include <filters/GP_FilterParam.h>
+
+void GP_FilterParamSetIntAll(GP_FilterParam params[], int32_t val);
+
+int GP_FilterParamSetInt(GP_FilterParam params[], const char *channel_name,
+ int32_t val);
+
+void GP_FilterParamSetFloatAll(GP_FilterParam params[], float val);
+
+int GP_FilterParamSetFloat(GP_FilterParam params[], const char *channel_name,
+ float val);
+
+void GP_FilterParamSetUIntAll(GP_FilterParam params[], uint32_t val);
+
+int GP_FilterParamSetUInt(GP_FilterParam params[], const char *channel_name,
+ uint32_t val);
+
+void GP_FilterParamSetPtrAll(GP_FilterParam params[], void *ptr);
+
+int GP_FilterParamSetPtr(GP_FilterParam params[], const char *channel_name,
+ void *ptr);
+
+void GP_FilterParamFreePtrAll(GP_FilterParam params[]);
+-------------------------------------------------------------------------------
+
+Parameter setters. Those that sets individual value returns zero on success
+(i.e. channel was found) and non-zero otherwise.
+
+The last one calls free() on all param pointers, which is used to free
+allocate memory.
+
Point operation filters
~~~~~~~~~~~~~~~~~~~~~~~
http://repo.or.cz/w/gfxprim.git/commit/a5f35c8236697c090110f3c00875dcec8106…
commit a5f35c8236697c090110f3c00875dcec810655f6
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Sun Jun 3 15:31:48 2012 +0200
filters: Cleanup GP_FilterParams API a little.
diff --git a/include/filters/GP_FilterParam.h b/include/filters/GP_FilterParam.h
index 892f166..6520354 100644
--- a/include/filters/GP_FilterParam.h
+++ b/include/filters/GP_FilterParam.h
@@ -16,7 +16,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, *
* Boston, MA 02110-1301 USA *
* *
- * Copyright (C) 2009-2011 Cyril Hrubis <metan(a)ucw.cz> *
+ * Copyright (C) 2009-2012 Cyril Hrubis <metan(a)ucw.cz> *
* *
*****************************************************************************/
@@ -46,14 +46,27 @@ typedef union GP_FilterParamVal {
* Filter takes, empty channel name terminated, arrray of these as parameter.
*/
typedef struct GP_FilterParam {
- //TODO: this must be >= for maximal channel name (now it's 2)
+ //TODO: this must be > than maximal channel name (now it's 2)
char channel_name[2];
union GP_FilterParamVal val;
} GP_FilterParam;
/*
- * Takes array of filter parameters and returns channel.
+ * Creates filter param structure large enough for given pixel_type.
*
+ * The returned structure has initalized channel_names and terminator.
+ */
+GP_FilterParam *GP_FilterParamCreate(GP_PixelType pixel_type);
+
+/*
+ * Destroys filter param structure.
+ */
+void GP_FilterParamDestroy(GP_FilterParam *self);
+
+/*
+ * Takes array of filter parameters and returns filter parameter by a channel
+ * name.
+ *
* Returns NULL if channel wasn't found.
*/
GP_FilterParam *GP_FilterParamChannel(GP_FilterParam params[],
@@ -69,7 +82,7 @@ uint32_t GP_FilterParamChannels(GP_FilterParam params[]);
* match.
*/
int GP_FilterParamCheckPixelType(GP_FilterParam params[],
- GP_PixelType type);
+ GP_PixelType pixel_type);
/*
* Returns zero only if params have exactly same channels as array of
@@ -85,53 +98,59 @@ int GP_FilterParamCheckChannels(GP_FilterParam params[],
GP_FilterParam name[GP_PixelTypes[pixel_type].numchannels + 1]; GP_FilterParamInitChannels(name, pixel_type);
-#define GP_FILTER_PARAMS_INT(pixel_type, name, val) - GP_FILTER_PARAMS(pixel_type, name) - GP_FilterParamSetIntAll(name, val);
-
-#define GP_FILTER_PARAMS_UINT(pixel_type, name, val) - GP_FILTER_PARAMS(pixel_type, name) - GP_FilterParamSetUIntAll(name, val);
-
-#define GP_FILTER_PARAMS_FLOAT(pixel_type, name, val) - GP_FILTER_PARAMS(pixel_type, name) - GP_FilterParamSetFloatAll(name, val);
-
-#define GP_FILTER_PARAMS_PTR(pixel_type, name, ptr) - GP_FILTER_PARAMS(pixel_type, name) - GP_FilterParamSetPtrAll(name, ptr);
-
/*
* Initalize param names and terminator.
*
* Sets all values to 0.
*/
void GP_FilterParamInitChannels(GP_FilterParam params[],
- GP_PixelType type);
+ GP_PixelType pixel_type);
/*
* Sets all values to integer value.
*/
-void GP_FilterParamSetIntAll(GP_FilterParam params[],
- int32_t val);
+void GP_FilterParamSetIntAll(GP_FilterParam params[], int32_t val);
+
+/*
+ * Sets integer value. Returns 0 if such value was found, non-zero otherwise.
+ */
+int GP_FilterParamSetInt(GP_FilterParam params[], const char *channel_name,
+ int32_t val);
/*
* Sets all values to float value.
*/
-void GP_FilterParamSetFloatAll(GP_FilterParam params[],
- float val);
+void GP_FilterParamSetFloatAll(GP_FilterParam params[], float val);
+
+/*
+ * Sets float value. Returns 0 if such value was found, non-zero otherwise.
+ */
+int GP_FilterParamSetFloat(GP_FilterParam params[], const char *channel_name,
+ float val);
/*
* Sets all values to unsigned integer value.
*/
-void GP_FilterParamSetUIntAll(GP_FilterParam params[],
- uint32_t val);
+void GP_FilterParamSetUIntAll(GP_FilterParam params[], uint32_t val);
+
+/*
+ * Sets unsigned integer value. Returns 0 if such value was found, non-zero
+ * otherwise.
+ */
+int GP_FilterParamSetUInt(GP_FilterParam params[], const char *channel_name,
+ uint32_t val);
/*
* Sets all values to pointer value.
*/
-void GP_FilterParamSetPtrAll(GP_FilterParam params[],
- void *ptr);
+void GP_FilterParamSetPtrAll(GP_FilterParam params[], void *ptr);
+
+/*
+ * Sets pointer value. Returns 0 if such value was found, non-zero otherwise.
+ */
+int GP_FilterParamSetPtr(GP_FilterParam params[], const char *channel_name,
+ void *ptr);
+
/*
* Call free on all pointer values.
*/
diff --git a/libs/filters/GP_FilterParam.c b/libs/filters/GP_FilterParam.c
index e968a4b..e6c0f6b 100644
--- a/libs/filters/GP_FilterParam.c
+++ b/libs/filters/GP_FilterParam.c
@@ -16,16 +16,38 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, *
* Boston, MA 02110-1301 USA *
* *
- * Copyright (C) 2009-2011 Cyril Hrubis <metan(a)ucw.cz> *
+ * Copyright (C) 2009-2012 Cyril Hrubis <metan(a)ucw.cz> *
* *
*****************************************************************************/
#include <string.h>
-#include <GP_Debug.h>
+#include "core/GP_Debug.h"
#include "GP_FilterParam.h"
+GP_FilterParam *GP_FilterParamCreate(GP_PixelType pixel_type)
+{
+ GP_FilterParam *ret;
+
+ ret = malloc((GP_PixelTypes[pixel_type].numchannels + 1)
+ * sizeof(GP_FilterParam));
+
+ if (ret == NULL) {
+ GP_WARN("Malloc Failed");
+ return NULL;
+ }
+
+ GP_FilterParamInitChannels(ret, pixel_type);
+
+ return ret;
+}
+
+void GP_FilterParamDestroy(GP_FilterParam *self)
+{
+ free(self);
+}
+
static unsigned int count_channels(GP_FilterParam params[])
{
unsigned int i = 0;
@@ -115,6 +137,19 @@ void GP_FilterParamSetIntAll(GP_FilterParam params[],
params[i].val.i = val;
}
+int GP_FilterParamSetInt(GP_FilterParam params[], const char *channel_name,
+ int32_t val)
+{
+ GP_FilterParam *param;
+ param = GP_FilterParamChannel(params, channel_name);
+
+ if (param == NULL)
+ return 1;
+
+ param->val.i = val;
+ return 0;
+}
+
void GP_FilterParamSetFloatAll(GP_FilterParam params[],
float val)
{
@@ -124,6 +159,19 @@ void GP_FilterParamSetFloatAll(GP_FilterParam params[],
params[i].val.f = val;
}
+int GP_FilterParamSetFloat(GP_FilterParam params[], const char *channel_name,
+ float val)
+{
+ GP_FilterParam *param;
+ param = GP_FilterParamChannel(params, channel_name);
+
+ if (param == NULL)
+ return 1;
+
+ param->val.f = val;
+ return 0;
+}
+
void GP_FilterParamSetUIntAll(GP_FilterParam params[],
uint32_t val)
{
@@ -133,6 +181,19 @@ void GP_FilterParamSetUIntAll(GP_FilterParam params[],
params[i].val.ui = val;
}
+int GP_FilterParamSetUInt(GP_FilterParam params[], const char *channel_name,
+ uint32_t val)
+{
+ GP_FilterParam *param;
+ param = GP_FilterParamChannel(params, channel_name);
+
+ if (param == NULL)
+ return 1;
+
+ param->val.ui = val;
+ return 0;
+}
+
void GP_FilterParamSetPtrAll(GP_FilterParam params[],
void *ptr)
{
@@ -142,6 +203,19 @@ void GP_FilterParamSetPtrAll(GP_FilterParam params[],
params[i].val.ptr = ptr;
}
+int GP_FilterParamSetPtr(GP_FilterParam params[], const char *channel_name,
+ void *ptr)
+{
+ GP_FilterParam *param;
+ param = GP_FilterParamChannel(params, channel_name);
+
+ if (param == NULL)
+ return 1;
+
+ param->val.ptr = ptr;
+ return 0;
+}
+
void GP_FilterParamFreePtrAll(GP_FilterParam params[])
{
unsigned int i;
diff --git a/tests/SDL/showimage.c b/tests/SDL/showimage.c
index 90bc393..a63ba78 100644
--- a/tests/SDL/showimage.c
+++ b/tests/SDL/showimage.c
@@ -51,7 +51,8 @@ void event_loop(void)
case SDLK_DOWN: {
brightness-=1;
- GP_FILTER_PARAMS_INT(bitmap->pixel_type, param, brightness);
+ GP_FILTER_PARAMS(bitmap->pixel_type, param);
+ GP_FilterParamSetIntAll(param, brightness);
res = GP_FilterBrightness(bitmap, NULL, param, NULL);
printf("brightness = %i %ux%un", brightness, res->w, res->h);
http://repo.or.cz/w/gfxprim.git/commit/5815d5e6aec94722550bf2a5eb9da1bf3dd8…
commit 5815d5e6aec94722550bf2a5eb9da1bf3dd8abdf
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Sun Jun 3 13:57:30 2012 +0200
doc: Update common filter API example.
diff --git a/doc/filters.txt b/doc/filters.txt
index 9329361..32c9fe0 100644
--- a/doc/filters.txt
+++ b/doc/filters.txt
@@ -41,17 +41,21 @@ as arguments.
/*
* Filter common API.
*/
-GP_Context *GP_FilterFoo(const GP_Context *src, GP_Context *dst,
- foo params ...,
- GP_ProgressCallback *callback);
+int GP_FilterFoo(const GP_Context *src, GP_Context *dst,
+ foo params ...,
+ GP_ProgressCallback *callback);
+
+GP_Context *GP_FilterFooAlloc(const GP_Context *src,
+ foo params ...,
+ GP_ProgressCallback *callback);
-------------------------------------------------------------------------------
-Filters also exists in _Raw variant (that just takes source context,
-destination context, filters parameters and progress callback). These filter
-APIs are used for internal implementation and shouldn't be called by user as
-the destination is expected to be crafted exactly for storing the filter
-result and there are 'NO' sanity checks in place.
+Filters also exists in _Raw variant whose interface is similar to the first
+type of filter function. These filter APIs are used for internal
+implementation and shouldn't be called by user as the destination is expected
+to be crafted exactly for storing the filter result and there are 'NO' sanity
+checks in place.
'You could use these at your own risk'
@@ -60,9 +64,9 @@ result and there are 'NO' sanity checks in place.
/*
* Raw filter common API.
*/
-void GP_FilterFoo_Raw(const GP_Context *src, GP_Context *dst,
- foo params ...,
- GP_ProgressCallback *callback);
+int GP_FilterFoo_Raw(const GP_Context *src, GP_Context *dst,
+ foo params ...,
+ GP_ProgressCallback *callback);
-------------------------------------------------------------------------------
Point operation filters
-----------------------------------------------------------------------
Summary of changes:
doc/filters.txt | 168 +++++++++++++++++++++++++++++++++++---
include/filters/GP_FilterParam.h | 77 +++++++++++-------
libs/filters/GP_FilterParam.c | 78 +++++++++++++++++-
tests/SDL/showimage.c | 3 +-
4 files changed, 283 insertions(+), 43 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: 9ba3f4f318081d8fc506b58a782375d3b36e19b2
by metan 03 Jun '12
by metan 03 Jun '12
03 Jun '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 9ba3f4f318081d8fc506b58a782375d3b36e19b2 (commit)
from 4c2a2fda5d4751fdc40f987c9aa8b80197b79f6b (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/9ba3f4f318081d8fc506b58a782375d3b36e…
commit 9ba3f4f318081d8fc506b58a782375d3b36e19b2
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Sun Jun 3 13:40:41 2012 +0200
pywrap: Update list of newobject filters.
diff --git a/pylib/gfxprim/filters/filters.i b/pylib/gfxprim/filters/filters.i
index 866ea9b..274c765 100644
--- a/pylib/gfxprim/filters/filters.i
+++ b/pylib/gfxprim/filters/filters.i
@@ -17,7 +17,6 @@
/* Listed in GP_Filters.h: */
%include "GP_FilterParam.h"
%include "GP_Point.h"
-%include "GP_Arithmetic.h"
%ignore GP_Histogram::hist;
%include "GP_Stats.h"
%include "GP_Linear.h"
@@ -26,16 +25,22 @@
/* Functions returning new allocated context */
%immutable GP_FilterSymmetryNames;
-%include "GP_Rotate.h"
-
%newobject GP_FilterMirrorH_Alloc;
%newobject GP_FilterMirrorV_Alloc;
%newobject GP_FilterRotate90_Alloc;
%newobject GP_FilterRotate180_Alloc;
%newobject GP_FilterRotate270_Alloc;
%newobject GP_FilterSymmetry_Alloc;
+%include "GP_Rotate.h"
-%include "GP_Dither.h"
%newobject GP_FilterFloydSteinberg_RGB888_Alloc;
%newobject GP_FilterHilbertPeano_RGB888_Alloc;
+%include "GP_Dither.h"
+
+%newobject GP_FilterAdditionAlloc;
+%newobject GP_FilterMultiplyAlloc;
+%newobject GP_FilterDifferenceAlloc;
+%newobject GP_FilterMaxAlloc;
+%newobject GP_FilterMinAlloc;
+%include "GP_Arithmetic.h"
-----------------------------------------------------------------------
Summary of changes:
pylib/gfxprim/filters/filters.i | 13 +++++++++----
1 files changed, 9 insertions(+), 4 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