copying data from a texture to my mem address?

i’m trying to copy the heightmap data (brightess of each pixel in grayscale image) of a geomipterrain to a specific memory address -
to be used by external DLL to calculate height and normal data, because the current methods of geomipterrain don’t produce accurate data, and python calculation is not very fast.
the DLL is imported by ctypes.

is there a way to copy data in batch?
these methods are what i want to avoid:

  1. write to an uncompressed file in panda,then load the file into memory in the DLL.
  2. keep an uncompressed texture file on disk.
  3. reading brightness of each pixel, and pass small amount of data (counting in bytes) to DLL by each loop of calls.

with ctypes, i can pass pointers or values as arguments. only passing pointers is the efficient way for such amount of data(1025x1025 bytes or 513x513 bytes).

You can use heightfield() to get a copy of the underlying PNMImage object, from which you can extract the necessary information. Depending on the value of the image’s maxval (255 or 65535), this may be 8-bits or 16-bits.

Or is that not what you were asking? You can also extract the data in string format via various means.

i know about heightfield() function in geomipterrain, and getbright()function in PNMImage, or other functions that extract color values.
but getbright() can only get 1 pixel per call.

what i need is a way to get the data in large batch in a single call. such as, a image contains brightness value:
byte0…byte1024
100,200,1,32,255,0,20…50,255,0,80

i want the data transfered to a memory address(my heap), such as 0x0f000000. then i can process the data from my DLL.

i don’t know how to use string functions. i read about write() functions in PNMImage and Texture, they mention ostream output. but the API reference about ostream is not very detailed.

i need a pointer(in C sense, not NodePath of Panda) that points to the byte data, then i can copy the data into my heap with my function imported by ctypes.

You could use write() to write the data in RGB format to a stringstream, then call str() on it to get the underlying string, then c_str() and size() on that to get a char* pointer and the number of bytes.

Alternatively, you can load the data into a Texture and use get_ram_image() to get a pointer to the actual image data.

thanks, i’ll try.