Gfxprim
Threads by month
- ----- 2026 -----
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
December 2011
- 3 participants
- 14 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