Weird PNG drawing??

Posted by Asmodeusbrooding on Wed 30 Aug 2023 11:58 PM — 3 posts, 9,967 views.

#0
Hey Nick,

I've got some weird behavior here with loading and drawing a png...

You can run this code in immediate if you want...

Any idea what's going on?


-- Create miniwindow
win_id = "myMiniWindow"
WindowCreate(win_id, 0, 0, 100, 100, 1, 1, 0xFFFFFF)

-- Load image into miniwindow
WindowLoadImage(win_id, "building", "worlds\plugins\images\building.png")

-- Get window dimensions
local win_width, win_height = WindowInfo(win_id, 14), WindowInfo(win_id, 15)

-- Draw image to fill the entire window
WindowDrawImage(win_id, "building", 0, 0, win_width, win_height, miniwin.image_stretch)

-- Display the miniwindow
WindowShow(win_id, true)


and the image can be found here
https://imgur.com/F7Dq4X5

Seems odd....

On top of this, every time it draws it changes.. I used it on a map and every single time the map reloaded the image shifted slightly and if you redrew it many times it looked animated.


Is this caused by the png not being 8 bit or 24 bit or something? I converted a bmp to png on another conversion website and the image worked OK. I'd love to learn about why this one didn't work though..
Amended on Thu 31 Aug 2023 12:21 AM by Asmodeusbrooding
USA Global Moderator #1
The image is 8 bit grey.

I wonder if either the calls to png_read_png from LoadPng and LoadPngMemory need to also include the PNG_TRANSFORM_GRAY_TO_RGB transform or the final bits per pixel needs to be made depth aware instead of choosing 24/32. The former seems safer.

See e.g.

https://github.com/nickgammon/mushclient/blob/5f1ca253cf6f44b65caeafd9f2ad7a4b87817c8e/Utilities.cpp#L3051-L3057

and

https://github.com/nickgammon/mushclient/blob/5f1ca253cf6f44b65caeafd9f2ad7a4b87817c8e/png/pngread.c#L1191-L1198
Amended on Thu 31 Aug 2023 10:35 AM by Fiendish
Australia Forum Administrator #2
That may well be the problem. If this is just one image try converting it to RGB with Gimp or some other program.