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: 730f353131afe02ce53c9957b1e80009abba59e4
by metan 06 Jan '12
by metan 06 Jan '12
06 Jan '12
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project gfxprim.git.
The branch, master has been updated
via 730f353131afe02ce53c9957b1e80009abba59e4 (commit)
from 870edf9002091a710e94dd929c2e9583af590f34 (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/730f353131afe02ce53c9957b1e80009abba…
commit 730f353131afe02ce53c9957b1e80009abba59e4
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Fri Jan 6 20:36:48 2012 +0100
core: Use table for gamma correction.
diff --git a/include/core/GP_GammaCorrection.h b/include/core/GP_GammaCorrection.h
index d36b1a9..c4eb3b1 100644
--- a/include/core/GP_GammaCorrection.h
+++ b/include/core/GP_GammaCorrection.h
@@ -34,14 +34,17 @@
#define GP_GAMMA 2.2
+extern uint8_t *GP_LinearToGamma_8bit;
+
/*
* Coverts linear 0 255 value into 0 255 gama value.
*
- * (this is used for Anti Aliased gfx primitives.
+ * (this is used for Anti Aliased gfx primitives.)
*/
-static inline uint8_t GP_GammaToLinear(uint8_t val)
+static inline uint8_t GP_LinearToGamma(uint8_t val)
{
- return pow(1.00 * val/255, 1/GP_GAMMA) * 255 + 0.5;
+
+ return GP_LinearToGamma_8bit[val];
}
#endif /* CORE_GP_GAMMA_CORRECTION_H */
diff --git a/libs/core/Makefile b/libs/core/Makefile
index 3af4933..2baef75 100644
--- a/libs/core/Makefile
+++ b/libs/core/Makefile
@@ -1,5 +1,6 @@
TOPDIR=../..
-GENSOURCES=GP_Pixel.gen.c GP_Blit.gen.c GP_Convert.gen.c
+GENSOURCES=GP_Pixel.gen.c GP_Blit.gen.c GP_Convert.gen.c + GP_GammaCorrection.gen.c
CSOURCES=$(filter-out $(wildcard *.gen.c),$(wildcard *.c))
LIBNAME=core
diff --git a/libs/gfx/GP_RectAA.c b/libs/gfx/GP_RectAA.c
index 69ddd8f..a48d72e 100644
--- a/libs/gfx/GP_RectAA.c
+++ b/libs/gfx/GP_RectAA.c
@@ -53,7 +53,7 @@ void GP_FillRectXYXY_AA_Raw(GP_Context *context, GP_Coord x0, GP_Coord y0,
/* Special case, vertical 1px line */
if (out_x0 == out_x1) {
- uint8_t mix = GP_GammaToLinear(w);
+ uint8_t mix = GP_LinearToGamma(w);
GP_Coord i;
/* Special case 1px 100% width line */
@@ -71,7 +71,7 @@ void GP_FillRectXYXY_AA_Raw(GP_Context *context, GP_Coord x0, GP_Coord y0,
/* Special case, horizontal 1px line */
if (out_y0 == out_y1) {
- uint8_t mix = GP_GammaToLinear(h);
+ uint8_t mix = GP_LinearToGamma(h);
GP_Coord i;
/* Special case 1px 100% height line */
@@ -105,7 +105,7 @@ void GP_FillRectXYXY_AA_Raw(GP_Context *context, GP_Coord x0, GP_Coord y0,
/* if the outer and innter coordinates doesn't match, draw blurred edge */
if (in_y0 != out_y0) {
- uint8_t mix = GP_GammaToLinear(GP_FP_FROM_INT(in_y0) + GP_FP_1_2 - y0);
+ uint8_t mix = GP_LinearToGamma(GP_FP_FROM_INT(in_y0) + GP_FP_1_2 - y0);
GP_Coord i;
for (i = out_x0; i <= out_x1; i++) {
@@ -116,7 +116,7 @@ void GP_FillRectXYXY_AA_Raw(GP_Context *context, GP_Coord x0, GP_Coord y0,
}
if (in_y1 != out_y1) {
- uint8_t mix = GP_GammaToLinear(y1 - GP_FP_FROM_INT(in_y0) - GP_FP_1_2);
+ uint8_t mix = GP_LinearToGamma(y1 - GP_FP_FROM_INT(in_y0) - GP_FP_1_2);
GP_Coord i;
for (i = out_x0; i <= out_x1; i++) {
@@ -127,7 +127,7 @@ void GP_FillRectXYXY_AA_Raw(GP_Context *context, GP_Coord x0, GP_Coord y0,
}
if (in_x0 != out_x0) {
- uint8_t mix = GP_GammaToLinear(GP_FP_FROM_INT(in_x0) + GP_FP_1_2 - x0);
+ uint8_t mix = GP_LinearToGamma(GP_FP_FROM_INT(in_x0) + GP_FP_1_2 - x0);
GP_Coord i;
for (i = out_y0; i <= out_y1; i++) {
@@ -138,7 +138,7 @@ void GP_FillRectXYXY_AA_Raw(GP_Context *context, GP_Coord x0, GP_Coord y0,
}
if (in_x1 != out_x1) {
- uint8_t mix = GP_GammaToLinear(x1 - GP_FP_FROM_INT(in_x1) - GP_FP_1_2);
+ uint8_t mix = GP_LinearToGamma(x1 - GP_FP_FROM_INT(in_x1) - GP_FP_1_2);
GP_Coord i;
for (i = out_y0; i <= out_y1; i++) {
-----------------------------------------------------------------------
Summary of changes:
include/core/GP_GammaCorrection.h | 9 ++++++---
libs/core/Makefile | 3 ++-
libs/gfx/GP_RectAA.c | 12 ++++++------
3 files changed, 14 insertions(+), 10 deletions(-)
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos(a)gmail.com
if you want to unsubscribe, or site admin admin(a)repo.or.cz if you receive
no reply.
--
gfxprim.git ("A simple 2D graphics library with emphasis on correctness and well-defined operation.")
1
0
[repo.or.cz] gfxprim.git branch master updated: 870edf9002091a710e94dd929c2e9583af590f34
by metan 06 Jan '12
by metan 06 Jan '12
06 Jan '12
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project gfxprim.git.
The branch, master has been updated
via 870edf9002091a710e94dd929c2e9583af590f34 (commit)
from 30d9e3ba8aa2412e028bb51b34d3be44ddf7a92b (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/870edf9002091a710e94dd929c2e9583af59…
commit 870edf9002091a710e94dd929c2e9583af590f34
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Fri Jan 6 20:27:13 2012 +0100
pylib: Propagate math python buildins to templates
Now we can use int() float() and round() in templates too.
diff --git a/pylib/gfxprim/render_utils.py b/pylib/gfxprim/render_utils.py
index d99aa3d..b115b91 100644
--- a/pylib/gfxprim/render_utils.py
+++ b/pylib/gfxprim/render_utils.py
@@ -28,6 +28,10 @@ def create_environment(config, template_dir):
env.globals['len'] = len
env.globals['error'] = template_error
env.globals['hex'] = lambda(x): hex(x).rstrip('L')
+ # Propagate some python buildins
+ env.globals['int'] = int;
+ env.globals['float'] = float;
+ env.globals['round'] = round;
return env
-----------------------------------------------------------------------
Summary of changes:
pylib/gfxprim/render_utils.py | 4 ++++
1 files changed, 4 insertions(+), 0 deletions(-)
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos(a)gmail.com
if you want to unsubscribe, or site admin admin(a)repo.or.cz if you receive
no reply.
--
gfxprim.git ("A simple 2D graphics library with emphasis on correctness and well-defined operation.")
1
0
[repo.or.cz] gfxprim.git branch master updated: 30d9e3ba8aa2412e028bb51b34d3be44ddf7a92b
by metan 06 Jan '12
by metan 06 Jan '12
06 Jan '12
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project gfxprim.git.
The branch, master has been updated
via 30d9e3ba8aa2412e028bb51b34d3be44ddf7a92b (commit)
from 183e450a847b698b96f2f7ecbd08ed785e58879f (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/30d9e3ba8aa2412e028bb51b34d3be44ddf7…
commit 30d9e3ba8aa2412e028bb51b34d3be44ddf7a92b
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Fri Jan 6 00:57:28 2012 +0100
loaders: use png conversion to RGB for unknown palettes.
diff --git a/libs/loaders/GP_PNG.c b/libs/loaders/GP_PNG.c
index 51c645e..c430e72 100644
--- a/libs/loaders/GP_PNG.c
+++ b/libs/loaders/GP_PNG.c
@@ -16,7 +16,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, *
* Boston, MA 02110-1301 USA *
* *
- * Copyright (C) 2009-2010 Cyril Hrubis <metan(a)ucw.cz> *
+ * Copyright (C) 2009-2011 Cyril Hrubis <metan(a)ucw.cz> *
* *
*****************************************************************************/
@@ -127,7 +127,7 @@ GP_RetCode GP_ReadPNG(FILE *f, GP_Context **res,
GP_DEBUG(2, "Have %s%s interlace %s PNG%s size %ux%u depth %i",
interlace_type_name(interlace_type),
- color_type & PNG_COLOR_MASK_PALETTE ? "pallete " : "",
+ color_type & PNG_COLOR_MASK_PALETTE ? " pallete " : "",
color_type & PNG_COLOR_MASK_COLOR ? "color" : "gray",
color_type & PNG_COLOR_MASK_ALPHA ? " with alpha channel" : "",
(unsigned int)w, (unsigned int)h, depth);
@@ -169,6 +169,12 @@ GP_RetCode GP_ReadPNG(FILE *f, GP_Context **res,
break;
}
}
+
+ /* Convert everything else to RGB888 */
+ //TODO: add palette matching to G2 G4 and G8
+ png_set_palette_to_rgb(png);
+ png_set_bgr(png);
+ pixel_type = GP_PIXEL_RGB888;
break;
}
-----------------------------------------------------------------------
Summary of changes:
libs/loaders/GP_PNG.c | 10 ++++++++--
1 files changed, 8 insertions(+), 2 deletions(-)
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos(a)gmail.com
if you want to unsubscribe, or site admin admin(a)repo.or.cz if you receive
no reply.
--
gfxprim.git ("A simple 2D graphics library with emphasis on correctness and well-defined operation.")
1
0
[repo.or.cz] gfxprim.git branch master updated: 183e450a847b698b96f2f7ecbd08ed785e58879f
by metan 05 Jan '12
by metan 05 Jan '12
05 Jan '12
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project gfxprim.git.
The branch, master has been updated
via 183e450a847b698b96f2f7ecbd08ed785e58879f (commit)
from b0791316458c7edc23a03dc8eb1d9bc346dc3b3a (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/183e450a847b698b96f2f7ecbd08ed785e58…
commit 183e450a847b698b96f2f7ecbd08ed785e58879f
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Thu Jan 5 02:17:25 2012 +0100
gfx: Anti Aliased rectangle, fixed one more special case.
diff --git a/libs/gfx/GP_RectAA.c b/libs/gfx/GP_RectAA.c
index c68c377..69ddd8f 100644
--- a/libs/gfx/GP_RectAA.c
+++ b/libs/gfx/GP_RectAA.c
@@ -99,11 +99,12 @@ void GP_FillRectXYXY_AA_Raw(GP_Context *context, GP_Coord x0, GP_Coord y0,
* Note that if out_x0 == in_x1 is 2px wide and both lines has less than
* 100% intensity. The same goes for out_y0 == in_y1.
*/
- if (in_x1 >= in_x0 && out_x0 != in_x1 && in_y1 >= in_y0 && out_y0 != in_y1)
+ if (in_x1 >= in_x0 && (out_x0 != in_x1 || out_x1 != in_x0)
+ && in_y1 >= in_y0 && (out_y0 != in_y1 || out_y1 != in_y0))
GP_FillRectXYXY_Raw(context, in_x0, in_y0, in_x1, in_y1, pixel);
/* if the outer and innter coordinates doesn't match, draw blurred edge */
- if (in_y0 != out_y0 && out_x0 != in_x1) {
+ if (in_y0 != out_y0) {
uint8_t mix = GP_GammaToLinear(GP_FP_FROM_INT(in_y0) + GP_FP_1_2 - y0);
GP_Coord i;
@@ -114,7 +115,7 @@ void GP_FillRectXYXY_AA_Raw(GP_Context *context, GP_Coord x0, GP_Coord y0,
}
}
- if (in_y1 != out_y1 && out_x0 != in_x1) {
+ if (in_y1 != out_y1) {
uint8_t mix = GP_GammaToLinear(y1 - GP_FP_FROM_INT(in_y0) - GP_FP_1_2);
GP_Coord i;
@@ -125,7 +126,7 @@ void GP_FillRectXYXY_AA_Raw(GP_Context *context, GP_Coord x0, GP_Coord y0,
}
}
- if (in_x0 != out_x0 && out_y0 != in_y1) {
+ if (in_x0 != out_x0) {
uint8_t mix = GP_GammaToLinear(GP_FP_FROM_INT(in_x0) + GP_FP_1_2 - x0);
GP_Coord i;
@@ -136,7 +137,7 @@ void GP_FillRectXYXY_AA_Raw(GP_Context *context, GP_Coord x0, GP_Coord y0,
}
}
- if (in_x1 != out_x1 && out_y0 != in_y1) {
+ if (in_x1 != out_x1) {
uint8_t mix = GP_GammaToLinear(x1 - GP_FP_FROM_INT(in_x1) - GP_FP_1_2);
GP_Coord i;
-----------------------------------------------------------------------
Summary of changes:
libs/gfx/GP_RectAA.c | 11 ++++++-----
1 files changed, 6 insertions(+), 5 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: b0791316458c7edc23a03dc8eb1d9bc346dc3b3a
by metan 05 Jan '12
by metan 05 Jan '12
05 Jan '12
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project gfxprim.git.
The branch, master has been updated
via b0791316458c7edc23a03dc8eb1d9bc346dc3b3a (commit)
from a52536952b40f8337b4415fe265217c5976f2f77 (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/b0791316458c7edc23a03dc8eb1d9bc346dc…
commit b0791316458c7edc23a03dc8eb1d9bc346dc3b3a
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Thu Jan 5 01:29:43 2012 +0100
gfx: working on Anti Aliased rectangles.
* the coordinates are rooted to the center of the pixels
(which is consistent to the rest of primitives)
* most of the code is ready
- the four pixels in the corners are not correct yet
- some of the corner cases are wrong, generally when
line is not grid aligned and grid width or height
is smaller than 3px
diff --git a/include/core/GP_FixedPoint.h b/include/core/GP_FixedPoint.h
index baf4ed4..d8556d9 100644
--- a/include/core/GP_FixedPoint.h
+++ b/include/core/GP_FixedPoint.h
@@ -49,7 +49,7 @@ typedef uint8_t GP_FP_Frac;
/*
* One Half
*/
-#define GP_FP_1_2 ((1<<(GP_FP_FRAC_BITS - 1))
+#define GP_FP_1_2 (1<<(GP_FP_FRAC_BITS - 1))
/*
* Fraction part bitmask.
@@ -57,6 +57,11 @@ typedef uint8_t GP_FP_Frac;
#define GP_FP_FRAC_MASK ((1<<GP_FP_FRAC_BITS)-1)
/*
+ * Integer part bitmask.
+ */
+#define GP_FP_INT_MASK (~GP_FP_FRAC_MASK)
+
+/*
* Addition.
*/
#define GP_FP_ADD(a, b) ((a)+(b))
@@ -69,22 +74,27 @@ typedef uint8_t GP_FP_Frac;
/*
* Floor.
*/
-#define GP_FP_FLOOR(a) ((a)>>GP_FP_FRAC_BITS)
+#define GP_FP_FLOOR(a) ((a) & GP_FP_INT_MASK)
+
+/*
+ * Floor with conversion to integer.
+ */
+#define GP_FP_FLOOR_TO_INT(a) ((a)>>GP_FP_FRAC_BITS)
/*
- * Ceilling.
+ * Ceiling.
*/
-#define GP_FP_CEIL(a) (((a)>>GP_FP_FRAC_BITS) + !!(GP_FP_FRAC(a)))
+#define GP_FP_CEIL(a) (((a) & GP_FP_INT_MASK) + ((a) & GP_FP_FRAC_MASK) ? GP_FP_1 : 0)
/*
- * Rounding.
+ * Ceilling with conversion to integer.
*/
-#define GP_FP_ROUND(a) (((a) + GP_FP_1_2))>>GP_FP_FRAC_BITS
+#define GP_FP_CEIL_TO_INT(a) (((a)>>GP_FP_FRAC_BITS) + !!(GP_FP_FRAC(a)))
/*
- * Integer part.
+ * Rounding wiht conversion to integer.
*/
-#define GP_FP_INT(a) GP_FP_FLOOR(a)
+#define GP_FP_ROUND_TO_INT(a) (((a) + GP_FP_1_2))>>GP_FP_FRAC_BITS
/*
* Fractional part.
diff --git a/libs/gfx/GP_RectAA.c b/libs/gfx/GP_RectAA.c
index 66e24b6..c68c377 100644
--- a/libs/gfx/GP_RectAA.c
+++ b/libs/gfx/GP_RectAA.c
@@ -28,6 +28,8 @@
#include "GP_Rect.h"
#include "GP_RectAA.h"
+
+
void GP_FillRectXYXY_AA_Raw(GP_Context *context, GP_Coord x0, GP_Coord y0,
GP_Coord x1, GP_Coord y1, GP_Pixel pixel)
{
@@ -39,80 +41,113 @@ void GP_FillRectXYXY_AA_Raw(GP_Context *context, GP_Coord x0, GP_Coord y0,
if (y0 > y1)
GP_SWAP(y0, y1);
+ /* Outer coordinates */
+ GP_Coord out_x0 = GP_FP_FLOOR_TO_INT(x0 + GP_FP_1_2);
+ GP_Coord out_y0 = GP_FP_FLOOR_TO_INT(y0 + GP_FP_1_2);
+ GP_Coord out_x1 = GP_FP_CEIL_TO_INT(x1 - GP_FP_1_2);
+ GP_Coord out_y1 = GP_FP_CEIL_TO_INT(y1 - GP_FP_1_2);
+
+ /* Size */
GP_Size w = x1 - x0;
GP_Size h = y1 - y0;
- printf("W = %f, H = %f, X = %f, Y = %fn",
- GP_FP_TO_FLOAT(w), GP_FP_TO_FLOAT(h),
- GP_FP_TO_FLOAT(x0), GP_FP_TO_FLOAT(y0));
+ /* Special case, vertical 1px line */
+ if (out_x0 == out_x1) {
+ uint8_t mix = GP_GammaToLinear(w);
+ GP_Coord i;
- /* This are integer coordinates of the "inner" rectangle */
- GP_Coord xi0 = GP_FP_CEIL(x0);
- GP_Coord yi0 = GP_FP_CEIL(y0);
- GP_Coord xi1 = GP_FP_FLOOR(x1);
- GP_Coord yi1 = GP_FP_FLOOR(y1);
+ /* Special case 1px 100% width line */
+ if (w == GP_FP_1)
+ mix = 255;
- if (xi1 >= xi0 && yi1 >= yi0)
- GP_FillRect_Raw(context, xi0, yi0, xi1, yi1, pixel);
-
- printf("%i %i %i %in", xi0, yi0, yi1, yi1);
-
- /* Draw the "frame" around */
- GP_Coord i;
+ for (i = out_y0; i <= out_y1; i++) {
+ GP_Pixel p = GP_GetPixel_Raw_Clipped(context, out_x0, i);
+ p = GP_MixPixels(pixel, p, mix, context->pixel_type);
+ GP_PutPixel_Raw_Clipped(context, out_x0, i, p);
+ }
- uint8_t u_perc;
- uint8_t d_perc;
-
- u_perc = GP_GammaToLinear(GP_FP_1 - GP_FP_FRAC(y0));
- d_perc = GP_GammaToLinear(GP_FP_FRAC(y1));
+ return;
+ }
- for (i = GP_FP_CEIL(x0); i <= GP_FP_FLOOR(x1); i++) {
- GP_Pixel u = GP_GetPixel_Raw_Clipped(context, i, GP_FP_FLOOR(y0));
- GP_Pixel d = GP_GetPixel_Raw_Clipped(context, i, GP_FP_CEIL(y1));
-
- u = GP_MixPixels(pixel, u, u_perc, context->pixel_type);
- d = GP_MixPixels(pixel, d, d_perc, context->pixel_type);
+ /* Special case, horizontal 1px line */
+ if (out_y0 == out_y1) {
+ uint8_t mix = GP_GammaToLinear(h);
+ GP_Coord i;
- GP_PutPixel_Raw_Clipped(context, i, GP_FP_FLOOR(y0), u);
- GP_PutPixel_Raw_Clipped(context, i, GP_FP_CEIL(y1), d);
+ /* Special case 1px 100% height line */
+ if (h == GP_FP_1)
+ mix = 255;
+
+ for (i = out_x0; i <= out_x1; i++) {
+ GP_Pixel p = GP_GetPixel_Raw_Clipped(context, i, out_y0);
+ p = GP_MixPixels(pixel, p, mix, context->pixel_type);
+ GP_PutPixel_Raw_Clipped(context, i, out_y0, p);
+ }
+
+ return;
}
- u_perc = GP_GammaToLinear(GP_FP_1 - GP_FP_FRAC(x0));
- d_perc = GP_GammaToLinear(GP_FP_FRAC(x1));
+ /* This are integer coordinates of the "inner" rectangle */
+ GP_Coord in_x0 = GP_FP_CEIL_TO_INT(x0 + GP_FP_1_2);
+ GP_Coord in_y0 = GP_FP_CEIL_TO_INT(y0 + GP_FP_1_2);
+ GP_Coord in_x1 = GP_FP_FLOOR_TO_INT(x1 - GP_FP_1_2);
+ GP_Coord in_y1 = GP_FP_FLOOR_TO_INT(y1 - GP_FP_1_2);
- for (i = GP_FP_CEIL(y0); i <= GP_FP_FLOOR(y1); i++) {
- GP_Pixel u = GP_GetPixel_Raw_Clipped(context, GP_FP_FLOOR(x0), i);
- GP_Pixel d = GP_GetPixel_Raw_Clipped(context, GP_FP_CEIL(x1), i);
-
- u = GP_MixPixels(pixel, u, u_perc, context->pixel_type);
- d = GP_MixPixels(pixel, d, d_perc, context->pixel_type);
-
- GP_PutPixel_Raw_Clipped(context, GP_FP_FLOOR(x0), i, u);
- GP_PutPixel_Raw_Clipped(context, GP_FP_CEIL(x1), i, d);
+ /*
+ * Draw the inner rectanle in 100% intensity.
+ *
+ * Note that if out_x0 == in_x1 is 2px wide and both lines has less than
+ * 100% intensity. The same goes for out_y0 == in_y1.
+ */
+ if (in_x1 >= in_x0 && out_x0 != in_x1 && in_y1 >= in_y0 && out_y0 != in_y1)
+ GP_FillRectXYXY_Raw(context, in_x0, in_y0, in_x1, in_y1, pixel);
+
+ /* if the outer and innter coordinates doesn't match, draw blurred edge */
+ if (in_y0 != out_y0 && out_x0 != in_x1) {
+ uint8_t mix = GP_GammaToLinear(GP_FP_FROM_INT(in_y0) + GP_FP_1_2 - y0);
+ GP_Coord i;
+
+ for (i = out_x0; i <= out_x1; i++) {
+ GP_Pixel p = GP_GetPixel_Raw_Clipped(context, i, out_y0);
+ p = GP_MixPixels(pixel, p, mix, context->pixel_type);
+ GP_PutPixel_Raw_Clipped(context, i, out_y0, p);
+ }
+ }
+
+ if (in_y1 != out_y1 && out_x0 != in_x1) {
+ uint8_t mix = GP_GammaToLinear(y1 - GP_FP_FROM_INT(in_y0) - GP_FP_1_2);
+ GP_Coord i;
+
+ for (i = out_x0; i <= out_x1; i++) {
+ GP_Pixel p = GP_GetPixel_Raw_Clipped(context, i, out_y1);
+ p = GP_MixPixels(pixel, p, mix, context->pixel_type);
+ GP_PutPixel_Raw_Clipped(context, i, out_y1, p);
+ }
}
- uint8_t perc;
- GP_Pixel p;
-
- perc = GP_GammaToLinear(GP_FP_1 - (GP_FP_FRAC(x0) + GP_FP_1 - GP_FP_FRAC(y0) + 2)/4);
- p = GP_GetPixel_Raw_Clipped(context, GP_FP_FLOOR(x0), GP_FP_FLOOR(y0));
- p = GP_MixPixels(pixel, p, perc, context->pixel_type);
- GP_PutPixel_Raw_Clipped(context, GP_FP_FLOOR(x0), GP_FP_FLOOR(y0), p);
-
- perc = GP_GammaToLinear((GP_FP_FRAC(x1) + GP_FP_1 - GP_FP_FRAC(y0) + 2)/4);
- p = GP_GetPixel_Raw_Clipped(context, GP_FP_CEIL(x1), GP_FP_FLOOR(y0));
- p = GP_MixPixels(pixel, p, perc, context->pixel_type);
- GP_PutPixel_Raw_Clipped(context, GP_FP_CEIL(x1), GP_FP_FLOOR(y0), p);
+ if (in_x0 != out_x0 && out_y0 != in_y1) {
+ uint8_t mix = GP_GammaToLinear(GP_FP_FROM_INT(in_x0) + GP_FP_1_2 - x0);
+ GP_Coord i;
+
+ for (i = out_y0; i <= out_y1; i++) {
+ GP_Pixel p = GP_GetPixel_Raw_Clipped(context, out_x0, i);
+ p = GP_MixPixels(pixel, p, mix, context->pixel_type);
+ GP_PutPixel_Raw_Clipped(context, out_x0, i, p);
+ }
+ }
- perc = GP_GammaToLinear((GP_FP_1 - GP_FP_FRAC(x0) + GP_FP_FRAC(y1) + 2)/4);
- p = GP_GetPixel_Raw_Clipped(context, GP_FP_FLOOR(x0), GP_FP_CEIL(y1));
- p = GP_MixPixels(pixel, p, perc, context->pixel_type);
- GP_PutPixel_Raw_Clipped(context, GP_FP_FLOOR(x0), GP_FP_CEIL(y1), p);
+ if (in_x1 != out_x1 && out_y0 != in_y1) {
+ uint8_t mix = GP_GammaToLinear(x1 - GP_FP_FROM_INT(in_x1) - GP_FP_1_2);
+ GP_Coord i;
- perc = GP_GammaToLinear((GP_FP_FRAC(x1) + GP_FP_FRAC(y1) + 2)/4);
- p = GP_GetPixel_Raw_Clipped(context, GP_FP_CEIL(x1), GP_FP_CEIL(y1));
- p = GP_MixPixels(pixel, p, perc, context->pixel_type);
- GP_PutPixel_Raw_Clipped(context, GP_FP_CEIL(x1), GP_FP_CEIL(y1), p);
+ for (i = out_y0; i <= out_y1; i++) {
+ GP_Pixel p = GP_GetPixel_Raw_Clipped(context, out_x1, i);
+ p = GP_MixPixels(pixel, p, mix, context->pixel_type);
+ GP_PutPixel_Raw_Clipped(context, out_x1, i, p);
+ }
+ }
+
+ //TODO four corner pixels!!!
}
void GP_FillRectXYWH_AA_Raw(GP_Context *context, GP_Coord x, GP_Coord y,
diff --git a/tests/SDL/aatest.c b/tests/SDL/aatest.c
index 247c553..6eba9a6 100644
--- a/tests/SDL/aatest.c
+++ b/tests/SDL/aatest.c
@@ -33,8 +33,8 @@
SDL_Surface *display = NULL;
GP_Context context;
-static GP_Coord x = 10<<8;
-static GP_Coord y = 10<<8;
+static GP_Coord x = 10 * GP_FP_1 + GP_FP_1_2;
+static GP_Coord y = 10 * GP_FP_1 + GP_FP_1_2;
SDL_UserEvent timer_event;
@@ -49,6 +49,9 @@ static void draw(void)
GP_Coord i;
for (i = 0; i < 24; i++) {
+ // GP_FillRect(ctx, (x>>8), (y + (10*i<<8) - 128)>>8,
+ // (x>>8) + 60, (y + ((10*i)<<8) + 64*i + 64 + 128)>>8, green_pixel);
+
GP_FillRect_AA(ctx, x, y + ((10*i)<<8),
x + (60<<8), y + ((10*i)<<8) + 64*i + 64, 0);
@@ -60,7 +63,7 @@ static void draw(void)
GP_FillRect_AA(ctx, x + (240<<8), y + ((10*i)<<8) + 192,
x + (300<<8), y + ((10*i)<<8) + 64*i + 256, 0);
- printf("--------------------------------------------------------n");
+ printf("%i --------------------------------------------------------n", i);
}
SDL_Flip(display);
@@ -133,7 +136,7 @@ int main(int argc, char **argv)
return 1;
}
- display = SDL_SetVideoMode(320, 240, display_bpp, SDL_SWSURFACE);
+ display = SDL_SetVideoMode(320, 320, display_bpp, SDL_SWSURFACE);
if (display == NULL) {
fprintf(stderr, "Could not open display: %sn", SDL_GetError());
goto fail;
-----------------------------------------------------------------------
Summary of changes:
include/core/GP_FixedPoint.h | 26 +++++--
libs/gfx/GP_RectAA.c | 153 ++++++++++++++++++++++++++----------------
tests/SDL/aatest.c | 11 ++-
3 files changed, 119 insertions(+), 71 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: a52536952b40f8337b4415fe265217c5976f2f77
by metan 03 Jan '12
by metan 03 Jan '12
03 Jan '12
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project gfxprim.git.
The branch, master has been updated
via a52536952b40f8337b4415fe265217c5976f2f77 (commit)
from 9f1c5605ccc309bc66b098c26590a3a1e35025b2 (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/a52536952b40f8337b4415fe265217c5976f…
commit a52536952b40f8337b4415fe265217c5976f2f77
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Tue Jan 3 21:09:12 2012 +0100
gfx: Fix Anti Aliased Rectangle rotations
Silly me I should use _Raw variants.
diff --git a/include/core/GP_GetPutPixel.h b/include/core/GP_GetPutPixel.h
index 0cd7661..671a16e 100644
--- a/include/core/GP_GetPutPixel.h
+++ b/include/core/GP_GetPutPixel.h
@@ -17,7 +17,7 @@
* Boston, MA 02110-1301 USA *
* *
* Copyright (C) 2011 Tomas Gavenciak <gavento(a)ucw.cz> *
- * Copyright (C) 2011 Cyril Hrubis <metan(a)ucw.cz> *
+ * Copyright (C) 2011-2012 Cyril Hrubis <metan(a)ucw.cz> *
* *
*****************************************************************************/
@@ -38,12 +38,13 @@
* GetPixel with context transformations and clipping.
* Returns 0 for clipped pixels or pixels outside bitmap.
*/
-GP_Pixel GP_GetPixel(const GP_Context *context, int x, int y);
+GP_Pixel GP_GetPixel(const GP_Context *context, GP_Coord x, GP_Coord y);
/*
* Version of GetPixel without transformations nor border checking.
*/
-static inline GP_Pixel GP_GetPixel_Raw(const GP_Context *context, int x, int y)
+static inline GP_Pixel GP_GetPixel_Raw(const GP_Context *context,
+ GP_Coord x, GP_Coord y)
{
GP_FN_RET_PER_BPP(GP_GetPixel_Raw, context->bpp, context->bit_endian,
context, x, y);
@@ -52,22 +53,44 @@ static inline GP_Pixel GP_GetPixel_Raw(const GP_Context *context, int x, int y)
}
/*
+ * Version of GetPixel without transformations and with border checking.
+ */
+static inline GP_Pixel GP_GetPixel_Raw_Clipped(const GP_Context *context,
+ GP_Coord x, GP_Coord y)
+{
+ if (GP_PIXEL_IS_CLIPPED(context, x, y))
+ return 0;
+
+ return GP_GetPixel_Raw(context, x, y);
+}
+
+/*
* PutPixel with context transformations and clipping.
* NOP for clipped pixels or pixels outside bitmap.
*/
-void GP_PutPixel(GP_Context *context, int x, int y, GP_Pixel p);
+void GP_PutPixel(GP_Context *context, GP_Coord x, GP_Coord y, GP_Pixel p);
/*
* Version of PutPixel without transformations nor border checking.
*/
-static inline void GP_PutPixel_Raw(GP_Context *context, int x, int y,
- GP_Pixel p)
+static inline void GP_PutPixel_Raw(GP_Context *context,
+ GP_Coord x, GP_Coord y, GP_Pixel p)
{
GP_FN_PER_BPP(GP_PutPixel_Raw, context->bpp, context->bit_endian,
context, x, y, p);
}
/*
+ * Version of PutPixel without transformation and with border checking.
+ */
+static inline void GP_PutPixel_Raw_Clipped(GP_Context *context,
+ GP_Coord x, GP_Coord y, GP_Pixel p)
+{
+ GP_FN_PER_BPP(GP_PutPixel_Raw_Clipped, context->bpp, context->bit_endian,
+ context, x, y, p);
+}
+
+/*
* Returns pixel offset.
*/
uint8_t GP_PixelAddrOffset(GP_Coord x, GP_PixelType pixel_type);
diff --git a/include/core/GP_Transform.h b/include/core/GP_Transform.h
index cc6e8b4..e903d69 100644
--- a/include/core/GP_Transform.h
+++ b/include/core/GP_Transform.h
@@ -28,6 +28,7 @@
#ifndef CORE_GP_TRANSFORM_H
#define CORE_GP_TRANSFORM_H
+#include "GP_Common.h"
#include "GP_FixedPoint.h"
/*
diff --git a/libs/core/GP_GetPutPixel.c b/libs/core/GP_GetPutPixel.c
index 6550275..83e4ff2 100644
--- a/libs/core/GP_GetPutPixel.c
+++ b/libs/core/GP_GetPutPixel.c
@@ -17,13 +17,14 @@
* Boston, MA 02110-1301 USA *
* *
* Copyright (C) 2011 Tomas Gavenciak <gavento(a)ucw.cz> *
+ * Copyright (C) 2012 Cyril Hrubis <metan(a)ucw.cz> *
* *
*****************************************************************************/
#include "GP_GetPutPixel.h"
#include "GP_Transform.h"
-GP_Pixel GP_GetPixel(const GP_Context *context, int x, int y)
+GP_Pixel GP_GetPixel(const GP_Context *context, GP_Coord x, GP_Coord y)
{
GP_TRANSFORM_POINT(context, x, y);
if (GP_PIXEL_IS_CLIPPED(context, x, y))
@@ -31,7 +32,7 @@ GP_Pixel GP_GetPixel(const GP_Context *context, int x, int y)
return GP_GetPixel_Raw(context, x, y);
}
-void GP_PutPixel(GP_Context *context, int x, int y, GP_Pixel p)
+void GP_PutPixel(GP_Context *context, GP_Coord x, GP_Coord y, GP_Pixel p)
{
GP_TRANSFORM_POINT(context, x, y);
if (!GP_PIXEL_IS_CLIPPED(context, x, y))
diff --git a/libs/gfx/GP_RectAA.c b/libs/gfx/GP_RectAA.c
index 4225fd0..66e24b6 100644
--- a/libs/gfx/GP_RectAA.c
+++ b/libs/gfx/GP_RectAA.c
@@ -53,7 +53,7 @@ void GP_FillRectXYXY_AA_Raw(GP_Context *context, GP_Coord x0, GP_Coord y0,
GP_Coord yi1 = GP_FP_FLOOR(y1);
if (xi1 >= xi0 && yi1 >= yi0)
- GP_FillRect(context, xi0, yi0, xi1, yi1, pixel);
+ GP_FillRect_Raw(context, xi0, yi0, xi1, yi1, pixel);
printf("%i %i %i %in", xi0, yi0, yi1, yi1);
@@ -67,54 +67,52 @@ void GP_FillRectXYXY_AA_Raw(GP_Context *context, GP_Coord x0, GP_Coord y0,
d_perc = GP_GammaToLinear(GP_FP_FRAC(y1));
for (i = GP_FP_CEIL(x0); i <= GP_FP_FLOOR(x1); i++) {
- GP_Pixel u = GP_GetPixel(context, i, GP_FP_FLOOR(y0));
- GP_Pixel d = GP_GetPixel(context, i, GP_FP_CEIL(y1));
+ GP_Pixel u = GP_GetPixel_Raw_Clipped(context, i, GP_FP_FLOOR(y0));
+ GP_Pixel d = GP_GetPixel_Raw_Clipped(context, i, GP_FP_CEIL(y1));
u = GP_MixPixels(pixel, u, u_perc, context->pixel_type);
d = GP_MixPixels(pixel, d, d_perc, context->pixel_type);
- GP_PutPixel(context, i, GP_FP_FLOOR(y0), u);
- GP_PutPixel(context, i, GP_FP_CEIL(y1), d);
+ GP_PutPixel_Raw_Clipped(context, i, GP_FP_FLOOR(y0), u);
+ GP_PutPixel_Raw_Clipped(context, i, GP_FP_CEIL(y1), d);
}
u_perc = GP_GammaToLinear(GP_FP_1 - GP_FP_FRAC(x0));
d_perc = GP_GammaToLinear(GP_FP_FRAC(x1));
for (i = GP_FP_CEIL(y0); i <= GP_FP_FLOOR(y1); i++) {
- GP_Pixel u = GP_GetPixel(context, GP_FP_FLOOR(x0), i);
- GP_Pixel d = GP_GetPixel(context, GP_FP_CEIL(x1), i);
+ GP_Pixel u = GP_GetPixel_Raw_Clipped(context, GP_FP_FLOOR(x0), i);
+ GP_Pixel d = GP_GetPixel_Raw_Clipped(context, GP_FP_CEIL(x1), i);
u = GP_MixPixels(pixel, u, u_perc, context->pixel_type);
d = GP_MixPixels(pixel, d, d_perc, context->pixel_type);
- GP_PutPixel(context, GP_FP_FLOOR(x0), i, u);
- GP_PutPixel(context, GP_FP_CEIL(x1), i, d);
+ GP_PutPixel_Raw_Clipped(context, GP_FP_FLOOR(x0), i, u);
+ GP_PutPixel_Raw_Clipped(context, GP_FP_CEIL(x1), i, d);
}
- return;
-
uint8_t perc;
GP_Pixel p;
- perc = GP_GammaToLinear((GP_FP_FRAC(x0) + GP_FP_FRAC(y0) + 1)/2);
- p = GP_GetPixel(context, GP_FP_FLOOR(x0), GP_FP_FLOOR(y0));
+ perc = GP_GammaToLinear(GP_FP_1 - (GP_FP_FRAC(x0) + GP_FP_1 - GP_FP_FRAC(y0) + 2)/4);
+ p = GP_GetPixel_Raw_Clipped(context, GP_FP_FLOOR(x0), GP_FP_FLOOR(y0));
p = GP_MixPixels(pixel, p, perc, context->pixel_type);
- GP_PutPixel(context, GP_FP_FLOOR(x0), GP_FP_FLOOR(y0), p);
+ GP_PutPixel_Raw_Clipped(context, GP_FP_FLOOR(x0), GP_FP_FLOOR(y0), p);
- perc = GP_GammaToLinear((GP_FP_FRAC(x1) + GP_FP_FRAC(y0) + 1)/2);
- p = GP_GetPixel(context, (x1>>8) + 1, (y0>>8) - 1);
+ perc = GP_GammaToLinear((GP_FP_FRAC(x1) + GP_FP_1 - GP_FP_FRAC(y0) + 2)/4);
+ p = GP_GetPixel_Raw_Clipped(context, GP_FP_CEIL(x1), GP_FP_FLOOR(y0));
p = GP_MixPixels(pixel, p, perc, context->pixel_type);
- GP_PutPixel(context, (x1>>8) + 1, (y0>>8) - 1, p);
+ GP_PutPixel_Raw_Clipped(context, GP_FP_CEIL(x1), GP_FP_FLOOR(y0), p);
- perc = GP_GammaToLinear((GP_FP_FRAC(x0) + GP_FP_FRAC(y1) + 1)/2);
- p = GP_GetPixel(context, (x0>>8) - 1, (y1>>8) + 1);
+ perc = GP_GammaToLinear((GP_FP_1 - GP_FP_FRAC(x0) + GP_FP_FRAC(y1) + 2)/4);
+ p = GP_GetPixel_Raw_Clipped(context, GP_FP_FLOOR(x0), GP_FP_CEIL(y1));
p = GP_MixPixels(pixel, p, perc, context->pixel_type);
- GP_PutPixel(context, (x0>>8) - 1, (y1>>8) + 1, p);
+ GP_PutPixel_Raw_Clipped(context, GP_FP_FLOOR(x0), GP_FP_CEIL(y1), p);
- perc = GP_GammaToLinear((GP_FP_FRAC(x1) + GP_FP_FRAC(y1) + 1)/2);
- p = GP_GetPixel(context, (x1>>8) + 1, (y1>>8) + 1);
+ perc = GP_GammaToLinear((GP_FP_FRAC(x1) + GP_FP_FRAC(y1) + 2)/4);
+ p = GP_GetPixel_Raw_Clipped(context, GP_FP_CEIL(x1), GP_FP_CEIL(y1));
p = GP_MixPixels(pixel, p, perc, context->pixel_type);
- GP_PutPixel(context, (x1>>8) + 1, (y1>>8) + 1, p);
+ GP_PutPixel_Raw_Clipped(context, GP_FP_CEIL(x1), GP_FP_CEIL(y1), p);
}
void GP_FillRectXYWH_AA_Raw(GP_Context *context, GP_Coord x, GP_Coord y,
@@ -135,7 +133,7 @@ void GP_FillRectXYXY_AA(GP_Context *context, GP_Coord x0, GP_Coord y0,
GP_TRANSFORM_POINT_FP(context, x0, y0);
GP_TRANSFORM_POINT_FP(context, x1, y1);
- GP_FillRect_AA_Raw(context, x0, y0, x1, y1, pixel);
+ GP_FillRectXYXY_AA_Raw(context, x0, y0, x1, y1, pixel);
}
void GP_FillRectXYWH_AA(GP_Context *context, GP_Coord x, GP_Coord y,
-----------------------------------------------------------------------
Summary of changes:
include/core/GP_GetPutPixel.h | 35 +++++++++++++++++++++++++-----
include/core/GP_Transform.h | 1 +
libs/core/GP_GetPutPixel.c | 5 ++-
libs/gfx/GP_RectAA.c | 46 +++++++++++++++++++---------------------
4 files changed, 55 insertions(+), 32 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: 9f1c5605ccc309bc66b098c26590a3a1e35025b2
by metan 03 Jan '12
by metan 03 Jan '12
03 Jan '12
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project gfxprim.git.
The branch, master has been updated
via 9f1c5605ccc309bc66b098c26590a3a1e35025b2 (commit)
from 0850c45f543489686dc6a2984cf104ed2e89b4aa (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/9f1c5605ccc309bc66b098c26590a3a1e350…
commit 9f1c5605ccc309bc66b098c26590a3a1e35025b2
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Tue Jan 3 19:43:28 2012 +0100
gfx: Working on Anti Aliased rectangles
Nearly done
* special cases not yet hanlded
* corners are not drawn correctly
diff --git a/include/core/GP_FixedPoint.h b/include/core/GP_FixedPoint.h
new file mode 100644
index 0000000..baf4ed4
--- /dev/null
+++ b/include/core/GP_FixedPoint.h
@@ -0,0 +1,104 @@
+/*****************************************************************************
+ * This file is part of gfxprim library. *
+ * *
+ * Gfxprim is free software; you can redistribute it and/or *
+ * modify it under the terms of the GNU Lesser General Public *
+ * License as published by the Free Software Foundation; either *
+ * version 2.1 of the License, or (at your option) any later version. *
+ * *
+ * Gfxprim is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with gfxprim; if not, write to the Free Software *
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
+ * Boston, MA 02110-1301 USA *
+ * *
+ * Copyright (C) 2009-2012 Cyril Hrubis <metan(a)ucw.cz> *
+ * *
+ *****************************************************************************/
+
+/*
+
+ Macros for fixed point arithmetic.
+
+ We use 8 bits for fractional part for coordinates and sizes for Anti Aliased
+ primitives.
+
+ */
+
+#ifndef CORE_GP_FIXED_POINT_H
+#define CORE_GP_FIXED_POINT_H
+
+#include <stdint.h>
+
+typedef uint8_t GP_FP_Frac;
+
+/*
+ * Number of bits used for fractional part.
+ */
+#define GP_FP_FRAC_BITS 8
+
+/*
+ * One
+ */
+#define GP_FP_1 (1<<GP_FP_FRAC_BITS)
+
+/*
+ * One Half
+ */
+#define GP_FP_1_2 ((1<<(GP_FP_FRAC_BITS - 1))
+
+/*
+ * Fraction part bitmask.
+ */
+#define GP_FP_FRAC_MASK ((1<<GP_FP_FRAC_BITS)-1)
+
+/*
+ * Addition.
+ */
+#define GP_FP_ADD(a, b) ((a)+(b))
+
+/*
+ * Substraction.
+ */
+#define GP_FP_SUB(a, b) ((a)-(b))
+
+/*
+ * Floor.
+ */
+#define GP_FP_FLOOR(a) ((a)>>GP_FP_FRAC_BITS)
+
+/*
+ * Ceilling.
+ */
+#define GP_FP_CEIL(a) (((a)>>GP_FP_FRAC_BITS) + !!(GP_FP_FRAC(a)))
+
+/*
+ * Rounding.
+ */
+#define GP_FP_ROUND(a) (((a) + GP_FP_1_2))>>GP_FP_FRAC_BITS
+
+/*
+ * Integer part.
+ */
+#define GP_FP_INT(a) GP_FP_FLOOR(a)
+
+/*
+ * Fractional part.
+ */
+#define GP_FP_FRAC(a) ((a) & GP_FP_FRAC_MASK)
+
+/*
+ * Returns an float.
+ */
+#define GP_FP_TO_FLOAT(a) (((float)(a))/((float)GP_FP_1))
+
+/*
+ * Returns fixed point from integer.
+ */
+#define GP_FP_FROM_INT(a) ((a)<<GP_FP_FRAC_BITS)
+
+#endif /* CORE_GP_FIXED_POINT_H */
diff --git a/include/core/GP_Transform.h b/include/core/GP_Transform.h
index 9ea5eec..cc6e8b4 100644
--- a/include/core/GP_Transform.h
+++ b/include/core/GP_Transform.h
@@ -19,26 +19,41 @@
* 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-2012 Cyril Hrubis <metan(a)ucw.cz> *
* *
* Copyright (C) 2011 Tomas Gavenciak <gavento(a)ucw.cz> *
* *
*****************************************************************************/
-#ifndef GP_TRANSFORM_H
-#define GP_TRANSFORM_H
+#ifndef CORE_GP_TRANSFORM_H
+#define CORE_GP_TRANSFORM_H
+
+#include "GP_FixedPoint.h"
/*
* Flip a coordinate within context according to context transformation.
*/
-#define GP_TRANSFORM_X(context, x) do { - if ((context)->x_swap) - x = (context)->w - x - 1; +#define GP_TRANSFORM_X(context, x) do { + if ((context)->x_swap) + x = (context)->w - x - 1; +} while (0)
+
+#define GP_TRANSFORM_Y(context, y) do { + if ((context)->y_swap) + y = (context)->h - y - 1; } while (0)
-#define GP_TRANSFORM_Y(context, y) do { - if ((context)->y_swap) - y = (context)->h - y - 1; +/*
+ * Fixed point variants.
+ */
+#define GP_TRANSFORM_X_FP(context, x) do { + if ((context)->x_swap) + x = GP_FP_FROM_INT((context)->w - 1) - x; +} while (0)
+
+#define GP_TRANSFORM_Y_FP(context, y) do { + if ((context)->y_swap) + y = GP_FP_FROM_INT((context)->h - 1) - y; } while (0)
/*
@@ -59,6 +74,12 @@
GP_TRANSFORM_Y(context, y); } while (0)
+#define GP_TRANSFORM_POINT_FP(context, x, y) do { + GP_TRANSFORM_SWAP(context, x, y); + GP_TRANSFORM_X_FP(context, x); + GP_TRANSFORM_Y_FP(context, y); +} while (0)
+
/*
* Transform "user"-coordinates to "real"-coordinates of a rectangle corner
* according to context transformation. Corner with min-coordinates is
@@ -68,12 +89,23 @@
#define GP_TRANSFORM_RECT(context, x, y, w, h) do { GP_TRANSFORM_SWAP(context, x, y); GP_TRANSFORM_SWAP(context, w, h); - if ((context)->x_swap) { + + if ((context)->x_swap) x = (context)->w - x - w; - } - if ((context)->y_swap) { + + if ((context)->y_swap) y = (context)->h - y - h; - } +} while (0)
+
+#define GP_TRANSFORM_RECT_FP(context, x, y, w, h) do { + GP_TRANSFORM_SWAP(context, x, y); + GP_TRANSFORM_SWAP(context, w, h); + + if ((context)->x_swap) + x = GP_FP_FROM_INT((context)->w) - x - w; + + if ((context)->y_swap) + y = GP_FP_FROM_INT((context)->h) - y - h; } while (0)
/*
@@ -98,4 +130,4 @@
GP_TRANSFORM_SWAP(context, x, y); } while (0)
-#endif /* GP_TRANSFORM_H */
+#endif /* CORE_GP_TRANSFORM_H */
diff --git a/libs/gfx/GP_RectAA.c b/libs/gfx/GP_RectAA.c
index 0939a7f..4225fd0 100644
--- a/libs/gfx/GP_RectAA.c
+++ b/libs/gfx/GP_RectAA.c
@@ -23,6 +23,7 @@
#include "core/GP_Transform.h"
#include "core/GP_GetPutPixel.h"
#include "core/GP_MixPixels.h"
+#include "core/GP_FixedPoint.h"
#include "core/GP_GammaCorrection.h"
#include "GP_Rect.h"
#include "GP_RectAA.h"
@@ -38,62 +39,79 @@ void GP_FillRectXYXY_AA_Raw(GP_Context *context, GP_Coord x0, GP_Coord y0,
if (y0 > y1)
GP_SWAP(y0, y1);
- /* Draw the full part of the rect */
- GP_FillRect(context, x0>>8, y0>>8, x1>>8, y1>>8, pixel);
+ GP_Size w = x1 - x0;
+ GP_Size h = y1 - y0;
+
+ printf("W = %f, H = %f, X = %f, Y = %fn",
+ GP_FP_TO_FLOAT(w), GP_FP_TO_FLOAT(h),
+ GP_FP_TO_FLOAT(x0), GP_FP_TO_FLOAT(y0));
+
+ /* This are integer coordinates of the "inner" rectangle */
+ GP_Coord xi0 = GP_FP_CEIL(x0);
+ GP_Coord yi0 = GP_FP_CEIL(y0);
+ GP_Coord xi1 = GP_FP_FLOOR(x1);
+ GP_Coord yi1 = GP_FP_FLOOR(y1);
+
+ if (xi1 >= xi0 && yi1 >= yi0)
+ GP_FillRect(context, xi0, yi0, xi1, yi1, pixel);
+ printf("%i %i %i %in", xi0, yi0, yi1, yi1);
+
/* Draw the "frame" around */
GP_Coord i;
uint8_t u_perc;
uint8_t d_perc;
- d_perc = GP_GammaToLinear(x0%8);
- u_perc = GP_GammaToLinear(x1%8);
+ u_perc = GP_GammaToLinear(GP_FP_1 - GP_FP_FRAC(y0));
+ d_perc = GP_GammaToLinear(GP_FP_FRAC(y1));
- for (i = x0>>8; i <= x1>>8; i++) {
- GP_Pixel u = GP_GetPixel(context, i, (y0>>8) - 1);
- GP_Pixel d = GP_GetPixel(context, i, (y1>>8) + 1);
+ for (i = GP_FP_CEIL(x0); i <= GP_FP_FLOOR(x1); i++) {
+ GP_Pixel u = GP_GetPixel(context, i, GP_FP_FLOOR(y0));
+ GP_Pixel d = GP_GetPixel(context, i, GP_FP_CEIL(y1));
u = GP_MixPixels(pixel, u, u_perc, context->pixel_type);
d = GP_MixPixels(pixel, d, d_perc, context->pixel_type);
- GP_PutPixel(context, i, (y0>>8) - 1, u);
- GP_PutPixel(context, i, (y1>>8) + 1, d);
+ GP_PutPixel(context, i, GP_FP_FLOOR(y0), u);
+ GP_PutPixel(context, i, GP_FP_CEIL(y1), d);
}
+
+ u_perc = GP_GammaToLinear(GP_FP_1 - GP_FP_FRAC(x0));
+ d_perc = GP_GammaToLinear(GP_FP_FRAC(x1));
- d_perc = GP_GammaToLinear(y0%8);
- u_perc = GP_GammaToLinear(y1%8);
-
- for (i = y0>>8; i <= y1>>8; i++) {
- GP_Pixel u = GP_GetPixel(context, (x0>>8) - 1, i);
- GP_Pixel d = GP_GetPixel(context, (x1>>8) + 1, i);
+ for (i = GP_FP_CEIL(y0); i <= GP_FP_FLOOR(y1); i++) {
+ GP_Pixel u = GP_GetPixel(context, GP_FP_FLOOR(x0), i);
+ GP_Pixel d = GP_GetPixel(context, GP_FP_CEIL(x1), i);
u = GP_MixPixels(pixel, u, u_perc, context->pixel_type);
d = GP_MixPixels(pixel, d, d_perc, context->pixel_type);
- GP_PutPixel(context, (x0>>8) - 1, i, u);
- GP_PutPixel(context, (x1>>8) + 1, i, d);
+ GP_PutPixel(context, GP_FP_FLOOR(x0), i, u);
+ GP_PutPixel(context, GP_FP_CEIL(x1), i, d);
}
+ return;
+
uint8_t perc;
GP_Pixel p;
- perc = GP_GammaToLinear((x0%8+y0%8)/2);
- p = GP_GetPixel(context, (x0>>8) - 1, (y0>>8) - 1);
+ perc = GP_GammaToLinear((GP_FP_FRAC(x0) + GP_FP_FRAC(y0) + 1)/2);
+ p = GP_GetPixel(context, GP_FP_FLOOR(x0), GP_FP_FLOOR(y0));
p = GP_MixPixels(pixel, p, perc, context->pixel_type);
- GP_PutPixel(context, (x0>>8) - 1, (y0>>8) - 1, p);
+ GP_PutPixel(context, GP_FP_FLOOR(x0), GP_FP_FLOOR(y0), p);
- perc = GP_GammaToLinear((x1%8+y0%8)/2);
+ perc = GP_GammaToLinear((GP_FP_FRAC(x1) + GP_FP_FRAC(y0) + 1)/2);
p = GP_GetPixel(context, (x1>>8) + 1, (y0>>8) - 1);
p = GP_MixPixels(pixel, p, perc, context->pixel_type);
GP_PutPixel(context, (x1>>8) + 1, (y0>>8) - 1, p);
- perc = GP_GammaToLinear((x0%8+y1%8)/2);
+ perc = GP_GammaToLinear((GP_FP_FRAC(x0) + GP_FP_FRAC(y1) + 1)/2);
p = GP_GetPixel(context, (x0>>8) - 1, (y1>>8) + 1);
p = GP_MixPixels(pixel, p, perc, context->pixel_type);
GP_PutPixel(context, (x0>>8) - 1, (y1>>8) + 1, p);
- perc = GP_GammaToLinear((x1%8+y1%8)/2);
+ perc = GP_GammaToLinear((GP_FP_FRAC(x1) + GP_FP_FRAC(y1) + 1)/2);
p = GP_GetPixel(context, (x1>>8) + 1, (y1>>8) + 1);
p = GP_MixPixels(pixel, p, perc, context->pixel_type);
GP_PutPixel(context, (x1>>8) + 1, (y1>>8) + 1, p);
@@ -105,7 +123,8 @@ void GP_FillRectXYWH_AA_Raw(GP_Context *context, GP_Coord x, GP_Coord y,
if (w == 0 || h == 0)
return;
- GP_FillRectXYXY_AA_Raw(context, x, y, x + w - 1, y + h - 1, pixel);
+ GP_FillRectXYXY_AA_Raw(context, x, y,
+ x + w - GP_FP_1, y + h - GP_FP_1, pixel);
}
void GP_FillRectXYXY_AA(GP_Context *context, GP_Coord x0, GP_Coord y0,
@@ -113,8 +132,8 @@ void GP_FillRectXYXY_AA(GP_Context *context, GP_Coord x0, GP_Coord y0,
{
GP_CHECK_CONTEXT(context);
- GP_TRANSFORM_POINT(context, x0, y0);
- GP_TRANSFORM_POINT(context, x1, y1);
+ GP_TRANSFORM_POINT_FP(context, x0, y0);
+ GP_TRANSFORM_POINT_FP(context, x1, y1);
GP_FillRect_AA_Raw(context, x0, y0, x1, y1, pixel);
}
@@ -125,5 +144,6 @@ void GP_FillRectXYWH_AA(GP_Context *context, GP_Coord x, GP_Coord y,
if (w == 0 || h == 0)
return;
- GP_FillRectXYXY_AA(context, x, y, x + w - 1, y + h - 1, pixel);
+ GP_FillRectXYXY_AA(context, x, y,
+ x + w - GP_FP_1, y + h - GP_FP_1, pixel);
}
diff --git a/tests/SDL/Makefile b/tests/SDL/Makefile
index 123889b..8520abb 100644
--- a/tests/SDL/Makefile
+++ b/tests/SDL/Makefile
@@ -6,7 +6,8 @@ INCLUDE=core gfx SDL backends
LDLIBS+=-lGP -L$(TOPDIR)/build/ -lGP_SDL -lSDL
APPS=pixeltest fileview fonttest linetest randomshapetest shapetest sierpinsky- symbolstest textaligntest trianglefps input blittest subcontext showimage
+ symbolstest textaligntest trianglefps input blittest subcontext showimage+ aatest
include $(TOPDIR)/include.mk
include $(TOPDIR)/app.mk
diff --git a/tests/SDL/aatest.c b/tests/SDL/aatest.c
new file mode 100644
index 0000000..247c553
--- /dev/null
+++ b/tests/SDL/aatest.c
@@ -0,0 +1,165 @@
+/*****************************************************************************
+ * This file is part of gfxprim library. *
+ * *
+ * Gfxprim is free software; you can redistribute it and/or *
+ * modify it under the terms of the GNU Lesser General Public *
+ * License as published by the Free Software Foundation; either *
+ * version 2.1 of the License, or (at your option) any later version. *
+ * *
+ * Gfxprim is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with gfxprim; if not, write to the Free Software *
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
+ * Boston, MA 02110-1301 USA *
+ * *
+ * Copyright (C) 2009-2010 Jiri "BlueBear" Dluhos *
+ * <jiri.bluebear.dluhos(a)gmail.com> *
+ * *
+ * Copyright (C) 2009-2012 Cyril Hrubis <metan(a)ucw.cz> *
+ * *
+ *****************************************************************************/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <SDL/SDL.h>
+
+#include "GP.h"
+#include "GP_SDL.h"
+
+SDL_Surface *display = NULL;
+GP_Context context;
+
+static GP_Coord x = 10<<8;
+static GP_Coord y = 10<<8;
+
+SDL_UserEvent timer_event;
+
+GP_Pixel red_pixel, green_pixel, blue_pixel, white_pixel;
+
+static void draw(void)
+{
+ GP_Context *ctx = &context;
+
+ GP_Fill(ctx, white_pixel);
+
+ GP_Coord i;
+
+ for (i = 0; i < 24; i++) {
+ GP_FillRect_AA(ctx, x, y + ((10*i)<<8),
+ x + (60<<8), y + ((10*i)<<8) + 64*i + 64, 0);
+
+ GP_FillRect_AA(ctx, x + (80<<8), y + ((10*i)<<8) + 64,
+ x + (140<<8), y + ((10*i)<<8) + 64*i + 128, 0);
+
+ GP_FillRect_AA(ctx, x + (160<<8), y + ((10*i)<<8) + 128,
+ x + (220<<8), y + ((10*i)<<8) + 64*i + 192, 0);
+
+ GP_FillRect_AA(ctx, x + (240<<8), y + ((10*i)<<8) + 192,
+ x + (300<<8), y + ((10*i)<<8) + 64*i + 256, 0);
+ printf("--------------------------------------------------------n");
+ }
+
+ SDL_Flip(display);
+}
+
+void event_loop(void)
+{
+ SDL_Event event;
+
+ while (SDL_WaitEvent(&event) > 0) {
+ switch (event.type) {
+ case SDL_KEYDOWN:
+ switch (event.key.keysym.sym) {
+ case SDLK_DOWN:
+ y += 64;
+ draw();
+ break;
+ case SDLK_UP:
+ y -= 64;
+ draw();
+ break;
+ case SDLK_LEFT:
+ x -= 64;
+ draw();
+ break;
+ case SDLK_RIGHT:
+ x += 64;
+ draw();
+ break;
+ case SDLK_x:
+ context.x_swap = !context.x_swap;
+ draw();
+ break;
+ case SDLK_y:
+ context.y_swap = !context.y_swap;
+ draw();
+ break;
+ case SDLK_r:
+ context.axes_swap = !context.axes_swap;
+ draw();
+ break;
+ case SDLK_ESCAPE:
+ case SDLK_q:
+ return;
+ default:
+ break;
+ }
+ break;
+ case SDL_QUIT:
+ return;
+ }
+ }
+}
+
+int main(int argc, char **argv)
+{
+ int display_bpp = 0;
+
+ int i;
+ for (i = 1; i < argc; i++) {
+ if (strcmp(argv[i], "-16") == 0) {
+ display_bpp = 16;
+ } else if (strcmp(argv[i], "-24") == 0) {
+ display_bpp = 24;
+ }
+ }
+
+ if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) != 0) {
+ fprintf(stderr, "Could not initialize SDL: %sn", SDL_GetError());
+ return 1;
+ }
+
+ display = SDL_SetVideoMode(320, 240, display_bpp, SDL_SWSURFACE);
+ if (display == NULL) {
+ fprintf(stderr, "Could not open display: %sn", SDL_GetError());
+ goto fail;
+ }
+
+
+ printf("Display surface properties:n");
+ printf(" width: %4d, height: %4d, pitch: %4dn",
+ display->w, display->h, display->pitch);
+ printf(" bits per pixel: %2d, bytes per pixel: %2dn",
+ display->format->BitsPerPixel, display->format->BytesPerPixel);
+
+ GP_SDL_ContextFromSurface(&context, display);
+
+ red_pixel = GP_ColorToContextPixel(GP_COL_RED, &context);
+ green_pixel = GP_ColorToContextPixel(GP_COL_GREEN, &context);
+ blue_pixel = GP_ColorToContextPixel(GP_COL_BLUE, &context);
+ white_pixel = GP_ColorToContextPixel(GP_COL_WHITE, &context);
+
+ draw();
+
+ event_loop();
+ SDL_Quit();
+ return 0;
+
+fail:
+ SDL_Quit();
+ return 1;
+}
-----------------------------------------------------------------------
Summary of changes:
.../core/{GP_GammaCorrection.h => GP_FixedPoint.h} | 83 +++++++++++--
include/core/GP_Transform.h | 60 +++++++--
libs/gfx/GP_RectAA.c | 74 +++++++----
tests/SDL/Makefile | 3 +-
tests/SDL/{pixeltest.c => aatest.c} | 126 ++++++++++----------
5 files changed, 226 insertions(+), 120 deletions(-)
copy include/core/{GP_GammaCorrection.h => GP_FixedPoint.h} (58%)
copy tests/SDL/{pixeltest.c => aatest.c} (66%)
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: 0850c45f543489686dc6a2984cf104ed2e89b4aa
by metan 03 Jan '12
by metan 03 Jan '12
03 Jan '12
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project gfxprim.git.
The branch, master has been updated
via 0850c45f543489686dc6a2984cf104ed2e89b4aa (commit)
via 39de4836f42404f669d76cf0ebd759a0a32f41b9 (commit)
via 261533840975611674984ee1e3a8ea2b83085dae (commit)
from 1bac6fdd5618b074d38c9f7d4da6e867b302ba16 (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/0850c45f543489686dc6a2984cf104ed2e89…
commit 0850c45f543489686dc6a2984cf104ed2e89b4aa
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Tue Jan 3 01:30:31 2012 +0100
gfx: First attempt on Anti Aliased rectangle.
diff --git a/include/gfx/GP_Gfx.h b/include/core/GP_GammaCorrection.h
similarity index 66%
copy from include/gfx/GP_Gfx.h
copy to include/core/GP_GammaCorrection.h
index 5e54131..d36b1a9 100644
--- a/include/gfx/GP_Gfx.h
+++ b/include/core/GP_GammaCorrection.h
@@ -16,39 +16,32 @@
* 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> *
+ * Copyright (C) 2009-2012 Cyril Hrubis <metan(a)ucw.cz> *
* *
*****************************************************************************/
/*
- This is a main header for gfx part.
+ Gamma correction.
+
+ */
+
+#ifndef CORE_GP_GAMMA_CORRECTION_H
+#define CORE_GP_GAMMA_CORRECTION_H
+#include <stdint.h>
+#include <math.h>
+
+#define GP_GAMMA 2.2
+
+/*
+ * Coverts linear 0 255 value into 0 255 gama value.
+ *
+ * (this is used for Anti Aliased gfx primitives.
*/
+static inline uint8_t GP_GammaToLinear(uint8_t val)
+{
+ return pow(1.00 * val/255, 1/GP_GAMMA) * 255 + 0.5;
+}
-#ifndef GP_GFX_H
-#define GP_GFX_H
-
-/* basic definitions and structures */
-#include "core/GP_Context.h"
-#include "core/GP_GetPutPixel.h"
-#include "core/GP_WritePixel.h"
-
-/* public drawing API */
-#include "GP_Fill.h"
-#include "GP_HLine.h"
-#include "GP_VLine.h"
-#include "GP_Line.h"
-#include "GP_Rect.h"
-#include "GP_Triangle.h"
-#include "GP_Tetragon.h"
-#include "GP_Circle.h"
-#include "GP_Ellipse.h"
-#include "GP_Arc.h"
-#include "GP_Polygon.h"
-#include "GP_Symbol.h"
-
-#endif /* GP_GFX_H */
+#endif /* CORE_GP_GAMMA_CORRECTION_H */
diff --git a/include/gfx/GP_Gfx.h b/include/gfx/GP_Gfx.h
index 5e54131..6503952 100644
--- a/include/gfx/GP_Gfx.h
+++ b/include/gfx/GP_Gfx.h
@@ -51,4 +51,6 @@
#include "GP_Polygon.h"
#include "GP_Symbol.h"
+#include "GP_RectAA.h"
+
#endif /* GP_GFX_H */
diff --git a/include/gfx/GP_Gfx.h b/include/gfx/GP_RectAA.h
similarity index 56%
copy from include/gfx/GP_Gfx.h
copy to include/gfx/GP_RectAA.h
index 5e54131..fc6d9e9 100644
--- a/include/gfx/GP_Gfx.h
+++ b/include/gfx/GP_RectAA.h
@@ -16,39 +16,41 @@
* 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> *
+ * Copyright (C) 2009-2012 Cyril Hrubis <metan(a)ucw.cz> *
* *
*****************************************************************************/
-/*
+#ifndef GFX_GP_RECT_AA_H
+#define GFX_GP_RECT_AA_H
+
+#include "core/GP_Context.h"
- This is a main header for gfx part.
+/* Filled Rectangle */
- */
+void GP_FillRectXYXY_AA(GP_Context *context, GP_Coord x0, GP_Coord y0,
+ GP_Coord x1, GP_Coord y1, GP_Pixel pixel);
-#ifndef GP_GFX_H
-#define GP_GFX_H
+void GP_FillRectXYXY_AA_Raw(GP_Context *context, GP_Coord x0, GP_Coord y0,
+ GP_Coord x1, GP_Coord y1, GP_Pixel pixel);
-/* basic definitions and structures */
-#include "core/GP_Context.h"
-#include "core/GP_GetPutPixel.h"
-#include "core/GP_WritePixel.h"
-
-/* public drawing API */
-#include "GP_Fill.h"
-#include "GP_HLine.h"
-#include "GP_VLine.h"
-#include "GP_Line.h"
-#include "GP_Rect.h"
-#include "GP_Triangle.h"
-#include "GP_Tetragon.h"
-#include "GP_Circle.h"
-#include "GP_Ellipse.h"
-#include "GP_Arc.h"
-#include "GP_Polygon.h"
-#include "GP_Symbol.h"
-
-#endif /* GP_GFX_H */
+void GP_FillRectXYWH_AA(GP_Context *context, GP_Coord x, GP_Coord y,
+ GP_Size w, GP_Size h, GP_Pixel pixel);
+
+void GP_FillRectXYWH_AA_Raw(GP_Context *context, GP_Coord x, GP_Coord y,
+ GP_Size w, GP_Size h, GP_Pixel pixel);
+
+/* The XYXY argument set is the default */
+static inline void GP_FillRect_AA(GP_Context *context, GP_Coord x0, GP_Coord y0,
+ GP_Coord x1, GP_Coord y1, GP_Pixel pixel)
+{
+ GP_FillRectXYXY_AA(context, x0, y0, x1, y1, pixel);
+}
+
+static inline void GP_FillRect_AA_Raw(GP_Context *context,
+ GP_Coord x0, GP_Coord y0,
+ GP_Coord x1, GP_Coord y1, GP_Pixel pixel)
+{
+ GP_FillRectXYXY_AA_Raw(context, x0, y0, x1, y1, pixel);
+}
+
+#endif /* GFX_GP_RECT_AA_H */
diff --git a/libs/gfx/GP_RectAA.c b/libs/gfx/GP_RectAA.c
new file mode 100644
index 0000000..0939a7f
--- /dev/null
+++ b/libs/gfx/GP_RectAA.c
@@ -0,0 +1,129 @@
+/*****************************************************************************
+ * This file is part of gfxprim library. *
+ * *
+ * Gfxprim is free software; you can redistribute it and/or *
+ * modify it under the terms of the GNU Lesser General Public *
+ * License as published by the Free Software Foundation; either *
+ * version 2.1 of the License, or (at your option) any later version. *
+ * *
+ * Gfxprim is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with gfxprim; if not, write to the Free Software *
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
+ * Boston, MA 02110-1301 USA *
+ * *
+ * Copyright (C) 2009-2012 Cyril Hrubis <metan(a)ucw.cz> *
+ * *
+ *****************************************************************************/
+
+#include "core/GP_Transform.h"
+#include "core/GP_GetPutPixel.h"
+#include "core/GP_MixPixels.h"
+#include "core/GP_GammaCorrection.h"
+#include "GP_Rect.h"
+#include "GP_RectAA.h"
+
+void GP_FillRectXYXY_AA_Raw(GP_Context *context, GP_Coord x0, GP_Coord y0,
+ GP_Coord x1, GP_Coord y1, GP_Pixel pixel)
+{
+ GP_CHECK_CONTEXT(context);
+
+ if (x0 > x1)
+ GP_SWAP(x0, x1);
+
+ if (y0 > y1)
+ GP_SWAP(y0, y1);
+
+ /* Draw the full part of the rect */
+ GP_FillRect(context, x0>>8, y0>>8, x1>>8, y1>>8, pixel);
+
+ /* Draw the "frame" around */
+ GP_Coord i;
+
+ uint8_t u_perc;
+ uint8_t d_perc;
+
+ d_perc = GP_GammaToLinear(x0%8);
+ u_perc = GP_GammaToLinear(x1%8);
+
+ for (i = x0>>8; i <= x1>>8; i++) {
+ GP_Pixel u = GP_GetPixel(context, i, (y0>>8) - 1);
+ GP_Pixel d = GP_GetPixel(context, i, (y1>>8) + 1);
+
+ u = GP_MixPixels(pixel, u, u_perc, context->pixel_type);
+ d = GP_MixPixels(pixel, d, d_perc, context->pixel_type);
+
+ GP_PutPixel(context, i, (y0>>8) - 1, u);
+ GP_PutPixel(context, i, (y1>>8) + 1, d);
+ }
+
+ d_perc = GP_GammaToLinear(y0%8);
+ u_perc = GP_GammaToLinear(y1%8);
+
+ for (i = y0>>8; i <= y1>>8; i++) {
+ GP_Pixel u = GP_GetPixel(context, (x0>>8) - 1, i);
+ GP_Pixel d = GP_GetPixel(context, (x1>>8) + 1, i);
+
+ u = GP_MixPixels(pixel, u, u_perc, context->pixel_type);
+ d = GP_MixPixels(pixel, d, d_perc, context->pixel_type);
+
+ GP_PutPixel(context, (x0>>8) - 1, i, u);
+ GP_PutPixel(context, (x1>>8) + 1, i, d);
+ }
+
+ uint8_t perc;
+ GP_Pixel p;
+
+ perc = GP_GammaToLinear((x0%8+y0%8)/2);
+ p = GP_GetPixel(context, (x0>>8) - 1, (y0>>8) - 1);
+ p = GP_MixPixels(pixel, p, perc, context->pixel_type);
+ GP_PutPixel(context, (x0>>8) - 1, (y0>>8) - 1, p);
+
+ perc = GP_GammaToLinear((x1%8+y0%8)/2);
+ p = GP_GetPixel(context, (x1>>8) + 1, (y0>>8) - 1);
+ p = GP_MixPixels(pixel, p, perc, context->pixel_type);
+ GP_PutPixel(context, (x1>>8) + 1, (y0>>8) - 1, p);
+
+ perc = GP_GammaToLinear((x0%8+y1%8)/2);
+ p = GP_GetPixel(context, (x0>>8) - 1, (y1>>8) + 1);
+ p = GP_MixPixels(pixel, p, perc, context->pixel_type);
+ GP_PutPixel(context, (x0>>8) - 1, (y1>>8) + 1, p);
+
+ perc = GP_GammaToLinear((x1%8+y1%8)/2);
+ p = GP_GetPixel(context, (x1>>8) + 1, (y1>>8) + 1);
+ p = GP_MixPixels(pixel, p, perc, context->pixel_type);
+ GP_PutPixel(context, (x1>>8) + 1, (y1>>8) + 1, p);
+}
+
+void GP_FillRectXYWH_AA_Raw(GP_Context *context, GP_Coord x, GP_Coord y,
+ GP_Size w, GP_Size h, GP_Pixel pixel)
+{
+ if (w == 0 || h == 0)
+ return;
+
+ GP_FillRectXYXY_AA_Raw(context, x, y, x + w - 1, y + h - 1, pixel);
+}
+
+void GP_FillRectXYXY_AA(GP_Context *context, GP_Coord x0, GP_Coord y0,
+ GP_Coord x1, GP_Coord y1, GP_Pixel pixel)
+{
+ GP_CHECK_CONTEXT(context);
+
+ GP_TRANSFORM_POINT(context, x0, y0);
+ GP_TRANSFORM_POINT(context, x1, y1);
+
+ GP_FillRect_AA_Raw(context, x0, y0, x1, y1, pixel);
+}
+
+void GP_FillRectXYWH_AA(GP_Context *context, GP_Coord x, GP_Coord y,
+ GP_Size w, GP_Size h, GP_Pixel pixel)
+{
+ if (w == 0 || h == 0)
+ return;
+
+ GP_FillRectXYXY_AA(context, x, y, x + w - 1, y + h - 1, pixel);
+}
diff --git a/tests/SDL/randomshapetest.c b/tests/SDL/randomshapetest.c
index edc8554..f7c8939 100644
--- a/tests/SDL/randomshapetest.c
+++ b/tests/SDL/randomshapetest.c
@@ -60,7 +60,8 @@ Uint32 timer_callback(__attribute__((unused)) Uint32 interval,
#define SHAPE_TRIANGLE 3
#define SHAPE_RECTANGLE 4
#define SHAPE_TETRAGON 5
-#define SHAPE_LAST 5
+#define SHAPE_RECTANGLE_AA 6
+#define SHAPE_LAST 6
static int shape = SHAPE_FIRST;
/* Draw outlines? */
@@ -83,6 +84,12 @@ void random_point(SDL_Surface *surf, int *x, int *y)
}
}
+void random_point_AA(SDL_Surface *surf, int *x, int *y)
+{
+ *x = random() % (surf->w<<8);
+ *y = random() % (surf->h<<8);
+}
+
void draw_random_circle(GP_Pixel pixel)
{
int x, y;
@@ -152,6 +159,20 @@ void draw_random_tetragon(GP_Pixel pixel)
GP_Tetragon(&context, x0, y0, x1, y1, x2, y2, x3, y3, pixel);
}
+void draw_random_rectangle_AA(GP_Pixel pixel)
+{
+ int x0, y0, x1, y1;
+ random_point_AA(display, &x0, &y0);
+ random_point_AA(display, &x1, &y1);
+
+// if (fill_flag)
+ GP_FillRect_AA(&context, x0, y0, x1, y1, pixel);
+
+// if (outline_flag)
+// GP_Rect(&context, x0, y0, x1, y1, white);
+}
+
+
void clear_screen(void)
{
SDL_LockSurface(display);
@@ -174,23 +195,22 @@ void redraw_screen(void)
switch (shape) {
case SHAPE_CIRCLE:
draw_random_circle(pixel);
- break;
-
+ break;
case SHAPE_ELLIPSE:
draw_random_ellipse(pixel);
- break;
-
+ break;
case SHAPE_TRIANGLE:
draw_random_triangle(pixel);
- break;
-
+ break;
case SHAPE_RECTANGLE:
draw_random_rectangle(pixel);
- break;
-
+ break;
case SHAPE_TETRAGON:
draw_random_tetragon(pixel);
- break;
+ break;
+ case SHAPE_RECTANGLE_AA:
+ draw_random_rectangle_AA(pixel);
+ break;
}
SDL_UnlockSurface(display);
http://repo.or.cz/w/gfxprim.git/commit/39de4836f42404f669d76cf0ebd759a0a32f…
commit 39de4836f42404f669d76cf0ebd759a0a32f41b9
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Tue Jan 3 00:16:41 2012 +0100
core: Remove now unused DEF_FFN_PER_BPP macros.
diff --git a/include/core/GP_FnPerBpp.gen.h.t b/include/core/GP_FnPerBpp.gen.h.t
index 02238a1..13a1f84 100644
--- a/include/core/GP_FnPerBpp.gen.h.t
+++ b/include/core/GP_FnPerBpp.gen.h.t
@@ -12,11 +12,6 @@
GP_DEF_FN_FOR_BPP(fname, MACRO_NAME, fdraw, {{ ps.suffix }}) {% endfor %}
-#define GP_DEF_FFN_PER_BPP(fname, MACRO_NAME) -%% for ps in pixelsizes
- GP_DEF_FFN_FOR_BPP(fname, MACRO_NAME, {{ ps.suffix }}) -{% endfor %}
-
{% macro bpp_suffix(suffix) %}{% if suffix == "LE" or suffix == "BE" %}_{{ suffix }}{% endif %}{% endmacro %}
/*
diff --git a/include/core/GP_FnPerBpp.h b/include/core/GP_FnPerBpp.h
index daf21c9..11d12a3 100644
--- a/include/core/GP_FnPerBpp.h
+++ b/include/core/GP_FnPerBpp.h
@@ -85,13 +85,4 @@
#define GP_DEF_FN_FOR_BPP(fname, MACRO_NAME, fdraw, bpp) MACRO_NAME(fname##_##bpp, GP_Context *, GP_Pixel, fdraw##bpp)
-/*
- * Dtto for filters.
- *
- * Filter is functions that works on Context per pixel.
- */
-#define GP_DEF_FFN_FOR_BPP(fname, MACRO_NAME, bpp) - MACRO_NAME(fname##_##bpp, GP_Context *, GP_Pixel, - GP_PutPixel_Raw_##bpp, GP_GetPixel_Raw_##bpp)
-
#endif /* GP_FN_PER_BPP_H */
http://repo.or.cz/w/gfxprim.git/commit/261533840975611674984ee1e3a8ea2b8308…
commit 261533840975611674984ee1e3a8ea2b83085dae
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Tue Jan 3 00:06:19 2012 +0100
core: Add GP_MixPixels() function.
diff --git a/include/core/GP_MixPixels.gen.h.t b/include/core/GP_MixPixels.gen.h.t
index 2ad33a8..deb6912 100644
--- a/include/core/GP_MixPixels.gen.h.t
+++ b/include/core/GP_MixPixels.gen.h.t
@@ -32,4 +32,19 @@ Macros to mix two pixels accordingly to percentage.
%% endif
%% endfor
+static inline GP_Pixel GP_MixPixels(GP_Pixel pix1, GP_Pixel pix2,
+ uint8_t perc, GP_PixelType pixel_type)
+{
+ switch (pixel_type) {
+%% for pt in pixeltypes
+%% if not pt.is_unknown()
+ case GP_PIXEL_{{ pt.name }}:
+ return GP_MIX_PIXELS_{{ pt.name }}(pix1, pix2, perc);
+%% endif
+%% endfor
+ default:
+ GP_ABORT("Unknown pixeltype");
+ }
+}
+
%% endblock body
diff --git a/include/core/GP_MixPixels.h b/include/core/GP_MixPixels.h
new file mode 100644
index 0000000..bd9006e
--- /dev/null
+++ b/include/core/GP_MixPixels.h
@@ -0,0 +1,29 @@
+/*****************************************************************************
+ * 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) 2012 Cyril Hrubis <metan(a)ucw.cz> *
+ * *
+ *****************************************************************************/
+
+#ifndef CORE_GP_MIXPIXELS_H
+#define CORE_GP_MIXPIXELS_H
+
+/* Generated header */
+#include "GP_MixPixels.gen.h"
+
+#endif /* CORE_GP_MIXPIXELS_H */
-----------------------------------------------------------------------
Summary of changes:
include/core/GP_FnPerBpp.gen.h.t | 5 -
include/core/GP_FnPerBpp.h | 9 --
.../GP_GammaCorrection.h} | 22 +++-
include/core/GP_MixPixels.gen.h.t | 15 +++
.../GP_Blit.test.c => include/core/GP_MixPixels.h | 11 +-
include/gfx/GP_Gfx.h | 2 +
libs/text/GP_Font.c => include/gfx/GP_RectAA.h | 58 ++++------
libs/gfx/GP_RectAA.c | 129 ++++++++++++++++++++
tests/SDL/randomshapetest.c | 40 +++++--
9 files changed, 220 insertions(+), 71 deletions(-)
copy include/{input/GP_InputDriverSDL.h => core/GP_GammaCorrection.h} (78%)
copy tests/core/GP_Blit.test.c => include/core/GP_MixPixels.h (88%)
copy libs/text/GP_Font.c => include/gfx/GP_RectAA.h (58%)
create mode 100644 libs/gfx/GP_RectAA.c
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: 1bac6fdd5618b074d38c9f7d4da6e867b302ba16
by metan 01 Jan '12
by metan 01 Jan '12
01 Jan '12
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project gfxprim.git.
The branch, master has been updated
via 1bac6fdd5618b074d38c9f7d4da6e867b302ba16 (commit)
via af6a9007db86d114595f630d6a6be24519a2b0df (commit)
from 0c39d1adbaeb40591a13cbf965d773374fb8194b (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/1bac6fdd5618b074d38c9f7d4da6e867b302…
commit 1bac6fdd5618b074d38c9f7d4da6e867b302ba16
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Sun Jan 1 21:26:09 2012 +0100
Text: Fix some overflows.
And that should be last bug that was lurking in there, I promise.
diff --git a/include/text/GP_Font.h b/include/text/GP_Font.h
index 4975ed2..0bce212 100644
--- a/include/text/GP_Font.h
+++ b/include/text/GP_Font.h
@@ -147,7 +147,7 @@ typedef struct GP_FontFace {
* offsets for all characters in glyphs. Otherwise the
* glyph_offset[0] defines step in the glyph table.
*/
- uint16_t glyph_offsets[];
+ uint32_t glyph_offsets[];
} GP_FontFace;
/*
diff --git a/libs/text/GP_Font.c b/libs/text/GP_Font.c
index f153edc..633e45d 100644
--- a/libs/text/GP_Font.c
+++ b/libs/text/GP_Font.c
@@ -51,7 +51,7 @@ GP_GlyphBitmap *GP_GetGlyphBitmap(const GP_FontFace *font, int c)
return NULL;
}
- uint16_t offset;
+ uint32_t offset;
if (font->glyph_offsets[0] == 0)
offset = font->glyph_offsets[i];
diff --git a/libs/text/GP_FreeType.c b/libs/text/GP_FreeType.c
index a66999a..b454d89 100644
--- a/libs/text/GP_FreeType.c
+++ b/libs/text/GP_FreeType.c
@@ -16,7 +16,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, *
* Boston, MA 02110-1301 USA *
* *
- * Copyright (C) 2009-2011 Cyril Hrubis <metan(a)ucw.cz> *
+ * Copyright (C) 2009-2012 Cyril Hrubis <metan(a)ucw.cz> *
* *
*****************************************************************************/
@@ -66,7 +66,7 @@ GP_FontFace *GP_FontFaceLoad(const char *path, uint32_t width, uint32_t height)
unsigned int font_face_size;
font_face_size = sizeof(GP_FontFace) +
- sizeof(uint16_t) * GP_GetGlyphCount(GP_CHARSET_7BIT);
+ sizeof(uint32_t) * GP_GetGlyphCount(GP_CHARSET_7BIT);
GP_FontFace *font = malloc(font_face_size);
@@ -183,7 +183,7 @@ GP_FontFace *GP_FontFaceLoad(const char *path, uint32_t width, uint32_t height)
for (y = 0; y < glyph_bitmap->height; y++) {
for (x = 0; x < glyph_bitmap->width; x++) {
- uint8_t addr = glyph_bitmap->width * y + x;
+ unsigned int addr = glyph_bitmap->width * y + x;
glyph_bitmap->bitmap[addr] = glyph->bitmap.buffer[y * glyph->bitmap.pitch + x];
}
http://repo.or.cz/w/gfxprim.git/commit/af6a9007db86d114595f630d6a6be24519a2…
commit af6a9007db86d114595f630d6a6be24519a2b0df
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Sun Jan 1 20:32:52 2012 +0100
Text: Fonttext can now change font size.
diff --git a/tests/SDL/fonttest.c b/tests/SDL/fonttest.c
index 6bbc913..ec9f93a 100644
--- a/tests/SDL/fonttest.c
+++ b/tests/SDL/fonttest.c
@@ -33,6 +33,9 @@
SDL_Surface *display = NULL;
GP_Context context;
+static const char *font_path = NULL;
+static unsigned int font_h = 16;
+
static GP_Pixel white_pixel, gray_pixel, dark_gray_pixel, black_pixel,
red_pixel, blue_pixel;
@@ -200,6 +203,24 @@ void event_loop(void)
redraw_screen();
SDL_Flip(display);
break;
+ case SDLK_b:
+ font_h++;
+ if (font_path) {
+ GP_FontFaceFree(font);
+ font = GP_FontFaceLoad(font_path, 0, font_h);
+ redraw_screen();
+ SDL_Flip(display);
+ }
+ break;
+ case SDLK_s:
+ font_h--;
+ if (font_path) {
+ GP_FontFaceFree(font);
+ font = GP_FontFaceLoad(font_path, 0, font_h);
+ redraw_screen();
+ SDL_Flip(display);
+ }
+ break;
case SDLK_ESCAPE:
return;
default:
@@ -219,6 +240,7 @@ void print_instructions(void)
printf(" Esc ................. exitn");
printf(" Space ............... change fontn");
printf(" up/down ............. increase/decrease trackingn");
+ printf(" b/s ................. change font size (freetype only)n");
}
int main(int argc, char *argv[])
@@ -228,8 +250,9 @@ int main(int argc, char *argv[])
GP_SetDebugLevel(10);
if (argc > 1) {
+ font_path = argv[1];
fprintf(stderr, "nLoading font '%s'n", argv[1]);
- font = GP_FontFaceLoad(argv[1], 0, 16);
+ font = GP_FontFaceLoad(argv[1], 0, font_h);
}
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) != 0) {
-----------------------------------------------------------------------
Summary of changes:
include/text/GP_Font.h | 2 +-
libs/text/GP_Font.c | 2 +-
libs/text/GP_FreeType.c | 6 +++---
tests/SDL/fonttest.c | 25 ++++++++++++++++++++++++-
4 files changed, 29 insertions(+), 6 deletions(-)
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos(a)gmail.com
if you want to unsubscribe, or site admin admin(a)repo.or.cz if you receive
no reply.
--
gfxprim.git ("A simple 2D graphics library with emphasis on correctness and well-defined operation.")
1
0
[repo.or.cz] gfxprim.git branch master updated: 0c39d1adbaeb40591a13cbf965d773374fb8194b
by metan 01 Jan '12
by metan 01 Jan '12
01 Jan '12
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project gfxprim.git.
The branch, master has been updated
via 0c39d1adbaeb40591a13cbf965d773374fb8194b (commit)
from 4d91a70e678339b10b0ed4b35ba9a18ccc84fa67 (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/0c39d1adbaeb40591a13cbf965d773374fb8…
commit 0c39d1adbaeb40591a13cbf965d773374fb8194b
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Sun Jan 1 17:57:21 2012 +0100
Text: More fixes for freetype.
* Do not use bearing for first letter in string.
* Specify only one of w/h when loading font
(yield in much better glyph bitmaps)
diff --git a/include/text/GP_Font.h b/include/text/GP_Font.h
index 201595e..4975ed2 100644
--- a/include/text/GP_Font.h
+++ b/include/text/GP_Font.h
@@ -16,7 +16,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, *
* Boston, MA 02110-1301 USA *
* *
- * Copyright (C) 2009-2011 Cyril Hrubis <metan(a)ucw.cz> *
+ * Copyright (C) 2009-2012 Cyril Hrubis <metan(a)ucw.cz> *
* *
*****************************************************************************/
@@ -188,4 +188,9 @@ GP_GlyphBitmap *GP_GetGlyphBitmap(const GP_FontFace *font, int c);
*/
GP_FontFace *GP_FontFaceLoad(const char *path, uint32_t width, uint32_t height);
+/*
+ * Free the font face memory.
+ */
+void GP_FontFaceFree(GP_FontFace *self);
+
#endif /* TEXT_GP_FONT_H */
diff --git a/libs/text/GP_Font.c b/libs/text/GP_Font.c
index a4439f9..f153edc 100644
--- a/libs/text/GP_Font.c
+++ b/libs/text/GP_Font.c
@@ -16,7 +16,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, *
* Boston, MA 02110-1301 USA *
* *
- * Copyright (C) 2009-2011 Cyril Hrubis <metan(a)ucw.cz> *
+ * Copyright (C) 2009-2012 Cyril Hrubis <metan(a)ucw.cz> *
* *
*****************************************************************************/
@@ -60,3 +60,9 @@ GP_GlyphBitmap *GP_GetGlyphBitmap(const GP_FontFace *font, int c)
return (GP_GlyphBitmap*)(font->glyphs + offset);
}
+
+void GP_FontFaceFree(GP_FontFace *self)
+{
+ free(self->glyphs);
+ free(self);
+}
diff --git a/libs/text/GP_Text.gen.c.t b/libs/text/GP_Text.gen.c.t
index 286d3a7..22498af 100644
--- a/libs/text/GP_Text.gen.c.t
+++ b/libs/text/GP_Text.gen.c.t
@@ -41,8 +41,11 @@ static void text_draw_1BPP_{{ pt.name }}(GP_Context *context, GP_TextStyle *styl
for (j = 0; j < glyph->height; j++) {
for (i = 0; i < glyph->width; i++) {
uint8_t bit = (glyph->bitmap[i/8 + j * bpp]) & (0x80>>(i%8));
-
+
unsigned int x_start = x + (i + glyph->bearing_x) * x_mul;
+
+ if (p == str)
+ x_start -= glyph->bearing_x * x_mul;
if (!bit)
continue;
@@ -56,6 +59,9 @@ static void text_draw_1BPP_{{ pt.name }}(GP_Context *context, GP_TextStyle *styl
}
x += glyph->advance_x * x_mul + style->char_xspace;
+
+ if (p == str)
+ x -= glyph->bearing_x * x_mul;
}
}
@@ -108,6 +114,9 @@ static void text_draw_8BPP_{{ pt.name }}(GP_Context *context, GP_TextStyle *styl
unsigned int x_start = x + (i + glyph->bearing_x) * x_mul;
+ if (p == str)
+ x_start -= glyph->bearing_x * x_mul;
+
if (!gray)
continue;
@@ -119,8 +128,11 @@ static void text_draw_8BPP_{{ pt.name }}(GP_Context *context, GP_TextStyle *styl
y += style->pixel_ymul + style->pixel_yspace;
}
-
+
x += glyph->advance_x * x_mul + style->char_xspace;
+
+ if (p == str)
+ x -= glyph->bearing_x * x_mul;
}
}
diff --git a/libs/text/GP_TextMetric.c b/libs/text/GP_TextMetric.c
index ae746df..737d61d 100644
--- a/libs/text/GP_TextMetric.c
+++ b/libs/text/GP_TextMetric.c
@@ -19,7 +19,7 @@
* Copyright (C) 2009-2010 Jiri "BlueBear" Dluhos *
* <jiri.bluebear.dluhos(a)gmail.com> *
* *
- * Copyright (C) 2009-2011 Cyril Hrubis <metan(a)ucw.cz> *
+ * Copyright (C) 2009-2012 Cyril Hrubis <metan(a)ucw.cz> *
* *
*****************************************************************************/
@@ -28,21 +28,50 @@
extern GP_TextStyle GP_DefaultStyle;
-/*
- * Returns glyph width from the basepoint to the end of the glyph bitmap.
- */
-static unsigned int glyph_width(const GP_TextStyle *style, char ch)
+static const GP_GlyphBitmap *get_glyph(const GP_TextStyle *style, int c)
{
- unsigned int pixel_multiplier = style->pixel_xmul + style->pixel_xspace;
- const GP_GlyphBitmap *glyph = GP_GetGlyphBitmap(style->font, ch);
+ const GP_GlyphBitmap *glyph = GP_GetGlyphBitmap(style->font, c);
if (glyph == NULL)
glyph = GP_GetGlyphBitmap(style->font, ' ');
+
+ return glyph;
+}
+
+static unsigned int get_pixel_multiplier(const GP_TextStyle *style)
+{
+ return style->pixel_xmul + style->pixel_xspace;
+}
+
+/*
+ * Returns glyph width from the basepoint to the end of the glyph bitmap.
+ */
+static unsigned int glyph_width(const GP_TextStyle *style, int c)
+{
+ unsigned int pixel_multiplier = get_pixel_multiplier(style);
+ const GP_GlyphBitmap *glyph = get_glyph(style, c);
return (glyph->width + glyph->bearing_x) * pixel_multiplier;
}
/*
+ * Returns size of the glyph but doesn't count bearing.
+ *
+ * Note that the bearing may be negative (typical case is letter 'j' or most of
+ * the italic glyphs). So in order not to draw out of the text bouding box,
+ * first glyph ignores bearing_x and draws beginning of the glyph bitmap on the
+ * starting basepoint.
+ *
+ */
+static unsigned int first_glyph_width(const GP_TextStyle *style, int c)
+{
+ unsigned int pixel_multiplier = get_pixel_multiplier(style);
+ const GP_GlyphBitmap *glyph = get_glyph(style, c);
+
+ return glyph->width * pixel_multiplier;
+}
+
+/*
* Returns space that is added after the glyph.
*
* Eg. the advance minus glyph width.
@@ -51,11 +80,8 @@ static unsigned int glyph_width(const GP_TextStyle *style, char ch)
*/
static unsigned int glyph_space(const GP_TextStyle *style, char ch)
{
- unsigned int pixel_multiplier = style->pixel_xmul + style->pixel_xspace;
- const GP_GlyphBitmap *glyph = GP_GetGlyphBitmap(style->font, ch);
-
- if (glyph == NULL)
- glyph = GP_GetGlyphBitmap(style->font, ' ');
+ unsigned int pixel_multiplier = get_pixel_multiplier(style);
+ const GP_GlyphBitmap *glyph = get_glyph(style, ch);
return (glyph->advance_x - glyph->width - glyph->bearing_x)
* pixel_multiplier + style->char_xspace;
@@ -97,7 +123,14 @@ unsigned int GP_TextWidth(const GP_TextStyle *style, const char *str)
if (str == NULL || str[0] == '0')
return 0;
- for (i = 0; str[i] != '0'; i++) {
+ len += first_glyph_width(style, str[0]);
+
+ if (str[1] == '0')
+ return len;
+
+ len += glyph_space(style, str[0]);
+
+ for (i = 1; str[i] != '0'; i++) {
len += glyph_width(style, str[i]);
if (str[i+1] != '0')
diff --git a/tests/SDL/fileview.c b/tests/SDL/fileview.c
index f468750..d1c8008 100644
--- a/tests/SDL/fileview.c
+++ b/tests/SDL/fileview.c
@@ -19,7 +19,7 @@
* Copyright (C) 2009-2010 Jiri "BlueBear" Dluhos *
* <jiri.bluebear.dluhos(a)gmail.com> *
* *
- * Copyright (C) 2009-2011 Cyril Hrubis <metan(a)ucw.cz> *
+ * Copyright (C) 2009-2012 Cyril Hrubis <metan(a)ucw.cz> *
* *
*****************************************************************************/
@@ -215,7 +215,7 @@ int main(int argc, char *argv[])
if (argc > 2)
- font = GP_FontFaceLoad(argv[2], 12, 17);
+ font = GP_FontFaceLoad(argv[2], 0, 16);
if (!read_file_head(argv[1]))
return 1;
diff --git a/tests/SDL/fonttest.c b/tests/SDL/fonttest.c
index ef1b39d..6bbc913 100644
--- a/tests/SDL/fonttest.c
+++ b/tests/SDL/fonttest.c
@@ -19,7 +19,7 @@
* Copyright (C) 2009-2010 Jiri "BlueBear" Dluhos *
* <jiri.bluebear.dluhos(a)gmail.com> *
* *
- * Copyright (C) 2009-2011 Cyril Hrubis <metan(a)ucw.cz> *
+ * Copyright (C) 2009-2012 Cyril Hrubis <metan(a)ucw.cz> *
* *
*****************************************************************************/
@@ -229,7 +229,7 @@ int main(int argc, char *argv[])
if (argc > 1) {
fprintf(stderr, "nLoading font '%s'n", argv[1]);
- font = GP_FontFaceLoad(argv[1], 12, 16);
+ font = GP_FontFaceLoad(argv[1], 0, 16);
}
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) != 0) {
diff --git a/tests/SDL/textaligntest.c b/tests/SDL/textaligntest.c
index 26c3028..a58e670 100644
--- a/tests/SDL/textaligntest.c
+++ b/tests/SDL/textaligntest.c
@@ -19,7 +19,7 @@
* Copyright (C) 2009-2010 Jiri "BlueBear" Dluhos *
* <jiri.bluebear.dluhos(a)gmail.com> *
* *
- * Copyright (C) 2009-2011 Cyril Hrubis <metan(a)ucw.cz> *
+ * Copyright (C) 2009-2012 Cyril Hrubis <metan(a)ucw.cz> *
* *
*****************************************************************************/
@@ -143,7 +143,7 @@ int main(int argc, char *argv[])
GP_SetDebugLevel(10);
if (argc > 1)
- font = GP_FontFaceLoad(argv[1], 12, 16);
+ font = GP_FontFaceLoad(argv[1], 0, 16);
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) != 0) {
fprintf(stderr, "Could not initialize SDL: %sn", SDL_GetError());
-----------------------------------------------------------------------
Summary of changes:
include/text/GP_Font.h | 7 ++++-
libs/text/GP_Font.c | 8 +++++-
libs/text/GP_Text.gen.c.t | 16 ++++++++++-
libs/text/GP_TextMetric.c | 59 +++++++++++++++++++++++++++++++++++----------
tests/SDL/fileview.c | 4 +-
tests/SDL/fonttest.c | 4 +-
tests/SDL/textaligntest.c | 4 +-
7 files changed, 79 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