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: 584ef7b40c75f90ad55347dac6e4fd95a4ff54af
by metan 12 Feb '12
by metan 12 Feb '12
12 Feb '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 584ef7b40c75f90ad55347dac6e4fd95a4ff54af (commit)
via 565271d45d92a19f90b6f8ec637e8626fe8c1f0f (commit)
from 6e4677159b0d9febdd48f359e335277b53991093 (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/584ef7b40c75f90ad55347dac6e4fd95a4ff…
commit 584ef7b40c75f90ad55347dac6e4fd95a4ff54af
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Sun Feb 12 19:43:18 2012 +0100
demos: Add simple particle demo.
diff --git a/demos/Makefile b/demos/Makefile
index eddfa9f..107f998 100644
--- a/demos/Makefile
+++ b/demos/Makefile
@@ -1,3 +1,3 @@
TOPDIR=..
-SUBDIRS=grinder fbshow
+SUBDIRS=grinder fbshow particle
include $(TOPDIR)/include.mk
diff --git a/demos/particle/particle_demo.c b/demos/particle/particle_demo.c
index 4615607..5061397 100644
--- a/demos/particle/particle_demo.c
+++ b/demos/particle/particle_demo.c
@@ -76,7 +76,7 @@ int main(int argc, char *argv[])
{
const char *backend_opts = "fb";
int opt;
- int pause_flag = 1;
+ int pause_flag = 0;
while ((opt = getopt(argc, argv, "b:Ii:Ps:r:")) != -1) {
switch (opt) {
@@ -105,7 +105,8 @@ int main(int argc, char *argv[])
GP_Fill(context, black_pixel);
GP_BackendFlip(backend);
- struct space *space = space_create(1000, context->w<<8, context->h<<8);
+ struct space *space;
+ space = space_create(1000, 10<<8, 10<<8, (context->w - 10)<<8, (context->h - 10)<<8);
for (;;) {
if (backend->Poll)
@@ -135,6 +136,12 @@ int main(int argc, char *argv[])
case GP_KEY_P:
pause_flag = !pause_flag;
break;
+ case GP_KEY_G:
+ space->gay = 1;
+ break;
+ case GP_KEY_T:
+ space->gay = 0;
+ break;
}
break;
}
diff --git a/demos/particle/space.c b/demos/particle/space.c
index bdf87e0..6a244b7 100644
--- a/demos/particle/space.c
+++ b/demos/particle/space.c
@@ -22,7 +22,8 @@
#include "space.h"
-struct space *space_create(unsigned int particle_count, int w, int h)
+struct space *space_create(unsigned int particle_count, int min_w, int min_h,
+ int max_w, int max_h)
{
struct space *new = malloc(sizeof(struct space) +
sizeof(struct particle) * particle_count);
@@ -31,14 +32,21 @@ struct space *space_create(unsigned int particle_count, int w, int h)
return NULL;
new->particle_count = particle_count;
- new->w = w;
- new->h = h;
+ new->min_w = min_w;
+ new->min_h = min_h;
+ new->max_w = max_w;
+ new->max_h = max_h;
+
+ new->gax = 0;
+ new->gay = 0;
+
+ new->elasticity = (1<<8) - (1<<6);
unsigned int i;
for (i = 0; i < particle_count; i++) {
- new->particles[i].x = random() % w;
- new->particles[i].y = random() % h;
+ new->particles[i].x = random() % (max_w - min_w) + min_w;
+ new->particles[i].y = random() % (max_h - min_h) + min_h;
new->particles[i].vx = random() % 40 - 20;
new->particles[i].vy = random() % 40 - 20;
}
@@ -63,12 +71,12 @@ void space_draw_particles(GP_Context *context, struct space *space)
static void modify_speeds(struct space *space, int time)
{
- unsigned int i, j;
+ unsigned int i;
for (i = 0; i < space->particle_count; i++) {
-// space->particles[i].vx += * time;
- space->particles[i].vy += time;
- }
+ space->particles[i].vy += space->gax * time;
+ space->particles[i].vy += space->gay * time;
+ }
}
void space_time_tick(struct space *space, int time)
@@ -78,11 +86,14 @@ void space_time_tick(struct space *space, int time)
modify_speeds(space, time);
for (i = 0; i < space->particle_count; i++) {
- if (space->particles[i].x <= 2 || space->particles[i].x >= space->w - 2)
- space->particles[i].vx *= -0.9;
+
+ if ((space->particles[i].x < space->min_w && space->particles[i].vx < 0) ||
+ (space->particles[i].x >= space->max_w && space->particles[i].vx > 0))
+ space->particles[i].vx = GP_FP_MUL(space->particles[i].vx, -space->elasticity);
- if (space->particles[i].y <= 2 || space->particles[i].y >= space->h - 2)
- space->particles[i].vy *= -0.9;
+ if ((space->particles[i].y < space->min_h && space->particles[i].vy < 0) ||
+ (space->particles[i].y >= space->max_h && space->particles[i].vy > 0))
+ space->particles[i].vy = GP_FP_MUL(space->particles[i].vy, -space->elasticity);
space->particles[i].x += space->particles[i].vx * time;
space->particles[i].y += space->particles[i].vy * time;
diff --git a/demos/particle/space.h b/demos/particle/space.h
index 0cb7c3f..d4b01a5 100644
--- a/demos/particle/space.h
+++ b/demos/particle/space.h
@@ -44,13 +44,25 @@ struct particle {
struct space {
unsigned int particle_count;
- int w;
- int h;
+ /* space is an rectanle */
+ int min_w;
+ int min_h;
+
+ int max_w;
+ int max_h;
+
+ /* gravitation vector */
+ int gax;
+ int gay;
+
+ /* elasticity at the boudaries */
+ int elasticity;
struct particle particles[];
};
-struct space *space_create(unsigned int particle_count, int w, int h);
+struct space *space_create(unsigned int particle_count, int min_w, int min_h,
+ int max_w, int max_h);
void space_destroy(struct space *space);
http://repo.or.cz/w/gfxprim.git/commit/565271d45d92a19f90b6f8ec637e8626fe8c…
commit 565271d45d92a19f90b6f8ec637e8626fe8c1f0f
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Sun Feb 12 19:41:53 2012 +0100
gfx: Added PutPixelAA.
diff --git a/demos/particle/Makefile b/demos/particle/Makefile
new file mode 100644
index 0000000..9843284
--- /dev/null
+++ b/demos/particle/Makefile
@@ -0,0 +1,13 @@
+TOPDIR=../..
+
+CSOURCES=$(shell echo *.c)
+
+INCLUDE=
+LDLIBS+=-lGP -lGP_backends -lSDL -L$(TOPDIR)/build/
+
+APPS=particle_demo
+
+$(APPS): space.o
+
+include $(TOPDIR)/include.mk
+include $(TOPDIR)/app.mk
diff --git a/demos/particle/particle_demo.c b/demos/particle/particle_demo.c
new file mode 100644
index 0000000..4615607
--- /dev/null
+++ b/demos/particle/particle_demo.c
@@ -0,0 +1,153 @@
+/*****************************************************************************
+ * 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> *
+ * *
+ *****************************************************************************/
+
+ /*
+
+ Particle demo.
+
+ */
+
+#include <signal.h>
+#include <string.h>
+#include <GP.h>
+#include <backends/GP_Backends.h>
+
+#include "space.h"
+
+static GP_Pixel black_pixel;
+static GP_Pixel white_pixel;
+
+static GP_Backend *backend = NULL;
+static GP_Context *context = NULL;
+
+static void sighandler(int signo)
+{
+ if (backend != NULL)
+ GP_BackendExit(backend);
+
+ fprintf(stderr, "Got signal %in", signo);
+
+ exit(1);
+}
+
+static void init_backend(const char *backend_opts)
+{
+ if (!strcmp(backend_opts, "fb")) {
+ fprintf(stderr, "Initalizing framebuffer backendn");
+ backend = GP_BackendLinuxFBInit("/dev/fb0");
+ }
+
+ if (!strcmp(backend_opts, "SDL")) {
+ fprintf(stderr, "Initalizing SDL backendn");
+ backend = GP_BackendSDLInit(800, 600, 0, 0);
+ }
+
+ if (!strcmp(backend_opts, "SDL:FS")) {
+ fprintf(stderr, "Initalizing SDL fullscreenn");
+ backend = GP_BackendSDLInit(0, 0, 0, GP_SDL_FULLSCREEN);
+ }
+
+ if (backend == NULL) {
+ fprintf(stderr, "Failed to initalize backend '%s'n", backend_opts);
+ exit(1);
+ }
+}
+
+int main(int argc, char *argv[])
+{
+ const char *backend_opts = "fb";
+ int opt;
+ int pause_flag = 1;
+
+ while ((opt = getopt(argc, argv, "b:Ii:Ps:r:")) != -1) {
+ switch (opt) {
+ case 'b':
+ backend_opts = optarg;
+ break;
+ default:
+ fprintf(stderr, "Invalid paramter '%c'n", opt);
+ }
+ }
+
+ GP_SetDebugLevel(10);
+
+ signal(SIGINT, sighandler);
+ signal(SIGSEGV, sighandler);
+ signal(SIGBUS, sighandler);
+ signal(SIGABRT, sighandler);
+
+ init_backend(backend_opts);
+
+ context = backend->context;
+
+ black_pixel = GP_ColorToContextPixel(GP_COL_BLACK, context);
+ white_pixel = GP_ColorToContextPixel(GP_COL_WHITE, context);
+
+ GP_Fill(context, black_pixel);
+ GP_BackendFlip(backend);
+
+ struct space *space = space_create(1000, context->w<<8, context->h<<8);
+
+ for (;;) {
+ if (backend->Poll)
+ GP_BackendPoll(backend);
+
+ usleep(5000);
+
+ /* Read and parse events */
+ GP_Event ev;
+
+ while (GP_EventGet(&ev)) {
+
+ GP_EventDump(&ev);
+
+ switch (ev.type) {
+ case GP_EV_KEY:
+ if (ev.code != GP_EV_KEY_DOWN)
+ continue;
+
+ switch (ev.val.key.key) {
+ case GP_KEY_ESC:
+ case GP_KEY_ENTER:
+ case GP_KEY_Q:
+ GP_BackendExit(backend);
+ return 0;
+ break;
+ case GP_KEY_P:
+ pause_flag = !pause_flag;
+ break;
+ }
+ break;
+ }
+ }
+
+ if (!pause_flag) {
+ space_time_tick(space, 2);
+ space_draw_particles(context, space);
+ GP_BackendFlip(backend);
+ }
+ }
+
+ GP_BackendExit(backend);
+
+ return 0;
+}
diff --git a/demos/particle/runtest.sh b/demos/particle/runtest.sh
new file mode 100755
index 0000000..0794707
--- /dev/null
+++ b/demos/particle/runtest.sh
@@ -0,0 +1,9 @@
+#!/bin/bash
+#
+# Run dynamically linked test.
+#
+
+PROG="$1"
+shift
+
+LD_LIBRARY_PATH=../../build/ ./$PROG "$@"
diff --git a/demos/particle/space.c b/demos/particle/space.c
new file mode 100644
index 0000000..bdf87e0
--- /dev/null
+++ b/demos/particle/space.c
@@ -0,0 +1,90 @@
+/*****************************************************************************
+ * 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 "space.h"
+
+struct space *space_create(unsigned int particle_count, int w, int h)
+{
+ struct space *new = malloc(sizeof(struct space) +
+ sizeof(struct particle) * particle_count);
+
+ if (new == NULL)
+ return NULL;
+
+ new->particle_count = particle_count;
+ new->w = w;
+ new->h = h;
+
+ unsigned int i;
+
+ for (i = 0; i < particle_count; i++) {
+ new->particles[i].x = random() % w;
+ new->particles[i].y = random() % h;
+ new->particles[i].vx = random() % 40 - 20;
+ new->particles[i].vy = random() % 40 - 20;
+ }
+
+ return new;
+}
+
+void space_destroy(struct space *space)
+{
+ free(space);
+}
+
+void space_draw_particles(GP_Context *context, struct space *space)
+{
+ unsigned int i;
+
+ GP_Fill(context, 0);
+
+ for (i = 0; i < space->particle_count; i++)
+ GP_PutPixelAA(context, space->particles[i].x, space->particles[i].y, 0xffffff);
+}
+
+static void modify_speeds(struct space *space, int time)
+{
+ unsigned int i, j;
+
+ for (i = 0; i < space->particle_count; i++) {
+// space->particles[i].vx += * time;
+ space->particles[i].vy += time;
+ }
+}
+
+void space_time_tick(struct space *space, int time)
+{
+ unsigned int i;
+
+ modify_speeds(space, time);
+
+ for (i = 0; i < space->particle_count; i++) {
+ if (space->particles[i].x <= 2 || space->particles[i].x >= space->w - 2)
+ space->particles[i].vx *= -0.9;
+
+ if (space->particles[i].y <= 2 || space->particles[i].y >= space->h - 2)
+ space->particles[i].vy *= -0.9;
+
+ space->particles[i].x += space->particles[i].vx * time;
+ space->particles[i].y += space->particles[i].vy * time;
+ }
+}
diff --git a/include/gfx/GP_Gfx.h b/demos/particle/space.h
similarity index 64%
copy from include/gfx/GP_Gfx.h
copy to demos/particle/space.h
index 54648a8..0cb7c3f 100644
--- a/include/gfx/GP_Gfx.h
+++ b/demos/particle/space.h
@@ -16,42 +16,46 @@
* 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> *
* *
*****************************************************************************/
-/*
+ /*
+
+ Particle demo.
+
+ */
+
+#ifndef PARTICLE_H
+#define PARTICLE_H
+
+#include <GP.h>
+
+struct particle {
+ /* fixed point coordinates */
+ int x;
+ int y;
+
+ /* fixed point speed */
+ int vx;
+ int vy;
+};
+
+struct space {
+ unsigned int particle_count;
- This is a main header for gfx part.
+ int w;
+ int h;
- */
+ struct particle particles[];
+};
-#ifndef GP_GFX_H
-#define GP_GFX_H
+struct space *space_create(unsigned int particle_count, int w, int h);
-/* basic definitions and structures */
-#include "core/GP_Context.h"
-#include "core/GP_GetPutPixel.h"
-#include "core/GP_WritePixel.h"
+void space_destroy(struct space *space);
-/* 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_CircleSeg.h"
-#include "GP_Ellipse.h"
-#include "GP_Arc.h"
-#include "GP_Polygon.h"
-#include "GP_Symbol.h"
+void space_draw_particles(GP_Context *context, struct space *space);
-#include "GP_RectAA.h"
+void space_time_tick(struct space *space, int time);
-#endif /* GP_GFX_H */
+#endif /* PARTICLE_H */
diff --git a/include/gfx/GP_Gfx.h b/include/gfx/GP_Gfx.h
index 54648a8..acc5fd2 100644
--- a/include/gfx/GP_Gfx.h
+++ b/include/gfx/GP_Gfx.h
@@ -53,5 +53,6 @@
#include "GP_Symbol.h"
#include "GP_RectAA.h"
+#include "GP_PutPixelAA.h"
#endif /* GP_GFX_H */
diff --git a/include/gfx/GP_Gfx.h b/include/gfx/GP_PutPixelAA.h
similarity index 65%
copy from include/gfx/GP_Gfx.h
copy to include/gfx/GP_PutPixelAA.h
index 54648a8..7d697c7 100644
--- a/include/gfx/GP_Gfx.h
+++ b/include/gfx/GP_PutPixelAA.h
@@ -16,42 +16,42 @@
* 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) 2012 Cyril Hrubis <metan(a)ucw.cz> *
* *
*****************************************************************************/
/*
+
+ Puts an anti aliased pixel to context.
- This is a main header for gfx part.
+ The coordinates are in XX.8 fixed point format, see core/GP_FixedPoint.h
+ for helper macros.
+
+ For RGB contexts gamma correction tables are used to generate correct
+ intensity for pixels.
*/
-#ifndef GP_GFX_H
-#define GP_GFX_H
+#ifndef GFX_GP_PUT_PIXEL_AA_H
+#define GFX_GP_PUT_PIXEL_AA_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_CircleSeg.h"
-#include "GP_Ellipse.h"
-#include "GP_Arc.h"
-#include "GP_Polygon.h"
-#include "GP_Symbol.h"
-
-#include "GP_RectAA.h"
-
-#endif /* GP_GFX_H */
+
+/*
+ * Anti Aliased Put Pixel respecting context rotation flags and with clipping.
+ */
+void GP_PutPixelAA(GP_Context *context, GP_Coord x, GP_Coord y, GP_Pixel pixel);
+
+/*
+ * Anti Aliased Put Pixel with clipping.
+ */
+void GP_PutPixelAA_Raw_Clipped(GP_Context *context, GP_Coord x, GP_Coord y,
+ GP_Pixel pixel);
+
+/*
+ * Raw Put Pixel.
+ */
+void GP_PutPixelAA_Raw(GP_Context *context, GP_Coord x, GP_Coord y,
+ GP_Pixel pixel);
+
+#endif /* GFX_GP_PUT_PIXEL_AA_H */
diff --git a/libs/gfx/GP_PutPixelAA.gen.c.t b/libs/gfx/GP_PutPixelAA.gen.c.t
new file mode 100644
index 0000000..625af68
--- /dev/null
+++ b/libs/gfx/GP_PutPixelAA.gen.c.t
@@ -0,0 +1,53 @@
+%% extends "base.c.t"
+
+{% block descr %}Anti Aliased Put Pixel{% endblock %}
+
+%% block body
+
+#include "core/GP_Context.h"
+#include "core/GP_MixPixels.h"
+#include "core/GP_FixedPoint.h"
+#include "core/GP_GammaCorrection.h"
+
+#include "gfx/GP_HLine.h"
+#include "gfx/GP_VLine.h"
+
+#define FP_TO_PERC(a) (GP_FP_ROUND_TO_INT((a) * 255))
+
+void GP_PutPixelAA_Raw(GP_Context *context, GP_Coord x, GP_Coord y,
+ GP_Pixel pixel)
+{
+ GP_Coord int_x = GP_FP_TO_INT(x);
+ GP_Coord int_y = GP_FP_TO_INT(y);
+ GP_Coord frac_x = GP_FP_FRAC(x);
+ GP_Coord frac_y = GP_FP_FRAC(y);
+ uint8_t perc;
+
+ perc = FP_TO_PERC(GP_FP_MUL(GP_FP_1 - frac_x, GP_FP_1 - frac_y));
+ GP_MixPixel_Raw_Clipped(context, int_x, int_y, pixel, perc);
+
+ perc = FP_TO_PERC(GP_FP_MUL(frac_x, GP_FP_1 - frac_y));
+ GP_MixPixel_Raw_Clipped(context, int_x + 1, int_y, pixel, perc);
+
+ perc = FP_TO_PERC(GP_FP_MUL(GP_FP_1 - frac_x, frac_y));
+ GP_MixPixel_Raw_Clipped(context, int_x, int_y + 1, pixel, perc);
+
+ perc = FP_TO_PERC(GP_FP_MUL(frac_x, frac_y));
+ GP_MixPixel_Raw_Clipped(context, int_x + 1, int_y + 1, pixel, perc);
+}
+
+void GP_PutPixelAA_Raw_Clipped(GP_Context *context, GP_Coord x, GP_Coord y,
+ GP_Pixel pixel)
+{
+ GP_PutPixelAA_Raw(context, x, y, pixel);
+}
+
+void GP_PutPixelAA(GP_Context *context, GP_Coord x, GP_Coord y, GP_Pixel pixel)
+{
+ GP_TRANSFORM_POINT_FP(context, x, y);
+
+ GP_PutPixelAA_Raw_Clipped(context, x, y, pixel);
+}
+
+
+%% endblock body
diff --git a/libs/gfx/Makefile b/libs/gfx/Makefile
index 64fd479..3e7cb28 100644
--- a/libs/gfx/Makefile
+++ b/libs/gfx/Makefile
@@ -1,6 +1,6 @@
TOPDIR=../..
CSOURCES=$(filter-out $(wildcard *.gen.c),$(wildcard *.c))
-GENSOURCES=GP_LineAA.gen.c
+GENSOURCES=GP_LineAA.gen.c GP_PutPixelAA.gen.c
LIBNAME=gfx
include $(TOPDIR)/gen.mk
-----------------------------------------------------------------------
Summary of changes:
demos/Makefile | 2 +-
{tests/drivers => demos/particle}/Makefile | 5 +-
demos/particle/particle_demo.c | 160 +++++++++++++++++++++
demos/{fbshow => particle}/runtest.sh | 0
demos/particle/space.c | 101 +++++++++++++
demos/{fbshow/cpu_timer.h => particle/space.h} | 57 +++++---
include/gfx/GP_Gfx.h | 1 +
include/{loaders/GP_JPG.h => gfx/GP_PutPixelAA.h} | 45 +++---
libs/gfx/GP_PutPixelAA.gen.c.t | 53 +++++++
libs/gfx/Makefile | 2 +-
10 files changed, 382 insertions(+), 44 deletions(-)
copy {tests/drivers => demos/particle}/Makefile (76%)
create mode 100644 demos/particle/particle_demo.c
copy demos/{fbshow => particle}/runtest.sh (100%)
create mode 100644 demos/particle/space.c
copy demos/{fbshow/cpu_timer.h => particle/space.h} (68%)
copy include/{loaders/GP_JPG.h => gfx/GP_PutPixelAA.h} (66%)
create mode 100644 libs/gfx/GP_PutPixelAA.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: 6e4677159b0d9febdd48f359e335277b53991093
by metan 12 Feb '12
by metan 12 Feb '12
12 Feb '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 6e4677159b0d9febdd48f359e335277b53991093 (commit)
from 8c91f2055c2d8a0f47593811e9ddb7261234d7b2 (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/6e4677159b0d9febdd48f359e335277b5399…
commit 6e4677159b0d9febdd48f359e335277b53991093
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Sun Feb 12 13:02:25 2012 +0100
core: blit added specialized rotated blits.
Now the code is a little baroque but fast,
maybe the _Raw variant isn't that needed
and non _Raw blits are fast enough
(I'll do some measurments).
diff --git a/include/core/GP_Blit.h b/include/core/GP_Blit.h
index 6c8ad84..adae66b 100644
--- a/include/core/GP_Blit.h
+++ b/include/core/GP_Blit.h
@@ -72,13 +72,6 @@ void GP_BlitXYXY_Raw(const GP_Context *src,
GP_Context *dst, GP_Coord x2, GP_Coord y2);
/*
- * Naive get/put pixel implementation, used when everything else fails.
- */
-void GP_BlitXYXY_Naive_Raw(const GP_Context *src,
- GP_Coord x0, GP_Coord y0, GP_Coord x1, GP_Coord y1,
- GP_Context *dst, GP_Coord x2, GP_Coord y2);
-
-/*
* Same as GP_BlitXYWH but doesn't respect rotations. Faster (for now).
*/
void GP_BlitXYWH_Raw(const GP_Context *src,
diff --git a/libs/core/GP_Blit.c b/libs/core/GP_Blit.c
index a31ef78..e69d7da 100644
--- a/libs/core/GP_Blit.c
+++ b/libs/core/GP_Blit.c
@@ -17,7 +17,7 @@
* Boston, MA 02110-1301 USA *
* *
* Copyright (C) 2011 Tomas Gavenciak <gavento(a)ucw.cz> *
- * Copyright (C) 2011,2012 Cyril Hrubis <metan(a)ucw.cz> *
+ * Copyright (C) 2011-2012 Cyril Hrubis <metan(a)ucw.cz> *
* *
*****************************************************************************/
@@ -26,12 +26,15 @@
#include "GP_Context.h"
#include "GP_Convert.h"
#include "GP_Blit.h"
-#include "GP_FnPerBpp.h"
-/* Generated function */
+/* Generated functions */
void GP_BlitXYXY_Raw_Fast(const GP_Context *src,
GP_Coord x0, GP_Coord y0, GP_Coord x1, GP_Coord y1,
- GP_Context *dst, GP_Coord x2, GP_Coord y2);
+ GP_Context *dst, GP_Coord x2, GP_Coord y2);
+
+void GP_BlitXYXY_Fast(const GP_Context *src,
+ GP_Coord x0, GP_Coord y0, GP_Coord x1, GP_Coord y1,
+ GP_Context *dst, GP_Coord x2, GP_Coord y2);
void GP_BlitXYXY_Naive(const GP_Context *src,
@@ -77,7 +80,7 @@ void GP_BlitXYXY(const GP_Context *src,
return;
}
- GP_BlitXYXY_Naive(src, x0, y0, x1, y1, dst, x2, y2);
+ GP_BlitXYXY_Fast(src, x0, y0, x1, y1, dst, x2, y2);
}
void GP_BlitXYWH(const GP_Context *src,
diff --git a/libs/core/GP_Blit.gen.c.t b/libs/core/GP_Blit.gen.c.t
index 9d5c160..50496e6 100644
--- a/libs/core/GP_Blit.gen.c.t
+++ b/libs/core/GP_Blit.gen.c.t
@@ -40,7 +40,7 @@ void blitXYXY_Naive_Raw(const GP_Context *src,
/*
* Blit for equal pixel types {{ ps.suffix }}
*/
-void GP_BlitXYXY_Raw_{{ ps.suffix }}(const GP_Context *src,
+void blitXYXY_Raw_{{ ps.suffix }}(const GP_Context *src,
GP_Coord x0, GP_Coord y0, GP_Coord x1, GP_Coord y1,
GP_Context *dst, GP_Coord x2, GP_Coord y2)
{
@@ -103,7 +103,7 @@ void GP_BlitXYXY_Raw_{{ ps.suffix }}(const GP_Context *src,
%% endfor
/*
- * Generate Naive Blits, I know this is n^2 variants but the gain is in speed is
+ * Generate Blits, I know this is n^2 variants but the gain is in speed is
* more than 50% and the size footprint for two for cycles is really small.
*/
%% for src in pixeltypes
@@ -114,7 +114,7 @@ void GP_BlitXYXY_Raw_{{ ps.suffix }}(const GP_Context *src,
/*
* Blits {{ src.name }} to {{ dst.name }}
*/
-static void blitXYXY_Naive_Raw_{{ src.name }}_{{ dst.name }}(const GP_Context *src,
+static void blitXYXY_Raw_{{ src.name }}_{{ dst.name }}(const GP_Context *src,
GP_Coord x0, GP_Coord y0, GP_Coord x1, GP_Coord y1,
GP_Context *dst, GP_Coord x2, GP_Coord y2)
{
@@ -138,16 +138,16 @@ static void blitXYXY_Naive_Raw_{{ src.name }}_{{ dst.name }}(const GP_Context *s
void GP_BlitXYXY_Raw_Fast(const GP_Context *src,
GP_Coord x0, GP_Coord y0, GP_Coord x1, GP_Coord y1,
- GP_Context *dst, GP_Coord x2, GP_Coord y2)
+ GP_Context *dst, GP_Coord x2, GP_Coord y2)
{
/* Same pixel type, could be (mostly) optimized to memcpy() */
if (src->pixel_type == dst->pixel_type) {
- GP_FN_PER_BPP(GP_BlitXYXY_Raw, src->bpp, src->bit_endian,
+ GP_FN_PER_BPP(blitXYXY_Raw, src->bpp, src->bit_endian,
src, x0, y0, x1, y1, dst, x2, y2);
return;
}
- /* Specialized naive functions */
+ /* Specialized functions */
switch (src->pixel_type) {
%% for src in pixeltypes
%% if not src.is_unknown() and not src.is_palette()
@@ -157,9 +157,111 @@ void GP_BlitXYXY_Raw_Fast(const GP_Context *src,
%% if not dst.is_unknown() and not dst.is_palette()
%% if dst.name != src.name
case GP_PIXEL_{{ dst.name }}:
- blitXYXY_Naive_Raw_{{ src.name }}_{{ dst.name }}(src, x0, y0,
- x1, y1,
- dst, x2, y2);
+ blitXYXY_Raw_{{ src.name }}_{{ dst.name }}(src, x0, y0, x1, y1, dst, x2, y2);
+ break;
+%% endif
+%% endif
+%% endfor
+ default:
+ GP_ABORT("Invalid destination pixel %s",
+ GP_PixelTypeName(dst->pixel_type));
+ }
+ break;
+%% endif
+%% endfor
+ default:
+ GP_ABORT("Invalid source pixel %s",
+ GP_PixelTypeName(src->pixel_type));
+ }
+}
+
+/*
+ * And the same for non-raw variants.
+ */
+%% for src in pixeltypes
+%% if not src.is_unknown() and not src.is_palette()
+%% for dst in pixeltypes
+%% if not dst.is_unknown() and not dst.is_palette()
+%% if dst.name != src.name
+/*
+ * Blits {{ src.name }} to {{ dst.name }}
+ */
+static void blitXYXY_{{ src.name }}_{{ dst.name }}(const GP_Context *src,
+ GP_Coord x0, GP_Coord y0, GP_Coord x1, GP_Coord y1,
+ GP_Context *dst, GP_Coord x2, GP_Coord y2)
+{
+ GP_Coord x, y, xt, yt;
+
+ for (y = y0; y <= y1; y++)
+ for (x = x0; x <= x1; x++) {
+ GP_Pixel p1, p2 = 0;
+ xt = x; yt = y;
+ GP_TRANSFORM_POINT(src, xt, yt);
+ p1 = GP_GetPixel_Raw_{{ src.pixelsize.suffix }}(src, xt, yt);
+ GP_Pixel_{{ src.name }}_TO_RGB888(p1, p2);
+ GP_Pixel_RGB888_TO_{{ dst.name }}(p2, p1);
+ xt = x2 + (x - x0);
+ yt = y2 + (y - y0);
+ GP_TRANSFORM_POINT(dst, xt, yt);
+ GP_PutPixel_Raw_{{ dst.pixelsize.suffix }}(dst, xt, yt, p1);
+ }
+}
+
+%% endif
+%% endif
+%% endfor
+%% endif
+%% endfor
+
+/*
+ * Same pixel type but with rotation.
+ */
+%% for ps in pixelsizes
+/*
+ * Blits for same pixel type and bpp {{ ps.suffix }}
+ */
+static void blitXYXY_{{ ps.suffix }}(const GP_Context *src,
+ GP_Coord x0, GP_Coord y0, GP_Coord x1, GP_Coord y1,
+ GP_Context *dst, GP_Coord x2, GP_Coord y2)
+{
+ GP_Coord x, y, xt, yt;
+
+ for (y = y0; y <= y1; y++)
+ for (x = x0; x <= x1; x++) {
+ GP_Pixel p;
+ xt = x; yt = y;
+ GP_TRANSFORM_POINT(src, xt, yt);
+ p = GP_GetPixel_Raw_{{ ps.suffix }}(src, xt, yt);
+ xt = x2 + (x - x0);
+ yt = y2 + (y - y0);
+ GP_TRANSFORM_POINT(dst, xt, yt);
+ GP_PutPixel_Raw_{{ ps.suffix }}(dst, xt, yt, p);
+ }
+}
+%% endfor
+
+void GP_BlitXYXY_Fast(const GP_Context *src,
+ GP_Coord x0, GP_Coord y0, GP_Coord x1, GP_Coord y1,
+ GP_Context *dst, GP_Coord x2, GP_Coord y2)
+{
+ /* Same pixel type */
+ if (src->pixel_type == dst->pixel_type) {
+ GP_FN_PER_BPP(blitXYXY, src->bpp, src->bit_endian,
+ src, x0, y0, x1, y1, dst, x2, y2);
+ return;
+ }
+
+ /* Specialized functions */
+ switch (src->pixel_type) {
+%% for src in pixeltypes
+%% if not src.is_unknown() and not src.is_palette()
+ case GP_PIXEL_{{ src.name }}:
+ switch (dst->pixel_type) {
+%% for dst in pixeltypes
+%% if not dst.is_unknown() and not dst.is_palette()
+%% if dst.name != src.name
+ case GP_PIXEL_{{ dst.name }}:
+ blitXYXY_{{ src.name }}_{{ dst.name }}(src, x0, y0, x1, y1, dst, x2, y2);
break;
%% endif
%% endif
-----------------------------------------------------------------------
Summary of changes:
include/core/GP_Blit.h | 7 ---
libs/core/GP_Blit.c | 13 +++--
libs/core/GP_Blit.gen.c.t | 120 +++++++++++++++++++++++++++++++++++++++++---
3 files changed, 119 insertions(+), 21 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: 8c91f2055c2d8a0f47593811e9ddb7261234d7b2
by metan 12 Feb '12
by metan 12 Feb '12
12 Feb '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 8c91f2055c2d8a0f47593811e9ddb7261234d7b2 (commit)
from 8dafb4ba1c30fc36d48f86e166212af3b7cf329c (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/8c91f2055c2d8a0f47593811e9ddb7261234…
commit 8c91f2055c2d8a0f47593811e9ddb7261234d7b2
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Sun Feb 12 12:08:48 2012 +0100
tests: blittest now tests rotated blits too.
diff --git a/tests/SDL/blittest.c b/tests/SDL/blittest.c
index 2198e04..5136200 100644
--- a/tests/SDL/blittest.c
+++ b/tests/SDL/blittest.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> *
* *
*****************************************************************************/
@@ -63,7 +63,7 @@ void redraw_screen(void)
bitmap_x += bitmap_vx;
bitmap_y += bitmap_vy;
- if (bitmap_x + bitmap->w > context.w) {
+ if (bitmap_x + GP_ContextW(bitmap) > context.w) {
bitmap_vx = -bitmap_vx;
bitmap_x += bitmap_vx;
}
@@ -73,7 +73,7 @@ void redraw_screen(void)
bitmap_x += bitmap_vx;
}
- if (bitmap_y + bitmap->h > context.h) {
+ if (bitmap_y + GP_ContextH(bitmap) > context.h) {
bitmap_vy = -bitmap_vy;
bitmap_y += bitmap_vy;
}
@@ -85,12 +85,21 @@ void redraw_screen(void)
SDL_LockSurface(display);
+ GP_FillRectXYWH(&context, 20, 20, 300, 50, black);
+
GP_Text(&context, NULL, 20, 20, GP_ALIGN_RIGHT|GP_VALIGN_BOTTOM,
white, black, text_buf);
- GP_Blit(bitmap, 0, 0, bitmap->w, bitmap->h, &context, bitmap_x, bitmap_y);
- SDL_UpdateRect(display, bitmap_x, bitmap_y, bitmap->w, bitmap->h);
- SDL_UpdateRect(display, 20, 20, 300, 50);
+ GP_Print(&context, NULL, 250, 20, GP_ALIGN_RIGHT|GP_VALIGN_BOTTOM,
+ white, black, "%c|%c|%c", bitmap->x_swap ? 'x' : ' ',
+ bitmap->y_swap ? 'y' : ' ', bitmap->axes_swap ? 'a' : ' ');
+
+ GP_Blit(bitmap, 0, 0, GP_ContextW(bitmap), GP_ContextH(bitmap),
+ &context, bitmap_x, bitmap_y);
+
+ SDL_UpdateRect(display, bitmap_x, bitmap_y,
+ GP_ContextW(bitmap), GP_ContextH(bitmap));
+ SDL_UpdateRect(display, 20, 20, 400, 50);
SDL_UnlockSurface(display);
}
@@ -102,11 +111,9 @@ static void change_bitmap(void)
else
bitmap = bitmap_raw;
- snprintf(text_buf, sizeof(text_buf), "Blitting '%s' -> '%s'",
+ snprintf(text_buf, sizeof(text_buf), "'%s' -> '%s'",
GP_PixelTypes[bitmap->pixel_type].name,
GP_PixelTypes[context.pixel_type].name);
-
- GP_FillRectXYWH(&context, 20, 20, 300, 50, black);
}
void event_loop(void)
@@ -125,12 +132,20 @@ void event_loop(void)
case SDLK_p:
pause_flag = !pause_flag;
break;
+ case SDLK_x:
+ bitmap->x_swap = !bitmap->x_swap;
+ break;
+ case SDLK_y:
+ bitmap->y_swap = !bitmap->y_swap;
+ break;
+ case SDLK_a:
+ bitmap->axes_swap = !bitmap->axes_swap;
+ break;
case SDLK_SPACE:
change_bitmap();
break;
case SDLK_ESCAPE:
return;
-
default:
break;
}
@@ -143,21 +158,34 @@ void event_loop(void)
}
}
+void print_instructions(void)
+{
+ printf("Use the following keys to control the test:n");
+ printf(" Esc ................. exitn");
+ printf(" Space ............... converts bitmap to screen pixel formatn");
+ printf(" A ................... swap sprite axesn");
+ printf(" X ................... mirror sprite Xn");
+ printf(" Y ................... mirror sprite Yn");
+ printf(" P ................... pausen");
+}
+
int main(int argc, char *argv[])
{
- /* Bits per pixel to be set for the display surface. */
int display_bpp = 0;
+ const char *sprite = "ball.ppm";
+
+ print_instructions();
int i;
for (i = 1; i < argc; i++) {
if (strcmp(argv[i], "-16") == 0) {
display_bpp = 16;
- }
- else if (strcmp(argv[i], "-24") == 0) {
+ } else if (strcmp(argv[i], "-24") == 0) {
display_bpp = 24;
- }
- else if (strcmp(argv[i], "-32") == 0) {
+ } else if (strcmp(argv[i], "-32") == 0) {
display_bpp = 32;
+ } else {
+ sprite = argv[i];
}
}
@@ -165,7 +193,7 @@ int main(int argc, char *argv[])
GP_RetCode ret;
- if ((ret = GP_LoadPPM("ball.ppm", &bitmap_raw))) {
+ if ((ret = GP_LoadImage(sprite, &bitmap_raw, NULL))) {
fprintf(stderr, "Failed to load bitmap: %sn", GP_RetCodeName(ret));
return 1;
}
-----------------------------------------------------------------------
Summary of changes:
tests/SDL/blittest.c | 60 ++++++++++++++++++++++++++++++++++++-------------
1 files changed, 44 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: 8dafb4ba1c30fc36d48f86e166212af3b7cf329c
by metan 11 Feb '12
by metan 11 Feb '12
11 Feb '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 8dafb4ba1c30fc36d48f86e166212af3b7cf329c (commit)
via 763bca3b9ac509c837ca940dcede58e58b86d21b (commit)
from 02901b7585b1265cedf68d019e7eb8ec5263c5a7 (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/8dafb4ba1c30fc36d48f86e166212af3b7cf…
commit 8dafb4ba1c30fc36d48f86e166212af3b7cf329c
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Sat Feb 11 21:39:59 2012 +0100
core: Much faster blit for most of the cases.
When src and dst have same pixel type and
orientation it's simple and fast memcpy in
most of the cases.
When src and dst have same orientation it's
optimized conversion loop more than 50% faster
than unspecialized even on small bitmaps and
about 5 times faster on fulscreen image blit.
Ultimate todo faster rotated blits.
diff --git a/include/core/GP_Blit.gen.h.t b/include/core/GP_Blit.gen.h.t
deleted file mode 100644
index cc1cc6e..0000000
--- a/include/core/GP_Blit.gen.h.t
+++ /dev/null
@@ -1,16 +0,0 @@
-%% extends "base.h.t"
-
-{% block descr %}Specialized blit functions and macros.{% endblock %}
-
-%% block body
-
-%% for ps in pixelsizes
-/*** Blit preserving type for {{ ps.suffix }} ***
- * Assumes the contexts to be of the right types and sizes
- * Ignores transformations and clipping */
-void GP_Blit_{{ ps.suffix }}(const GP_Context *c1, GP_Coord x1, GP_Coord y1, GP_Size w, GP_Size h,
- GP_Context *c2, GP_Coord x2, GP_Coord y2);
-
-%% endfor
-
-%% endblock body
diff --git a/include/core/GP_Blit.h b/include/core/GP_Blit.h
index 152df72..6c8ad84 100644
--- a/include/core/GP_Blit.h
+++ b/include/core/GP_Blit.h
@@ -39,9 +39,6 @@
#ifndef CORE_GP_BLIT_H
#define CORE_GP_BLIT_H
-/* Generated header */
-#include "GP_Blit.gen.h"
-
/*
* Blits rectangle from src defined by x0, y0, x1, y1 (x1, y1 included) to dst
* starting on x2, y2.
@@ -75,6 +72,13 @@ void GP_BlitXYXY_Raw(const GP_Context *src,
GP_Context *dst, GP_Coord x2, GP_Coord y2);
/*
+ * Naive get/put pixel implementation, used when everything else fails.
+ */
+void GP_BlitXYXY_Naive_Raw(const GP_Context *src,
+ GP_Coord x0, GP_Coord y0, GP_Coord x1, GP_Coord y1,
+ GP_Context *dst, GP_Coord x2, GP_Coord y2);
+
+/*
* Same as GP_BlitXYWH but doesn't respect rotations. Faster (for now).
*/
void GP_BlitXYWH_Raw(const GP_Context *src,
@@ -92,4 +96,6 @@ static inline void GP_Blit_Raw(const GP_Context *src,
GP_BlitXYWH_Raw(src, x0, y0, w0, h0, dst, x1, y1);
}
+
+
#endif /* CORE_GP_BLIT_H */
diff --git a/include/core/GP_Context.h b/include/core/GP_Context.h
index d91e54d..a6b76df 100644
--- a/include/core/GP_Context.h
+++ b/include/core/GP_Context.h
@@ -19,7 +19,7 @@
* Copyright (C) 2009-2011 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> *
* *
*****************************************************************************/
@@ -87,6 +87,14 @@ typedef struct GP_Context {
|| (y) < 0 || y >= (typeof(y)) context->h)
/*
+ * Check for exactly same rotation flags.
+ */
+#define GP_CONTEXT_ROTATION_EQUAL(c1, c2) + ((c1)->axes_swap == (c2)->axes_swap && + (c1)->x_swap == (c2)->x_swap && + (c1)->y_swap == (c2)->y_swap)
+
+/*
* Allocate context.
*/
GP_Context *GP_ContextAlloc(GP_Size w, GP_Size h, GP_PixelType type);
diff --git a/include/core/Makefile b/include/core/Makefile
index c9be7d8..bf82884 100644
--- a/include/core/Makefile
+++ b/include/core/Makefile
@@ -1,5 +1,5 @@
TOPDIR=../..
-GENHEADERS=GP_Convert_Scale.gen.h GP_Blit.gen.h GP_Pixel.gen.h +GENHEADERS=GP_Convert_Scale.gen.h GP_Pixel.gen.h GP_GetPutPixel.gen.h GP_Convert.gen.h GP_FnPerBpp.gen.h GP_MixPixels.gen.h GP_GammaCorrection.gen.h
LIBNAME=core
diff --git a/libs/core/GP_Blit.c b/libs/core/GP_Blit.c
index e7576d9..a31ef78 100644
--- a/libs/core/GP_Blit.c
+++ b/libs/core/GP_Blit.c
@@ -26,28 +26,18 @@
#include "GP_Context.h"
#include "GP_Convert.h"
#include "GP_Blit.h"
+#include "GP_FnPerBpp.h"
+
+/* Generated function */
+void GP_BlitXYXY_Raw_Fast(const GP_Context *src,
+ GP_Coord x0, GP_Coord y0, GP_Coord x1, GP_Coord y1,
+ GP_Context *dst, GP_Coord x2, GP_Coord y2);
+
void GP_BlitXYXY_Naive(const GP_Context *src,
GP_Coord x0, GP_Coord y0, GP_Coord x1, GP_Coord y1,
GP_Context *dst, GP_Coord x2, GP_Coord y2)
{
- /* Normalize source rectangle */
- if (x1 < x0)
- GP_SWAP(x0, x1);
-
- if (y1 < y0)
- GP_SWAP(y0, y1);
-
- /* All coordinates are inside of src the context */
- GP_CHECK(x0 < (GP_Coord)GP_ContextW(src));
- GP_CHECK(y0 < (GP_Coord)GP_ContextH(src));
- GP_CHECK(x1 < (GP_Coord)GP_ContextW(src));
- GP_CHECK(y1 < (GP_Coord)GP_ContextH(src));
-
- /* Destination is big enough */
- GP_CHECK(x2 + (x1 - x0) < (GP_Coord)GP_ContextW(dst));
- GP_CHECK(y2 + (y1 - y0) < (GP_Coord)GP_ContextH(dst));
-
GP_Coord x, y;
for (y = y0; y <= y1; y++)
@@ -65,7 +55,28 @@ void GP_BlitXYXY(const GP_Context *src,
GP_Coord x0, GP_Coord y0, GP_Coord x1, GP_Coord y1,
GP_Context *dst, GP_Coord x2, GP_Coord y2)
{
- //TODO
+ /* Normalize source rectangle */
+ if (x1 < x0)
+ GP_SWAP(x0, x1);
+
+ if (y1 < y0)
+ GP_SWAP(y0, y1);
+
+ /* All coordinates are inside of src the context */
+ GP_CHECK(x0 < (GP_Coord)GP_ContextW(src));
+ GP_CHECK(y0 < (GP_Coord)GP_ContextH(src));
+ GP_CHECK(x1 < (GP_Coord)GP_ContextW(src));
+ GP_CHECK(y1 < (GP_Coord)GP_ContextH(src));
+
+ /* Destination is big enough */
+ GP_CHECK(x2 + (x1 - x0) < (GP_Coord)GP_ContextW(dst));
+ GP_CHECK(y2 + (y1 - y0) < (GP_Coord)GP_ContextH(dst));
+
+ if (GP_CONTEXT_ROTATION_EQUAL(src, dst)) {
+ GP_BlitXYXY_Raw_Fast(src, x0, y0, x1, y1, dst, x2, y2);
+ return;
+ }
+
GP_BlitXYXY_Naive(src, x0, y0, x1, y1, dst, x2, y2);
}
@@ -79,10 +90,9 @@ void GP_BlitXYWH(const GP_Context *src,
GP_BlitXYXY(src, x0, y0, x0 + w0 - 1, y0 + h0 - 1, dst, x1, y1);
}
-
-void GP_BlitXYXY_Naive_Raw(const GP_Context *src,
- GP_Coord x0, GP_Coord y0, GP_Coord x1, GP_Coord y1,
- GP_Context *dst, GP_Coord x2, GP_Coord y2)
+void GP_BlitXYXY_Raw(const GP_Context *src,
+ GP_Coord x0, GP_Coord y0, GP_Coord x1, GP_Coord y1,
+ GP_Context *dst, GP_Coord x2, GP_Coord y2)
{
/* Normalize source rectangle */
if (x1 < x0)
@@ -101,24 +111,7 @@ void GP_BlitXYXY_Naive_Raw(const GP_Context *src,
GP_CHECK(x2 + (x1 - x0) < (GP_Coord)dst->w);
GP_CHECK(y2 + (y1 - y0) < (GP_Coord)dst->h);
- GP_Coord x, y;
-
- for (y = y0; y <= y1; y++)
- for (x = x0; x <= x1; x++) {
- GP_Pixel p = GP_GetPixel_Raw(src, x, y);
-
- if (src->pixel_type != dst->pixel_type)
- p = GP_ConvertContextPixel(p, src, dst);
-
- GP_PutPixel_Raw(dst, x2 + (x - x0), y2 + (y - y0), p);
- }
-}
-
-void GP_BlitXYXY_Raw(const GP_Context *src,
- GP_Coord x0, GP_Coord y0, GP_Coord x1, GP_Coord y1,
- GP_Context *dst, GP_Coord x2, GP_Coord y2)
-{
- GP_BlitXYXY_Naive_Raw(src, x0, y0, x1, y1, dst, x2, y2);
+ GP_BlitXYXY_Raw_Fast(src, x0, y0, x1, y1, dst, x2, y2);
}
void GP_BlitXYWH_Raw(const GP_Context *src,
diff --git a/libs/core/GP_Blit.gen.c.t b/libs/core/GP_Blit.gen.c.t
index 2259956..9d5c160 100644
--- a/libs/core/GP_Blit.gen.c.t
+++ b/libs/core/GP_Blit.gen.c.t
@@ -3,72 +3,178 @@
{% block descr %}Specialized blit functions and macros.{% endblock %}
%% block body
-#include <stdio.h>
#include <string.h>
-#include "GP_Pixel.h"
-#include "GP_GetPutPixel.h"
-#include "GP_Context.h"
-#include "GP_Blit.h"
-%% for ps in pixelsizes
-/*** Blit preservimg PixelType, variant for {{ ps.suffix }} ***/
-void GP_Blit_{{ ps.suffix }}(const GP_Context *c1, GP_Coord x1, GP_Coord y1, GP_Size w, GP_Size h,
- GP_Context *c2, GP_Coord x2, GP_Coord y2)
+#include "core/GP_Pixel.h"
+#include "core/GP_GetPutPixel.h"
+#include "core/GP_Context.h"
+#include "core/GP_Blit.h"
+#include "core/GP_Debug.h"
+#include "core/GP_Convert.h"
+#include "core/GP_Convert.gen.h"
+#include "core/GP_Convert_Scale.gen.h"
+
+/*
+ * TODO: this is used for same pixel but different offset, could still be optimized
+ */
+void blitXYXY_Naive_Raw(const GP_Context *src,
+ GP_Coord x0, GP_Coord y0, GP_Coord x1, GP_Coord y1,
+ GP_Context *dst, GP_Coord x2, GP_Coord y2)
{
- if (unlikely(w == 0 || h == 0)) return;
+ GP_Coord x, y;
+
+ for (y = y0; y <= y1; y++) {
+ for (x = x0; x <= x1; x++) {
+ GP_Pixel p = GP_GetPixel_Raw(src, x, y);
+
+ if (src->pixel_type != dst->pixel_type)
+ p = GP_ConvertContextPixel(p, src, dst);
+
+ GP_PutPixel_Raw(dst, x2 + (x - x0), y2 + (y - y0), p);
+ }
+ }
+}
+
+%% for ps in pixelsizes
+/*
+ * Blit for equal pixel types {{ ps.suffix }}
+ */
+void GP_BlitXYXY_Raw_{{ ps.suffix }}(const GP_Context *src,
+ GP_Coord x0, GP_Coord y0, GP_Coord x1, GP_Coord y1,
+ GP_Context *dst, GP_Coord x2, GP_Coord y2)
+{
/* Special case - copy whole line-block with one memcpy() */
- if ((x1 == 0) && (x2 == 0) && (w == c1->w) && (c1->w == c2->w) &&
- (c1->bytes_per_row == c2->bytes_per_row)) {
- memcpy(c2->pixels + c2->bytes_per_row * y2,
- c1->pixels + c1->bytes_per_row * y1,
- c1->bytes_per_row * h);
+ if ((x0 == 0) && (x2 == 0) && (x1 == (GP_Coord)src->w - 1) &&
+ (src->w == dst->w) &&
+ (src->bytes_per_row == dst->bytes_per_row)) {
+
+ memcpy(dst->pixels + dst->bytes_per_row * y2,
+ src->pixels + src->bytes_per_row * y0,
+ src->bytes_per_row * y1);
return;
}
%% if not ps.needs_bit_endian()
/* General case - memcpy() each horizontal line */
- GP_Size i;
+ GP_Coord y;
- for (i = 0; i < h; i++)
- memcpy(GP_PIXEL_ADDR_{{ ps.suffix }}(c2, x2, y2 + i),
- GP_PIXEL_ADDR_{{ ps.suffix }}(c1, x2, y2 + i),
- {{ ps.size/8 }} * w);
+ for (y = y0; y <= y1; y++)
+ memcpy(GP_PIXEL_ADDR_{{ ps.suffix }}(dst, x2, y2 + y),
+ GP_PIXEL_ADDR_{{ ps.suffix }}(src, x0, y0 + y),
+ {{ int(ps.size/8) }} * (x1 - x0 + 1));
%% else
/* Rectangles may not be bit-aligned in the same way! */
/* Alignment (index) of first bits in the first byte */
- int al1 = GP_PIXEL_ADDR_OFFSET_{{ ps.suffix }}(x1);
+ //TODO: This is wrong for subcontexts where the offset
+ // needs to be summed with context->offset and moduled
+ int al1 = GP_PIXEL_ADDR_OFFSET_{{ ps.suffix }}(x0);
int al2 = GP_PIXEL_ADDR_OFFSET_{{ ps.suffix }}(x2);
/* Special case of the same alignment and width >=2 bytes */
- if ((al1 == al2) && (w * {{ ps.size }} >= 16)) {
+ if ((al1 == al2) && ((x1 - x0 + 1) * {{ ps.size }} >= 16)) {
/* Number of bits in the last partial byte */
- int end_al = GP_PIXEL_ADDR_OFFSET_{{ ps.suffix }}(x1 + w);
- GP_ASSERT(({{ ps.size }} * w - al1 - end_al) % 8 == 0);
- int copy_size = ({{ ps.size }} * w - al1 - end_al) / 8;
+ int end_al = GP_PIXEL_ADDR_OFFSET_{{ ps.suffix }}(x1);
+ GP_ASSERT(({{ ps.size }} * (x1 - x0 + 1) - al1 - end_al) % 8 == 0);
+ int copy_size = ({{ ps.size }} * (x1 - x0 + 1) - al1 - end_al) / 8;
/* First and last byte incident to the line */
- uint8_t *p1 = (uint8_t *) GP_PIXEL_ADDR_{{ ps.suffix }}(c1, x1, y1);
- uint8_t *p2 = (uint8_t *) GP_PIXEL_ADDR_{{ ps.suffix }}(c2, x2, y2);
- uint8_t *end_p1 = (uint8_t *) GP_PIXEL_ADDR_{{ ps.suffix }}(c1, x1 + w - 1, y1);
- uint8_t *end_p2 = (uint8_t *) GP_PIXEL_ADDR_{{ ps.suffix }}(c2, x2 + w - 1, y2);
+ uint8_t *p1 = (uint8_t *) GP_PIXEL_ADDR_{{ ps.suffix }}(src, x1, y1);
+ uint8_t *p2 = (uint8_t *) GP_PIXEL_ADDR_{{ ps.suffix }}(dst, x2, y2);
+ uint8_t *end_p1 = (uint8_t *) GP_PIXEL_ADDR_{{ ps.suffix }}(src, x1, y0);
+ uint8_t *end_p2 = (uint8_t *) GP_PIXEL_ADDR_{{ ps.suffix }}(dst, x2, y2);
- GP_Size i;
+ GP_Coord i;
- for (i = 0; i < h; i++) {
+ for (i = 0; i < (y1 - y0 + 1); i++) {
if (al1 != 0)
GP_SET_BITS(al1, 8-al1, *p2, GP_GET_BITS(al1, 8-al1, *p1));
memcpy(p2+(al1!=0), p1+(al1!=0), copy_size);
if (end_al != 0)
GP_SET_BITS(0, end_al, *end_p2, GP_GET_BITS(0, end_al, *end_p1));
- p1 += c1->bytes_per_row;
- end_p1 += c1->bytes_per_row;
- p2 += c2->bytes_per_row;
- end_p2 += c2->bytes_per_row;
+ p1 += src->bytes_per_row;
+ end_p1 += src->bytes_per_row;
+ p2 += dst->bytes_per_row;
+ end_p2 += dst->bytes_per_row;
}
- }// else /* Different bit-alignment, can't use memcpy() */
- // GP_Blit_Naive(c1, x1, y1, w, h, c2, x2, y2);
+ } else /* Different bit-alignment, can't use memcpy() */
+ blitXYXY_Naive_Raw(src, x0, y0, x1, y1, dst, x2, y2);
%% endif
}
+%% endfor
+
+/*
+ * Generate Naive Blits, I know this is n^2 variants but the gain is in speed is
+ * more than 50% and the size footprint for two for cycles is really small.
+ */
+%% for src in pixeltypes
+%% if not src.is_unknown() and not src.is_palette()
+%% for dst in pixeltypes
+%% if not dst.is_unknown() and not dst.is_palette()
+%% if dst.name != src.name
+/*
+ * Blits {{ src.name }} to {{ dst.name }}
+ */
+static void blitXYXY_Naive_Raw_{{ src.name }}_{{ dst.name }}(const GP_Context *src,
+ GP_Coord x0, GP_Coord y0, GP_Coord x1, GP_Coord y1,
+ GP_Context *dst, GP_Coord x2, GP_Coord y2)
+{
+ GP_Coord x, y;
+
+ for (y = y0; y <= y1; y++)
+ for (x = x0; x <= x1; x++) {
+ GP_Pixel p1, p2 = 0;
+ p1 = GP_GetPixel_Raw_{{ src.pixelsize.suffix }}(src, x, y);
+ GP_Pixel_{{ src.name }}_TO_RGB888(p1, p2);
+ GP_Pixel_RGB888_TO_{{ dst.name }}(p2, p1);
+ GP_PutPixel_Raw_{{ dst.pixelsize.suffix }}(dst, x2 + (x - x0), y2 + (y - y0), p1);
+ }
+}
+
+%% endif
+%% endif
+%% endfor
+%% endif
+%% endfor
+
+void GP_BlitXYXY_Raw_Fast(const GP_Context *src,
+ GP_Coord x0, GP_Coord y0, GP_Coord x1, GP_Coord y1,
+ GP_Context *dst, GP_Coord x2, GP_Coord y2)
+{
+ /* Same pixel type, could be (mostly) optimized to memcpy() */
+ if (src->pixel_type == dst->pixel_type) {
+ GP_FN_PER_BPP(GP_BlitXYXY_Raw, src->bpp, src->bit_endian,
+ src, x0, y0, x1, y1, dst, x2, y2);
+ return;
+ }
+ /* Specialized naive functions */
+ switch (src->pixel_type) {
+%% for src in pixeltypes
+%% if not src.is_unknown() and not src.is_palette()
+ case GP_PIXEL_{{ src.name }}:
+ switch (dst->pixel_type) {
+%% for dst in pixeltypes
+%% if not dst.is_unknown() and not dst.is_palette()
+%% if dst.name != src.name
+ case GP_PIXEL_{{ dst.name }}:
+ blitXYXY_Naive_Raw_{{ src.name }}_{{ dst.name }}(src, x0, y0,
+ x1, y1,
+ dst, x2, y2);
+ break;
+%% endif
+%% endif
+%% endfor
+ default:
+ GP_ABORT("Invalid destination pixel %s",
+ GP_PixelTypeName(dst->pixel_type));
+ }
+ break;
+%% endif
%% endfor
+ default:
+ GP_ABORT("Invalid source pixel %s",
+ GP_PixelTypeName(src->pixel_type));
+ }
+}
+
%% endblock body
http://repo.or.cz/w/gfxprim.git/commit/763bca3b9ac509c837ca940dcede58e58b86…
commit 763bca3b9ac509c837ca940dcede58e58b86d21b
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Sat Feb 11 21:34:50 2012 +0100
demos: fbshow add timer for blit measuring.
diff --git a/demos/fbshow/fbshow.c b/demos/fbshow/fbshow.c
index 5e3e06d..83bed96 100644
--- a/demos/fbshow/fbshow.c
+++ b/demos/fbshow/fbshow.c
@@ -211,7 +211,9 @@ static void *image_loader(void *ptr)
uint32_t cx = (context->w - ret->w)/2;
uint32_t cy = (context->h - ret->h)/2;
+ cpu_timer_start(&timer, "Blitting");
GP_Blit_Raw(ret, 0, 0, ret->w, ret->h, context, cx, cy);
+ cpu_timer_stop(&timer);
GP_ContextFree(ret);
/* clean up the rest of the display */
-----------------------------------------------------------------------
Summary of changes:
demos/fbshow/fbshow.c | 2 +
include/core/GP_Blit.gen.h.t | 16 ----
include/core/GP_Blit.h | 12 ++-
include/core/GP_Context.h | 10 ++-
include/core/Makefile | 2 +-
libs/core/GP_Blit.c | 73 ++++++++---------
libs/core/GP_Blit.gen.c.t | 180 +++++++++++++++++++++++++++++++++---------
7 files changed, 197 insertions(+), 98 deletions(-)
delete mode 100644 include/core/GP_Blit.gen.h.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: 02901b7585b1265cedf68d019e7eb8ec5263c5a7
by metan 11 Feb '12
by metan 11 Feb '12
11 Feb '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 02901b7585b1265cedf68d019e7eb8ec5263c5a7 (commit)
via d170475005b04f6e2a1d69283760c0bc03bc4d64 (commit)
via 173957cead4c3099479976cfd3a5b62f3d2b0f56 (commit)
from e659d64782d1f5d6c93fc1547c81d941b5ea45bc (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/02901b7585b1265cedf68d019e7eb8ec5263…
commit 02901b7585b1265cedf68d019e7eb8ec5263c5a7
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Sat Feb 11 18:40:33 2012 +0100
core: Cleanup Blit interface.
It's same old slow blit, this just cleans up the interface.
diff --git a/include/core/GP_Blit.h b/include/core/GP_Blit.h
index f772ce0..152df72 100644
--- a/include/core/GP_Blit.h
+++ b/include/core/GP_Blit.h
@@ -21,36 +21,75 @@
* *
*****************************************************************************/
+/*
+
+ These blits automatically converts pixel types, that's good (and fast), but
+ there is a catch. This works rather well when the number of colors per
+ pixel/color channel is increased (the gamma correction is still on TODO).
+ However when the number of colors is decreased it's generally better to use
+ dithering, which will yield into far better (you can use Floyd Steinberg
+ filter for that).
+
+ Also variants without the _Raw suffix do honor the rotation flags, that may
+ get a little tricky as the flags for rotation are put together but don't
+ worry althouth there is some algebra involved the result is quite intuitive.
+
+ */
+
#ifndef CORE_GP_BLIT_H
#define CORE_GP_BLIT_H
/* Generated header */
#include "GP_Blit.gen.h"
-void GP_Blit(const GP_Context *c1, GP_Coord x1, GP_Coord y1,
- GP_Size w, GP_Size h, GP_Context *c2, GP_Coord x2, GP_Coord y2);
+/*
+ * Blits rectangle from src defined by x0, y0, x1, y1 (x1, y1 included) to dst
+ * starting on x2, y2.
+ */
+void GP_BlitXYXY(const GP_Context *src,
+ GP_Coord x0, GP_Coord y0, GP_Coord x1, GP_Coord y1,
+ GP_Context *dst, GP_Coord x2, GP_Coord y2);
/*
- * Doesn't respect rotations. Most of the time faster.
+ * Blits rectangle from src defined by x0, y0, w0, h0 (uses w0 x h0 pixels) to
+ * dst starting on x2, y2.
*/
-void GP_Blit_Raw(const GP_Context *c1, GP_Coord x1, GP_Coord y1,
- GP_Size w, GP_Size h, GP_Context *c2, GP_Coord x2, GP_Coord y2);
+void GP_BlitXYWH(const GP_Context *src,
+ GP_Coord x0, GP_Coord y0, GP_Size w0, GP_Size h0,
+ GP_Context *dst, GP_Coord x1, GP_Coord y1);
+/* The default is XYWH now, will be changed */
+static inline void GP_Blit(const GP_Context *src,
+ GP_Coord x0, GP_Coord y0,
+ GP_Size w0, GP_Size h0,
+ GP_Context *dst, GP_Coord x1, GP_Coord y1)
+{
+ GP_BlitXYWH(src, x0, y0, w0, h0, dst, x1, y1);
+}
/*
- * Very naive blit, no optimalizations whatsoever - keep it that way.
- * Used as a reference for testing and such. Aaand ultimate fallback.
- * GP_CHECKS for clipping and size (for testing)
+ * Same as GP_BlitXYXY but doesn't respect rotations. Faster (for now).
*/
-void GP_Blit_Naive(const GP_Context *c1, GP_Coord x1, GP_Coord y1, GP_Size w, GP_Size h,
- GP_Context *c2, GP_Coord x2, GP_Coord y2);
+void GP_BlitXYXY_Raw(const GP_Context *src,
+ GP_Coord x0, GP_Coord y0, GP_Coord x1, GP_Coord y1,
+ GP_Context *dst, GP_Coord x2, GP_Coord y2);
-/*
- * Similar in purpose to GP_Blit_Naive, but operates on raw coordinates.
- * Does no range checking.
+/*
+ * Same as GP_BlitXYWH but doesn't respect rotations. Faster (for now).
*/
+void GP_BlitXYWH_Raw(const GP_Context *src,
+ GP_Coord x0, GP_Coord y0, GP_Size w0, GP_Size h0,
+ GP_Context *dst, GP_Coord x2, GP_Coord y2);
+
/*
-void GP_Blit_Naive_Raw(const GP_Context *c1, int x1, int y1, int w, int h,
- GP_Context *c2, int x2, int y2);
-*/
-#endif // CORE_GP_BLIT_H
+ * Same as GP_Blit but doesn't respect rotations. Faster (for now).
+ */
+static inline void GP_Blit_Raw(const GP_Context *src,
+ GP_Coord x0, GP_Coord y0,
+ GP_Size w0, GP_Size h0,
+ GP_Context *dst, GP_Coord x1, GP_Coord y1)
+{
+ GP_BlitXYWH_Raw(src, x0, y0, w0, h0, dst, x1, y1);
+}
+
+#endif /* CORE_GP_BLIT_H */
diff --git a/libs/core/GP_Blit.c b/libs/core/GP_Blit.c
index 9bcb80e..e7576d9 100644
--- a/libs/core/GP_Blit.c
+++ b/libs/core/GP_Blit.c
@@ -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> *
* *
*****************************************************************************/
@@ -27,79 +27,106 @@
#include "GP_Convert.h"
#include "GP_Blit.h"
-void GP_Blit(const GP_Context *c1, GP_Coord x1, GP_Coord y1,
- GP_Size w, GP_Size h, GP_Context *c2, GP_Coord x2, GP_Coord y2)
+void GP_BlitXYXY_Naive(const GP_Context *src,
+ GP_Coord x0, GP_Coord y0, GP_Coord x1, GP_Coord y1,
+ GP_Context *dst, GP_Coord x2, GP_Coord y2)
{
- // Ultimate TODO: effective processing
- GP_Blit_Naive(c1, x1, y1, w, h, c2, x2, y2);
+ /* Normalize source rectangle */
+ if (x1 < x0)
+ GP_SWAP(x0, x1);
+
+ if (y1 < y0)
+ GP_SWAP(y0, y1);
+
+ /* All coordinates are inside of src the context */
+ GP_CHECK(x0 < (GP_Coord)GP_ContextW(src));
+ GP_CHECK(y0 < (GP_Coord)GP_ContextH(src));
+ GP_CHECK(x1 < (GP_Coord)GP_ContextW(src));
+ GP_CHECK(y1 < (GP_Coord)GP_ContextH(src));
+
+ /* Destination is big enough */
+ GP_CHECK(x2 + (x1 - x0) < (GP_Coord)GP_ContextW(dst));
+ GP_CHECK(y2 + (y1 - y0) < (GP_Coord)GP_ContextH(dst));
+
+ GP_Coord x, y;
+
+ for (y = y0; y <= y1; y++)
+ for (x = x0; x <= x1; x++) {
+ GP_Pixel p = GP_GetPixel(src, x, y);
+
+ if (src->pixel_type != dst->pixel_type)
+ p = GP_ConvertContextPixel(p, src, dst);
+
+ GP_PutPixel(dst, x2 + (x - x0), y2 + (y - y0), p);
+ }
}
-// TODO(gavento, czech) Plan:
-// GP_Blit_Naive - Zadne rotovani a tak, jen Get/PutPixel a konverze A->RGBA8888->B
-// GP_Blit_Simple - S rotovanim, makrovy Get/PutPixel, mozna optimalizace na radky, chytrejsi konverze (ale porad univ.)
-// GP_Blit_Simple_xBPP - S rotovanim, makrovy Get/PutPixel
-// GP_Blit_xBPP - Optimalizovane, muze volat GP_Blit_Simple_xBPP pro divne pripady
-// GP_Blit - Vola GP_Blit_xBPP (stejny typ) nebo GP_Blit_Simple (jine typy), pripadne optimalizovat
+void GP_BlitXYXY(const GP_Context *src,
+ GP_Coord x0, GP_Coord y0, GP_Coord x1, GP_Coord y1,
+ GP_Context *dst, GP_Coord x2, GP_Coord y2)
+{
+ //TODO
+ GP_BlitXYXY_Naive(src, x0, y0, x1, y1, dst, x2, y2);
+}
-/*
-void GP_Blit_Naive(const GP_Context *c1, int x1, int y1, int w, int h,
- GP_Context *c2, int x2, int y2)
+void GP_BlitXYWH(const GP_Context *src,
+ GP_Coord x0, GP_Coord y0, GP_Size w0, GP_Size h0,
+ GP_Context *dst, GP_Coord x1, GP_Coord y1)
{
- GP_TRANSFORM_BLIT(c1, x1, y1, w, h, c2, x2, y2);
- // TODO: Cipping?
- GP_Blit_Naive_Raw(c1, x1, y1, w, h, c2, x2, y2);
+ if (w0 == 0 || h0 == 0)
+ return;
+
+ GP_BlitXYXY(src, x0, y0, x0 + w0 - 1, y0 + h0 - 1, dst, x1, y1);
}
-*/
-void GP_Blit_Naive_Raw(const GP_Context *c1, GP_Coord x1, GP_Coord y1, GP_Size w, GP_Size h,
- GP_Context *c2, GP_Coord x2, GP_Coord y2)
+
+void GP_BlitXYXY_Naive_Raw(const GP_Context *src,
+ GP_Coord x0, GP_Coord y0, GP_Coord x1, GP_Coord y1,
+ GP_Context *dst, GP_Coord x2, GP_Coord y2)
{
- GP_CHECK(x1 >= 0);
- GP_CHECK(y1 >= 0);
- GP_CHECK(x1 + w <= GP_ContextW(c1));
- GP_CHECK(y1 + h <= GP_ContextH(c1));
- GP_CHECK(x2 >= 0);
- GP_CHECK(y2 >= 0);
- GP_CHECK(x2 + w <= GP_ContextW(c2));
- GP_CHECK(y2 + h <= GP_ContextH(c2));
-
- GP_Size i, j;
-
- for (i = 0; i < w; i++)
- for (j = 0; j < h; j++) {
- GP_Pixel p = GP_GetPixel_Raw(c1, x1 + i, y1 + j);
- if (c1->pixel_type != c2->pixel_type)
- p = GP_ConvertContextPixel(p, c1, c2);
- GP_PutPixel_Raw(c2, x2 + i, y2 + j, p);
+ /* Normalize source rectangle */
+ if (x1 < x0)
+ GP_SWAP(x0, x1);
+
+ if (y1 < y0)
+ GP_SWAP(y0, y1);
+
+ /* All coordinates are inside of src the context */
+ GP_CHECK(x0 < (GP_Coord)src->w);
+ GP_CHECK(y0 < (GP_Coord)src->h);
+ GP_CHECK(x1 < (GP_Coord)src->w);
+ GP_CHECK(y1 < (GP_Coord)src->h);
+
+ /* Destination is big enough */
+ GP_CHECK(x2 + (x1 - x0) < (GP_Coord)dst->w);
+ GP_CHECK(y2 + (y1 - y0) < (GP_Coord)dst->h);
+
+ GP_Coord x, y;
+
+ for (y = y0; y <= y1; y++)
+ for (x = x0; x <= x1; x++) {
+ GP_Pixel p = GP_GetPixel_Raw(src, x, y);
+
+ if (src->pixel_type != dst->pixel_type)
+ p = GP_ConvertContextPixel(p, src, dst);
+
+ GP_PutPixel_Raw(dst, x2 + (x - x0), y2 + (y - y0), p);
}
}
-void GP_Blit_Raw(const GP_Context *c1, GP_Coord x1, GP_Coord y1,
- GP_Size w, GP_Size h, GP_Context *c2, GP_Coord x2, GP_Coord y2)
+void GP_BlitXYXY_Raw(const GP_Context *src,
+ GP_Coord x0, GP_Coord y0, GP_Coord x1, GP_Coord y1,
+ GP_Context *dst, GP_Coord x2, GP_Coord y2)
{
- // Ultimate TODO: effective processing
- GP_Blit_Naive_Raw(c1, x1, y1, w, h, c2, x2, y2);
+ GP_BlitXYXY_Naive_Raw(src, x0, y0, x1, y1, dst, x2, y2);
}
-void GP_Blit_Naive(const GP_Context *c1, GP_Coord x1, GP_Coord y1, GP_Size w, GP_Size h,
- GP_Context *c2, GP_Coord x2, GP_Coord y2)
+void GP_BlitXYWH_Raw(const GP_Context *src,
+ GP_Coord x0, GP_Coord y0, GP_Size w0, GP_Size h0,
+ GP_Context *dst, GP_Coord x2, GP_Coord y2)
{
- GP_CHECK(x1 >= 0);
- GP_CHECK(y1 >= 0);
- GP_CHECK(x1 + w <= GP_ContextW(c1));
- GP_CHECK(y1 + h <= GP_ContextH(c1));
- GP_CHECK(x2 >= 0);
- GP_CHECK(y2 >= 0);
- GP_CHECK(x2 + w <= GP_ContextW(c2));
- GP_CHECK(y2 + h <= GP_ContextH(c2));
-
- GP_Size i, j;
-
- for (i = 0; i < w; i++)
- for (j = 0; j < h; j++) {
- GP_Pixel p = GP_GetPixel(c1, x1 + i, y1 + j);
- if (c1->pixel_type != c2->pixel_type)
- p = GP_ConvertContextPixel(p, c1, c2);
- GP_PutPixel(c2, x2 + i, y2 + j, p);
- }
+ if (w0 == 0 || h0 == 0)
+ return;
+
+ GP_BlitXYXY_Raw(src, x0, y0, x0 + w0 - 1, y0 + h0 - 1, dst, x2, y2);
}
diff --git a/libs/core/GP_Blit.gen.c.t b/libs/core/GP_Blit.gen.c.t
index 2bc3f69..2259956 100644
--- a/libs/core/GP_Blit.gen.c.t
+++ b/libs/core/GP_Blit.gen.c.t
@@ -64,8 +64,8 @@ void GP_Blit_{{ ps.suffix }}(const GP_Context *c1, GP_Coord x1, GP_Coord y1, GP_
p2 += c2->bytes_per_row;
end_p2 += c2->bytes_per_row;
}
- } else /* Different bit-alignment, can't use memcpy() */
- GP_Blit_Naive(c1, x1, y1, w, h, c2, x2, y2);
+ }// else /* Different bit-alignment, can't use memcpy() */
+ // GP_Blit_Naive(c1, x1, y1, w, h, c2, x2, y2);
%% endif
}
http://repo.or.cz/w/gfxprim.git/commit/d170475005b04f6e2a1d69283760c0bc03bc…
commit d170475005b04f6e2a1d69283760c0bc03bc4d64
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Sat Feb 11 18:40:21 2012 +0100
core: Remove unused code from Fixed point.
diff --git a/include/core/GP_FixedPoint.h b/include/core/GP_FixedPoint.h
index 33029ad..77e802f 100644
--- a/include/core/GP_FixedPoint.h
+++ b/include/core/GP_FixedPoint.h
@@ -34,8 +34,6 @@
#include <stdint.h>
-typedef uint8_t GP_FP_Frac;
-
/*
* Number of bits used for fractional part.
*/
http://repo.or.cz/w/gfxprim.git/commit/173957cead4c3099479976cfd3a5b62f3d2b…
commit 173957cead4c3099479976cfd3a5b62f3d2b0f56
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Sat Feb 11 18:39:57 2012 +0100
tests: Add pause flag for linetest.
diff --git a/tests/SDL/linetest.c b/tests/SDL/linetest.c
index 9e35f96..5a2e082 100644
--- a/tests/SDL/linetest.c
+++ b/tests/SDL/linetest.c
@@ -55,6 +55,7 @@ Uint32 timer_callback(__attribute__((unused)) Uint32 interval,
double start_angle = 0.0;
static int aa_flag = 0;
+static int pause_flag = 0;
void redraw_screen(void)
{
@@ -101,6 +102,10 @@ void event_loop(void)
case SDL_USEREVENT:
redraw_screen();
SDL_Flip(display);
+
+ if (pause_flag)
+ continue;
+
start_angle += 0.01;
if (start_angle > 2*M_PI) {
start_angle = 0.0;
@@ -111,6 +116,9 @@ void event_loop(void)
case SDLK_a:
aa_flag = !aa_flag;
break;
+ case SDLK_p:
+ pause_flag = !pause_flag;
+ break;
default:
return;
}
-----------------------------------------------------------------------
Summary of changes:
include/core/GP_Blit.h | 73 ++++++++++++++++-----
include/core/GP_FixedPoint.h | 2 -
libs/core/GP_Blit.c | 149 +++++++++++++++++++++++++-----------------
libs/core/GP_Blit.gen.c.t | 4 +-
tests/SDL/linetest.c | 8 ++
5 files changed, 154 insertions(+), 82 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: e659d64782d1f5d6c93fc1547c81d941b5ea45bc
by metan 08 Feb '12
by metan 08 Feb '12
08 Feb '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 e659d64782d1f5d6c93fc1547c81d941b5ea45bc (commit)
from c9a9d19055f9add550845b8e3c9050e7e32467c2 (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/e659d64782d1f5d6c93fc1547c81d941b5ea…
commit e659d64782d1f5d6c93fc1547c81d941b5ea45bc
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Wed Feb 8 20:27:09 2012 +0100
tests: Add LineAA to linetest.
* The key 'a' now changes between anti aliased
and normal lines.
diff --git a/tests/SDL/linetest.c b/tests/SDL/linetest.c
index 1b01a3a..9e35f96 100644
--- a/tests/SDL/linetest.c
+++ b/tests/SDL/linetest.c
@@ -54,6 +54,8 @@ Uint32 timer_callback(__attribute__((unused)) Uint32 interval,
double start_angle = 0.0;
+static int aa_flag = 0;
+
void redraw_screen(void)
{
double angle;
@@ -74,17 +76,18 @@ void redraw_screen(void)
GP_Pixel pixel;
pixel = GP_RGBToPixel(r, 0, b, context.pixel_type);
- /*
- * Draw the line forth and back to detect any pixel change
- * between one direction and the other.
- */
- GP_Line(&context, xcenter, ycenter, xcenter + x, ycenter + y, pixel);
- GP_Line(&context, xcenter + x, ycenter + y, xcenter, ycenter, pixel);
+ if (aa_flag) {
+ GP_LineAA_Raw(&context, GP_FP_FROM_INT(xcenter), GP_FP_FROM_INT(ycenter),
+ GP_FP_FROM_INT(xcenter + x), GP_FP_FROM_INT(ycenter + y), pixel);
+ } else {
+ GP_Line(&context, xcenter + x, ycenter + y, xcenter, ycenter, pixel);
+ GP_Line(&context, xcenter, ycenter, xcenter + x, ycenter + y, pixel);
+ }
}
/* axes */
- GP_HLineXYW(&context, 0, ycenter, display->w, white);
- GP_VLineXYH(&context, xcenter, 0, display->h, white);
+// GP_HLineXYW(&context, 0, ycenter, display->w, white);
+// GP_VLineXYH(&context, xcenter, 0, display->h, white);
SDL_UnlockSurface(display);
}
@@ -95,17 +98,25 @@ void event_loop(void)
while (SDL_WaitEvent(&event) > 0) {
switch (event.type) {
- case SDL_USEREVENT:
- redraw_screen();
- SDL_Flip(display);
- start_angle += 0.01;
- if (start_angle > 2*M_PI) {
- start_angle = 0.0;
- }
+ case SDL_USEREVENT:
+ redraw_screen();
+ SDL_Flip(display);
+ start_angle += 0.01;
+ if (start_angle > 2*M_PI) {
+ start_angle = 0.0;
+ }
+ break;
+ case SDL_KEYDOWN:
+ switch (event.key.keysym.sym) {
+ case SDLK_a:
+ aa_flag = !aa_flag;
break;
- case SDL_KEYDOWN:
- case SDL_QUIT:
+ default:
return;
+ }
+ break;
+ case SDL_QUIT:
+ return;
}
}
}
-----------------------------------------------------------------------
Summary of changes:
tests/SDL/linetest.c | 45 ++++++++++++++++++++++++++++-----------------
1 files changed, 28 insertions(+), 17 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: c9a9d19055f9add550845b8e3c9050e7e32467c2
by metan 08 Feb '12
by metan 08 Feb '12
08 Feb '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 c9a9d19055f9add550845b8e3c9050e7e32467c2 (commit)
via b98ab667d547b2de4ad9d8fdb2c5d1dee4e65419 (commit)
from 4c14716c974906c490a2f96bdbd0cef840fe1812 (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/c9a9d19055f9add550845b8e3c9050e7e324…
commit c9a9d19055f9add550845b8e3c9050e7e32467c2
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Wed Feb 8 20:21:44 2012 +0100
gfx: LineAA nearly complete
diff --git a/libs/gfx/GP_LineAA.gen.c.t b/libs/gfx/GP_LineAA.gen.c.t
index 6bbc22f..2bf413f 100644
--- a/libs/gfx/GP_LineAA.gen.c.t
+++ b/libs/gfx/GP_LineAA.gen.c.t
@@ -14,39 +14,21 @@
#define FP_TO_PERC(a) (GP_FP_ROUND_TO_INT((a) * 255))
-void GP_LineAA_Raw(GP_Context *context, GP_Coord x0, GP_Coord y0,
- GP_Coord x1, GP_Coord y1, GP_Pixel pixel)
+static inline void line_aa_x(GP_Context *context,
+ GP_Coord x0, GP_Coord y0,
+ GP_Coord x1, GP_Coord y1, GP_Pixel pixel)
{
+ GP_Coord xend, yend, xgap, xpx0, ypx0, xpx1, ypx1;
+ uint8_t perc;
+
int64_t dx = x1 - x0;
int64_t dy = y1 - y0;
-
- if (dy == 0) {
- //TODO!!!
- GP_HLine_Raw(context, GP_FP_ROUND_TO_INT(x0), GP_FP_ROUND_TO_INT(x1),
- GP_FP_ROUND_TO_INT(y0), pixel);
- return;
- }
-
- if (dx == 0) {
- //TODO!!!
- GP_VLine(context, GP_FP_ROUND_TO_INT(x0), GP_FP_ROUND_TO_INT(y0),
- GP_FP_ROUND_TO_INT(y1), pixel);
- return;
- }
-
- if (GP_ABS(dx) < GP_ABS(dy)) {
- //TODO
- return;
- }
if (x1 < x0) {
GP_SWAP(x0, x1);
GP_SWAP(y0, y1);
}
- GP_Coord xend, yend, xgap, xpx0, ypx0, xpx1, ypx1;
- uint8_t perc;
-
xend = GP_FP_ROUND(x1);
yend = y1 + GP_FP_DIV(GP_FP_MUL(dy, xend - x1), dx);
xgap = GP_FP_FRAC(x1 + GP_FP_1_2);
@@ -74,9 +56,88 @@ void GP_LineAA_Raw(GP_Context *context, GP_Coord x0, GP_Coord y0,
for (x = xpx0 + 1; x < xpx1; x++) {
intery = yend + GP_FP_DIV((x - xpx0) * dy, dx);
- GP_MixPixel_Raw_Clipped(context, x, GP_FP_TO_INT(intery), pixel, FP_TO_PERC(GP_FP_RFRAC(intery)));
- GP_MixPixel_Raw_Clipped(context, x, GP_FP_TO_INT(intery) + 1, pixel, FP_TO_PERC(GP_FP_FRAC(intery)));
+
+ perc = FP_TO_PERC(GP_FP_RFRAC(intery));
+ GP_MixPixel_Raw_Clipped(context, x, GP_FP_TO_INT(intery), pixel, perc);
+ perc = FP_TO_PERC(GP_FP_FRAC(intery));
+ GP_MixPixel_Raw_Clipped(context, x, GP_FP_TO_INT(intery)+1, pixel, perc);
+ }
+}
+
+static inline void line_aa_y(GP_Context *context,
+ GP_Coord x0, GP_Coord y0,
+ GP_Coord x1, GP_Coord y1, GP_Pixel pixel)
+{
+ GP_Coord xend, yend, ygap, xpx0, ypx0, xpx1, ypx1;
+ uint8_t perc;
+
+ int64_t dx = x1 - x0;
+ int64_t dy = y1 - y0;
+
+ if (y1 < y0) {
+ GP_SWAP(x0, x1);
+ GP_SWAP(y0, y1);
+ }
+
+ yend = GP_FP_ROUND(y1);
+ xend = x1 + GP_FP_DIV(GP_FP_MUL(dx, yend - y1), dy);
+ ygap = GP_FP_FRAC(y1 + GP_FP_1_2);
+ ypx1 = GP_FP_TO_INT(yend);
+ xpx1 = GP_FP_TO_INT(xend);
+
+ perc = FP_TO_PERC(GP_FP_MUL(GP_FP_RFRAC(xend), ygap));
+ GP_MixPixel_Raw_Clipped(context, xpx1, ypx1, pixel, perc);
+ perc = FP_TO_PERC(GP_FP_MUL(GP_FP_FRAC(xend), ygap));
+ GP_MixPixel_Raw_Clipped(context, xpx1, ypx1+1, pixel, perc);
+
+ yend = GP_FP_ROUND(y0);
+ xend = x0 + GP_FP_DIV(GP_FP_MUL(dx, yend - y0), dy);
+ ygap = GP_FP_RFRAC(y0 + GP_FP_1_2);
+ ypx0 = GP_FP_TO_INT(yend);
+ xpx0 = GP_FP_TO_INT(xend);
+
+ perc = FP_TO_PERC(GP_FP_MUL(GP_FP_RFRAC(xend), ygap));
+ GP_MixPixel_Raw_Clipped(context, xpx0, ypx0, pixel, perc);
+ perc = FP_TO_PERC(GP_FP_MUL(GP_FP_FRAC(xend), ygap));
+ GP_MixPixel_Raw_Clipped(context, xpx0, ypx0+1, pixel, perc);
+
+ GP_Coord y;
+ GP_Coord intery;
+
+ for (y = ypx0 + 1; y < ypx1; y++) {
+ intery = xend + GP_FP_DIV((y - ypx0) * dx, dy);
+
+ perc = FP_TO_PERC(GP_FP_RFRAC(intery));
+ GP_MixPixel_Raw_Clipped(context, GP_FP_TO_INT(intery), y, pixel, perc);
+ perc = FP_TO_PERC(GP_FP_FRAC(intery));
+ GP_MixPixel_Raw_Clipped(context, GP_FP_TO_INT(intery)+1, y, pixel, perc);
}
}
+void GP_LineAA_Raw(GP_Context *context, GP_Coord x0, GP_Coord y0,
+ GP_Coord x1, GP_Coord y1, GP_Pixel pixel)
+{
+ int64_t dx = x1 - x0;
+ int64_t dy = y1 - y0;
+
+ if (dy == 0) {
+ //TODO!!!
+ GP_HLine_Raw(context, GP_FP_ROUND_TO_INT(x0), GP_FP_ROUND_TO_INT(x1),
+ GP_FP_ROUND_TO_INT(y0), pixel);
+ return;
+ }
+
+ if (dx == 0) {
+ //TODO!!!
+ GP_VLine(context, GP_FP_ROUND_TO_INT(x0), GP_FP_ROUND_TO_INT(y0),
+ GP_FP_ROUND_TO_INT(y1), pixel);
+ return;
+ }
+
+ if (GP_ABS(dx) < GP_ABS(dy))
+ line_aa_y(context, x0, y0, x1, y1, pixel);
+ else
+ line_aa_x(context, x0, y0, x1, y1, pixel);
+}
+
%% endblock body
http://repo.or.cz/w/gfxprim.git/commit/b98ab667d547b2de4ad9d8fdb2c5d1dee4e6…
commit b98ab667d547b2de4ad9d8fdb2c5d1dee4e65419
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Wed Feb 8 20:13:20 2012 +0100
gfx: LineAA fix typo, reorder code.
diff --git a/libs/gfx/GP_LineAA.gen.c.t b/libs/gfx/GP_LineAA.gen.c.t
index 37af24e..6bbc22f 100644
--- a/libs/gfx/GP_LineAA.gen.c.t
+++ b/libs/gfx/GP_LineAA.gen.c.t
@@ -22,15 +22,15 @@ void GP_LineAA_Raw(GP_Context *context, GP_Coord x0, GP_Coord y0,
if (dy == 0) {
//TODO!!!
- //GP_HLine_Raw(context, GP_FP_ROUND_TO_INT(x0), GP_FP_ROUND_TO_INT(x1),
- // GP_FP_ROUND_TO_INT(y0), pixel);
+ GP_HLine_Raw(context, GP_FP_ROUND_TO_INT(x0), GP_FP_ROUND_TO_INT(x1),
+ GP_FP_ROUND_TO_INT(y0), pixel);
return;
}
if (dx == 0) {
//TODO!!!
- //GP_VLine(context, GP_FP_ROUND_TO_INT(x0), GP_FP_ROUND_TO_INT(y0),
- // GP_FP_ROUND_TO_INT(y1), pixel);
+ GP_VLine(context, GP_FP_ROUND_TO_INT(x0), GP_FP_ROUND_TO_INT(y0),
+ GP_FP_ROUND_TO_INT(y1), pixel);
return;
}
@@ -44,9 +44,20 @@ void GP_LineAA_Raw(GP_Context *context, GP_Coord x0, GP_Coord y0,
GP_SWAP(y0, y1);
}
- GP_Coord xend, yend, xgap, xpx0, ypx0, xpx1, ypx1, ddd;
+ GP_Coord xend, yend, xgap, xpx0, ypx0, xpx1, ypx1;
uint8_t perc;
+ xend = GP_FP_ROUND(x1);
+ yend = y1 + GP_FP_DIV(GP_FP_MUL(dy, xend - x1), dx);
+ xgap = GP_FP_FRAC(x1 + GP_FP_1_2);
+ xpx1 = GP_FP_TO_INT(xend);
+ ypx1 = GP_FP_TO_INT(yend);
+
+ perc = FP_TO_PERC(GP_FP_MUL(GP_FP_RFRAC(yend), xgap));
+ GP_MixPixel_Raw_Clipped(context, xpx1, ypx1, pixel, perc);
+ perc = FP_TO_PERC(GP_FP_MUL(GP_FP_FRAC(yend), xgap));
+ GP_MixPixel_Raw_Clipped(context, xpx1, ypx1+1, pixel, perc);
+
xend = GP_FP_ROUND(x0);
yend = y0 + GP_FP_DIV(GP_FP_MUL(dy, xend - x0), dx);
xgap = GP_FP_RFRAC(x0 + GP_FP_1_2);
@@ -58,24 +69,11 @@ void GP_LineAA_Raw(GP_Context *context, GP_Coord x0, GP_Coord y0,
perc = FP_TO_PERC(GP_FP_MUL(GP_FP_FRAC(yend), xgap));
GP_MixPixel_Raw_Clipped(context, xpx0, ypx0+1, pixel, perc);
- ddd = yend;
-
- xend = GP_FP_ROUND(x1);
- yend = y1 + GP_FP_DIV(GP_FP_MUL(dy, xend - x1), dx);
- xgap = GP_FP_FRAC(x1 + GP_FP_1_2);
- xpx1 = GP_FP_TO_INT(xend);
- ypx1 = GP_FP_TO_INT(yend);
-
- perc = FP_TO_PERC(GP_FP_MUL(GP_FP_RFRAC(yend), xgap));
- GP_MixPixel_Raw_Clipped(context, xpx1, ypx1, pixel, perc);
- perc = FP_TO_PERC(GP_FP_MUL(GP_FP_RFRAC(yend), xgap));
- GP_MixPixel_Raw_Clipped(context, xpx1, ypx1+1, pixel, perc);
-
GP_Coord x;
GP_Coord intery;
for (x = xpx0 + 1; x < xpx1; x++) {
- intery = ddd + GP_FP_DIV((x - xpx0) * dy, dx);
+ intery = yend + GP_FP_DIV((x - xpx0) * dy, dx);
GP_MixPixel_Raw_Clipped(context, x, GP_FP_TO_INT(intery), pixel, FP_TO_PERC(GP_FP_RFRAC(intery)));
GP_MixPixel_Raw_Clipped(context, x, GP_FP_TO_INT(intery) + 1, pixel, FP_TO_PERC(GP_FP_FRAC(intery)));
}
-----------------------------------------------------------------------
Summary of changes:
libs/gfx/GP_LineAA.gen.c.t | 129 ++++++++++++++++++++++++++++++++------------
1 files changed, 94 insertions(+), 35 deletions(-)
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos(a)gmail.com
if you want to unsubscribe, or site admin admin(a)repo.or.cz if you receive
no reply.
--
gfxprim.git ("A simple 2D graphics library with emphasis on correctness and well-defined operation.")
1
0
[repo.or.cz] gfxprim.git branch master updated: 4c14716c974906c490a2f96bdbd0cef840fe1812
by metan 07 Feb '12
by metan 07 Feb '12
07 Feb '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 4c14716c974906c490a2f96bdbd0cef840fe1812 (commit)
via c5bfa31f9116879d4bf934536c238427fb5c0f19 (commit)
from 52bed540fa7128ba565a2a6ab8bb3f91674c04d1 (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/4c14716c974906c490a2f96bdbd0cef840fe…
commit 4c14716c974906c490a2f96bdbd0cef840fe1812
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Tue Feb 7 12:39:41 2012 +0100
gfx: LineAA fix some rounding errors, more to come.
diff --git a/libs/gfx/GP_LineAA.gen.c.t b/libs/gfx/GP_LineAA.gen.c.t
index 4f08298..37af24e 100644
--- a/libs/gfx/GP_LineAA.gen.c.t
+++ b/libs/gfx/GP_LineAA.gen.c.t
@@ -14,72 +14,71 @@
#define FP_TO_PERC(a) (GP_FP_ROUND_TO_INT((a) * 255))
-void GP_LineAA(GP_Context *context, GP_Coord x1, GP_Coord y1,
- GP_Coord x2, GP_Coord y2, GP_Pixel pixel)
+void GP_LineAA_Raw(GP_Context *context, GP_Coord x0, GP_Coord y0,
+ GP_Coord x1, GP_Coord y1, GP_Pixel pixel)
{
- GP_Coord dx = x2 - x1;
- GP_Coord dy = y2 - y1;
+ int64_t dx = x1 - x0;
+ int64_t dy = y1 - y0;
if (dy == 0) {
//TODO!!!
- //GP_HLine_Raw(context, GP_FP_ROUND_TO_INT(x1), GP_FP_ROUND_TO_INT(x2),
- // GP_FP_ROUND_TO_INT(y1), pixel);
+ //GP_HLine_Raw(context, GP_FP_ROUND_TO_INT(x0), GP_FP_ROUND_TO_INT(x1),
+ // GP_FP_ROUND_TO_INT(y0), pixel);
return;
}
if (dx == 0) {
//TODO!!!
- //GP_VLine(context, GP_FP_ROUND_TO_INT(x1), GP_FP_ROUND_TO_INT(y1),
- // GP_FP_ROUND_TO_INT(y2), pixel);
+ //GP_VLine(context, GP_FP_ROUND_TO_INT(x0), GP_FP_ROUND_TO_INT(y0),
+ // GP_FP_ROUND_TO_INT(y1), pixel);
return;
}
if (GP_ABS(dx) < GP_ABS(dy)) {
- GP_SWAP(x1, y1);
- GP_SWAP(x2, y2);
- GP_SWAP(dx, dy);
//TODO
return;
}
- if (x2 < x1) {
- GP_SWAP(x1, x2);
- GP_SWAP(y1, y2);
+ if (x1 < x0) {
+ GP_SWAP(x0, x1);
+ GP_SWAP(y0, y1);
}
- GP_Coord grad = GP_FP_DIV(dy, dx);
+ GP_Coord xend, yend, xgap, xpx0, ypx0, xpx1, ypx1, ddd;
+ uint8_t perc;
- GP_Coord xend, yend, xgap, xpx1, ypx1, xpx2, ypx2;
+ xend = GP_FP_ROUND(x0);
+ yend = y0 + GP_FP_DIV(GP_FP_MUL(dy, xend - x0), dx);
+ xgap = GP_FP_RFRAC(x0 + GP_FP_1_2);
+ xpx0 = GP_FP_TO_INT(xend);
+ ypx0 = GP_FP_TO_INT(yend);
+
+ perc = FP_TO_PERC(GP_FP_MUL(GP_FP_RFRAC(yend), xgap));
+ GP_MixPixel_Raw_Clipped(context, xpx0, ypx0, pixel, perc);
+ perc = FP_TO_PERC(GP_FP_MUL(GP_FP_FRAC(yend), xgap));
+ GP_MixPixel_Raw_Clipped(context, xpx0, ypx0+1, pixel, perc);
+
+ ddd = yend;
xend = GP_FP_ROUND(x1);
- yend = y1 + GP_FP_MUL(grad, xend - x1);
- xgap = GP_FP_RFRAC(x1 + GP_FP_1_2);
+ yend = y1 + GP_FP_DIV(GP_FP_MUL(dy, xend - x1), dx);
+ xgap = GP_FP_FRAC(x1 + GP_FP_1_2);
xpx1 = GP_FP_TO_INT(xend);
ypx1 = GP_FP_TO_INT(yend);
- GP_MixPixel_Raw_Clipped(context, xpx1, ypx1, pixel, FP_TO_PERC(GP_FP_MUL(GP_FP_RFRAC(yend), xgap)));
- GP_MixPixel_Raw_Clipped(context, xpx1, ypx1 + 1, pixel, FP_TO_PERC(GP_FP_MUL(GP_FP_FRAC(yend), xgap)));
-
- GP_Coord intery = yend + grad;
-
- xend = GP_FP_ROUND(x2);
- yend = y2 + GP_FP_MUL(grad, xend - x2);
- xgap = GP_FP_FRAC(x2 + GP_FP_1_2);
- xpx2 = GP_FP_TO_INT(xend);
- ypx2 = GP_FP_TO_INT(yend);
-
- GP_MixPixel_Raw_Clipped(context, xpx2, ypx2, pixel, FP_TO_PERC(GP_FP_MUL(GP_FP_RFRAC(yend), xgap)));
- GP_MixPixel_Raw_Clipped(context, xpx2, ypx2 + 1, pixel, FP_TO_PERC(GP_FP_MUL(GP_FP_RFRAC(yend), xgap)));
+ perc = FP_TO_PERC(GP_FP_MUL(GP_FP_RFRAC(yend), xgap));
+ GP_MixPixel_Raw_Clipped(context, xpx1, ypx1, pixel, perc);
+ perc = FP_TO_PERC(GP_FP_MUL(GP_FP_RFRAC(yend), xgap));
+ GP_MixPixel_Raw_Clipped(context, xpx1, ypx1+1, pixel, perc);
GP_Coord x;
+ GP_Coord intery;
- for (x = xpx1 + 1; x < xpx2; x++) {
+ for (x = xpx0 + 1; x < xpx1; x++) {
+ intery = ddd + GP_FP_DIV((x - xpx0) * dy, dx);
GP_MixPixel_Raw_Clipped(context, x, GP_FP_TO_INT(intery), pixel, FP_TO_PERC(GP_FP_RFRAC(intery)));
GP_MixPixel_Raw_Clipped(context, x, GP_FP_TO_INT(intery) + 1, pixel, FP_TO_PERC(GP_FP_FRAC(intery)));
-
- intery += grad;
}
}
-
%% endblock body
http://repo.or.cz/w/gfxprim.git/commit/c5bfa31f9116879d4bf934536c238427fb5c…
commit c5bfa31f9116879d4bf934536c238427fb5c0f19
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Tue Feb 7 11:36:47 2012 +0100
core: Fix typo in Mix Pixel.
diff --git a/include/core/GP_MixPixels.gen.h.t b/include/core/GP_MixPixels.gen.h.t
index ebcaa38..67fdf31 100644
--- a/include/core/GP_MixPixels.gen.h.t
+++ b/include/core/GP_MixPixels.gen.h.t
@@ -83,7 +83,7 @@ static inline void GP_MixPixel_Raw_{{ pt.name }}(GP_Context *context,
GP_Coord x, GP_Coord y, GP_Pixel pixel, uint8_t perc)
{
GP_Pixel pix = GP_GetPixel_Raw_{{ pt.pixelsize.suffix }}(context, x, y);
- GP_MIX_PIXELS_{{ pt.name }}(pixel, pix, perc);
+ pix = GP_MIX_PIXELS_{{ pt.name }}(pixel, pix, perc);
GP_PutPixel_Raw_{{ pt.pixelsize.suffix }}(context, x, y, pix);
}
-----------------------------------------------------------------------
Summary of changes:
include/core/GP_MixPixels.gen.h.t | 2 +-
libs/gfx/GP_LineAA.gen.c.t | 69 ++++++++++++++++++-------------------
2 files changed, 35 insertions(+), 36 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: 52bed540fa7128ba565a2a6ab8bb3f91674c04d1
by metan 05 Feb '12
by metan 05 Feb '12
05 Feb '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 52bed540fa7128ba565a2a6ab8bb3f91674c04d1 (commit)
via 7949b70ee58a7ce28bf21767e1b29efe56ef68e0 (commit)
via 076239276ea6205aaf69d5338bfd529d40592c4b (commit)
via 2954919a806b005e125f1bc08542dc38f94138c8 (commit)
via 504c3a5c6858d9af39bc640b2a16638b984226a7 (commit)
via 150058b75f541d901eda178e485d65112ab77e5b (commit)
via cb293ded8c994e9df465ad5af0b0777def55f680 (commit)
from 89d86e0b6926dd8f6a5f650a89920e104ea52b00 (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/52bed540fa7128ba565a2a6ab8bb3f91674c…
commit 52bed540fa7128ba565a2a6ab8bb3f91674c04d1
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Sun Feb 5 23:42:39 2012 +0100
gfx: Experimental AA line.
* Doesn't do corner cases
* The arithmetics is off (looses precision soon)
diff --git a/libs/gfx/GP_LineAA.gen.c.t b/libs/gfx/GP_LineAA.gen.c.t
new file mode 100644
index 0000000..4f08298
--- /dev/null
+++ b/libs/gfx/GP_LineAA.gen.c.t
@@ -0,0 +1,85 @@
+%% extends "base.c.t"
+
+{% block descr %}Anti Aliased Line{% endblock %}
+
+%% block body
+
+#include "core/GP_Context.h"
+#include "core/GP_MixPixels.h"
+#include "core/GP_FixedPoint.h"
+#include "core/GP_GammaCorrection.h"
+
+#include "gfx/GP_HLine.h"
+#include "gfx/GP_VLine.h"
+
+#define FP_TO_PERC(a) (GP_FP_ROUND_TO_INT((a) * 255))
+
+void GP_LineAA(GP_Context *context, GP_Coord x1, GP_Coord y1,
+ GP_Coord x2, GP_Coord y2, GP_Pixel pixel)
+{
+ GP_Coord dx = x2 - x1;
+ GP_Coord dy = y2 - y1;
+
+ if (dy == 0) {
+ //TODO!!!
+ //GP_HLine_Raw(context, GP_FP_ROUND_TO_INT(x1), GP_FP_ROUND_TO_INT(x2),
+ // GP_FP_ROUND_TO_INT(y1), pixel);
+ return;
+ }
+
+ if (dx == 0) {
+ //TODO!!!
+ //GP_VLine(context, GP_FP_ROUND_TO_INT(x1), GP_FP_ROUND_TO_INT(y1),
+ // GP_FP_ROUND_TO_INT(y2), pixel);
+ return;
+ }
+
+ if (GP_ABS(dx) < GP_ABS(dy)) {
+ GP_SWAP(x1, y1);
+ GP_SWAP(x2, y2);
+ GP_SWAP(dx, dy);
+ //TODO
+ return;
+ }
+
+ if (x2 < x1) {
+ GP_SWAP(x1, x2);
+ GP_SWAP(y1, y2);
+ }
+
+ GP_Coord grad = GP_FP_DIV(dy, dx);
+
+ GP_Coord xend, yend, xgap, xpx1, ypx1, xpx2, ypx2;
+
+ xend = GP_FP_ROUND(x1);
+ yend = y1 + GP_FP_MUL(grad, xend - x1);
+ xgap = GP_FP_RFRAC(x1 + GP_FP_1_2);
+ xpx1 = GP_FP_TO_INT(xend);
+ ypx1 = GP_FP_TO_INT(yend);
+
+ GP_MixPixel_Raw_Clipped(context, xpx1, ypx1, pixel, FP_TO_PERC(GP_FP_MUL(GP_FP_RFRAC(yend), xgap)));
+ GP_MixPixel_Raw_Clipped(context, xpx1, ypx1 + 1, pixel, FP_TO_PERC(GP_FP_MUL(GP_FP_FRAC(yend), xgap)));
+
+ GP_Coord intery = yend + grad;
+
+ xend = GP_FP_ROUND(x2);
+ yend = y2 + GP_FP_MUL(grad, xend - x2);
+ xgap = GP_FP_FRAC(x2 + GP_FP_1_2);
+ xpx2 = GP_FP_TO_INT(xend);
+ ypx2 = GP_FP_TO_INT(yend);
+
+ GP_MixPixel_Raw_Clipped(context, xpx2, ypx2, pixel, FP_TO_PERC(GP_FP_MUL(GP_FP_RFRAC(yend), xgap)));
+ GP_MixPixel_Raw_Clipped(context, xpx2, ypx2 + 1, pixel, FP_TO_PERC(GP_FP_MUL(GP_FP_RFRAC(yend), xgap)));
+
+ GP_Coord x;
+
+ for (x = xpx1 + 1; x < xpx2; x++) {
+ GP_MixPixel_Raw_Clipped(context, x, GP_FP_TO_INT(intery), pixel, FP_TO_PERC(GP_FP_RFRAC(intery)));
+ GP_MixPixel_Raw_Clipped(context, x, GP_FP_TO_INT(intery) + 1, pixel, FP_TO_PERC(GP_FP_FRAC(intery)));
+
+ intery += grad;
+ }
+}
+
+
+%% endblock body
diff --git a/libs/gfx/Makefile b/libs/gfx/Makefile
index a3e7da2..64fd479 100644
--- a/libs/gfx/Makefile
+++ b/libs/gfx/Makefile
@@ -1,5 +1,8 @@
TOPDIR=../..
-CSOURCES=$(shell ls *.c)
+CSOURCES=$(filter-out $(wildcard *.gen.c),$(wildcard *.c))
+GENSOURCES=GP_LineAA.gen.c
LIBNAME=gfx
+
+include $(TOPDIR)/gen.mk
include $(TOPDIR)/include.mk
include $(TOPDIR)/lib.mk
http://repo.or.cz/w/gfxprim.git/commit/7949b70ee58a7ce28bf21767e1b29efe56ef…
commit 7949b70ee58a7ce28bf21767e1b29efe56ef68e0
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Sun Feb 5 23:38:32 2012 +0100
core: MixPixel() use Gamma correction for RGB pixels.
diff --git a/include/core/GP_MixPixels.gen.h.t b/include/core/GP_MixPixels.gen.h.t
index f182ee5..ebcaa38 100644
--- a/include/core/GP_MixPixels.gen.h.t
+++ b/include/core/GP_MixPixels.gen.h.t
@@ -9,15 +9,17 @@ Macros to mix two pixels accordingly to percentage.
#include "core/GP_Context.h"
#include "core/GP_Pixel.h"
#include "core/GP_GetPutPixel.h"
+#include "core/GP_GammaCorrection.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) ({ +#define GP_MIX_PIXELS_LINEAR_{{ pt.name }}(pix1, pix2, perc) ({ %% for c in pt.chanslist
GP_Pixel {{ c[0] }}; @@ -30,6 +32,32 @@ Macros to mix two pixels accordingly to percentage.
GP_Pixel_CREATE_{{ pt.name }}({{ pt.chanslist[0][0] }}{% for c in pt.chanslist[1:] %}, {{ c[0] }}{% endfor %}); })
+/*
+ * Mixes two {{ pt.name }} pixels.
+ *
+ * The percentage is expected as 8 bit unsigned integer [0 .. 255]
+ */
+#define GP_MIX_PIXELS_GAMMA_{{ pt.name }}(pix1, pix2, perc) ({ +%% for c in pt.chanslist
+ GP_Pixel {{ c[0] }}; ++ {{ c[0] }} = GP_Gamma{{ c[2] }}ToLinear10(GP_Pixel_GET_{{ c[0] }}_{{ pt.name }}(pix1)) * (perc); + {{ c[0] }} += GP_Gamma{{ c[2] }}ToLinear10(GP_Pixel_GET_{{ c[0] }}_{{ pt.name }}(pix2)) * (255 - (perc)); + {{ c[0] }} = ({{ c[0] }} + 128) / 255; + {{ c[0] }} = GP_Linear10ToGamma{{ c[2] }}({{ c[0] }}); ++%% endfor
++ GP_Pixel_CREATE_{{ pt.name }}({{ pt.chanslist[0][0] }}{% for c in pt.chanslist[1:] %}, {{ c[0] }}{% endfor %}); +})
+
+#define GP_MIX_PIXELS_{{ pt.name }}(pix1, pix2, perc) +%% if pt.is_rgb()
+ GP_MIX_PIXELS_GAMMA_{{ pt.name }}(pix1, pix2, perc)
+%% else
+ GP_MIX_PIXELS_LINEAR_{{ pt.name }}(pix1, pix2, perc)
+%% endif
+
%% endif
%% endfor
@@ -40,7 +68,7 @@ static inline GP_Pixel GP_MixPixels(GP_Pixel pix1, GP_Pixel pix2,
%% for pt in pixeltypes
%% if not pt.is_unknown()
case GP_PIXEL_{{ pt.name }}:
- return GP_MIX_PIXELS_{{ pt.name }}(pix1, pix2, perc);
+ return GP_MIX_PIXELS_LINEAR_{{ pt.name }}(pix1, pix2, perc);
%% endif
%% endfor
default:
@@ -55,7 +83,7 @@ static inline void GP_MixPixel_Raw_{{ pt.name }}(GP_Context *context,
GP_Coord x, GP_Coord y, GP_Pixel pixel, uint8_t perc)
{
GP_Pixel pix = GP_GetPixel_Raw_{{ pt.pixelsize.suffix }}(context, x, y);
- pix = GP_MIX_PIXELS_{{ pt.name }}(pixel, pix, perc);
+ GP_MIX_PIXELS_{{ pt.name }}(pixel, pix, perc);
GP_PutPixel_Raw_{{ pt.pixelsize.suffix }}(context, x, y, pix);
}
http://repo.or.cz/w/gfxprim.git/commit/076239276ea6205aaf69d5338bfd529d4059…
commit 076239276ea6205aaf69d5338bfd529d40592c4b
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Sun Feb 5 23:28:59 2012 +0100
core: Add GP_MixPixel().
diff --git a/include/core/GP_MixPixels.gen.h.t b/include/core/GP_MixPixels.gen.h.t
index deb6912..f182ee5 100644
--- a/include/core/GP_MixPixels.gen.h.t
+++ b/include/core/GP_MixPixels.gen.h.t
@@ -6,8 +6,9 @@ Macros to mix two pixels accordingly to percentage.
%% block body
-
-#include "GP_Pixel.h"
+#include "core/GP_Context.h"
+#include "core/GP_Pixel.h"
+#include "core/GP_GetPutPixel.h"
%% for pt in pixeltypes
%% if not pt.is_unknown()
@@ -47,4 +48,65 @@ static inline GP_Pixel GP_MixPixels(GP_Pixel pix1, GP_Pixel pix2,
}
}
+
+%% for pt in pixeltypes
+%% if not pt.is_unknown()
+static inline void GP_MixPixel_Raw_{{ pt.name }}(GP_Context *context,
+ GP_Coord x, GP_Coord y, GP_Pixel pixel, uint8_t perc)
+{
+ GP_Pixel pix = GP_GetPixel_Raw_{{ pt.pixelsize.suffix }}(context, x, y);
+ pix = GP_MIX_PIXELS_{{ pt.name }}(pixel, pix, perc);
+ GP_PutPixel_Raw_{{ pt.pixelsize.suffix }}(context, x, y, pix);
+}
+
+%% endif
+%% endfor
+
+%% for pt in pixeltypes
+%% if not pt.is_unknown()
+static inline void GP_MixPixel_Raw_Clipped_{{ pt.name }}(GP_Context *context,
+ GP_Coord x, GP_Coord y, GP_Pixel pixel, uint8_t perc)
+{
+ if (GP_PIXEL_IS_CLIPPED(context, x, y))
+ return;
+
+ GP_MixPixel_Raw_{{ pt.name }}(context, x, y, pixel, perc);
+}
+
+%% endif
+%% endfor
+
+static inline void GP_MixPixel_Raw(GP_Context *context, GP_Coord x, GP_Coord y,
+ GP_Pixel pixel, uint8_t perc)
+{
+ switch (context->pixel_type) {
+%% for pt in pixeltypes
+%% if not pt.is_unknown()
+ case GP_PIXEL_{{ pt.name }}:
+ GP_MixPixel_Raw_{{ pt.name }}(context, x, y, pixel, perc);
+ break;
+%% endif
+%% endfor
+ default:
+ GP_ABORT("Unknown pixeltype");
+ }
+}
+
+static inline void GP_MixPixel_Raw_Clipped(GP_Context *context,
+ GP_Coord x, GP_Coord y,
+ GP_Pixel pixel, uint8_t perc)
+{
+ switch (context->pixel_type) {
+%% for pt in pixeltypes
+%% if not pt.is_unknown()
+ case GP_PIXEL_{{ pt.name }}:
+ GP_MixPixel_Raw_Clipped_{{ pt.name }}(context, x, y, pixel, perc);
+ break;
+%% endif
+%% endfor
+ default:
+ GP_ABORT("Unknown pixeltype");
+ }
+}
+
%% endblock body
http://repo.or.cz/w/gfxprim.git/commit/2954919a806b005e125f1bc08542dc38f941…
commit 2954919a806b005e125f1bc08542dc38f94138c8
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Sun Feb 5 23:03:08 2012 +0100
core: Add fixed point operations.
diff --git a/include/core/GP_FixedPoint.h b/include/core/GP_FixedPoint.h
index d8556d9..33029ad 100644
--- a/include/core/GP_FixedPoint.h
+++ b/include/core/GP_FixedPoint.h
@@ -72,6 +72,16 @@ typedef uint8_t GP_FP_Frac;
#define GP_FP_SUB(a, b) ((a)-(b))
/*
+ * Multiplication, may overflow.
+ */
+#define GP_FP_MUL(a, b) ((((a) * (b)) + GP_FP_1_2)>>GP_FP_FRAC_BITS)
+
+/*
+ * Division, may overflow
+ */
+#define GP_FP_DIV(a, b) ((((a)<<GP_FP_FRAC_BITS) + GP_FP_1_2) / (b))
+
+/*
* Floor.
*/
#define GP_FP_FLOOR(a) ((a) & GP_FP_INT_MASK)
@@ -79,7 +89,8 @@ typedef uint8_t GP_FP_Frac;
/*
* Floor with conversion to integer.
*/
-#define GP_FP_FLOOR_TO_INT(a) ((a)>>GP_FP_FRAC_BITS)
+#define GP_FP_TO_INT(a) ((a)>>GP_FP_FRAC_BITS)
+#define GP_FP_FLOOR_TO_INT(a) GP_FP_TO_INT(a)
/*
* Ceiling.
@@ -92,9 +103,14 @@ typedef uint8_t GP_FP_Frac;
#define GP_FP_CEIL_TO_INT(a) (((a)>>GP_FP_FRAC_BITS) + !!(GP_FP_FRAC(a)))
/*
- * Rounding wiht conversion to integer.
+ * Rounding.
*/
-#define GP_FP_ROUND_TO_INT(a) (((a) + GP_FP_1_2))>>GP_FP_FRAC_BITS
+#define GP_FP_ROUND(a) GP_FP_FLOOR((a) + GP_FP_1_2)
+
+/*
+ * Rounding with conversion to integer.
+ */
+#define GP_FP_ROUND_TO_INT(a) ((((a) + GP_FP_1_2))>>GP_FP_FRAC_BITS)
/*
* Fractional part.
@@ -102,6 +118,11 @@ typedef uint8_t GP_FP_Frac;
#define GP_FP_FRAC(a) ((a) & GP_FP_FRAC_MASK)
/*
+ * Reverse fractional part 1 - frac(x)
+ */
+#define GP_FP_RFRAC(a) (GP_FP_1 - GP_FP_FRAC(a))
+
+/*
* Returns an float.
*/
#define GP_FP_TO_FLOAT(a) (((float)(a))/((float)GP_FP_1))
http://repo.or.cz/w/gfxprim.git/commit/504c3a5c6858d9af39bc640b2a16638b9842…
commit 504c3a5c6858d9af39bc640b2a16638b984226a7
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Sun Feb 5 22:12:19 2012 +0100
core: Redo gamma correction.
diff --git a/include/core/GP_GammaCorrection.gen.h.t b/include/core/GP_GammaCorrection.gen.h.t
new file mode 100644
index 0000000..b2d0b26
--- /dev/null
+++ b/include/core/GP_GammaCorrection.gen.h.t
@@ -0,0 +1,27 @@
+%% extends "base.h.t"
+
+{% block descr %}Gamma corrections.{% endblock %}
+
+%% block body
+
+
+extern uint16_t *GP_Gamma8_Linear10;
+extern uint8_t *GP_Linear10_Gamma8;
+
+%% for i in range(1, 9)
+static inline uint16_t GP_Gamma{{ i }}ToLinear10(uint8_t val)
+{
+ return GP_Gamma8_Linear10[val<<{{8 - i}}];
+}
+
+%% endfor
+
+%% for i in range(1, 9)
+static inline uint8_t GP_Linear10ToGamma{{ i }}(uint16_t val)
+{
+ return (GP_Linear10_Gamma8[val] + {{ int(2 ** (7 - i))}})>>{{8 - i}};
+}
+
+%% endfor
+
+%% endblock body
diff --git a/include/core/GP_GammaCorrection.h b/include/core/GP_GammaCorrection.h
index d7d9d9c..e06ab9a 100644
--- a/include/core/GP_GammaCorrection.h
+++ b/include/core/GP_GammaCorrection.h
@@ -60,19 +60,7 @@
#define CORE_GP_GAMMA_CORRECTION_H
#include <stdint.h>
-#include <math.h>
-extern uint8_t *GP_LinearToGamma_8bit;
-
-/*
- * Coverts linear 0 255 value into 0 255 gama value.
- *
- * (this is used for Anti Aliased gfx primitives.)
- */
-static inline uint8_t GP_LinearToGamma(uint8_t val)
-{
-
- return GP_LinearToGamma_8bit[val];
-}
+#include "core/GP_GammaCorrection.gen.h"
#endif /* CORE_GP_GAMMA_CORRECTION_H */
diff --git a/include/core/Makefile b/include/core/Makefile
index 48eb3d2..c9be7d8 100644
--- a/include/core/Makefile
+++ b/include/core/Makefile
@@ -1,7 +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_MixPixels.gen.h
+ GP_MixPixels.gen.h GP_GammaCorrection.gen.h
LIBNAME=core
include $(TOPDIR)/gen.mk
include $(TOPDIR)/include.mk
diff --git a/libs/core/GP_GammaCorrection.gen.c.t b/libs/core/GP_GammaCorrection.gen.c.t
index 0fdd467..4b1a23e 100644
--- a/libs/core/GP_GammaCorrection.gen.c.t
+++ b/libs/core/GP_GammaCorrection.gen.c.t
@@ -13,18 +13,27 @@
#include <stdint.h>
/*
- * 8-bit linear to gamma translation table.
+ * Converts 8 bit gamma to 10 bit linear.
*/
-static uint8_t linear_to_gamma_8bit[] = {
+static uint16_t gamma8_linear10[] = {
%% for i in range(0, 256)
- {{ int(((float(i)/255) ** (1/2.2)) * 255 + 0.5) }}, /* {{i}} */
+ {{ int(((float(i)/255) ** 2.2) * 1024 + 0.5) }}, /* {{i}} */
%% endfor
};
/*
- * Pointer to 8 bit translation table.
+ * Converts 10 bit linear to 8 bit gamma.
*/
-uint8_t *GP_LinearToGamma_8bit = linear_to_gamma_8bit;
+static uint8_t linear10_gamma8[] = {
+%% for i in range(0, 1025)
+ {{ int(((float(i)/1024) ** (1/2.2)) * 255 + 0.5) }}, /* {{i}} */
+%% endfor
+};
+/*
+ * Pointers to tables
+ */
+uint16_t *GP_Gamma8_Linear10 = gamma8_linear10;
+uint8_t *GP_Linear10_Gamma8 = linear10_gamma8;
%% endblock body
diff --git a/libs/gfx/GP_RectAA.c b/libs/gfx/GP_RectAA.c
index a48d72e..812c6bd 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_LinearToGamma(w);
+ uint8_t mix = 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_LinearToGamma(h);
+ uint8_t mix = w;
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_LinearToGamma(GP_FP_FROM_INT(in_y0) + GP_FP_1_2 - y0);
+ uint8_t mix = 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_LinearToGamma(y1 - GP_FP_FROM_INT(in_y0) - GP_FP_1_2);
+ uint8_t mix = 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_LinearToGamma(GP_FP_FROM_INT(in_x0) + GP_FP_1_2 - x0);
+ uint8_t mix = 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_LinearToGamma(x1 - GP_FP_FROM_INT(in_x1) - GP_FP_1_2);
+ uint8_t mix = x1 - GP_FP_FROM_INT(in_x1) - GP_FP_1_2;
GP_Coord i;
for (i = out_y0; i <= out_y1; i++) {
http://repo.or.cz/w/gfxprim.git/commit/150058b75f541d901eda178e485d65112ab7…
commit 150058b75f541d901eda178e485d65112ab77e5b
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Sun Feb 5 19:39:06 2012 +0100
gfx: Fix includes
* Include only needed files
diff --git a/libs/gfx/GP_Arc.c b/libs/gfx/GP_Arc.c
index 094497d..ac0360a 100644
--- a/libs/gfx/GP_Arc.c
+++ b/libs/gfx/GP_Arc.c
@@ -19,13 +19,15 @@
* Copyright (C) 2009-2011 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> *
* *
*****************************************************************************/
-#include "GP_Gfx.h"
+#include "core/GP_GetPutPixel.h"
#include "core/GP_FnPerBpp.h"
+#include "gfx/GP_Arc.h"
+
#include "algo/Arc.algo.h"
/* Generate drawing functions for various bit depths. */
diff --git a/libs/gfx/GP_Circle.c b/libs/gfx/GP_Circle.c
index 0cfc88f..66e63c5 100644
--- a/libs/gfx/GP_Circle.c
+++ b/libs/gfx/GP_Circle.c
@@ -19,13 +19,16 @@
* Copyright (C) 2009-2011 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> *
* *
*****************************************************************************/
-#include "GP_Gfx.h"
+#include "core/GP_GetPutPixel.h"
#include "core/GP_FnPerBpp.h"
+#include "gfx/GP_Circle.h"
+#include "gfx/GP_HLine.h"
+
#include "algo/Circle.algo.h"
/* Generate drawing functions for various bit depths. */
diff --git a/libs/gfx/GP_CircleSeg.c b/libs/gfx/GP_CircleSeg.c
index 512699e..4d7dc19 100644
--- a/libs/gfx/GP_CircleSeg.c
+++ b/libs/gfx/GP_CircleSeg.c
@@ -23,12 +23,12 @@
* *
*****************************************************************************/
-#include "GP_CircleSeg.h"
-#include "GP_HLine.h"
-
#include "core/GP_GetPutPixel.h"
#include "core/GP_FnPerBpp.h"
+#include "gfx/GP_CircleSeg.h"
+#include "gfx/GP_HLine.h"
+
#include "algo/CircleSeg.algo.h"
static uint8_t transform_segments(GP_Context *context, uint8_t seg_flags)
diff --git a/libs/gfx/GP_Ellipse.c b/libs/gfx/GP_Ellipse.c
index b416906..a41ca5f 100644
--- a/libs/gfx/GP_Ellipse.c
+++ b/libs/gfx/GP_Ellipse.c
@@ -19,13 +19,16 @@
* Copyright (C) 2009-2011 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> *
* *
*****************************************************************************/
-#include "GP_Gfx.h"
+#include "core/GP_GetPutPixel.h"
#include "core/GP_FnPerBpp.h"
+#include "gfx/GP_Ellipse.h"
+#include "gfx/GP_HLine.h"
+
#include "algo/Ellipse.algo.h"
/* Generate drawing functions for various bit depths. */
diff --git a/libs/gfx/GP_HLine.c b/libs/gfx/GP_HLine.c
index 38200d5..e9daf45 100644
--- a/libs/gfx/GP_HLine.c
+++ b/libs/gfx/GP_HLine.c
@@ -19,13 +19,18 @@
* Copyright (C) 2009-2011 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> *
* *
*****************************************************************************/
-#include "GP_Gfx.h"
-#include "algo/HLine.algo.h"
#include "core/GP_FnPerBpp.h"
+#include "core/GP_WritePixel.h"
+#include "core/GP_Transform.h"
+
+#include "algo/HLine.algo.h"
+
+#include "gfx/GP_HLine.h"
+#include "gfx/GP_VLine.h"
/* Generate drawing functions for various bit depths. */
diff --git a/libs/gfx/GP_Line.c b/libs/gfx/GP_Line.c
index 947a337..62db8a7 100644
--- a/libs/gfx/GP_Line.c
+++ b/libs/gfx/GP_Line.c
@@ -19,13 +19,15 @@
* 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> *
* *
*****************************************************************************/
-#include "GP_Gfx.h"
+#include "core/GP_GetPutPixel.h"
#include "core/GP_FnPerBpp.h"
+#include "gfx/GP_Line.h"
+
#include "algo/Line.algo.h"
/* Generate drawing functions for various bit depths. */
diff --git a/libs/gfx/GP_PartialEllipse.c b/libs/gfx/GP_PartialEllipse.c
index 5415a58..964bf93 100644
--- a/libs/gfx/GP_PartialEllipse.c
+++ b/libs/gfx/GP_PartialEllipse.c
@@ -23,9 +23,11 @@
* *
*****************************************************************************/
-#include "GP_Gfx.h"
+#include "core/GP_GetPutPixel.h"
#include "core/GP_FnPerBpp.h"
+#include "gfx/GP_Ellipse.h"
+
#include "algo/PartialEllipse.algo.h"
/* Generate drawing functions for various bit depths. */
@@ -50,4 +52,4 @@ void GP_PartialEllipse(GP_Context *context, GP_Coord xcenter, GP_Coord ycenter,
GP_TRANSFORM_SWAP(context, a, b);
GP_PartialEllipse_Raw(context, xcenter, ycenter, a, b, start, end, pixel);
-}
No newline at end of file
+}
diff --git a/libs/gfx/GP_Polygon.c b/libs/gfx/GP_Polygon.c
index fa82216..328e7fa 100644
--- a/libs/gfx/GP_Polygon.c
+++ b/libs/gfx/GP_Polygon.c
@@ -19,11 +19,12 @@
* Copyright (C) 2009-2011 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> *
* *
*****************************************************************************/
-#include "GP_Gfx.h"
+#include "gfx/GP_Polygon.h"
+#include "gfx/GP_HLine.h"
#include <limits.h>
#include <stdlib.h>
diff --git a/libs/gfx/GP_Rect.c b/libs/gfx/GP_Rect.c
index 5e8fbc7..9c30385 100644
--- a/libs/gfx/GP_Rect.c
+++ b/libs/gfx/GP_Rect.c
@@ -19,11 +19,15 @@
* Copyright (C) 2009-2011 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> *
* *
*****************************************************************************/
-#include "GP_Gfx.h"
+#include "core/GP_Transform.h"
+
+#include "gfx/GP_HLine.h"
+#include "gfx/GP_VLine.h"
+#include "gfx/GP_Rect.h"
void GP_RectXYXY_Raw(GP_Context *context, GP_Coord x0, GP_Coord y0,
GP_Coord x1, GP_Coord y1, GP_Pixel pixel)
diff --git a/libs/gfx/GP_Tetragon.c b/libs/gfx/GP_Tetragon.c
index 8e31801..e087d12 100644
--- a/libs/gfx/GP_Tetragon.c
+++ b/libs/gfx/GP_Tetragon.c
@@ -19,11 +19,15 @@
* Copyright (C) 2009-2011 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> *
* *
*****************************************************************************/
-#include "GP_Gfx.h"
+#include "core/GP_Transform.h"
+
+#include "gfx/GP_Line.h"
+#include "gfx/GP_Polygon.h"
+#include "gfx/GP_Tetragon.h"
void GP_Tetragon_Raw(GP_Context *context, GP_Coord x0, GP_Coord y0,
GP_Coord x1, GP_Coord y1, GP_Coord x2, GP_Coord y2,
diff --git a/libs/gfx/GP_Triangle.c b/libs/gfx/GP_Triangle.c
index 863c9b0..724e407 100644
--- a/libs/gfx/GP_Triangle.c
+++ b/libs/gfx/GP_Triangle.c
@@ -19,11 +19,15 @@
* Copyright (C) 2009-2011 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> *
* *
*****************************************************************************/
-#include "GP_Gfx.h"
+#include "core/GP_Transform.h"
+
+#include "gfx/GP_Line.h"
+#include "gfx/GP_Polygon.h"
+#include "gfx/GP_Triangle.h"
void GP_Triangle_Raw(GP_Context *context, GP_Coord x0, GP_Coord y0,
GP_Coord x1, GP_Coord y1,
diff --git a/libs/gfx/GP_VLine.c b/libs/gfx/GP_VLine.c
index 88cde1e..910033d 100644
--- a/libs/gfx/GP_VLine.c
+++ b/libs/gfx/GP_VLine.c
@@ -19,13 +19,16 @@
* Copyright (C) 2009-2011 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> *
* *
*****************************************************************************/
-#include "GP_Gfx.h"
+#include "core/GP_GetPutPixel.h"
#include "core/GP_FnPerBpp.h"
+#include "gfx/GP_VLine.h"
+#include "gfx/GP_HLine.h"
+
#include "algo/VLine.algo.h"
/* Generate drawing functions for various bit depths. */
http://repo.or.cz/w/gfxprim.git/commit/cb293ded8c994e9df465ad5af0b0777def55…
commit cb293ded8c994e9df465ad5af0b0777def55f680
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Sun Feb 5 19:32:20 2012 +0100
gfx: Partial Ellipse, fix warning.
diff --git a/libs/gfx/algo/PartialEllipse.algo.h b/libs/gfx/algo/PartialEllipse.algo.h
index b87826e..25ba402 100644
--- a/libs/gfx/algo/PartialEllipse.algo.h
+++ b/libs/gfx/algo/PartialEllipse.algo.h
@@ -65,4 +65,5 @@ void FN_NAME(CONTEXT_T context, int xcenter, int ycenter, int a, int b, PUTPIXEL(context, xcenter-x, ycenter-y, pixval); } } -}
No newline at end of file
+}
+
-----------------------------------------------------------------------
Summary of changes:
include/core/GP_FixedPoint.h | 27 ++++++++-
include/core/GP_GammaCorrection.gen.h.t | 27 +++++++++
include/core/GP_GammaCorrection.h | 14 +----
include/core/GP_MixPixels.gen.h.t | 98 +++++++++++++++++++++++++++++-
include/core/Makefile | 2 +-
libs/core/GP_GammaCorrection.gen.c.t | 19 +++++--
libs/gfx/GP_Arc.c | 6 +-
libs/gfx/GP_Circle.c | 7 ++-
libs/gfx/GP_CircleSeg.c | 6 +-
libs/gfx/GP_Ellipse.c | 7 ++-
libs/gfx/GP_HLine.c | 11 +++-
libs/gfx/GP_Line.c | 6 +-
libs/gfx/GP_LineAA.gen.c.t | 85 ++++++++++++++++++++++++++
libs/gfx/GP_PartialEllipse.c | 6 +-
libs/gfx/GP_Polygon.c | 5 +-
libs/gfx/GP_Rect.c | 8 ++-
libs/gfx/GP_RectAA.c | 12 ++--
libs/gfx/GP_Tetragon.c | 8 ++-
libs/gfx/GP_Triangle.c | 8 ++-
libs/gfx/GP_VLine.c | 7 ++-
libs/gfx/Makefile | 5 +-
libs/gfx/algo/PartialEllipse.algo.h | 3 +-
22 files changed, 317 insertions(+), 60 deletions(-)
create mode 100644 include/core/GP_GammaCorrection.gen.h.t
create mode 100644 libs/gfx/GP_LineAA.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: 89d86e0b6926dd8f6a5f650a89920e104ea52b00
by metan 30 Jan '12
by metan 30 Jan '12
30 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 89d86e0b6926dd8f6a5f650a89920e104ea52b00 (commit)
via 995986f457f6cc5d2ea615622cb6d3a310f51e9d (commit)
from 9b6212e7e083c6a78dca9cf322553c27baea66b2 (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/89d86e0b6926dd8f6a5f650a89920e104ea5…
commit 89d86e0b6926dd8f6a5f650a89920e104ea52b00
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Mon Jan 30 20:35:31 2012 +0100
core: Fix the Blit to honor rotations, added Blit_Raw.
diff --git a/demos/fbshow/fbshow.c b/demos/fbshow/fbshow.c
index f6187f8..5e3e06d 100644
--- a/demos/fbshow/fbshow.c
+++ b/demos/fbshow/fbshow.c
@@ -211,7 +211,7 @@ static void *image_loader(void *ptr)
uint32_t cx = (context->w - ret->w)/2;
uint32_t cy = (context->h - ret->h)/2;
- GP_Blit(ret, 0, 0, ret->w, ret->h, context, cx, cy);
+ GP_Blit_Raw(ret, 0, 0, ret->w, ret->h, context, cx, cy);
GP_ContextFree(ret);
/* clean up the rest of the display */
diff --git a/include/core/GP_Blit.h b/include/core/GP_Blit.h
index 3c9ec54..f772ce0 100644
--- a/include/core/GP_Blit.h
+++ b/include/core/GP_Blit.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> *
* *
*****************************************************************************/
@@ -30,6 +30,12 @@
void GP_Blit(const GP_Context *c1, GP_Coord x1, GP_Coord y1,
GP_Size w, GP_Size h, GP_Context *c2, GP_Coord x2, GP_Coord y2);
+/*
+ * Doesn't respect rotations. Most of the time faster.
+ */
+void GP_Blit_Raw(const GP_Context *c1, GP_Coord x1, GP_Coord y1,
+ GP_Size w, GP_Size h, GP_Context *c2, GP_Coord x2, GP_Coord y2);
+
/*
* Very naive blit, no optimalizations whatsoever - keep it that way.
diff --git a/libs/core/GP_Blit.c b/libs/core/GP_Blit.c
index 1aa1e7e..9bcb80e 100644
--- a/libs/core/GP_Blit.c
+++ b/libs/core/GP_Blit.c
@@ -51,8 +51,8 @@ void GP_Blit_Naive(const GP_Context *c1, int x1, int y1, int w, int h,
}
*/
-void GP_Blit_Naive(const GP_Context *c1, GP_Coord x1, GP_Coord y1, GP_Size w, GP_Size h,
- GP_Context *c2, GP_Coord x2, GP_Coord y2)
+void GP_Blit_Naive_Raw(const GP_Context *c1, GP_Coord x1, GP_Coord y1, GP_Size w, GP_Size h,
+ GP_Context *c2, GP_Coord x2, GP_Coord y2)
{
GP_CHECK(x1 >= 0);
GP_CHECK(y1 >= 0);
@@ -73,3 +73,33 @@ void GP_Blit_Naive(const GP_Context *c1, GP_Coord x1, GP_Coord y1, GP_Size w, GP
GP_PutPixel_Raw(c2, x2 + i, y2 + j, p);
}
}
+
+void GP_Blit_Raw(const GP_Context *c1, GP_Coord x1, GP_Coord y1,
+ GP_Size w, GP_Size h, GP_Context *c2, GP_Coord x2, GP_Coord y2)
+{
+ // Ultimate TODO: effective processing
+ GP_Blit_Naive_Raw(c1, x1, y1, w, h, c2, x2, y2);
+}
+
+void GP_Blit_Naive(const GP_Context *c1, GP_Coord x1, GP_Coord y1, GP_Size w, GP_Size h,
+ GP_Context *c2, GP_Coord x2, GP_Coord y2)
+{
+ GP_CHECK(x1 >= 0);
+ GP_CHECK(y1 >= 0);
+ GP_CHECK(x1 + w <= GP_ContextW(c1));
+ GP_CHECK(y1 + h <= GP_ContextH(c1));
+ GP_CHECK(x2 >= 0);
+ GP_CHECK(y2 >= 0);
+ GP_CHECK(x2 + w <= GP_ContextW(c2));
+ GP_CHECK(y2 + h <= GP_ContextH(c2));
+
+ GP_Size i, j;
+
+ for (i = 0; i < w; i++)
+ for (j = 0; j < h; j++) {
+ GP_Pixel p = GP_GetPixel(c1, x1 + i, y1 + j);
+ if (c1->pixel_type != c2->pixel_type)
+ p = GP_ConvertContextPixel(p, c1, c2);
+ GP_PutPixel(c2, x2 + i, y2 + j, p);
+ }
+}
http://repo.or.cz/w/gfxprim.git/commit/995986f457f6cc5d2ea615622cb6d3a310f5…
commit 995986f457f6cc5d2ea615622cb6d3a310f51e9d
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Mon Jan 30 19:57:08 2012 +0100
core: Added GP_ContextInit().
diff --git a/include/core/GP_Context.h b/include/core/GP_Context.h
index 664f15b..d91e54d 100644
--- a/include/core/GP_Context.h
+++ b/include/core/GP_Context.h
@@ -92,6 +92,12 @@ typedef struct GP_Context {
GP_Context *GP_ContextAlloc(GP_Size w, GP_Size h, GP_PixelType type);
/*
+ * Initalize context.
+ */
+void GP_ContextInit(GP_Context *context, GP_Size w, GP_Size h,
+ GP_PixelType type, void *pixels);
+
+/*
* If passed the pixels are copied to newly created context, otherwise
* the pixels are allocated but uninitalized.
*/
diff --git a/libs/core/GP_Context.c b/libs/core/GP_Context.c
index 73e926e..157fc82 100644
--- a/libs/core/GP_Context.c
+++ b/libs/core/GP_Context.c
@@ -107,6 +107,31 @@ GP_Context *GP_ContextAlloc(GP_Size w, GP_Size h, GP_PixelType type)
return context;
}
+void GP_ContextInit(GP_Context *context, GP_Size w, GP_Size h,
+ GP_PixelType type, void *pixels)
+{
+ uint32_t bpp = GP_PixelSize(type);
+ uint32_t bpr = (bpp * w) / 8 + !!((bpp * w) % 8);
+
+ context->pixels = pixels;
+ context->bpp = bpp;
+ context->bytes_per_row = bpr;
+ context->offset = 0;
+
+ context->w = w;
+ context->h = h;
+
+ context->pixel_type = type;
+ context->bit_endian = 0;
+
+ /* rotation and mirroring */
+ context->axes_swap = 0;
+ context->y_swap = 0;
+ context->x_swap = 0;
+
+ context->free_pixels = 0;
+}
+
GP_Context *GP_ContextConvert(const GP_Context *src,
GP_PixelType dst_pixel_type)
{
-----------------------------------------------------------------------
Summary of changes:
demos/fbshow/fbshow.c | 2 +-
include/core/GP_Blit.h | 8 +++++++-
include/core/GP_Context.h | 6 ++++++
libs/core/GP_Blit.c | 34 ++++++++++++++++++++++++++++++++--
libs/core/GP_Context.c | 25 +++++++++++++++++++++++++
5 files changed, 71 insertions(+), 4 deletions(-)
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos(a)gmail.com
if you want to unsubscribe, or site admin admin(a)repo.or.cz if you receive
no reply.
--
gfxprim.git ("A simple 2D graphics library with emphasis on correctness and well-defined operation.")
1
0