summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--html/en/building.html4
-rw-r--r--html/en/history.html15
-rw-r--r--html/examples/glut_capture.c2
-rw-r--r--include/im_convert.h10
-rw-r--r--src/im.def1
-rw-r--r--src/im_convertbitmap.cpp146
-rw-r--r--src/lua5/imlua_image.c17
-rw-r--r--src/lua5/imlua_palette.c12
-rw-r--r--src/lua5/imlua_util.c8
-rw-r--r--test/glut_capture.c2
10 files changed, 153 insertions, 64 deletions
diff --git a/html/en/building.html b/html/en/building.html
index 737cf1c..4c4b564 100644
--- a/html/en/building.html
+++ b/html/en/building.html
@@ -122,12 +122,12 @@ cd ..
mkdir cd
cd cd
-tar -xpvzf cd-5.4_Linux26g4_lib.tar.gz
+tar -xpvzf ../cd-5.4_Linux26g4_lib.tar.gz
cd ..
mkdir im
cd im
-tar -xpvzf im-3.6.2_Linux26g4_lib.tar.gz
+tar -xpvzf ../im-3.6.2_Linux26g4_lib.tar.gz
cd ..
</pre>
diff --git a/html/en/history.html b/html/en/history.html
index 89ff861..f789543 100644
--- a/html/en/history.html
+++ b/html/en/history.html
@@ -26,8 +26,21 @@
<h2>History of Changes</h2>
<h3 dir="ltr">
- CVS (12/Aug/2010)</h3>
+ CVS (25/Oct/2010)</h3>
<ul dir="ltr">
+ <li dir="ltr"><span class="hist_new">New:</span><span style="color: #008000"><span
+ style="color: #000000">
+ function </span></span><strong>imImageCreateFromOpenGLData</strong>.</li>
+ <li dir="ltr">
+ <span class="hist_changed">Changed:</span> the function <strong>
+ imConvertPacking</strong> now has one more parameter so src_depth can be
+ different from dst_depth.</li>
+ <li dir="ltr">
+ <span style="color: #008000">
+ <span
+ style="color: #000000">
+ <span class="hist_fixed">Fixed:</span> </span></span><strong>
+ imImageGetOpenGLData</strong> for some configurations.</li>
<li dir="ltr"><span style="color: #008000">
<span
style="color: #000000">
diff --git a/html/examples/glut_capture.c b/html/examples/glut_capture.c
index 80aadd2..b9a1779 100644
--- a/html/examples/glut_capture.c
+++ b/html/examples/glut_capture.c
@@ -152,7 +152,7 @@ void idle(void)
}
}
- imConvertPacking(image->data[0], gl_data, image->width, image->height, image->depth, image->data_type, 0);
+ imConvertPacking(image->data[0], gl_data, image->width, image->height, image->depth, image->depth, image->data_type, 0);
display();
}
}
diff --git a/include/im_convert.h b/include/im_convert.h
index 794eed9..9bca445 100644
--- a/include/im_convert.h
+++ b/include/im_convert.h
@@ -105,6 +105,11 @@ int imConvertToBitmap(const imImage* src_image, imImage* dst_image, int cpx2real
* \ingroup convert */
void* imImageGetOpenGLData(const imImage* image, int *glformat);
+/** Creates an image from an OpenGL data.
+ *
+ * \verbatim im.ImageCreateFromOpenGLData(width, height, glformat: number, gldata: userdata) -> image: imImage [in Lua 5] \endverbatim
+ * \ingroup convert */
+imImage* imImageCreateFromOpenGLData(int width, int height, int glformat, const void* gldata);
/** \defgroup cnvutil Raw Data Conversion Utilities
@@ -115,9 +120,10 @@ void* imImageGetOpenGLData(const imImage* image, int *glformat);
* \ingroup imagerep */
-/** Changes the packing of the data buffer. Both must have the same depth.
+/** Changes the packing of the data buffer. Both must have the same width, height and data_type. \n
+ * It can be used to copy data even if depth=1.
* \ingroup cnvutil */
-void imConvertPacking(const void* src_data, void* dst_data, int width, int height, int depth, int data_type, int src_is_packed);
+void imConvertPacking(const void* src_data, void* dst_data, int width, int height, int src_depth, int dst_depth, int data_type, int src_is_packed);
/** Changes in-place a MAP data into a RGB data. The data must have room for the RGB image. \n
* depth can be 3 or 4. count=width*height. \n
diff --git a/src/im.def b/src/im.def
index 9c448d5..1bbe79d 100644
--- a/src/im.def
+++ b/src/im.def
@@ -101,6 +101,7 @@ EXPORTS
imImageLineSize
imImageIsBitmap
imImageGetOpenGLData
+ imImageCreateFromOpenGLData
imImageMatch
imImageMatchColor
imImageMatchColorSpace
diff --git a/src/im_convertbitmap.cpp b/src/im_convertbitmap.cpp
index a4f6b70..629dcf5 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.3 2009/08/18 02:23:33 scuri Exp $
+ * $Id: im_convertbitmap.cpp,v 1.4 2010/10/25 18:29:07 scuri Exp $
*/
#include "im.h"
@@ -66,7 +66,7 @@ int imConvertToBitmap(const imImage* src_image, imImage* dst_image, int cpx2real
template <class T>
-void iDoChangePacking(const T* src_data, T* dst_data, int width, int height, int depth,
+void iDoChangePacking(const T* src_data, T* dst_data, int width, int height, int src_depth, int dst_depth,
int src_is_packed)
{
int count = width*height;
@@ -74,11 +74,12 @@ void iDoChangePacking(const T* src_data, T* dst_data, int width, int height, int
{
for (int i = 0; i < count; i++)
{
- for (int d = 0; d < depth; d++)
+ for (int d = 0; d < dst_depth; d++)
{
- *(dst_data + d*count) = *src_data++;
+ *(dst_data + d*count) = *(src_data + d);
}
+ src_data += src_depth;
dst_data++;
}
}
@@ -86,58 +87,59 @@ void iDoChangePacking(const T* src_data, T* dst_data, int width, int height, int
{
for (int i = 0; i < count; i++)
{
- for (int d = 0; d < depth; d++)
+ for (int d = 0; d < src_depth; d++)
{
- *dst_data++ = *(src_data + d*count);
+ *(dst_data + d) = *(src_data + d*count);
}
+ dst_data += dst_depth;
src_data++;
}
}
}
-void imConvertPacking(const void* src_data, void* dst_data, int width, int height, int depth,
+void imConvertPacking(const void* src_data, void* dst_data, int width, int height, int src_depth, int dst_depth,
int data_type, int src_is_packed)
{
switch(data_type)
{
case IM_BYTE:
- iDoChangePacking((const imbyte*)src_data, (imbyte*)dst_data, width, height, depth, src_is_packed);
+ iDoChangePacking((const imbyte*)src_data, (imbyte*)dst_data, width, height, src_depth, dst_depth, src_is_packed);
break;
case IM_USHORT:
- iDoChangePacking((const imushort*)src_data, (imushort*)dst_data, width, height, depth, src_is_packed);
+ iDoChangePacking((const imushort*)src_data, (imushort*)dst_data, width, height, src_depth, dst_depth, src_is_packed);
break;
case IM_INT:
- iDoChangePacking((const int*)src_data, (int*)dst_data, width, height, depth, src_is_packed);
+ iDoChangePacking((const int*)src_data, (int*)dst_data, width, height, src_depth, dst_depth, src_is_packed);
break;
case IM_FLOAT:
- iDoChangePacking((const float*)src_data, (float*)dst_data, width, height, depth, src_is_packed);
+ iDoChangePacking((const float*)src_data, (float*)dst_data, width, height, src_depth, dst_depth, src_is_packed);
break;
case IM_CFLOAT:
- iDoChangePacking((const imcfloat*)src_data, (imcfloat*)dst_data, width, height, depth, src_is_packed);
+ iDoChangePacking((const imcfloat*)src_data, (imcfloat*)dst_data, width, height, src_depth, dst_depth, src_is_packed);
break;
}
}
-static void iImageMakeGray(imbyte *map, int count, int step)
+static void iImageMakeGray(imbyte *map, int gldepth, int count)
{
for(int i = 0; i < count; i++)
{
if (*map)
*map = 255;
- map += step;
+ map += gldepth;
}
}
-static void iImageGLCopyMapAlpha(imbyte *map, imbyte *gldata, int depth, int count)
+static void iImageGLCopyMapAlpha(imbyte *map, imbyte *gldata, int gldepth, int count)
{
/* gldata can be GL_RGBA or GL_LUMINANCE_ALPHA */
- gldata += depth-1; /* position at first alpha */
+ gldata += gldepth-1; /* position at first alpha */
for(int i = 0; i < count; i++)
{
*gldata = *map;
map++;
- gldata += depth; /* skip to next alpha */
+ gldata += gldepth; /* skip to next alpha */
}
}
@@ -172,10 +174,10 @@ static void iImageGLSetTranspMap(imbyte *map, imbyte *gldata, int count, imbyte
}
}
-static void iImageGLSetTranspIndex(imbyte *map, imbyte *gldata, int depth, int count, imbyte index)
+static void iImageGLSetTranspIndex(imbyte *map, imbyte *gldata, int gldepth, int count, imbyte index)
{
/* gldata can be GL_RGBA or GL_LUMINANCE_ALPHA */
- gldata += depth-1; /* position at first alpha */
+ gldata += gldepth-1; /* position at first alpha */
for(int i = 0; i < count; i++)
{
if (*map == index)
@@ -184,7 +186,7 @@ static void iImageGLSetTranspIndex(imbyte *map, imbyte *gldata, int depth, int c
*gldata = 255; /* opaque */
map++;
- gldata += depth; /* skip to next alpha */
+ gldata += gldepth; /* skip to next alpha */
}
}
@@ -194,6 +196,46 @@ static void iImageGLSetTranspIndex(imbyte *map, imbyte *gldata, int depth, int c
#define GL_LUMINANCE 0x1909
#define GL_LUMINANCE_ALPHA 0x190A
+imImage* imImageCreateFromOpenGLData(int width, int height, int glformat, const void* gldata)
+{
+ int color_space, has_alpha, depth;
+ imImage* image;
+
+ switch(glformat)
+ {
+ case GL_RGBA:
+ color_space = IM_RGB;
+ has_alpha = 1;
+ depth = 4;
+ break;
+ case GL_RGB:
+ color_space = IM_RGB;
+ has_alpha = 0;
+ depth = 3;
+ break;
+ case GL_LUMINANCE_ALPHA:
+ color_space = IM_GRAY;
+ depth = 2;
+ has_alpha = 1;
+ default: /* GL_LUMINANCE */
+ color_space = IM_GRAY;
+ depth = 1;
+ has_alpha = 0;
+ break;
+ }
+
+ image = imImageCreate(width, height, color_space, IM_BYTE);
+ if (!image)
+ return NULL;
+
+ if (has_alpha)
+ imImageAddAlpha(image);
+
+ imConvertPacking(gldata, image->data[0], image->width, image->height, depth, depth, IM_BYTE, 1);
+
+ return image;
+}
+
void* imImageGetOpenGLData(const imImage* image, int *format)
{
if (!imImageIsBitmap(image))
@@ -221,61 +263,73 @@ void* imImageGetOpenGLData(const imImage* image, int *format)
break;
case IM_BINARY:
default: /* IM_GRAY */
- if (image->has_alpha || transp_index)
+ if (image->has_alpha || transp_map || transp_index)
glformat = GL_LUMINANCE_ALPHA;
else
glformat = GL_LUMINANCE;
break;
}
- int depth;
+ int gldepth;
switch (glformat)
{
case GL_RGB:
- depth = 3;
+ gldepth = 3;
break;
case GL_RGBA:
- depth = 4;
+ gldepth = 4;
break;
case GL_LUMINANCE_ALPHA:
- depth = 2;
+ gldepth = 2;
break;
default: /* GL_LUMINANCE */
- depth = 1;
+ gldepth = 1;
break;
}
- int size = image->count*depth;
+ int size = image->count*gldepth;
imImageSetAttribute(image, "GLDATA", IM_BYTE, size, NULL);
imbyte* gldata = (imbyte*)imImageGetAttribute(image, "GLDATA", NULL, NULL);
- if (image->color_space == IM_RGB)
+ int depth = image->depth;
+ if (image->has_alpha)
+ depth++;
+
+ /* copy data, including alpha */
+ if (image->color_space != IM_MAP)
{
- if (image->has_alpha)
- imConvertPacking(image->data[0], gldata, image->width, image->height, 4, IM_BYTE, 0);
- else
- {
- imConvertPacking(image->data[0], gldata, image->width, image->height, 3, IM_BYTE, 0);
+ imConvertPacking(image->data[0], gldata, image->width, image->height, depth, gldepth, IM_BYTE, 0);
- if (transp_color)
- iImageGLSetTranspColor(gldata, image->count, *(transp_color+0), *(transp_color+1), *(transp_color+2));
- }
+ if (image->color_space == IM_BINARY)
+ iImageMakeGray(gldata, gldepth, image->count);
}
else
{
- memcpy(gldata, image->data[0], image->size);
+ /* copy map data */
+ memcpy(gldata, image->data[0], image->size); /* size does not include alpha */
- if (image->color_space == IM_MAP)
- imConvertMapToRGB(gldata, image->count, depth, 1, image->palette, image->palette_count);
- else if (image->color_space == IM_BINARY)
- iImageMakeGray(gldata, image->count, (glformat==GL_LUMINANCE_ALPHA)? 2: 1);
+ /* expand MAP to RGB or RGBA */
+ imConvertMapToRGB(gldata, image->count, gldepth, 1, image->palette, image->palette_count);
if (image->has_alpha)
- iImageGLCopyMapAlpha((imbyte*)image->data[1], gldata, depth, image->count);
- else if (transp_map)
- iImageGLSetTranspMap((imbyte*)image->data[0], gldata, image->count, transp_map, transp_count);
- else if (transp_index)
- iImageGLSetTranspIndex((imbyte*)image->data[0], gldata, depth, image->count, *transp_index);
+ iImageGLCopyMapAlpha((imbyte*)image->data[1], gldata, gldepth, image->count); /* copy the alpha plane */
+ }
+
+ /* set alpha based on attributes */
+ if (!image->has_alpha)
+ {
+ if (image->color_space == IM_RGB)
+ {
+ if (transp_color)
+ iImageGLSetTranspColor(gldata, image->count, *(transp_color+0), *(transp_color+1), *(transp_color+2));
+ }
+ else
+ {
+ if (transp_map)
+ iImageGLSetTranspMap((imbyte*)image->data[0], gldata, image->count, transp_map, transp_count);
+ else if (transp_index)
+ iImageGLSetTranspIndex((imbyte*)image->data[0], gldata, gldepth, image->count, *transp_index);
+ }
}
if (format) *format = glformat;
diff --git a/src/lua5/imlua_image.c b/src/lua5/imlua_image.c
index 5f84b97..b8bc1a8 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.12 2010/07/18 03:04:23 scuri Exp $
+ * $Id: imlua_image.c,v 1.13 2010/10/25 18:29:07 scuri Exp $
*/
#include <string.h>
@@ -119,6 +119,20 @@ static int imluaImageCreate (lua_State *L)
}
/*****************************************************************************\
+ im.ImageCreateFromOpenGLData(width, height, glformat, gldata)
+\*****************************************************************************/
+static int imluaImageCreateFromOpenGLData (lua_State *L)
+{
+ int width = luaL_checkint(L, 1);
+ int height = luaL_checkint(L, 2);
+ int glformat = luaL_checkint(L, 3);
+ void* gldata = lua_touserdata(L, 4);
+ imImage *image = imImageCreateFromOpenGLData(width, height, glformat, gldata);
+ imlua_pushimage(L, image);
+ return 1;
+}
+
+/*****************************************************************************\
image:AddAlpha()
\*****************************************************************************/
static int imluaImageAddAlpha (lua_State *L)
@@ -1014,6 +1028,7 @@ static int imluaImage_index (lua_State *L)
static const luaL_reg imimage_lib[] = {
{"ImageCreate", imluaImageCreate},
+ {"ImageCreateFromOpenGLData", imluaImageCreateFromOpenGLData},
{"ImageDestroy", imluaImageDestroy},
{"FileImageLoad", imluaFileImageLoad},
{"FileImageLoadBitmap", imluaFileImageLoadBitmap},
diff --git a/src/lua5/imlua_palette.c b/src/lua5/imlua_palette.c
index 135fe9a..029374c 100644
--- a/src/lua5/imlua_palette.c
+++ b/src/lua5/imlua_palette.c
@@ -2,7 +2,7 @@
* \brief IM Lua 5 Binding
*
* See Copyright Notice in im_lib.h
- * $Id: imlua_palette.c,v 1.2 2010/06/11 17:43:52 scuri Exp $
+ * $Id: imlua_palette.c,v 1.3 2010/10/25 18:29:07 scuri Exp $
*/
#include <string.h>
@@ -91,7 +91,7 @@ static int imluaPaletteCreate(lua_State *L)
static int imluaPaletteFindNearest (lua_State *L)
{
imluaPalette *pal = imlua_checkpalette(L, 1);
- long color = (long int) lua_touserdata(L, 1);
+ long color = (long)lua_touserdata(L, 1);
lua_pushnumber(L, imPaletteFindNearest(pal->color, pal->count, color));
return 1;
@@ -103,7 +103,7 @@ static int imluaPaletteFindNearest (lua_State *L)
static int imluaPaletteFindColor (lua_State *L)
{
imluaPalette *pal = imlua_checkpalette(L, 1);
- long color = (long) lua_touserdata(L, 2);
+ long color = (long)lua_touserdata(L, 2);
unsigned char tol = (unsigned char)luaL_checkint(L, 3);
lua_pushnumber(L, imPaletteFindColor(pal->color, pal->count, color, tol));
@@ -241,7 +241,7 @@ static int imluaPaletteUniform (lua_State *L)
\*****************************************************************************/
static int imluaPaletteUniformIndex (lua_State *L)
{
- lua_pushnumber(L, imPaletteUniformIndex((long int) lua_touserdata(L, 1)));
+ lua_pushnumber(L, imPaletteUniformIndex((long)lua_touserdata(L, 1)));
return 1;
}
@@ -250,7 +250,7 @@ static int imluaPaletteUniformIndex (lua_State *L)
\*****************************************************************************/
static int imluaPaletteUniformIndexHalftoned (lua_State *L)
{
- long color = (long) lua_touserdata(L, 1);
+ long color = (long)lua_touserdata(L, 1);
int x = luaL_checkint(L, 2);
int y = luaL_checkint(L, 3);
@@ -321,7 +321,7 @@ static int imluaPalette_newindex(lua_State *L)
if (!lua_islightuserdata(L, 3))
luaL_argerror(L, 3, "color must be a light user data");
- color_i = (long int) lua_touserdata(L, 3);
+ color_i = (long)lua_touserdata(L, 3);
pal->color[index_i] = color_i;
return 0;
diff --git a/src/lua5/imlua_util.c b/src/lua5/imlua_util.c
index 69cfb19..c07d920 100644
--- a/src/lua5/imlua_util.c
+++ b/src/lua5/imlua_util.c
@@ -2,7 +2,7 @@
* \brief IM Lua 5 Binding
*
* See Copyright Notice in im_lib.h
- * $Id: imlua_util.c,v 1.1 2008/10/17 06:16:32 scuri Exp $
+ * $Id: imlua_util.c,v 1.2 2010/10/25 18:29:07 scuri Exp $
*/
#include "im.h"
@@ -199,7 +199,7 @@ static int imlua_colorencode(lua_State *L)
{
int red_f, green_f, blue_f;
unsigned char red_i, green_i, blue_i;
- long int color_i;
+ long color_i;
red_f = luaL_checkint(L, 1);
green_f = luaL_checkint(L, 2);
@@ -228,13 +228,13 @@ static int imlua_colorencode(lua_State *L)
\***************************************************************************/
static int imlua_colordecode(lua_State *L)
{
- long int color_i;
+ long color_i;
unsigned char red_i, green_i, blue_i;
if (!lua_islightuserdata(L, 1))
luaL_argerror(L, 1, "color must be a light user data");
- color_i = (long int) lua_touserdata(L,1);
+ color_i = (long)lua_touserdata(L,1);
imColorDecode(&red_i, &green_i, &blue_i, color_i);
lua_pushnumber(L, red_i);
diff --git a/test/glut_capture.c b/test/glut_capture.c
index 80aadd2..b9a1779 100644
--- a/test/glut_capture.c
+++ b/test/glut_capture.c
@@ -152,7 +152,7 @@ void idle(void)
}
}
- imConvertPacking(image->data[0], gl_data, image->width, image->height, image->depth, image->data_type, 0);
+ imConvertPacking(image->data[0], gl_data, image->width, image->height, image->depth, image->depth, image->data_type, 0);
display();
}
}