diff options
-rw-r--r-- | html/en/history.html | 5 | ||||
-rw-r--r-- | include/im_attrib.h | 4 | ||||
-rw-r--r-- | include/im_attrib_flat.h | 1 | ||||
-rw-r--r-- | include/im_image.h | 10 | ||||
-rw-r--r-- | src/im.def | 1 | ||||
-rw-r--r-- | src/im_attrib.cpp | 16 | ||||
-rw-r--r-- | src/im_image.cpp | 24 | ||||
-rw-r--r-- | src/lua5/imlua_image.c | 15 |
8 files changed, 71 insertions, 5 deletions
diff --git a/html/en/history.html b/html/en/history.html index 525cfe0..4ed4c30 100644 --- a/html/en/history.html +++ b/html/en/history.html @@ -26,8 +26,11 @@ <h2>History of Changes</h2> <h3 dir="ltr"> - CVS (19/Jan/2011)</h3> + CVS (04/Apr/2011)</h3> <ul dir="ltr"> + <li dir="ltr"><span class="hist_new">New:</span><span style="color: #008000"><span + style="color: #000000"> + function <strong>imImageMergeAttributes.</strong></span></span></li> <li dir="ltr"><span style="color: #008000"> <span style="color: #000000"> diff --git a/include/im_attrib.h b/include/im_attrib.h index 76302ef..f7d5b0e 100644 --- a/include/im_attrib.h +++ b/include/im_attrib.h @@ -45,6 +45,10 @@ public: void CopyFrom(const imAttribTable& table) { imAttribTableCopyFrom(ptable, table.ptable); } + /** Merges the contents of the given table into this table. */ + void MergeFrom(const imAttribTable& table) + { imAttribTableMergeFrom(ptable, table.ptable); } + /** Inserts an attribute into the table. \n * If data_type is BYTE then count can be -1 to indicate a NULL terminated string. * Data is duplicated if not NULL, else data is initialized with zeros. diff --git a/include/im_attrib_flat.h b/include/im_attrib_flat.h index db6c2d8..8b5af2d 100644 --- a/include/im_attrib_flat.h +++ b/include/im_attrib_flat.h @@ -25,6 +25,7 @@ const void* imAttribTableGet(const imAttribTablePrivate* ptable, const char *nam void imAttribTableSet(imAttribTablePrivate* ptable, const char* name, int data_type, int count, const void* data); void imAttribTableUnSet(imAttribTablePrivate* ptable, const char *name); void imAttribTableCopyFrom(imAttribTablePrivate* ptable_dst, const imAttribTablePrivate* ptable_src); +void imAttribTableMergeFrom(imAttribTablePrivate* ptable_dst, const imAttribTablePrivate* ptable_src); void imAttribTableForEach(const imAttribTablePrivate* ptable, void* user_data, imAttribTableCallback attrib_func); imAttribTablePrivate* imAttribArrayCreate(int hash_size); diff --git a/include/im_image.h b/include/im_image.h index 6c1a084..bd13c24 100644 --- a/include/im_image.h +++ b/include/im_image.h @@ -136,12 +136,20 @@ void imImageCopy(const imImage* src_image, imImage* dst_image); void imImageCopyData(const imImage* src_image, imImage* dst_image); /** Copies the image attributes from src to dst. - * Includes the pallete when a MAP or GRAY image. + * Includes the pallete if defined in both images. * * \verbatim image:CopyAttributes(dst_image: imImage) [in Lua 5] \endverbatim * \ingroup imgclass */ void imImageCopyAttributes(const imImage* src_image, imImage* dst_image); +/** Merges the image attributes from src to dst. \n + * Attributes that exist in dst are not replaced. + * Doens NOT include the pallete. + * + * \verbatim image:MergeAttributes(dst_image: imImage) [in Lua 5] \endverbatim + * \ingroup imgclass */ +void imImageMergeAttributes(const imImage* src_image, imImage* dst_image); + /** Copy one image plane fom one image to another. \n * Images must have the same size and type. * @@ -109,6 +109,7 @@ EXPORTS imImageMatchSize imImageClear imImageCopyAttributes + imImageMergeAttributes imImageDestroy imImageGetAttributeList imImageReshape diff --git a/src/im_attrib.cpp b/src/im_attrib.cpp index 10d4599..b2809bb 100644 --- a/src/im_attrib.cpp +++ b/src/im_attrib.cpp @@ -2,7 +2,7 @@ * \brief Attributes Table * * See Copyright Notice in im_lib.h - * $Id: im_attrib.cpp,v 1.3 2009/08/22 04:31:04 scuri Exp $ + * $Id: im_attrib.cpp,v 1.4 2011/04/04 20:42:47 scuri Exp $ */ #include <stdlib.h> @@ -305,6 +305,20 @@ void imAttribTableCopyFrom(imAttribTablePrivate* ptable_dst, const imAttribTable imAttribTableForEach(ptable_src, (void*)ptable_dst, iCopyFunc); } +static int iMergeFunc(void* user_data, int index, const char* name, int data_type, int count, const void* data) +{ + (void)index; + imAttribTablePrivate* ptable = (imAttribTablePrivate*)user_data; + if (!imAttribTableGet(ptable, name, NULL, NULL)) + imAttribTableSet(ptable, name, data_type, count, data); + return 1; +} + +void imAttribTableMergeFrom(imAttribTablePrivate* ptable_dst, const imAttribTablePrivate* ptable_src) +{ + imAttribTableForEach(ptable_src, (void*)ptable_dst, iMergeFunc); +} + static int iCopyArrayFunc(void* user_data, int index, const char* name, int data_type, int count, const void* data) { (void)index; diff --git a/src/im_image.cpp b/src/im_image.cpp index 5f865f8..712de7f 100644 --- a/src/im_image.cpp +++ b/src/im_image.cpp @@ -2,7 +2,7 @@ * \brief Image Manipulation * * See Copyright Notice in im_lib.h - * $Id: im_image.cpp,v 1.7 2010/01/17 18:18:12 scuri Exp $ + * $Id: im_image.cpp,v 1.8 2011/04/04 20:42:47 scuri Exp $ */ #include <stdlib.h> @@ -424,6 +424,28 @@ void imImageCopyAttributes(const imImage* src_image, imImage* dst_image) iAttributeTableCopy(src_image->attrib_table, dst_image->attrib_table); } +static void iAttributeTableMerge(const void* src_attrib_table, void* dst_attrib_table) +{ + const imAttribTable* src_table = (const imAttribTable*)src_attrib_table; + imAttribTable* dst_table = (imAttribTable*)dst_attrib_table; + dst_table->MergeFrom(*src_table); +} + +void imImageMergeAttributes(const imImage* src_image, imImage* dst_image) +{ + assert(src_image); + assert(dst_image); + + if (src_image->palette && dst_image->palette && + src_image->color_space == dst_image->color_space) + { + memcpy(dst_image->palette, src_image->palette, 256*sizeof(long)); + dst_image->palette_count = src_image->palette_count; + } + + iAttributeTableMerge(src_image->attrib_table, dst_image->attrib_table); +} + static int iAttribCB(void* user_data, int index, const char* name, int data_type, int count, const void* data) { (void)data_type; diff --git a/src/lua5/imlua_image.c b/src/lua5/imlua_image.c index b8bc1a8..057e757 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.13 2010/10/25 18:29:07 scuri Exp $ + * $Id: imlua_image.c,v 1.14 2011/04/04 20:42:48 scuri Exp $ */ #include <string.h> @@ -546,6 +546,18 @@ static int imluaImageCopyAttributes (lua_State *L) } /*****************************************************************************\ + image:MergeAttributes(dst_image) +\*****************************************************************************/ +static int imluaImageMergeAttributes (lua_State *L) +{ + imImage *src_image = imlua_checkimage(L, 1); + imImage *dst_image = imlua_checkimage(L, 2); + + imImageMergeAttributes(src_image, dst_image); + return 0; +} + +/*****************************************************************************\ image:MatchSize(image2) \*****************************************************************************/ static int imluaImageMatchSize (lua_State *L) @@ -1056,6 +1068,7 @@ static const luaL_reg imimage_metalib[] = { {"SetPalette", imluaImageSetPalette}, {"GetPalette", imluaImageGetPalette}, {"CopyAttributes", imluaImageCopyAttributes}, + {"MergeAttributes", imluaImageMergeAttributes}, {"MatchSize", imluaImageMatchSize}, {"MatchColor", imluaImageMatchColor}, {"MatchDataType", imluaImageMatchDataType}, |