Hi again, I'm struggling to get a really strange typedef working in Cython. The original C (preprocessor) code looks like this:
#define IW_CTAB_SIZE 256
typedef guchar (*iwColtab)[3];
extern iwColtab iw_def_col_tab;
/* Color formats of the data for prev_render...() */
#define IW_RGB ((iwColtab)0)
// some more formats
#define IW_BW ((iwColtab)7)
#define IW_GRAY IW_BW
#define IW_INDEX (iw_def_col_tab)
#define IW_COLFORMAT_MAX IW_BW /* last 'special' definition */
The purpose of this strange construct was that one can use normal color
spaces without struggling, but one is also able to use a custom color table.
This definition was originally used like this:
void prev_colConvert (iwColtab ctab, gint r, gint g, gint b,
gint *rd, gint *gd, gint *bd)
{
if (ctab == IW_RGB) {
*rd = r;
*gd = g;
*bd = b;
} else if (ctab == IW_BGR) {
*rd = b;
*gd = g;
*bd = r;
} else if (ctab > IW_COLFORMAT_MAX && r>=0 && r < IW_CTAB_SIZE){
*rd = ctab[r][0];
*gd = ctab[r][1];
*bd = ctab[r][2];
}
}
I need to be able to do the same thing in cython with this definition.
My current approach was simply using a enum to emulate it:
cdef extern from "gui/Gimage.h":
ctypedef enum iwColtab:
IW_RGB
# ...
IW_GRAY
IW_CTAB_SIZE
IW_COLFORMAT_MAX
The normal color modes work like this, but using the color table doesn't
work:
Error converting Pyrex file to C:
------------------------------------------------------------
...
elif ctab == IW_YUV:
return Color(1.164 * (r - 16) + 1.596 * (b - 128),
1.164 * (r - 16) - 0.813 * (b - 128) - 0.391 * (g -
128),
1.164 * (r - 16) + 2.018 * (g - 128))
elif (ctab > IW_COLFORMAT_MAX and r >= 0 and r < IW_CTAB_SIZE):
return Color(ctab[r][0], ctab[r][1], ctab[r][2])
^
------------------------------------------------------------
image_utils.pyx:144:25: Attempting to index non-array type 'iwColtab'
I really have no idea how to solve this. Has anyone got a solution for this?
Thanks for the help
Johannes
signature.asc
Description: OpenPGP digital signature
_______________________________________________ Cython-dev mailing list [email protected] http://codespeak.net/mailman/listinfo/cython-dev
