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
November 2011
- 3 participants
- 52 discussions
[repo.or.cz] gfxprim.git branch master updated: 4e46a97e8f7fab77c38ac3f2c3f3620ea7ea3aeb
by bluebear 06 Nov '11
by bluebear 06 Nov '11
06 Nov '11
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 4e46a97e8f7fab77c38ac3f2c3f3620ea7ea3aeb (commit)
from 87668c03813dbb86473d1080c58810a60e56f8f8 (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/4e46a97e8f7fab77c38ac3f2c3f3620ea7ea…
commit 4e46a97e8f7fab77c38ac3f2c3f3620ea7ea3aeb
Author: BlueBear <jiri.bluebear.dluhos(a)gmail.com>
Date: Sun Nov 6 17:22:10 2011 +0100
Fixed some typos in documentation.
diff --git a/doc/filters.txt b/doc/filters.txt
index af8e467..066d04c 100644
--- a/doc/filters.txt
+++ b/doc/filters.txt
@@ -3,7 +3,7 @@ Context filters
Pixel filters for 'GP_Context'.
-The context filter is basially an function that operates on context pixels.
+The context filter is basically a function that operates on context pixels.
The result may be stored into a new bitmap or placed to bitmap passed as
argument or, in some cases, the filter could be used 'in place' so the result
is stored into the same context as the one passed as filter source.
@@ -11,7 +11,7 @@ is stored into the same context as the one passed as filter source.
Common filter API
~~~~~~~~~~~~~~~~~
-The filters have, for your convinience unified API.
+For convenience, the filters API is unified:
* Each filter returns pointer to destination context or 'NULL' on failure
* The first two arguments are source and destination
@@ -19,13 +19,13 @@ The filters have, for your convinience unified API.
Each filter function could be used in two modes.
-By passing non 'NULL' argument as filter destination user requests result to
+By passing non-'NULL' argument as filter destination user requests result to
be stored into the destination context. The context must have correct pixel
type and the context size must be big enough to store the result.
-For filters that works 'in-place' (which is explicitly said for each filter)
+For filters that work 'in-place' (which is explicitly said for each filter)
the source and the destination could be the same context. Note that this is
-not expected to work if you do several overlaping subcontextes and pass these
+not expected to work if you do several overlaping subcontexts and pass these
as arguments.
When 'NULL' is passed as destination new context for storing the result is
@@ -148,7 +148,7 @@ Rotate context by 90 degrees.
Doesn't work 'in-place' (yet).
-The destinatoin has to have the same pixel type and destination size must be
+The destination has to have the same pixel type and destination size must be
big enough to fit rotated context (eg. W and H are swapped).
[source,c]
@@ -252,8 +252,8 @@ destination defined by 'w' and 'h'.
Nearest Neighbour Interpolation
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-Fast, but produces "pixelated" images may however work better for images with
-sharp edges mostly consisting of big one colour regions (eg. doesn't blur the
+Fast, but produces "pixelated" images. May however work better for images with
+sharp edges mostly consisting of big one colour regions (it doesn't blur the
result on upscaling).
Bicubic Interpolation
@@ -261,7 +261,7 @@ Bicubic Interpolation
Works well as is on image upscaling. To get decent result on downscaling
low-pass filter (gaussian blur) must be used on original image before actuall
-downscaling. To do this reasonably fast we could cheat a little first resize
-big images a little without the low-past filter, then apply low-pass filter and
+downscaling. To do this reasonably fast we could cheat a little: first resize
+big images a little without the low-pass filter, then apply low-pass filter and
finally downscale it to desired size.
diff --git a/doc/loaders.txt b/doc/loaders.txt
index 73a6b28..7a752e8 100644
--- a/doc/loaders.txt
+++ b/doc/loaders.txt
@@ -36,7 +36,7 @@ Opens file and checks for 'PNG' signature upon successful return (file could
be opened, signature matches), the opened file is returned and the file
possition points right after the end of the 'PNG' signature.
-This function is semi-internal, you should rather use functions listed bellow.
+This function is semi-internal, you should rather use functions listed below.
[source,c]
-------------------------------------------------------------------------------
@@ -71,7 +71,7 @@ GP_RetCode GP_SavePNG(const char *dst_path, GP_Context *src,
-------------------------------------------------------------------------------
Writes a Context into a 'PNG' image. If aborted by a callback, the opened file
-is closed and unliked before the call returns 'GP_EINTR'.
+is closed and removed before the call returns 'GP_EINTR'.
Currently only 'RGB888' format is supported, you should convert the GP_Context
to 'RGB888' before calling this function otherwise 'GP_ENOIMPL' will be
@@ -93,7 +93,7 @@ Opens file and checks for 'JPG' signature upon successful return (file could
be opened, signature matches), the opened file is returned and the file
possition points right after the end of the 'JPG' signature.
-This function is semi-internal, you should rather use functions listed bellow.
+This function is semi-internal, you should rather use functions listed below.
'TODO:' This is not finished yet, currently this just opens and returns the
file and the 'GP_ReadJPG()' reads the signature instead.
@@ -120,7 +120,7 @@ GP_RetCode GP_LoadJPG(const char *src_path, GP_Context **res,
-------------------------------------------------------------------------------
Same as abowe but takes path to the file as a parameter and check for the
-signature. Basically this combines both of the calls abowe.
+signature. Basically this combines both of the calls above.
[source,c]
-------------------------------------------------------------------------------
@@ -131,7 +131,7 @@ GP_RetCode GP_SaveJPG(const char *dst_path, GP_Context *src,
-------------------------------------------------------------------------------
Writes a Context into a 'JPG' image. If aborted by a callback, the opened file
-is closed and unliked before the call returns 'GP_EINTR'.
+is closed and removed before the call returns 'GP_EINTR'.
The 'JPG' format could store either 'G8' or 'RGB888' pixeltypes and you must
convert the context into one of them before this fucntions is called.
-----------------------------------------------------------------------
Summary of changes:
doc/filters.txt | 20 ++++++++++----------
doc/loaders.txt | 10 +++++-----
2 files changed, 15 insertions(+), 15 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: 87668c03813dbb86473d1080c58810a60e56f8f8
by metan 06 Nov '11
by metan 06 Nov '11
06 Nov '11
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 87668c03813dbb86473d1080c58810a60e56f8f8 (commit)
via 73686098d636fbfd72a4ae5b3bb8d2e0c241ba80 (commit)
from 025f1bba56285d57ebab61325415cd2c07a0073c (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/87668c03813dbb86473d1080c58810a60e56…
commit 87668c03813dbb86473d1080c58810a60e56f8f8
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Sun Nov 6 14:24:12 2011 +0100
doc: Fixed basic types and moved progress callback docs.
diff --git a/doc/basic_types.txt b/doc/basic_types.txt
index efc9c7b..8f7283c 100644
--- a/doc/basic_types.txt
+++ b/doc/basic_types.txt
@@ -19,7 +19,8 @@ typedef enum GP_RetCode {
GP_EBADFILE, /* error in file, or bad file format */
GP_ENOENT, /* no such file or another object */
GP_ENOMEM, /* not enough memory */
- GP_EMAX,
+ GP_EINTR, /* interrupted by a callback */
+ GP_EMAX,
} GP_RetCode;
--------------------------------------------------------------------------------
@@ -35,7 +36,6 @@ Coord and Size
For drawing API there are two integer types defined the 'GP_Coord' for
coordinates and 'GP_Size' for size, length or so.
-
Color and pixel types
~~~~~~~~~~~~~~~~~~~~~
@@ -58,6 +58,7 @@ typedef enum GP_Color {
GP_COL_INVALID = -1,
GP_COL_BLACK,
...
+ GP_COL_MAX,
} GP_Color;
--------------------------------------------------------------------------------
@@ -66,15 +67,62 @@ successful match and conversion and false otherwise.
[source,c]
--------------------------------------------------------------------------------
-#include <core/GP_Color.h>
+#include <GP_Color.h>
-GP_Pixel GP_ColorToPixel(GP_Context *context, GP_Color color);
+GP_Pixel GP_ColorToPixel(GP_Color color, GP_PixelType pixel_type);
+GP_Pixel GP_ColorToContextPixel(GP_Color color, GP_Context *context);
GP_Color GP_ColorNameToColor(const char *color_name);
-
const char *GP_ColorToColorName(GP_Color color);
-bool GP_ColorNameToPixel(GP_Context *context, const char *color_name,
+bool GP_ColorNameToPixel(const char *color_name, GP_PixelType pixel_type,
GP_Pixel *pixel);
+bool GP_ColorNameToContextPixel(const char *color_name, GP_Context *context,
+ GP_Pixel *pixel);
+--------------------------------------------------------------------------------
+
+Functions to convert color to pixel and color to context pixel. The last two
+returns true if color with such name was found.
+
+[source,c]
+--------------------------------------------------------------------------------
+#include <GP_Color.h>
+
+void GP_ColorLoadPixels(GP_Pixel pixels[], GP_PixelType pixel_type);
+void GP_ColorLoadContextPixels(GP_Pixel pixels[], GP_Context *context);
--------------------------------------------------------------------------------
+Loads array of 'GP_Pixel' of size 'GP_COL_MAX', the array is then used with
+the GP_Color enum as 'pixels[GP_COL_BLACK]'.
+
+Progress Callback
+~~~~~~~~~~~~~~~~~
+
+Progress callback is a structure that stores user-defined callback function,
+pointer to store location of user data and percentage.
+
+It is passed as last parameter to functions that could take some time to
+complete and adds capability to track the operation progress as well as to
+abort the operation.
+
+Currently it's used for filters and loaders.
+
+[source,c]
+-------------------------------------------------------------------------------
+typdedef struct GP_ProgressCallback {
+ float percentage;
+ int (*callback)(struct GP_ProgressCallback *self);
+ void *priv;
+} GP_ProgressCallback;
+-------------------------------------------------------------------------------
+
+If non 'NULL' progress callback structure is passed to a function, the
+callback function is periodically called and the percentage is updated.
+
+The return value from callback could abort the function execution. If non zero
+value is returned the filter is aborted, all memory freed etc. and the
+function either returns 'NULL' if pointer is returned or 'GP_EINTR' in case
+filter returns 'GP_RetCode'.
+
+The callback, if supported, is the last parameter of a function.
+
diff --git a/doc/filters.txt b/doc/filters.txt
index c189599..af8e467 100644
--- a/doc/filters.txt
+++ b/doc/filters.txt
@@ -8,31 +8,6 @@ The result may be stored into a new bitmap or placed to bitmap passed as
argument or, in some cases, the filter could be used 'in place' so the result
is stored into the same context as the one passed as filter source.
-Progress Callback
-~~~~~~~~~~~~~~~~~
-
-Progress callback is a structure that stores user-defined callback function,
-pointer to store location of user data and percentage.
-
-[source,c]
--------------------------------------------------------------------------------
-typdedef struct GP_ProgressCallback {
- float percentage;
- int (*callback)(struct GP_ProgressCallback *self);
- void *priv;
-} GP_ProgressCallback;
--------------------------------------------------------------------------------
-
-If non 'NULL' progress callback structure is passed to a filter function, the
-callback function is periodically called and the percentage is updated.
-
-The return value from callback could abort the filter execution. If non zero
-value is returned the filter is aborted, all memory freed etc. and the filter
-either returns 'NULL' if pointer is returned or 'GP_EINTR' in case filter
-returns 'GP_RetCode'.
-
-The callback, if supported, is the last parameter of the filter function.
-
Common filter API
~~~~~~~~~~~~~~~~~
http://repo.or.cz/w/gfxprim.git/commit/73686098d636fbfd72a4ae5b3bb8d2e0c241…
commit 73686098d636fbfd72a4ae5b3bb8d2e0c241ba80
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Sun Nov 6 14:17:31 2011 +0100
core: Fix typo in color API.
diff --git a/include/core/GP_Color.h b/include/core/GP_Color.h
index 4e39e07..514fe82 100644
--- a/include/core/GP_Color.h
+++ b/include/core/GP_Color.h
@@ -94,11 +94,11 @@ bool GP_ColorNameToPixel(const char *color_name, GP_PixelType pixel_type,
*
* Returns true if conversion was successful false otherwise.
*/
-static inline bool GP_ColorNameContextToPixel(const char *color_name,
- GP_PixelType pixel_type,
- GP_Pixel *pixel)
+static inline bool GP_ColorNameToContextPixel(const char *color_name,
+ GP_Context *context,
+ GP_Pixel *pixel)
{
- return GP_ColorNameToPixel(color_name, pixel_type, pixel);
+ return GP_ColorNameToPixel(color_name, context->pixel_type, pixel);
}
/*
-----------------------------------------------------------------------
Summary of changes:
doc/basic_types.txt | 60 ++++++++++++++++++++++++++++++++++++++++++----
doc/filters.txt | 25 -------------------
include/core/GP_Color.h | 8 +++---
3 files changed, 58 insertions(+), 35 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: 025f1bba56285d57ebab61325415cd2c07a0073c
by metan 06 Nov '11
by metan 06 Nov '11
06 Nov '11
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 025f1bba56285d57ebab61325415cd2c07a0073c (commit)
from fa647eaeeb44a5b63a6f2141f3ced35ccf27364a (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/025f1bba56285d57ebab61325415cd2c07a0…
commit 025f1bba56285d57ebab61325415cd2c07a0073c
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Sun Nov 6 14:06:42 2011 +0100
doc: added basic documentation for JPG and PNG loaders.
diff --git a/doc/loaders.txt b/doc/loaders.txt
index a086213..73a6b28 100644
--- a/doc/loaders.txt
+++ b/doc/loaders.txt
@@ -1,6 +1,142 @@
Context loaders
---------------
-Loaders are functions GP_Context from various file formats.
+This part of gfxprim library aims to create API to load/save images from/to
+common image fileformats.
+
+Common Loader
+~~~~~~~~~~~~~
+
+[source,c]
+-------------------------------------------------------------------------------
+#include <GP_Loaders.h>
+
+GP_RetCode GP_LoadImage(const char *src_path, GP_Context **res,
+ GP_ProgressCallback *callback);
+-------------------------------------------------------------------------------
+
+Loads image from a file. The image format is now recognized by the file
+filename extension. Format detection using file signature is planned.
+
+The loading process could be aborted by process callback.
+
+PNG
+~~~
+
+Just now, the 'PNG' support is not fully finished, the Alpha channel as well
+as palletes doesn't work well or at all, we are working on that.
+
+[source,c]
+-------------------------------------------------------------------------------
+#include <GP_Loaders.h>
+
+GP_RetCode GP_OpenPNG(const char *src, FILE **f);
+-------------------------------------------------------------------------------
+
+Opens file and checks for 'PNG' signature upon successful return (file could
+be opened, signature matches), the opened file is returned and the file
+possition points right after the end of the 'PNG' signature.
+
+This function is semi-internal, you should rather use functions listed bellow.
+
+[source,c]
+-------------------------------------------------------------------------------
+#include <GP_Loaders.h>
+
+GP_RetCode GP_ReadPNG(FILE *f, GP_Context **res,
+ GP_ProgressCallback *callback);
+-------------------------------------------------------------------------------
+
+Loads 'PNG' file into context the file pointer must point to the start of the
+'PNG' data stream (eg. should point right after the signature). The context,
+to store the image to, is allocated. The loading process could by aborted by a
+callback, in such case all memory is freed and the call returns 'GP_EINTR'.
+
+[source,c]
+-------------------------------------------------------------------------------
+#include <GP_Loaders.h>
+
+GP_RetCode GP_LoadPNG(const char *src_path, GP_Context **res,
+ GP_ProgressCallback *callback);
+-------------------------------------------------------------------------------
+
+Same as abowe but takes path to the file as a parameter and check for the
+signature. Basically this combines both of the calls abowe.
+
+[source,c]
+-------------------------------------------------------------------------------
+#include <GP_Loaders.h>
+
+GP_RetCode GP_SavePNG(const char *dst_path, GP_Context *src,
+ GP_ProgressCallback *callback);
+-------------------------------------------------------------------------------
+
+Writes a Context into a 'PNG' image. If aborted by a callback, the opened file
+is closed and unliked before the call returns 'GP_EINTR'.
+
+Currently only 'RGB888' format is supported, you should convert the GP_Context
+to 'RGB888' before calling this function otherwise 'GP_ENOIMPL' will be
+returned.
+
+JPG
+~~~
+
+The 'JPG' format is supported for both 'G8' as well as 'RGB888' pixel formats.
+
+[source,c]
+-------------------------------------------------------------------------------
+#include <GP_Loaders.h>
+
+GP_RetCode GP_OpenJPG(const char *src, FILE **f);
+-------------------------------------------------------------------------------
+
+Opens file and checks for 'JPG' signature upon successful return (file could
+be opened, signature matches), the opened file is returned and the file
+possition points right after the end of the 'JPG' signature.
+
+This function is semi-internal, you should rather use functions listed bellow.
+
+'TODO:' This is not finished yet, currently this just opens and returns the
+file and the 'GP_ReadJPG()' reads the signature instead.
+
+[source,c]
+-------------------------------------------------------------------------------
+#include <GP_Loaders.h>
+
+GP_RetCode GP_ReadJPG(FILE *f, GP_Context **res,
+ GP_ProgressCallback *callback);
+-------------------------------------------------------------------------------
+
+Loads 'JPG' file into context the file pointer must point to the start of the
+'JPG' data stream (eg. should point right after the signature). The context, to
+store the image to, is allocated. The loading process could by aborted by a
+callback, in such case all memory is freed and the call returns 'GP_EINTR'.
+
+[source,c]
+-------------------------------------------------------------------------------
+#include <GP_Loaders.h>
+
+GP_RetCode GP_LoadJPG(const char *src_path, GP_Context **res,
+ GP_ProgressCallback *callback);
+-------------------------------------------------------------------------------
+
+Same as abowe but takes path to the file as a parameter and check for the
+signature. Basically this combines both of the calls abowe.
+
+[source,c]
+-------------------------------------------------------------------------------
+#include <GP_Loaders.h>
+
+GP_RetCode GP_SaveJPG(const char *dst_path, GP_Context *src,
+ GP_ProgressCallback *callback);
+-------------------------------------------------------------------------------
+
+Writes a Context into a 'JPG' image. If aborted by a callback, the opened file
+is closed and unliked before the call returns 'GP_EINTR'.
+
+The 'JPG' format could store either 'G8' or 'RGB888' pixeltypes and you must
+convert the context into one of them before this fucntions is called.
+
+'TODO:' add parameters to change the encoding settings.
PBM
~~~
-----------------------------------------------------------------------
Summary of changes:
doc/loaders.txt | 138 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 137 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: fa647eaeeb44a5b63a6f2141f3ced35ccf27364a
by metan 06 Nov '11
by metan 06 Nov '11
06 Nov '11
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 fa647eaeeb44a5b63a6f2141f3ced35ccf27364a (commit)
from 30a31dc2d764c91837a690112c601e6363db224e (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/fa647eaeeb44a5b63a6f2141f3ced35ccf27…
commit fa647eaeeb44a5b63a6f2141f3ced35ccf27364a
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Sun Nov 6 13:17:31 2011 +0100
doc: Update the filter documentation.
diff --git a/doc/filters.txt b/doc/filters.txt
index d806786..c189599 100644
--- a/doc/filters.txt
+++ b/doc/filters.txt
@@ -18,7 +18,7 @@ pointer to store location of user data and percentage.
-------------------------------------------------------------------------------
typdedef struct GP_ProgressCallback {
float percentage;
- void (*callback)(struct GP_ProgressCallback *self);
+ int (*callback)(struct GP_ProgressCallback *self);
void *priv;
} GP_ProgressCallback;
-------------------------------------------------------------------------------
@@ -26,7 +26,12 @@ typdedef struct GP_ProgressCallback {
If non 'NULL' progress callback structure is passed to a filter function, the
callback function is periodically called and the percentage is updated.
-The callback is, if supported, the last parameter of the filter function.
+The return value from callback could abort the filter execution. If non zero
+value is returned the filter is aborted, all memory freed etc. and the filter
+either returns 'NULL' if pointer is returned or 'GP_EINTR' in case filter
+returns 'GP_RetCode'.
+
+The callback, if supported, is the last parameter of the filter function.
Common filter API
~~~~~~~~~~~~~~~~~
-----------------------------------------------------------------------
Summary of changes:
doc/filters.txt | 9 +++++++--
1 files changed, 7 insertions(+), 2 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: 30a31dc2d764c91837a690112c601e6363db224e
by metan 04 Nov '11
by metan 04 Nov '11
04 Nov '11
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 30a31dc2d764c91837a690112c601e6363db224e (commit)
via 7f9e2efe90d7fe60e03bf60ab55f59e110113036 (commit)
from 05551ed06488f6e537a0705980630f2d36b47c40 (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/30a31dc2d764c91837a690112c601e6363db…
commit 30a31dc2d764c91837a690112c601e6363db224e
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Fri Nov 4 16:17:06 2011 +0100
Basic JPG writer support.
diff --git a/include/loaders/GP_JPG.h b/include/loaders/GP_JPG.h
index fddac6e..db9c51f 100644
--- a/include/loaders/GP_JPG.h
+++ b/include/loaders/GP_JPG.h
@@ -33,22 +33,28 @@
#include "core/GP_ProgressCallback.h"
/*
- * Opens up file and checks signature. Upon successful return the file
- * possition would be set to eight bytes (exactly after the PNG signature).
+ * Opens up file and checks signature.
*/
GP_RetCode GP_OpenJPG(const char *src_path, FILE **f);
/*
- * Reads PNG from an open FILE. Expects the file possition set after the eight
- * bytes PNG signature.
+ * Reads JPG from an open FILE. Expects the file possition set after the eight
+ * bytes JPG signature.
*/
GP_RetCode GP_ReadJPG(FILE *f, GP_Context **res,
GP_ProgressCallback *callback);
/*
- * Loads a PNG file into GP_Context. The Context is newly allocated.
+ * Loads a JPG file into GP_Context. The Context is newly allocated.
*/
GP_RetCode GP_LoadJPG(const char *src_path, GP_Context **res,
GP_ProgressCallback *callback);
+/*
+ * Saves JPG to a file.
+ */
+GP_RetCode GP_SaveJPG(const char *dst_path, const GP_Context *src,
+ GP_ProgressCallback *callback);
+
+
#endif /* LOADERS_GP_JPG_H */
diff --git a/libs/loaders/GP_JPG.c b/libs/loaders/GP_JPG.c
index be0b67c..cbb5758 100644
--- a/libs/loaders/GP_JPG.c
+++ b/libs/loaders/GP_JPG.c
@@ -64,7 +64,7 @@ static void my_error_exit(j_common_ptr cinfo)
{
struct my_jpg_err *my_err = (struct my_jpg_err*) cinfo->err;
- GP_DEBUG(1, "ERROR reading jpeg file");
+ GP_DEBUG(1, "ERROR reading/writing jpeg file");
longjmp(my_err->setjmp_buf, 1);
}
@@ -194,3 +194,93 @@ GP_RetCode GP_LoadJPG(const char *src_path, GP_Context **res,
return GP_ReadJPG(f, res, callback);
}
+
+GP_RetCode GP_SaveJPG(const char *dst_path, const GP_Context *src,
+ GP_ProgressCallback *callback)
+{
+ FILE *f;
+ GP_RetCode ret;
+ struct jpeg_compress_struct cinfo;
+ struct my_jpg_err my_err;
+
+ if (src->pixel_type != GP_PIXEL_RGB888 &&
+ src->pixel_type != GP_PIXEL_G8) {
+ GP_DEBUG(1, "Can't save png with pixel type %s",
+ GP_PixelTypeName(src->pixel_type));
+ return GP_ENOIMPL;
+ }
+
+ f = fopen(dst_path, "wb");
+
+ if (f == NULL) {
+ GP_DEBUG(1, "Failed to open '%s' for writing: %s",
+ dst_path, strerror(errno));
+ return GP_EBADFILE;
+ }
+
+ if (setjmp(my_err.setjmp_buf)) {
+ ret = GP_EBADFILE;;
+ goto err1;
+ }
+
+ cinfo.err = jpeg_std_error(&my_err.error_mgr);
+ my_err.error_mgr.error_exit = my_error_exit;
+
+ jpeg_create_compress(&cinfo);
+
+ jpeg_stdio_dest(&cinfo, f);
+
+ cinfo.image_width = src->w;
+ cinfo.image_height = src->h;
+ cinfo.input_components = src->pixel_type == GP_PIXEL_RGB888 ? 3 : 1;
+ cinfo.in_color_space = JCS_RGB;
+
+ jpeg_set_defaults(&cinfo);
+
+ jpeg_start_compress(&cinfo, TRUE);
+
+ while (cinfo.next_scanline < cinfo.image_height) {
+ uint32_t y = cinfo.next_scanline;
+
+ if (src->pixel_type == GP_PIXEL_RGB888) {
+ uint32_t i;
+ uint8_t tmp[3 * src->w];
+
+ memcpy(tmp, GP_PIXEL_ADDR(src, 0, y), 3 * src->w);
+
+ /* fix the pixels as we want in fact BGR */
+ for (i = 0; i < src->w; i++) {
+ uint8_t *pix = tmp + 3 * i;
+ GP_SWAP(pix[0], pix[2]);
+ }
+
+ JSAMPROW row = (void*)tmp;
+ jpeg_write_scanlines(&cinfo, &row, 1);
+ } else {
+ JSAMPROW row = (void*)GP_PIXEL_ADDR(src, 0, y);
+ jpeg_write_scanlines(&cinfo, &row, 1);
+ }
+
+ if (GP_ProgressCallbackReport(callback, y, src->h, src->w)) {
+ GP_DEBUG(1, "Operation aborted");
+ ret = GP_EINTR;
+ goto err1;
+ }
+ }
+
+ jpeg_finish_compress(&cinfo);
+
+ if (fclose(f)) {
+ GP_DEBUG(1, "Failed to close file '%s': %s",
+ dst_path, strerror(errno));
+ return GP_EBADFILE;
+ }
+
+ return GP_ESUCCESS;
+//TODO: is cinfo allocated?
+err1:
+ jpeg_destroy_compress(&cinfo);
+ fclose(f);
+ unlink(dst_path);
+ return ret;
+}
http://repo.or.cz/w/gfxprim.git/commit/7f9e2efe90d7fe60e03bf60ab55f59e11011…
commit 7f9e2efe90d7fe60e03bf60ab55f59e110113036
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Fri Nov 4 15:10:01 2011 +0100
Basic PNG writer code.
diff --git a/include/loaders/GP_PNG.h b/include/loaders/GP_PNG.h
index cfa9438..1b4d9cf 100644
--- a/include/loaders/GP_PNG.h
+++ b/include/loaders/GP_PNG.h
@@ -51,4 +51,10 @@ GP_RetCode GP_ReadPNG(FILE *f, GP_Context **res,
GP_RetCode GP_LoadPNG(const char *src_path, GP_Context **res,
GP_ProgressCallback *callback);
-#endif /* GP_PNG_H */
+/*
+ * Saves PNG to a file.
+ */
+GP_RetCode GP_SavePNG(const char *dst_path, const GP_Context *src,
+ GP_ProgressCallback *callback);
+
+#endif /* LOADERS_GP_PNG_H */
diff --git a/libs/loaders/GP_PNG.c b/libs/loaders/GP_PNG.c
index b013c42..d7da8ae 100644
--- a/libs/loaders/GP_PNG.c
+++ b/libs/loaders/GP_PNG.c
@@ -70,13 +70,25 @@ err:
return GP_EBADFILE;
}
+static const char *interlace_type_name(int interlace)
+{
+ switch (interlace) {
+ case PNG_INTERLACE_NONE:
+ return "none";
+ case PNG_INTERLACE_ADAM7:
+ return "adam7";
+ default:
+ return "unknown";
+ }
+}
+
GP_RetCode GP_ReadPNG(FILE *f, GP_Context **res,
GP_ProgressCallback *callback)
{
png_structp png;
png_infop png_info = NULL;
png_uint_32 w, h;
- int depth, color_type;
+ int depth, color_type, interlace_type;
GP_PixelType pixel_type = GP_PIXEL_UNKNOWN;
GP_RetCode ret;
@@ -107,9 +119,10 @@ GP_RetCode GP_ReadPNG(FILE *f, GP_Context **res,
png_read_info(png, png_info);
png_get_IHDR(png, png_info, &w, &h, &depth,
- &color_type, NULL, NULL, NULL);
+ &color_type, &interlace_type, NULL, NULL);
- GP_DEBUG(2, "Have %s%s PNG%s size %ux%u depth %i",
+ GP_DEBUG(2, "Have %s%s interlace %s PNG%s size %ux%u depth %i",
+ interlace_type_name(interlace_type),
color_type & PNG_COLOR_MASK_PALETTE ? "pallete " : "",
color_type & PNG_COLOR_MASK_COLOR ? "color" : "gray",
color_type & PNG_COLOR_MASK_ALPHA ? " with alpha channel" : "",
@@ -156,6 +169,7 @@ GP_RetCode GP_ReadPNG(FILE *f, GP_Context **res,
}
if (pixel_type == GP_PIXEL_UNKNOWN) {
+ GP_DEBUG(1, "Unimplemented png format");
ret = GP_ENOIMPL;
goto err2;
}
@@ -168,10 +182,11 @@ GP_RetCode GP_ReadPNG(FILE *f, GP_Context **res,
}
uint32_t y;
-
+
+ /* start the actuall reading */
for (y = 0; y < h; y++) {
- png_bytep addr = GP_PIXEL_ADDR(*res, 0, y);
- png_read_rows(png, &addr, NULL, 1);
+ png_bytep row = GP_PIXEL_ADDR(*res, 0, y);
+ png_read_rows(png, &row, NULL, 1);
if (GP_ProgressCallbackReport(callback, y, h, w)) {
GP_DEBUG(1, "Operation aborted");
@@ -204,3 +219,88 @@ GP_RetCode GP_LoadPNG(const char *src_path, GP_Context **res,
return GP_ReadPNG(f, res, callback);
}
+
+GP_RetCode GP_SavePNG(const char *dst_path, const GP_Context *src,
+ GP_ProgressCallback *callback)
+{
+ FILE *f;
+ GP_RetCode ret;
+ png_structp png;
+ png_infop png_info = NULL;
+
+ if (src->pixel_type != GP_PIXEL_RGB888) {
+ GP_DEBUG(1, "Can't save png with pixel type %s",
+ GP_PixelTypeName(src->pixel_type));
+ return GP_ENOIMPL;
+ }
+
+ f = fopen(dst_path, "wb");
+
+ if (f == NULL) {
+ GP_DEBUG(1, "Failed to open '%s' for writing: %s",
+ dst_path, strerror(errno));
+ return GP_EBADFILE;
+ }
+
+ png = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
+
+ if (png == NULL) {
+ GP_DEBUG(1, "Failed to allocate PNG write buffer");
+ ret = GP_ENOMEM;
+ goto err1;
+ }
+
+ png_info = png_create_info_struct(png);
+
+ if (png_info == NULL) {
+ GP_DEBUG(1, "Failed to allocate PNG info buffer");
+ ret = GP_ENOMEM;
+ goto err2;
+ }
+
+ if (setjmp(png_jmpbuf(png))) {
+ GP_DEBUG(1, "Failed to write PNG file :(");
+ ret = GP_EBADFILE;
+ goto err2;
+ }
+
+ png_init_io(png, f);
+ png_set_IHDR(png, png_info, src->w, src->h, 8, PNG_COLOR_TYPE_RGB,
+ PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT,
+ PNG_FILTER_TYPE_DEFAULT);
+
+ /* start the actuall writing */
+ png_write_info(png, png_info);
+ png_set_bgr(png);
+
+ uint32_t y;
+
+ for (y = 0; y < src->h; y++) {
+ png_bytep row = GP_PIXEL_ADDR(src, 0, y);
+ png_write_row(png, row);
+
+ if (GP_ProgressCallbackReport(callback, y, src->h, src->w)) {
+ GP_DEBUG(1, "Operation aborted");
+ ret = GP_EINTR;
+ goto err2;
+ }
+
+ }
+
+ png_write_end(png, png_info);
+ png_destroy_write_struct(&png, &png_info);
+
+ if (fclose(f)) {
+ GP_DEBUG(1, "Failed to close file '%s': %s",
+ dst_path, strerror(errno));
+ return GP_EBADFILE;
+ }
+
+ return GP_ESUCCESS;
+err2:
+ png_destroy_write_struct(&png, png_info == NULL ? NULL : &png_info);
+err1:
+ fclose(f);
+ unlink(dst_path);
+ return ret;
+}
-----------------------------------------------------------------------
Summary of changes:
include/loaders/GP_JPG.h | 16 +++++--
include/loaders/GP_PNG.h | 8 +++-
libs/loaders/GP_JPG.c | 92 +++++++++++++++++++++++++++++++++++++-
libs/loaders/GP_PNG.c | 112 +++++++++++++++++++++++++++++++++++++++++++---
4 files changed, 215 insertions(+), 13 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: 05551ed06488f6e537a0705980630f2d36b47c40
by metan 04 Nov '11
by metan 04 Nov '11
04 Nov '11
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 05551ed06488f6e537a0705980630f2d36b47c40 (commit)
via c793286d79acf527139becc2b6ba847193cad08d (commit)
from a2f97569d98cda1ac080fbe73de4fa58fa5ae10b (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/05551ed06488f6e537a0705980630f2d36b4…
commit 05551ed06488f6e537a0705980630f2d36b47c40
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Fri Nov 4 13:43:15 2011 +0100
Add progress callback to JPG and PNG loaders.
diff --git a/demos/fbshow/fbshow.c b/demos/fbshow/fbshow.c
index 260e821..ead85bf 100644
--- a/demos/fbshow/fbshow.c
+++ b/demos/fbshow/fbshow.c
@@ -69,6 +69,7 @@ static float calc_img_size(uint32_t img_w, uint32_t img_h,
static void *image_loader(void *ptr)
{
struct loader_params *params = ptr;
+ GP_ProgressCallback callback = {.callback = image_loader_callback};
fprintf(stderr, "Loading '%s'n", params->img_path);
@@ -83,7 +84,7 @@ static void *image_loader(void *ptr)
GP_Context *img = NULL;
- if (GP_LoadImage(params->img_path, &img) != 0) {
+ if (GP_LoadImage(params->img_path, &img, &callback) != 0) {
GP_BoxCenteredText(&fb->context, NULL, 0, 0,
fb->context.w, fb->context.h,
"Failed to load image", white_pixel);
@@ -115,7 +116,6 @@ static void *image_loader(void *ptr)
img = tmp;
}
- GP_ProgressCallback callback = {.callback = image_loader_callback};
GP_Context *ret;
diff --git a/demos/grinder/grinder.c b/demos/grinder/grinder.c
index 2854ac3..9833ea1 100644
--- a/demos/grinder/grinder.c
+++ b/demos/grinder/grinder.c
@@ -549,7 +549,7 @@ int main(int argc, char *argv[])
snprintf(buf, sizeof(buf), "out_%i.ppm", i - optind + 1);
fprintf(stderr, "Processing '%s' -> '%s'n", argv[i], buf);
- if ((ret = GP_LoadImage(argv[i], &bitmap))) {
+ if ((ret = GP_LoadImage(argv[i], &bitmap, NULL))) {
fprintf(stderr, "Failed to load bitmap: %sn",
GP_RetCodeName(ret));
return 1;
diff --git a/include/loaders/GP_JPG.h b/include/loaders/GP_JPG.h
index bef6e10..fddac6e 100644
--- a/include/loaders/GP_JPG.h
+++ b/include/loaders/GP_JPG.h
@@ -26,10 +26,11 @@
*/
-#ifndef GP_JPG_H
-#define GP_JPG_H
+#ifndef LOADERS_GP_JPG_H
+#define LOADERS_GP_JPG_H
#include "core/GP_Context.h"
+#include "core/GP_ProgressCallback.h"
/*
* Opens up file and checks signature. Upon successful return the file
@@ -41,11 +42,13 @@ GP_RetCode GP_OpenJPG(const char *src_path, FILE **f);
* Reads PNG from an open FILE. Expects the file possition set after the eight
* bytes PNG signature.
*/
-GP_RetCode GP_ReadJPG(FILE *f, GP_Context **res);
+GP_RetCode GP_ReadJPG(FILE *f, GP_Context **res,
+ GP_ProgressCallback *callback);
/*
* Loads a PNG file into GP_Context. The Context is newly allocated.
*/
-GP_RetCode GP_LoadJPG(const char *src_path, GP_Context **res);
+GP_RetCode GP_LoadJPG(const char *src_path, GP_Context **res,
+ GP_ProgressCallback *callback);
-#endif /* GP_JPG_H */
+#endif /* LOADERS_GP_JPG_H */
diff --git a/include/loaders/GP_Loaders.h b/include/loaders/GP_Loaders.h
index e3ff703..b327744 100644
--- a/include/loaders/GP_Loaders.h
+++ b/include/loaders/GP_Loaders.h
@@ -29,10 +29,11 @@
*/
-#ifndef GP_LOADERS_H
-#define GP_LOADERS_H
+#ifndef LOADERS_GP_LOADERS_H
+#define LOADERS_GP_LOADERS_H
#include "core/GP_Context.h"
+#include "core/GP_ProgressCallback.h"
#include "GP_PBM.h"
#include "GP_PGM.h"
@@ -45,6 +46,7 @@
/*
* Tries to load image accordingly to extension.
*/
-GP_RetCode GP_LoadImage(const char *src_path, GP_Context **res);
+GP_RetCode GP_LoadImage(const char *src_path, GP_Context **res,
+ GP_ProgressCallback *callback);
-#endif /* GP_LOADERS_H */
+#endif /* LOADERS_GP_LOADERS_H */
diff --git a/include/loaders/GP_PNG.h b/include/loaders/GP_PNG.h
index 2b02deb..cfa9438 100644
--- a/include/loaders/GP_PNG.h
+++ b/include/loaders/GP_PNG.h
@@ -26,9 +26,10 @@
*/
-#ifndef GP_PNG_H
-#define GP_PNG_H
+#ifndef LOADERS_GP_PNG_H
+#define LOADERS_GP_PNG_H
+#include "core/GP_ProgressCallback.h"
#include "core/GP_Context.h"
/*
@@ -41,11 +42,13 @@ GP_RetCode GP_OpenPNG(const char *src_path, FILE **f);
* Reads PNG from an open FILE. Expects the file possition set after the eight
* bytes PNG signature.
*/
-GP_RetCode GP_ReadPNG(FILE *f, GP_Context **res);
+GP_RetCode GP_ReadPNG(FILE *f, GP_Context **res,
+ GP_ProgressCallback *callback);
/*
* Loads a PNG file into GP_Context. The Context is newly allocated.
*/
-GP_RetCode GP_LoadPNG(const char *src_path, GP_Context **res);
+GP_RetCode GP_LoadPNG(const char *src_path, GP_Context **res,
+ GP_ProgressCallback *callback);
#endif /* GP_PNG_H */
diff --git a/libs/loaders/GP_JPG.c b/libs/loaders/GP_JPG.c
index 5958dab..be0b67c 100644
--- a/libs/loaders/GP_JPG.c
+++ b/libs/loaders/GP_JPG.c
@@ -36,8 +36,8 @@
#include <jpeglib.h>
-#include <GP_Context.h>
-#include <GP_Debug.h>
+#include "GP_JPG.h"
+#include "core/GP_Debug.h"
GP_RetCode GP_OpenJPG(const char *src_path, FILE **f)
{
@@ -87,7 +87,8 @@ static const char *get_colorspace(J_COLOR_SPACE color_space)
};
}
-GP_RetCode GP_ReadJPG(FILE *f, GP_Context **res)
+GP_RetCode GP_ReadJPG(FILE *f, GP_Context **res,
+ GP_ProgressCallback *callback)
{
struct jpeg_decompress_struct cinfo;
struct my_jpg_err my_err;
@@ -163,17 +164,27 @@ GP_RetCode GP_ReadJPG(FILE *f, GP_Context **res)
uint8_t *pix = GP_PIXEL_ADDR(ret, i, y);
GP_SWAP(pix[0], pix[2]);
}
+
+ if (GP_ProgressCallbackReport(callback, y, ret->h, ret->w)) {
+ GP_DEBUG(1, "Operation aborted");
+ jpeg_destroy_decompress(&cinfo);
+ fclose(f);
+ GP_ContextFree(ret);
+ return GP_EINTR;
+ }
}
jpeg_finish_decompress(&cinfo);
jpeg_destroy_decompress(&cinfo);
fclose(f);
*res = ret;
-
+
+ GP_ProgressCallbackDone(callback);
return GP_ESUCCESS;
}
-GP_RetCode GP_LoadJPG(const char *src_path, GP_Context **res)
+GP_RetCode GP_LoadJPG(const char *src_path, GP_Context **res,
+ GP_ProgressCallback *callback)
{
FILE *f;
GP_RetCode ret;
@@ -181,5 +192,5 @@ GP_RetCode GP_LoadJPG(const char *src_path, GP_Context **res)
if ((ret = GP_OpenJPG(src_path, &f)))
return ret;
- return GP_ReadJPG(f, res);
+ return GP_ReadJPG(f, res, callback);
}
diff --git a/libs/loaders/GP_Loaders.c b/libs/loaders/GP_Loaders.c
index 8f69d03..8a57c59 100644
--- a/libs/loaders/GP_Loaders.c
+++ b/libs/loaders/GP_Loaders.c
@@ -30,11 +30,12 @@
#include <unistd.h>
#include <errno.h>
-#include <GP_Debug.h>
+#include "core/GP_Debug.h"
#include "GP_Loaders.h"
-GP_RetCode GP_LoadImage(const char *src_path, GP_Context **res)
+GP_RetCode GP_LoadImage(const char *src_path, GP_Context **res,
+ GP_ProgressCallback *callback)
{
int len = strlen(src_path);
GP_RetCode ret = GP_ENOIMPL;
@@ -54,13 +55,13 @@ GP_RetCode GP_LoadImage(const char *src_path, GP_Context **res)
case 'N':
if (src_path[len - 3] == 'p' ||
src_path[len - 3] == 'P')
- ret = GP_LoadPNG(src_path, res);
+ ret = GP_LoadPNG(src_path, res, callback);
break;
case 'p':
case 'P':
if (src_path[len - 3] == 'j' ||
src_path[len - 3] == 'J')
- ret = GP_LoadJPG(src_path, res);
+ ret = GP_LoadJPG(src_path, res, callback);
break;
case 'e':
case 'E':
@@ -68,7 +69,7 @@ GP_RetCode GP_LoadImage(const char *src_path, GP_Context **res)
src_path[len - 3] == 'P') &&
(src_path[len - 4] == 'j' ||
src_path[len - 4] == 'J'))
- ret = GP_LoadJPG(src_path, res);
+ ret = GP_LoadJPG(src_path, res, callback);
break;
}
break;
diff --git a/libs/loaders/GP_PNG.c b/libs/loaders/GP_PNG.c
index dae8120..b013c42 100644
--- a/libs/loaders/GP_PNG.c
+++ b/libs/loaders/GP_PNG.c
@@ -34,8 +34,8 @@
#include <png.h>
-#include <GP_Context.h>
-#include <GP_Debug.h>
+#include "GP_PNG.h"
+#include "core/GP_Debug.h"
GP_RetCode GP_OpenPNG(const char *src_path, FILE **f)
{
@@ -70,7 +70,8 @@ err:
return GP_EBADFILE;
}
-GP_RetCode GP_ReadPNG(FILE *f, GP_Context **res)
+GP_RetCode GP_ReadPNG(FILE *f, GP_Context **res,
+ GP_ProgressCallback *callback)
{
png_structp png;
png_infop png_info = NULL;
@@ -171,8 +172,19 @@ GP_RetCode GP_ReadPNG(FILE *f, GP_Context **res)
for (y = 0; y < h; y++) {
png_bytep addr = GP_PIXEL_ADDR(*res, 0, y);
png_read_rows(png, &addr, NULL, 1);
+
+ if (GP_ProgressCallbackReport(callback, y, h, w)) {
+ GP_DEBUG(1, "Operation aborted");
+ png_destroy_read_struct(&png, &png_info, NULL);
+ fclose(f);
+ GP_ContextFree(*res);
+ return GP_EINTR;
+ }
+
}
+ GP_ProgressCallbackDone(callback);
+
ret = GP_ESUCCESS;
err2:
png_destroy_read_struct(&png, png_info ? &png_info : NULL, NULL);
@@ -181,7 +193,8 @@ err1:
return ret;
}
-GP_RetCode GP_LoadPNG(const char *src_path, GP_Context **res)
+GP_RetCode GP_LoadPNG(const char *src_path, GP_Context **res,
+ GP_ProgressCallback *callback)
{
FILE *f;
GP_RetCode ret;
@@ -189,5 +202,5 @@ GP_RetCode GP_LoadPNG(const char *src_path, GP_Context **res)
if ((ret = GP_OpenPNG(src_path, &f)))
return ret;
- return GP_ReadPNG(f, res);
+ return GP_ReadPNG(f, res, callback);
}
diff --git a/tests/SDL/showimage.c b/tests/SDL/showimage.c
index 134f8f9..9df416d 100644
--- a/tests/SDL/showimage.c
+++ b/tests/SDL/showimage.c
@@ -92,7 +92,7 @@ int main(int argc, char *argv[])
GP_RetCode ret;
- if ((ret = GP_LoadImage(argv[1], &bitmap))) {
+ if ((ret = GP_LoadImage(argv[1], &bitmap, NULL))) {
fprintf(stderr, "Failed to load bitmap: %sn", GP_RetCodeName(ret));
return 1;
}
http://repo.or.cz/w/gfxprim.git/commit/c793286d79acf527139becc2b6ba847193ca…
commit c793286d79acf527139becc2b6ba847193cad08d
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Fri Nov 4 13:26:56 2011 +0100
Added GP_EINTR ret code.
diff --git a/include/core/GP_RetCode.h b/include/core/GP_RetCode.h
index 9241a26..ce875fd 100644
--- a/include/core/GP_RetCode.h
+++ b/include/core/GP_RetCode.h
@@ -19,12 +19,12 @@
* Copyright (C) 2009-2010 Jiri "BlueBear" Dluhos *
* <jiri.bluebear.dluhos(a)gmail.com> *
* *
- * Copyright (C) 2009-2010 Cyril Hrubis <metan(a)ucw.cz> *
+ * Copyright (C) 2009-2011 Cyril Hrubis <metan(a)ucw.cz> *
* *
*****************************************************************************/
-#ifndef GP_RETCODE_H
-#define GP_RETCODE_H
+#ifndef CORE_GP_RETCODE_H
+#define CORE_GP_RETCODE_H
typedef enum GP_RetCode {
GP_ESUCCESS,
@@ -38,9 +38,10 @@ typedef enum GP_RetCode {
GP_EBADFILE, /* error in file, or bad file format */
GP_ENOENT, /* no such file or another object */
GP_ENOMEM, /* not enough memory */
+ GP_EINTR, /* operation interrupted by user */
GP_EMAX,
} GP_RetCode;
const char *GP_RetCodeName(GP_RetCode code);
-#endif /* GP_RETCODE_H */
+#endif /* CORE_GP_RETCODE_H */
diff --git a/libs/core/GP_RetCode.c b/libs/core/GP_RetCode.c
index a4069c5..f14b5cc 100644
--- a/libs/core/GP_RetCode.c
+++ b/libs/core/GP_RetCode.c
@@ -19,7 +19,7 @@
* Copyright (C) 2009-2010 Jiri "BlueBear" Dluhos *
* <jiri.bluebear.dluhos(a)gmail.com> *
* *
- * Copyright (C) 2009-2010 Cyril Hrubis <metan(a)ucw.cz> *
+ * Copyright (C) 2009-2011 Cyril Hrubis <metan(a)ucw.cz> *
* *
*****************************************************************************/
@@ -37,10 +37,10 @@ static char *ret_code_names[] = {
"Bad context",
"Bad file",
"Not found",
- "Not enough memory"
+ "Not enough memory",
+ "Operation interrupted"
};
-
const char *GP_RetCodeName(GP_RetCode code)
{
if (code >= GP_EMAX)
-----------------------------------------------------------------------
Summary of changes:
demos/fbshow/fbshow.c | 4 ++--
demos/grinder/grinder.c | 2 +-
include/core/GP_RetCode.h | 9 +++++----
include/loaders/GP_JPG.h | 13 ++++++++-----
include/loaders/GP_Loaders.h | 10 ++++++----
include/loaders/GP_PNG.h | 11 +++++++----
libs/core/GP_RetCode.c | 6 +++---
libs/loaders/GP_JPG.c | 23 +++++++++++++++++------
libs/loaders/GP_Loaders.c | 11 ++++++-----
libs/loaders/GP_PNG.c | 23 ++++++++++++++++++-----
tests/SDL/showimage.c | 2 +-
11 files changed, 74 insertions(+), 40 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: a2f97569d98cda1ac080fbe73de4fa58fa5ae10b
by metan 04 Nov '11
by metan 04 Nov '11
04 Nov '11
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 a2f97569d98cda1ac080fbe73de4fa58fa5ae10b (commit)
from a2550171ddb5623635256c50ffa60e5e20d6b2dd (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/a2f97569d98cda1ac080fbe73de4fa58fa5a…
commit a2f97569d98cda1ac080fbe73de4fa58fa5ae10b
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Fri Nov 4 13:05:07 2011 +0100
Move the progress callback to the core.
diff --git a/include/filters/GP_Filter.h b/include/core/GP_ProgressCallback.h
similarity index 87%
copy from include/filters/GP_Filter.h
copy to include/core/GP_ProgressCallback.h
index 74637ab..72857ce 100644
--- a/include/filters/GP_Filter.h
+++ b/include/core/GP_ProgressCallback.h
@@ -22,20 +22,23 @@
/*
- Common filters typedefs and includes.
+ Progress callback implementation.
- */
+ Progress callbacks serves two purposes
+
+ - ability to visibly show algorithm progress
+ - ability to correctly abort operation in the middle of processing
-#ifndef GP_FILTERS_FILTER_H
-#define GP_FILTERS_FILTER_H
+ */
-#include "core/GP_Context.h"
+#ifndef CORE_GP_PROGRESSCALLBACK_H
+#define CORE_GP_PROGRESSCALLBACK_H
/*
* Progress callback
*
* Non zero return value from callback will abort current operation
- * free memory and return NULL from filter.
+ * free memory and return NULL from filter/loader...
*/
typedef struct GP_ProgressCallback {
float percentage;
@@ -66,4 +69,4 @@ static inline void GP_ProgressCallbackDone(GP_ProgressCallback *callback)
callback->callback(callback);
}
-#endif /* FILTERS_GP_FILTER_H */
+#endif /* CORE_GP_PROGRESSCALBACK_H */
diff --git a/include/filters/GP_Filter.h b/include/filters/GP_Filter.h
index 74637ab..e986ae6 100644
--- a/include/filters/GP_Filter.h
+++ b/include/filters/GP_Filter.h
@@ -26,44 +26,10 @@
*/
-#ifndef GP_FILTERS_FILTER_H
-#define GP_FILTERS_FILTER_H
+#ifndef FILTERS_GP_FILTER_H
+#define FILTERS_GP_FILTER_H
#include "core/GP_Context.h"
-
-/*
- * Progress callback
- *
- * Non zero return value from callback will abort current operation
- * free memory and return NULL from filter.
- */
-typedef struct GP_ProgressCallback {
- float percentage;
- int (*callback)(struct GP_ProgressCallback *self);
- void *priv;
-} GP_ProgressCallback;
-
-static inline int GP_ProgressCallbackReport(GP_ProgressCallback *callback,
- unsigned int val, unsigned int max,
- unsigned int mul __attribute__((unused)))
-{
- if (callback == NULL)
- return 0;
-
- if (val % 100)
- return 0;
-
- callback->percentage = 100.00 * val / max;
- return callback->callback(callback);
-}
-
-static inline void GP_ProgressCallbackDone(GP_ProgressCallback *callback)
-{
- if (callback == NULL)
- return;
-
- callback->percentage = 100;
- callback->callback(callback);
-}
+#include "core/GP_ProgressCallback.h"
#endif /* FILTERS_GP_FILTER_H */
-----------------------------------------------------------------------
Summary of changes:
.../GP_Filter.h => core/GP_ProgressCallback.h} | 17 +++++---
include/filters/GP_Filter.h | 40 +------------------
2 files changed, 13 insertions(+), 44 deletions(-)
copy include/{filters/GP_Filter.h => core/GP_ProgressCallback.h} (87%)
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: a2550171ddb5623635256c50ffa60e5e20d6b2dd
by metan 01 Nov '11
by metan 01 Nov '11
01 Nov '11
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 a2550171ddb5623635256c50ffa60e5e20d6b2dd (commit)
via cd3240b7d4f5cd92e2dbbf750807cfac4d8299ea (commit)
via c696722f489a1cd8e8019dd27821e260f2f80756 (commit)
from 55303a1b980b3e008a6cac5cf9070e21c1814a51 (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/a2550171ddb5623635256c50ffa60e5e20d6…
commit a2550171ddb5623635256c50ffa60e5e20d6b2dd
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Tue Nov 1 21:04:39 2011 +0100
fbshow: Now with two threads (needs a little cleaup).
diff --git a/demos/fbshow/Makefile b/demos/fbshow/Makefile
index 0a8147c..a3bf9c3 100644
--- a/demos/fbshow/Makefile
+++ b/demos/fbshow/Makefile
@@ -3,6 +3,7 @@ TOPDIR=../..
CSOURCES=$(shell echo *.c)
INCLUDE=
+CFLAGS+=-pthread
LDLIBS+=-lGP -L$(TOPDIR)/build/
APPS=fbshow
diff --git a/demos/fbshow/fbshow.c b/demos/fbshow/fbshow.c
index 37f7e3a..260e821 100644
--- a/demos/fbshow/fbshow.c
+++ b/demos/fbshow/fbshow.c
@@ -29,6 +29,7 @@
#include <signal.h>
#include <unistd.h>
#include <string.h>
+#include <pthread.h>
#include <GP.h>
#include <backends/GP_Framebuffer.h>
@@ -39,17 +40,23 @@ static GP_Pixel white_pixel;
static GP_Framebuffer *fb = NULL;
+/* image loader thread */
+static int abort_flag = 0;
static int rotate = 0;
-
-static void sighandler(int signo __attribute__((unused)))
+static int image_loader_callback(GP_ProgressCallback *self)
{
- if (fb != NULL)
- GP_FramebufferExit(fb);
-
- exit(1);
+ if (abort_flag)
+ return 1;
+
+ return 0;
}
+struct loader_params {
+ const char *img_path;
+ int clear;
+};
+
static float calc_img_size(uint32_t img_w, uint32_t img_h,
uint32_t src_w, uint32_t src_h)
{
@@ -59,23 +66,29 @@ static float calc_img_size(uint32_t img_w, uint32_t img_h,
return GP_MIN(w_rat, h_rat);
}
-static int show_image(GP_Framebuffer *fb, const char *img_path, int clear)
+static void *image_loader(void *ptr)
{
- GP_Context *img;
+ struct loader_params *params = ptr;
- fprintf(stderr, "Loading '%s'n", img_path);
+ fprintf(stderr, "Loading '%s'n", params->img_path);
- if (clear) {
+ if (params->clear) {
char buf[100];
- snprintf(buf, sizeof(buf), "Loading '%s'", img_path);
+ snprintf(buf, sizeof(buf), "Loading '%s'", params->img_path);
GP_Fill(&fb->context, black_pixel);
GP_BoxCenteredText(&fb->context, NULL, 0, 0,
fb->context.w, fb->context.h,
buf, white_pixel);
}
- if (GP_LoadImage(img_path, &img) != 0)
- return 1;
+ GP_Context *img = NULL;
+
+ if (GP_LoadImage(params->img_path, &img) != 0) {
+ GP_BoxCenteredText(&fb->context, NULL, 0, 0,
+ fb->context.w, fb->context.h,
+ "Failed to load image", white_pixel);
+ return NULL;
+ }
GP_Size w, h;
@@ -94,7 +107,7 @@ static int show_image(GP_Framebuffer *fb, const char *img_path, int clear)
}
float rat = calc_img_size(img->w, img->h, w, h);
-
+
/* Workaround */
if (img->pixel_type != GP_PIXEL_RGB888) {
GP_Context *tmp = GP_ContextConvert(img, GP_PIXEL_RGB888);
@@ -102,23 +115,29 @@ static int show_image(GP_Framebuffer *fb, const char *img_path, int clear)
img = tmp;
}
+ GP_ProgressCallback callback = {.callback = image_loader_callback};
+
GP_Context *ret;
-// GP_FilterGaussianBlur(img, img, 0.7, 0.7, NULL);
- ret = GP_FilterResize(img, NULL, GP_INTERP_CUBIC, img->w * rat, img->h * rat, NULL);
+// if (GP_FilterGaussianBlur(img, img, 0.7, 0.7, &callback))
+// return NULL;
+ ret = GP_FilterResize(img, NULL, GP_INTERP_CUBIC, img->w * rat, img->h * rat, &callback);
GP_ContextFree(img);
+ if (ret == NULL)
+ return NULL;
+
switch (rotate) {
case 0:
break;
case 90:
- img = GP_FilterRotate90(ret, NULL, NULL);
+ img = GP_FilterRotate90(ret, NULL, &callback);
break;
case 180:
- img = GP_FilterRotate180(ret, NULL, NULL);
+ img = GP_FilterRotate180(ret, NULL, &callback);
break;
case 270:
- img = GP_FilterRotate270(ret, NULL, NULL);
+ img = GP_FilterRotate270(ret, NULL, &callback);
break;
}
@@ -127,6 +146,9 @@ static int show_image(GP_Framebuffer *fb, const char *img_path, int clear)
ret = img;
}
+ if (img == NULL)
+ return NULL;
+
uint32_t cx = (fb->context.w - ret->w)/2;
uint32_t cy = (fb->context.h - ret->h)/2;
@@ -139,7 +161,42 @@ static int show_image(GP_Framebuffer *fb, const char *img_path, int clear)
GP_FillRectXYWH(&fb->context, ret->w+cx, 0, cx, fb->context.h, black_pixel);
GP_FillRectXYWH(&fb->context, 0, ret->h+cy, fb->context.w, cy, black_pixel);
- return 0;
+ return NULL;
+}
+
+static pthread_t loader_thread = (pthread_t)0;
+static struct loader_params params;
+
+static void show_image(const char *img_path, int clear)
+{
+ int ret;
+
+ params.img_path = img_path;
+ params.clear = clear;
+
+ /* stop previous loader thread */
+ if (loader_thread) {
+ abort_flag = 1;
+ pthread_join(loader_thread, NULL);
+ loader_thread = (pthread_t)0;
+ abort_flag = 0;
+ }
+
+ ret = pthread_create(&loader_thread, NULL, image_loader, (void*)¶ms);
+
+ if (ret) {
+ fprintf(stderr, "Failed to start thread: %sn", strerror(ret));
+ GP_FramebufferExit(fb);
+ exit(1);
+ }
+}
+
+static void sighandler(int signo __attribute__((unused)))
+{
+ if (fb != NULL)
+ GP_FramebufferExit(fb);
+
+ exit(1);
}
int main(int argc, char *argv[])
@@ -204,7 +261,7 @@ int main(int argc, char *argv[])
int argf = optind;
int argn = argf;
- show_image(fb, argv[argf], 1);
+ show_image(argv[argf], 1);
/* Initalize select */
fd_set rfds;
@@ -231,7 +288,7 @@ int main(int argc, char *argv[])
if (argn >= argc)
argn = argf;
- show_image(fb, argv[argn], 0);
+ show_image(argv[argn], 0);
break;
default:
while (GP_InputDriverLinuxRead(drv));
@@ -245,7 +302,7 @@ int main(int argc, char *argv[])
if (argn >= argc)
argn = argf;
- show_image(fb, argv[argn], 0);
+ show_image(argv[argn], 0);
}
/* Read and parse events */
@@ -265,7 +322,7 @@ int main(int argc, char *argv[])
rotate += 90;
if (rotate > 270)
rotate = 0;
- show_image(fb, argv[argn], 1);
+ show_image(argv[argn], 1);
break;
case GP_KEY_ESC:
case GP_KEY_ENTER:
@@ -273,11 +330,20 @@ int main(int argc, char *argv[])
GP_FramebufferExit(fb);
return 0;
break;
+ case GP_KEY_UP:
case GP_KEY_SPACE:
argn++;
if (argn >= argc)
argn = argf;
- show_image(fb, argv[argn], 1);
+ show_image(argv[argn], 1);
+ break;
+ case GP_KEY_DOWN:
+ argn--;
+
+ if (argn < argf)
+ argn = argc - 1;
+
+ show_image(argv[argn], 1);
break;
}
break;
diff --git a/demos/fbshow/runtest.sh b/demos/fbshow/runtest.sh
index 163c76c..0794707 100755
--- a/demos/fbshow/runtest.sh
+++ b/demos/fbshow/runtest.sh
@@ -6,5 +6,4 @@
PROG="$1"
shift
-echo "LD_LIBRARY_PATH=../../build/ ./$PROG $@"
LD_LIBRARY_PATH=../../build/ ./$PROG "$@"
http://repo.or.cz/w/gfxprim.git/commit/cd3240b7d4f5cd92e2dbbf750807cfac4d82…
commit cd3240b7d4f5cd92e2dbbf750807cfac4d8299ea
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Tue Nov 1 21:00:55 2011 +0100
Fix the mirror filters.
For odd size and dst != src we must copy the middle odd line.
diff --git a/libs/filters/GP_MirrorV.gen.c.t b/libs/filters/GP_MirrorV.gen.c.t
index cdc21cd..a54d949 100644
--- a/libs/filters/GP_MirrorV.gen.c.t
+++ b/libs/filters/GP_MirrorV.gen.c.t
@@ -30,7 +30,14 @@ int GP_MirrorV_Raw_{{ ps.suffix }}(const GP_Context *src, GP_Context *dst,
if (GP_ProgressCallbackReport(callback, 2 * x, src->w, src->h))
return 1;
}
-
+
+ /* Copy the middle odd line */
+ if (src != dst && src->w % 2) {
+ x = src->w / 2;
+ for (y = 0; y < src->h; y++)
+ GP_PutPixel_Raw_{{ ps.suffix }}(dst, x, y, GP_GetPixel_Raw_{{ ps.suffix }}(src, x, y));
+ }
+
GP_ProgressCallbackDone(callback);
return 0;
}
diff --git a/libs/filters/GP_Rotate.c b/libs/filters/GP_Rotate.c
index b45b74c..1409e06 100644
--- a/libs/filters/GP_Rotate.c
+++ b/libs/filters/GP_Rotate.c
@@ -37,19 +37,32 @@ int GP_FilterMirrorH_Raw(const GP_Context *src, GP_Context *dst,
GP_DEBUG(1, "Mirroring image horizontally %ux%u", src->w, src->h);
#warning FIXME: non byte aligned pixels
-
+
+ /* Note that this should work both for src != dst and src == dst */
for (y = 0; y < src->h/2; y++) {
- uint8_t *l1 = dst->pixels + bpr * y;
- uint8_t *l2 = dst->pixels + bpr * (src->h - y - 1);
-
- memcpy(buf, l1, bpr);
- memcpy(l1, l2, bpr);
- memcpy(l2, buf, bpr);
+ uint8_t *sl1 = src->pixels + bpr * y;
+ uint8_t *sl2 = src->pixels + bpr * (src->h - y - 1);
+ uint8_t *dl1 = dst->pixels + bpr * y;
+ uint8_t *dl2 = dst->pixels + bpr * (src->h - y - 1);
+
+ memcpy(buf, sl1, bpr);
+ memcpy(dl1, sl2, bpr);
+ memcpy(dl2, buf, bpr);
if (GP_ProgressCallbackReport(callback, 2 * y, src->h, src->w))
return 1;
}
+ /* Copy the middle odd line */
+ if (src != dst && src->h % 2) {
+ y = src->h / 2;
+
+ uint8_t *sl = src->pixels + bpr * y;
+ uint8_t *dl = dst->pixels + bpr * y;
+
+ memcpy(dl, sl, bpr);
+ }
+
GP_ProgressCallbackDone(callback);
return 0;
}
http://repo.or.cz/w/gfxprim.git/commit/c696722f489a1cd8e8019dd27821e260f2f8…
commit c696722f489a1cd8e8019dd27821e260f2f80756
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Tue Nov 1 19:16:28 2011 +0100
The filter could now be aborted from progress callback.
If progress callback returns non zero number
the filter is aborted, allocated memory freed
and NULL is returned.
diff --git a/demos/grinder/grinder.c b/demos/grinder/grinder.c
index 51c362b..2854ac3 100644
--- a/demos/grinder/grinder.c
+++ b/demos/grinder/grinder.c
@@ -33,10 +33,12 @@ static GP_ProgressCallback *progress_callback = NULL;
static const char *progress_prefix = NULL;
-static void show_progress(GP_ProgressCallback *self)
+static int show_progress(GP_ProgressCallback *self)
{
fprintf(stderr, "rFilter %s %3.2f%%",
progress_prefix, self->percentage);
+
+ return 0;
}
static int param_err(const struct param *self, const char *val, void *priv)
diff --git a/include/filters/GP_Filter.h b/include/filters/GP_Filter.h
index 20d323c..74637ab 100644
--- a/include/filters/GP_Filter.h
+++ b/include/filters/GP_Filter.h
@@ -33,26 +33,37 @@
/*
* Progress callback
+ *
+ * Non zero return value from callback will abort current operation
+ * free memory and return NULL from filter.
*/
typedef struct GP_ProgressCallback {
float percentage;
- void (*callback)(struct GP_ProgressCallback *self);
+ int (*callback)(struct GP_ProgressCallback *self);
void *priv;
} GP_ProgressCallback;
-static inline void GP_ProgressCallbackReport(GP_ProgressCallback *callback,
- float percentage)
+static inline int GP_ProgressCallbackReport(GP_ProgressCallback *callback,
+ unsigned int val, unsigned int max,
+ unsigned int mul __attribute__((unused)))
{
if (callback == NULL)
- return;
+ return 0;
- callback->percentage = percentage;
- callback->callback(callback);
+ if (val % 100)
+ return 0;
+
+ callback->percentage = 100.00 * val / max;
+ return callback->callback(callback);
}
static inline void GP_ProgressCallbackDone(GP_ProgressCallback *callback)
{
- GP_ProgressCallbackReport(callback, 100);
+ if (callback == NULL)
+ return;
+
+ callback->percentage = 100;
+ callback->callback(callback);
}
#endif /* FILTERS_GP_FILTER_H */
diff --git a/include/filters/GP_Linear.h b/include/filters/GP_Linear.h
index 3c0d1e9..21c627b 100644
--- a/include/filters/GP_Linear.h
+++ b/include/filters/GP_Linear.h
@@ -44,9 +44,9 @@
*
* GP_FilterGaussianBlur_Raw(context, context, ...);
*/
-void GP_FilterGaussianBlur_Raw(const GP_Context *src, GP_Context *dst,
- float sigma_x, float sigma_y,
- GP_ProgressCallback *callback);
+int GP_FilterGaussianBlur_Raw(const GP_Context *src, GP_Context *dst,
+ float sigma_x, float sigma_y,
+ GP_ProgressCallback *callback);
/*
* Gaussian blur.
*
@@ -78,9 +78,9 @@ GP_Context *GP_FilterGaussianBlur(const GP_Context *src, GP_Context *dst,
*
* This function works also in-place.
*/
-void GP_FilterLinearConvolution_Raw(const GP_Context *src, GP_Context *dst,
- float kernel[], uint32_t kw, uint32_t kh,
- GP_ProgressCallback *callback);
+int GP_FilterLinearConvolution_Raw(const GP_Context *src, GP_Context *dst,
+ float kernel[], uint32_t kw, uint32_t kh,
+ GP_ProgressCallback *callback);
/*
* Special cases for convolution only in horizontal/vertical direction.
@@ -92,12 +92,12 @@ void GP_FilterLinearConvolution_Raw(const GP_Context *src, GP_Context *dst,
*
* Both works also in-place.
*/
-void GP_FilterHLinearConvolution_Raw(const GP_Context *src, GP_Context *dst,
- float kernel[], uint32_t kw,
- GP_ProgressCallback *callback);
+int GP_FilterHLinearConvolution_Raw(const GP_Context *src, GP_Context *dst,
+ float kernel[], uint32_t kw,
+ GP_ProgressCallback *callback);
-void GP_FilterVLinearConvolution_Raw(const GP_Context *src, GP_Context *dst,
- float kernel[], uint32_t kh,
- GP_ProgressCallback *callback);
+int GP_FilterVLinearConvolution_Raw(const GP_Context *src, GP_Context *dst,
+ float kernel[], uint32_t kh,
+ GP_ProgressCallback *callback);
#endif /* FILTERS_GP_LINEAR_H */
diff --git a/include/filters/GP_Resize.h b/include/filters/GP_Resize.h
index 63a6143..692339c 100644
--- a/include/filters/GP_Resize.h
+++ b/include/filters/GP_Resize.h
@@ -54,9 +54,9 @@ typedef enum GP_InterpolationType {
/*
* Just interpolate the source context into destination context.
*/
-void GP_FilterResize_Raw(const GP_Context *src, GP_Context *dst,
- GP_InterpolationType type,
- GP_ProgressCallback *callback);
+int GP_FilterResize_Raw(const GP_Context *src, GP_Context *dst,
+ GP_InterpolationType type,
+ GP_ProgressCallback *callback);
/*
* If destination is non NULL, the w and h are used to create subcontext from
diff --git a/include/filters/GP_Rotate.h b/include/filters/GP_Rotate.h
index 245e3c2..515d2b5 100644
--- a/include/filters/GP_Rotate.h
+++ b/include/filters/GP_Rotate.h
@@ -37,8 +37,8 @@
*
* Works 'in place'. The contexts must have equal pixel_type and size.
*/
-void GP_FilterMirrorH_Raw(const GP_Context *src, GP_Context *dst,
- GP_ProgressCallback *callback);
+int GP_FilterMirrorH_Raw(const GP_Context *src, GP_Context *dst,
+ GP_ProgressCallback *callback);
/*
* Mirrors bitmap horizontally.
@@ -55,8 +55,8 @@ GP_Context *GP_FilterMirrorH(const GP_Context *src, GP_Context *dst,
*
* Works 'in place'. The contexts must have equal pixel_type and size.
*/
-void GP_FilterMirrorV_Raw(const GP_Context *src, GP_Context *dst,
- GP_ProgressCallback *callback);
+int GP_FilterMirrorV_Raw(const GP_Context *src, GP_Context *dst,
+ GP_ProgressCallback *callback);
/*
* Mirrors bitmap vertically.
@@ -74,14 +74,14 @@ GP_Context *GP_FilterMirrorV(const GP_Context *src, GP_Context *dst,
* Doesn't work 'in place'. The contexts must have equal pixel_type size must
* match the rotated size (is equal for 180 and swapped for 90 and 270).
*/
-void GP_FilterRotate90_Raw(const GP_Context *src, GP_Context *dst,
- GP_ProgressCallback *callback);
+int GP_FilterRotate90_Raw(const GP_Context *src, GP_Context *dst,
+ GP_ProgressCallback *callback);
-void GP_FilterRotate180_Raw(const GP_Context *src, GP_Context *dst,
- GP_ProgressCallback *callback);
+int GP_FilterRotate180_Raw(const GP_Context *src, GP_Context *dst,
+ GP_ProgressCallback *callback);
-void GP_FilterRotate270_Raw(const GP_Context *src, GP_Context *dst,
- GP_ProgressCallback *callback);
+int GP_FilterRotate270_Raw(const GP_Context *src, GP_Context *dst,
+ GP_ProgressCallback *callback);
/*
* Rotate the context by 90, 180, 270.
diff --git a/libs/filters/GP_Linear.c b/libs/filters/GP_Linear.c
index b0148c9..e5b8d81 100644
--- a/libs/filters/GP_Linear.c
+++ b/libs/filters/GP_Linear.c
@@ -49,19 +49,25 @@ static inline void gaussian_kernel_init(float sigma, float *kernel)
}
}
-static void gaussian_callback_1(GP_ProgressCallback *self)
+static int gaussian_callback_horiz(GP_ProgressCallback *self)
{
- GP_ProgressCallbackReport(self->priv, self->percentage/2);
+ GP_ProgressCallback *callback = self->priv;
+
+ callback->percentage = self->percentage / 2;
+ return callback->callback(callback);
}
-static void gaussian_callback_2(GP_ProgressCallback *self)
+static int gaussian_callback_vert(GP_ProgressCallback *self)
{
- GP_ProgressCallbackReport(self->priv, self->percentage/2 + 50);
+ GP_ProgressCallback *callback = self->priv;
+
+ callback->percentage = self->percentage / 2 + 50;
+ return callback->callback(callback);
}
-void GP_FilterGaussianBlur_Raw(const GP_Context *src, GP_Context *dst,
- float sigma_x, float sigma_y,
- GP_ProgressCallback *callback)
+int GP_FilterGaussianBlur_Raw(const GP_Context *src, GP_Context *dst,
+ float sigma_x, float sigma_y,
+ GP_ProgressCallback *callback)
{
unsigned int size_x = gaussian_kernel_size(sigma_x);
unsigned int size_y = gaussian_kernel_size(sigma_y);
@@ -72,7 +78,7 @@ void GP_FilterGaussianBlur_Raw(const GP_Context *src, GP_Context *dst,
GP_ProgressCallback *new_callback = NULL;
GP_ProgressCallback gaussian_callback = {
- .callback = gaussian_callback_1,
+ .callback = gaussian_callback_horiz,
.priv = callback
};
@@ -84,23 +90,26 @@ void GP_FilterGaussianBlur_Raw(const GP_Context *src, GP_Context *dst,
float kernel_x[size_x];
gaussian_kernel_init(sigma_x, kernel_x);
- GP_FilterHLinearConvolution_Raw(src, dst, kernel_x, size_x,
- new_callback);
+ if (GP_FilterHLinearConvolution_Raw(src, dst, kernel_x, size_x,
+ new_callback))
+ return 1;
}
if (new_callback != NULL)
- new_callback->callback = gaussian_callback_2;
+ new_callback->callback = gaussian_callback_vert;
/* compute kernel and apply in vertical direction */
if (sigma_y > 0) {
float kernel_y[size_y];
gaussian_kernel_init(sigma_y, kernel_y);
- GP_FilterVLinearConvolution_Raw(dst, dst, kernel_y, size_y,
- new_callback);
+ if (GP_FilterVLinearConvolution_Raw(dst, dst, kernel_y, size_y,
+ new_callback))
+ return 1;
}
GP_ProgressCallbackDone(callback);
+ return 0;
}
GP_Context *GP_FilterGaussianBlur(const GP_Context *src, GP_Context *dst,
@@ -128,9 +137,9 @@ GP_Context *GP_FilterGaussianBlur(const GP_Context *src, GP_Context *dst,
return dst;
}
-void GP_FilterHLinearConvolution_Raw(const GP_Context *src, GP_Context *dst,
- float kernel[], uint32_t kw,
- GP_ProgressCallback *callback)
+int GP_FilterHLinearConvolution_Raw(const GP_Context *src, GP_Context *dst,
+ float kernel[], uint32_t kw,
+ GP_ProgressCallback *callback)
{
float kernel_sum = 0;
GP_Coord x, y;
@@ -221,11 +230,12 @@ void GP_FilterHLinearConvolution_Raw(const GP_Context *src, GP_Context *dst,
idx = 0;
}
- if (callback != NULL && y % 100 == 0)
- GP_ProgressCallbackReport(callback, 100.00 * y/dst->h);
+ if (GP_ProgressCallbackReport(callback, y, dst->h, dst->w))
+ return 1;
}
GP_ProgressCallbackDone(callback);
+ return 0;
}
/*
@@ -233,9 +243,9 @@ void GP_FilterHLinearConvolution_Raw(const GP_Context *src, GP_Context *dst,
*
* Can be used in-place.
*/
-void GP_FilterVLinearConvolution_Raw(const GP_Context *src, GP_Context *dst,
- float kernel[], uint32_t kh,
- GP_ProgressCallback *callback)
+int GP_FilterVLinearConvolution_Raw(const GP_Context *src, GP_Context *dst,
+ float kernel[], uint32_t kh,
+ GP_ProgressCallback *callback)
{
float kernel_sum = 0;
GP_Coord x, y;
@@ -326,11 +336,12 @@ void GP_FilterVLinearConvolution_Raw(const GP_Context *src, GP_Context *dst,
idx = 0;
}
- if (callback != NULL && x % 100 == 0)
- GP_ProgressCallbackReport(callback, 100.00 * x/dst->w);
+ if (GP_ProgressCallbackReport(callback, x, dst->w, dst->h))
+ return 1;
}
GP_ProgressCallbackDone(callback);
+ return 0;
}
@@ -339,9 +350,9 @@ void GP_FilterVLinearConvolution_Raw(const GP_Context *src, GP_Context *dst,
*
* Can be used in-place.
*/
-void GP_FilterLinearConvolution_Raw(const GP_Context *src, GP_Context *dst,
- float kernel[], uint32_t kw, uint32_t kh,
- GP_ProgressCallback *callback)
+int GP_FilterLinearConvolution_Raw(const GP_Context *src, GP_Context *dst,
+ float kernel[], uint32_t kw, uint32_t kh,
+ GP_ProgressCallback *callback)
{
float kernel_sum = 0;
GP_Coord x, y;
@@ -452,9 +463,10 @@ void GP_FilterLinearConvolution_Raw(const GP_Context *src, GP_Context *dst,
idx = 0;
}
- if (callback != NULL && y % 100 == 0)
- GP_ProgressCallbackReport(callback, 100.00 * y/dst->h);
+ if (GP_ProgressCallbackReport(callback, y, dst->h, dst->w))
+ return 1;
}
GP_ProgressCallbackDone(callback);
+ return 0;
}
diff --git a/libs/filters/GP_MirrorV.gen.c.t b/libs/filters/GP_MirrorV.gen.c.t
index c696349..cdc21cd 100644
--- a/libs/filters/GP_MirrorV.gen.c.t
+++ b/libs/filters/GP_MirrorV.gen.c.t
@@ -11,7 +11,7 @@ Vertical Mirror alogorithm
#include "GP_Rotate.h"
%% for ps in pixelsizes
-void GP_MirrorV_Raw_{{ ps.suffix }}(const GP_Context *src, GP_Context *dst,
+int GP_MirrorV_Raw_{{ ps.suffix }}(const GP_Context *src, GP_Context *dst,
GP_ProgressCallback *callback)
{
uint32_t x, y;
@@ -27,18 +27,20 @@ void GP_MirrorV_Raw_{{ ps.suffix }}(const GP_Context *src, GP_Context *dst,
GP_PutPixel_Raw_{{ ps.suffix }}(dst, xm, y, tmp);
}
- if (callback != NULL && x % 100 == 0)
- GP_ProgressCallbackReport(callback, 200.00 * x / src->w);
+ if (GP_ProgressCallbackReport(callback, 2 * x, src->w, src->h))
+ return 1;
}
GP_ProgressCallbackDone(callback);
+ return 0;
}
%% endfor
-void GP_FilterMirrorV_Raw(const GP_Context *src, GP_Context *dst,
+int GP_FilterMirrorV_Raw(const GP_Context *src, GP_Context *dst,
GP_ProgressCallback *callback)
{
- GP_FN_PER_BPP_CONTEXT(GP_MirrorV_Raw, src, src, dst, callback);
+ GP_FN_RET_PER_BPP_CONTEXT(GP_MirrorV_Raw, src, src, dst, callback);
+ return 1;
}
%% endblock body
diff --git a/libs/filters/GP_Resize.c b/libs/filters/GP_Resize.c
index eb42478..1c7d593 100644
--- a/libs/filters/GP_Resize.c
+++ b/libs/filters/GP_Resize.c
@@ -27,8 +27,8 @@
#include <GP_Resize.h>
-void GP_FilterInterpolate_NN(const GP_Context *src, GP_Context *dst,
- GP_ProgressCallback *callback)
+int GP_FilterInterpolate_NN(const GP_Context *src, GP_Context *dst,
+ GP_ProgressCallback *callback)
{
GP_Coord x, y;
@@ -46,11 +46,12 @@ void GP_FilterInterpolate_NN(const GP_Context *src, GP_Context *dst,
GP_PutPixel_Raw_24BPP(dst, x, y, pix);
}
- if (callback != NULL && y % 100 == 0)
- GP_ProgressCallbackReport(callback, 100.00 * y/dst->h);
+ if (GP_ProgressCallbackReport(callback, y, dst->h, dst->w))
+ return 1;
}
GP_ProgressCallbackDone(callback);
+ return 0;
}
#define A 0.5
@@ -79,8 +80,8 @@ typedef union v4f {
#define MUL_V4SF(a, b) ((union v4f)((a).v * (b).v))
#define SUM_V4SF(a) ((a).f[0] + (a).f[1] + (a).f[2] + (a).f[3])
-void GP_FilterInterpolate_Cubic(const GP_Context *src, GP_Context *dst,
- GP_ProgressCallback *callback)
+int GP_FilterInterpolate_Cubic(const GP_Context *src, GP_Context *dst,
+ GP_ProgressCallback *callback)
{
float col_r[src->h], col_g[src->h], col_b[src->h];
uint32_t i, j;
@@ -202,25 +203,26 @@ void GP_FilterInterpolate_Cubic(const GP_Context *src, GP_Context *dst,
GP_PutPixel_Raw_24BPP(dst, i, j, pix);
}
- if (callback != NULL && i % 100 == 0)
- GP_ProgressCallbackReport(callback, 100.00 * i/dst->w);
+ if (GP_ProgressCallbackReport(callback, i, dst->w, dst->h))
+ return 1;
}
GP_ProgressCallbackDone(callback);
+ return 0;
}
-void GP_FilterResize_Raw(const GP_Context *src, GP_Context *dst,
- GP_InterpolationType type,
- GP_ProgressCallback *callback)
+int GP_FilterResize_Raw(const GP_Context *src, GP_Context *dst,
+ GP_InterpolationType type,
+ GP_ProgressCallback *callback)
{
switch (type) {
case GP_INTERP_NN:
- GP_FilterInterpolate_NN(src, dst, callback);
- break;
+ return GP_FilterInterpolate_NN(src, dst, callback);
case GP_INTERP_CUBIC:
- GP_FilterInterpolate_Cubic(src, dst, callback);
- break;
+ return GP_FilterInterpolate_Cubic(src, dst, callback);
}
+
+ return 1;
}
GP_Context *GP_FilterResize(const GP_Context *src, GP_Context *dst,
@@ -235,12 +237,10 @@ GP_Context *GP_FilterResize(const GP_Context *src, GP_Context *dst,
return NULL;
if (dst == NULL) {
- dst = GP_ContextAlloc(w, h, src->pixel_type);
+ res = GP_ContextAlloc(w, h, src->pixel_type);
- if (dst == NULL)
+ if (res == NULL)
return NULL;
-
- res = dst;
} else {
GP_ASSERT(src->pixel_type == dst->pixel_type,
"The src and dst pixel types must match");
@@ -250,7 +250,19 @@ GP_Context *GP_FilterResize(const GP_Context *src, GP_Context *dst,
res = GP_ContextSubContext(dst, &sub, 0, 0, w, h);
}
- GP_FilterResize_Raw(src, res, type, callback);
+ /*
+ * Operation was aborted by progress callback.
+ *
+ * Free any alloacted data and exit.
+ */
+ if (GP_FilterResize_Raw(src, res, type, callback)) {
+ GP_DEBUG(1, "Operation aborted");
+
+ if (dst == NULL)
+ GP_ContextFree(dst);
+
+ return NULL;
+ }
- return dst;
+ return dst == NULL ? res : dst;
}
diff --git a/libs/filters/GP_Rotate.c b/libs/filters/GP_Rotate.c
index 73987e7..b45b74c 100644
--- a/libs/filters/GP_Rotate.c
+++ b/libs/filters/GP_Rotate.c
@@ -27,8 +27,8 @@
#include <string.h>
-void GP_FilterMirrorH_Raw(const GP_Context *src, GP_Context *dst,
- GP_ProgressCallback *callback)
+int GP_FilterMirrorH_Raw(const GP_Context *src, GP_Context *dst,
+ GP_ProgressCallback *callback)
{
uint32_t bpr = src->bytes_per_row;
uint8_t buf[bpr];
@@ -46,20 +46,23 @@ void GP_FilterMirrorH_Raw(const GP_Context *src, GP_Context *dst,
memcpy(l1, l2, bpr);
memcpy(l2, buf, bpr);
- if (callback != NULL && y % 100 == 0)
- GP_ProgressCallbackReport(callback, 200.00 * y / src->h);
+ if (GP_ProgressCallbackReport(callback, 2 * y, src->h, src->w))
+ return 1;
}
GP_ProgressCallbackDone(callback);
+ return 0;
}
GP_Context *GP_FilterMirrorH(const GP_Context *src, GP_Context *dst,
GP_ProgressCallback *callback)
{
- if (dst == NULL) {
- dst = GP_ContextCopy(src, 0);
+ GP_Context *res = dst;
+
+ if (res == NULL) {
+ res = GP_ContextCopy(src, 0);
- if (dst == NULL)
+ if (res == NULL)
return NULL;
} else {
GP_ASSERT(src->pixel_type == dst->pixel_type,
@@ -68,19 +71,28 @@ GP_Context *GP_FilterMirrorH(const GP_Context *src, GP_Context *dst,
"Destination is not big enough");
}
- GP_FilterMirrorH_Raw(src, dst, callback);
+ if (GP_FilterMirrorH_Raw(src, res, callback)) {
+ GP_DEBUG(1, "Operation aborted");
+
+ if (dst == NULL)
+ GP_ContextFree(res);
+
+ return NULL;
+ }
- return dst;
+ return res;
}
GP_Context *GP_FilterMirrorV(const GP_Context *src, GP_Context *dst,
GP_ProgressCallback *callback)
{
- if (dst == NULL) {
- dst = GP_ContextCopy(src, 0);
+ GP_Context *res = dst;
+
+ if (res == NULL) {
+ res = GP_ContextCopy(src, 0);
- if (dst == NULL)
+ if (res == NULL)
return NULL;
} else {
GP_ASSERT(src->pixel_type == dst->pixel_type,
@@ -89,27 +101,38 @@ GP_Context *GP_FilterMirrorV(const GP_Context *src, GP_Context *dst,
"Destination is not big enough");
}
- GP_FilterMirrorV_Raw(src, dst, callback);
+ if (GP_FilterMirrorV_Raw(src, dst, callback)) {
+ GP_DEBUG(1, "Operation aborted");
+
+ if (dst == NULL)
+ GP_ContextFree(res);
+
+ return NULL;
+ }
- return dst;
+ return res;
}
-void GP_FilterRotate180_Raw(const GP_Context *src, GP_Context *dst,
- GP_ProgressCallback *callback)
+int GP_FilterRotate180_Raw(const GP_Context *src, GP_Context *dst,
+ GP_ProgressCallback *callback)
{
#warning FIXME: Callbacks, faster algorighm?
GP_FilterMirrorV_Raw(src, dst, NULL);
GP_FilterMirrorH_Raw(dst, dst, callback);
+
+ return 0;
}
GP_Context *GP_FilterRotate90(const GP_Context *src, GP_Context *dst,
GP_ProgressCallback *callback)
{
- if (dst == NULL) {
- dst = GP_ContextAlloc(src->h, src->w, src->pixel_type);
+ GP_Context *res = dst;
+
+ if (res == NULL) {
+ res = GP_ContextAlloc(src->h, src->w, src->pixel_type);
- if (dst == NULL)
+ if (res == NULL)
return NULL;
} else {
GP_ASSERT(src->pixel_type == dst->pixel_type,
@@ -118,18 +141,27 @@ GP_Context *GP_FilterRotate90(const GP_Context *src, GP_Context *dst,
"Destination is not big enough");
}
- GP_FilterRotate90_Raw(src, dst, callback);
+ if (GP_FilterRotate90_Raw(src, res, callback)) {
+ GP_DEBUG(1, "Operation aborted");
+
+ if (dst == NULL)
+ GP_ContextFree(res);
+
+ return NULL;
+ }
- return dst;
+ return res;
}
GP_Context *GP_FilterRotate180(const GP_Context *src, GP_Context *dst,
GP_ProgressCallback *callback)
{
- if (dst == NULL) {
- dst = GP_ContextCopy(src, 0);
+ GP_Context *res = dst;
+
+ if (res == NULL) {
+ res = GP_ContextCopy(src, 0);
- if (dst == NULL)
+ if (res == NULL)
return NULL;
} else {
GP_ASSERT(src->pixel_type == dst->pixel_type,
@@ -138,18 +170,27 @@ GP_Context *GP_FilterRotate180(const GP_Context *src, GP_Context *dst,
"Destination is not big enough");
}
- GP_FilterRotate180_Raw(src, dst, callback);
+ if (GP_FilterRotate180_Raw(src, res, callback)) {
+ GP_DEBUG(1, "Operation aborted");
+
+ if (dst == NULL)
+ GP_ContextFree(res);
+
+ return NULL;
+ }
- return dst;
+ return res;
}
GP_Context *GP_FilterRotate270(const GP_Context *src, GP_Context *dst,
GP_ProgressCallback *callback)
{
- if (dst == NULL) {
- dst = GP_ContextAlloc(src->h, src->w, src->pixel_type);
+ GP_Context *res = dst;
+
+ if (res == NULL) {
+ res = GP_ContextAlloc(src->h, src->w, src->pixel_type);
- if (dst == NULL)
+ if (res == NULL)
return NULL;
} else {
GP_ASSERT(src->pixel_type == dst->pixel_type,
@@ -158,9 +199,16 @@ GP_Context *GP_FilterRotate270(const GP_Context *src, GP_Context *dst,
"Destination is not big enough");
}
- GP_FilterRotate270_Raw(src, dst, callback);
+ if (GP_FilterRotate270_Raw(src, res, callback)) {
+ GP_DEBUG(1, "Operation aborted");
+
+ if (dst == NULL)
+ GP_ContextFree(res);
+
+ return NULL;
+ }
- return dst;
+ return res;
}
GP_Context *GP_FilterSymmetry(const GP_Context *src, GP_Context *dst,
@@ -180,5 +228,7 @@ GP_Context *GP_FilterSymmetry(const GP_Context *src, GP_Context *dst,
return GP_FilterMirrorV(src, dst, callback);
}
+ GP_DEBUG(1, "Invalid symmetry %i", (int) symmetry);
+
return NULL;
}
diff --git a/libs/filters/GP_Rotate.gen.c.t b/libs/filters/GP_Rotate.gen.c.t
index 9ef7bd9..af2e679 100644
--- a/libs/filters/GP_Rotate.gen.c.t
+++ b/libs/filters/GP_Rotate.gen.c.t
@@ -11,8 +11,8 @@ Vertical Mirror alogorithm
#include "GP_Rotate.h"
%% for ps in pixelsizes
-void GP_FilterRotate90_Raw_{{ ps.suffix }}(const GP_Context *src, GP_Context *dst,
- GP_ProgressCallback *callback)
+int GP_FilterRotate90_Raw_{{ ps.suffix }}(const GP_Context *src, GP_Context *dst,
+ GP_ProgressCallback *callback)
{
uint32_t x, y;
@@ -24,23 +24,25 @@ void GP_FilterRotate90_Raw_{{ ps.suffix }}(const GP_Context *src, GP_Context *ds
GP_PutPixel_Raw_{{ ps.suffix }}(dst, yr, x, GP_GetPixel_Raw_{{ ps.suffix }}(src, x, y));
}
- if (callback != NULL && x % 100 == 0)
- GP_ProgressCallbackReport(callback, 100.00 * x / src->w);
+ if (GP_ProgressCallbackReport(callback, x, src->w, src->h))
+ return 1;
}
GP_ProgressCallbackDone(callback);
+ return 0;
}
%% endfor
-void GP_FilterRotate90_Raw(const GP_Context *src, GP_Context *dst,
- GP_ProgressCallback *callback)
+int GP_FilterRotate90_Raw(const GP_Context *src, GP_Context *dst,
+ GP_ProgressCallback *callback)
{
- GP_FN_PER_BPP_CONTEXT(GP_FilterRotate90_Raw, src, src, dst, callback);
+ GP_FN_RET_PER_BPP_CONTEXT(GP_FilterRotate90_Raw, src, src, dst, callback);
+ return 1;
}
%% for ps in pixelsizes
-void GP_FilterRotate270_Raw_{{ ps.suffix }}(const GP_Context *src, GP_Context *dst,
+int GP_FilterRotate270_Raw_{{ ps.suffix }}(const GP_Context *src, GP_Context *dst,
GP_ProgressCallback *callback)
{
uint32_t x, y;
@@ -53,19 +55,21 @@ void GP_FilterRotate270_Raw_{{ ps.suffix }}(const GP_Context *src, GP_Context *d
GP_PutPixel_Raw_{{ ps.suffix }}(dst, y, xr, GP_GetPixel_Raw_{{ ps.suffix }}(src, x, y));
}
- if (callback != NULL && x % 100 == 0)
- GP_ProgressCallbackReport(callback, 100.00 * x / src->w);
+ if (GP_ProgressCallbackReport(callback, x, src->w, src->h))
+ return 1;
}
GP_ProgressCallbackDone(callback);
+ return 0;
}
%% endfor
-void GP_FilterRotate270_Raw(const GP_Context *src, GP_Context *dst,
- GP_ProgressCallback *callback)
+int GP_FilterRotate270_Raw(const GP_Context *src, GP_Context *dst,
+ GP_ProgressCallback *callback)
{
- GP_FN_PER_BPP_CONTEXT(GP_FilterRotate270_Raw, src, src, dst, callback);
+ GP_FN_RET_PER_BPP_CONTEXT(GP_FilterRotate270_Raw, src, src, dst, callback);
+ return 1;
}
%% endblock body
diff --git a/pylib/templates/filter.point.c.t b/pylib/templates/filter.point.c.t
index 4c3bdaa..9a925cf 100644
--- a/pylib/templates/filter.point.c.t
+++ b/pylib/templates/filter.point.c.t
@@ -16,7 +16,7 @@
%% macro filter_per_pixel_size(name, opts="")
%% for ps in pixelsizes
%% if ps.size <= 8 and ps.size > 1
-void GP_Filter{{ name }}_{{ ps.suffix }}(const GP_Context *src, GP_Context *dst{{ maybe_opts(opts) }},
+int GP_Filter{{ name }}_{{ ps.suffix }}(const GP_Context *src, GP_Context *dst{{ maybe_opts(opts) }},
GP_ProgressCallback *callback)
{
uint32_t x, y;
@@ -28,11 +28,12 @@ void GP_Filter{{ name }}_{{ ps.suffix }}(const GP_Context *src, GP_Context *dst{
GP_PutPixel_Raw_{{ ps.suffix }}(dst, x, y, pix);
}
- if (callback != NULL && y % 100 == 0)
- GP_ProgressCallbackReport(callback, 100.00 * y/src->h);
+ if (GP_ProgressCallbackReport(callback, y, src->h, src->w))
+ return 1;
}
GP_ProgressCallbackDone(callback);
+ return 0;
}
%% endif
%% endfor
@@ -44,7 +45,7 @@ void GP_Filter{{ name }}_{{ ps.suffix }}(const GP_Context *src, GP_Context *dst{
%% macro filter_per_pixel_type(name, opts="")
%% for pt in pixeltypes
%% if not pt.is_unknown() and len(pt.chanslist) > 1
-void GP_Filter{{ name }}_{{ pt.name }}(const GP_Context *src, GP_Context *dst{{ maybe_opts(opts) }},
+int GP_Filter{{ name }}_{{ pt.name }}(const GP_Context *src, GP_Context *dst{{ maybe_opts(opts) }},
GP_ProgressCallback *callback)
{
uint32_t x, y;
@@ -65,11 +66,12 @@ void GP_Filter{{ name }}_{{ pt.name }}(const GP_Context *src, GP_Context *dst{{
GP_PutPixel_Raw_{{ pt.pixelsize.suffix }}(dst, x, y, pix);
}
- if (callback != NULL && y % 100 == 0)
- GP_ProgressCallbackReport(callback, 100.00 * y/src->h);
+ if (GP_ProgressCallbackReport(callback, y, src->h, src->w))
+ return 1;
}
GP_ProgressCallbackDone(callback);
+ return 0;
}
%% endif
@@ -91,7 +93,7 @@ void GP_Filter{{ name }}_{{ pt.name }}(const GP_Context *src, GP_Context *dst{{
* Switch per pixel sizes or pixel types.
*/
%% macro filter_functions(name, opts="", params="", fmt="")
-void GP_Filter{{ name }}_Raw(const GP_Context *src, GP_Context *dst{{ maybe_opts(opts) }},
+int GP_Filter{{ name }}_Raw(const GP_Context *src, GP_Context *dst{{ maybe_opts(opts) }},
GP_ProgressCallback *callback)
{
GP_DEBUG(1, "Running filter {{ name }} {{ fmt }}"{{ maybe_opts(params) }});
@@ -100,27 +102,29 @@ void GP_Filter{{ name }}_Raw(const GP_Context *src, GP_Context *dst{{ maybe_opts
%% for pt in pixeltypes
case GP_PIXEL_{{ pt.name }}:
%% if pt.is_unknown() or pt.pixelsize.size < 2
- return;
+ return 1;
%% elif len(pt.chanslist) == 1:
- GP_Filter{{ name }}_{{ pt.pixelsize.suffix }}(src, dst{{ maybe_opts(params) }}, callback);
+ return GP_Filter{{ name }}_{{ pt.pixelsize.suffix }}(src, dst{{ maybe_opts(params) }}, callback);
%% else
- GP_Filter{{ name }}_{{ pt.name }}(src, dst{{ maybe_opts(params) }}, callback);
+ return GP_Filter{{ name }}_{{ pt.name }}(src, dst{{ maybe_opts(params) }}, callback);
%% endif
- break;
%% endfor
default:
break;
}
+
+ return 1;
}
GP_Context *GP_Filter{{ name }}(const GP_Context *src, GP_Context *dst{{ maybe_opts(opts) }},
GP_ProgressCallback *callback)
{
+ GP_Context *res = dst;
- if (dst == NULL) {
- dst = GP_ContextCopy(src, 0);
+ if (res == NULL) {
+ res = GP_ContextCopy(src, 0);
- if (dst == NULL)
+ if (res == NULL)
return NULL;
} else {
GP_ASSERT(src->pixel_type == dst->pixel_type,
@@ -129,9 +133,16 @@ GP_Context *GP_Filter{{ name }}(const GP_Context *src, GP_Context *dst{{ maybe_o
"Destination is not big enough");
}
- GP_Filter{{ name }}_Raw(src, dst{{ maybe_opts(params) }}, callback);
+ if (GP_Filter{{ name }}_Raw(src, dst{{ maybe_opts(params) }}, callback)) {
+ GP_DEBUG(1, "Operation aborted");
+
+ if (dst == NULL)
+ GP_ContextFree(res);
+
+ return NULL;
+ }
- return dst;
+ return res;
}
%% endmacro
-----------------------------------------------------------------------
Summary of changes:
demos/fbshow/Makefile | 1 +
demos/fbshow/fbshow.c | 116 +++++++++++++++++++++++++-------
demos/fbshow/runtest.sh | 1 -
demos/grinder/grinder.c | 4 +-
include/filters/GP_Filter.h | 25 +++++--
include/filters/GP_Linear.h | 24 +++---
include/filters/GP_Resize.h | 6 +-
include/filters/GP_Rotate.h | 20 +++---
libs/filters/GP_Linear.c | 68 +++++++++++--------
libs/filters/GP_MirrorV.gen.c.t | 21 ++++--
libs/filters/GP_Resize.c | 54 +++++++++------
libs/filters/GP_Rotate.c | 137 +++++++++++++++++++++++++++----------
libs/filters/GP_Rotate.gen.c.t | 30 +++++----
pylib/templates/filter.point.c.t | 43 ++++++++-----
14 files changed, 370 insertions(+), 180 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
Good news everyone,
the generate branch is now good enough so it became our master branch for the
time being.
--
metan
1
0
[repo.or.cz] gfxprim.git branch master created: 55303a1b980b3e008a6cac5cf9070e21c1814a51
by metan 01 Nov '11
by metan 01 Nov '11
01 Nov '11
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 created
at 55303a1b980b3e008a6cac5cf9070e21c1814a51 (commit)
- Log -----------------------------------------------------------------
-----------------------------------------------------------------------
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