Re: [sdljava-users] Anyone using get/setPixelDataXX()?
Status: Beta
Brought to you by:
ivan_ganza
From: Rainer K. <ar...@gm...> - 2005-07-18 22:05:07
|
S. Meslin-Weber wrote: > Hi Ivan, > > On Tue, Jul 12, 2005 at 05:54:19PM -0400, Ivan Z. Ganza wrote: > >>Not a problem. I did not have time to properly test them, however, the >>code was actually still in the native layer from where I first coded >>that part , and I know it was working at that point. > > > Yup, it's back as it was... > > >>The reason for long instead of int is because that is how swig maps it. >> >> void SWIG_GetPixelData32(SDL_Surface *surface, Uint32 pixelData[]) > > > Argh. that's a huge bottleneck for me. I treat ints as uint32 as it is > (for AARRGGBB) and other libraries I use (VNCj notably) also use this > interpretation for int. > > >>For the above SWIG mapg the Uint32 to a long[]. I suppose we could add >>our own (additonal) method with takes an int[] and casts it to long[] >>calling the appropriate method (for conviencence). Not sure if that >>would cause any problems due to the cast. > > > No, it's not possible to cast int[] to long[]. I end up having to do the > following: > > long[] longs = new long[source.length]; > for (int i = 0; i < source.length; i++) { > longs[i] = source[i]; > } > SDLUtil.setPixelData32(screen, longs); > > You can imagine how expensive this can get :( I don't think that pushing > this to C is the answer. Perhaps SWIG needs fixing? Maybe there's nothing to fix. Java primitives are always signed so the range is not the same as the unsigned 32 bit int. Java Data Types: int 4 bytes, signed (two's complement). -2,147,483,648 to 2,147,483,647. Like all numeric types ints may be cast into other numeric types (byte, short, long, float, double). When lossy casts are done (e.g. int to byte) the conversion is done modulo the length of the smaller type. long 8 bytes signed (two's complement). Ranges from -9,223,372,036,854,775,808 to +9,223,372,036,854,775,807. C: uint8 0 to 255 Unsigned 8-bit integer 1 uint8 uint16 0 to 65535 Unsigned 16-bit integer 2 uint16 uint32 0 to 4,294,967,295 Unsigned 32-bit integer 4 uint32 |