Commit 16c4fbf7 authored by luc.moulinier's avatar luc.moulinier
Browse files

first commmit of ordalie sources

parents
This diff is collapsed.
# CriTcl parameters for Darwin-ppc
namespace eval critcl {
proc compiling args {return 1}
proc scripting args {return 0}
proc failed args {return 0}
}
# CriTcl parameters for Darwin-ppc
namespace eval critcl {
proc compiling args {return 1}
proc scripting args {return 0}
proc failed args {return 0}
}
# CriTcl parameters for Darwin-x86
namespace eval critcl {
proc compiling args {return 1}
proc scripting args {return 0}
proc failed args {return 0}
}
# CriTcl parameters for Linux-x86
namespace eval critcl {
proc compiling args {return 1}
proc scripting args {return 0}
proc failed args {return 0}
}
# CriTcl parameters for Linux-x86
namespace eval critcl {
proc compiling args {return 1}
proc scripting args {return 0}
proc failed args {return 0}
}
# CriTcl parameters for Windows-x86
namespace eval critcl {
proc compiling args {return 1}
proc scripting args {return 0}
proc failed args {return 0}
}
#
# CriTcl - build C extensions on-the-fly
#
# Copyright (c) 2001-2004 Jean-Claude Wippler
# Copyright (c) 2002-2004 Steve Landers
#
# See http://www.purl.org/tcl/wiki/critcl
namespace eval ::critcl {
proc check args {}
proc config args {}
proc cheaders args {}
proc csources args {}
proc clibraries args {}
proc cinit args {}
proc ccode args {}
proc ccommand args {}
proc cproc args {}
proc cdata args {}
proc tk args {}
proc tsources args {}
proc cheaders args {}
proc cdefines args {}
proc done args {return 1}
proc check args {return 0}
proc loadlib {dir package version} {
global tcl_platform
set path [file join $dir [critcl::platform]]
set lib [file join $path $package[info sharedlibextension]]
set plat [file join $path critcl.tcl]
set provide "package provide $package $version"
append provide "; [list load $lib $package]; [list source $plat]"
foreach t [glob -nocomplain [file join $dir Tcl *.tcl]] {
append provide "; [list source $t]"
}
package ifneeded $package $version $provide
package ifneeded critcl 0.0 "package provide critcl 0.0; [list source [file join $dir critcl.tcl]]"
}
proc platform {} {
global tcl_platform
set plat [lindex $tcl_platform(os) 0]
set mach $tcl_platform(machine)
switch -glob -- $mach {
sun4* { set mach sparc }
intel -
i*86* { set mach x86 }
"Power Macintosh" { set mach ppc }
}
switch -- $plat {
AIX { set mach ppc }
HP-UX { set mach hppa }
}
return "$plat-$mach"
}
}
source [file join $dir critcl.tcl]
critcl::loadlib $dir LRIPhoto 1.1
/* LRIPhoto.c
*
* Xavier Garreau , xavier@larochelle-innovation.com, Sep. 7 2005
*
* XG: Sep. 9 2005
* - added scaleXYTkImg function
* - rotation dans le sens horaire plutt que trigo
*/
#include <tcl.h>
#include <tk.h>
// Rotate a Tk Image by 90, 180 or 270 degrees
int LRI_rotateTkImg(Tk_PhotoHandle destHandle, int angle) {
int iX, iY, destX, destY;
int R, V, B, A;
unsigned char* dest;
Tk_PhotoImageBlock srcBlockPtr, destBlockPtr;
Tk_PhotoGetImage(destHandle, &srcBlockPtr);
memcpy(&destBlockPtr, &srcBlockPtr, sizeof(Tk_PhotoImageBlock));
switch (angle) {
case 90:
case 270:
destBlockPtr.height = srcBlockPtr.width;
destBlockPtr.width = srcBlockPtr.height;
destBlockPtr.pitch = destBlockPtr.width * destBlockPtr.pixelSize;
break;
case 180:
default:
break;
}
destBlockPtr.pixelPtr=(unsigned char*)ckalloc(destBlockPtr.width*destBlockPtr.height*destBlockPtr.pixelSize);
if (destBlockPtr.pixelPtr==NULL)
return TCL_ERROR;
dest=destBlockPtr.pixelPtr;
for (iY=0; iY<srcBlockPtr.height; ++iY) {
for (iX=0; iX<srcBlockPtr.width; ++iX) {
R=srcBlockPtr.pixelPtr[srcBlockPtr.pixelSize*iX+srcBlockPtr.pitch*iY+srcBlockPtr.offset[0]];
V=srcBlockPtr.pixelPtr[srcBlockPtr.pixelSize*iX+srcBlockPtr.pitch*iY+srcBlockPtr.offset[1]];
B=srcBlockPtr.pixelPtr[srcBlockPtr.pixelSize*iX+srcBlockPtr.pitch*iY+srcBlockPtr.offset[2]];
if (srcBlockPtr.pixelSize==4) {
A=srcBlockPtr.pixelPtr[srcBlockPtr.pixelSize*iX+srcBlockPtr.pitch*iY+3];
} else {
A=255;
}
switch (angle) {
case 270:
destX = iY;
destY = srcBlockPtr.width-1 - iX;
break;
case 180:
destX = srcBlockPtr.width-1 - iX;
destY = srcBlockPtr.height-1 - iY;
break;
case 90:
destX = srcBlockPtr.height-1 - iY;
destY = iX;
break;
default:
destX=iX;
destY=iY;
break;
}
dest[destBlockPtr.pixelSize*destX+destBlockPtr.pitch*destY+destBlockPtr.offset[0]]=R;
dest[destBlockPtr.pixelSize*destX+destBlockPtr.pitch*destY+destBlockPtr.offset[1]]=V;
dest[destBlockPtr.pixelSize*destX+destBlockPtr.pitch*destY+destBlockPtr.offset[2]]=B;
if (destBlockPtr.pixelSize==4)
dest[destBlockPtr.pixelSize*destX+destBlockPtr.pitch*destY+3]=A;
}
}
Tk_PhotoSetSize (destHandle, destBlockPtr.width, destBlockPtr.height);
Tk_PhotoPutBlock (destHandle, &destBlockPtr, 0, 0, destBlockPtr.width, destBlockPtr.height, TK_PHOTO_COMPOSITE_SET);
ckfree(dest);
return TCL_OK;
}
// Scale a Tk Image
// scale is in per cents
// Uses a bicubic interpolation
int LRI_scaleTkImg(Tk_PhotoHandle destHandle, int scale) {
int iX, iY, y13, x34, sX, sY;
int R1, V1, B1, A1;
int R2, V2, B2, A2;
int R3, V3, B3, A3;
int R4, V4, B4, A4;
int R, V, B;
float scale1, scale2;
unsigned char* dest;
Tk_PhotoImageBlock srcBlockPtr, destBlockPtr;
scale1 = (float)100/scale;
scale2 = scale1/2;
Tk_PhotoGetImage(destHandle, &srcBlockPtr);
memcpy(&destBlockPtr, &srcBlockPtr, sizeof(Tk_PhotoImageBlock));
destBlockPtr.width=(srcBlockPtr.width*scale)/100;
destBlockPtr.height=(srcBlockPtr.height*scale)/100;
destBlockPtr.pitch=destBlockPtr.pixelSize*destBlockPtr.width;
destBlockPtr.pixelPtr=(unsigned char*)ckalloc(destBlockPtr.width*destBlockPtr.height*destBlockPtr.pixelSize);
dest=destBlockPtr.pixelPtr;
if (!dest) return TCL_ERROR;
for (iY=0; iY<destBlockPtr.height; ++iY) {
for (iX=0; iX<destBlockPtr.width; ++iX) {
// Bicubic algorithm
// Bilinear would be faster
sX = (int)(iX*scale1);
sY = (int)(iY*scale1);
x34 = (int)(sX+scale2);
if (x34>srcBlockPtr.width-1) x34=srcBlockPtr.width-1;
y13 = (int)(sY+scale2);
if (y13>srcBlockPtr.height-1) y13=srcBlockPtr.height-1;
R1=srcBlockPtr.pixelPtr[srcBlockPtr.pixelSize*sX+srcBlockPtr.pitch*y13+srcBlockPtr.offset[0]];
V1=srcBlockPtr.pixelPtr[srcBlockPtr.pixelSize*sX+srcBlockPtr.pitch*y13+srcBlockPtr.offset[1]];
B1=srcBlockPtr.pixelPtr[srcBlockPtr.pixelSize*sX+srcBlockPtr.pitch*y13+srcBlockPtr.offset[2]];
R2=srcBlockPtr.pixelPtr[srcBlockPtr.pixelSize*sX+srcBlockPtr.pitch*sY+srcBlockPtr.offset[0]];
V2=srcBlockPtr.pixelPtr[srcBlockPtr.pixelSize*sX+srcBlockPtr.pitch*sY+srcBlockPtr.offset[1]];
B2=srcBlockPtr.pixelPtr[srcBlockPtr.pixelSize*sX+srcBlockPtr.pitch*sY+srcBlockPtr.offset[2]];
R3=srcBlockPtr.pixelPtr[srcBlockPtr.pixelSize*x34+srcBlockPtr.pitch*y13+srcBlockPtr.offset[0]];
V3=srcBlockPtr.pixelPtr[srcBlockPtr.pixelSize*x34+srcBlockPtr.pitch*y13+srcBlockPtr.offset[1]];
B3=srcBlockPtr.pixelPtr[srcBlockPtr.pixelSize*x34+srcBlockPtr.pitch*y13+srcBlockPtr.offset[2]];
R4=srcBlockPtr.pixelPtr[srcBlockPtr.pixelSize*x34+srcBlockPtr.pitch*sY+srcBlockPtr.offset[0]];
V4=srcBlockPtr.pixelPtr[srcBlockPtr.pixelSize*x34+srcBlockPtr.pitch*sY+srcBlockPtr.offset[1]];
B4=srcBlockPtr.pixelPtr[srcBlockPtr.pixelSize*x34+srcBlockPtr.pitch*sY+srcBlockPtr.offset[2]];
if (srcBlockPtr.pixelSize==4) {
A1=srcBlockPtr.pixelPtr[srcBlockPtr.pixelSize*sX+srcBlockPtr.pitch*y13+3];
A2=srcBlockPtr.pixelPtr[srcBlockPtr.pixelSize*sX+srcBlockPtr.pitch*sY+3];
A3=srcBlockPtr.pixelPtr[srcBlockPtr.pixelSize*x34+srcBlockPtr.pitch*y13+3];
A4=srcBlockPtr.pixelPtr[srcBlockPtr.pixelSize*x34+srcBlockPtr.pitch*sY+3];
} else {
A1=A2=A3=A4=255;
}
dest[destBlockPtr.pixelSize*iX+destBlockPtr.pitch*iY+destBlockPtr.offset[0]]=(R1+R2+R3+R4)/4;
dest[destBlockPtr.pixelSize*iX+destBlockPtr.pitch*iY+destBlockPtr.offset[1]]=(V1+V2+V3+V4)/4;
dest[destBlockPtr.pixelSize*iX+destBlockPtr.pitch*iY+destBlockPtr.offset[2]]=(B1+B2+B3+B4)/4;
if (destBlockPtr.pixelSize==4)
dest[destBlockPtr.pixelSize*iX+destBlockPtr.pitch*iY+3]=(A1+A2+A3+A4)/4;
}
}
Tk_PhotoSetSize (destHandle, destBlockPtr.width, destBlockPtr.height);
Tk_PhotoPutBlock(destHandle, &destBlockPtr, 0, 0, destBlockPtr.width, destBlockPtr.height, TK_PHOTO_COMPOSITE_SET);
ckfree(dest);
return TCL_OK;
}
// Scale a Tk Image
// scale is in per cents
// Uses a bicubic interpolation
int LRI_scaleXYTkImg(Tk_PhotoHandle destHandle, int scalex, int scaley) {
int iX, iY, y13, x34, sX, sY;
int R1, V1, B1, A1;
int R2, V2, B2, A2;
int R3, V3, B3, A3;
int R4, V4, B4, A4;
int R, V, B;
float scale1x, scale2x;
float scale1y, scale2y;
unsigned char* dest;
Tk_PhotoImageBlock srcBlockPtr, destBlockPtr;
scale1x = (float)100/scalex;
scale2x = scale1x/2;
scale1y = (float)100/scaley;
scale2y = scale1y/2;
Tk_PhotoGetImage(destHandle, &srcBlockPtr);
memcpy(&destBlockPtr, &srcBlockPtr, sizeof(Tk_PhotoImageBlock));
destBlockPtr.width=(srcBlockPtr.width*scalex)/100;
destBlockPtr.height=(srcBlockPtr.height*scaley)/100;
destBlockPtr.pitch=destBlockPtr.pixelSize*destBlockPtr.width;
destBlockPtr.pixelPtr=(unsigned char*)ckalloc(destBlockPtr.width*destBlockPtr.height*destBlockPtr.pixelSize);
dest=destBlockPtr.pixelPtr;
if (!dest) return TCL_ERROR;
for (iY=0; iY<destBlockPtr.height; ++iY) {
for (iX=0; iX<destBlockPtr.width; ++iX) {
// Bicubic algorithm
// Bilinear would be faster
sX = (int)(iX*scale1x);
sY = (int)(iY*scale1y);
x34 = (int)(sX+scale2x);
if (x34>srcBlockPtr.width-1) x34=srcBlockPtr.width-1;
y13 = (int)(sY+scale2y);
if (y13>srcBlockPtr.height-1) y13=srcBlockPtr.height-1;
R1=srcBlockPtr.pixelPtr[srcBlockPtr.pixelSize*sX+srcBlockPtr.pitch*y13+srcBlockPtr.offset[0]];
V1=srcBlockPtr.pixelPtr[srcBlockPtr.pixelSize*sX+srcBlockPtr.pitch*y13+srcBlockPtr.offset[1]];
B1=srcBlockPtr.pixelPtr[srcBlockPtr.pixelSize*sX+srcBlockPtr.pitch*y13+srcBlockPtr.offset[2]];
R2=srcBlockPtr.pixelPtr[srcBlockPtr.pixelSize*sX+srcBlockPtr.pitch*sY+srcBlockPtr.offset[0]];
V2=srcBlockPtr.pixelPtr[srcBlockPtr.pixelSize*sX+srcBlockPtr.pitch*sY+srcBlockPtr.offset[1]];
B2=srcBlockPtr.pixelPtr[srcBlockPtr.pixelSize*sX+srcBlockPtr.pitch*sY+srcBlockPtr.offset[2]];
R3=srcBlockPtr.pixelPtr[srcBlockPtr.pixelSize*x34+srcBlockPtr.pitch*y13+srcBlockPtr.offset[0]];
V3=srcBlockPtr.pixelPtr[srcBlockPtr.pixelSize*x34+srcBlockPtr.pitch*y13+srcBlockPtr.offset[1]];
B3=srcBlockPtr.pixelPtr[srcBlockPtr.pixelSize*x34+srcBlockPtr.pitch*y13+srcBlockPtr.offset[2]];
R4=srcBlockPtr.pixelPtr[srcBlockPtr.pixelSize*x34+srcBlockPtr.pitch*sY+srcBlockPtr.offset[0]];
V4=srcBlockPtr.pixelPtr[srcBlockPtr.pixelSize*x34+srcBlockPtr.pitch*sY+srcBlockPtr.offset[1]];
B4=srcBlockPtr.pixelPtr[srcBlockPtr.pixelSize*x34+srcBlockPtr.pitch*sY+srcBlockPtr.offset[2]];
if (srcBlockPtr.pixelSize==4) {
A1=srcBlockPtr.pixelPtr[srcBlockPtr.pixelSize*sX+srcBlockPtr.pitch*y13+3];
A2=srcBlockPtr.pixelPtr[srcBlockPtr.pixelSize*sX+srcBlockPtr.pitch*sY+3];
A3=srcBlockPtr.pixelPtr[srcBlockPtr.pixelSize*x34+srcBlockPtr.pitch*y13+3];
A4=srcBlockPtr.pixelPtr[srcBlockPtr.pixelSize*x34+srcBlockPtr.pitch*sY+3];
} else {
A1=A2=A3=A4=255;
}
dest[destBlockPtr.pixelSize*iX+destBlockPtr.pitch*iY+destBlockPtr.offset[0]]=(R1+R2+R3+R4)/4;
dest[destBlockPtr.pixelSize*iX+destBlockPtr.pitch*iY+destBlockPtr.offset[1]]=(V1+V2+V3+V4)/4;
dest[destBlockPtr.pixelSize*iX+destBlockPtr.pitch*iY+destBlockPtr.offset[2]]=(B1+B2+B3+B4)/4;
if (destBlockPtr.pixelSize==4)
dest[destBlockPtr.pixelSize*iX+destBlockPtr.pitch*iY+3]=(A1+A2+A3+A4)/4;
}
}
Tk_PhotoSetSize (destHandle, destBlockPtr.width, destBlockPtr.height);
Tk_PhotoPutBlock(destHandle, &destBlockPtr, 0, 0, destBlockPtr.width, destBlockPtr.height, TK_PHOTO_COMPOSITE_SET);
ckfree(dest);
return TCL_OK;
}
// Grays a Tk Image
void LRI_grayTkImg (Tk_PhotoHandle destHandle) {
int iX, iY;
int R, V, B, A, Gray;
unsigned char* dest;
Tk_PhotoImageBlock srcBlockPtr, destBlockPtr;
Tk_PhotoGetImage(destHandle, &srcBlockPtr);
destBlockPtr.width=srcBlockPtr.width;
destBlockPtr.height=srcBlockPtr.height;
destBlockPtr.offset[0]=0;
destBlockPtr.offset[1]=0;
destBlockPtr.offset[2]=0;
destBlockPtr.pixelSize=1;
destBlockPtr.pitch=destBlockPtr.pixelSize*destBlockPtr.width;
destBlockPtr.pixelPtr=(unsigned char*)ckalloc(destBlockPtr.width*destBlockPtr.height*destBlockPtr.pixelSize);
dest=destBlockPtr.pixelPtr;
for (iX=0; iX<destBlockPtr.width; ++iX) {
for (iY=0; iY<destBlockPtr.height; ++iY) {
R=srcBlockPtr.pixelPtr[srcBlockPtr.pixelSize*iX+srcBlockPtr.pitch*iY+srcBlockPtr.offset[0]];
V=srcBlockPtr.pixelPtr[srcBlockPtr.pixelSize*iX+srcBlockPtr.pitch*iY+srcBlockPtr.offset[1]];
B=srcBlockPtr.pixelPtr[srcBlockPtr.pixelSize*iX+srcBlockPtr.pitch*iY+srcBlockPtr.offset[2]];
if (srcBlockPtr.pixelSize==4) {
A=srcBlockPtr.pixelPtr[srcBlockPtr.pixelSize*iX+srcBlockPtr.pitch*iY+3];
} else {
A=255;
}
Gray=255-(A*(255-(R+V+B)/3))/255;
dest[destBlockPtr.pixelSize*iX+destBlockPtr.pitch*iY]=Gray;
}
}
Tk_PhotoPutBlock(destHandle, &destBlockPtr, 0, 0, destBlockPtr.width, destBlockPtr.height, TK_PHOTO_COMPOSITE_SET);
ckfree(dest);
}
// Convert a Tk Image to black and white
// Uses a Floyd Steinberg dithering method
void LRI_BWTkImg(Tk_PhotoHandle destHandle) {
int iX, iY;
int Gray, NB;
float err;
unsigned char *dest, *src;
Tk_PhotoImageBlock srcBlockPtr, destBlockPtr;
Tk_PhotoGetImage(destHandle, &srcBlockPtr);
if (srcBlockPtr.pixelSize>1) {
LRI_grayTkImg(destHandle);
}
destBlockPtr.width=srcBlockPtr.width;
destBlockPtr.height=srcBlockPtr.height;
destBlockPtr.offset[0]=0;
destBlockPtr.offset[1]=0;
destBlockPtr.offset[2]=0;
destBlockPtr.pixelSize=1;
destBlockPtr.pitch=destBlockPtr.pixelSize*destBlockPtr.width;
destBlockPtr.pixelPtr=(unsigned char*)ckalloc(destBlockPtr.width*destBlockPtr.height*destBlockPtr.pixelSize);
dest=destBlockPtr.pixelPtr;
src=srcBlockPtr.pixelPtr;
for (iY=0; iY<destBlockPtr.height; ++iY) {
for (iX=0; iX<destBlockPtr.width; ++iX) {
Gray=srcBlockPtr.pixelPtr[srcBlockPtr.pixelSize*iX+srcBlockPtr.pitch*iY];
NB=(Gray>127)?255:0;
dest[destBlockPtr.pixelSize*iX+destBlockPtr.pitch*iY]=NB;
// Floyd Steinberg error propagation
// Would give better results by changing direction after each row
err=(Gray-NB)/16;
if (iY+1<srcBlockPtr.height) {
if (iX>0) {
if (src[srcBlockPtr.pixelSize*(iX-1)+srcBlockPtr.pitch*(iY+1)]+3*err > 255) {
src[srcBlockPtr.pixelSize*(iX-1)+srcBlockPtr.pitch*(iY+1)]=255;
} else if (src[srcBlockPtr.pixelSize*(iX-1)+srcBlockPtr.pitch*(iY+1)]+3*err < 0) {
src[srcBlockPtr.pixelSize*(iX-1)+srcBlockPtr.pitch*(iY+1)]=0;
} else {
src[srcBlockPtr.pixelSize*(iX-1)+srcBlockPtr.pitch*(iY+1)]+=3*err;
}
}
if (src[srcBlockPtr.pixelSize*(iX)+srcBlockPtr.pitch*(iY+1)]+5*err > 255) {
src[srcBlockPtr.pixelSize*(iX)+srcBlockPtr.pitch*(iY+1)]=255;
} else if (src[srcBlockPtr.pixelSize*(iX)+srcBlockPtr.pitch*(iY+1)]+5*err < 0) {
src[srcBlockPtr.pixelSize*(iX)+srcBlockPtr.pitch*(iY+1)]=0;
} else {
src[srcBlockPtr.pixelSize*(iX)+srcBlockPtr.pitch*(iY+1)]+=5*err;
}
if (iX+1<srcBlockPtr.width) {
if (src[srcBlockPtr.pixelSize*(iX+1)+srcBlockPtr.pitch*(iY+1)]+err > 255) {
src[srcBlockPtr.pixelSize*(iX+1)+srcBlockPtr.pitch*(iY+1)]=255;
} else if (src[srcBlockPtr.pixelSize*(iX+1)+srcBlockPtr.pitch*(iY+1)]+err < 0) {
src[srcBlockPtr.pixelSize*(iX+1)+srcBlockPtr.pitch*(iY+1)]=0;
} else {
src[srcBlockPtr.pixelSize*(iX+1)+srcBlockPtr.pitch*(iY+1)]+=err;
}
}
}
if (iX+1<srcBlockPtr.width) {
if (src[srcBlockPtr.pixelSize*(iX+1)+srcBlockPtr.pitch*(iY)]+7*err > 255) {
src[srcBlockPtr.pixelSize*(iX+1)+srcBlockPtr.pitch*(iY)]=255;
} else if (src[srcBlockPtr.pixelSize*(iX+1)+srcBlockPtr.pitch*(iY)]+7*err < 0) {
src[srcBlockPtr.pixelSize*(iX+1)+srcBlockPtr.pitch*(iY)]=0;
} else {
src[srcBlockPtr.pixelSize*(iX+1)+srcBlockPtr.pitch*(iY)]+=7*err;
}
}
}
}
Tk_PhotoPutBlock(destHandle, &destBlockPtr, 0, 0, destBlockPtr.width, destBlockPtr.height, TK_PHOTO_COMPOSITE_SET);
ckfree(dest);
}
# LRIPhoto.tcl
#
# Xavier Garreau , xavier@larochelle-innovation.com, Sep. 7 2005
# XG: Sep. 9 2005
# - added scalex and scaley args
#
package provide LRIPhoto 1.1
package require critcl
critcl::tk
switch $::tcl_platform(platform) {
windows {set platform "win"}
unix {set platform "unix"}
}
set tcl_prefix [file normalize [file join [pwd] tcl8.4.18]]
set tk_prefix [file normalize [file join [pwd] tk8.4.18]]
switch $::tcl_platform(platform) {
windows {
critcl::cheaders -I$tk_prefix/generic -I$tk_prefix/xlib -I$tk_prefix/$platform -I$tk_prefix -I$tcl_prefix/generic -I$tcl_prefix/$platform -I$tcl_prefix -I[pwd]
}
default {
# critcl::cheaders -I$tk_prefix/generic -I$tk_prefix/xlib -I$tk_prefix/$platform -I$tk_prefix -I$tcl_prefix/generic -I$tcl_prefix/$platform -I$tcl_prefix -I[pwd] -L/usr/lib64 -lX11
# critcl::clibraries -lX11 -L/usr/lib64
}
}
# Functions are stored in this file
::critcl::csources LRIPhoto.c
# put everything in LRI namespace
namespace eval LRI {
critcl::ccommand imgtransform {dummy interp objc objv} {
Tk_PhotoHandle destimg;
int scale=-1;
int scalex=-1;
int scaley=-1;
int angle=-1;
int bw = 0;
int gray = 0;
char* param;
int plength;
int err;
int i;
if (objc <= 3) {
Tcl_WrongNumArgs(interp, 1, objv, "image ?-scale %? ?-scalex %? ?-scaley %? ?-rotate angle? ?-gray bool? ?-bw bool?");
return TCL_ERROR;
}
destimg = Tk_FindPhoto (interp, Tcl_GetString(objv[1]));
if (!destimg) {
Tcl_WrongNumArgs(interp, 1, objv, "image ?-scale %? ?-scalex %? ?-scaley %? ?-rotate angle? ?-gray bool? ?-bw bool?");
return TCL_ERROR;
}
for (i=2; i<objc; ++i) {
param = Tcl_GetStringFromObj(objv[i], (int *) &plength);
if (i+1>=objc) {
Tcl_WrongNumArgs(interp, 1, objv, "image ?-scale %? ?-scalex %? ?-scaley %? ?-rotate angle? ?-gray bool? ?-bw bool?");
return TCL_ERROR;
} else {
++i;
if (0==strcmp(param, "-scale"))
err = Tcl_GetInt(interp, Tcl_GetString(objv[i]), &scale);
else if (0==strcmp(param, "-scalex"))
err = Tcl_GetInt(interp, Tcl_GetString(objv[i]), &scalex);
else if (0==strcmp(param, "-scaley"))
err = Tcl_GetInt(interp, Tcl_GetString(objv[i]), &scaley);
else if (0==strcmp(param, "-rotate"))
err = Tcl_GetInt(interp, Tcl_GetString(objv[i]), &angle);
else if (0==strcmp(param, "-bw"))
err = Tcl_GetBoolean(interp, Tcl_GetString(objv[i]), &bw);
else if (0==strcmp(param, "-gray"))
err = Tcl_GetBoolean(interp, Tcl_GetString(objv[i]), &gray);
else {
Tcl_WrongNumArgs(interp, 1, objv, "image ?-scale %? ?-scalex %? ?-scaley %? ?-rotate angle? ?-gray bool? ?-bw bool?");
return TCL_ERROR;
}
if (TCL_OK != err ) return TCL_ERROR;
}
}
if (scalex>0 && scaley==-1) scaley=100;
if (scaley>0 && scalex==-1) scalex=100;
if (scalex>0 && scaley>0 && (scalex!=100 || scaley!=100)) {
if (TCL_OK != LRI_scaleXYTkImg (destimg, scalex, scaley)) return TCL_ERROR;
} else if (scale>0 && scale<100) {
if (TCL_OK != LRI_scaleTkImg (destimg, scale)) return TCL_ERROR;
}
if ((angle == 90) || (angle == 180) || (angle == 270)) {
if (TCL_OK != LRI_rotateTkImg (destimg, angle)) return TCL_ERROR;
}
if (scale>0 && scale>100 && scaley==-1 && scalex==-1) {
if (TCL_OK != LRI_scaleTkImg (destimg, scale)) return TCL_ERROR;
}
if (bw) {