How to change/get pixel of image, put_pixel, get_pixel deprecated?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Charles Woodhill
:warning: Old Version Published before Godot 3 was released.

hi,
how to change a pixel of an image?
Image::put_pixel, get_pixel seems to be deprecated.
is there an alternative?
(c++)

(EDITED)

I don’t see a clear way of doing it in the current Image class (Godot 3.0), and it’s certainly because it can have multiple formats (RGBA 8 bit, RF float, RGB 8 bit…).
So I would like to know what’s the best way to set individual pixels on that too.

Zylann | 2017-03-25 20:58

So no way to edit an image or texture anymore?
Because i used it to manipulate a texture at runtime,
needed this to change my splatmaps alphaTexture in my terrain.

EDIT: I will give it a try tomorrow, maybe i can hack something out of the old one :slight_smile:
also get_pixel vanquished :frowning:

Charles Woodhill | 2017-03-25 22:34

In theory using GPU painting (basically drawing stuff on a render texture) instead of CPU painting could be a way to paint on the splatmap too, but I’m not sure how easy it is with the current Godot API.

Zylann | 2017-03-26 01:55

:bust_in_silhouette: Reply From: Charles Woodhill

ok played around abit,
for all who need get_pixel again until (i hope) its implemented again.

workaround to get the pixels raw data (putpixel can be similar done):
i added a member to image-class (since _get_pixelb is private ) :

void Image::get_pixel_raw(int p_x, int p_y, uint8_t * p_dst, uint32_t &p_pixelsize)
{

	uint32_t pixel_size = get_format_pixel_size(format);
	if (p_pixelsize != pixel_size)
	{
		ERR_PRINT("Image.get_pixel_raw: pixelSize different");
		ERR_FAIL();
	}

	PoolVector<uint8_t>::Read r = data.read();

	_get_pixelb(p_x, p_y, pixel_size, r.ptr(), p_dst);

}

and use it like this:

uint32_t pixelSize = img.get_format_pixel_size(Image::FORMAT_RGBA8);

	// TODO: create my "GRAY16" format again, to be able to load geoData
	if (img.get_format() != Image::FORMAT_RGBA8)
	{
		ERR_PRINT("Only RGBA8 supported yet")
			ERR_FAIL();
	}

	int width = img.get_width();
	int height = img.get_height();

	union sPixel { struct sPixelRGBA { uint8_t r; uint8_t g; uint8_t b; uint8_t a; } values; uint8_t data[4]; };
	sPixel pixel;

	PoolVector<real_t>::Write w = heights.write();
	for (int y = 0; y < height; y++)
	{
		for (int x = 0; x < width; x++)
		{
			
			img.get_pixel_raw(x, y,pixel.data, pixelSize);
			w[getVectorIndex(x, y)] = pixel.values.r;
		}
	}

but be aware of: [3.0] Image::_get_pixelb bugged? · Issue #8158 · godotengine/godot · GitHub