glist, GValue, GTypes?



Hello,

I would like to use the glib as a foundation for some image processing
routines. The fundamental problem of imageprocessing is, that you have 
to deal with different data types. So I defined the following structs
for an image

typedef struct _Image Image;
struct _Image {
  int ndim;
  int veclen;
  int type;
  int *dimension;
  int size;
  
  union {
    ubyte	*data_ubyte;
    float	*data_float;
    double	*data_double;
    int		*data_int;
    short	*data_short;
    complex	*data_complex;
    pointer	*data_pointer;
  } data_union;

  union {
    ubyte	data_ubyte;
    float	data_float;
    double	data_double;
    int		data_int;
    short	data_short;
    complex	data_complex;
    pointer	data_pointer;
  } data_union_thresh;
};

typedef struct _Image_double Image_double;
struct _Image_double {
  int ndim;
  int veclen;
  int type;
  int *dimension;
  int size;

  double *data;
  double thresh;
};

If I know the image type I can cast a generic Image to the appropriate 
type and can extract the elements from the image.

To extract a value from a compile time unknown image type I have a
functions that extract a data_union based on the type field. 

Now I want to switch to glib, and I thought to use the GValue union as 
my data_union type. But the GValue field defines v_float as a gdouble
or a v_int as a gulong. I know most compilers handle floats as doubles 
and the on most systems the size of int is the same as the size of a
long. Can you explain the reason for this to me. 

Second, I would like to use defines or enums like GINT, GDOUBLE,
GFLOAT, ... to switch between the different cases. Shouldn´t there be
a GTypes type in glib.h which enums all types declared in glib.h, like

Dirk



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]