Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

first commit

  • Loading branch information...
commit 896060b50f76836efd23dbdd94a0e3749ceff1c1 0 parents
@TheHippo authored
50 Test1.hx
@@ -0,0 +1,50 @@
+package;
+
+import hxGD.Image;
+import hxGD.Loader;
+import hxGD.Color;
+import hxGD.Polygon;
+import hxGD.Graphics;
+
+class Test1 {
+
+ public function new() {
+
+ var img:Image = Loader.createFromJpeg("test.jpg");
+
+ trace("width: "+img.width+" height: "+img.height);
+
+ //img.graphics.setBrush(brush);
+
+
+ img.graphics.color = Color.ofRGB(0xFF0000);
+
+ /* var ca:Array<Color> = new Array<Color>();
+ ca.push(new Color(255,0,0));
+ ca.push(new Color(255,0,0));
+ ca.push(new Color(0,255,0));
+ ca.push(new Color(0,255,0));
+ ca.push(new Color(0,0,255));
+ ca.push(new Color(0,0,255));
+
+ img.graphics.setStyle(ca); */
+ img.graphics.thickness = 5;
+ img.graphics.color = Color.ofRGBA(0xFF000055);
+
+ img.graphics.imageLine(0,0,img.width,img.height,false);
+ img.graphics.imageCircle(150,150,130);
+
+
+
+ img.saveImage("test2.png",FileType.Png);
+ }
+
+ public static function main() {
+ //for (i in 0...5000) {
+ new Test1();
+ // if (i % 10 == 0)
+ // neko.vm.Gc.run(true);
+ //}
+ }
+
+}
2  build.hxml
@@ -0,0 +1,2 @@
+-main Test1
+-neko test1.n
33 hxGD/Color.hx
@@ -0,0 +1,33 @@
+package hxGD;
+
+class Color {
+
+ public var gd(gdColor,null):Int;
+ public var red:Int;
+ public var green:Int;
+ public var blue:Int;
+ public var alpha:Int;
+
+ public function new(red:Int,green:Int,blue:Int,?alpha:Int=255) {
+ this.red = red;
+ this.green = green;
+ this.blue = blue;
+ this.alpha = alpha;
+ // trace(this);
+ }
+
+ public static inline function ofRGB(color:Int):Color {
+ //0xRRGGBB
+ return new Color(((color & 0xFF0000) >> 16),((color & 0x00FF00) >> 8),(color & 0x0000FF));
+ }
+
+ public static inline function ofRGBA(color:Int):Color {
+ //0xRRGGBBAA
+ return new Color(((color & 0xFF000000) >> 24),((color & 0x00FF0000) >> 16) ,((color & 0x0000FF00) >> 8),(color & 0x000000FF));
+ }
+
+ private function gdColor():Int {
+ return ((((((red << 8) + green) << 8) + blue) << 8 ) + alpha);
+ }
+
+}
172 hxGD/Graphics.hx
@@ -0,0 +1,172 @@
+
+package hxGD;
+
+import neko.Lib;
+
+enum ArcFillType {
+ ArcFilled;
+ ArcOutline;
+ ArcBorder;
+ ChordFilled;
+ ChordOutline;
+ ChordBorder;
+}
+
+class Graphics {
+
+ public static var defaultColor:Color = Color.ofRGB(0x000000);
+ public static var defaultThickness:Int = 1;
+ public static var defaultAntiAliasing:Bool = true;
+
+
+ private var img:Void;
+
+ public var color(getColor,setColor):Color;
+ private var _color:Color;
+
+ public var thickness(getThickness,setThickness):Int;
+ private var _thickness:Int;
+
+ public var antiAliasing(getAntiAliasing,setAntiAliasing):Bool;
+ private var _antiAliasing:Bool;
+
+
+ public function new(img:Void) {
+ this.img = img;
+ setColor(Graphics.defaultColor);
+ setAntiAliasing(Graphics.defaultAntiAliasing);
+ setThickness(Graphics.defaultThickness);
+ }
+
+ /* public function setBrush(?brushImage:Image=null) {
+ gd_setBrush(img,brushImage,(brushImage!=null));
+ }
+
+ public function setTile(?tileImage:Image=null) {
+ gd_setTile(img,tileImage,(tileImage!=null));
+ } */
+
+
+ public inline function setStyle(colors:Array<Color>):Void {
+ var ca:Array<Int> = new Array<Int>();
+ for (c in colors)
+ ca.push(c.gd);
+ gd_setStyle(img,Lib.haxeToNeko(ca));
+ }
+
+
+ private inline function getAntiAliasing():Bool {
+ return _antiAliasing;
+ }
+
+ private inline function setAntiAliasing(aa:Bool):Bool {
+ _antiAliasing = aa;
+ gd_setAntiAliasing(img,aa);
+ return _antiAliasing;
+ }
+
+ private inline function getThickness():Int {
+ return _thickness;
+ }
+
+ private inline function setThickness(thickn:Int):Int {
+ _thickness = gd_setThickness(img,(thickn!=0?thickn:1));
+ return _thickness;
+ }
+
+
+ private inline function setColor(c:Color):Color {
+ _color = c;
+ gd_setColor(img,_color.gd);
+ return color;
+ }
+
+ private inline function getColor():Color {
+ return _color;
+ }
+
+ public inline function setPixel(x:Int,y:Int):Void {
+ gd_setPixel(img,x,y);
+ }
+
+ public inline function imageLine(x1:Int,y1:Int,x2:Int,y2:Int,?dashed:Bool=false):Void {
+ if (dashed)
+ gd_imageDashedLine(img,x1,y1,x2,y2);
+ else
+ gd_imageLine(img,x1,y1,x2,y2);
+ }
+
+ public inline function imagePolygon(poly:Polygon,?open:Bool=false,?filled:Bool=false):Void {
+ if (open)
+ if (filled)
+ gd_imageFilledPolygon(img,poly.x,poly.y);
+ else
+ gd_imageOpenPolygon(img,poly.x,poly.y);
+ else
+ if (filled)
+ gd_imageFilledPolygon(img,poly.x,poly.y);
+ else
+ gd_imagePolygon(img,poly.x,poly.y);
+ }
+
+ public inline function imageRectangle(x:Int,y:Int,width:Int,height:Int,?filled:Bool=false):Void {
+ if (filled)
+ gd_imageFilledRectangle(img,x,y,width,height);
+ else
+ gd_imageRectangle(img,x,y,width,height);
+ }
+
+ public inline function imageEllipse(x:Int, y:Int, width:Int,height:Int,?filled:Bool=false):Void {
+ if (filled)
+ gd_imageFilledEllipse(img,x,y,width,height);
+ else
+ gd_imageArc(img,x,y,width,height,0,360);
+ }
+
+ public inline function imageCircle(x:Int, y:Int, radius:Int,?filled:Bool=false):Void {
+ if (filled)
+ gd_imageFilledArc(img,x,y,radius*2,radius*2,0,360,0);
+ else
+ gd_imageArc(img,x,y,radius*2,radius*2,0,360);
+ }
+
+ public inline function imageArc(x:Int,y:Int, width:Int,height:Int, start:Int, end:Int, fillType:ArcFillType):Void {
+ switch (fillType) {
+ case ArcFilled: gd_imageFilledArc(img,x,y,width,height,start,end,0);
+ case ArcOutline: gd_imageFilledArc(img,x,y,width,height,start,end,2);
+ case ArcBorder: gd_imageFilledArc(img,x,y,width,height,start,end,6);
+ case ChordFilled: gd_imageFilledArc(img,x,y,width,height,start,end,1);
+ case ChordOutline: gd_imageFilledArc(img,x,y,width,height,start,end,3);
+ case ChordBorder: gd_imageFilledArc(img,x,y,width,height,start,end,7);
+ }
+ }
+
+ public inline function imageFillToBorder(x:Int,y:Int, borderColor:Color):Void {
+ gd_imageFillToBorder(img,x,y,borderColor.gd);
+ }
+
+ public inline function imageFill(x:Int, y:Int) {
+ gd_imageFill(img,x,y);
+ }
+
+ private static var gd_setAntiAliasing = Lib.load("nGD","SetAntiAliasing",2);
+ private static var gd_setThickness = Lib.load("nGD","SetThickness",2);
+ private static var gd_setColor = Lib.load("nGD","SetColor",2);
+ private static var gd_setPixel = Lib.load("nGD","SetPixel",3);
+ private static var gd_imageLine = Lib.load("nGD","ImageLine",5);
+ private static var gd_imageDashedLine = Lib.load("nGD","ImageDashedLine",5);
+ private static var gd_imagePolygon = Lib.load("nGD","ImagePolygon",3);
+ private static var gd_imageFilledPolygon = Lib.load("nGD","ImageFilledPolygon",3);
+ private static var gd_imageOpenPolygon = Lib.load("nGD","ImageOpenPolygon",3);
+ private static var gd_imageRectangle = Lib.load("nGD","ImageRectangle",5);
+ private static var gd_imageFilledRectangle = Lib.load("nGD","ImageFilledRectangle",5);
+ private static var gd_imageFilledEllipse = Lib.load("nGD","ImageFilledEllipse",5);
+ private static var gd_imageArc = Lib.load("nGD","ImageArc",-1);
+ private static var gd_imageFilledArc = Lib.load("nGD","ImageFilledArc",-1);
+ private static var gd_imageFillToBorder = Lib.load("nGD","ImageFillToBorder",4);
+ private static var gd_imageFill = Lib.load("nGD","ImageFill",3);
+ //private static var gd_setBrush = Lib.load("nGD","SetBrush",3);
+ //private static var gd_setTile = Lib.load("nGD","SetTile",3);
+ private static var gd_setStyle = Lib.load("nGD","SetStyle",2);
+
+}
94 hxGD/Image.hx
@@ -0,0 +1,94 @@
+package hxGD;
+
+import neko.Lib;
+
+
+enum FileType {
+ Png;
+ Jpeg (quality:Int);
+ Gif;
+ Gd;
+ Gd2 (compressed:Bool, chunkSize:Int);
+}
+
+
+class Image {
+
+ public static var defaultBackgroundColor:Color = Color.ofRGB(0xFFFFFF);
+
+ public var img:Void;
+
+ public var trueColor(isTrueColor,null):Bool;
+ public var width(getWidth,null):Int;
+ public var height(getHeight,null):Int;
+
+ public var graphics:Graphics;
+
+ public function new (width:Int,height:Int,?color:Color,trueColor:Bool=true) {
+ if (img!=null)
+ gd_freeImage(img);
+ if (!trueColor) {
+ img = gd_imageCreate(width,height,(color==null?Image.defaultBackgroundColor.gd:color.gd));
+ //gd_setColor(img,(color==null?Image.defaultBackgroundColor.gd:color.gd));
+ //gd_imageFill(0,0);
+ graphics = new Graphics(img);
+ }
+ else {
+ img = gd_imageCreateTrueColor(width,height,(color==null?Image.defaultBackgroundColor.gd:color.gd));
+ //gd_setColor(img,(color==null?Image.defaultBackgroundColor.gd:color.gd));
+ graphics = new Graphics(img);
+ }
+ //trace("new image "+trueColor);
+ }
+
+ public inline function saveImage(filename:String,type:FileType):Void {
+ var file:Dynamic = Lib.haxeToNeko(filename);
+ switch (type) {
+ case Png: gd_imagePng(img,file);
+ case Jpeg(q): gd_imageJpeg(img,file,q);
+ case Gif: gd_imageGif(img,file);
+ case Gd: gd_imageGd(img,file);
+ case Gd2(comp,ch): gd_imageGd2(img,file,comp,ch);
+ }
+ }
+
+ public inline function make256Colors(?dithering:Bool=true,?anzColors:Int=255):Void {
+ gd_makeImageToPalette(img,dithering,(Math.abs(anzColors)<256?Math.abs(anzColors):255));
+ }
+
+ public inline function cloneTo256Colors(?dithering:Bool,?anzColors:Int=255):Image {
+ var ret:Image = Type.createEmptyInstance(Image);
+ ret.img = gd_cloneImageToPalette(img,dithering,(Math.abs(anzColors)<256?Math.abs(anzColors):255));
+ ret.graphics = new Graphics(ret.img);
+ return ret;
+ }
+
+ private function isTrueColor():Bool {
+ return gd_imageTrueColor(img);
+ }
+
+ private inline function getWidth():Int {
+ return gd_imageX(img);
+ }
+
+ private inline function getHeight():Int {
+ return gd_imageY(img);
+ }
+
+ private static var gd_imageFill = Lib.load("nGD","ImageFill",3);
+ private static var gd_setColor = Lib.load("nGD","SetColor",2);
+ private static var gd_freeImage = Lib.load("nGD","FreeImage",1);
+ private static var gd_imageCreate = Lib.load("nGD","ImageCreate",3);
+ private static var gd_imageCreateTrueColor = Lib.load("nGD","ImageCreateTrueColor",3);
+ private static var gd_imageJpeg = Lib.load("nGD","ImageJpeg",3);
+ private static var gd_imageGif = Lib.load("nGD","ImageGif",2);
+ private static var gd_imagePng = Lib.load("nGD","ImagePng",2);
+ private static var gd_imageGd = Lib.load("nGD","ImageGd",2);
+ private static var gd_imageGd2 = Lib.load("nGD","ImageGd2",4);
+ private static var gd_makeImageToPalette = Lib.load("nGD","MakeImageToPalette",3);
+ private static var gd_cloneImageToPalette = Lib.load("nGD","CloneImageToPalette",3);
+ private static var gd_imageX = Lib.load("nGD","ImageX",1);
+ private static var gd_imageY = Lib.load("nGD","ImageY",1);
+ private static var gd_imageTrueColor = Lib.load("nGD","ImageTrueColor",1);
+
+}
66 hxGD/Loader.hx
@@ -0,0 +1,66 @@
+package hxGD;
+
+import neko.Lib;
+
+class Loader {
+
+ public static inline function createFromJpeg (filename:String):Image {
+ var ret:Image = Type.createEmptyInstance(Image);
+ ret.img = gd_imageCreateFromJpeg(Lib.haxeToNeko(filename));
+ ret.graphics = new Graphics(ret.img);
+ return ret;
+ }
+
+ public static inline function createFromPng (filename:String):Image {
+ var ret:Image = Type.createEmptyInstance(Image);
+ ret.img = gd_imageCreateFromPng(Lib.haxeToNeko(filename));
+ ret.graphics = new Graphics(ret.img);
+ return ret;
+ }
+
+ public static inline function createFromGif (filename:String):Image {
+ var ret:Image = Type.createEmptyInstance(Image);
+ ret.img = gd_imageCreateFromGif(Lib.haxeToNeko(filename));
+ ret.graphics = new Graphics(ret.img);
+ return ret;
+ }
+
+ public static inline function createFromGd (filename:String):Image {
+ var ret:Image = Type.createEmptyInstance(Image);
+ ret.img = gd_imageCreateFromGd(Lib.haxeToNeko(filename));
+ ret.graphics = new Graphics(ret.img);
+ return ret;
+ }
+
+ public static inline function createFromGd2 (filename:String):Image {
+ var ret:Image = Type.createEmptyInstance(Image);
+ ret.img = gd_imageCreateFromGd2(Lib.haxeToNeko(filename));
+ ret.graphics = new Graphics(ret.img);
+ return ret;
+ }
+
+ public static inline function createFromGd2Part (filename:String,srcX:Int,srcY:Int,width:Int,height:Int):Image {
+ var ret:Image = Type.createEmptyInstance(Image);
+ ret.img = gd_imageCreateFromGd2Part(Lib.haxeToNeko(filename),srcX,srcY,width,height);
+ ret.graphics = new Graphics(ret.img);
+ return ret;
+ }
+
+ public static inline function createFromWBMP(filename:String):Image {
+ var ret:Image = Type.createEmptyInstance(Image);
+ ret.img = gd_imageCreateFromWBMP(Lib.haxeToNeko(filename));
+ ret.graphics = new Graphics(ret.img);
+ return ret;
+ }
+
+
+
+
+ private static var gd_imageCreateFromJpeg = Lib.load("nGD","ImageCreateFromJpeg",1);
+ private static var gd_imageCreateFromPng = Lib.load("nGD","ImageCreateFromPng",1);
+ private static var gd_imageCreateFromGif = Lib.load("nGD","ImageCreateFromGif",1);
+ private static var gd_imageCreateFromGd = Lib.load("nGD","ImageCreateFromGd",1);
+ private static var gd_imageCreateFromGd2 = Lib.load("nGD","ImageCreateFromGd2",1);
+ private static var gd_imageCreateFromGd2Part = Lib.load("nGD","ImageCreateFromGd2Part",5);
+ private static var gd_imageCreateFromWBMP = Lib.load("nGD","ImageCreateFromWBMP",1);
+}
41 hxGD/Polygon.hx
@@ -0,0 +1,41 @@
+package hxGD;
+
+import neko.Lib;
+
+typedef PolygonPoint = {
+ x : Int,
+ y : Int
+}
+
+class Polygon {
+
+ public var x(getX,null):Array<Int>;
+ public var y(getY,null):Array<Int>;
+
+ private var _x:Array<Int>;
+ private var _y:Array<Int>;
+
+ public function new() {
+ _x = new Array<Int>();
+ _y = new Array<Int>();
+ }
+
+ public inline function addPoint(x:Int,y:Int):Void {
+ _x.push(x);
+ _y.push(y);
+ }
+
+ public inline function addPolygonPoint(p:PolygonPoint):Void {
+ _x.push(p.x);
+ _y.push(p.y);
+ }
+
+ private inline function getX():Array<Int> {
+ return Lib.haxeToNeko(_x);
+ }
+
+ private inline function getY():Array<Int> {
+ return Lib.haxeToNeko(_y);
+ }
+
+}
33 makefile
@@ -0,0 +1,33 @@
+
+NEKOPATH=/usr/lib/neko/include/
+
+CC=gcc
+CFLAGS=-Wall -shared -I$(NEKOPATH)
+BINDING=-lgd
+
+OUT=nGD.ndll
+
+all: nGD src/nGDImage.o src/nGDDraw.o src/nGDFile.o src/nGD.o src/nGDCopy.o
+ $(CC) $(CFLAGS) $(BINDING) src/nGDImage.o src/nGDDraw.o src/nGDFile.o src/nGD.o src/nGDCopy.o -o $(OUT)
+
+nGD: src/nGD.o nGDFile
+
+nGDFile: src/nGDFile.o nGDImage
+
+nGDDraw: src/nGDDraw.o nGDImage
+
+nGDCopy: src/nGDCopy.o nGDImage
+
+nGDImage: src/nGDImage.o
+
+clean:
+ rm -f src/*.o
+
+force:
+ touch src/*.c
+
+haxe:
+ haxe build.hxml
+
+run:
+ neko test1.n
131 src/nGD.c
@@ -0,0 +1,131 @@
+/*
+ * nGD.c
+ *
+ * Copyright 2009 Philipp Klose <hippo@byteanvil.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ */
+
+#include <gd.h>
+#include <neko.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include "nGDFile.h"
+#include "nGDImage.h"
+#include "nGDDraw.h"
+#include "nGDCopy.h"
+
+
+value ImageCreate(value x,value y, value back) {
+ int _x = val_int(x);
+ int _y = val_int(y);
+ gdImagePtr img = gdImageCreate(_x,_y);
+ value ret = alloc_gc_image(img);
+ ImageData i = getImage(ret);
+ initColor(i,back);
+ return ret;
+}
+
+value ImageCreateTrueColor(value x,value y,value back) {
+ int _x = val_int(x);
+ int _y = val_int(y);
+ gdImagePtr img = gdImageCreateTrueColor(_x,_y);
+ value ret = alloc_gc_image(img);
+ ImageData i = getImage(ret);
+ int _color = initColor(i,back);
+ gdImageFill(imageImage(i),0,0,_color);
+ return ret;
+}
+
+value MakeImageToPalette(value img,value dither,value anzColors) {
+ ImageData _img = getImage(img);
+ int _dither = val_bool(dither);
+ int _anzColors = val_int(anzColors);
+ gdImageTrueColorToPalette(imageImage(_img),_dither,_anzColors);
+ return val_null;
+}
+
+value CloneImageToPalette(value img,value dither, value anzColors) {
+ ImageData _img = getImage(img);
+ int _dither = val_bool(dither);
+ int _anzColors = val_int(anzColors);
+ gdImagePtr _clone = gdImageCreatePaletteFromTrueColor(imageImage(_img),_dither,_anzColors);
+ return alloc_gc_image(_clone);
+}
+
+
+value ImageX(value img) {
+ ImageData _img = getImage(img);
+ int x = gdImageSX(imageImage(_img));
+ return alloc_int(x);
+}
+
+value ImageY(value img) {
+ ImageData _img = getImage(img);
+ int y = gdImageSY(imageImage(_img));
+ return alloc_int(y);
+}
+
+
+value ImageTrueColor(value img) {
+ ImageData _img = getImage(img);
+ int tc = gdImageTrueColor(imageImage(_img));
+ if (tc!=0)
+ return val_true;
+ else
+ return val_false;
+}
+
+
+DEFINE_PRIM(SetAntiAliasing,2);
+DEFINE_PRIM(SetThickness,2);
+DEFINE_PRIM(SetColor,2);
+DEFINE_PRIM(FreeImage,1);
+DEFINE_PRIM(ImageCreate,3);
+DEFINE_PRIM(ImageCreateTrueColor,3);
+DEFINE_PRIM(ImageCreateFromJpeg,1);
+DEFINE_PRIM(ImageCreateFromPng,1);
+DEFINE_PRIM(ImageCreateFromGif,1);
+DEFINE_PRIM(ImageCreateFromGd,1);
+DEFINE_PRIM(ImageCreateFromGd2,1);
+DEFINE_PRIM(ImageCreateFromGd2Part,5);
+DEFINE_PRIM(ImageCreateFromWBMP,1);
+DEFINE_PRIM(ImageJpeg,3);
+DEFINE_PRIM(ImageGif,2);
+DEFINE_PRIM(ImagePng,2);
+DEFINE_PRIM(ImageGd,2);
+DEFINE_PRIM(ImageGd2,4);
+DEFINE_PRIM(MakeImageToPalette,3);
+DEFINE_PRIM(CloneImageToPalette,3);
+DEFINE_PRIM(ImageX,1);
+DEFINE_PRIM(ImageY,1);
+DEFINE_PRIM(ImageTrueColor,1);
+DEFINE_PRIM(SetPixel,3);
+DEFINE_PRIM(ImageLine,5);
+DEFINE_PRIM(ImageDashedLine,5);
+DEFINE_PRIM(ImagePolygon,3);
+DEFINE_PRIM(ImageOpenPolygon,3);
+DEFINE_PRIM(ImageRectangle,5);
+DEFINE_PRIM(ImageFilledPolygon,3);
+DEFINE_PRIM(ImageFilledRectangle,5);
+DEFINE_PRIM_MULT(ImageArc);
+DEFINE_PRIM_MULT(ImageFilledArc);
+DEFINE_PRIM(ImageFilledEllipse,5);
+DEFINE_PRIM(ImageFillToBorder,4);
+DEFINE_PRIM(ImageFill,3);
+//DEFINE_PRIM(SetBrush,3);
+//DEFINE_PRIM(SetTile,3);
+DEFINE_PRIM(SetStyle,2);
46 src/nGDCopy.c
@@ -0,0 +1,46 @@
+/*
+ * nGDCopy.c
+ *
+ * Copyright 2009 Philipp Klose <hippo@byteanvil.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ */
+
+#include <gd.h>
+#include <neko.h>
+#include "nGDImage.h"
+
+value CloneImage(value img) {
+ ImageData _img = getImage(img);
+ gdImagePtr cd = gdImageCreateTrueColor(gdImageSX(imageImage(_img)),gdImageSY(imageImage(_img)));
+ gdImageCopy(cd,imageImage(_img),0,0,0,0,gdImageSX(imageImage(_img)),gdImageSY(imageImage(_img)));
+ value ret = alloc_gc_image(cd);
+ return ret;
+}
+
+// void gdImageCopy(gdImagePtr dst, gdImagePtr src, int dstX, int dstY, int srcX, int srcY, int w, int h)
+
+value GetImagePart(value img,value x,value y,value w,value h) {
+ ImageData _img = getImage(img);
+ int _x = abs(val_int(x));
+ int _y = abs(val_int(y));
+ int _w = abs(val_int(w));
+ int _h = abs(val_int(h));
+ gdImagePtr cd = gdImageCreateTrueColor(_w,_h);
+ gdImageCopy(cd,imageImage(_img),0,0,_x,_y,_w,_h);
+ value ret = alloc_gc_image(cd);
+ return ret;
+}
21 src/nGDCopy.h
@@ -0,0 +1,21 @@
+/*
+ * nGDCopy.h
+ *
+ * Copyright 2009 Philipp Klose <hippo@byteanvil.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ */
+
190 src/nGDDraw.c
@@ -0,0 +1,190 @@
+/*
+ * nGDDraw.c
+ *
+ * Copyright 2009 Philipp Klose <hippo@byteanvil.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ */
+
+#include <neko.h>
+#include <gd.h>
+#include <stdlib.h>
+#include "nGDImage.h"
+
+value SetPixel(value img,value x,value y) {
+ ImageData _img = getImage(img);
+ int _x = val_int(x);
+ int _y = val_int(y);
+ gdImageSetPixel(imageImage(_img),_x,_y,imageColor(_img));
+ return val_null;
+}
+
+value ImageLine(value img,value x1,value y1, value x2, value y2) {
+ ImageData _img = getImage(img);
+ int _x1 = val_int(x1);
+ int _y1 = val_int(y1);
+ int _x2 = val_int(x2);
+ int _y2 = val_int(y2);
+// printf("imageLine: %i - c:%i\n",imageColor(_img),_img->color);
+ gdImageLine(imageImage(_img),_x1,_y1,_x2,_y2,imageColor(_img));
+ //printf("after gdImageLine\n");
+ return val_null;
+}
+
+
+
+value ImageDashedLine(value img,value x1,value y1, value x2, value y2) {
+ ImageData _img = getImage(img);
+ int _x1 = val_int(x1);
+ int _y1 = val_int(y1);
+ int _x2 = val_int(x2);
+ int _y2 = val_int(y2);
+ gdImageDashedLine(imageImage(_img),_x1,_y1,_x2,_y2,imageColor(_img));
+ return val_null;
+}
+
+gdPoint* pointsHaxeToGd (value *x, value *y,int nPoints) {
+ gdPoint *points = (gdPoint*)alloc(sizeof(gdPoint)*nPoints);
+ int i;
+ for (i=0; i<nPoints; i++) {
+ points[i].x = val_int(x[i]);
+ points[i].y = val_int(y[i]);
+ }
+ return points;
+}
+
+value ImagePolygon(value img,value x,value y) {
+ ImageData _img = getImage(img);
+ int _nPoints = val_array_size(x);
+ if ((val_array_size(y)==_nPoints) && (_nPoints>2)) {
+ value *_x = val_array_ptr(x);
+ value *_y = val_array_ptr(y);
+ gdPoint *points = pointsHaxeToGd(_x,_y,_nPoints);
+ gdImagePolygon(imageImage(_img),points,_nPoints,imageColor(_img));
+ free(points);
+ return val_true;
+ }
+ return val_false;
+}
+
+value ImageOpenPolygon(value img,value x,value y,value color) {
+ ImageData _img = getImage(img);
+ int _nPoints = val_array_size(x);
+ if ((val_array_size(y)==_nPoints) && (_nPoints>2)) {
+ value *_x = val_array_ptr(x);
+ value *_y = val_array_ptr(y);
+ gdPoint *points = pointsHaxeToGd(_x,_y,_nPoints);
+ gdImageOpenPolygon(imageImage(_img),points,_nPoints,imageColor(_img));
+ free(points);
+ return val_true;
+ }
+ return val_false;
+}
+
+value ImageRectangle(value img,value x,value y, value width, value height) {
+ ImageData _img = getImage(img);
+ int _x1 = val_int(x);
+ int _y1 = val_int(y);
+ int _x2 = _x1 + val_int(width);
+ int _y2 = _y1 + val_int(height);
+ gdImageRectangle(imageImage(_img),_x1,_y1,_x2,_y2,imageColor(_img));
+ return val_null;
+}
+
+value ImageFilledPolygon(value img,value x,value y) {
+ ImageData _img = getImage(img);
+ int _nPoints = val_array_size(x);
+ if ((val_array_size(y)==_nPoints) && (_nPoints>2)) {
+ value *_x = val_array_ptr(x);
+ value *_y = val_array_ptr(y);
+ gdPoint *points = pointsHaxeToGd(_x,_y,_nPoints);
+ gdImageFilledPolygon(imageImage(_img),points,_nPoints,imageColor(_img));
+ free(points);
+ return val_true;
+ }
+ return val_false;
+}
+
+
+value ImageFilledRectangle(value img,value x,value y, value width, value height) {
+ ImageData _img = getImage(img);
+ int _x1 = val_int(x);
+ int _y1 = val_int(y);
+ int _x2 = _x1 + val_int(width);
+ int _y2 = _y1 + val_int(height);
+ gdImageFilledRectangle(imageImage(_img),_x1,_y1,_x2,_y2,imageColor(_img));
+ return val_null;
+}
+
+//value ImageArc(value img, value x,value y,value width, value height,value start, value end) {
+value ImageArc(value *args, int nargs) {
+ enum {eImg,eX,eY,eWidth,eHeight,eStart,eEnd,eSize};
+ if (nargs != eSize)
+ neko_error();
+ ImageData _img = getImage(args[eImg]);
+ int _x = val_int(args[eX]);
+ int _y = val_int(args[eY]);
+ int _w = val_int(args[eWidth]);
+ int _h = val_int(args[eHeight]);
+ int _start = val_int(args[eStart]);
+ int _end = val_int(args[eEnd]);
+ gdImageArc(imageImage(_img),_x,_y,_w,_h,_start,_end,imageColor(_img));
+ return val_null;
+}
+
+//value ImageFilledArc(value img, value x,value y,value width, value height,value start, value end, value style) {
+value ImageFilledArc(value *args, int nargs) {
+ enum {eImg,eX,eY,eWidth,eHeight,eStart,eEnd,eStyle,eSize};
+ if (nargs!=eSize)
+ neko_error();
+ ImageData _img = getImage(args[eImg]);
+ int _x = val_int(args[eX]);
+ int _y = val_int(args[eY]);
+ int _w = val_int(args[eWidth]);
+ int _h = val_int(args[eHeight]);
+ int _start = val_int(args[eStart]);
+ int _end = val_int(args[eEnd]);
+ int _style = val_int(args[eStyle]);
+ gdImageFilledArc(imageImage(_img),_x,_y,_w,_h,_start,_end,imageColor(_img),_style);
+ return val_null;
+}
+
+value ImageFilledEllipse(value img, value x, value y, value w, value h) {
+ ImageData _img = getImage(img);
+ int _x = val_int(x);
+ int _y = val_int(y);
+ int _w = val_int(w);
+ int _h = val_int(h);
+ gdImageFilledEllipse(imageImage(_img),_x,_y,_w,_h,imageColor(_img));
+ return val_null;
+}
+
+value ImageFillToBorder(value img, value x, value y, value border) {
+ ImageData _img = getImage(img);
+ int _x = val_int(x);
+ int _y = val_int(y);
+ int _border = initColor(_img,border);
+ gdImageFillToBorder(imageImage(_img),_x,_y,_border,imageColor(_img));
+ return val_null;
+}
+
+value ImageFill(value img, value x, value y) {
+ ImageData _img = getImage(img);
+ int _x = val_int(x);
+ int _y = val_int(y);
+ gdImageFill(imageImage(_img),_x,_y,imageColor(_img));
+ return val_null;
+}
49 src/nGDDraw.h
@@ -0,0 +1,49 @@
+/*
+ * nGDDraw.h
+ *
+ * Copyright 2009 Philipp Klose <hippo@byteanvil.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ */
+
+
+value SetPixel(value img,value x,value y);
+
+value ImageLine(value img,value x1,value y1, value x2, value y2);
+
+value ImageDashedLine(value img,value x1,value y1, value x2, value y2);
+
+value ImagePolygon(value img,value x,value y);
+
+value ImageOpenPolygon(value img,value x,value y,value color);
+
+value ImageRectangle(value img,value x,value y, value width, value height);
+
+value ImageFilledPolygon(value img,value x,value y);
+
+value ImageFilledRectangle(value img,value x,value y, value width, value height);
+
+//value ImageArc(value img, value x,value y,value width, value height,value start, value end) {
+value ImageArc(value *args, int nargs);
+
+//value ImageFilledArc(value img, value x,value y,value width, value height,value start, value end, value style) {
+value ImageFilledArc(value *args, int nargs);
+
+value ImageFilledEllipse(value img, value x, value y, value w, value h);
+
+value ImageFillToBorder(value img, value x, value y, value border);
+
+value ImageFill(value img, value x, value y);
142 src/nGDFile.c
@@ -0,0 +1,142 @@
+/*
+ * nGDFile.c
+ *
+ * Copyright 2009 Philipp Klose <hippo@byteanvil.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ */
+
+#include <neko.h>
+#include <gd.h>
+#include "nGDImage.h"
+
+
+value ImageCreateFromJpeg(value filename) {
+ val_check(filename,string);
+ char *_filename = val_string(filename);
+ FILE *_file = fopen(_filename,"r");
+ gdImagePtr img = gdImageCreateFromJpeg(_file);
+ fclose(_file);
+ value ret = alloc_gc_image(img);
+ return ret;
+}
+
+value ImageCreateFromPng(value filename) {
+ val_check(filename,string);
+ char *_filename = val_string(filename);
+ FILE *_file = fopen(_filename,"r");
+ gdImagePtr img = gdImageCreateFromPng(_file);
+ fclose(_file);
+ return alloc_gc_image(img);
+}
+
+value ImageCreateFromGif(value filename) {
+ val_check(filename,string);
+ char *_filename = val_string(filename);
+ FILE *_file = fopen(_filename,"r");
+ gdImagePtr img = gdImageCreateFromGif(_file);
+ fclose(_file);
+ return alloc_gc_image(img);
+}
+
+value ImageCreateFromGd(value filename) {
+ val_check(filename,string);
+ char *_filename = val_string(filename);
+ FILE *_file = fopen(_filename,"r");
+ gdImagePtr img = gdImageCreateFromGd(_file);
+ fclose(_file);
+ return alloc_gc_image(img);
+}
+
+value ImageCreateFromGd2(value filename) {
+ val_check(filename,string);
+ char *_filename = val_string(filename);
+ FILE *_file = fopen(_filename,"r");
+ gdImagePtr img = gdImageCreateFromGd2(_file);
+ fclose(_file);
+ return alloc_gc_image(img);
+}
+
+value ImageCreateFromGd2Part(value filename, value srcX, value srcY, value width, value height) {
+ val_check(filename,string);
+ char *_filename = val_string(filename);
+ FILE *_file = fopen(_filename,"r");
+ int _srcX = val_int(srcX);
+ int _srcY = val_int(srcY);
+ int _width = val_int(width);
+ int _height = val_int(height);
+ gdImagePtr img = gdImageCreateFromGd2Part(_file,_srcX,_srcY,_width,_height);
+ fclose(_file);
+ return alloc_gc_image(img);
+}
+
+value ImageCreateFromWBMP(value filename) {
+ val_check(filename,string);
+ char *_filename = val_string(filename);
+ FILE *_file = fopen(_filename,"r");
+ gdImagePtr img = gdImageCreateFromWBMP(_file);
+ fclose(_file);
+ return alloc_gc_image(img);
+}
+
+
+value ImageJpeg(value img,value filename,value quality) {
+ char *_filename = val_string(filename);
+ int _quality = val_int(quality);
+ ImageData _img = getImage(img);
+ FILE *_file = fopen(_filename,"wb");
+ gdImageJpeg(imageImage(_img),_file,_quality);
+ fclose(_file);
+ return val_null;
+}
+
+value ImageGif(value img,value filename) {
+ char *_filename = val_string(filename);
+ ImageData _img = getImage(img);
+ FILE *_file = fopen(_filename,"wb");
+ gdImageGif(imageImage(_img),_file);
+ fclose(_file);
+ return val_null;
+}
+
+value ImagePng(value img,value filename) {
+ char *_filename = val_string(filename);
+ ImageData _img = getImage(img);
+ FILE *_file = fopen(_filename,"wb");
+ gdImagePng(imageImage(_img),_file);
+ fclose(_file);
+ return val_null;
+}
+
+value ImageGd (value img,value filename) {
+ char *_filename = val_string(filename);
+ ImageData _img = getImage(img);
+ FILE *_file = fopen(_filename,"wb");
+ gdImageGd(imageImage(_img),_file);
+ fclose(_file);
+ return val_null;
+}
+
+value ImageGd2 (value img,value filename,value compressed,value chunksize) {
+ ImageData _img = getImage(img);
+ char *_filename = val_string(filename);
+ int _compressed = val_int(compressed);
+ int _chunksize = val_int(chunksize);
+ FILE *_file = fopen(_filename,"wb");
+ gdImageGd2(imageImage(_img),_file,_chunksize,_compressed);
+ fclose(_file);
+ return val_null;
+}
46 src/nGDFile.h
@@ -0,0 +1,46 @@
+/*
+ * nGDFile.c
+ *
+ * Copyright 2009 Philipp Klose <hippo@byteanvil.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ */
+
+
+
+value ImageCreateFromJpeg(value filename);
+
+value ImageCreateFromPng(value filename);
+
+value ImageCreateFromGif(value filename);
+
+value ImageCreateFromGd(value filename);
+
+value ImageCreateFromGd2(value filename);
+
+value ImageCreateFromGd2Part(value filename, value srcX, value srcY, value width, value height);
+
+value ImageCreateFromWBMP(value filename);
+
+value ImageJpeg(value img,value filename,value quality);
+
+value ImageGif(value img,value filename);
+
+value ImagePng(value img,value filename);
+
+value ImageGd (value img,value filename);
+
+value ImageGd2 (value img,value filename,value compressed,value chunksize);
219 src/nGDImage.c
@@ -0,0 +1,219 @@
+/*
+ * nGDImage.c
+ *
+ * Copyright 2009 Philipp Klose <hippo@byteanvil.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ */
+
+#include <neko.h>
+#include <gd.h>
+#include <stdlib.h>
+
+#define abs(i) (i>0?i:-i)
+
+//#ifndef _GDIP
+//#define _GDIP
+DEFINE_KIND(ImagePtr);
+//#endif
+
+
+#define imageAntiAliased 1
+#define imageBrushed 2
+#define imageTiled 4
+#define imageStyled 8
+
+struct _ImageData {
+ int config;
+ int color;
+ int thickness;
+ gdImagePtr img;
+ //gdImagePtr brush;
+};
+
+typedef struct _ImageData *ImageData;
+
+
+#define imageIsAntiAliased(i) ((((i->config) & imageAntiAliased) == imageAntiAliased)?1:0)
+#define imageIsStyled(i) ((((i->config) & imageStyled) == imageStyled)?1:0)
+#define imageSetAntiAliased(i,a) (i->config = ((a==1) ? (i->config | imageAntiAliased) : (i->config & ~imageAntiAliased)))
+#define imageSetStyled(i,a) (i->config = ((a==1) ? (i->config | imageStyled) : (i->config & ~imageStyled)))
+//#define imageSetBrushed(i,a) (i->config = ((a==1) ? (i->config | imageBrushed) : (i->config & ~imageBrushed)))
+//#define imageSetTiled(i,a) (i->config = ((a==1) ? (i->config | imageTiled) : (i->config & ~imageTiled)))
+//#define imageIsBrushed(i) ((((i->config) & imageBrushed) == imageBrushed)?1:0)
+//#define imageIsTiled(i) ((((i->config) & imageTiled) == imageTiled)?1:0)
+#define imageConfig(i) (i->config)
+#define imageThickness(i) (i->thickness)
+//#define imageColor(i) (imageThickness(i)==1?(imageIsAntiAliased(i)==0?i->color:gdAntiAliased):i->color)
+//#define imageColor(i) (imageIsAntiAliased(i)==0?i->color:gdAntiAliased)
+#define imageImage(i) (i->img)
+//#define imageBrush(i) (i->brush)
+//#define imageTile(i) (i->brush)
+
+
+//#define getImage(v) ((val_is_kind(v,ImagePtr)?val_data(v):NULL))
+
+
+// More safe
+
+int imageColor(ImageData img) {
+ //if (imageIsBrushed(img)==1) {
+ // printf("brushed\n");
+ // return gdBrushed;
+ //}
+ //if (imageIsTiled(img)==1) {
+ // return gdTiled;
+ //}
+ if (imageIsStyled(img)==1)
+ return gdStyled;
+ if (imageThickness(img)==1) {
+ if (imageIsAntiAliased(img)==0)
+ return img->color;
+ else
+ return gdAntiAliased;
+ }
+ else {
+ return img->color;
+ }
+}
+
+ImageData getImage(value img) {
+ val_check_kind(img,ImagePtr);
+ return val_data(img);
+}
+
+/*
+void setBrushImage(ImageData in,ImageData cl) {
+ gdImagePtr cld;
+ if (gdImageTrueColor(imageImage(in))) {
+ // printf("clone true color\n");
+ cld = gdImageCreateTrueColor(gdImageSX(imageImage(in)),gdImageSY(imageImage(in)));
+ }
+ else {
+// printf("clone palette\n");
+ cld = gdImageCreate(gdImageSX(imageImage(in)),gdImageSY(imageImage(in)));
+ }
+// printf("made copy\n");
+ gdImageCopy(cld,imageImage(in),0,0,0,0,gdImageSX(imageImage(in)),gdImageSY(imageImage(in)));
+ imageBrush(in)=cld;
+}
+
+value SetBrush(value img,value brush, value flag) {
+ ImageData _img = getImage(img);
+ if (val_bool(flag)==1) {
+ imageSetTiled(_img,0);
+ imageSetBrushed(_img,1);
+ ImageData _brush = getImage(brush);
+ //printf("before clone\n");
+ setBrushImage(_img,_brush);
+ //(imageImage(_brush));
+ //printf("after clone\n");
+ }
+ return val_null;
+}
+
+value SetTile(value img, value tile, value flag) {
+ ImageData _img = getImage(img);
+ if (val_bool(flag)==1) {
+ imageSetBrushed(_img,0);
+ imageSetTiled(_img,1);
+ ImageData _tile = getImage(tile);
+ setBrushImage(_img,_tile);
+ }
+ return val_null;
+} */
+
+value FreeImage (value v) {
+ ImageData img = getImage(v);
+ gdImageDestroy(imageImage(img));
+// if (imageBrush(img)!=NULL)
+// gdImageDestroy(imageBrush(img));
+ return val_null;
+}
+
+void finalize( value v ) {
+ FreeImage(v);
+}
+
+value alloc_gc_image(gdImagePtr image) {
+ ImageData abstr = (ImageData)alloc_private(sizeof(ImageData));
+ imageImage(abstr) = image;
+ imageConfig(abstr) = 0;
+ imageThickness(abstr) = 0;
+ //imageBrush(abstr) = NULL;
+ value ret = alloc_abstract(ImagePtr,abstr);
+ val_gc(ret,finalize);
+ return ret;
+}
+
+int initColor(ImageData img,value color) {
+
+ //imageSetBrushed(img,0);
+ //imageSetTiled(img,0);
+ imageSetStyled(img,0);
+
+ int _color = val_int(color);
+ int alpha = (255 -(0x000000FF & _color)) >> 1;
+ int red = (0xFF000000 & _color) >> 24;
+ int green = (0x00FF0000 & _color) >> 16;
+ int blue = (0x0000FF00 & _color) >> 8;
+ int c = gdImageColorResolveAlpha(imageImage(img),red,green,blue,alpha);
+ //if (c == -1)
+ // c = gdImageColorClosestAlpha(imageImage(img),red,green,blue,alpha);
+ if (imageIsAntiAliased(img)==1)
+ gdImageSetAntiAliased(imageImage(img),c);
+ return c;
+}
+
+value SetStyle(value img,value colors) {
+ ImageData _img = getImage(img);
+ int n = val_array_size(colors);
+ value *_colors = val_array_ptr(colors);
+ int style[n];
+ int i;
+ for (i=0;i<n;i++)
+ style[i]=initColor(_img,_colors[i]);
+ imageSetStyled(_img,1);
+ gdImageSetStyle(imageImage(_img),style,n);
+ return val_null;
+}
+
+
+value SetAntiAliasing (value img, value antiAlias) {
+ ImageData _img = getImage(img);
+
+ imageSetAntiAliased(_img,val_bool(antiAlias));
+
+ if (imageIsAntiAliased(_img)==1)
+ gdImageSetAntiAliased(imageImage(_img),imageColor(_img));
+
+ return val_null;
+}
+
+value SetThickness(value img, value thickness) {
+ ImageData _img = getImage(img);
+ imageThickness(_img) = abs(val_int(thickness));
+ gdImageSetThickness(imageImage(_img),imageThickness(_img));
+ if (imageIsAntiAliased(_img)==1)
+ gdImageSetAntiAliased(imageImage(_img),imageColor(_img));
+ return alloc_int(imageThickness(_img));
+}
+
+value SetColor(value img, value color) {
+ ImageData _img = getImage(img);
+ _img->color = initColor(_img,color);
+ return val_null;
+}
82 src/nGDImage.h
@@ -0,0 +1,82 @@
+/*
+ * nGDImage.h
+ *
+ * Copyright 2009 Philipp Klose <hippo@byteanvil.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ */
+
+#define abs(i) (i>0?i:-i)
+
+#define imageAntiAliased 1
+#define imageBrushed 2
+#define imageTiled 4
+#define imageStyled 8
+
+struct _ImageData {
+ int config;
+ int color;
+ int thickness;
+ gdImagePtr img;
+};
+
+typedef struct _ImageData *ImageData;
+
+
+
+#define imageIsAntiAliased(i) ((((i->config) & imageAntiAliased) == imageAntiAliased)?1:0)
+#define imageIsStyled(i) ((((i->config) & imageStyled) == imageStyled)?1:0)
+#define imageSetAntiAliased(i,a) (i->config = ((a==1) ? (i->config | imageAntiAliased) : (i->config & ~imageAntiAliased)))
+#define imageSetStyled(i,a) (i->config = ((a==1) ? (i->config | imageStyled) : (i->config & ~imageStyled)))
+//#define imageSetBrushed(i,a) (i->config = ((a==1) ? (i->config | imageBrushed) : (i->config & ~imageBrushed)))
+//#define imageSetTiled(i,a) (i->config = ((a==1) ? (i->config | imageTiled) : (i->config & ~imageTiled)))
+//#define imageIsBrushed(i) ((((i->config) & imageBrushed) == imageBrushed)?1:0)
+//#define imageIsTiled(i) ((((i->config) & imageTiled) == imageTiled)?1:0)
+#define imageConfig(i) (i->config)
+#define imageThickness(i) (i->thickness)
+//#define imageColor(i) (imageThickness(i)==1?(imageIsAntiAliased(i)==0?i->color:gdAntiAliased):i->color)
+//#define imageColor(i) (imageIsAntiAliased(i)==0?i->color:gdAntiAliased)
+#define imageImage(i) (i->img)
+//#define imageBrush(i) (i->brush)
+//#define imageTile(i) (i->brush)
+
+
+//#define getImage(v) ((val_is_kind(v,ImagePtr)?val_data(v):NULL))
+
+
+int imageColor(ImageData img);
+
+ImageData getImage(value img);
+
+value FreeImage (value v);
+
+void finalize( value v );
+
+value alloc_gc_image(gdImagePtr image);
+
+int initColor(ImageData img,value color);
+
+value SetStyle(value img,value colors);
+
+//value SetBrush(value img,value brush, value flag);
+
+//value SetTile(value img, value tile, value flag);
+
+value SetAntiAliasing (value img, value antiAlias);
+
+value SetThickness(value img, value thickness);
+
+value SetColor(value img, value color);
Please sign in to comment.
Something went wrong with that request. Please try again.