Gfxprim
Threads by month
- ----- 2026 -----
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- 929 discussions
[repo.or.cz] gfxprim.git branch master updated: d10318c0369619faa73b93abe840ea8e67cb5a52
by metan 11 Dec '11
by metan 11 Dec '11
11 Dec '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 d10318c0369619faa73b93abe840ea8e67cb5a52 (commit)
via db1bbab2baeb3c556862cacaa9ac9e0fa15ce859 (commit)
from 2f824b15387739be5c32dd417b6fabbf54234bc8 (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/d10318c0369619faa73b93abe840ea8e67cb…
commit d10318c0369619faa73b93abe840ea8e67cb5a52
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Sun Dec 11 16:39:32 2011 +0000
core: Added MIX_PIXELS + basic tests.
diff --git a/include/core/GP_MixPixels.gen.h.t b/include/core/GP_MixPixels.gen.h.t
new file mode 100644
index 0000000..ab611aa
--- /dev/null
+++ b/include/core/GP_MixPixels.gen.h.t
@@ -0,0 +1,35 @@
+%% extends "base.h.t"
+
+%% block descr
+Macros to mix two pixels accordingly to percentage.
+%% endblock
+
+%% block body
+
+
+#include "GP_Pixel.h"
+
+%% for pt in pixeltypes
+%% if not pt.is_unknown()
+/*
+ * Mixes two {{ pt.name }} pixels.
+ *
+ * The percentage is expected as 8 bit unsigned integer [0 .. 255]
+ */
+#define GP_MIX_PIXELS_{{ pt.name }}(pix1, pix2, perc) ({ +%% for c in pt.chanslist
+ GP_Pixel {{ c[0] }}; ++ {{ c[0] }} = GP_Pixel_GET_{{ c[0] }}_{{ pt.name }}(pix1) * perc; + {{ c[0] }} += GP_Pixel_GET_{{ c[0] }}_{{ pt.name }}(pix2) * (255 - perc); + {{ c[0] }} = ({{ c[0] }} + 128) / 255; ++%% endfor
++ GP_Pixel_CREATE_{{ pt.name }}({{ pt.chanslist[0][0] }}{% for c in pt.chanslist[1:] %}, {{ c[0] }}{% endfor %}); +})
+
+%% endif
+%% endfor
+
+%% endblock body
diff --git a/include/core/Makefile b/include/core/Makefile
index 186b6dd..48eb3d2 100644
--- a/include/core/Makefile
+++ b/include/core/Makefile
@@ -1,6 +1,7 @@
TOPDIR=../..
GENHEADERS=GP_Convert_Scale.gen.h GP_Blit.gen.h GP_Pixel.gen.h - GP_GetPutPixel.gen.h GP_Convert.gen.h GP_FnPerBpp.gen.h
+ GP_GetPutPixel.gen.h GP_Convert.gen.h GP_FnPerBpp.gen.h + GP_MixPixels.gen.h
LIBNAME=core
include $(TOPDIR)/gen.mk
include $(TOPDIR)/include.mk
diff --git a/tests/core/GP_MixPixels.test.gen.c.t b/tests/core/GP_MixPixels.test.gen.c.t
new file mode 100644
index 0000000..ffb9d6d
--- /dev/null
+++ b/tests/core/GP_MixPixels.test.gen.c.t
@@ -0,0 +1,37 @@
+%% extends "base.test.c.t"
+
+%% block body
+#include "GP_Tests.h"
+#include "GP_Core.h"
+#include "GP_MixPixels.gen.h"
+#include "GP_TestingCore.h"
+
+GP_SUITE(GP_MixPixels)
+
+%% call(pt) test_for_all_pixeltypes("MixPixelsWhiteStaysWhite_via",
+ opts="loop_start=0, loop_end=4",
+ palette=False)
+ GP_Pixel p1 = GP_RGBToPixel(255, 255, 255, GP_PIXEL_{{ pt.name }});
+ GP_Pixel p2 = GP_RGBToPixel(255, 255, 255, GP_PIXEL_{{ pt.name }});
+ GP_Pixel p3;
+ int i;
+ for (i = 0; i < 256; i++) {
+ p3 = GP_MIX_PIXELS_{{ pt.name }}(p1, p2, i);
+ GP_CHECK_EqualColors(p1, GP_PIXEL_{{ pt.name }}, p3, GP_PIXEL_{{ pt.name }});
+ }
+%% endcall
+
+%% call(pt) test_for_all_pixeltypes("MixPixelsBlackStaysBlack_via",
+ opts="loop_start=0, loop_end=4",
+ palette=False)
+ GP_Pixel p1 = GP_RGBToPixel(0, 0, 0, GP_PIXEL_{{ pt.name }});
+ GP_Pixel p2 = GP_RGBToPixel(0, 0, 0, GP_PIXEL_{{ pt.name }});
+ GP_Pixel p3;
+ int i;
+ for (i = 0; i < 256; i++) {
+ p3 = GP_MIX_PIXELS_{{ pt.name }}(p1, p2, i);
+ GP_CHECK_EqualColors(p1, GP_PIXEL_{{ pt.name }}, p3, GP_PIXEL_{{ pt.name }});
+ }
+%% endcall
+
+%% endblock body
diff --git a/tests/core/Makefile b/tests/core/Makefile
index 67d52e1..56955b9 100644
--- a/tests/core/Makefile
+++ b/tests/core/Makefile
@@ -3,7 +3,8 @@ TOPDIR=../..
LIBNAME=core
TESTSUITE=core_suite
LDLIBS+=-lGP -L$(TOPDIR)/build/ -lcheck -lm -ldl
-GENSOURCES+=GP_Convert.test.gen.c GP_WritePixel.test.gen.c
+GENSOURCES+=GP_Convert.test.gen.c GP_WritePixel.test.gen.c + GP_MixPixels.test.gen.c
all: $(TESTSUITE)
http://repo.or.cz/w/gfxprim.git/commit/db1bbab2baeb3c556862cacaa9ac9e0fa15c…
commit db1bbab2baeb3c556862cacaa9ac9e0fa15ce859
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Sun Dec 11 15:19:10 2011 +0000
gfx: fix build broken by previous commit
diff --git a/include/gfx/GP_Gfx.h b/include/gfx/GP_Gfx.h
index 5ab2f03..3c36bf0 100644
--- a/include/gfx/GP_Gfx.h
+++ b/include/gfx/GP_Gfx.h
@@ -46,6 +46,7 @@
#include "GP_Triangle.h"
#include "GP_Tetragon.h"
#include "GP_Circle.h"
+#include "GP_Arc.h"
#include "GP_Ellipse.h"
#include "GP_Polygon.h"
#include "GP_Symbol.h"
-----------------------------------------------------------------------
Summary of changes:
include/core/GP_MixPixels.gen.h.t | 35 ++++++++++++++++++++++++++++++++
include/core/Makefile | 3 +-
include/gfx/GP_Gfx.h | 1 +
tests/core/GP_MixPixels.test.gen.c.t | 37 ++++++++++++++++++++++++++++++++++
tests/core/Makefile | 3 +-
5 files changed, 77 insertions(+), 2 deletions(-)
create mode 100644 include/core/GP_MixPixels.gen.h.t
create mode 100644 tests/core/GP_MixPixels.test.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: 2f824b15387739be5c32dd417b6fabbf54234bc8
by bluebear 11 Dec '11
by bluebear 11 Dec '11
11 Dec '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 2f824b15387739be5c32dd417b6fabbf54234bc8 (commit)
via 0c88946ef930d04eb2c3ea3afe202ab8248150b4 (commit)
from 36a72a1ec467da8e2b49ed57e98be58f911d01f7 (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/2f824b15387739be5c32dd417b6fabbf5423…
commit 2f824b15387739be5c32dd417b6fabbf54234bc8
Merge: 0c88946 36a72a1
Author: BlueBear <jiri.bluebear.dluhos(a)gmail.com>
Date: Sun Dec 11 15:03:47 2011 +0100
Merge branch 'master' of git://repo.or.cz/gfxprim
http://repo.or.cz/w/gfxprim.git/commit/0c88946ef930d04eb2c3ea3afe202ab82481…
commit 0c88946ef930d04eb2c3ea3afe202ab8248150b4
Author: BlueBear <jiri.bluebear.dluhos(a)gmail.com>
Date: Sun Dec 11 15:03:04 2011 +0100
Added first support for arcs (currently with very strange syntax).
diff --git a/include/gfx/GP_Arc.h b/include/gfx/GP_Arc.h
new file mode 100644
index 0000000..dfec46e
--- /dev/null
+++ b/include/gfx/GP_Arc.h
@@ -0,0 +1,48 @@
+/*****************************************************************************
+ * This file is part of gfxprim library. *
+ * *
+ * Gfxprim is free software; you can redistribute it and/or *
+ * modify it under the terms of the GNU Lesser General Public *
+ * License as published by the Free Software Foundation; either *
+ * version 2.1 of the License, or (at your option) any later version. *
+ * *
+ * Gfxprim is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with gfxprim; if not, write to the Free Software *
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
+ * Boston, MA 02110-1301 USA *
+ * *
+ * Copyright (C) 2009-2011 Jiri "BlueBear" Dluhos *
+ * <jiri.bluebear.dluhos(a)gmail.com> *
+ * *
+ * Copyright (C) 2009-2011 Cyril Hrubis <metan(a)ucw.cz> *
+ * *
+ *****************************************************************************/
+
+#ifndef GP_ARC_H
+#define GP_ARC_H
+
+#include "core/GP_Context.h"
+
+#define GP_QUADRANT_MINUSMINUS 1
+#define GP_QUADRANT_PLUSMINUS 2
+#define GP_QUADRANT_MINUSPLUS 4
+#define GP_QUADRANT_PLUSPLUS 8
+
+void GP_Arc(GP_Context *context, GP_Coord xcenter, GP_Coord ycenter,
+ GP_Size a, GP_Size b, int quadrant_mask,
+ int low_dx, int low_dy,
+ int high_dx, int high_dy,
+ GP_Pixel pixel);
+
+void GP_Arc_Raw(GP_Context *context, GP_Coord xcenter, GP_Coord ycenter,
+ GP_Size a, GP_Size b, int quadrant_mask,
+ int low_dx, int low_dy,
+ int high_dx, int high_dy,
+ GP_Pixel pixel);
+
+#endif /* GP_ARC_H */
diff --git a/libs/gfx/GP_Arc.c b/libs/gfx/GP_Arc.c
new file mode 100644
index 0000000..c64d94d
--- /dev/null
+++ b/libs/gfx/GP_Arc.c
@@ -0,0 +1,63 @@
+/*****************************************************************************
+ * This file is part of gfxprim library. *
+ * *
+ * Gfxprim is free software; you can redistribute it and/or *
+ * modify it under the terms of the GNU Lesser General Public *
+ * License as published by the Free Software Foundation; either *
+ * version 2.1 of the License, or (at your option) any later version. *
+ * *
+ * Gfxprim is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with gfxprim; if not, write to the Free Software *
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
+ * Boston, MA 02110-1301 USA *
+ * *
+ * Copyright (C) 2009-2011 Jiri "BlueBear" Dluhos *
+ * <jiri.bluebear.dluhos(a)gmail.com> *
+ * *
+ * Copyright (C) 2009-2011 Cyril Hrubis <metan(a)ucw.cz> *
+ * *
+ *****************************************************************************/
+
+#include "GP_Gfx.h"
+#include "core/GP_FnPerBpp.h"
+
+#include "algo/Arc.algo.h"
+
+/* Generate drawing functions for various bit depths. */
+GP_DEF_DRAW_FN_PER_BPP(GP_Arc_Raw, DEF_ARC_FN)
+
+void GP_Arc_Raw(GP_Context *context, GP_Coord xcenter, GP_Coord ycenter,
+ GP_Size a, GP_Size b, int quadrant_mask,
+ int low_dx, int low_dy,
+ int high_dx, int high_dy,
+ GP_Pixel pixel)
+{
+ GP_CHECK_CONTEXT(context);
+
+ GP_FN_PER_BPP_CONTEXT(GP_Arc_Raw, context, context,
+ xcenter, ycenter, a, b, quadrant_mask,
+ low_dx, low_dy, high_dx, high_dy,
+ pixel);
+}
+
+void GP_Arc(GP_Context *context, GP_Coord xcenter, GP_Coord ycenter,
+ GP_Size a, GP_Size b, int quadrant_mask,
+ int low_dx, int low_dy,
+ int high_dx, int high_dy,
+ GP_Pixel pixel)
+{
+ GP_CHECK_CONTEXT(context);
+
+ /* recalculate center point and swap a and b when axes are swapped */
+ GP_TRANSFORM_POINT(context, xcenter, ycenter);
+ GP_TRANSFORM_SWAP(context, a, b);
+
+ GP_Arc_Raw(context, xcenter, ycenter, a, b, quadrant_mask,
+ low_dx, low_dy, high_dx, high_dy,
+ pixel);
+}
diff --git a/libs/gfx/algo/Arc.algo.h b/libs/gfx/algo/Arc.algo.h
new file mode 100644
index 0000000..1681ce8
--- /dev/null
+++ b/libs/gfx/algo/Arc.algo.h
@@ -0,0 +1,84 @@
+/*****************************************************************************
+ * This file is part of gfxprim library. *
+ * *
+ * Gfxprim is free software; you can redistribute it and/or *
+ * modify it under the terms of the GNU Lesser General Public *
+ * License as published by the Free Software Foundation; either *
+ * version 2.1 of the License, or (at your option) any later version. *
+ * *
+ * Gfxprim is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with gfxprim; if not, write to the Free Software *
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
+ * Boston, MA 02110-1301 USA *
+ * *
+ * Copyright (C) 2009-2010 Jiri "BlueBear" Dluhos *
+ * <jiri.bluebear.dluhos(a)gmail.com> *
+ * *
+ * Copyright (C) 2009-2010 Cyril Hrubis <metan(a)ucw.cz> *
+ * *
+ *****************************************************************************/
+
+/*
+ * The elliptical arc algorithm; a generalization of an ellipse that allows
+ * to draw only part of it. The math is exactly the same, only it has
+ * additional tests of what part to draw.
+ */
+
+/*
+ * This macro defines an elliptic arc drawing function.
+ * Arguments:
+ * CONTEXT_T - user-defined type of drawing context (passed to PUTPIXEL)
+ * PIXVAL_T - user-defined pixel value type (passed to PUTPIXEL)
+ * PUTPIXEL - a pixel drawing function f(context, x, y, pixval)
+ * FN_NAME - name of the function to be defined
+ */
+#define DEF_ARC_FN(FN_NAME, CONTEXT_T, PIXVAL_T, PUTPIXEL) +void FN_NAME(CONTEXT_T context, int xcenter, int ycenter, + unsigned int a, unsigned int b, int quadrant_mask, + int low_dx, int low_dy, int high_dx, int high_dy, + PIXVAL_T pixval) +{ + /* Precompute quadratic terms. */ + int a2 = a*a; + int b2 = b*b; ++ int x, y, error; + for (x = 0, error = -b2*a, y = b; y >= 0; y--) { + while (error < 0) { ++ /* Calculate error(x+1) from error(x). */ + error += 2*x*b2 + b2; + x++; ++ if ((x*low_dy >= y*low_dx) && (x*high_dy <= y*high_dx)) { + if (quadrant_mask & GP_QUADRANT_MINUSMINUS) + PUTPIXEL(context, xcenter-x+1, ycenter-y, pixval); + if (quadrant_mask & GP_QUADRANT_PLUSMINUS) + PUTPIXEL(context, xcenter+x-1, ycenter-y, pixval); + if (quadrant_mask & GP_QUADRANT_MINUSPLUS) + PUTPIXEL(context, xcenter-x+1, ycenter+y, pixval); + if (quadrant_mask & GP_QUADRANT_PLUSPLUS) + PUTPIXEL(context, xcenter+x-1, ycenter+y, pixval); + } + } ++ /*
Calculate error(y-1) from error(y). */ + error += -2*y*a2 + a2; ++ if ((x*low_dy >= y*low_dx) && (x*high_dy <= y*high_dx)) { + if (quadrant_mask & GP_QUADRANT_MINUSMINUS) + PUTPIXEL(context, xcenter-x+1, ycenter-y, pixval); + if (quadrant_mask & GP_QUADRANT_PLUSMINUS) + PUTPIXEL(context, xcenter+x-1, ycenter-y, pixval); + if (quadrant_mask & GP_QUADRANT_MINUSPLUS) + PUTPIXEL(context, xcenter-x+1, ycenter+y, pixval); + if (quadrant_mask & GP_QUADRANT_PLUSPLUS) + PUTPIXEL(context, xcenter+x-1, ycenter+y, pixval); + } + } +}
-----------------------------------------------------------------------
Summary of changes:
include/gfx/{GP_Line.h => GP_Arc.h} | 25 ++++++---
libs/gfx/{GP_Line.c => GP_Arc.c} | 33 ++++++++----
libs/gfx/algo/{Ellipse.algo.h => Arc.algo.h} | 76 ++++++++++----------------
3 files changed, 68 insertions(+), 66 deletions(-)
copy include/gfx/{GP_Line.h => GP_Arc.h} (77%)
copy libs/gfx/{GP_Line.c => GP_Arc.c} (68%)
copy libs/gfx/algo/{Ellipse.algo.h => Arc.algo.h} (59%)
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: 36a72a1ec467da8e2b49ed57e98be58f911d01f7
by metan 11 Dec '11
by metan 11 Dec '11
11 Dec '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 36a72a1ec467da8e2b49ed57e98be58f911d01f7 (commit)
via 3c4a561ca197f91aa1b3040a18ced825667e63dc (commit)
from 42ad59f700932298c5d6441054ca7d6d7590a9e1 (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/36a72a1ec467da8e2b49ed57e98be58f911d…
commit 36a72a1ec467da8e2b49ed57e98be58f911d01f7
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Fri Dec 9 17:48:08 2011 +0100
build: Now jpeg or libpng could be disabled by configure.
diff --git a/include/core/GP_Common.h b/include/core/GP_Common.h
index cae989e..62ba32c 100644
--- a/include/core/GP_Common.h
+++ b/include/core/GP_Common.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_COMMON_H
-#define GP_COMMON_H
+#ifndef CORE_GP_COMMON_H
+#define CORE_GP_COMMON_H
#include <stdio.h>
#include <stdint.h>
@@ -70,6 +70,8 @@
#endif
#endif
+#define GP_UNUSED(x) (x)__attribute__ ((unused))
+
/*
* Internal macros with common code for GP_ABORT, GP_ASSERT and GP_CHECK.
* GP_INTERNAL_ABORT takes a message that may contain % (e.g. assert condition)
@@ -149,4 +151,4 @@
(_a > 0) ? 1 : ((_a < 0) ? -1 : 0); })
-#endif /* GP_COMMON_H */
+#endif /* CORE_GP_COMMON_H */
diff --git a/libs/loaders/GP_JPG.c b/libs/loaders/GP_JPG.c
index db3de62..4ea6e35 100644
--- a/libs/loaders/GP_JPG.c
+++ b/libs/loaders/GP_JPG.c
@@ -34,10 +34,14 @@
#include <stdio.h>
#include <setjmp.h>
-#include <jpeglib.h>
+#include "../../config.h"
+#include "core/GP_Debug.h"
#include "GP_JPG.h"
-#include "core/GP_Debug.h"
+
+#ifdef HAVE_JPEG
+
+#include <jpeglib.h>
GP_RetCode GP_OpenJPG(const char *src_path, FILE **f)
{
@@ -285,3 +289,34 @@ err1:
unlink(dst_path);
return ret;
}
+
+#else
+
+GP_RetCode GP_OpenJPG(const char GP_UNUSED(*src_path),
+ FILE GP_UNUSED(**f))
+{
+ return GP_ENOIMPL;
+}
+
+GP_RetCode GP_ReadJPG(FILE GP_UNUSED(*f),
+ GP_Context GP_UNUSED(**res),
+ GP_ProgressCallback GP_UNUSED(*callback))
+{
+ return GP_ENOIMPL;
+}
+
+GP_RetCode GP_LoadJPG(const char GP_UNUSED(*src_path),
+ GP_Context GP_UNUSED(**res),
+ GP_ProgressCallback GP_UNUSED(*callback))
+{
+ return GP_ENOIMPL;
+}
+
+GP_RetCode GP_SaveJPG(const char GP_UNUSED(*dst_path),
+ const GP_Context GP_UNUSED(*src),
+ GP_ProgressCallback GP_UNUSED(*callback))
+{
+ return GP_ENOIMPL;
+}
+
+#endif /* HAVE_JPEG */
diff --git a/libs/loaders/GP_PNG.c b/libs/loaders/GP_PNG.c
index 32a6358..51c645e 100644
--- a/libs/loaders/GP_PNG.c
+++ b/libs/loaders/GP_PNG.c
@@ -32,10 +32,14 @@
#include <errno.h>
#include <string.h>
-#include <png.h>
+#include "../../config.h"
+#include "core/GP_Debug.h"
#include "GP_PNG.h"
-#include "core/GP_Debug.h"
+
+#ifdef HAVE_LIBPNG
+
+#include <png.h>
GP_RetCode GP_OpenPNG(const char *src_path, FILE **f)
{
@@ -305,3 +309,34 @@ err1:
unlink(dst_path);
return ret;
}
+
+#else
+
+GP_RetCode GP_OpenPNG(const char GP_UNUSED(*src_path),
+ FILE GP_UNUSED(**f))
+{
+ return GP_ENOIMPL;
+}
+
+GP_RetCode GP_ReadPNG(FILE GP_UNUSED(*f),
+ GP_Context GP_UNUSED(**res),
+ GP_ProgressCallback GP_UNUSED(*callback))
+{
+ return GP_ENOIMPL;
+}
+
+GP_RetCode GP_LoadPNG(const char GP_UNUSED(*src_path),
+ GP_Context GP_UNUSED(**res),
+ GP_ProgressCallback GP_UNUSED(*callback))
+{
+ return GP_ENOIMPL;
+}
+
+GP_RetCode GP_SavePNG(const char GP_UNUSED(*dst_path),
+ const GP_Context GP_UNUSED(*src),
+ GP_ProgressCallback GP_UNUSED(*callback))
+{
+ return GP_ENOIMPL;
+}
+
+#endif /* HAVE_LIBPNG */
http://repo.or.cz/w/gfxprim.git/commit/3c4a561ca197f91aa1b3040a18ced825667e…
commit 3c4a561ca197f91aa1b3040a18ced825667e63dc
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Fri Dec 9 17:27:15 2011 +0100
build: The CFLAGS and LDFLAGS are now from configure.
diff --git a/app.mk b/app.mk
index 0b301df..460ebf7 100644
--- a/app.mk
+++ b/app.mk
@@ -2,7 +2,7 @@ ifndef APPS
$(error APPS not defined, fix your library Makefile)
endif
-LDLIBS+=-lpng -ljpeg -lm -ldl
+LDLIBS+=-lm -ldl
all: $(APPS)
diff --git a/configure b/configure
index 12c3a89..36b0418 100755
--- a/configure
+++ b/configure
@@ -97,7 +97,7 @@ class libraries:
#
# Writes '#define HAVE_XXX_H' into passed file
#
- def write(self, f):
+ def write_config_h(self, f):
for i in self.libraries:
f.write("/*n * {0}n */n".format(i[1]))
if self.results[i[0]]:
@@ -106,6 +106,14 @@ class libraries:
f.write("//#define HAVE_{0}n".format(i[0].upper()))
f.write("n")
+ #
+ # Writes LDFLAGS and CFLAGS into passed file
+ #
+ def write_config_mk(self, f):
+ for i in self.libraries:
+ if self.results[i[0]]:
+ f.write("# {0}nCFLAGS+={1}nLDFLAGS+={2}n".format(i[0], i[3], i[4]))
+
def basic_checks(cfg):
sys.stderr.write("Basic checksn")
sys.stderr.write("------------n")
@@ -121,7 +129,7 @@ def basic_checks(cfg):
def write_config_h(cfg, libs):
f = open("config.h", "w")
f.write("#ifndef CONFIG_Hn#define CONFIG_Hnn")
- libs.write(f);
+ libs.write_config_h(f);
f.write("#endif /* CONFIG_H */n");
sys.stderr.write("Config 'config.h' writtenn")
f.close()
@@ -129,7 +137,8 @@ def write_config_h(cfg, libs):
def write_config_mk(cfg, libs):
f = open('config.gen.mk', 'w')
for i in cfg:
- f.write("#{0}n{1}={2}n".format(cfg[i][1], i, cfg[i][0]))
+ f.write("# {0}n{1}={2}n".format(cfg[i][1], i, cfg[i][0]))
+ libs.write_config_mk(f);
f.close()
sys.stderr.write("Config 'config.gen.mk' writtenn")
@@ -145,15 +154,20 @@ if __name__ == '__main__':
#
# Library detection/enable disable
#
+ # name, description, [detection], cflags, ldflags
+ #
l = libraries([["libpng",
"Portable Network Graphics Library",
- [header_exists, "png.h"]],
+ [header_exists, "png.h"], "", "-lpng"],
["libsdl",
"Simple Direct Media Layer",
- [header_exists, "SDL/SDL.h"]],
+ [header_exists, "SDL/SDL.h"], "", ""],
["jpeg",
"Library to load, handle and manipulate images in the JPEG format",
- [header_exists, "jpeglib.h"]]], cfg)
+ [header_exists, "jpeglib.h"], "", "-ljpeg"],
+ ["freetype",
+ "A high-quality and portable font engine",
+ [header_exists, "ft2build.h"], "", ""]], cfg)
parser = OptionParser();
diff --git a/tests/core/Makefile b/tests/core/Makefile
index 1ee793a..67d52e1 100644
--- a/tests/core/Makefile
+++ b/tests/core/Makefile
@@ -2,7 +2,7 @@ TOPDIR=../..
LIBNAME=core
TESTSUITE=core_suite
-LDLIBS+=-lGP -L$(TOPDIR)/build/ -lcheck -lpng -ljpeg -lm -ldl
+LDLIBS+=-lGP -L$(TOPDIR)/build/ -lcheck -lm -ldl
GENSOURCES+=GP_Convert.test.gen.c GP_WritePixel.test.gen.c
all: $(TESTSUITE)
-----------------------------------------------------------------------
Summary of changes:
app.mk | 2 +-
configure | 26 ++++++++++++++++++++------
include/core/GP_Common.h | 10 ++++++----
libs/loaders/GP_JPG.c | 39 +++++++++++++++++++++++++++++++++++++--
libs/loaders/GP_PNG.c | 39 +++++++++++++++++++++++++++++++++++++--
tests/core/Makefile | 2 +-
6 files changed, 102 insertions(+), 16 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: 42ad59f700932298c5d6441054ca7d6d7590a9e1
by metan 01 Dec '11
by metan 01 Dec '11
01 Dec '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 42ad59f700932298c5d6441054ca7d6d7590a9e1 (commit)
from 5777210fdacd7e722325dbad7a3df78bfa587462 (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/42ad59f700932298c5d6441054ca7d6d7590…
commit 42ad59f700932298c5d6441054ca7d6d7590a9e1
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Thu Dec 1 23:32:47 2011 +0100
filters: initial support for histograms.
diff --git a/demos/grinder/Makefile b/demos/grinder/Makefile
index a984bd9..377d008 100644
--- a/demos/grinder/Makefile
+++ b/demos/grinder/Makefile
@@ -7,7 +7,7 @@ LDLIBS+=-lGP -L$(TOPDIR)/build/
APPS=grinder
-grinder: params.o
+grinder: params.o histogram.o
include $(TOPDIR)/include.mk
include $(TOPDIR)/app.mk
diff --git a/demos/grinder/grinder.c b/demos/grinder/grinder.c
index f9a0675..4df4004 100644
--- a/demos/grinder/grinder.c
+++ b/demos/grinder/grinder.c
@@ -28,6 +28,7 @@
#include "GP.h"
#include "params.h"
+#include "histogram.h"
static GP_ProgressCallback *progress_callback = NULL;
@@ -629,6 +630,29 @@ static GP_RetCode arithmetic(GP_Context **c, const char *params)
return GP_ESUCCESS;
}
+/* histogram */
+
+static struct param histogram_params[] = {
+ {"file", PARAM_STR, "Filename of image to use.", NULL, NULL},
+ {NULL, 0, NULL, NULL, NULL}
+};
+
+static GP_RetCode histogram(GP_Context **c, const char *params)
+{
+ char *file = "histogram.png";
+
+ if (param_parse(params, histogram_params, "histogram", param_err, &file))
+ return GP_EINVAL;
+
+ if (file == NULL) {
+ print_error("histogram: Filename missing");
+ return GP_EINVAL;
+ }
+
+ histogram_to_png(*c, file);
+ return GP_ESUCCESS;
+}
+
/* filters */
struct filter {
@@ -650,6 +674,7 @@ static struct filter filter_table[] = {
{"blur", "gaussian blur", blur_params, blur},
{"dither", "dithers bitmap", dither_params, dither},
{"arithmetic", "arithmetic operation", arithmetic_params, arithmetic},
+ {"histogram", "save histogram into image file", histogram_params, histogram},
{"jpg", "save jpg image", save_jpg_params, save_jpg},
{"png", "save png image", save_png_params, save_png},
{NULL, NULL, NULL, NULL}
diff --git a/include/filters/GP_Filters.h b/demos/grinder/histogram.c
similarity index 52%
copy from include/filters/GP_Filters.h
copy to demos/grinder/histogram.c
index 5bd60a8..24fc9a7 100644
--- a/include/filters/GP_Filters.h
+++ b/demos/grinder/histogram.c
@@ -16,41 +16,66 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, *
* Boston, MA 02110-1301 USA *
* *
- * Copyright (C) 2009-2010 Jiri "BlueBear" Dluhos *
- * <jiri.bluebear.dluhos(a)gmail.com> *
- * *
* Copyright (C) 2009-2011 Cyril Hrubis <metan(a)ucw.cz> *
* *
*****************************************************************************/
-/*
+#include "histogram.h"
- GP_Context filters.
+void histogram_to_png(const GP_Context *src, const char *filename)
+{
+ GP_FILTER_PARAMS(src->pixel_type, params);
+
+ GP_FilterHistogramAlloc(src->pixel_type, params);
+ GP_FilterHistogram(src, params, NULL);
- */
+ unsigned int i, j;
-#ifndef GP_FILTERS_H
-#define GP_FILTERS_H
+ GP_Context *res = GP_ContextAlloc(257*4, 256, GP_PIXEL_RGB888);
+
+ GP_Fill(res, 0xffffff);
-/* Filter per channel parameter passing interface */
-#include "filters/GP_FilterParam.h"
+ GP_Histogram *hist_r;
+ hist_r = (GP_FilterParamChannel(params, "R"))->val.ptr;
+
+ for (i = 0; i < hist_r->len; i++)
+ GP_VLineXYH(res, i, 256, -255.00 * hist_r->hist[i] / hist_r->max + 0.5 , 0xff0000);
+
+ GP_Histogram *hist_g;
+ hist_g = (GP_FilterParamChannel(params, "G"))->val.ptr;
+
+ for (i = 0; i < hist_g->len; i++)
+ GP_VLineXYH(res, i+257, 256, -255.00 * hist_g->hist[i] / hist_g->max + 0.5 , 0x00ff00);
+
+ GP_Histogram *hist_b;
+ hist_b = (GP_FilterParamChannel(params, "B"))->val.ptr;
+
+ for (i = 0; i < hist_b->len; i++)
+ GP_VLineXYH(res, i+514, 256, -255.00 * hist_b->hist[i] / hist_b->max + 0.5 , 0x0000ff);
-/* Image rotations (90 180 270 grads) and mirroring */
-#include "filters/GP_Rotate.h"
+ uint32_t max = GP_MAX(hist_r->max, hist_g->max);
-/* Point filters, brightness, contrast ... */
-#include "filters/GP_Point.h"
+ max = GP_MAX(max, hist_b->max);
-/* Addition, difference, min, max ... */
-#include "filters/GP_Arithmetic.h"
+ for (i = 0; i < hist_r->len; i++) {
+ for (j = 0; j < hist_r->len; j++) {
+ GP_Pixel pix = 0;
+
+ if (255 * hist_r->hist[i] / max + 0.5 > j)
+ pix |= 0xff0000;
+
+ if (255 * hist_g->hist[i] / max + 0.5 > j)
+ pix |= 0x00ff00;
-/* Linear convolution based filters (mostly blurs) */
-#include "filters/GP_Linear.h"
+ if (255 * hist_b->hist[i] / max + 0.5 > j)
+ pix |= 0x0000ff;
-/* Image scaling (resampling) */
-#include "filters/GP_Resize.h"
+ GP_PutPixel(res, i+771, 256-j, pix);
+ }
+ }
-/* Bitmap dithering */
-#include "filters/GP_Dither.h"
+ GP_SavePNG(filename, res, NULL);
-#endif /* GP_FILTERS_H */
+ GP_ContextFree(res);
+ GP_FilterHistogramFree(params);
+}
diff --git a/include/filters/GP_Filters.h b/demos/grinder/histogram.h
similarity index 65%
copy from include/filters/GP_Filters.h
copy to demos/grinder/histogram.h
index 5bd60a8..d6fdb4e 100644
--- a/include/filters/GP_Filters.h
+++ b/demos/grinder/histogram.h
@@ -16,41 +16,15 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, *
* Boston, MA 02110-1301 USA *
* *
- * Copyright (C) 2009-2010 Jiri "BlueBear" Dluhos *
- * <jiri.bluebear.dluhos(a)gmail.com> *
- * *
* Copyright (C) 2009-2011 Cyril Hrubis <metan(a)ucw.cz> *
* *
*****************************************************************************/
-/*
-
- GP_Context filters.
-
- */
-
-#ifndef GP_FILTERS_H
-#define GP_FILTERS_H
-
-/* Filter per channel parameter passing interface */
-#include "filters/GP_FilterParam.h"
-
-/* Image rotations (90 180 270 grads) and mirroring */
-#include "filters/GP_Rotate.h"
-
-/* Point filters, brightness, contrast ... */
-#include "filters/GP_Point.h"
-
-/* Addition, difference, min, max ... */
-#include "filters/GP_Arithmetic.h"
-
-/* Linear convolution based filters (mostly blurs) */
-#include "filters/GP_Linear.h"
+#ifndef HISTOGRAM_H
+#define HISTOGRAM_H
-/* Image scaling (resampling) */
-#include "filters/GP_Resize.h"
+#include <GP.h>
-/* Bitmap dithering */
-#include "filters/GP_Dither.h"
+void histogram_to_png(const GP_Context *src, const char *filename);
-#endif /* GP_FILTERS_H */
+#endif /* HISTOGRAM_H */
diff --git a/include/filters/GP_FilterParam.h b/include/filters/GP_FilterParam.h
index f997ed5..892f166 100644
--- a/include/filters/GP_FilterParam.h
+++ b/include/filters/GP_FilterParam.h
@@ -132,6 +132,10 @@ void GP_FilterParamSetUIntAll(GP_FilterParam params[],
*/
void GP_FilterParamSetPtrAll(GP_FilterParam params[],
void *ptr);
+/*
+ * Call free on all pointer values.
+ */
+void GP_FilterParamFreePtrAll(GP_FilterParam params[]);
/*
* Functions to print the array.
diff --git a/include/filters/GP_Filters.h b/include/filters/GP_Filters.h
index 5bd60a8..d00a852 100644
--- a/include/filters/GP_Filters.h
+++ b/include/filters/GP_Filters.h
@@ -35,15 +35,18 @@
/* Filter per channel parameter passing interface */
#include "filters/GP_FilterParam.h"
-/* Image rotations (90 180 270 grads) and mirroring */
-#include "filters/GP_Rotate.h"
-
/* Point filters, brightness, contrast ... */
#include "filters/GP_Point.h"
/* Addition, difference, min, max ... */
#include "filters/GP_Arithmetic.h"
+/* Histograms, ... */
+#include "filters/GP_Stats.h"
+
+/* Image rotations (90 180 270 grads) and mirroring */
+#include "filters/GP_Rotate.h"
+
/* Linear convolution based filters (mostly blurs) */
#include "filters/GP_Linear.h"
diff --git a/include/filters/GP_Filters.h b/include/filters/GP_Stats.h
similarity index 66%
copy from include/filters/GP_Filters.h
copy to include/filters/GP_Stats.h
index 5bd60a8..6ad62df 100644
--- a/include/filters/GP_Filters.h
+++ b/include/filters/GP_Stats.h
@@ -16,41 +16,49 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, *
* Boston, MA 02110-1301 USA *
* *
- * Copyright (C) 2009-2010 Jiri "BlueBear" Dluhos *
- * <jiri.bluebear.dluhos(a)gmail.com> *
- * *
* Copyright (C) 2009-2011 Cyril Hrubis <metan(a)ucw.cz> *
* *
*****************************************************************************/
/*
- GP_Context filters.
+ Statistic filters.
*/
-#ifndef GP_FILTERS_H
-#define GP_FILTERS_H
-
-/* Filter per channel parameter passing interface */
-#include "filters/GP_FilterParam.h"
-
-/* Image rotations (90 180 270 grads) and mirroring */
-#include "filters/GP_Rotate.h"
+#ifndef FILTERS_GP_STATS_H
+#define FILTERS_GP_STATS_H
-/* Point filters, brightness, contrast ... */
-#include "filters/GP_Point.h"
+#include "GP_Filter.h"
-/* Addition, difference, min, max ... */
-#include "filters/GP_Arithmetic.h"
+typedef struct GP_Histogram {
+ uint32_t min;
+ uint32_t max;
+ uint32_t len;
+ uint32_t hist[];
+} GP_Histogram;
-/* Linear convolution based filters (mostly blurs) */
-#include "filters/GP_Linear.h"
+/*
+ * Histogram filter.
+ *
+ * The filter param is expected to hold pointers to struct GP_Histogram
+ */
+int GP_FilterHistogram(const GP_Context *src, GP_FilterParam histogram[],
+ GP_ProgressCallback *callback);
-/* Image scaling (resampling) */
-#include "filters/GP_Resize.h"
+/*
+ * Allocate and initalize struct GP_Histogram for each channel and stores the
+ * pointer to filter params array. The pixel type must match the params[]
+ * channels.
+ */
+void GP_FilterHistogramAlloc(GP_PixelType type, GP_FilterParam params[]);
-/* Bitmap dithering */
-#include "filters/GP_Dither.h"
+/*
+ * Free the histogram arrays.
+ */
+static inline void GP_FilterHistogramFree(GP_FilterParam params[])
+{
+ GP_FilterParamFreePtrAll(params);
+}
-#endif /* GP_FILTERS_H */
+#endif /* FILTERS_GP_STATS_H */
diff --git a/libs/filters/GP_Brightness.gen.c.t b/libs/filters/GP_Brightness.gen.c.t
index b0fa776..7db0fd5 100644
--- a/libs/filters/GP_Brightness.gen.c.t
+++ b/libs/filters/GP_Brightness.gen.c.t
@@ -6,7 +6,7 @@ Brightness filters -- Increments color channel(s) by a fixed value.
%% block body
-{{ filter_include() }}
+{{ filter_point_include() }}
%% macro filter_op(chann_name, chann_size)
{{ chann_name }} = {{ chann_name }} + {{ chann_name }}_inc;
diff --git a/libs/filters/GP_Contrast.gen.c.t b/libs/filters/GP_Contrast.gen.c.t
index 3153db2..dda0b2d 100644
--- a/libs/filters/GP_Contrast.gen.c.t
+++ b/libs/filters/GP_Contrast.gen.c.t
@@ -6,7 +6,7 @@ Contrast filters -- Multiply color channel(s) by a fixed float value.
%% block body
-{{ filter_include() }}
+{{ filter_point_include() }}
%% macro filter_op(chan_name, chan_size)
{{ chan_name }} = {{ chan_name }} * {{ chan_name }}_mul + 0.5;
diff --git a/libs/filters/GP_FilterParam.c b/libs/filters/GP_FilterParam.c
index a07b3de..e968a4b 100644
--- a/libs/filters/GP_FilterParam.c
+++ b/libs/filters/GP_FilterParam.c
@@ -142,6 +142,14 @@ void GP_FilterParamSetPtrAll(GP_FilterParam params[],
params[i].val.ptr = ptr;
}
+void GP_FilterParamFreePtrAll(GP_FilterParam params[])
+{
+ unsigned int i;
+
+ for (i = 0; params[i].channel_name[0] != '0'; i++)
+ free(params[i].val.ptr);
+}
+
void GP_FilterParamPrintInt(GP_FilterParam params[])
{
unsigned int i;
diff --git a/libs/filters/GP_Histogram.gen.c.t b/libs/filters/GP_Histogram.gen.c.t
new file mode 100644
index 0000000..cd519d6
--- /dev/null
+++ b/libs/filters/GP_Histogram.gen.c.t
@@ -0,0 +1,25 @@
+%% extends "filter.stats.c.t"
+
+%% block descr
+Histogram filter -- Compute image histogram.
+%% endblock
+
+%% block body
+
+{{ filter_stats_include() }}
+
+%% macro filter_op(chan_name, chan_size)
+{{ chan_name }}_hist->hist[{{ chan_name }}]++;
+%% endmacro
+
+%% call(pt) filter_point_per_channel('Histogram', 'GP_FilterParam histogram[]', filter_op)
+{{ filter_params(pt, 'histogram', 'GP_Histogram *', '_hist', 'ptr') }}
+%% endcall
+
+%% call(ps) filter_point_per_bpp('Histogram', 'GP_FilterParam histogram[]', filter_op)
+{{ filter_param(ps, 'histogram', 'GP_Histogram *', '_hist', 'ptr') }}
+%% endcall
+
+{{ filter_functions('Histogram', 'GP_FilterParam histogram[]', 'histogram') }}
+
+%% endblock body
diff --git a/libs/filters/GP_Invert.gen.c.t b/libs/filters/GP_Invert.gen.c.t
index e6d4b24..ed4ce98 100644
--- a/libs/filters/GP_Invert.gen.c.t
+++ b/libs/filters/GP_Invert.gen.c.t
@@ -6,7 +6,7 @@ Invert filters -- Invert image
%% block body
-{{ filter_include() }}
+{{ filter_point_include() }}
%% macro filter_op(chann_name, chann_size)
{{ chann_name }} = {{ 2 ** chann_size - 1 }} - {{ chann_name }};
diff --git a/libs/filters/GP_Point.gen.c.t b/libs/filters/GP_Point.gen.c.t
index bd41579..1e9af26 100644
--- a/libs/filters/GP_Point.gen.c.t
+++ b/libs/filters/GP_Point.gen.c.t
@@ -6,7 +6,7 @@ Point filters -- General point filter.
%% block body
-{{ filter_include() }}
+{{ filter_point_include() }}
typedef uint32_t (*func)(uint32_t, uint8_t, GP_FilterParam *priv);
diff --git a/include/filters/GP_Filters.h b/libs/filters/GP_Stats.c
similarity index 53%
copy from include/filters/GP_Filters.h
copy to libs/filters/GP_Stats.c
index 5bd60a8..df65794 100644
--- a/include/filters/GP_Filters.h
+++ b/libs/filters/GP_Stats.c
@@ -16,41 +16,72 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, *
* Boston, MA 02110-1301 USA *
* *
- * Copyright (C) 2009-2010 Jiri "BlueBear" Dluhos *
- * <jiri.bluebear.dluhos(a)gmail.com> *
- * *
* Copyright (C) 2009-2011 Cyril Hrubis <metan(a)ucw.cz> *
* *
*****************************************************************************/
-/*
+#include <string.h>
+
+#include <GP_Debug.h>
+
+#include "GP_Stats.h"
+
+int GP_FilterHistogram_Raw(const GP_Context *src, GP_FilterParam histogram[],
+ GP_ProgressCallback *callback);
+
+int GP_FilterHistogram(const GP_Context *src, GP_FilterParam histogram[],
+ GP_ProgressCallback *callback)
+{
+ int ret;
+
+ ret = GP_FilterHistogram_Raw(src, histogram, callback);
- GP_Context filters.
+ if (ret)
+ return ret;
- */
+ unsigned int i;
-#ifndef GP_FILTERS_H
-#define GP_FILTERS_H
+ for (i = 0; histogram[i].channel_name[0] != '0'; i++) {
+ unsigned int j;
+ GP_Histogram *hist = histogram[i].val.ptr;
+
+ hist->max = hist->hist[0];
+ hist->min = hist->hist[0];
-/* Filter per channel parameter passing interface */
-#include "filters/GP_FilterParam.h"
+ for (j = 1; j < hist->len; j++) {
+ if (hist->hist[j] > hist->max)
+ hist->max = hist->hist[j];
-/* Image rotations (90 180 270 grads) and mirroring */
-#include "filters/GP_Rotate.h"
+ if (hist->hist[j] < hist->min)
+ hist->min = hist->hist[j];
+ }
+ }
-/* Point filters, brightness, contrast ... */
-#include "filters/GP_Point.h"
+ return 0;
+}
-/* Addition, difference, min, max ... */
-#include "filters/GP_Arithmetic.h"
+void GP_FilterHistogramAlloc(GP_PixelType type, GP_FilterParam params[])
+{
+ uint32_t i;
-/* Linear convolution based filters (mostly blurs) */
-#include "filters/GP_Linear.h"
+ GP_FilterParamSetPtrAll(params, NULL);
+
+ const GP_PixelTypeChannel *channels = GP_PixelTypes[type].channels;
-/* Image scaling (resampling) */
-#include "filters/GP_Resize.h"
+ for (i = 0; i < GP_PixelTypes[type].numchannels; i++) {
+ size_t chan_size = 1<<channels[i].size;
-/* Bitmap dithering */
-#include "filters/GP_Dither.h"
+ GP_Histogram *hist = malloc(sizeof(struct GP_Histogram) +
+ sizeof(uint32_t) * chan_size);
+
+ if (hist == NULL) {
+ GP_FilterHistogramFree(params);
+ return;
+ }
+
+ hist->len = chan_size;
+ memset(hist->hist, 0, sizeof(uint32_t) * chan_size);
-#endif /* GP_FILTERS_H */
+ (GP_FilterParamChannel(params, channels[i].name))->val.ptr = hist;
+ }
+}
diff --git a/libs/filters/Makefile b/libs/filters/Makefile
index d3f68c2..d3b6012 100644
--- a/libs/filters/Makefile
+++ b/libs/filters/Makefile
@@ -1,5 +1,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
@@ -7,7 +9,7 @@ ARITHMETIC_FILTERS=GP_Difference.gen.c GP_Addition.gen.c GP_Min.gen.c GP_Max.gen.c GP_Multiply.gen.c
GENSOURCES=GP_MirrorV.gen.c GP_Rotate.gen.c GP_Dither.gen.c- $(POINT_FILTERS) $(ARITHMETIC_FILTERS)
+ $(POINT_FILTERS) $(ARITHMETIC_FILTERS) $(STATS_FILTERS)
CSOURCES=$(filter-out $(wildcard *.gen.c),$(wildcard *.c))
LIBNAME=filters
@@ -17,6 +19,7 @@ include $(TOPDIR)/gen.mk
include $(TOPDIR)/include.mk
include $(TOPDIR)/lib.mk
-$(POINT_FILTERS) $(ARITHMETIC_FILTERS): $(TEMPLATE_DIR)/filter.c.t
+$(POINT_FILTERS) $(ARITHMETIC_FILTERS) $(STATS_FILTERS): $(TEMPLATE_DIR)/filter.c.t
+$(STATS_FILTERS): $(TEMPLATE_DIR)/filter.stats.c.t
$(POINT_FILTERS): $(TEMPLATE_DIR)/filter.point.c.t
$(ARITHMETIC_FILTERS): $(TEMPLATE_DIR)/filter.arithmetic.c.t
diff --git a/pylib/templates/filter.stats.c.t b/pylib/templates/filter.stats.c.t
new file mode 100644
index 0000000..14779a9
--- /dev/null
+++ b/pylib/templates/filter.stats.c.t
@@ -0,0 +1,102 @@
+%% extends "filter.c.t"
+
+%% macro filter_stats_include()
+{{ filter_include() }}
+#include "GP_Stats.h"
+%% endmacro
+
+/*
+ * Filter per pixel type, used for images with more than one channel per pixel
+ */
+%% macro filter_point_per_channel(name, opts="", filter_op)
+%% for pt in pixeltypes
+%% if not pt.is_unknown() and len(pt.chanslist) > 1
+static int GP_Filter{{ name }}_{{ pt.name }}(const GP_Context *src,
+ {{ maybe_opts_r(opts) }}GP_ProgressCallback *callback)
+{
+{{ caller(pt) }}
+ uint32_t x, y;
+
+ for (y = 0; y < src->h; y++) {
+ for (x = 0; x < src->w; x++) {
+ GP_Pixel pix = GP_GetPixel_Raw_{{ pt.pixelsize.suffix }}(src, x, y);
+ %% for c in pt.chanslist
+ int32_t {{ c[0] }} = GP_Pixel_GET_{{ c[0] }}_{{ pt.name }}(pix);
+ %% endfor
+
+ %% for c in pt.chanslist
+ {{ filter_op(c[0], c[2]) }}
+ %% endfor
+ }
+
+ if (GP_ProgressCallbackReport(callback, y, src->h, src->w))
+ return 1;
+ }
+
+ GP_ProgressCallbackDone(callback);
+ return 0;
+}
+
+%% endif
+%% endfor
+%% endmacro
+
+/*
+ * Point filter per bpp (used for 1 channel pixels to save space).
+ */
+%% macro filter_point_per_bpp(name, opts="", filter_op)
+%% for ps in pixelsizes
+%% if ps.size <= 8 and ps.size > 1
+static int GP_Filter{{ name }}_{{ ps.suffix }}(const GP_Context *src,
+ {{ maybe_opts_r(opts) }}GP_ProgressCallback *callback)
+{
+{{ caller(ps) }}
+ uint32_t x, y;
+
+ for (y = 0; y < src->h; y++) {
+ for (x = 0; x < src->w; x++) {
+ int32_t pix = GP_GetPixel_Raw_{{ ps.suffix }}(src, x, y);
+ {{ filter_op('pix', ps.size) }}
+ }
+
+ if (GP_ProgressCallbackReport(callback, y, src->h, src->w))
+ return 1;
+ }
+
+ GP_ProgressCallbackDone(callback);
+ return 0;
+}
+
+%% endif
+%% endfor
+%% endmacro
+
+/*
+ * Switch per pixel sizes or pixel types.
+ */
+%% macro filter_functions(name, opts="", params="", fmt="")
+int GP_Filter{{ name }}_Raw(const GP_Context *src{{ maybe_opts_l(opts) }},
+ GP_ProgressCallback *callback)
+{
+ GP_DEBUG(1, "Running filter {{ name }}");
+
+ switch (src->pixel_type) {
+ %% for pt in pixeltypes
+ case GP_PIXEL_{{ pt.name }}:
+ %% if pt.is_unknown() or pt.pixelsize.size < 2
+ return 1;
+ %% elif len(pt.chanslist) == 1:
+ //TODO: BITENDIAN
+ return GP_Filter{{ name }}_{{ pt.pixelsize.suffix }}(src{{ maybe_opts_l(params) }}, callback);
+ %% else
+ return GP_Filter{{ name }}_{{ pt.name }}(src{{ maybe_opts_l(params) }}, callback);
+ %% endif
+ %% endfor
+ default:
+ break;
+ }
+
+ return 1;
+}
+
+%% endmacro
-----------------------------------------------------------------------
Summary of changes:
demos/grinder/Makefile | 2 +-
demos/grinder/grinder.c | 25 +++++++
.../linux_input.c => demos/grinder/histogram.c | 73 ++++++++++++-------
libs/core/GP_Debug.c => demos/grinder/histogram.h | 15 ++---
include/filters/GP_FilterParam.h | 4 +
include/filters/GP_Filters.h | 9 ++-
include/{loaders/GP_JPG.h => filters/GP_Stats.h} | 52 +++++++------
libs/filters/GP_Brightness.gen.c.t | 2 +-
libs/filters/GP_Contrast.gen.c.t | 2 +-
libs/filters/GP_FilterParam.c | 8 ++
libs/filters/GP_Histogram.gen.c.t | 25 +++++++
libs/filters/GP_Invert.gen.c.t | 2 +-
libs/filters/GP_Point.gen.c.t | 2 +-
.../linux_input.c => libs/filters/GP_Stats.c | 75 +++++++++++++-------
libs/filters/Makefile | 7 ++-
.../{filter.point.c.t => filter.stats.c.t} | 47 ++-----------
16 files changed, 214 insertions(+), 136 deletions(-)
copy tests/drivers/linux_input.c => demos/grinder/histogram.c (53%)
copy libs/core/GP_Debug.c => demos/grinder/histogram.h (88%)
copy include/{loaders/GP_JPG.h => filters/GP_Stats.h} (66%)
create mode 100644 libs/filters/GP_Histogram.gen.c.t
copy tests/drivers/linux_input.c => libs/filters/GP_Stats.c (54%)
copy pylib/templates/{filter.point.c.t => filter.stats.c.t} (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: 5777210fdacd7e722325dbad7a3df78bfa587462
by metan 29 Nov '11
by metan 29 Nov '11
29 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 5777210fdacd7e722325dbad7a3df78bfa587462 (commit)
via e8994a4be0338cc1d5edc52ea60612157eed9c2b (commit)
via a19d7e22a4d18fc9ada59ce5968b3ea382ff6498 (commit)
via b4d70c436ceb9fa60ed951a3a5259db2dc4159d5 (commit)
from 9800d72f27df325aa25aaa5b35851551ef010921 (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/5777210fdacd7e722325dbad7a3df78bfa58…
commit 5777210fdacd7e722325dbad7a3df78bfa587462
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Tue Nov 29 21:30:22 2011 +0100
filters: Add support for arithmetic filters.
diff --git a/demos/grinder/grinder.c b/demos/grinder/grinder.c
index 0d573fd..f9a0675 100644
--- a/demos/grinder/grinder.c
+++ b/demos/grinder/grinder.c
@@ -500,6 +500,8 @@ static GP_RetCode save_png(GP_Context **c, const char *params)
return GP_ESUCCESS;
}
+/* noise filter */
+
static struct param add_noise_params[] = {
{"percents", PARAM_FLOAT, "Percents of noise to add", NULL, NULL},
{"chann", PARAM_STR, "Channel name {R, G, B, A, V, ...}", NULL, NULL},
@@ -562,6 +564,71 @@ static GP_RetCode add_noise(GP_Context **c, const char *params)
return GP_ESUCCESS;
}
+/* arithmetics */
+
+static const char *arithmetic_ops[] = {
+ "difference",
+ "addition",
+ "multiply",
+ "min",
+ "max",
+ NULL
+};
+
+static struct param arithmetic_params[] = {
+ {"file", PARAM_STR, "Filename of image to use.", NULL, NULL},
+ {"op", PARAM_ENUM, "Arithmetic peration", arithmetic_ops, NULL},
+ {NULL, 0, NULL, NULL, NULL}
+};
+
+static GP_RetCode arithmetic(GP_Context **c, const char *params)
+{
+ char *file = NULL;
+ int op = -1;
+
+ if (param_parse(params, arithmetic_params, "arithmetic", param_err, &file, &op))
+ return GP_EINVAL;
+
+ if (file == NULL) {
+ print_error("arithmetic: Filename missing");
+ return GP_EINVAL;
+ }
+
+ GP_Context *img, *res = NULL;
+
+ if (GP_LoadImage(file, &img, progress_callback)) {
+ print_error("arithmetic: Invalid image.");
+ return GP_EINVAL;
+ }
+
+ switch (op) {
+ case 0:
+ res = GP_FilterDifference(*c, img, NULL, progress_callback);
+ break;
+ case 1:
+ res = GP_FilterAddition(*c, img, NULL, progress_callback);
+ break;
+ case 2:
+ res = GP_FilterMultiply(*c, img, NULL, progress_callback);
+ break;
+ case 3:
+ res = GP_FilterMin(*c, img, NULL, progress_callback);
+ break;
+ case 4:
+ res = GP_FilterMax(*c, img, NULL, progress_callback);
+ break;
+ }
+
+ if (res == NULL)
+ return GP_EINVAL;
+
+ GP_ContextFree(*c);
+
+ *c = res;
+
+ return GP_ESUCCESS;
+}
+
/* filters */
struct filter {
@@ -572,19 +639,20 @@ struct filter {
};
static struct filter filter_table[] = {
- {"rotate", "rotate image", rotate_params, rotate},
- {"mirror", "mirror vertically/horizontally", mirror_params, mirror},
- {"scale", "scale image to given width and height", scale_params, scale},
- {"resize", "resize image by given ratio", resize_params, resize},
- {"bright", "alter image brightness", bright_params, bright},
- {"contrast", "alter image contrast", contrast_params, contrast},
- {"invert", "inverts image", invert_params, invert},
- {"add_noise", "adds noise", add_noise_params, add_noise},
- {"blur", "gaussian blur", blur_params, blur},
- {"dither", "dithers bitmap", dither_params, dither},
- {"jpg", "save jpg image", save_jpg_params, save_jpg},
- {"png", "save png image", save_png_params, save_png},
- {NULL, NULL, NULL, NULL}
+ {"rotate", "rotate image", rotate_params, rotate},
+ {"mirror", "mirror vertically/horizontally", mirror_params, mirror},
+ {"scale", "scale image to given width and height", scale_params, scale},
+ {"resize", "resize image by given ratio", resize_params, resize},
+ {"bright", "alter image brightness", bright_params, bright},
+ {"contrast", "alter image contrast", contrast_params, contrast},
+ {"invert", "inverts image", invert_params, invert},
+ {"add_noise", "adds noise", add_noise_params, add_noise},
+ {"blur", "gaussian blur", blur_params, blur},
+ {"dither", "dithers bitmap", dither_params, dither},
+ {"arithmetic", "arithmetic operation", arithmetic_params, arithmetic},
+ {"jpg", "save jpg image", save_jpg_params, save_jpg},
+ {"png", "save png image", save_png_params, save_png},
+ {NULL, NULL, NULL, NULL}
};
static struct filter *get_filter(const char *name)
diff --git a/gen.mk b/gen.mk
index 5c957f9..ef10aa4 100644
--- a/gen.mk
+++ b/gen.mk
@@ -36,7 +36,7 @@ CLEAN+=$(GENSOURCES) $(GENHEADERS)
#
# Some base dependencies
#
-$(GENSOURCES): $(TEMPLATE_DIR)/base.c.t
+$(GENSOURCES): $(TEMPLATE_DIR)/base.c.t $(TEMPLATE_DIR)/common.c.t
$(GENHEADERS): $(TEMPLATE_DIR)/base.h.t
#
diff --git a/include/filters/GP_Filters.h b/include/filters/GP_Arithmetic.h
similarity index 53%
copy from include/filters/GP_Filters.h
copy to include/filters/GP_Arithmetic.h
index f5cb848..9f1cb20 100644
--- a/include/filters/GP_Filters.h
+++ b/include/filters/GP_Arithmetic.h
@@ -16,38 +16,65 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, *
* Boston, MA 02110-1301 USA *
* *
- * Copyright (C) 2009-2010 Jiri "BlueBear" Dluhos *
- * <jiri.bluebear.dluhos(a)gmail.com> *
- * *
* Copyright (C) 2009-2011 Cyril Hrubis <metan(a)ucw.cz> *
* *
*****************************************************************************/
/*
- GP_Context filters.
+ Arithmetic filters - compute products of two bitmaps.
*/
-#ifndef GP_FILTERS_H
-#define GP_FILTERS_H
-
-/* Filter per channel parameter passing interface */
-#include "filters/GP_FilterParam.h"
+#ifndef FILTERS_GP_ARITHMETIC_H
+#define FILTERS_GP_ARITHMETIC_H
-/* Image rotations (90 180 270 grads) and mirroring */
-#include "filters/GP_Rotate.h"
+#include "GP_Filter.h"
-/* Point filters, brightness, contrast ... */
-#include "filters/GP_Point.h"
+/*
+ * Addition filter.
+ *
+ * Produces clamped addtion.
+ */
+GP_Context *GP_FilterAddition(const GP_Context *src_a,
+ const GP_Context *src_b,
+ GP_Context *dst,
+ GP_ProgressCallback *callback);
+/*
+ * Multiply filter.
+ *
+ * Produces clamped multiplication.
+ */
+GP_Context *GP_FilterMultiply(const GP_Context *src_a,
+ const GP_Context *src_b,
+ GP_Context *dst,
+ GP_ProgressCallback *callback);
-/* Linear convolution based filters (mostly blurs) */
-#include "filters/GP_Linear.h"
+/*
+ * Difference filter.
+ *
+ * Produces symetric difference.
+ * eg. dst = abs(src_a - src_b)
+ */
+GP_Context *GP_FilterDifference(const GP_Context *src_a,
+ const GP_Context *src_b,
+ GP_Context *dst,
+ GP_ProgressCallback *callback);
-/* Image scaling (resampling) */
-#include "filters/GP_Resize.h"
+/*
+ * Maximum filter.
+ */
+GP_Context *GP_FilterMax(const GP_Context *src_a,
+ const GP_Context *src_b,
+ GP_Context *dst,
+ GP_ProgressCallback *callback);
-/* Bitmap dithering */
-#include "filters/GP_Dither.h"
+/*
+ * Minimum filter.
+ */
+GP_Context *GP_FilterMin(const GP_Context *src_a,
+ const GP_Context *src_b,
+ GP_Context *dst,
+ GP_ProgressCallback *callback);
-#endif /* GP_FILTERS_H */
+#endif /* FILTERS_GP_ARITHMETIC_H */
diff --git a/include/filters/GP_Filters.h b/include/filters/GP_Filters.h
index f5cb848..5bd60a8 100644
--- a/include/filters/GP_Filters.h
+++ b/include/filters/GP_Filters.h
@@ -41,6 +41,9 @@
/* Point filters, brightness, contrast ... */
#include "filters/GP_Point.h"
+/* Addition, difference, min, max ... */
+#include "filters/GP_Arithmetic.h"
+
/* Linear convolution based filters (mostly blurs) */
#include "filters/GP_Linear.h"
diff --git a/libs/filters/GP_Addition.gen.c.t b/libs/filters/GP_Addition.gen.c.t
new file mode 100644
index 0000000..f89ebd4
--- /dev/null
+++ b/libs/filters/GP_Addition.gen.c.t
@@ -0,0 +1,24 @@
+%% extends "filter.arithmetic.c.t"
+
+%% block descr
+Addition filter -- Addition of two bitmaps.
+%% endblock
+
+%% block body
+
+{{ filter_arithmetic_include() }}
+
+%% macro filter_op(chan_name, chan_size)
+{{ chan_name }} = {{ chan_name }}_A + {{ chan_name }}_B;
+{{ filter_clamp_val(chan_name, chan_size) }}
+%% endmacro
+
+%% call(pt) filter_arithmetic_per_channel('Addition', filter_op)
+%% endcall
+
+%% call(ps) filter_arithmetic_per_bpp('Addition', filter_op)
+%% endcall
+
+{{ filter_arithmetic_functions('Addition') }}
+
+%% endblock body
diff --git a/libs/filters/GP_Difference.gen.c.t b/libs/filters/GP_Difference.gen.c.t
new file mode 100644
index 0000000..cf60b97
--- /dev/null
+++ b/libs/filters/GP_Difference.gen.c.t
@@ -0,0 +1,23 @@
+%% extends "filter.arithmetic.c.t"
+
+%% block descr
+Difference filter -- Symetric difference of two bitmaps.
+%% endblock
+
+%% block body
+
+{{ filter_arithmetic_include() }}
+
+%% macro filter_op(chan_name, chan_size)
+{{ chan_name }} = GP_ABS({{ chan_name }}_A - {{ chan_name }}_B);
+%% endmacro
+
+%% call(pt) filter_arithmetic_per_channel('Difference', filter_op)
+%% endcall
+
+%% call(ps) filter_arithmetic_per_bpp('Difference', filter_op)
+%% endcall
+
+{{ filter_arithmetic_functions('Difference') }}
+
+%% endblock body
diff --git a/libs/filters/GP_Max.gen.c.t b/libs/filters/GP_Max.gen.c.t
new file mode 100644
index 0000000..6e8813d
--- /dev/null
+++ b/libs/filters/GP_Max.gen.c.t
@@ -0,0 +1,23 @@
+%% extends "filter.arithmetic.c.t"
+
+%% block descr
+Max filter -- Choose max for each pixel (and for each channel) for two bitmaps.
+%% endblock
+
+%% block body
+
+{{ filter_arithmetic_include() }}
+
+%% macro filter_op(chan_name, chan_size)
+{{ chan_name }} = GP_MAX({{ chan_name }}_A, {{ chan_name }}_B);
+%% endmacro
+
+%% call(pt) filter_arithmetic_per_channel('Max', filter_op)
+%% endcall
+
+%% call(ps) filter_arithmetic_per_bpp('Max', filter_op)
+%% endcall
+
+{{ filter_arithmetic_functions('Max') }}
+
+%% endblock body
diff --git a/libs/filters/GP_Min.gen.c.t b/libs/filters/GP_Min.gen.c.t
new file mode 100644
index 0000000..b27d303
--- /dev/null
+++ b/libs/filters/GP_Min.gen.c.t
@@ -0,0 +1,23 @@
+%% extends "filter.arithmetic.c.t"
+
+%% block descr
+Min filter -- Choose min for each pixel (and for each channel) for two bitmaps.
+%% endblock
+
+%% block body
+
+{{ filter_arithmetic_include() }}
+
+%% macro filter_op(chan_name, chan_size)
+{{ chan_name }} = GP_MIN({{ chan_name }}_A, {{ chan_name }}_B);
+%% endmacro
+
+%% call(pt) filter_arithmetic_per_channel('Min', filter_op)
+%% endcall
+
+%% call(ps) filter_arithmetic_per_bpp('Min', filter_op)
+%% endcall
+
+{{ filter_arithmetic_functions('Min') }}
+
+%% endblock body
diff --git a/libs/filters/GP_Multiply.gen.c.t b/libs/filters/GP_Multiply.gen.c.t
new file mode 100644
index 0000000..3bfe7a3
--- /dev/null
+++ b/libs/filters/GP_Multiply.gen.c.t
@@ -0,0 +1,24 @@
+%% extends "filter.arithmetic.c.t"
+
+%% block descr
+Multiply filter -- Multiplies two images.
+%% endblock
+
+%% block body
+
+{{ filter_arithmetic_include() }}
+
+%% macro filter_op(chan_name, chan_size)
+{{ chan_name }} = ({{ chan_name }}_A * {{ chan_name }}_B + {{ (2 ** chan_size - 1) // 2}})/ ({{ 2 ** chan_size - 1}});
+{{ filter_clamp_val(chan_name, chan_size) }}
+%% endmacro
+
+%% call(pt) filter_arithmetic_per_channel('Multiply', filter_op)
+%% endcall
+
+%% call(ps) filter_arithmetic_per_bpp('Multiply', filter_op)
+%% endcall
+
+{{ filter_arithmetic_functions('Multiply') }}
+
+%% endblock body
diff --git a/libs/filters/Makefile b/libs/filters/Makefile
index e6d8aec..d3f68c2 100644
--- a/libs/filters/Makefile
+++ b/libs/filters/Makefile
@@ -1,7 +1,11 @@
TOPDIR=../..
-POINT_FILTERS=GP_Contrast.gen.c GP_Brightness.gen.c GP_Invert.gen.c GP_Point.gen.c
-ARITHMETIC_FILTERS=GP_Difference.gen.c
+POINT_FILTERS=GP_Contrast.gen.c GP_Brightness.gen.c GP_Invert.gen.c+ GP_Point.gen.c
+
+ARITHMETIC_FILTERS=GP_Difference.gen.c GP_Addition.gen.c GP_Min.gen.c+ GP_Max.gen.c GP_Multiply.gen.c
+
GENSOURCES=GP_MirrorV.gen.c GP_Rotate.gen.c GP_Dither.gen.c $(POINT_FILTERS) $(ARITHMETIC_FILTERS)
@@ -13,5 +17,6 @@ include $(TOPDIR)/gen.mk
include $(TOPDIR)/include.mk
include $(TOPDIR)/lib.mk
+$(POINT_FILTERS) $(ARITHMETIC_FILTERS): $(TEMPLATE_DIR)/filter.c.t
$(POINT_FILTERS): $(TEMPLATE_DIR)/filter.point.c.t
$(ARITHMETIC_FILTERS): $(TEMPLATE_DIR)/filter.arithmetic.c.t
diff --git a/pylib/templates/common.c.t b/pylib/templates/common.c.t
new file mode 100644
index 0000000..b4af2f8
--- /dev/null
+++ b/pylib/templates/common.c.t
@@ -0,0 +1,11 @@
+%% extends 'base.c.t'
+
+/*
+ * Maybe opts, adds comma on the left side
+ */
+{% macro maybe_opts_l(opts) %}{% if opts %}, {{ opts }}{% endif %}{% endmacro %}
+
+/*
+ * Maybe opts, adds comma on the right side.
+ */
+{% macro maybe_opts_r(opts) %}{% if opts %}{{ opts }}, {% endif %}{% endmacro %}
diff --git a/pylib/templates/filter.arithmetic.c.t b/pylib/templates/filter.arithmetic.c.t
new file mode 100644
index 0000000..e083921
--- /dev/null
+++ b/pylib/templates/filter.arithmetic.c.t
@@ -0,0 +1,154 @@
+%% extends "filter.c.t"
+
+%% macro filter_arithmetic_include()
+{{ filter_include() }}
+#include "GP_Arithmetic.h"
+%% endmacro
+
+/*
+ * Filter per pixel type, used for images with more than one channel per pixel
+ */
+%% macro filter_arithmetic_per_channel(name, filter_op, opts="")
+%% for pt in pixeltypes
+%% if not pt.is_unknown() and len(pt.chanslist) > 1
+static int GP_Filter{{ name }}_{{ pt.name }}(const GP_Context *src_a, const GP_Context *src_b,
+ GP_Context *dst, {{ maybe_opts_r(opts) }}GP_ProgressCallback *callback)
+{
+{{ caller(pt) }}
+ uint32_t x, y, w, h;
+
+ w = GP_MIN(src_a->w, src_b->w);
+ h = GP_MIN(src_a->h, src_b->h);
+
+ for (y = 0; y < h; y++) {
+ for (x = 0; x < w; x++) {
+ GP_Pixel pix_a = GP_GetPixel_Raw_{{ pt.pixelsize.suffix }}(src_a, x, y);
+ GP_Pixel pix_b = GP_GetPixel_Raw_{{ pt.pixelsize.suffix }}(src_b, x, y);
+
+ %% for c in pt.chanslist
+ int32_t {{ c[0] }}_A = GP_Pixel_GET_{{ c[0] }}_{{ pt.name }}(pix_a);
+ int32_t {{ c[0] }}_B = GP_Pixel_GET_{{ c[0] }}_{{ pt.name }}(pix_b);
+ %% endfor
+
+ %% for c in pt.chanslist
+ int32_t {{ c[0] }};
+ {{ filter_op(c[0], c[2]) }}
+ %% endfor
+
+ GP_Pixel pix;
+ pix = GP_Pixel_CREATE_{{ pt.name }}({{ pt.chanslist[0][0] }}{% for c in pt.chanslist[1:] %}, {{ c[0] }}{% endfor %});
+
+ GP_PutPixel_Raw_{{ pt.pixelsize.suffix }}(dst, x, y, pix);
+ }
+
+ if (GP_ProgressCallbackReport(callback, y, h, w))
+ return 1;
+ }
+
+ GP_ProgressCallbackDone(callback);
+ return 0;
+}
+%% endif
+%% endfor
+%% endmacro
+
+/*
+ * Point filter per bpp (used for 1 channel pixels to save space).
+ */
+%% macro filter_arithmetic_per_bpp(name, filter_op, opts="")
+%% for ps in pixelsizes
+%% if ps.size <= 8 and ps.size > 1
+static int GP_Filter{{ name }}_{{ ps.suffix }}(const GP_Context *src_a, const GP_Context *src_b,
+ GP_Context *dst, {{ maybe_opts_r(opts) }}GP_ProgressCallback *callback)
+{
+{{ caller(ps) }}
+ uint32_t x, y, w, h;
+
+ w = GP_MIN(src_a->w, src_b->w);
+ h = GP_MIN(src_a->h, src_b->h);
+
+ for (y = 0; y < h; y++) {
+ for (x = 0; x < w; x++) {
+ int32_t pix_A = GP_GetPixel_Raw_{{ ps.suffix }}(src_a, x, y);
+ int32_t pix_B = GP_GetPixel_Raw_{{ ps.suffix }}(src_b, x, y);
+ int32_t pix;
+ {{ filter_op('pix', ps.size) }}
+ GP_PutPixel_Raw_{{ ps.suffix }}(dst, x, y, pix);
+ }
+
+ if (GP_ProgressCallbackReport(callback, y, h, w))
+ return 1;
+ }
+
+ GP_ProgressCallbackDone(callback);
+ return 0;
+}
+
+%% endif
+%% endfor
+%% endmacro
+
+/*
+ * Switch per pixel sizes or pixel types.
+ */
+%% macro filter_arithmetic_functions(name, opts="", params="", fmt="")
+int GP_Filter{{ name }}_Raw(const GP_Context *src_a, const GP_Context *src_b,
+ GP_Context *dst{{ maybe_opts_l(opts) }}, GP_ProgressCallback *callback)
+{
+ GP_DEBUG(1, "Running filter {{ name }}");
+
+ switch (src_a->pixel_type) {
+ %% for pt in pixeltypes
+ case GP_PIXEL_{{ pt.name }}:
+ %% if pt.is_unknown() or pt.pixelsize.size < 2
+ return 1;
+ %% elif len(pt.chanslist) == 1:
+ //TODO: BITENDIAN
+ return GP_Filter{{ name }}_{{ pt.pixelsize.suffix }}(src_a, src_b, dst{{ maybe_opts_l(params) }}, callback);
+ %% else
+ return GP_Filter{{ name }}_{{ pt.name }}(src_a, src_b, dst{{ maybe_opts_l(params) }}, callback);
+ %% endif
+ %% endfor
+ default:
+ break;
+ }
+
+ return 1;
+}
+
+GP_Context *GP_Filter{{ name }}(const GP_Context *src_a, const GP_Context *src_b,
+ GP_Context *dst{{ maybe_opts_l(opts) }}, GP_ProgressCallback *callback)
+{
+ GP_Context *res = dst;
+
+ GP_ASSERT(src_a->pixel_type == src_b->pixel_type,
+ "Pixel types for sources must match.");
+
+ GP_Size w = GP_MIN(src_a->w, src_b->w);
+ GP_Size h = GP_MIN(src_a->h, src_b->h);
+
+ if (res == NULL) {
+
+ res = GP_ContextAlloc(w, h, src_a->pixel_type);
+
+ if (res == NULL)
+ return NULL;
+ } else {
+ GP_ASSERT(src_a->pixel_type == dst->pixel_type,
+ "The src and dst pixel types must match");
+ GP_ASSERT(w <= dst->w && h <= dst->h,
+ "Destination is not big enough");
+ }
+
+ if (GP_Filter{{ name }}_Raw(src_a, src_b, res{{ maybe_opts_l(params) }}, callback)) {
+ GP_DEBUG(1, "Operation aborted");
+
+ if (dst == NULL)
+ GP_ContextFree(res);
+
+ return NULL;
+ }
+
+ return res;
+}
+%% endmacro
diff --git a/pylib/templates/filter.c.t b/pylib/templates/filter.c.t
new file mode 100644
index 0000000..335ffbc
--- /dev/null
+++ b/pylib/templates/filter.c.t
@@ -0,0 +1,58 @@
+%% extends "common.c.t"
+
+%% macro filter_include()
+#include "core/GP_Context.h"
+#include "core/GP_Pixel.h"
+#include "core/GP_GetPutPixel.h"
+#include "core/GP_Debug.h"
+#include "GP_Filter.h"
+%% endmacro
+
+/*
+ * Value clamping macro
+ */
+%% macro filter_clamp_val(var, size)
+ if ({{ var }} < 0)
+ {{ var }} = 0;
+
+ if ({{ var }} > {{ 2 ** size - 1}})
+ {{ var }} = {{ 2 ** size - 1}};
+%% endmacro
+
+/*
+ * Load parameters from params structure into variables
+ */
+%% macro filter_params(pt, params, c_type, suffix, id)
+ GP_ASSERT(GP_FilterParamCheckPixelType({{ params }}, GP_PIXEL_{{ pt.name }}) == 0,
+ "Invalid params channels for context pixel type");
+
+ %% for chann in pt.chanslist
+ {{ c_type }}{{ chann[0] }}{{ suffix }} = (GP_FilterParamChannel({{ params }}, "{{ chann[0] }}"))->val.{{ id }};
+ %% endfor
+%% endmacro
+
+%% macro filter_params_raw(pt, params, suffix)
+ GP_ASSERT(GP_FilterParamCheckPixelType({{ params }}, GP_PIXEL_{{ pt.name }}) == 0,
+ "Invalid params channels for context pixel type");
+
+ %% for chann in pt.chanslist
+ GP_FilterParam *{{ chann[0] }}{{ suffix }} = GP_FilterParamChannel({{ params }}, "{{ chann[0] }}");
+ %% endfor
+%% endmacro
+
+/*
+ * Load parameters from params structure into variable
+ */
+%% macro filter_param(ps, params, c_type, suffix, id)
+ GP_ASSERT(GP_FilterParamChannels({{ params }}) != 1,
+ "Expected only one channel");
+
+ {{ c_type }}pix{{ suffix }} = {{ params }}[0].val.{{ id }};
+%% endmacro
+
+%% macro filter_param_raw(ps, params, suffix)
+ GP_ASSERT(GP_FilterParamChannels({{ params }}) != 1,
+ "Expected only one channel");
+
+ GP_FilterParam *pix{{ suffix }} = &{{ params }}[0];
+%% endmacro
diff --git a/pylib/templates/filter.point.c.t b/pylib/templates/filter.point.c.t
index 88bd6c8..c084efd 100644
--- a/pylib/templates/filter.point.c.t
+++ b/pylib/templates/filter.point.c.t
@@ -1,48 +1,8 @@
-%% extends "base.c.t"
+%% extends "filter.c.t"
-{% macro maybe_opts(opts) %}{% if opts %}, {{ opts }}{% endif %}{% endmacro %}
-
-{% macro maybe_opts2(opts) %}{% if opts %}{{ opts }}, {% endif %}{% endmacro %}
-
-%% macro filter_include()
-#include "core/GP_Context.h"
-#include "core/GP_Pixel.h"
-#include "core/GP_GetPutPixel.h"
-#include "core/GP_Debug.h"
+%% macro filter_point_include()
+{{ filter_include() }}
#include "GP_Point.h"
-#include "GP_Filter.h"
-%% endmacro
-
-/*
- * Value clamping macro
- */
-%% macro filter_clamp_val(var, size)
- if ({{ var }} < 0)
- {{ var }} = 0;
-
- if ({{ var }} > {{ 2 ** size - 1}})
- {{ var }} = {{ 2 ** size - 1}};
-%% endmacro
-
-/*
- * Load parameters from params structure into variables
- */
-%% macro filter_params(pt, params, c_type, suffix, id)
- GP_ASSERT(GP_FilterParamCheckPixelType({{ params }}, GP_PIXEL_{{ pt.name }}) == 0,
- "Invalid params channels for context pixel type");
-
- %% for chann in pt.chanslist
- {{ c_type }}{{ chann[0] }}{{ suffix }} = (GP_FilterParamChannel({{ params }}, "{{ chann[0] }}"))->val.{{ id }};
- %% endfor
-%% endmacro
-
-%% macro filter_params_raw(pt, params, suffix)
- GP_ASSERT(GP_FilterParamCheckPixelType({{ params }}, GP_PIXEL_{{ pt.name }}) == 0,
- "Invalid params channels for context pixel type");
-
- %% for chann in pt.chanslist
- GP_FilterParam *{{ chann[0] }}{{ suffix }} = GP_FilterParamChannel({{ params }}, "{{ chann[0] }}");
- %% endfor
%% endmacro
/*
@@ -52,7 +12,7 @@
%% for pt in pixeltypes
%% if not pt.is_unknown() and len(pt.chanslist) > 1
static int GP_Filter{{ name }}_{{ pt.name }}(const GP_Context *src, GP_Context *dst,
- {{ maybe_opts2(opts) }}GP_ProgressCallback *callback)
+ {{ maybe_opts_r(opts) }}GP_ProgressCallback *callback)
{
{{ caller(pt) }}
uint32_t x, y;
@@ -86,30 +46,13 @@ static int GP_Filter{{ name }}_{{ pt.name }}(const GP_Context *src, GP_Context *
%% endmacro
/*
- * Load parameters from params structure into variable
- */
-%% macro filter_param(ps, params, c_type, suffix, id)
- GP_ASSERT(GP_FilterParamChannels({{ params }}) != 1,
- "Expected only one channel");
-
- {{ c_type }}pix{{ suffix }} = {{ params }}[0].val.{{ id }};
-%% endmacro
-
-%% macro filter_param_raw(ps, params, suffix)
- GP_ASSERT(GP_FilterParamChannels({{ params }}) != 1,
- "Expected only one channel");
-
- GP_FilterParam *pix{{ suffix }} = &{{ params }}[0];
-%% endmacro
-
-/*
* Point filter per bpp (used for 1 channel pixels to save space).
*/
%% macro filter_point_per_bpp(name, opts="", filter_op)
%% for ps in pixelsizes
%% if ps.size <= 8 and ps.size > 1
static int GP_Filter{{ name }}_{{ ps.suffix }}(const GP_Context *src, GP_Context *dst,
- {{ maybe_opts2(opts) }}GP_ProgressCallback *callback)
+ {{ maybe_opts_r(opts) }}GP_ProgressCallback *callback)
{
{{ caller(ps) }}
uint32_t x, y;
@@ -137,7 +80,7 @@ static int GP_Filter{{ name }}_{{ ps.suffix }}(const GP_Context *src, GP_Context
* Switch per pixel sizes or pixel types.
*/
%% macro filter_functions(name, opts="", params="", fmt="")
-int 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_l(opts) }},
GP_ProgressCallback *callback)
{
GP_DEBUG(1, "Running filter {{ name }}");
@@ -149,9 +92,9 @@ int GP_Filter{{ name }}_Raw(const GP_Context *src, GP_Context *dst{{ maybe_opts(
return 1;
%% elif len(pt.chanslist) == 1:
//TODO: BITENDIAN
- return GP_Filter{{ name }}_{{ pt.pixelsize.suffix }}(src, dst{{ maybe_opts(params) }}, callback);
+ return GP_Filter{{ name }}_{{ pt.pixelsize.suffix }}(src, dst{{ maybe_opts_l(params) }}, callback);
%% else
- return GP_Filter{{ name }}_{{ pt.name }}(src, dst{{ maybe_opts(params) }}, callback);
+ return GP_Filter{{ name }}_{{ pt.name }}(src, dst{{ maybe_opts_l(params) }}, callback);
%% endif
%% endfor
default:
@@ -161,7 +104,7 @@ int GP_Filter{{ name }}_Raw(const GP_Context *src, GP_Context *dst{{ maybe_opts(
return 1;
}
-GP_Context *GP_Filter{{ name }}(const GP_Context *src, GP_Context *dst{{ maybe_opts(opts) }},
+GP_Context *GP_Filter{{ name }}(const GP_Context *src, GP_Context *dst{{ maybe_opts_l(opts) }},
GP_ProgressCallback *callback)
{
GP_Context *res = dst;
@@ -178,7 +121,7 @@ GP_Context *GP_Filter{{ name }}(const GP_Context *src, GP_Context *dst{{ maybe_o
"Destination is not big enough");
}
- if (GP_Filter{{ name }}_Raw(src, res{{ maybe_opts(params) }}, callback)) {
+ if (GP_Filter{{ name }}_Raw(src, res{{ maybe_opts_l(params) }}, callback)) {
GP_DEBUG(1, "Operation aborted");
if (dst == NULL)
http://repo.or.cz/w/gfxprim.git/commit/e8994a4be0338cc1d5edc52ea60612157eed…
commit e8994a4be0338cc1d5edc52ea60612157eed9c2b
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Tue Nov 29 19:26:02 2011 +0100
build: Back at the explicit dependencies.
diff --git a/gen.mk b/gen.mk
index 58cd612..5c957f9 100644
--- a/gen.mk
+++ b/gen.mk
@@ -29,22 +29,15 @@ all: $(GENHEADERS) $(GENSOURCES)
TEMPLATE_DIR=$(TOPDIR)/pylib/templates/
#
-# ALL templates and potential generated files (not generated automatically)
-# NOTE: Currently unused
-#
-ALL_TEMPLATES=$(shell find $(TOPDIR) -name '*.t')
-ALL_GENERATED=$(basename $(ALL_TEMPLATES))
-
-#
# And clean them
#
CLEAN+=$(GENSOURCES) $(GENHEADERS)
#
-# Add templates as dependencies
+# Some base dependencies
#
-PYTHON_FILES=$(shell find $(TEMPLATE_DIR) -name '*.t')
-$(GENSOURCES) $(GENHEADERS): $(PYTHON_FILES)
+$(GENSOURCES): $(TEMPLATE_DIR)/base.c.t
+$(GENHEADERS): $(TEMPLATE_DIR)/base.h.t
#
# Generated files depend on python generators and the template
diff --git a/libs/filters/Makefile b/libs/filters/Makefile
index 43b0539..e6d8aec 100644
--- a/libs/filters/Makefile
+++ b/libs/filters/Makefile
@@ -1,7 +1,10 @@
TOPDIR=../..
-GENSOURCES=GP_Contrast.gen.c GP_Brightness.gen.c GP_Invert.gen.c GP_Point.gen.c- GP_MirrorV.gen.c GP_Rotate.gen.c GP_Dither.gen.c GP_Difference.gen.c
-GENHEADERS=
+
+POINT_FILTERS=GP_Contrast.gen.c GP_Brightness.gen.c GP_Invert.gen.c GP_Point.gen.c
+ARITHMETIC_FILTERS=GP_Difference.gen.c
+GENSOURCES=GP_MirrorV.gen.c GP_Rotate.gen.c GP_Dither.gen.c+ $(POINT_FILTERS) $(ARITHMETIC_FILTERS)
+
CSOURCES=$(filter-out $(wildcard *.gen.c),$(wildcard *.c))
LIBNAME=filters
INCLUDE=core
@@ -9,3 +12,6 @@ INCLUDE=core
include $(TOPDIR)/gen.mk
include $(TOPDIR)/include.mk
include $(TOPDIR)/lib.mk
+
+$(POINT_FILTERS): $(TEMPLATE_DIR)/filter.point.c.t
+$(ARITHMETIC_FILTERS): $(TEMPLATE_DIR)/filter.arithmetic.c.t
http://repo.or.cz/w/gfxprim.git/commit/a19d7e22a4d18fc9ada59ce5968b3ea382ff…
commit a19d7e22a4d18fc9ada59ce5968b3ea382ff6498
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Tue Nov 29 19:01:48 2011 +0100
build: Fix and clean up the gen.mk.
diff --git a/gen.mk b/gen.mk
index 0d4d937..58cd612 100644
--- a/gen.mk
+++ b/gen.mk
@@ -14,12 +14,6 @@ GENSOURCES=
endif
#
-# Headers go into include/core/
-#
-INCLUDE_PREFIX=$(TOPDIR)/include/$(LIBNAME)/
-RGENHEADERS=$(addprefix $(INCLUDE_PREFIX),$(GENHEADERS))
-
-#
# Generate genfiles for generated sources
#
CSOURCES+=$(GENSOURCES)
@@ -27,7 +21,7 @@ CSOURCES+=$(GENSOURCES)
#
# Make the genrated headers actually build
#
-all: $(GENHEADERS)
+all: $(GENHEADERS) $(GENSOURCES)
#
# Base common templates location
@@ -47,9 +41,15 @@ ALL_GENERATED=$(basename $(ALL_TEMPLATES))
CLEAN+=$(GENSOURCES) $(GENHEADERS)
#
+# Add templates as dependencies
+#
+PYTHON_FILES=$(shell find $(TEMPLATE_DIR) -name '*.t')
+$(GENSOURCES) $(GENHEADERS): $(PYTHON_FILES)
+
+#
# Generated files depend on python generators and the template
#
-$(GENSOURCES) $(GENHEADERS): %: %.t $(PYTHON_FILES)
+$(GENSOURCES) $(GENHEADERS): %: %.t
ifdef VERBOSE
${PYTHON} ${TOPDIR}/pylib/bin/generate_file.py -t $(TEMPLATE_DIR) "$@.t" "$@"
else
diff --git a/libs/filters/Makefile b/libs/filters/Makefile
index 3188e17..43b0539 100644
--- a/libs/filters/Makefile
+++ b/libs/filters/Makefile
@@ -1,6 +1,6 @@
TOPDIR=../..
GENSOURCES=GP_Contrast.gen.c GP_Brightness.gen.c GP_Invert.gen.c GP_Point.gen.c- GP_MirrorV.gen.c GP_Rotate.gen.c GP_Dither.gen.c
+ GP_MirrorV.gen.c GP_Rotate.gen.c GP_Dither.gen.c GP_Difference.gen.c
GENHEADERS=
CSOURCES=$(filter-out $(wildcard *.gen.c),$(wildcard *.c))
LIBNAME=filters
@@ -9,5 +9,3 @@ INCLUDE=core
include $(TOPDIR)/gen.mk
include $(TOPDIR)/include.mk
include $(TOPDIR)/lib.mk
-
-$(GENSOURCES): $(TOPDIR)/pylib/templates/filter.point.c.t
http://repo.or.cz/w/gfxprim.git/commit/b4d70c436ceb9fa60ed951a3a5259db2dc41…
commit b4d70c436ceb9fa60ed951a3a5259db2dc4159d5
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Tue Nov 29 18:22:11 2011 +0100
TODO: Remove finished TODO.
diff --git a/TODO b/TODO
index 9606fe0..ac6d898 100644
--- a/TODO
+++ b/TODO
@@ -13,8 +13,6 @@ What's not implemented (and should be)
- some overall initialization routines
- backed event handling
-* Fix contrast - pass GP_Pixel so each channel could have different increment
-
* Meditate about bit endians and why these aren't separate pixel types
(which would make our lives a bit easier)
-----------------------------------------------------------------------
Summary of changes:
TODO | 2 -
demos/grinder/grinder.c | 94 +++++++++++--
gen.mk | 23 +--
include/filters/{GP_Dither.h => GP_Arithmetic.h} | 60 ++++++---
include/filters/GP_Filters.h | 3 +
libs/filters/GP_Addition.gen.c.t | 24 ++++
libs/filters/GP_Difference.gen.c.t | 23 ++++
libs/filters/GP_Max.gen.c.t | 23 ++++
libs/filters/GP_Min.gen.c.t | 23 ++++
libs/filters/GP_Multiply.gen.c.t | 24 ++++
libs/filters/Makefile | 17 ++-
pylib/templates/common.c.t | 11 ++
pylib/templates/filter.arithmetic.c.t | 154 ++++++++++++++++++++++
pylib/templates/filter.c.t | 58 ++++++++
pylib/templates/filter.point.c.t | 77 ++----------
15 files changed, 493 insertions(+), 123 deletions(-)
copy include/filters/{GP_Dither.h => GP_Arithmetic.h} (55%)
create mode 100644 libs/filters/GP_Addition.gen.c.t
create mode 100644 libs/filters/GP_Difference.gen.c.t
create mode 100644 libs/filters/GP_Max.gen.c.t
create mode 100644 libs/filters/GP_Min.gen.c.t
create mode 100644 libs/filters/GP_Multiply.gen.c.t
create mode 100644 pylib/templates/common.c.t
create mode 100644 pylib/templates/filter.arithmetic.c.t
create mode 100644 pylib/templates/filter.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 pywrap updated: 0f2c026b6360e700cf3f1a87d0031a5760523886
by metan 29 Nov '11
by metan 29 Nov '11
29 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, pywrap has been updated
via 0f2c026b6360e700cf3f1a87d0031a5760523886 (commit)
via 79e7ced60aec15842bb5c7c8620b69d5a2689f1b (commit)
via 9800d72f27df325aa25aaa5b35851551ef010921 (commit)
via ee7841b92486c22488a2efcb8fe29ea8642f863c (commit)
via c2d53d78b138cc441a28c025b8899f6d3b80f29e (commit)
via 97f2975708403ba5aff97ad8c4c9bad612046342 (commit)
via 1a2763d0c3acb1b96f6aa658c8f28abef429eb04 (commit)
via 5cdba1dbc960776f21bdd7e9a07a4546ad918ea3 (commit)
via 86f0ef66d88f47ebb9ac8b9a1a30a83e3b449d2b (commit)
via eb0fe417461ded37e79ffa76e90cedf1b39af555 (commit)
from ce520ce10439ac3e63d5819e136ee623d5531206 (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/0f2c026b6360e700cf3f1a87d0031a576052…
commit 0f2c026b6360e700cf3f1a87d0031a5760523886
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Tue Nov 29 12:13:39 2011 +0100
build: sketch of build systems for pywrap.
diff --git a/Makefile b/Makefile
index 142c98c..2fcd174 100644
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,5 @@
TOPDIR=.
-SUBDIRS=include libs tests pylib demos
+SUBDIRS=include libs tests pylib demos pywrap
include include.mk
#
diff --git a/configure b/configure
index 12c3a89..3157690 100755
--- a/configure
+++ b/configure
@@ -140,6 +140,7 @@ if __name__ == '__main__':
cfg = {'CC' : ['gcc', 'Path/name of the C compiler'],
'CFLAGS' : ['-W -Wall -Wextra -fPIC -O2', 'C compiler flags'],
'PYTHON_BIN' : ['python', 'Path/name of python interpreter'],
+ 'SWIG' : ['swig', 'Simplified Wrapper and Interface Generator'],
'include_path': ['/usr/include', 'Path to the system headers']}
#
diff --git a/include/core/swigify.sh b/include/core/swigify.sh
deleted file mode 100755
index d275dc4..0000000
--- a/include/core/swigify.sh
+++ /dev/null
@@ -1,9 +0,0 @@
-set -e
-
-swig -python -Wall -I/usr/include/ gfxprim_core.swig
-gcc -shared gfxprim_core_wrap.c -L ../../build/ -I /usr/include/python2.6/ -I.. - -fPIC -Wall -lGP -lpng -ljpeg -lm -ldl -o ../../build/_gfxprim_core_c.so
-mv gfxprim_core_c.py ../../pylib/
-rm gfxprim_core_wrap.c
-
-echo Swigified!
diff --git a/include/loaders/swigify.sh b/include/loaders/swigify.sh
deleted file mode 100755
index e0514ec..0000000
--- a/include/loaders/swigify.sh
+++ /dev/null
@@ -1,9 +0,0 @@
-set -e
-
-swig -python -Wall -I/usr/include/ gfxprim_loaders.swig
-gcc -shared gfxprim_loaders_wrap.c -L ../../build/ -I /usr/include/python2.6/ -I.. - -fPIC -Wall -lGP -lpng -ljpeg -lm -ldl -o ../../build/_gfxprim_loaders_c.so
-mv gfxprim_loaders_c.py ../../pylib/
-rm gfxprim_loaders_wrap.c
-
-echo Swigified!
diff --git a/pywrap.mk b/pywrap.mk
new file mode 100644
index 0000000..fd60b0f
--- /dev/null
+++ b/pywrap.mk
@@ -0,0 +1,34 @@
+ifndef LIBNAME
+$(error LIBNAME not defined, fix your library Makefile)
+endif
+
+include $(TOPDIR)/config.gen.mk
+
+ifneq ($(SWIG),)
+
+INCLUDES+=$(addprefix -I$(TOPDIR)/include/, $(INCLUDE))
+
+all: _gfxprim_$(LIBNAME)_c.so
+
+gfxprim_$(LIBNAME).c: gfxprim_$(LIBNAME).swig
+
+gfxprim_$(LIBNAME).c: %.c: %.swig
+ifdef VERBOSE
+ $(SWIG) -python -Wall -I/usr/include/ $(INCLUDES) $<
+ cp gfxprim_$(LIBNAME)_c.py ../../pylib/
+else
+ @echo "SWIG $(LIBNAME)"
+ @$(SWIG) -python -Wall -I/usr/include/ $(INCLUDES) $<
+ @cp gfxprim_$(LIBNAME)_c.py ../../pylib/
+endif
+
+_gfxprim_$(LIBNAME)_c.so: gfxprim_$(LIBNAME).c
+ifdef VERBOSE
+ $(CC) -fPIC -dPIC --shared -Wall -lGP -lpng -ljpeg -lm -ldl -o _gfxprim_$(LIBNAME)_c.so
+else
+ @echo "LD $@"
+ @$(CC) -fPIC -dPIC --shared -Wall -lGP -lpng -ljpeg -lm -ldl -o _gfxprim_$(LIBNAME)_c.so
+endif
+
+CLEAN+=gfxprim_$(LIBNAME).c gfxprim_$(LIBNAME)_c.py gfxprim_$(LIBNAME)_wrap.c _gfxprim_$(LIBNAME)_c.so
+endif
diff --git a/pywrap/Makefile b/pywrap/Makefile
new file mode 100644
index 0000000..1004920
--- /dev/null
+++ b/pywrap/Makefile
@@ -0,0 +1,3 @@
+TOPDIR=..
+SUBDIRS=core loaders
+include $(TOPDIR)/include.mk
diff --git a/pywrap/core/Makefile b/pywrap/core/Makefile
new file mode 100644
index 0000000..eb25047
--- /dev/null
+++ b/pywrap/core/Makefile
@@ -0,0 +1,4 @@
+TOPDIR=../..
+LIBNAME=core
+include $(TOPDIR)/pywrap.mk
+include $(TOPDIR)/include.mk
diff --git a/include/core/gfxprim_core.swig b/pywrap/core/gfxprim_core.swig
similarity index 100%
rename from include/core/gfxprim_core.swig
rename to pywrap/core/gfxprim_core.swig
diff --git a/pywrap/loaders/Makefile b/pywrap/loaders/Makefile
new file mode 100644
index 0000000..b599253
--- /dev/null
+++ b/pywrap/loaders/Makefile
@@ -0,0 +1,5 @@
+TOPDIR=../..
+LIBNAME=loaders
+INCLUDE=core
+include $(TOPDIR)/pywrap.mk
+include $(TOPDIR)/include.mk
diff --git a/include/loaders/gfxprim_loaders.swig b/pywrap/loaders/gfxprim_loaders.swig
similarity index 100%
rename from include/loaders/gfxprim_loaders.swig
rename to pywrap/loaders/gfxprim_loaders.swig
diff --git a/pywrap/loaders/gfxprim_loaders_c.so b/pywrap/loaders/gfxprim_loaders_c.so
new file mode 100755
index 0000000..b809122
Binary files /dev/null and b/pywrap/loaders/gfxprim_loaders_c.so differ
http://repo.or.cz/w/gfxprim.git/commit/79e7ced60aec15842bb5c7c8620b69d5a268…
commit 79e7ced60aec15842bb5c7c8620b69d5a2689f1b
Merge: ce520ce 9800d72
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Tue Nov 29 00:41:52 2011 +0100
Merge branch 'master' into pywrap
-----------------------------------------------------------------------
Summary of changes:
Makefile | 7 +-
build/Makefile | 1 +
configure | 1 +
demos/fbshow/fbshow.c | 8 +-
doc/context.txt | 23 ++-
doc/drawing_api.txt | 62 +++++--
gen.mk | 7 +-
{demos => include}/Makefile | 2 +-
include/core/Makefile | 6 +
include/core/swigify.sh | 9 -
include/loaders/swigify.sh | 9 -
libs/core/Makefile | 2 -
libs/filters/GP_Linear.c | 216 +++++++++++++++++++++-
pywrap.mk | 34 ++++
{demos => pywrap}/Makefile | 2 +-
pywrap/core/Makefile | 4 +
{include => pywrap}/core/gfxprim_core.swig | 0
{libs => pywrap}/loaders/Makefile | 5 +-
{include => pywrap}/loaders/gfxprim_loaders.swig | 0
pywrap/loaders/gfxprim_loaders_c.so | Bin 0 -> 6141 bytes
20 files changed, 334 insertions(+), 64 deletions(-)
copy {demos => include}/Makefile (62%)
create mode 100644 include/core/Makefile
delete mode 100755 include/core/swigify.sh
delete mode 100755 include/loaders/swigify.sh
create mode 100644 pywrap.mk
copy {demos => pywrap}/Makefile (62%)
create mode 100644 pywrap/core/Makefile
rename {include => pywrap}/core/gfxprim_core.swig (100%)
copy {libs => pywrap}/loaders/Makefile (58%)
rename {include => pywrap}/loaders/gfxprim_loaders.swig (100%)
create mode 100755 pywrap/loaders/gfxprim_loaders_c.so
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: 9800d72f27df325aa25aaa5b35851551ef010921
by bluebear 27 Nov '11
by bluebear 27 Nov '11
27 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 9800d72f27df325aa25aaa5b35851551ef010921 (commit)
from ee7841b92486c22488a2efcb8fe29ea8642f863c (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/9800d72f27df325aa25aaa5b35851551ef01…
commit 9800d72f27df325aa25aaa5b35851551ef010921
Author: BlueBear <jiri.bluebear.dluhos(a)gmail.com>
Date: Sun Nov 27 21:30:48 2011 +0100
Slightly refined documentation for circles and ellipses.
diff --git a/doc/drawing_api.txt b/doc/drawing_api.txt
index 75a67e4..e73a07c 100644
--- a/doc/drawing_api.txt
+++ b/doc/drawing_api.txt
@@ -79,7 +79,10 @@ void GP_Circle(GP_Context *context, GP_Coord xcenter, GP_Coord ycenter,
GP_Size r, GP_Pixel pixel);
--------------------------------------------------------------------------------
-Draws a circle.
+Draws a circle centered at (xcenter, ycenter) with radius 'r' (in pixels).
+
+The circle is drawn so that all affected pixels will fit into a square
+specified by points (xcenter-r, ycenter-r, xcenter+r, ycenter+r), inclusive.
[source,c]
--------------------------------------------------------------------------------
@@ -89,6 +92,10 @@ void GP_FillCircle(GP_Context *context, GP_Coord xcenter, GP_Coord ycenter,
Draws a filled circle.
+The set of pixels affected by 'GP_FillCircle()' is exactly the same as if
+drawing the circle boundary using GP_Circle() and then filling all pixels
+within the boundary with the same color.
+
Rings
~~~~~
[source,c]
@@ -97,7 +104,10 @@ void GP_Ring(GP_Context *context, GP_Coord xcenter, GP_Coord ycenter,
GP_Size r1, GP_Size r2, GP_Pixel pixel);
--------------------------------------------------------------------------------
-Draws a ring.
+Draws a ring (two circles centered at (xcenter, ycenter) with radii 'r1' and 'r2').
+
+The result is exactly the same as calling 'GP_Circle()' with the same center
+and appropriate radii.
[source,c]
--------------------------------------------------------------------------------
@@ -119,7 +129,10 @@ void GP_Ellipse(GP_Context *context, GP_Coord xcenter, GP_Coord ycenter,
GP_Size a, GP_Size b, GP_Pixel pixel);
--------------------------------------------------------------------------------
-Draws an ellipse.
+Draws an axis-aligned ellipse.
+
+The ellipse is drawn so that all affected pixels will fit into a rectangle
+specified by points (xcenter-a, ycenter-b, xcenter+a, ycenter+b), inclusive.
[source,c]
--------------------------------------------------------------------------------
@@ -127,7 +140,7 @@ void GP_FillEllipse(GP_Context *context, GP_Coord xcenter, GP_Coord ycenter,
GP_Size a, GP_Size b, GP_Pixel pixel);
--------------------------------------------------------------------------------
-Draws a filled ellipse.
+Draws a filled axis-aligned ellipse.
Triangles
~~~~~~~~~
-----------------------------------------------------------------------
Summary of changes:
doc/drawing_api.txt | 21 +++++++++++++++++----
1 files changed, 17 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
[repo.or.cz] gfxprim.git branch master updated: ee7841b92486c22488a2efcb8fe29ea8642f863c
by bluebear 27 Nov '11
by bluebear 27 Nov '11
27 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 ee7841b92486c22488a2efcb8fe29ea8642f863c (commit)
from c2d53d78b138cc441a28c025b8899f6d3b80f29e (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/ee7841b92486c22488a2efcb8fe29ea8642f…
commit ee7841b92486c22488a2efcb8fe29ea8642f863c
Author: BlueBear <jiri.bluebear.dluhos(a)gmail.com>
Date: Sun Nov 27 20:23:07 2011 +0100
More precise documentation of line drawing functions and subcontexts.
diff --git a/doc/context.txt b/doc/context.txt
index a98d21a..38a8efb 100644
--- a/doc/context.txt
+++ b/doc/context.txt
@@ -99,8 +99,9 @@ void GP_ContextFree(GP_Context *context);
The 'GP_ContextAlloc()' allocates context and initalizes the context
structure. The orientation flags are all set to 0 and the rest of the metadata
-are calculated accordingly to width, height and pixel_type. The bitmap
-(context->pixels) is not initalized.
+are calculated accordingly to width, height and pixel_type. A bitmap with
+appropriate size is allocated and stored in context->pixels; the initial
+contents of the bitmap are undefined.
The 'GP_ContextCopy()' allocates and initalizes a copy of the context passed
as argument. If 'flag' is not zero, the bitmap (context->pixels) is copied
@@ -112,12 +113,12 @@ In both cases the resulting context should later be freed with
Subcontext
~~~~~~~~~~
-Given a rectangular area inside of any context subcontext could be created.
-The resulting context could be used for all context operations (including
-subcontext creation). The only difference between allocated context and
-subcontext of such context is that the 'GP_ContextFree()' doesn't call
-'free()' on subcontext pixels (which as a matter of a fact is a pointer that
-points somewhere into to allocated area).
+A subcontext is a context that refers to a rectangular area within another
+context. Subcontexts can be used as any other context (including creating
+another subcontexts).
+
+Calling GP_ContextFree() on a subcontext is safe; the bitmap is not freed as
+it belongs to another context; it will be freed with the hosting context.
[source,c]
-------------------------------------------------------------------------------
@@ -129,12 +130,12 @@ GP_Context *GP_ContextSubContext(GP_Context *context, GP_Context *subcontext,
Creates subcontext of a context. The rectangular area must fit into the context.
-If subcontext pointer is 'NULL' the context structure is allocated otherwise
+If subcontext pointer is 'NULL', the context structure is allocated; otherwise
the metadata are filled into the context structure pointed by subcontext
pointer.
-In both cases pointer to subcontext or NULL (in case of 'malloc(2)' failure) is
-returned.
+In both cases, the call returns either a pointer to the new subcontext,
+or NULL on failure (when there is not enough memory).
Conversions
~~~~~~~~~~~
diff --git a/doc/drawing_api.txt b/doc/drawing_api.txt
index 6cfd7e8..75a67e4 100644
--- a/doc/drawing_api.txt
+++ b/doc/drawing_api.txt
@@ -9,8 +9,8 @@ Fill
void GP_Fill(GP_Context *context, GP_Pixel pixel);
--------------------------------------------------------------------------------
-Fills the context bitmap. This has the same effect as calling
-'GP_FillRect(context, 0, 0, context->w, context->h, pixel)'.
+Fills the whole context bitmap with the specified pixel value. This has the
+same effect as calling 'GP_FillRect(context, 0, 0, context->w, context->h, pixel)'.
Lines
~~~~~
@@ -20,30 +20,45 @@ Lines
void GP_HLineXXY(GP_Context *context, GP_Coord x0, GP_Coord x1, GP_Coord y,
GP_Pixel pixel);
-void GP_HLineXYW(GP_Context *context, GP_Coord x, GP_Coord y, GP_Size w,
- GP_Pixel pixel);
-
void GP_HLine(GP_Context *context, GP_Coord x0, GP_Coord x1, GP_Coord y,
GP_Pixel pixel);
--------------------------------------------------------------------------------
-Draws a horizontal line. The 'GP_HLine()' function is an alias for
-'GP_HLineXXY()'.
+Draws a horizontal line from (x0, y) to (x1, y), inclusive. The coordinates
+x0, x1 can be specified in any order.
+
+'GP_HLine()' is an alias for 'GP_HLineXXY()'.
[source,c]
--------------------------------------------------------------------------------
-void GP_VLineXYY(GP_Context *context, GP_Coord x, GP_Coord y0, GP_Coord y1,
+void GP_HLineXYW(GP_Context *context, GP_Coord x, GP_Coord y, GP_Size w,
GP_Pixel pixel);
+--------------------------------------------------------------------------------
-void GP_VLineXYH(GP_Context *context, GP_Coord x, GP_Coord y, GP_Size h,
+Draws a horizontal line from (x, y) to (x+w-1, y), inclusive.
+
+
+[source,c]
+--------------------------------------------------------------------------------
+void GP_VLineXYY(GP_Context *context, GP_Coord x, GP_Coord y0, GP_Coord y1,
GP_Pixel pixel);
void GP_VLine(GP_Context *context, GP_Coord x, GP_Coord y0, GP_Coord y1,
GP_Pixel pixel);
--------------------------------------------------------------------------------
-Draws a vertical line. The 'GP_VLine()' function is an alias for
-'GP_VLineXYY()'.
+Draws a vertical line from (x, y0) to (x, y1), inclusive. The coordinates
+y0, y1 can be specified in any order.
+
+'GP_VLine()' is an alias for 'GP_VLineXYY()'.
+
+--------------------------------------------------------------------------------
+void GP_VLineXYH(GP_Context *context, GP_Coord x, GP_Coord y, GP_Size h,
+ GP_Pixel pixel);
+
+--------------------------------------------------------------------------------
+
+Draws a vertical line from (x, y) to (x, y+h-1), inclusive.
[source,c]
--------------------------------------------------------------------------------
@@ -51,7 +66,9 @@ void GP_Line(GP_Context *context, GP_Coord x0, GP_Coord y0,
GP_Coord x1, GP_Coord y1, GP_Pixel pixel);
--------------------------------------------------------------------------------
-Draws a line from (x0, y0) to (x1, y1), inclusive.
+Draws a line from (x0, y0) to (x1, y1), inclusive. The starting and ending
+point can be specified in any order (the implementation guarantees that
+exactly the same set of pixels will be drawn in both cases).
Circles
~~~~~~~
-----------------------------------------------------------------------
Summary of changes:
doc/context.txt | 23 ++++++++++++-----------
doc/drawing_api.txt | 41 +++++++++++++++++++++++++++++------------
2 files changed, 41 insertions(+), 23 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: c2d53d78b138cc441a28c025b8899f6d3b80f29e
by metan 27 Nov '11
by metan 27 Nov '11
27 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 c2d53d78b138cc441a28c025b8899f6d3b80f29e (commit)
from 97f2975708403ba5aff97ad8c4c9bad612046342 (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/c2d53d78b138cc441a28c025b8899f6d3b80…
commit c2d53d78b138cc441a28c025b8899f6d3b80f29e
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Sun Nov 27 14:13:36 2011 +0100
build: Fix the gen headers build and paralel build.
Now headers are generated first before any other
code is compiled so 'make -j3' works correctly.
diff --git a/Makefile b/Makefile
index 4f303c0..142c98c 100644
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,5 @@
TOPDIR=.
-SUBDIRS=libs tests pylib demos
+SUBDIRS=include libs tests pylib demos
include include.mk
#
@@ -9,7 +9,10 @@ include include.mk
#
.PHONY: build
-tests: build libs
+libs: include
+
+tests: libs
+demos: libs
build:
@$(MAKE) --no-print-directory -C build clean
diff --git a/build/Makefile b/build/Makefile
index 709dd08..1b39ee3 100644
--- a/build/Makefile
+++ b/build/Makefile
@@ -1,6 +1,7 @@
LIB_OBJECTS=$(shell ./get_objs.sh)
all: libGP.a libGP.so libGP.so.0
+.PHONY: libGP.a libGP.so libGP.so.0
clean:
ifdef VERBOSE
diff --git a/gen.mk b/gen.mk
index 41ad5f5..0d4d937 100644
--- a/gen.mk
+++ b/gen.mk
@@ -27,8 +27,7 @@ CSOURCES+=$(GENSOURCES)
#
# Make the genrated headers actually build
#
-all: $(RGENHEADERS)
-$(CSOURCES): $(RGENHEADERS)
+all: $(GENHEADERS)
#
# Base common templates location
@@ -45,12 +44,12 @@ ALL_GENERATED=$(basename $(ALL_TEMPLATES))
#
# And clean them
#
-CLEAN+=$(GENSOURCES) $(RGENHEADERS)
+CLEAN+=$(GENSOURCES) $(GENHEADERS)
#
# Generated files depend on python generators and the template
#
-$(GENSOURCES) $(RGENHEADERS): %: %.t $(PYTHON_FILES)
+$(GENSOURCES) $(GENHEADERS): %: %.t $(PYTHON_FILES)
ifdef VERBOSE
${PYTHON} ${TOPDIR}/pylib/bin/generate_file.py -t $(TEMPLATE_DIR) "$@.t" "$@"
else
diff --git a/include/Makefile b/include/Makefile
new file mode 100644
index 0000000..03277e3
--- /dev/null
+++ b/include/Makefile
@@ -0,0 +1,3 @@
+TOPDIR=..
+SUBDIRS=core
+include $(TOPDIR)/include.mk
diff --git a/include/core/Makefile b/include/core/Makefile
new file mode 100644
index 0000000..186b6dd
--- /dev/null
+++ b/include/core/Makefile
@@ -0,0 +1,6 @@
+TOPDIR=../..
+GENHEADERS=GP_Convert_Scale.gen.h GP_Blit.gen.h GP_Pixel.gen.h + GP_GetPutPixel.gen.h GP_Convert.gen.h GP_FnPerBpp.gen.h
+LIBNAME=core
+include $(TOPDIR)/gen.mk
+include $(TOPDIR)/include.mk
diff --git a/libs/core/Makefile b/libs/core/Makefile
index 3f0fffd..3af4933 100644
--- a/libs/core/Makefile
+++ b/libs/core/Makefile
@@ -1,7 +1,5 @@
TOPDIR=../..
GENSOURCES=GP_Pixel.gen.c GP_Blit.gen.c GP_Convert.gen.c
-GENHEADERS=GP_Convert_Scale.gen.h GP_Blit.gen.h GP_Pixel.gen.h - GP_GetPutPixel.gen.h GP_Convert.gen.h GP_FnPerBpp.gen.h
CSOURCES=$(filter-out $(wildcard *.gen.c),$(wildcard *.c))
LIBNAME=core
-----------------------------------------------------------------------
Summary of changes:
Makefile | 7 +++++--
build/Makefile | 1 +
gen.mk | 7 +++----
{demos => include}/Makefile | 2 +-
include/core/Makefile | 6 ++++++
libs/core/Makefile | 2 --
6 files changed, 16 insertions(+), 9 deletions(-)
copy {demos => include}/Makefile (62%)
create mode 100644 include/core/Makefile
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: 97f2975708403ba5aff97ad8c4c9bad612046342
by metan 27 Nov '11
by metan 27 Nov '11
27 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 97f2975708403ba5aff97ad8c4c9bad612046342 (commit)
via 1a2763d0c3acb1b96f6aa658c8f28abef429eb04 (commit)
from 5cdba1dbc960776f21bdd7e9a07a4546ad918ea3 (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/97f2975708403ba5aff97ad8c4c9bad61204…
commit 97f2975708403ba5aff97ad8c4c9bad612046342
Merge: 1a2763d 5cdba1d
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Sun Nov 27 00:04:39 2011 +0100
Merge ssh://repo.or.cz/srv/git/gfxprim
http://repo.or.cz/w/gfxprim.git/commit/1a2763d0c3acb1b96f6aa658c8f28abef429…
commit 1a2763d0c3acb1b96f6aa658c8f28abef429eb04
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Sun Nov 27 00:00:49 2011 +0100
filters: Experimental integer aritmetic convolutions.
Seems to work fine, needs to be checked more properly.
diff --git a/libs/filters/GP_Linear.c b/libs/filters/GP_Linear.c
index e5b8d81..da15f11 100644
--- a/libs/filters/GP_Linear.c
+++ b/libs/filters/GP_Linear.c
@@ -90,7 +90,7 @@ int GP_FilterGaussianBlur_Raw(const GP_Context *src, GP_Context *dst,
float kernel_x[size_x];
gaussian_kernel_init(sigma_x, kernel_x);
- if (GP_FilterHLinearConvolution_Raw(src, dst, kernel_x, size_x,
+ if (GP_FilterHLinearConvolutionInt_Raw(src, dst, kernel_x, size_x,
new_callback))
return 1;
}
@@ -103,7 +103,7 @@ int GP_FilterGaussianBlur_Raw(const GP_Context *src, GP_Context *dst,
float kernel_y[size_y];
gaussian_kernel_init(sigma_y, kernel_y);
- if (GP_FilterVLinearConvolution_Raw(dst, dst, kernel_y, size_y,
+ if (GP_FilterVLinearConvolutionInt_Raw(dst, dst, kernel_y, size_y,
new_callback))
return 1;
}
@@ -344,6 +344,218 @@ int GP_FilterVLinearConvolution_Raw(const GP_Context *src, GP_Context *dst,
return 0;
}
+#define MUL 1024
+
+int GP_FilterHLinearConvolutionInt_Raw(const GP_Context *src, GP_Context *dst,
+ float kernel[], uint32_t kw,
+ GP_ProgressCallback *callback)
+{
+ int32_t kernel_sum = 0;
+ GP_Coord x, y;
+ uint32_t i;
+ int ikernel[kw];
+
+ for (i = 0; i < kw; i++)
+ ikernel[i] = kernel[i] * MUL + 0.5;
+
+ GP_DEBUG(1, "Horizontal linear convolution kernel width %i image %ux%u",
+ kw, src->w, src->h);
+
+ /* count kernel sum for normalization */
+ for (i = 0; i < kw; i++)
+ kernel_sum += ikernel[i];
+
+ /* do linear convolution */
+ for (y = 0; y < (GP_Coord)dst->h; y++) {
+ GP_Pixel pix;
+ uint32_t R[kw], G[kw], B[kw];
+
+ /* prefill the buffer on the start */
+ for (i = 0; i < kw - 1; i++) {
+ int cx = i - kw/2;
+
+ if (cx < 0)
+ cx = 0;
+
+ pix = GP_GetPixel_Raw_24BPP(src, cx, y);
+
+ R[i] = GP_Pixel_GET_R_RGB888(pix);
+ G[i] = GP_Pixel_GET_G_RGB888(pix);
+ B[i] = GP_Pixel_GET_B_RGB888(pix);
+ }
+
+ int idx = kw - 1;
+
+ for (x = 0; x < (GP_Coord)dst->w; x++) {
+ float r = 0, g = 0, b = 0;
+
+ int cx = x + kw/2;
+
+ if (cx >= (int)src->w)
+ cx = src->w - 1;
+
+ pix = GP_GetPixel_Raw_24BPP(src, cx, y);
+
+ R[idx] = GP_Pixel_GET_R_RGB888(pix);
+ G[idx] = GP_Pixel_GET_G_RGB888(pix);
+ B[idx] = GP_Pixel_GET_B_RGB888(pix);
+
+ /* count the pixel value from neighbours weighted by kernel */
+ for (i = 0; i < kw; i++) {
+ int k;
+
+ if ((int)i < idx + 1)
+ k = kw - idx - 1 + i;
+ else
+ k = i - idx - 1;
+
+ r += R[i] * ikernel[k];
+ g += G[i] * ikernel[k];
+ b += B[i] * ikernel[k];
+ }
+
+ /* normalize the result */
+ r /= kernel_sum;
+ g /= kernel_sum;
+ b /= kernel_sum;
+
+ /* and clamp just to be extra sure */
+ if (r > 255)
+ r = 255;
+ if (r < 0)
+ r = 0;
+ if (g > 255)
+ g = 255;
+ if (g < 0)
+ g = 0;
+ if (b > 255)
+ b = 255;
+ if (b < 0)
+ b = 0;
+
+ pix = GP_Pixel_CREATE_RGB888((uint32_t)r, (uint32_t)g, (uint32_t)b);
+
+ GP_PutPixel_Raw_24BPP(dst, x, y, pix);
+
+ idx++;
+
+ if (idx >= (int)kw)
+ idx = 0;
+ }
+
+ if (GP_ProgressCallbackReport(callback, y, dst->h, dst->w))
+ return 1;
+ }
+
+ GP_ProgressCallbackDone(callback);
+ return 0;
+}
+
+int GP_FilterVLinearConvolutionInt_Raw(const GP_Context *src, GP_Context *dst,
+ float kernel[], uint32_t kh,
+ GP_ProgressCallback *callback)
+{
+ int32_t kernel_sum = 0;
+ GP_Coord x, y;
+ uint32_t i;
+ int32_t ikernel[kh];
+
+ for (i = 0; i < kh; i++)
+ ikernel[i] = kernel[i] * MUL + 0.5;
+
+ GP_DEBUG(1, "Vertical linear convolution kernel width %i image %ux%u",
+ kh, src->w, src->h);
+
+ /* count kernel sum for normalization */
+ for (i = 0; i < kh; i++)
+ kernel_sum += ikernel[i];
+
+ /* do linear convolution */
+ for (x = 0; x < (GP_Coord)dst->w; x++) {
+ GP_Pixel pix;
+ uint32_t R[kh], G[kh], B[kh];
+
+ /* prefill the buffer on the start */
+ for (i = 0; i < kh - 1; i++) {
+ int cy = i - kh/2;
+
+ if (cy < 0)
+ cy = 0;
+
+ pix = GP_GetPixel_Raw_24BPP(src, x, cy);
+
+ R[i] = GP_Pixel_GET_R_RGB888(pix);
+ G[i] = GP_Pixel_GET_G_RGB888(pix);
+ B[i] = GP_Pixel_GET_B_RGB888(pix);
+ }
+
+ int idx = kh - 1;
+
+ for (y = 0; y < (GP_Coord)dst->h; y++) {
+ int32_t r = 0, g = 0, b = 0;
+
+ int cy = y + kh/2;
+
+ if (cy >= (int)src->h)
+ cy = src->h - 1;
+
+ pix = GP_GetPixel_Raw_24BPP(src, x, cy);
+
+ R[idx] = GP_Pixel_GET_R_RGB888(pix);
+ G[idx] = GP_Pixel_GET_G_RGB888(pix);
+ B[idx] = GP_Pixel_GET_B_RGB888(pix);
+
+ /* count the pixel value from neighbours weighted by kernel */
+ for (i = 0; i < kh; i++) {
+ int k;
+
+ if ((int)i < idx + 1)
+ k = kh - idx - 1 + i;
+ else
+ k = i - idx - 1;
+
+ r += R[i] * ikernel[k];
+ g += G[i] * ikernel[k];
+ b += B[i] * ikernel[k];
+ }
+
+ /* normalize the result */
+ r /= kernel_sum;
+ g /= kernel_sum;
+ b /= kernel_sum;
+
+ /* and clamp just to be extra sure */
+ if (r > 255)
+ r = 255;
+ if (r < 0)
+ r = 0;
+ if (g > 255)
+ g = 255;
+ if (g < 0)
+ g = 0;
+ if (b > 255)
+ b = 255;
+ if (b < 0)
+ b = 0;
+
+ pix = GP_Pixel_CREATE_RGB888((uint32_t)r, (uint32_t)g, (uint32_t)b);
+
+ GP_PutPixel_Raw_24BPP(dst, x, y, pix);
+
+ idx++;
+
+ if (idx >= (int)kh)
+ idx = 0;
+ }
+
+ if (GP_ProgressCallbackReport(callback, x, dst->w, dst->h))
+ return 1;
+ }
+
+ GP_ProgressCallbackDone(callback);
+ return 0;
+}
+
/*
* Linear convolution.
-----------------------------------------------------------------------
Summary of changes:
libs/filters/GP_Linear.c | 216 +++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 214 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