Help with array maniipulation

ollie ollie at home.net
Tue Feb 4 10:58:18 PST 2014


I have a C Struct:

   typedef struct
   {
       enum LibRaw_image_formats type; 
       ushort      height,
                   width,
                   colors,
                   bits;
       unsigned int  data_size; 
       unsigned char data[1]; 
   }libraw_processed_image_t;

with a D version:

   struct libraw_processed_image_t
   {
       LibRaw_image_formats    type; 
       ushort                  height,
                               width,
                               colors,
                               bits;
       uint                    data_size; 
       ubyte[1]                data; 
   }

libraw_dcraw_make_mem_thumb() returns a pointer to this struct.
I need to create a char[] from the data and data_size members,
ideally without copying, to send to GdkPixbufLoader.write(char[]).

If I do this:
   libraw_processed_image_t *img;
   img = libraw_dcraw_make_mem_thumb();
   char[] buf = cast(char[]) img.data[];
   GdkPixbufLoader.write(buf); // Runtime error

buf.ptr == img.data.ptr and length of both arrays is 1.
If I try:
   buf.length = img.data_size;
buf is reallocated.

Any suggestions to make buf.ptr == img.data.ptr and
buf.length = img.data_size?

Thanks
ollie


More information about the Digitalmars-d-learn mailing list