|
From: <mi...@mr...> - 2005-04-12 21:33:42
|
# This is a BitKeeper generated diff -Nru style patch.
#
# ChangeSet
# 2005/04/12 23:33:29+02:00 mi...@go... =
# New module draw
# =
# BitKeeper/etc/logging_ok
# 2005/04/12 23:33:29+02:00 mi...@go... +1 -0
# Logging to lo...@op... accepted
# =
# src/draw/draw.c
# 2005/04/12 23:33:26+02:00 mi...@go... +76 -0
# =
# src/draw/TC2Module
# 2005/04/12 23:33:26+02:00 mi...@go... +7 -0
# =
# interfaces/draw.tc2
# 2005/04/12 23:33:26+02:00 mi...@go... +4 -0
# =
# src/draw/draw.c
# 2005/04/12 23:33:26+02:00 mi...@go... +0 -0
# BitKeeper file /home/michael/RALPH/tc2-modules/src/draw/draw.c
# =
# src/draw/TC2Module
# 2005/04/12 23:33:26+02:00 mi...@go... +0 -0
# BitKeeper file /home/michael/RALPH/tc2-modules/src/draw/TC2Module
# =
# interfaces/draw.tc2
# 2005/04/12 23:33:26+02:00 mi...@go... +0 -0
# BitKeeper file /home/michael/RALPH/tc2-modules/interfaces/draw.tc2
# =
# TC2Package
# 2005/04/12 23:33:26+02:00 mi...@go... +1 -0
# New module draw
# =
diff -Nru a/TC2Package b/TC2Package
--- a/TC2Package 2005-04-12 23:33:30 +02:00
+++ b/TC2Package 2005-04-12 23:33:30 +02:00
@@ -1,5 +1,6 @@
name "TC2 Modules"
version 0.6.0
+module src/draw
module src/eventq
module src/file
module src/gif
diff -Nru a/interfaces/draw.tc2 b/interfaces/draw.tc2
--- /dev/null Wed Dec 31 16:00:00 196900
+++ b/interfaces/draw.tc2 2005-04-12 23:33:30 +02:00
@@ -0,0 +1,4 @@
+symbol "line" int (*%s)(image_t *img, int x1, int y1, int x2, int y2, int width, uint64_t *color)
+symbol "filled_rectangle" int (*%s)(image_t *img, int x1, int y1, int x2, int y2, uint64_t *color)
+
+require "image"
diff -Nru a/src/draw/TC2Module b/src/draw/TC2Module
--- /dev/null Wed Dec 31 16:00:00 196900
+++ b/src/draw/TC2Module 2005-04-12 23:33:30 +02:00
@@ -0,0 +1,7 @@
+module draw
+name "TC2/draw"
+version 0.1.0
+tc2version 0.4.0
+description "drawing of geometric shapes"
+sources draw.c
+implement "draw" "filled_rectangle" i_draw_fillrect
diff -Nru a/src/draw/draw.c b/src/draw/draw.c
--- /dev/null Wed Dec 31 16:00:00 196900
+++ b/src/draw/draw.c 2005-04-12 23:33:30 +02:00
@@ -0,0 +1,76 @@
+/**
+ Copyright (C) 2005 Michael Ahlberg, M=C3=A5ns Rullg=C3=A5rd
+
+ Permission is hereby granted, free of charge, to any person
+ obtaining a copy of this software and associated documentation
+ files (the "Software"), to deal in the Software without
+ restriction, including without limitation the rights to use, copy,
+ modify, merge, publish, distribute, sublicense, and/or sell copies
+ of the Software, and to permit persons to whom the Software is
+ furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be
+ included in all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ DEALINGS IN THE SOFTWARE.
+**/
+
+#include <stdio.h>
+#include <string.h>
+#include <tcalloc.h>
+#include <draw_tc2.h>
+
+
+static void
+alpha_pixel(uint8_t *dest, uint8_t *src)
+{
+ int a =3D src[3];
+ int b =3D 255-src[3];
+ int d;
+
+ dest[0] =3D (dest[0]*b + src[0]*a)/255;
+ dest[1] =3D (dest[1]*b + src[1]*a)/255;
+ dest[2] =3D (dest[2]*b + src[2]*a)/255;
+
+ d =3D dest[3] + (src[3]*a)/255;
+ dest[3] =3D (d>255)?255:d;
+}
+
+static int
+draw_horizontal_line(image_t *img, int x1, int x2, int y, int width,
+ uint64_t *color)
+{
+ if(width =3D=3D 1) {
+ uint32_t *imgdata =3D (uint32_t *)img->data[0];
+ int i;
+ int start =3D x1 + y*img->params.width[0];
+ int end =3D x2 + y*img->params.width[0];
+
+ for(i =3D start; i < end; i++){
+ alpha_pixel((uint8_t *) &imgdata[i], (uint8_t *) &color[0]);
+ }
+ }
+
+ return 0;
+}
+
+
+extern int
+i_draw_fillrect(image_t *img, int x1, int y1, int x2, int y2, uint64_t *color)
+{
+ int i;
+
+ if(img->params.pixel_type !=3D IMAGE_COLOR_RGB_ALPHA) return -1;
+
+ for(i=3Dy1; i<=3Dy2; i++) =
+ draw_horizontal_line(img, x1, x2, i, 1, color);
+
+ return 0;
+}
|