diff options
39 files changed, 493 insertions, 1257 deletions
diff --git a/html/en/history.html b/html/en/history.html index 93cf1c4..528f656 100644 --- a/html/en/history.html +++ b/html/en/history.html @@ -12,7 +12,7 @@ <h1>History of Changes</h1> <h3 dir="ltr"> - CVS (11/Aug/2009)</h3> + CVS (17/Aug/2009)</h3> <ul> <li><span style="color: #0000FF">New:</span> function <strong> imImageGetOpenGLData</strong>.</li> @@ -20,7 +20,8 @@ 1.2.37. Removed changes to the library that made it incompatible with other libPNG distributions.</li> <li><span style="color: #008000">Changed: <span - style="color: #000000"> <strong>imImageCreateBased</strong> now also + style="color: #000000"> <strong>imImageCreateBased</strong> and + <strong>imConvertColorSpace</strong> now also consider the alpha plane.</span></span></li> <li><span style="color: #008000"><span style="color: #ff0000">Fixed:</span><span style="color: #000000"> PNG attribute TransparencyIndex. new PNG diff --git a/html/examples/animate_gif.wlua b/html/examples/animate_gif.wlua new file mode 100644 index 0000000..de96d48 --- /dev/null +++ b/html/examples/animate_gif.wlua @@ -0,0 +1,90 @@ +require"imlua" +require"cdlua" +require"cdluaim" +require"iuplua" +require"iupluacd" + +gimgs={} +gimgs.delays={} + +ggif=im.FileOpen(iup.GetFile("*.*")) + +for i=1, select(3,ggif:GetInfo()) do + gimgs[i]=ggif:LoadImage(i-1) + err, gimgs[i] = im.ConvertColorSpaceNew(gimgs[i], im.RGB, true) + local delay=gimgs[i]:GetAttribute "Delay" + if delay then + gimgs.delays[i]=delay[1]*10 + else + gimgs.delays[i]=10 + end +end + +ggif:Close() + +function gifanimator(gimgs, behavior, start, final, runyn, initial) + + start=start or 1 + final=final or #gimgs + local increment=1 + local frame=initial or start + + --hack to get data to canvas action + anii=frame + return iup.timer{ + time=gimgs.delays[frame], + run=runyn or "YES", + action_cb=function(self) + self.run="NO" + if frame==final then + if behavior=="LOOP" then + frame=start + elseif behavior=="BOUNCE" then + increment=-1 + frame=frame+increment + else + return nil + end + elseif frame==start and behavior=="BOUNCE" then + increment=1 + frame=frame+increment + else + frame=frame+increment + end + self.time=gimgs.delays[frame] + self.run="YES" + + --for the canvas redrawing function + anii=frame + --redraw the canvas. yeah, it's a bit of a hack. + cnv.action() + end} +end + +anit=gifanimator(gimgs,"LOOP")--,"BOUNCE",3,20) + +cnv = iup.canvas{rastersize = gimgs[1]:Width().."x"..gimgs[1]:Height(), + border = "NO", + expand = "YES"} + +function cnv:map_cb()-- the CD canvas can only be created when the IUP canvas is mapped + cdanvas = cd.CreateCanvas(cd.IUP, self) +end + +function cnv:action()-- called everytime the IUP canvas needs to be repainted + cdanvas:Activate() + gimgs[anii]:cdCanvasPutImageRect(cdanvas, 0, 0, 0, 0, 0, 0, 0, 0) -- use default values +end + +dlg = iup.dialog{cnv,title="Animated Gif Player"} + +function dlg:close_cb() + iup.Destroy(anit) + gimgs=nil --Destroys will be called by the garbage collector + cdanvas:Kill() + self:destroy() + return iup.IGNORE -- because we destroy the dialog +end + +dlg:show() +iup.MainLoop() diff --git a/html/examples/combine9.lua b/html/examples/combine9.wlua index 0bc1b17..0bc1b17 100644 --- a/html/examples/combine9.lua +++ b/html/examples/combine9.wlua diff --git a/test/lua/combine9view.lua b/html/examples/combine9view.wlua index d606355..d606355 100644 --- a/test/lua/combine9view.lua +++ b/html/examples/combine9view.wlua diff --git a/html/examples/multimorpho.lua b/html/examples/multimorpho.lua index be612c6..742d713 100644 --- a/html/examples/multimorpho.lua +++ b/html/examples/multimorpho.lua @@ -16,7 +16,7 @@ err_msg = { "Invalid or unrecognized file format.", "Invalid or unsupported data.", "Invalid or unsupported compression.", - "Insuficient memory", + "Insufficient memory", "Interrupted by the counter", } diff --git a/test/lua/view_image.lua b/html/examples/view_image.wlua index c156bd3..c156bd3 100644 --- a/test/lua/view_image.lua +++ b/html/examples/view_image.wlua diff --git a/include/im_convert.h b/include/im_convert.h index 114786b..794eed9 100644 --- a/include/im_convert.h +++ b/include/im_convert.h @@ -66,6 +66,7 @@ enum imCastMode * See also \ref imComplex2Real, \ref imGammaFactor and \ref imCastMode. * * \verbatim im.ConvertDataType(src_image: imImage, dst_image: imImage, cpx2real: number, gamma: number, abssolute: boolean, cast_mode: number) -> error: number [in Lua 5] \endverbatim + * \verbatim im.ConvertDataTypeNew(image: imImage, data_type: number, cpx2real: number, gamma: number, abssolute: boolean, cast_mode: number) -> error: number, new_image: imImage [in Lua 5] \endverbatim * \ingroup convert */ int imConvertDataType(const imImage* src_image, imImage* dst_image, int cpx2real, float gamma, int abssolute, int cast_mode); @@ -73,25 +74,29 @@ int imConvertDataType(const imImage* src_image, imImage* dst_image, int cpx2real * CMYK can be converted to RGB only, and it is a very simple conversion. \n * All colors can be converted to Binary, the non zero gray values are converted to 1. \n * RGB to Map uses the median cut implementation from the free IJG JPEG software, copyright Thomas G. Lane. \n + * Alpha channel is considered and Transparency* attributes are converted to alpha channel. \n * All other color space conversions assume sRGB and CIE definitions. \n * Returns IM_ERR_NONE, IM_ERR_DATA or IM_ERR_COUNTER, see also \ref imErrorCodes. * * \verbatim im.ConvertColorSpace(src_image: imImage, dst_image: imImage) -> error: number [in Lua 5] \endverbatim + * \verbatim im.ConvertColorSpaceNew(image: imImage, color_space: number, has_alpha: boolean) -> error: number, new_image: imImage [in Lua 5] \endverbatim * \ingroup convert */ int imConvertColorSpace(const imImage* src_image, imImage* dst_image); /** Converts the image to its bitmap equivalent, * uses \ref imConvertColorSpace and \ref imConvertDataType. \n * Returns IM_ERR_NONE, IM_ERR_DATA or IM_ERR_COUNTER, see also \ref imErrorCodes. - * See also \ref imComplex2Real, \ref imGammaFactor and \ref imCastMode. + * See also \ref imComplex2Real, \ref imGammaFactor and \ref imCastMode. \n + * The function im.ConvertToBitmapNew uses the default convertion result from \ref imColorModeToBitmap if color_space is nil. * * \verbatim im.ConvertToBitmap(src_image: imImage, dst_image: imImage, cpx2real: number, gamma: number, abssolute: boolean, cast_mode: number) -> error: number [in Lua 5] \endverbatim + * \verbatim im.ConvertToBitmapNew(image: imImage, color_space: number, has_alpha: boolean, cpx2real: number, gamma: number, abssolute: boolean, cast_mode: number) -> error: number, new_image: imImage [in Lua 5] \endverbatim * \ingroup convert */ int imConvertToBitmap(const imImage* src_image, imImage* dst_image, int cpx2real, float gamma, int abssolute, int cast_mode); /** Returns an OpenGL compatible data buffer. Also returns the correspondant pixel format. \n * The memory allocated is stored in the attribute "GLDATA" with BYTE type. And it will exists while the image exists. \n - * It can also be cleared setting the attribute to NULL. \n + * It can be cleared by setting the attribute to NULL. \n * MAP images are converted to RGB, and BINARY images are converted to GRAY. * Alpha channel is considered and Transparency* attributes are converted to alpha channel. * So calculate depth from glformat, not from image depth. diff --git a/include/im_image.h b/include/im_image.h index 7438f11..09de54b 100644 --- a/include/im_image.h +++ b/include/im_image.h @@ -169,7 +169,7 @@ const void* imImageGetAttribute(const imImage* image, const char* attrib, int *d void imImageGetAttributeList(const imImage* image, char** attrib, int *attrib_count); /** Sets all image data to zero. But if color space is YCBCR, LAB or LUV, and data type is BYTE or USHORT, then - * data is initialized with 128 or 32768 accordingly. + * data is initialized with 128 or 32768 accordingly. Alpha is initialized as transparent (0). * * \verbatim image:Clear() [in Lua 5] \endverbatim * \ingroup imgclass */ diff --git a/mak.vc9/imlua5.vcproj b/mak.vc9/imlua5.vcproj index 4314812..8832ed0 100644 --- a/mak.vc9/imlua5.vcproj +++ b/mak.vc9/imlua5.vcproj @@ -96,6 +96,14 @@ Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" > <File + RelativePath="..\src\lua5\im_convert.lua" + > + </File> + <File + RelativePath="..\src\lua5\im_image.lua" + > + </File> + <File RelativePath="..\src\lua5\imlua.c" > </File> diff --git a/src/im_convertbitmap.cpp b/src/im_convertbitmap.cpp index 9d3c720..a4f6b70 100644 --- a/src/im_convertbitmap.cpp +++ b/src/im_convertbitmap.cpp @@ -2,7 +2,7 @@ * \brief Image Conversion * * See Copyright Notice in im_lib.h - * $Id: im_convertbitmap.cpp,v 1.2 2009/08/13 22:34:25 scuri Exp $ + * $Id: im_convertbitmap.cpp,v 1.3 2009/08/18 02:23:33 scuri Exp $ */ #include "im.h" @@ -129,7 +129,7 @@ static void iImageMakeGray(imbyte *map, int count, int step) } } -static void iImageCopyMapAlpha(imbyte *map, imbyte *gldata, int depth, int count) +static void iImageGLCopyMapAlpha(imbyte *map, imbyte *gldata, int depth, int count) { /* gldata can be GL_RGBA or GL_LUMINANCE_ALPHA */ gldata += depth-1; /* position at first alpha */ @@ -141,38 +141,38 @@ static void iImageCopyMapAlpha(imbyte *map, imbyte *gldata, int depth, int count } } -static void iImageSetTranspMap(imbyte *map, imbyte *gldata, int count, imbyte *transp_map, int transp_count) +static void iImageGLSetTranspColor(imbyte *gldata, int count, imbyte r, imbyte g, imbyte b) { /* gldata is GL_RGBA */ - gldata += 3; /* position at first alpha */ for(int i = 0; i < count; i++) { - if (*map < transp_count) - *gldata = transp_map[*map]; + if (*(gldata+0) == r && + *(gldata+1) == g && + *(gldata+2) == b) + *(gldata+3) = 0; /* transparent */ else - *gldata = 255; /* opaque */ - - map++; + *(gldata+3) = 255; /* opaque */ gldata += 4; } } -static void iImageSetTranspColor(imbyte *gldata, int count, imbyte r, imbyte g, imbyte b) +static void iImageGLSetTranspMap(imbyte *map, imbyte *gldata, int count, imbyte *transp_map, int transp_count) { /* gldata is GL_RGBA */ + gldata += 3; /* position at first alpha */ for(int i = 0; i < count; i++) { - if (*(gldata+0) == r && - *(gldata+1) == g && - *(gldata+2) == b) - *(gldata+3) = 0; /* transparent */ + if (*map < transp_count) + *gldata = transp_map[*map]; else - *(gldata+3) = 255; /* opaque */ + *gldata = 255; /* opaque */ + + map++; gldata += 4; } } -static void iImageSetTranspIndex(imbyte *map, imbyte *gldata, int depth, int count, imbyte index) +static void iImageGLSetTranspIndex(imbyte *map, imbyte *gldata, int depth, int count, imbyte index) { /* gldata can be GL_RGBA or GL_LUMINANCE_ALPHA */ gldata += depth-1; /* position at first alpha */ @@ -258,7 +258,7 @@ void* imImageGetOpenGLData(const imImage* image, int *format) imConvertPacking(image->data[0], gldata, image->width, image->height, 3, IM_BYTE, 0); if (transp_color) - iImageSetTranspColor(gldata, image->count, *(transp_color+0), *(transp_color+1), *(transp_color+2)); + iImageGLSetTranspColor(gldata, image->count, *(transp_color+0), *(transp_color+1), *(transp_color+2)); } } else @@ -271,11 +271,11 @@ void* imImageGetOpenGLData(const imImage* image, int *format) iImageMakeGray(gldata, image->count, (glformat==GL_LUMINANCE_ALPHA)? 2: 1); if (image->has_alpha) - iImageCopyMapAlpha((imbyte*)image->data[1], gldata, depth, image->count); + iImageGLCopyMapAlpha((imbyte*)image->data[1], gldata, depth, image->count); else if (transp_map) - iImageSetTranspMap((imbyte*)image->data[0], gldata, image->count, transp_map, transp_count); + iImageGLSetTranspMap((imbyte*)image->data[0], gldata, image->count, transp_map, transp_count); else if (transp_index) - iImageSetTranspIndex((imbyte*)image->data[0], gldata, depth, image->count, *transp_index); + iImageGLSetTranspIndex((imbyte*)image->data[0], gldata, depth, image->count, *transp_index); } if (format) *format = glformat; diff --git a/src/im_convertcolor.cpp b/src/im_convertcolor.cpp index 4068b94..8e96ccc 100644 --- a/src/im_convertcolor.cpp +++ b/src/im_convertcolor.cpp @@ -2,7 +2,7 @@ * \brief Image Conversion * * See Copyright Notice in im_lib.h - * $Id: im_convertcolor.cpp,v 1.1 2008/10/17 06:10:16 scuri Exp $ + * $Id: im_convertcolor.cpp,v 1.2 2009/08/18 02:23:33 scuri Exp $ */ #include "im.h" @@ -56,6 +56,57 @@ void imConvertMapToRGB(unsigned char* data, int count, int depth, int packed, lo } } +static void iConvertSetTranspMap(imbyte *src_map, imbyte *dst_alpha, int count, imbyte *transp_map, int transp_count) +{ + for(int i = 0; i < count; i++) + { + if (*src_map < transp_count) + *dst_alpha = transp_map[*src_map]; + else + *dst_alpha = 255; /* opaque */ + + src_map++; + dst_alpha++; + } +} + +static void iConvertSetTranspIndex(imbyte *src_map, imbyte *dst_alpha, int count, imbyte index) +{ + for(int i = 0; i < count; i++) + { + if (*src_map == index) + *dst_alpha = 0; /* full transparent */ + else + *dst_alpha = 255; /* opaque */ + + src_map++; + dst_alpha++; + } +} + +static void iConvertSetTranspColor(imbyte **dst_data, int count, imbyte r, imbyte g, imbyte b) +{ + imbyte *pr = dst_data[0]; + imbyte *pg = dst_data[1]; + imbyte *pb = dst_data[2]; + imbyte *pa = dst_data[3]; + + for(int i = 0; i < count; i++) + { + if (*pr == r && + *pg == g && + *pb == b) + *pa = 0; /* transparent */ + else + *pa = 255; /* opaque */ + + pr++; + pg++; + pb++; + pa++; + } +} + // convert bin2gray and gray2bin inline void iConvertBinary(imbyte* map, int count, imbyte value) { @@ -124,7 +175,7 @@ static void iConvertMapToRGB(const imbyte* src_map, imbyte* red, imbyte* green, template <class T> int iDoConvert2Gray(int count, int data_type, - const T** src_data, int src_color_space, T** dst_data, int counter) + const T** src_data, int src_color_space, T** dst_data, int counter) { int i; T max; @@ -201,7 +252,7 @@ int iDoConvert2Gray(int count, int data_type, template <class T> int iDoConvert2RGB(int count, int data_type, - const T** src_data, int src_color_space, T** dst_data, int counter) + const T** src_data, int src_color_space, T** dst_data, int counter) { int i; T max, zero; @@ -303,7 +354,7 @@ int iDoConvert2RGB(int count, int data_type, template <class T> int iDoConvert2YCbCr(int count, int data_type, - const T** src_data, int src_color_space, T** dst_data, int counter) + const T** src_data, int src_color_space, T** dst_data, int counter) { int i; T zero; @@ -339,7 +390,7 @@ int iDoConvert2YCbCr(int count, int data_type, template <class T> int iDoConvert2XYZ(int count, int data_type, - const T** src_data, int src_color_space, T** dst_data, int counter) + const T** src_data, int src_color_space, T** dst_data, int counter) { int i; T max; @@ -439,7 +490,7 @@ int iDoConvert2XYZ(int count, int data_type, template <class T> int iDoConvert2Lab(int count, int data_type, - const T** src_data, int src_color_space, T** dst_data, int counter) + const T** src_data, int src_color_space, T** dst_data, int counter) { int i; T max; @@ -561,7 +612,7 @@ int iDoConvert2Lab(int count, int data_type, template <class T> int iDoConvert2Luv(int count, int data_type, - const T** src_data, int src_color_space, T** dst_data, int counter) + const T** src_data, int src_color_space, T** dst_data, int counter) { int i; T max; @@ -779,105 +830,152 @@ static int iConvertColorSpace(const imImage* src_image, imImage* dst_image) int imConvertColorSpace(const imImage* src_image, imImage* dst_image) { + int ret = IM_ERR_NONE; assert(src_image); assert(dst_image); if (!imImageMatchDataType(src_image, dst_image)) return IM_ERR_DATA; - if (src_image->color_space == dst_image->color_space) - return IM_ERR_DATA; - - switch(dst_image->color_space) + if (src_image->color_space != dst_image->color_space) { - case IM_RGB: - switch(src_image->color_space) + switch(dst_image->color_space) { - case IM_BINARY: - memcpy(dst_image->data[0], src_image->data[0], dst_image->plane_size); + case IM_RGB: + switch(src_image->color_space) + { + case IM_BINARY: + memcpy(dst_image->data[0], src_image->data[0], dst_image->plane_size); + iConvertBinary((imbyte*)dst_image->data[0], dst_image->count, 255); + memcpy(dst_image->data[1], dst_image->data[0], dst_image->plane_size); + memcpy(dst_image->data[2], dst_image->data[0], dst_image->plane_size); + ret = IM_ERR_NONE; + break; + case IM_MAP: + iConvertMapToRGB((imbyte*)src_image->data[0], (imbyte*)dst_image->data[0], (imbyte*)dst_image->data[1], (imbyte*)dst_image->data[2], dst_image->count, src_image->palette, src_image->palette_count); + ret = IM_ERR_NONE; + break; + case IM_GRAY: + memcpy(dst_image->data[0], src_image->data[0], dst_image->plane_size); + memcpy(dst_image->data[1], src_image->data[0], dst_image->plane_size); + memcpy(dst_image->data[2], src_image->data[0], dst_image->plane_size); + ret = IM_ERR_NONE; + break; + default: + ret = iConvertColorSpace(src_image, dst_image); + break; + } + break; + case IM_GRAY: + switch(src_image->color_space) + { + case IM_BINARY: + memcpy(dst_image->data[0], src_image->data[0], dst_image->size); iConvertBinary((imbyte*)dst_image->data[0], dst_image->count, 255); - memcpy(dst_image->data[1], dst_image->data[0], dst_image->plane_size); - memcpy(dst_image->data[2], dst_image->data[0], dst_image->plane_size); - return IM_ERR_NONE; - case IM_MAP: - iConvertMapToRGB((imbyte*)src_image->data[0], (imbyte*)dst_image->data[0], (imbyte*)dst_image->data[1], (imbyte*)dst_image->data[2], dst_image->count, src_image->palette, src_image->palette_count); - return IM_ERR_NONE; - case IM_GRAY: + ret = IM_ERR_NONE; + break; + case IM_MAP: + iConvertMap2Gray((imbyte*)src_image->data[0], (imbyte*)dst_image->data[0], dst_image->count, src_image->palette, src_image->palette_count); + ret = IM_ERR_NONE; + break; + case IM_YCBCR: memcpy(dst_image->data[0], src_image->data[0], dst_image->plane_size); - memcpy(dst_image->data[1], src_image->data[0], dst_image->plane_size); - memcpy(dst_image->data[2], src_image->data[0], dst_image->plane_size); - return IM_ERR_NONE; - default: - return iConvertColorSpace(src_image, dst_image); - } - case IM_GRAY: - switch(src_image->color_space) - { + ret = IM_ERR_NONE; + break; + default: + ret = iConvertColorSpace(src_image, dst_image); + break; + } + break; + case IM_MAP: + switch(src_image->color_space) + { + case IM_BINARY: // no break, same procedure as gray + case IM_GRAY: + memcpy(dst_image->data[0], src_image->data[0], dst_image->size); + dst_image->palette_count = src_image->palette_count; + memcpy(dst_image->palette, src_image->palette, dst_image->palette_count*sizeof(long)); + ret = IM_ERR_NONE; + break; + case IM_RGB: + dst_image->palette_count = 256; + ret = imConvertRGB2Map(src_image->width, src_image->height, + (imbyte*)src_image->data[0], (imbyte*)src_image->data[1], (imbyte*)src_image->data[2], + (imbyte*)dst_image->data[0], dst_image->palette, &dst_image->palette_count); + break; + default: + ret = IM_ERR_DATA; + break; + } + break; case IM_BINARY: - memcpy(dst_image->data[0], src_image->data[0], dst_image->size); - iConvertBinary((imbyte*)dst_image->data[0], dst_image->count, 255); - return IM_ERR_NONE; - case IM_MAP: - iConvertMap2Gray((imbyte*)src_image->data[0], (imbyte*)dst_image->data[0], dst_image->count, src_image->palette, src_image->palette_count); - return IM_ERR_NONE; - case IM_YCBCR: - memcpy(dst_image->data[0], src_image->data[0], dst_image->plane_size); - return IM_ERR_NONE; - default: - return iConvertColorSpace(src_image, dst_image); - } - case IM_MAP: - switch(src_image->color_space) - { - case IM_BINARY: // no break, same procedure as gray - case IM_GRAY: - memcpy(dst_image->data[0], src_image->data[0], dst_image->size); - dst_image->palette_count = src_image->palette_count; - memcpy(dst_image->palette, src_image->palette, dst_image->palette_count*sizeof(long)); - return IM_ERR_NONE; - case IM_RGB: - dst_image->palette_count = 256; - return imConvertRGB2Map(src_image->width, src_image->height, - (imbyte*)src_image->data[0], (imbyte*)src_image->data[1], (imbyte*)src_image->data[2], - (imbyte*)dst_image->data[0], dst_image->palette, &dst_image->palette_count); - default: - return IM_ERR_DATA; - } - case IM_BINARY: - switch(src_image->color_space) - { - case IM_GRAY: - memcpy(dst_image->data[0], src_image->data[0], dst_image->size); - iConvertBinary((imbyte*)dst_image->data[0], dst_image->count, 1); - return IM_ERR_NONE; - case IM_MAP: // convert to gray, then convert to binary - iConvertMap2Gray((imbyte*)src_image->data[0], (imbyte*)dst_image->data[0], dst_image->count, src_image->palette, src_image->palette_count); - iConvertBinary((imbyte*)dst_image->data[0], dst_image->count, 1); - return IM_ERR_NONE; - case IM_YCBCR: // convert to gray, then convert to binary - memcpy(dst_image->data[0], src_image->data[0], dst_image->plane_size); - iConvertBinary((imbyte*)dst_image->data[0], dst_image->count, 1); - return IM_ERR_NONE; - default: // convert to gray, then convert to binary + switch(src_image->color_space) { + case IM_GRAY: + memcpy(dst_image->data[0], src_image->data[0], dst_image->size); + iConvertBinary((imbyte*)dst_image->data[0], dst_image->count, 1); + ret = IM_ERR_NONE; + break; + case IM_MAP: // convert to gray, then convert to binary + iConvertMap2Gray((imbyte*)src_image->data[0], (imbyte*)dst_image->data[0], dst_image->count, src_image->palette, src_image->palette_count); + iConvertBinary((imbyte*)dst_image->data[0], dst_image->count, 1); + ret = IM_ERR_NONE; + break; + case IM_YCBCR: // convert to gray, then convert to binary + memcpy(dst_image->data[0], src_image->data[0], dst_image->plane_size); + iConvertBinary((imbyte*)dst_image->data[0], dst_image->count, 1); + ret = IM_ERR_NONE; + break; + default: // convert to gray, then convert to binary dst_image->color_space = IM_GRAY; - int ret = iConvertColorSpace(src_image, dst_image); + ret = iConvertColorSpace(src_image, dst_image); dst_image->color_space = IM_BINARY; - if (ret != IM_ERR_NONE) return ret; - iConvertBinary((imbyte*)dst_image->data[0], dst_image->count, 1); - return IM_ERR_NONE; + if (ret == IM_ERR_NONE) + iConvertBinary((imbyte*)dst_image->data[0], dst_image->count, 1); + ret = IM_ERR_NONE; + break; } + break; + case IM_YCBCR: + switch(src_image->color_space) + { + case IM_GRAY: + memcpy(dst_image->data[0], src_image->data[0], dst_image->plane_size); + ret = IM_ERR_NONE; + break; + default: + ret = iConvertColorSpace(src_image, dst_image); + break; + } + break; + default: + ret = iConvertColorSpace(src_image, dst_image); + break; } - case IM_YCBCR: - switch(src_image->color_space) + } + + if (src_image->has_alpha && dst_image->has_alpha) + memcpy(dst_image->data[dst_image->depth], src_image->data[src_image->depth], src_image->plane_size); + else if (dst_image->color_space == IM_RGB && dst_image->data_type == IM_BYTE && dst_image->has_alpha) + { + if (src_image->color_space == IM_RGB) + { + imbyte* transp_color = (imbyte*)imImageGetAttribute(src_image, "TransparencyColor", NULL, NULL); + if (transp_color) + iConvertSetTranspColor((imbyte**)dst_image->data, dst_image->count, *(transp_color+0), *(transp_color+1), *(transp_color+2)); + } + else { - case IM_GRAY: - memcpy(dst_image->data[0], src_image->data[0], dst_image->plane_size); - return IM_ERR_NONE; - default: - return iConvertColorSpace(src_image, dst_image); + int transp_count; + imbyte* transp_index = (imbyte*)imImageGetAttribute(src_image, "TransparencyIndex", NULL, NULL); + imbyte* transp_map = (imbyte*)imImageGetAttribute(src_image, "TransparencyMap", NULL, &transp_count); + if (transp_map) + iConvertSetTranspMap((imbyte*)src_image->data[0], (imbyte*)dst_image->data[3], dst_image->count, transp_map, transp_count); + else if (transp_index) + iConvertSetTranspIndex((imbyte*)src_image->data[0], (imbyte*)dst_image->data[3], dst_image->count, *transp_index); } - default: - return iConvertColorSpace(src_image, dst_image); } + + return ret; } + diff --git a/src/imlua5.mak b/src/imlua5.mak index 560616a..554b701 100644 --- a/src/imlua5.mak +++ b/src/imlua5.mak @@ -1,12 +1,14 @@ PROJNAME = im LIBNAME = imlua51 -DEF_FILE = imlua.def OPT = YES -SRCDIR = lua5 +LOHDIR = lua5/loh +SRC = lua5/imlua.c lua5/imlua_aux.c lua5/imlua_convert.c lua5/imlua_file.c lua5/imlua_image.c lua5/imlua_palette.c lua5/imlua_util.c +DEF_FILE = lua5/imlua.def -SRC = imlua.c imlua_aux.c imlua_convert.c imlua_file.c imlua_image.c imlua_palette.c imlua_util.c +SRCLUA = lua5/im_image.lua lua5/im_convert.lua +SRCLUADIR = lua5 INCLUDES = lua5 diff --git a/src/imlua_process5.mak b/src/imlua_process5.mak index c5e9c79..85415c4 100644 --- a/src/imlua_process5.mak +++ b/src/imlua_process5.mak @@ -1,6 +1,5 @@ PROJNAME = im LIBNAME = imlua_process51 -DEF_FILE = imlua_process.def OPT = YES diff --git a/src/lua5/im_convert.lua b/src/lua5/im_convert.lua new file mode 100644 index 0000000..231bdb5 --- /dev/null +++ b/src/lua5/im_convert.lua @@ -0,0 +1,18 @@ + +function im.ConvertDataTypeNew(src_image, data_type, cpx2real, gamma, abssolute, cast_mode) + local dst_image = im.ImageCreateBased(src_image, nil, nil, nil, data_type) + return im.ConvertDataType(src_image, dst_image, cpx2real, gamma, abssolute, cast_mode), dst_image +end + +function im.ConvertColorSpaceNew(src_image, color_space, has_alpha) + local dst_image = im.ImageCreateBased(src_image, nil, nil, color_space) + if (has_alpha) then dst_image:AddAlpha() end + return im.ConvertColorSpace(src_image, dst_image), dst_image +end + +function im.ConvertToBitmapNew(src_image, color_space, has_alpha, cpx2real, gamma, abssolute, cast_mode) + if (not color_space) then color_space = im.ColorModeToBitmap(src_image:ColorSpace()) end + local dst_image = im.ImageCreateBased(src_image, nil, nil, color_space) + if (has_alpha) then dst_image:AddAlpha() end + return im.ConvertToBitmap(src_image, dst_image, cpx2real, gamma, abssolute, cast_mode), dst_image +end diff --git a/src/lua5/im_fftw.lua b/src/lua5/im_fftw.lua index e57c7bf..7bae53e 100644 --- a/src/lua5/im_fftw.lua +++ b/src/lua5/im_fftw.lua @@ -3,6 +3,7 @@ -- Creates a new function, with the name suffixed by "New". This new function -- creates a new image, based on a source image, and calls the previous function -- with this new image. +-- We assume here that the functions returns only one parameter or none. local function OneSourceOneDest (funcname, width, height, color_space, data_type) local func = im[funcname] @@ -14,8 +15,12 @@ local function OneSourceOneDest (funcname, width, height, color_space, data_type local dst_image = im.ImageCreateBased(src_image, width, height, color_space, data_type) -- call previous method, repassing all parameters - func(src_image, dst_image, unpack(arg)) - return dst_image + local ret = func(src_image, dst_image, unpack(arg)) + if (ret) then + return ret, dst_image + else + return dst_image + end end end @@ -25,7 +30,7 @@ end local function TwoSourcesOneDest (funcname, width, height, color_space, data_type) local func = im[funcname] - + -- see if function is really defined assert(func, string.format("undefined function `%s'", funcname)) @@ -35,8 +40,12 @@ local function TwoSourcesOneDest (funcname, width, height, color_space, data_typ local dst_image = im.ImageCreateBased(src_image1, width, height, color_space, data_type) -- call previous method, repassing all parameters - func(src_image1, src_image2, dst_image, unpack(arg)) - return dst_image + local ret = func(src_image1, src_image2, dst_image, unpack(arg)) + if (ret) then + return ret, dst_image + else + return dst_image + end end end diff --git a/src/lua5/im_image.lua b/src/lua5/im_image.lua new file mode 100644 index 0000000..03e80f6 --- /dev/null +++ b/src/lua5/im_image.lua @@ -0,0 +1,24 @@ +-- If all parameteres, besides the image, are nil, this is equivalent to image:Clone. +-- If any parameter is not nil, then the value is used instead of the one from the source image. +-- If a parameter is a function, then the function is called, passing the source +-- image as parameter, to obtain the substituion value. + +function im.ImageCreateBased(image, width, height, color_space, data_type) + -- default values are those of the source image + width = width or image:Width() + height = height or image:Height() + color_space = color_space or image:ColorSpace() + data_type = data_type or image:DataType() + + -- callback to calculate parameters based on source image + if type(width) == "function" then width = width(image) end + if type(height) == "function" then height = height(image) end + if type(color_space) == "function" then color_space = color_space(image) end + if type(data_type) == "function" then data_type = data_type(image) end + + -- create a new image + new_image = im.ImageCreate(width, height, color_space, data_type) + image:CopyAttributes(new_image) + if (image:HasAlpha()) then new_image:AddAlpha() end + return new_image +end diff --git a/src/lua5/imlua_convert.c b/src/lua5/imlua_convert.c index 96b8429..c2c56d9 100644 --- a/src/lua5/imlua_convert.c +++ b/src/lua5/imlua_convert.c @@ -2,7 +2,7 @@ * \brief IM Lua 5 Binding * * See Copyright Notice in im_lib.h - * $Id: imlua_convert.c,v 1.2 2009/08/04 21:35:26 scuri Exp $ + * $Id: imlua_convert.c,v 1.3 2009/08/18 02:23:33 scuri Exp $ */ #include "im.h" @@ -76,4 +76,21 @@ void imlua_open_convert (lua_State *L) { /* "im" table is at the top of the stack */ luaL_register(L, NULL, imconvert_lib); +#ifdef TEC_BIGENDIAN +#ifdef TEC_64 +#include "loh/im_convert_be64.loh" +#else +#include "loh/im_convert_be32.loh" +#endif +#else +#ifdef TEC_64 +#ifdef WIN64 +#include "loh/im_convert_le64w.loh" +#else +#include "loh/im_convert_le64.loh" +#endif +#else +#include "loh/im_convert.loh" +#endif +#endif } diff --git a/src/lua5/imlua_image.c b/src/lua5/imlua_image.c index dc3322a..d823ac1 100644 --- a/src/lua5/imlua_image.c +++ b/src/lua5/imlua_image.c @@ -2,7 +2,7 @@ * \brief IM Lua 5 Binding * * See Copyright Notice in im_lib.h - * $Id: imlua_image.c,v 1.2 2009/08/12 04:09:17 scuri Exp $ + * $Id: imlua_image.c,v 1.3 2009/08/18 02:23:33 scuri Exp $ */ #include <string.h> @@ -1055,40 +1055,26 @@ static void createmeta (lua_State *L) lua_pop(L, 1); /* removes the metatable from the top of the stack */ } -/* If all parameteres, besides the image, are nil, this is equivalent to image:Clone. - If any parameter is not nil, then the value is used instead of the one from the source image. - If a parameter is a function, then the function is called, passing the source - image as parameter, to obtain the substituion value. */ -static void reg_image(lua_State *L) -{ - const char* data = { -"function im.ImageCreateBased(image, width, height, color_space, data_type) \n" -" -- default values are those of the source image \n" -" width = width or image:Width() \n" -" height = height or image:Height() \n" -" color_space = color_space or image:ColorSpace() \n" -" data_type = data_type or image:DataType() \n" -" \n" -" -- callback to calculate parameters based on source image \n" -" if type(width) == \"function\" then width = width(image) end \n" -" if type(height) == \"function\" then height = height(image) end \n" -" if type(color_space) == \"function\" then color_space = color_space(image) end \n" -" if type(data_type) == \"function\" then data_type = data_type(image) end \n" -" \n" -" -- create a new image \n" -" new_image = im.ImageCreate(width, height, color_space, data_type) \n" -" image:CopyAttributes(new_image) \n" -" return new_image \n" -"end \n" - }; - - if (luaL_loadbuffer(L, data, strlen(data), "reg_image")==0) lua_pcall(L, 0, 0, 0); -} - void imlua_open_image (lua_State *L) { /* "im" table is at the top of the stack */ createmeta(L); luaL_register(L, NULL, imimage_lib); - reg_image(L); +#ifdef TEC_BIGENDIAN +#ifdef TEC_64 +#include "loh/im_image_be64.loh" +#else +#include "loh/im_image_be32.loh" +#endif +#else +#ifdef TEC_64 +#ifdef WIN64 +#include "loh/im_image_le64w.loh" +#else +#include "loh/im_image_le64.loh" +#endif +#else +#include "loh/im_image.loh" +#endif +#endif } diff --git a/src/lua5/loh/im_fftw.loh b/src/lua5/loh/im_fftw.loh index 4f45bcc..9e7c78a 100644 --- a/src/lua5/loh/im_fftw.loh +++ b/src/lua5/loh/im_fftw.loh @@ -17,86 +17,93 @@ static const unsigned char B1[]={ 111,110, 0, 4, 3, 0, 0, 0,105,109, 0, 4, 7, 0, 0, 0, 67, 70, 76, 79, 65, 84, 0, 4, 11, 0, 0, 0, 80,114,111, 99,101,115,115, 70, 70, 84, 0, 4, 12, 0, 0, 0, 80,114,111, 99,101,115,115, 73, 70, 70, 84, 0, 2, 0, 0, 0, - 0, 0, 0, 0, 7, 0, 0, 0, 20, 0, 0, 0, 0, 5, 0, 9, 17, 0, 0, 0, + 0, 0, 0, 0, 8, 0, 0, 0, 25, 0, 0, 0, 0, 5, 0, 9, 17, 0, 0, 0, 69, 1, 0, 0, 70, 1,128, 2,133, 65, 0, 0,192, 1,128, 2,156, 65, 0, 1, 133, 1, 0, 0,192, 1, 0, 0, 1,130, 0, 0,213, 1,130, 3, 36, 2, 0, 0, 0, 0,128, 0, 0, 0, 0, 1, 0, 0,128, 1, 0, 0, 0, 2, 0, 0,128, 2, 137, 1,130, 3, 30, 0,128, 0, 3, 0, 0, 0, 4, 3, 0, 0, 0,105,109, 0, 4, 7, 0, 0, 0, 97,115,115,101,114,116, 0, 4, 4, 0, 0, 0, 78,101,119, - 0, 1, 0, 0, 0, 0, 0, 0, 0, 12, 0, 0, 0, 19, 0, 0, 0, 5, 1, 7, - 8, 17, 0, 0, 0,133, 0, 0, 0,134, 64, 64, 1,192, 0, 0, 0, 4, 1, 0, + 0, 1, 0, 0, 0, 0, 0, 0, 0, 13, 0, 0, 0, 24, 0, 0, 0, 5, 1, 7, + 8, 23, 0, 0, 0,133, 0, 0, 0,134, 64, 64, 1,192, 0, 0, 0, 4, 1, 0, 0, 68, 1,128, 0,132, 1, 0, 1,196, 1,128, 1,156,128, 0, 3,196, 0, 0, 2, 0, 1, 0, 0, 64, 1, 0, 1,133,129, 0, 0,192, 1,128, 0,156, 1, 0, - 1,220, 64, 0, 0,158, 0, 0, 1, 30, 0,128, 0, 3, 0, 0, 0, 4, 3, 0, - 0, 0,105,109, 0, 4, 17, 0, 0, 0, 73,109, 97,103,101, 67,114,101, 97,116, -101, 66, 97,115,101,100, 0, 4, 7, 0, 0, 0,117,110,112, 97, 99,107, 0, 0, - 0, 0, 0, 17, 0, 0, 0, 14, 0, 0, 0, 14, 0, 0, 0, 14, 0, 0, 0, 14, - 0, 0, 0, 14, 0, 0, 0, 14, 0, 0, 0, 14, 0, 0, 0, 14, 0, 0, 0, 17, - 0, 0, 0, 17, 0, 0, 0, 17, 0, 0, 0, 17, 0, 0, 0, 17, 0, 0, 0, 17, - 0, 0, 0, 17, 0, 0, 0, 18, 0, 0, 0, 19, 0, 0, 0, 3, 0, 0, 0, 10, - 0, 0, 0,115,114, 99, 95,105,109, 97,103,101, 0, 0, 0, 0, 0, 16, 0, 0, - 0, 4, 0, 0, 0, 97,114,103, 0, 0, 0, 0, 0, 16, 0, 0, 0, 10, 0, 0, - 0,100,115,116, 95,105,109, 97,103,101, 0, 8, 0, 0, 0, 16, 0, 0, 0, 5, - 0, 0, 0, 6, 0, 0, 0,119,105,100,116,104, 0, 7, 0, 0, 0,104,101,105, -103,104,116, 0, 12, 0, 0, 0, 99,111,108,111,114, 95,115,112, 97, 99,101, 0, - 10, 0, 0, 0,100, 97,116, 97, 95,116,121,112,101, 0, 5, 0, 0, 0,102,117, -110, 99, 0, 17, 0, 0, 0, 8, 0, 0, 0, 8, 0, 0, 0, 9, 0, 0, 0, 9, - 0, 0, 0, 9, 0, 0, 0, 12, 0, 0, 0, 12, 0, 0, 0, 12, 0, 0, 0, 12, - 0, 0, 0, 19, 0, 0, 0, 19, 0, 0, 0, 19, 0, 0, 0, 19, 0, 0, 0, 19, - 0, 0, 0, 19, 0, 0, 0, 19, 0, 0, 0, 20, 0, 0, 0, 6, 0, 0, 0, 9, - 0, 0, 0,102,117,110, 99,110, 97,109,101, 0, 0, 0, 0, 0, 16, 0, 0, 0, - 6, 0, 0, 0,119,105,100,116,104, 0, 0, 0, 0, 0, 16, 0, 0, 0, 7, 0, - 0, 0,104,101,105,103,104,116, 0, 0, 0, 0, 0, 16, 0, 0, 0, 12, 0, 0, - 0, 99,111,108,111,114, 95,115,112, 97, 99,101, 0, 0, 0, 0, 0, 16, 0, 0, - 0, 10, 0, 0, 0,100, 97,116, 97, 95,116,121,112,101, 0, 0, 0, 0, 0, 16, - 0, 0, 0, 5, 0, 0, 0,102,117,110, 99, 0, 2, 0, 0, 0, 16, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 26, 0, 0, 0, 41, 0, 0, 0, 0, 5, 0, 11, - 22, 0, 0, 0, 69, 1, 0, 0, 70, 1,128, 2,133, 65, 0, 0,192, 1,128, 2, - 5,130, 0, 0, 6,194, 64, 4, 65, 2, 1, 0,128, 2, 0, 0, 28, 2,128, 1, -156, 65, 0, 0,133, 1, 0, 0,192, 1, 0, 0, 1, 66, 1, 0,213, 1,130, 3, - 36, 2, 0, 0, 0, 0,128, 0, 0, 0, 0, 1, 0, 0,128, 1, 0, 0, 0, 2, - 0, 0,128, 2,137, 1,130, 3, 30, 0,128, 0, 6, 0, 0, 0, 4, 3, 0, 0, - 0,105,109, 0, 4, 7, 0, 0, 0, 97,115,115,101,114,116, 0, 4, 7, 0, 0, - 0,115,116,114,105,110,103, 0, 4, 7, 0, 0, 0,102,111,114,109, 97,116, 0, - 4, 24, 0, 0, 0,117,110,100,101,102,105,110,101,100, 32,102,117,110, 99,116, -105,111,110, 32, 96, 37,115, 39, 0, 4, 4, 0, 0, 0, 78,101,119, 0, 1, 0, - 0, 0, 0, 0, 0, 0, 33, 0, 0, 0, 40, 0, 0, 0, 5, 2, 7, 10, 18, 0, - 0, 0,197, 0, 0, 0,198, 64,192, 1, 0, 1, 0, 0, 68, 1, 0, 0,132, 1, -128, 0,196, 1, 0, 1, 4, 2,128, 1,220,128, 0, 3, 4, 1, 0, 2, 64, 1, - 0, 0,128, 1,128, 0,192, 1,128, 1, 5,130, 0, 0, 64, 2, 0, 1, 28, 2, - 0, 1, 28, 65, 0, 0,222, 0, 0, 1, 30, 0,128, 0, 3, 0, 0, 0, 4, 3, - 0, 0, 0,105,109, 0, 4, 17, 0, 0, 0, 73,109, 97,103,101, 67,114,101, 97, -116,101, 66, 97,115,101,100, 0, 4, 7, 0, 0, 0,117,110,112, 97, 99,107, 0, - 0, 0, 0, 0, 18, 0, 0, 0, 35, 0, 0, 0, 35, 0, 0, 0, 35, 0, 0, 0, - 35, 0, 0, 0, 35, 0, 0, 0, 35, 0, 0, 0, 35, 0, 0, 0, 35, 0, 0, 0, - 38, 0, 0, 0, 38, 0, 0, 0, 38, 0, 0, 0, 38, 0, 0, 0, 38, 0, 0, 0, - 38, 0, 0, 0, 38, 0, 0, 0, 38, 0, 0, 0, 39, 0, 0, 0, 40, 0, 0, 0, - 4, 0, 0, 0, 11, 0, 0, 0,115,114, 99, 95,105,109, 97,103,101, 49, 0, 0, - 0, 0, 0, 17, 0, 0, 0, 11, 0, 0, 0,115,114, 99, 95,105,109, 97,103,101, - 50, 0, 0, 0, 0, 0, 17, 0, 0, 0, 4, 0, 0, 0, 97,114,103, 0, 0, 0, - 0, 0, 17, 0, 0, 0, 10, 0, 0, 0,100,115,116, 95,105,109, 97,103,101, 0, - 8, 0, 0, 0, 17, 0, 0, 0, 5, 0, 0, 0, 6, 0, 0, 0,119,105,100,116, -104, 0, 7, 0, 0, 0,104,101,105,103,104,116, 0, 12, 0, 0, 0, 99,111,108, -111,114, 95,115,112, 97, 99,101, 0, 10, 0, 0, 0,100, 97,116, 97, 95,116,121, -112,101, 0, 5, 0, 0, 0,102,117,110, 99, 0, 22, 0, 0, 0, 27, 0, 0, 0, - 27, 0, 0, 0, 30, 0, 0, 0, 30, 0, 0, 0, 30, 0, 0, 0, 30, 0, 0, 0, - 30, 0, 0, 0, 30, 0, 0, 0, 30, 0, 0, 0, 30, 0, 0, 0, 33, 0, 0, 0, - 33, 0, 0, 0, 33, 0, 0, 0, 33, 0, 0, 0, 40, 0, 0, 0, 40, 0, 0, 0, + 1,220,128, 0, 0,218, 0, 0, 0, 22,192, 0,128, 0, 1,128, 1, 64, 1, 0, + 1, 30, 1,128, 1, 22, 0, 0,128,158, 0, 0, 1, 30, 0,128, 0, 3, 0, 0, + 0, 4, 3, 0, 0, 0,105,109, 0, 4, 17, 0, 0, 0, 73,109, 97,103,101, 67, +114,101, 97,116,101, 66, 97,115,101,100, 0, 4, 7, 0, 0, 0,117,110,112, 97, + 99,107, 0, 0, 0, 0, 0, 23, 0, 0, 0, 15, 0, 0, 0, 15, 0, 0, 0, 15, + 0, 0, 0, 15, 0, 0, 0, 15, 0, 0, 0, 15, 0, 0, 0, 15, 0, 0, 0, 15, + 0, 0, 0, 18, 0, 0, 0, 18, 0, 0, 0, 18, 0, 0, 0, 18, 0, 0, 0, 18, + 0, 0, 0, 18, 0, 0, 0, 18, 0, 0, 0, 19, 0, 0, 0, 19, 0, 0, 0, 20, + 0, 0, 0, 20, 0, 0, 0, 20, 0, 0, 0, 20, 0, 0, 0, 22, 0, 0, 0, 24, + 0, 0, 0, 4, 0, 0, 0, 10, 0, 0, 0,115,114, 99, 95,105,109, 97,103,101, + 0, 0, 0, 0, 0, 22, 0, 0, 0, 4, 0, 0, 0, 97,114,103, 0, 0, 0, 0, + 0, 22, 0, 0, 0, 10, 0, 0, 0,100,115,116, 95,105,109, 97,103,101, 0, 8, + 0, 0, 0, 22, 0, 0, 0, 4, 0, 0, 0,114,101,116, 0, 15, 0, 0, 0, 22, + 0, 0, 0, 5, 0, 0, 0, 6, 0, 0, 0,119,105,100,116,104, 0, 7, 0, 0, + 0,104,101,105,103,104,116, 0, 12, 0, 0, 0, 99,111,108,111,114, 95,115,112, + 97, 99,101, 0, 10, 0, 0, 0,100, 97,116, 97, 95,116,121,112,101, 0, 5, 0, + 0, 0,102,117,110, 99, 0, 17, 0, 0, 0, 9, 0, 0, 0, 9, 0, 0, 0, 10, + 0, 0, 0, 10, 0, 0, 0, 10, 0, 0, 0, 13, 0, 0, 0, 13, 0, 0, 0, 13, + 0, 0, 0, 13, 0, 0, 0, 24, 0, 0, 0, 24, 0, 0, 0, 24, 0, 0, 0, 24, + 0, 0, 0, 24, 0, 0, 0, 24, 0, 0, 0, 24, 0, 0, 0, 25, 0, 0, 0, 6, + 0, 0, 0, 9, 0, 0, 0,102,117,110, 99,110, 97,109,101, 0, 0, 0, 0, 0, + 16, 0, 0, 0, 6, 0, 0, 0,119,105,100,116,104, 0, 0, 0, 0, 0, 16, 0, + 0, 0, 7, 0, 0, 0,104,101,105,103,104,116, 0, 0, 0, 0, 0, 16, 0, 0, + 0, 12, 0, 0, 0, 99,111,108,111,114, 95,115,112, 97, 99,101, 0, 0, 0, 0, + 0, 16, 0, 0, 0, 10, 0, 0, 0,100, 97,116, 97, 95,116,121,112,101, 0, 0, + 0, 0, 0, 16, 0, 0, 0, 5, 0, 0, 0,102,117,110, 99, 0, 2, 0, 0, 0, + 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 31, 0, 0, 0, 50, 0, 0, 0, + 0, 5, 0, 11, 22, 0, 0, 0, 69, 1, 0, 0, 70, 1,128, 2,133, 65, 0, 0, +192, 1,128, 2, 5,130, 0, 0, 6,194, 64, 4, 65, 2, 1, 0,128, 2, 0, 0, + 28, 2,128, 1,156, 65, 0, 0,133, 1, 0, 0,192, 1, 0, 0, 1, 66, 1, 0, +213, 1,130, 3, 36, 2, 0, 0, 0, 0,128, 0, 0, 0, 0, 1, 0, 0,128, 1, + 0, 0, 0, 2, 0, 0,128, 2,137, 1,130, 3, 30, 0,128, 0, 6, 0, 0, 0, + 4, 3, 0, 0, 0,105,109, 0, 4, 7, 0, 0, 0, 97,115,115,101,114,116, 0, + 4, 7, 0, 0, 0,115,116,114,105,110,103, 0, 4, 7, 0, 0, 0,102,111,114, +109, 97,116, 0, 4, 24, 0, 0, 0,117,110,100,101,102,105,110,101,100, 32,102, +117,110, 99,116,105,111,110, 32, 96, 37,115, 39, 0, 4, 4, 0, 0, 0, 78,101, +119, 0, 1, 0, 0, 0, 0, 0, 0, 0, 38, 0, 0, 0, 49, 0, 0, 0, 5, 2, + 7, 10, 24, 0, 0, 0,197, 0, 0, 0,198, 64,192, 1, 0, 1, 0, 0, 68, 1, + 0, 0,132, 1,128, 0,196, 1, 0, 1, 4, 2,128, 1,220,128, 0, 3, 4, 1, + 0, 2, 64, 1, 0, 0,128, 1,128, 0,192, 1,128, 1, 5,130, 0, 0, 64, 2, + 0, 1, 28, 2, 0, 1, 28,129, 0, 0, 26, 1, 0, 0, 22,192, 0,128, 64, 1, + 0, 2,128, 1,128, 1, 94, 1,128, 1, 22, 0, 0,128,222, 0, 0, 1, 30, 0, +128, 0, 3, 0, 0, 0, 4, 3, 0, 0, 0,105,109, 0, 4, 17, 0, 0, 0, 73, +109, 97,103,101, 67,114,101, 97,116,101, 66, 97,115,101,100, 0, 4, 7, 0, 0, + 0,117,110,112, 97, 99,107, 0, 0, 0, 0, 0, 24, 0, 0, 0, 40, 0, 0, 0, 40, 0, 0, 0, 40, 0, 0, 0, 40, 0, 0, 0, 40, 0, 0, 0, 40, 0, 0, 0, - 41, 0, 0, 0, 6, 0, 0, 0, 9, 0, 0, 0,102,117,110, 99,110, 97,109,101, - 0, 0, 0, 0, 0, 21, 0, 0, 0, 6, 0, 0, 0,119,105,100,116,104, 0, 0, - 0, 0, 0, 21, 0, 0, 0, 7, 0, 0, 0,104,101,105,103,104,116, 0, 0, 0, - 0, 0, 21, 0, 0, 0, 12, 0, 0, 0, 99,111,108,111,114, 95,115,112, 97, 99, -101, 0, 0, 0, 0, 0, 21, 0, 0, 0, 10, 0, 0, 0,100, 97,116, 97, 95,116, -121,112,101, 0, 0, 0, 0, 0, 21, 0, 0, 0, 5, 0, 0, 0,102,117,110, 99, - 0, 2, 0, 0, 0, 21, 0, 0, 0, 0, 0, 0, 0, 18, 0, 0, 0, 20, 0, 0, - 0, 41, 0, 0, 0, 45, 0, 0, 0, 45, 0, 0, 0, 45, 0, 0, 0, 46, 0, 0, - 0, 46, 0, 0, 0, 46, 0, 0, 0, 46, 0, 0, 0, 46, 0, 0, 0, 46, 0, 0, - 0, 47, 0, 0, 0, 47, 0, 0, 0, 47, 0, 0, 0, 48, 0, 0, 0, 48, 0, 0, - 0, 48, 0, 0, 0, 48, 0, 0, 0, 2, 0, 0, 0, 17, 0, 0, 0, 79,110,101, - 83,111,117,114, 99,101, 79,110,101, 68,101,115,116, 0, 1, 0, 0, 0, 17, 0, - 0, 0, 18, 0, 0, 0, 84,119,111, 83,111,117,114, 99,101,115, 79,110,101, 68, -101,115,116, 0, 2, 0, 0, 0, 17, 0, 0, 0, 0, 0, 0, 0, + 40, 0, 0, 0, 40, 0, 0, 0, 43, 0, 0, 0, 43, 0, 0, 0, 43, 0, 0, 0, + 43, 0, 0, 0, 43, 0, 0, 0, 43, 0, 0, 0, 43, 0, 0, 0, 43, 0, 0, 0, + 44, 0, 0, 0, 44, 0, 0, 0, 45, 0, 0, 0, 45, 0, 0, 0, 45, 0, 0, 0, + 45, 0, 0, 0, 47, 0, 0, 0, 49, 0, 0, 0, 5, 0, 0, 0, 11, 0, 0, 0, +115,114, 99, 95,105,109, 97,103,101, 49, 0, 0, 0, 0, 0, 23, 0, 0, 0, 11, + 0, 0, 0,115,114, 99, 95,105,109, 97,103,101, 50, 0, 0, 0, 0, 0, 23, 0, + 0, 0, 4, 0, 0, 0, 97,114,103, 0, 0, 0, 0, 0, 23, 0, 0, 0, 10, 0, + 0, 0,100,115,116, 95,105,109, 97,103,101, 0, 8, 0, 0, 0, 23, 0, 0, 0, + 4, 0, 0, 0,114,101,116, 0, 16, 0, 0, 0, 23, 0, 0, 0, 5, 0, 0, 0, + 6, 0, 0, 0,119,105,100,116,104, 0, 7, 0, 0, 0,104,101,105,103,104,116, + 0, 12, 0, 0, 0, 99,111,108,111,114, 95,115,112, 97, 99,101, 0, 10, 0, 0, + 0,100, 97,116, 97, 95,116,121,112,101, 0, 5, 0, 0, 0,102,117,110, 99, 0, + 22, 0, 0, 0, 32, 0, 0, 0, 32, 0, 0, 0, 35, 0, 0, 0, 35, 0, 0, 0, + 35, 0, 0, 0, 35, 0, 0, 0, 35, 0, 0, 0, 35, 0, 0, 0, 35, 0, 0, 0, + 35, 0, 0, 0, 38, 0, 0, 0, 38, 0, 0, 0, 38, 0, 0, 0, 38, 0, 0, 0, + 49, 0, 0, 0, 49, 0, 0, 0, 49, 0, 0, 0, 49, 0, 0, 0, 49, 0, 0, 0, + 49, 0, 0, 0, 49, 0, 0, 0, 50, 0, 0, 0, 6, 0, 0, 0, 9, 0, 0, 0, +102,117,110, 99,110, 97,109,101, 0, 0, 0, 0, 0, 21, 0, 0, 0, 6, 0, 0, + 0,119,105,100,116,104, 0, 0, 0, 0, 0, 21, 0, 0, 0, 7, 0, 0, 0,104, +101,105,103,104,116, 0, 0, 0, 0, 0, 21, 0, 0, 0, 12, 0, 0, 0, 99,111, +108,111,114, 95,115,112, 97, 99,101, 0, 0, 0, 0, 0, 21, 0, 0, 0, 10, 0, + 0, 0,100, 97,116, 97, 95,116,121,112,101, 0, 0, 0, 0, 0, 21, 0, 0, 0, + 5, 0, 0, 0,102,117,110, 99, 0, 2, 0, 0, 0, 21, 0, 0, 0, 0, 0, 0, + 0, 18, 0, 0, 0, 25, 0, 0, 0, 50, 0, 0, 0, 54, 0, 0, 0, 54, 0, 0, + 0, 54, 0, 0, 0, 55, 0, 0, 0, 55, 0, 0, 0, 55, 0, 0, 0, 55, 0, 0, + 0, 55, 0, 0, 0, 55, 0, 0, 0, 56, 0, 0, 0, 56, 0, 0, 0, 56, 0, 0, + 0, 57, 0, 0, 0, 57, 0, 0, 0, 57, 0, 0, 0, 57, 0, 0, 0, 2, 0, 0, + 0, 17, 0, 0, 0, 79,110,101, 83,111,117,114, 99,101, 79,110,101, 68,101,115, +116, 0, 1, 0, 0, 0, 17, 0, 0, 0, 18, 0, 0, 0, 84,119,111, 83,111,117, +114, 99,101,115, 79,110,101, 68,101,115,116, 0, 2, 0, 0, 0, 17, 0, 0, 0, + 0, 0, 0, 0, }; if (luaL_loadbuffer(L,(const char*)B1,sizeof(B1),"../obj/imlua_fftw51/im_fftw.lo")==0) lua_call(L, 0, 0); diff --git a/test/lua/analyze.lua b/test/lua/analyze.lua deleted file mode 100644 index 7f06496..0000000 --- a/test/lua/analyze.lua +++ /dev/null @@ -1,28 +0,0 @@ -require"imlua" -require"imlua_process" - -local filename = "lena.jpg" - -local image = im.FileImageLoad(filename) -local gray = im.ImageCreate(image:Width(), image:Height(), im.GRAY, image:DataType()) -local binary = im.ImageCreate(image:Width(), image:Height(), im.BINARY, image:DataType()) -local region = im.ImageCreate(image:Width(), image:Height(), im.GRAY, im.USHORT) - --- make it grayscale -im.ConvertColorSpace(image, gray) -gray:Save("lena_gray.jpg", "JPEG") - --- make it binary -im.ProcessSliceThreshold(gray, binary, 0, 128) -binary:Save("lena_binary.jpg", "JPEG") - -local count = im.AnalyzeFindRegions(binary, region, 4, 1) -print("regions: ", count) - -local region2 = im.ImageCreate(image:Width(), image:Height(), im.GRAY, im.BYTE) -im.ConvertDataType(region, region2, 0, 0, 0, 0) - -local region3 = im.ImageCreate(image:Width(), image:Height(), im.MAP, im.BYTE) -im.ConvertColorSpace(region2, region3) -region3:SetPalette(im.PaletteHighContrast(), 256) -region3:Save("lena_region.gif", "GIF") diff --git a/test/lua/capture.lua b/test/lua/capture.lua deleted file mode 100644 index 491518a..0000000 --- a/test/lua/capture.lua +++ /dev/null @@ -1,63 +0,0 @@ -require"imlua" -require"imlua_capture" - -im.VideoCaptureReloadDevices() - -print("--- Devices ---") -local n = im.VideoCaptureDeviceCount() - -for i = 0, n - 1 do - desc = im.VideoCaptureDeviceDesc(i) - print(desc) -end - -local vc = im.VideoCaptureCreate() -print("connect: ", vc:Connect(0)) -print() - -print("--- Dialogs ---") - -local dc = vc:DialogCount() -for i = 0, dc - 1 do - desc = vc:DialogDesc(i) - print(i, desc) - vc:ShowDialog(i) -end -print() - - -print("--- Formats ---") - -local fc = vc:FormatCount() -for i = 0, fc - 1 do - local success, width, height, desc = vc:GetFormat(i) - print(i, string.format("%dx%d", width, height), desc) -end -print() - -print("--- Image Size ---") -local width, height = vc:GetImageSize() -print(width, height) -print() - -print("--- Attributes ---") -attribs = vc:GetAttributeList() -for i, name in ipairs(attribs) do - local error, percent = vc:GetAttribute(name) - if error == 0 then percent = "get error" end - print(i, name, percent) -end ---vc:SetAttribute("FlipVertical", 1) ---vc:SetAttribute("FlipHorizontal", 1) -print() - -print("--- Capture ---") -local image = im.ImageCreate(width, height, im.RGB, im.BYTE) -local res = vc:Live(1) -if (res > 0) then - print("grabbing frame") - print(vc:Frame(image, 3000)) -end -image:Save("capture.jpg", "JPEG") - -vc:Disconnect() diff --git a/test/lua/combine9.lua b/test/lua/combine9.lua deleted file mode 100644 index 0bc1b17..0000000 --- a/test/lua/combine9.lua +++ /dev/null @@ -1,107 +0,0 @@ ---A script to compose 9 photos, with 4/6 aspect ratio - -require"imlua" -require"imlua_process" -require"iuplua" - -function Confirm(title,msg) - if continue then - b=iup.Alarm(title, msg ,"Continue" ,"Exit") - if b==2 then continue=false print("Script Aborted!") end - end -end - -function Create_Host_Image() - if continue then - local screenx=1024*3 screeny=684*3 - dst_photo = im.ImageCreate(screenx, screeny, im.RGB, im.BYTE) - resize_photo = im.ImageCreate(1024, 684, im.RGB, im.BYTE) -- for resize - end -end - -function Create_Host_Name(name) - if continue then - i=0 - repeat - i=i+1 - num=1000+i - numstr=string.sub(tostring(num),-3) --- path="D:/Composite/" - path="D:/Downloads/Test/" - ext=".jpg" - Result=path..name..numstr..ext - res,msg=io.open(Result) - io.close() - until not res - end -end - -function Get_Source_Photo() - if continue then --- path="D:/MyPictures/" - path="D:/Downloads/Test/*.jpg" - Source, err = iup.GetFile(path) - print("Source: ", Source) - if err<0 then continue=false end - end -end - -function Insert_Photo(num) - if continue then - title="Photo "..num.." of 9" msg=Source Confirm(title,msg) - wd=dst_photo:Width() - hd=dst_photo:Height() - --print("Dst Size:",wd,hd) - src_photo=im.FileImageLoadBitmap(Source) - valuex=src_photo:Width() - valuey=src_photo:Height() - --print("Source Size:",valuex,valuey) - panex={0,1024,2048,0,1024,2048,0,1024,2048} - paney={0,0,0,684,684,684,1368,1368,1368} - Xd=panex[num] - Yd=paney[num] - Wd=1024 Hd=684 - -- extract a proportional rectangle from the source image - if 1.5*valuey>valuex then - Ws=valuex - Xs=0 - Hs=math.floor(valuex/1.5) - Ys=math.floor((valuey-Hs)/2) - else - Hs=valuey - Ys=0 - Ws=math.floor(1.5*Hs) - Xs=math.floor((valuex-Ws)/2) - end - - --print("Crop Size:",Ws, Hs) - --print("Crop Shift:",Xs,Ys) - crop_photo = im.ImageCreate(Ws, Hs, im.RGB, im.BYTE) - im.ProcessCrop(src_photo, crop_photo, Xs,Ys) - im.ProcessResize(crop_photo, resize_photo, 1) -- do bilinear interpolation - im.ProcessInsert(dst_photo, resize_photo, dst_photo, Xd, Yd) -- insert resize in dst and place the result in dst - crop_photo:Destroy() - - if num==9 then src_photo:CopyAttributes(dst_photo) end - end -end - -function Save_Composite_Photo() - if continue then - name="Composite" - Create_Host_Name(name) - dst_photo:Save(Result, "JPEG") - os.execute(Result) - end -end - ---Script Starts -continue=true -title="9 Panel Composite" msg="Photos can be anysize." Confirm(title,msg) -Create_Host_Image() -for i=1,9 do - num=i - Get_Source_Photo() - Insert_Photo(num) - end -Save_Composite_Photo() diff --git a/test/lua/error.lua b/test/lua/error.lua deleted file mode 100644 index f8c71a8..0000000 --- a/test/lua/error.lua +++ /dev/null @@ -1,10 +0,0 @@ -require"imlua" - -local filename = "lena.jpg" -local image = im.FileImageLoad(filename) -local image2 = im.ImageCreate(image:Width(), image:Height(), im.GRAY, im.USHORT) - --- Both calls will signal an error because of incompatible parameters - ---im.ConvertDataType(image, image2, im.CPX_REAL, im.GAMMA_LINEAR, 0, im.CAST_MINMAX) -im.ConvertColorSpace(image, image2, im.CPX_REAL, im.GAMMA_LINEAR, 0, im.CAST_MINMAX) diff --git a/test/lua/fft.lua b/test/lua/fft.lua deleted file mode 100644 index 3589635..0000000 --- a/test/lua/fft.lua +++ /dev/null @@ -1,17 +0,0 @@ -require"imlua" -require"imlua_process" -require"imlua_fftw" - -local filename = "lena.jpg" -local image = im.FileImageLoad(filename) - -local complex = im.ImageCreate(image:Width(), image:Height(), image:ColorSpace(), im.CFLOAT) -im.ProcessFFT(image, complex) - -local c = complex[0][5][10] -- component=0(Red), y = 5 x =10 -print(c[1], c[2]) - -complex[0][5][10] = { 2*c[1], c[2]/2 } - -local c = complex[0][5][10] -print(c[1], c[2]) diff --git a/test/lua/flower.jpg b/test/lua/flower.jpg Binary files differdeleted file mode 100644 index 2b9dbf1..0000000 --- a/test/lua/flower.jpg +++ /dev/null diff --git a/test/lua/index.lua b/test/lua/index.lua deleted file mode 100644 index 1c4c1e4..0000000 --- a/test/lua/index.lua +++ /dev/null @@ -1,18 +0,0 @@ -require"imlua" - -local filename = "lena.jpg" -local image = im.FileImageLoad(filename) - -local r = image[0] -local g = image[1] -local b = image[2] - -for row = 0, image:Height() - 1, 10 do - for column = 0, image:Width() - 1, 10 do - r[row][column] = 0 - g[row][column] = 0 - b[row][column] = 0 - end -end - -image:Save("lena_indexing.bmp", "BMP") diff --git a/test/lua/info.lua b/test/lua/info.lua deleted file mode 100644 index b1afb2a..0000000 --- a/test/lua/info.lua +++ /dev/null @@ -1,149 +0,0 @@ -require"imlua" -require"lfs" - -function PrintError(error) - local msg = {} - msg[im.ERR_OPEN] = "Error Opening File." - msg[im.ERR_MEM] = "Insuficient memory." - msg[im.ERR_ACCESS] = "Error Accessing File." - msg[im.ERR_DATA] = "Image type not Suported." - msg[im.ERR_FORMAT] = "Invalid Format." - msg[im.ERR_COMPRESS] = "Invalid or unsupported compression." - - if msg[error] then - print(msg[error]) - else - print("Unknown Error.") - end -end - -function FindZero(data) - if (not data) then return false end - for i = 1, table.getn(data) do - if data[i] == 0 then - return true - end - end - return false -end - -function AttribData2Str(data, data_type) - local data_str - - if data_type == im.BYTE then - data_str = string.format("%3d", data[1]) - elseif data_type == im.USHORT then - data_str = string.format("%5d", data[1]) - elseif data_type == im.INT then - data_str = string.format("%5d", data[1]) - elseif data_type == im.FLOAT then - data_str = string.format("%5.2f", data[1]) - elseif data_type == im.CFLOAT then - data_str = string.format("%5.2f, %5.2f", data[1], data[2]) - end - - return data_str -end - -function GetSizeDesc(size) - local size_desc - - if size < 1024 then - size_desc = "b" - else - size = size / 1024 - - if size < 1024 then - size_desc = "Kb" - else - size = size / 1024 - size_desc = "Mb" - end - end - - return size, size_desc -end - -function FileSize(file_name) - if lfs then - local attr = lfs.attributes(file_name) - return attr.size - else - return 0 - end -end - -function PrintImageInfo(file_name) - print("IM Info") - print(string.format(" File Name:\n %s", file_name)) - - local ifile, error = im.FileOpen(file_name) - if not ifile then - PrintError(error) - return nil - end - - local file_size = FileSize(file_name) - - print(string.format(" File Size: %.2f %s", GetSizeDesc(file_size))) - - local format, compression, image_count = ifile:GetInfo() - - local error, format_desc = im.FormatInfo(format) - print(string.format(" Format: %s - %s", format, format_desc)) - print(string.format(" Compression: %s", compression)) - print(string.format(" Image Count: %d", image_count)) - for i = 1, image_count do - local error, width, height, color_mode, data_type = ifile:ReadImageInfo(i-1) - if width == nil then - PrintError(height) - ifile:Close() - return nil - end - - print(string.format(" Image #%d", i)) - print(string.format(" Width: %d", width)) - print(string.format(" Height: %d", height)) - print(string.format(" Color Space: %s", im.ColorModeSpaceName(color_mode))) - print(string.format(" Has Alpha: %s", im.ColorModeHasAlpha(color_mode) and "Yes" or "No")) - print(string.format(" Is Packed: %s", im.ColorModeIsPacked(color_mode) and "Yes" or "No")) - print(string.format(" Is Top Down: %s", im.ColorModeIsTopDown(color_mode) and "Yes" or "No")) - print(string.format(" Data Type: %s", im.DataTypeName(data_type))) - - local image_size = im.ImageDataSize(width, height, color_mode, data_type) - print(string.format(" Data Size: %.2f %s", GetSizeDesc(image_size))) - - local attrib_list = ifile:GetAttributeList() - for a = 1, table.getn(attrib_list) do - if a == 1 then - print(" Attributes:") - end - - local attrib_data, attrib_data_type = ifile:GetAttribute(attrib_list[a]) - - if table.getn(attrib_data) == 1 then - print(string.format(" %s: %s", attrib_list[a], AttribData2Str(attrib_data, attrib_data_type))) - elseif attrib_data_type == im.BYTE and FindZero(attrib_data) then - attrib_data = ifile:GetAttribute(attrib_list[a], true) - print(string.format(" %s: %s", attrib_list[a], attrib_data)) - else - print(string.format(" %s: %s ...", attrib_list[a], AttribData2Str(attrib_data, attrib_data_type))) - end - end - end - - ifile:Close() -end - -function main(arg) - if (not arg or table.getn(arg) < 1) then - print("Invalid number of arguments.") - return nil - end - - PrintImageInfo(arg[1]) - return 1 -end - -main(arg) ---PrintImageInfo("lena.jpg") diff --git a/test/lua/lena.jpg b/test/lua/lena.jpg Binary files differdeleted file mode 100644 index b6bad61..0000000 --- a/test/lua/lena.jpg +++ /dev/null diff --git a/test/lua/multicrop.lua b/test/lua/multicrop.lua deleted file mode 100644 index 6af3e52..0000000 --- a/test/lua/multicrop.lua +++ /dev/null @@ -1,61 +0,0 @@ --- lua5.1 multicrop.lua 100 500 100 500 *.jpg - -require"imlua" -require"imlua_process" - -err_msg = { - "No error.", - "Error while opening the file.", - "Error while accessing the file.", - "Invalid or unrecognized file format.", - "Invalid or unsupported data.", - "Invalid or unsupported compression.", - "Insuficient memory", - "Interrupted by the counter", -} - -x1 = arg[1] -x2 = arg[2] -y1 = arg[3] -y2 = arg[4] -filename1 = arg[5] -if (not x1 or not x2 or not y1 or not y2 or not filename1) then - print("Must have the rectangle coordinates and at least one file name as parameters.") - print(" Can have more than one file name as parameters and can use wildcards.") - print(" Usage:") - print(" lua multicrop.lua x1 x2 y1 y2 filename1 filename2 ...") - return -end - -print(">>> Crop of multiple images <<<") -print("") - -function ProcessImageFile(file_name) - print("Loading File: "..file_name) - image, err = im.FileImageLoad(file_name); - - if (err and err ~= im.ERR_NONE) then - error(err_msg[err+1]) - end - - new_image = im.ProcessCropNew(image, x1, x2, y1, y2) - - new_image:Save(file_name, "JPEG"); - - new_image:Destroy() - image:Destroy() - print("Done File.") - print("") -end - -file_count = 0 -for index,value in ipairs(arg) do - if (index > 4) then - ProcessImageFile(arg[index]) - file_count = file_count + 1 - end -end - -if (file_count > 1) then - print("Processed "..file_count.." Files.") -end diff --git a/test/lua/multimorpho.lua b/test/lua/multimorpho.lua deleted file mode 100644 index 742d713..0000000 --- a/test/lua/multimorpho.lua +++ /dev/null @@ -1,103 +0,0 @@ --- multi-step morphological opening on a binarized image, with increasing structuring element (Se) size: --- step 1 - 3x3 Se --- step 2 - 5x5 Se --- step 3 - 7x7 Se --- Step n - (2n+1)x (2n+1) Se --- after each step, a count of the objects (white items) in the opened image has to be performed, --- and the number of counted items to be saved in a .txt file for easy and fast exporting to excel - -require"imlua" -require"imlua_process" - -err_msg = { - "No error.", - "Error while opening the file.", - "Error while accessing the file.", - "Invalid or unrecognized file format.", - "Invalid or unsupported data.", - "Invalid or unsupported compression.", - "Insufficient memory", - "Interrupted by the counter", -} - -colorspace_str = { - "RGB", - "MAP", - "GRAY", - "BINARY", - "CMYK", - "YCBCR", - "LAB", - "LUV", - "XYZ" -} - -num_step = arg[1] -file_name1 = arg[2] -if (not num_step or not file_name1) then - print("Must have the number of steps and a file name as parameters.") - print(" Can have more than one file name as parameters and can use wildcards.") - print(" Usage:") - print(" lua multimorpho.lua num_step filename1 filename2 ...") - return -end - -print(">>> Multi-step Morphological Opening <<<") -print("Number of Steps: "..num_step) -print("") - -function ProcessImageFile(file_name, num_step) - print("Loading File: "..file_name) - image, err = im.FileImageLoad(file_name); - - if (err and err ~= im.ERR_NONE) then - error(err_msg[err+1]) - end - - if (image:ColorSpace() ~= im.BINARY) then - error("Invalid Image Color Space. Must be a Binary image [Color Space="..colorspace_str[image:ColorSpace()+1].."].") - end - - file_name = file_name..".csv" - print("Saving Log File: "..file_name) - log = io.open(file_name, "w") - - morph_image = image:Clone() - obj_image = im.ImageCreateBased(image, nil, nil, im.GRAY, im.USHORT) - - for step = 1, num_step do - kernel_size = 2*step+1 - print(" Binary Morphology Open [Kernel Size="..kernel_size.."x"..kernel_size.."].") - im.ProcessBinMorphOpen(image, morph_image, kernel_size, 1) -- 1 interaction - - num_obj = im.AnalyzeFindRegions(morph_image, obj_image, 4, false) -- 4 connected, ignore objects that touch the border - print(" Objects Found: "..num_obj) - log:write(kernel_size..";"..num_obj.."\n") - - if (num_obj == 0) then - step = num_step - end - - obj_image:Clear() - morph_image:Clear() - end - - log:close() - obj_image:Destroy() - morph_image:Destroy() - image:Destroy() - print("Done File.") - print("") -end - -file_count = 0 -for index,value in ipairs(arg) do - if (index > 1) then - ProcessImageFile(arg[index], num_step) - file_count = file_count + 1 - end -end - -if (file_count > 1) then - print("Processed "..file_count.." Files.") -end diff --git a/test/lua/palette.lua b/test/lua/palette.lua deleted file mode 100644 index 5ec7168..0000000 --- a/test/lua/palette.lua +++ /dev/null @@ -1,6 +0,0 @@ -require"imlua" - -local impal = im.PaletteHotIron() -print(impal) -print(im.ColorDecode(impal[1])) - diff --git a/test/lua/process.lua b/test/lua/process.lua deleted file mode 100644 index e942b27..0000000 --- a/test/lua/process.lua +++ /dev/null @@ -1,50 +0,0 @@ -require"imlua" -require"imlua_process" - -function save_histogram (hist, filename, format) - local height = 200 -- altura da imagem - local max = math.max(unpack(hist)) -- pega o maior valor do histograma - local n = table.getn(hist) + 1 -- zero-based - local image = im.ImageCreate(n, height, im.GRAY, im.BYTE) -- cria a imagem - local white = 255 - local black = 0 - - local render = function (x, y, d, param) - local v = hist[x] / max - local h = v * height - if y <= h then return black end - return white - end - - im.ProcessRenderOp(image, render, "histogram", {}, 0) - image:Save(filename, format) -end - -local filename = "lena.jpg" - -local image = im.FileImageLoad(filename) - -save_histogram(im.CalcHistogram(image, 0, 0), "lena_histogram_R.gif", "GIF") -save_histogram(im.CalcHistogram(image, 1, 0), "lena_histogram_G.gif", "GIF") -save_histogram(im.CalcHistogram(image, 2, 0), "lena_histogram_B.gif", "GIF") -save_histogram(im.CalcGrayHistogram(image, 0), "lena_histogram_gray.gif", "GIF") - -local r = im.ImageCreate(image:Width(), image:Height(), im.GRAY, image:DataType()) -local g = im.ImageCreate(image:Width(), image:Height(), im.GRAY, image:DataType()) -local b = im.ImageCreate(image:Width(), image:Height(), im.GRAY, image:DataType()) -im.ProcessSplitComponents(image, { r, g, b}) -r:Save("lena_r.jpg", "JPEG") -g:Save("lena_g.jpg", "JPEG") -b:Save("lena_b.jpg", "JPEG") - -local rgb = image:Clone() -im.ProcessMergeComponents({r, g, b}, rgb) -rgb:Save("lena_rgb.jpg", "JPEG") - -local replace = image:Duplicate() -im.ProcessReplaceColor(image, replace, { 146, 93, 145 }, { 255, 0, 255 }) -replace:Save("lena_replace.jpg", "JPEG") - -local bitmask = image:Duplicate() -im.ProcessBitMask(image, bitmask, "01111010", im.BIT_XOR) -bitmask:Save("lena_bitmask.jpg", "JPEG") diff --git a/test/lua/process_new.lua b/test/lua/process_new.lua deleted file mode 100644 index 93ebcce..0000000 --- a/test/lua/process_new.lua +++ /dev/null @@ -1,44 +0,0 @@ -require"imlua" -require"imlua_process" - -function save_histogram (hist, filename, format) - local height = 200 -- altura da imagem - local max = math.max(unpack(hist)) -- pega o maior valor do histograma - local n = table.getn(hist) + 1 -- zero-based - local image = im.ImageCreate(n, height, im.GRAY, im.BYTE) -- cria a imagem - local white = 255 - local black = 0 - - local render = function (x, y, d, param) - local v = hist[x] / max - local h = v * height - if y <= h then return black end - return white - end - - im.ProcessRenderOp(image, render, "histogram", {}, 0) - image:Save(filename, format) -end - -local filename = "lena.jpg" - -local image = im.FileImageLoad(filename) - -save_histogram(im.CalcHistogram(image, 0, 0), "lena_histogram_R.gif", "GIF") -save_histogram(im.CalcHistogram(image, 1, 0), "lena_histogram_G.gif", "GIF") -save_histogram(im.CalcHistogram(image, 2, 0), "lena_histogram_B.gif", "GIF") -save_histogram(im.CalcGrayHistogram(image, 0), "lena_histogram_gray.gif", "GIF") - -local r, g, b = im.ProcessSplitComponentsNew(image) -r:Save("lena_r.jpg", "JPEG") -g:Save("lena_g.jpg", "JPEG") -b:Save("lena_b.jpg", "JPEG") - -local rgb = im.ProcessMergeComponentsNew({r, g, b}) -rgb:Save("lena_rgb.jpg", "JPEG") - -local replace = im.ProcessReplaceColorNew(image, { 146, 93, 145 }, { 255, 0, 255 }) -replace:Save("lena_replace.jpg", "JPEG") - -local bitmask = im.ProcessBitMaskNew(image, "01111010", im.BIT_XOR) -replace:Save("lena_bitmask.jpg", "JPEG") diff --git a/test/lua/render.lua b/test/lua/render.lua deleted file mode 100644 index b57f906..0000000 --- a/test/lua/render.lua +++ /dev/null @@ -1,50 +0,0 @@ -require"imlua" -require"imlua_process" - -local image = im.ImageCreate(500, 500, im.RGB, im.BYTE) - -im.ProcessRenderRandomNoise(image) -image:Save("render_noise.bmp", "BMP") - -im.ProcessRenderConstant(image, { 128.0, 0.0, 255.0 }) -image:Save("render_constant.bmp", "BMP") - -im.ProcessRenderWheel(image, 100, 200) -image:Save("render_wheel.bmp", "BMP") - -im.ProcessRenderTent(image, 300, 200) -image:Save("render_tent.bmp", "BMP") - -im.ProcessRenderRamp(image, 0, 500, 0) -image:Save("render_ramp.bmp", "BMP") - -im.ProcessRenderBox(image, 200, 200) -image:Save("render_box.bmp", "BMP") - -im.ProcessRenderSinc(image, 100.0, 100.0) -image:Save("render_sinc.bmp", "BMP") - -im.ProcessRenderGaussian(image, 100.0) -image:Save("render_gaussian.bmp", "BMP") - -im.ProcessRenderLapOfGaussian(image, 100.0) -image:Save("render_lapofgaussian.bmp", "BMP") - -im.ProcessRenderCosine(image, 100.0, 100.0) -image:Save("render_cosine.bmp", "BMP") - -im.ProcessRenderGrid(image, 100.0, 100.0) -image:Save("render_grid.bmp", "BMP") - -im.ProcessRenderChessboard(image, 100.0, 100.0) -image:Save("render_chess.bmp", "BMP") - -im.ProcessRenderCone(image, 200) -image:Save("render_cone.bmp", "BMP") - -local render_func = function (x, y, d, param) - return math.mod(x + y, 256) -end - -im.ProcessRenderOp(image, render_func, "test", {}, 0) -image:Save("render_func.bmp", "BMP") diff --git a/test/lua/render_cd.lua b/test/lua/render_cd.lua deleted file mode 100644 index 4af8a16..0000000 --- a/test/lua/render_cd.lua +++ /dev/null @@ -1,19 +0,0 @@ -require"imlua" -require"cdlua" -require"cdluaim" - -local image = im.ImageCreate(500, 500, im.RGB, im.BYTE) -local canvas = image:cdCreateCanvas() -- Creates a CD_IMAGERGB canvas - -canvas:Activate() -canvas:Background(cd.EncodeColor(255, 255, 255)) -canvas:Clear() -fgcolor = cd.EncodeColor(255, 0, 0) -- red -fgcolor = cd.EncodeAlpha(fgcolor, 50) -- semi transparent -canvas:Foreground(fgcolor) -canvas:Font("Times", cd.BOLD, 24) -canvas:Text(100, 100, "Test") -canvas:Line(0,0,100,100) -canvas:Kill() - -image:Save("new.bmp", "BMP") diff --git a/test/lua/screencapture.lua b/test/lua/screencapture.lua deleted file mode 100644 index 16eb94e..0000000 --- a/test/lua/screencapture.lua +++ /dev/null @@ -1,13 +0,0 @@ -require"imlua" -require"cdlua" -require"cdluaim" - -local canvas = cd.CreateCanvas(cd.NATIVEWINDOW, nil) -canvas:Activate() -local w, h = canvas:GetSize() -local image = im.ImageCreate(w, h, im.RGB, im.BYTE) -image:cdCanvasGetImage(canvas, 0, 0) -error = image:Save("screencapture.jpg", "JPEG") -image:Destroy() -if (error) then print("error = "..error) end - diff --git a/test/lua/show_flower.wlua b/test/lua/show_flower.wlua deleted file mode 100644 index ec97a88..0000000 --- a/test/lua/show_flower.wlua +++ /dev/null @@ -1,31 +0,0 @@ -require"imlua" -require"cdlua" -require"cdluaim" -require"iuplua" -require"iupluacd" - -image = im.FileImageLoad("flower.jpg") -- directly load the image at index 0. it will open and close the file -cnv = iup.canvas{rastersize = image:Width().."x"..image:Height(), border = "NO"} -cnv.image = image -- store the new image in the IUP canvas as an attribute - -function cnv:map_cb() -- the CD canvas can only be created when the IUP canvas is mapped - self.canvas = cd.CreateCanvas(cd.IUP, self) -end - -function cnv:action() -- called everytime the IUP canvas needs to be repainted - self.canvas:Activate() - self.canvas:Clear() - self.image:cdCanvasPutImageRect(self.canvas, 0, 0, 0, 0, 0, 0, 0, 0) -- use default values -end - -dlg = iup.dialog{cnv} - -function dlg:close_cb() - cnv.image:Destroy() - cnv.canvas:Kill() - self:destroy() - return iup.IGNORE -- because we destroy the dialog -end - -dlg:show() -iup.MainLoop() diff --git a/test/lua/view.wlua b/test/lua/view.wlua deleted file mode 100644 index 60be33e..0000000 --- a/test/lua/view.wlua +++ /dev/null @@ -1,183 +0,0 @@ -require"imlua" -require"cdlua" -require"cdluaim" -require"iuplua" -require"iupluacd" - -function PrintError(func, error) - local msg = {} - msg[im.ERR_OPEN] = "Error Opening File." - msg[im.ERR_MEM] = "Insuficient memory." - msg[im.ERR_ACCESS] = "Error Accessing File." - msg[im.ERR_DATA] = "Image type not Suported." - msg[im.ERR_FORMAT] = "Invalid Format." - msg[im.ERR_COMPRESS] = "Invalid or unsupported compression." - - if msg[error] then - print(func..": "..msg[error]) - else - print("Unknown Error.") - end -end - -function LoadImage(file_name) - local image - local ifile, error = im.FileOpen(file_name) - if not ifile then - PrintError("open", error) - return - end - - -- load the first image in the file. - -- force the image to be converted to a bitmap - image, error = ifile:LoadBitmap() - if not image then - PrintError("load", error) - return - end - - ifile:Close() - return image -end - - -dlg = nil -- only one dlg - -function ShowImage(file_name) - - local image = LoadImage(file_name) - if not image then - return false - end - - if dlg then - local old_canvas = dlg.canvas - local old_image = dlg.image - - if old_canvas ~= nil then old_canvas:Kill() end - if old_image ~= nil then old_image:Destroy() end - - iup.Destroy(dlg) - end - - cnv = iup.canvas{} - - function cnv:action() - local canvas = dlg.canvas - local image = dlg.image - - if (not canvas) then return end - - -- posy is top-down, CD is bottom-top. - -- invert scroll reference (YMAX-DY - POSY). - y = self.ymax-self.dy - self.posy - if (y < 0) then y = 0 end - - - canvas:Activate() - canvas:Clear() - x = -self.posx - y = -y - image:cdCanvasPutImageRect(canvas, x, y, image:Width(), image:Height(), 0, 0, 0, 0) - canvas:Flush() - - return iup.DEFAULT - end - - function cnv:button_cb() - local file_name = "*.*" - local error - - file_name, error = iup.GetFile(file_name) - if error ~= 0 then - return iup.DEFAULT - end - - ShowImage(file_name) - return iup.DEFAULT - end - - - -- Set the Canvas inicial size (IUP will retain this value). - w = image:Width() - h = image:Height() - if (w > 800) then w = 800 end - if (h > 600) then h = 600 end - cnv.rastersize = string.format("%dx%d", w, h) - cnv.border = "no" - cnv.scrollbar = "yes" - cnv.xmax = image:Width()-1 - cnv.ymax = image:Height()-1 - - function cnv:resize_cb(w, h) - self.dx = w - self.dy = h - self.posx = self.posx -- needed only in IUP 2.x - self.posy = self.posy - end - - dlg = iup.dialog{cnv} - dlg.title = file_name - dlg.cnv = cnv - dlg.image = image - - function dlg:close_cb() - local canvas = self.canvas - local image = self.image - - if canvas then canvas:Kill() end - if image then image:Destroy() end - - return iup.CLOSE - end - - function dlg:map_cb() - canvas = cd.CreateCanvas(cd.IUP, self.cnv) - self.canvas = canvas - self.posx = 0 -- needed only in IUP 2.x - self.posy = 0 - end - - dlg:show() - cnv.rastersize = nil -- to remove the minimum limit - - return true -end - -function main(arg) - local file_name = "*.*" - local error - - -- Try to get a file name from the command line. - if (arg == nil or table.getn(arg) < 2) then - file_name, error = iup.GetFile(file_name) - if error ~= 0 then - return true - end - else - file_name = arg[1] - end - - if not ShowImage(file_name) then - local Try = true - -- If ShowImage returns an error I will try to read another image. - -- I can give up on File Open dlg choosing "Cancel". - while Try do - file_name = "*.*" - - file_name, error = iup.GetFile(file_name) - if error ~= 0 then - return true - end - - if ShowImage(file_name) then - Try = false - end - end - end - - iup.MainLoop() - return true -end - -main(arg) diff --git a/test/lua/viewGL.wlua b/test/lua/viewGL.wlua deleted file mode 100644 index f5ce58a..0000000 --- a/test/lua/viewGL.wlua +++ /dev/null @@ -1,76 +0,0 @@ -require("iuplua") -require("iupluagl") -require("luagl") -require("imlua") - -iup.key_open() - -texture = 0 - -cnv = iup.glcanvas{buffer="DOUBLE", rastersize = "640x480"} - -function cnv:resize_cb(width, height) - iup.GLMakeCurrent(self) - gl.Viewport(0, 0, width, height) -end - -function cnv:action(x, y) - iup.GLMakeCurrent(self) - gl.PixelStore(gl.UNPACK_ALIGNMENT, 1) - gl.Clear('COLOR_BUFFER_BIT,DEPTH_BUFFER_BIT') -- Clear Screen And Depth Buffer - - gl.DrawPixelsRaw (image:Width(), image:Height(), glformat, gl.UNSIGNED_BYTE, gldata) - - iup.GLSwapBuffers(self) -end - -function cnv:k_any(c) - if c == iup.K_q or c == iup.K_ESC then - return iup.CLOSE - end - - if c == iup.K_F1 then - if fullscreen then - fullscreen = false - dlg.fullscreen = "No" - else - fullscreen = true - dlg.fullscreen = "Yes" - end - end - - if c == iup.K_F2 then - fileName = iup.GetFile("*.*") - new_image = im.FileImageLoadBitmap(fileName) - if (not new_image) then - iup.Message("Error", "LoadBitmap failed.") - else - gldata, glformat = new_image:GetOpenGLData() - if (image) then image:Destroy() end - image = new_image - iup.Update(cnv) - end - end - -end - -if arg and arg[1] ~= nil then - fileName = arg[1] -else - fileName = iup.GetFile("*.*") -end - -image = im.FileImageLoadBitmap(fileName) -if (not image) then - error("LoadBitmap failed.") -end -gldata, glformat = image:GetOpenGLData() - -dlg = iup.dialog{cnv; title="LuaGL/IUP/IM Loader"} - -dlg:show() -cnv.rastersize = nil -- reset minimum limitation - -if (not iup.MainLoopLevel or iup.MainLoopLevel()==0) then - iup.MainLoop() -end |