From c28fa00d6a835b1f538122be9801727eaf0c967b Mon Sep 17 00:00:00 2001 From: Harco de Hilster Date: Sun, 5 Mar 2000 18:05:55 +0000 Subject: [PATCH] added java support in the GIFPlot example some minor changes where needed in the interface file git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@331 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/GIFPlot/Interface/gifplot.i | 17 ++ Examples/GIFPlot/Java/Makefile | 17 ++ Examples/GIFPlot/Java/README | 30 +++ Examples/GIFPlot/Java/cm15 | Bin 0 -> 768 bytes Examples/GIFPlot/Java/cmap | Bin 0 -> 768 bytes Examples/GIFPlot/Java/gifplot.i | 273 +++++++++++++++++++++++++++ Examples/GIFPlot/Java/ortho.java | 107 +++++++++++ Examples/GIFPlot/Java/shadow.java | 22 +++ Examples/GIFPlot/Java/simple.java | 22 +++ 9 files changed, 488 insertions(+) create mode 100644 Examples/GIFPlot/Java/Makefile create mode 100644 Examples/GIFPlot/Java/README create mode 100644 Examples/GIFPlot/Java/cm15 create mode 100644 Examples/GIFPlot/Java/cmap create mode 100644 Examples/GIFPlot/Java/gifplot.i create mode 100644 Examples/GIFPlot/Java/ortho.java create mode 100644 Examples/GIFPlot/Java/shadow.java create mode 100644 Examples/GIFPlot/Java/simple.java diff --git a/Examples/GIFPlot/Interface/gifplot.i b/Examples/GIFPlot/Interface/gifplot.i index f64162385..b8f17f657 100644 --- a/Examples/GIFPlot/Interface/gifplot.i +++ b/Examples/GIFPlot/Interface/gifplot.i @@ -30,7 +30,11 @@ typedef struct ColorMap { %addmethods { ColorMap(char *filename); ~ColorMap(); +#ifdef SWIGJAVA + %name(make_default) void default(); +#else void default(); +#endif void assign(int index,int r, int g, int b); %name(__getitem__) int getitem(int index); %name(__setitem__) void setitem(int index, int value); @@ -40,6 +44,16 @@ typedef struct ColorMap { /* Some default colors */ +#ifdef SWIGJAVA +const Pixel BLACK = 0; +const Pixel WHITE = 1; +const Pixel RED = 2; +const Pixel GREEN = 3; +const Pixel BLUE = 4; +const Pixel YELLOW = 5; +const Pixel CYAN = 6; +const Pixel MAGENTA = 7; +#else #define BLACK 0 #define WHITE 1 #define RED 2 @@ -48,6 +62,7 @@ typedef struct ColorMap { #define YELLOW 5 #define CYAN 6 #define MAGENTA 7 +#endif /*------------------------------------------------------------------------- FrameBuffer @@ -245,9 +260,11 @@ typedef struct Plot3D { } } Plot3D; +#ifndef SWIGJAVA const PixMap *SQUARE = &PixMap_SQUARE; const PixMap *TRIANGLE = &PixMap_TRIANGLE; const PixMap *CROSS = &PixMap_CROSS; +#endif %enabledoc diff --git a/Examples/GIFPlot/Java/Makefile b/Examples/GIFPlot/Java/Makefile new file mode 100644 index 000000000..f9d368963 --- /dev/null +++ b/Examples/GIFPlot/Java/Makefile @@ -0,0 +1,17 @@ +TOP = ../.. +SWIG = $(TOP)/../swig -shadow +SWIGOPT = -I../Include +SRCS = +TARGET = libjgifplot +INTERFACE = gifplot.i +LIBS = -L.. -lgifplot -lm +INCLUDE = -I../Include + +all:: + $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + INCLUDE='$(INCLUDE)' LIBS='$(LIBS)' SWIGOPT='$(SWIGOPT)' \ + TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' java + +clean:: + rm -f *_wrap* *.o *~ *.so .~* core *.gif *.class ColorMap.java FrameBuffer.java Plot2D.java Plot3D.java gifplot.java + diff --git a/Examples/GIFPlot/Java/README b/Examples/GIFPlot/Java/README new file mode 100644 index 000000000..30058e52b --- /dev/null +++ b/Examples/GIFPlot/Java/README @@ -0,0 +1,30 @@ +The gifplot example does not work straight out of the box, +I had to change ../Interface/gifplot.i slightly for java. + +a) +The colors (e.g. BLACK) where defined as: + + #define BLACK 0 + +and the functions expect 'Pixel color' where Pixel is a unsigned char. +#define constants contain no type information and are translated to integer +constants. Because of that, you have to cast every Pixel to a byte in java. + +Changing the definition to: + const Pixel BLACK = 0; +fixes this. + +b) +The definitions: + +const PixMap *SQUARE = &PixMap_SQUARE; +const PixMap *TRIANGLE = &PixMap_TRIANGLE; +const PixMap *CROSS = &PixMap_CROSS; + +don't work. +The wrapper code expects actual variables SQUARE, etc. and they are not +defined in gifplot.h. + +c) +In shadow mode the method ColorMap::default() clashes with the reserved name +default. diff --git a/Examples/GIFPlot/Java/cm15 b/Examples/GIFPlot/Java/cm15 new file mode 100644 index 0000000000000000000000000000000000000000..7a8cd99b58dc0f11a6cdd13309e58d0de1ec7366 GIT binary patch literal 768 zcmaEK_vV!gr;i`rw`=RhH7l0PpFM3-Z)a;mO?h!%R$5|gM2Nq)yOW)zsez7$vb>a- z5Ca-u<>D8Wl2_HzH?^{N_3{smiciVPFR7|;>FS>{YyOf|>$mLOf8^x(D>v^ydHMd! z&;O)?e}Dh{{`K?6_itaneE#(D!-x0p-oAPL>g9{)&z?Sc{OIAs2lwyYy>t84%^TOR zUA=Po(xvlfPoF$~^zgy`dw1{LzGc&fRZHg0oZQ>dR8wAhI}dXJM?Xt|TKS z$j!>Y@QBX-|M}(p%P045UO9jA$o`#M)~{MJf7X=#u9o_$lKiZcc%b{dT^}KY#uH^Y`EXC)Gb_$%i19RR3STa_#!fTX*i>fAHw>(`V0LzI^ri k^_#bE-@X6v;p3-IpTB(l`tAGoA3uNn`u*q6-+%uZ0Llc9m;e9( literal 0 HcmV?d00001 diff --git a/Examples/GIFPlot/Java/cmap b/Examples/GIFPlot/Java/cmap new file mode 100644 index 0000000000000000000000000000000000000000..a20c331a9573dd8443380680bfe2cc428780d8a9 GIT binary patch literal 768 zcmZQzpd(=A5)hSEP}Mdtvvzdz4h)M)OwTDSuW4%Uoiu&!q7`d5@7R0z#JS5i?>&C` z?#s{r^Z@9-XXO?YlTlLFHMX#G@$?UkN=VBFxv-;m^2~WlR;}N<`@pd?7q8!a^y1xT znmh34m-nxpKDd4D;+bOy_iW#^cE#d(Gbi_Tw$xXZ7G$R-M27|XxI5We80l&#%Snpx zbFrd(h8Vt}lCeu@T6xFJRlCpJeMef510DGC$^DyG&YwK8f9IC 254) c1 = 254; + + c2 = (int) ((z2 + 1.0)*120) + 16; + if (c2 < 16) c2 = 16; + if (c2 > 254) c2 = 254; + + c3 = (int) ((z3 + 1.0)*120) + 16; + if (c3 < 16) c3 = 16; + if (c3 > 254) c3 = 254; + + c4 = (int) ((z4 + 1.0)*120) + 16; + if (c4 < 16) c4 = 16; + if (c4 > 254) c4= 254; + + p3.interpquad(x,y,z1,(byte) c1, + x+dx,y,z2,(byte) c2, + x+dx,y+dy,z3,(byte) c3, + x,y+dy,z4,(byte) c4); + y = y + dy; + } + x = x + dx; + } + + /* Make a GIF file */ + + f.writeGIF(cm,"plot.gif"); + + System.out.println("Image written to 'plot.gif'"); + } +} diff --git a/Examples/GIFPlot/Java/shadow.java b/Examples/GIFPlot/Java/shadow.java new file mode 100644 index 000000000..34e9bf6f9 --- /dev/null +++ b/Examples/GIFPlot/Java/shadow.java @@ -0,0 +1,22 @@ +import gifplot; + +public class shadow { + + static { + System.loadLibrary("jgifplot"); + } + + public static void main(String argv[]) { + FrameBuffer fb = new FrameBuffer(300, 300); + ColorMap cm = new ColorMap("cmap"); + + fb.clear(gifplot.BLACK); + fb.drawstring(50, 50, gifplot.WHITE, gifplot.BLACK, "Hello world", gifplot.VERTICAL); + fb.solidbox(200, 200, 220, 240, gifplot.BLUE); + fb.line(0, 290, 293, 50, gifplot.RED); + fb.circle(100, 100, 10, gifplot.YELLOW); + fb.writeGIF(cm, "plot.gif"); + + System.out.println("Image written to 'plot.gif'"); + } +} diff --git a/Examples/GIFPlot/Java/simple.java b/Examples/GIFPlot/Java/simple.java new file mode 100644 index 000000000..b5a243206 --- /dev/null +++ b/Examples/GIFPlot/Java/simple.java @@ -0,0 +1,22 @@ +import gifplot; + +public class simple { + + static { + System.loadLibrary("jgifplot"); + } + + public static void main(String argv[]) { + long f = gifplot.new_FrameBuffer(300, 300); + long c = gifplot.new_ColorMap("cmap"); + + gifplot.FrameBuffer_clear(f, gifplot.BLACK); + gifplot.FrameBuffer_drawstring(f, 50, 50, gifplot.WHITE, gifplot.BLACK, "Hello world", gifplot.HORIZONTAL); + gifplot.FrameBuffer_solidbox(f, 200, 200, 220, 240, gifplot.BLUE); + gifplot.FrameBuffer_line(f, 0, 290, 293, 50, gifplot.RED); + gifplot.FrameBuffer_circle(f, 100, 100, 10, gifplot.YELLOW); + gifplot.FrameBuffer_writeGIF(f, c, "plot.gif"); + + System.out.println("Image written to 'plot.gif'"); + } +}