Dynamic creation of the atlas in the script

~30 avatars, gui node type, 100X100
Thanks!

1 Like

I have it working, cleaning it up and then will release it.

Test images

https://i.imgur.com/iMPi3lq.png
https://i.imgur.com/Y8JhMoR.png
4 Likes

It would be easier if the images are a power of 2 due to how the textures work. I’ll have to do a test for that size…

DynamicAtlasNoBreakBatching.zip (460.1 KB)

Here is the ugly proof of concept so you can see how it works. I still need to clean it up, add proper offsetting, and make it work with irregular texture sizes. Right now the tiles are starting from the bottom left because it’s easier.

I can’t spend more time on it right now though but can finish it tomorrow. If anyone else feels like making the final production ready version before then please do. :pray:

4 Likes

Fine work, thank you!
Unfortunately, I can not use it - all social networks give out avatars in jpg format :joy:

You should be able to adapt the solution to work with jpg as well. The solution could likely be adapted to using image.load() instead (since it supports both png and jpg).

1 Like

image.load() gives the raw image data that has not yet been decoded to rgb yet I think? Or is that data ready to use but in a different way?

Working on this again now. JPG format will be supported.

image.load() gives you the decoded pixel data.

1 Like

Have irregular sizes working, tiles now start at top left, have offsets working properly.

A feature which would be nice to add after everything else is working is automatic edge extrusion support so the images don’t bleed into each other when scaled as they share the same texture space. If you have a frame around the avatar it’s not noticeable, but otherwise you can see a tile bleed into another.

3 Likes

For JPG / image.load() the raw data is in the Lua table instead of a Defold buffer. Would it be better to transfer the raw data into a Defold buffer after loading and then use that, or use the raw data directly?

Yes, image.load() returns a table with the image data and some meta data about the image

I guess it depends on what you want to do. There’s a benefit of having it as a buffer if you intend to pass it back and forth to some C code.

I’ll work with the raw data in Lua then.

Maybe there can be made a sister module to the PNG one for JPG that does direct Defold buffer creation.

1 Like

Switched to image.load() so now it should support any format that ends up supporting.

I suppose I need to flip the pixels, or grab the bytes in opposite order. It’s black and white too because of the wrong order?

string.reverse() worked to flip it correctly, but still in black and white?

Ah, it’s not actually flipped correctly…

My mistake I was only setting the red channel to each rgb when I changed over the code. The images do appear to be incorrectly flipped horizontally still…

There is a flip flag to gui.set_texture_data, could you give it a try?

I’m not using that, I’m setting the buffer directly.

Here is current code

https://github.com/subsoap/imagebatch/blob/master/example/avatar_controller.script

I disabled string.reverse() because I don’t think it’s the right solution.

Here’s what current version looks like

It does look like a vertical flip of the pixels is all that’s needed.

1 Like

I’m not sure how to flip the raw data properly. I guess you could flip the gui node too by setting its y scale to -1 but that’s not the most ideal solution…

Should image.load() have a flip flag?

Got image flipping working. I realized it could be done very easily… but it’s using strings so probably would be faster if it was done in an extension, or image.load() had a flip flag.

local function flip_image(image)

	local width = image.width
	local height = image.height

	local temp_buffer = ""
	local width_chunk = width * 3

	for i=1, height do
		local start = (i - 1) * width_chunk + 1
		local stop = start + width_chunk - 1
		temp_buffer = string.sub(image.buffer, start, stop) .. temp_buffer
	end

	return temp_buffer
end

Here I was off by 1 at the end until I did -1. And a few abominations from editing width_chunk to custom values…

2018-07-13%2009_34_31-ImageBatch2018-07-13%2009_34_22-ImageBatch2018-07-13%2009_29_48-ImageBatch2018-07-13%2009_27_43-ImageBatch

Now it’s time for the real cleanup and putting everything into a neat package.

5 Likes

Move out Test Driven Development, PDD is here - Pkeod Driven Development. :smiley:

5 Likes

The script currently is unavailable. Is there a newer version?

It’s all here https://github.com/subsoap/imagebatch/tree/master/imagebatch

5 Likes