Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ MUSHclient ➜ Miniwindows ➜ quicker way to draw images

quicker way to draw images

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by Zimmy   (31 posts)  Bio
Date Mon 11 Nov 2019 05:27 AM (UTC)
Message
I have a miniwindow where I use DrawImage() to draw a bunch of little bmp images (directional arrows). I have around 50 of these to draw, although there are only 9 different bmps (everything is just a copy of one of these 9 bmps). The problem is it takes around .4 seconds to draw all the images, which is too slow. Is there a more efficient way to do this?
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #1 on Mon 11 Nov 2019 06:21 AM (UTC)
Message
Can you show your code please?

I can't suggest a more efficient way until I see your current way.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Zimmy   (31 posts)  Bio
Date Reply #2 on Mon 11 Nov 2019 07:02 AM (UTC)
Message
-- this is how I load them
file_path = (GetPluginInfo (GetPluginID (), 6)):match("^(.*\).*$")

local directions = {"n", "ne", "e", "se", "s", "sw", "w", "nw"}
for _, v in ipairs(directions) do
WindowLoadImage (win, v, file_path.."arrows\"..v..".bmp")
end
------------------------------------------------------
--below are the functions I use that draw them

local function give_direction(exit)
if exit == "n" then return 0, 1 end
if exit == "ne" then return 1, 1 end
if exit == "e" then return 1, 0 end
if exit == "se" then return 1, -1 end
if exit == "s" then return 0, -1 end
if exit == "sw" then return -1, -1 end
if exit == "w" then return -1, 0 end
if exit == "nw" then return -1, 1 end
end

local function draw_exit(x_pos, y_pos, exit_dir, arrow_dir, exit_colour)
x_dir, y_dir = give_direction(exit_dir)
local exit_center_x = mw_buffer_x + (x_pos*block_x) - (block_x/2) + ((room_width + exit_width)/2)*x_dir
local exit_center_y = mw_buffer_y + (y_pos*block_y) + ((room_height + exit_height)/2)*-y_dir

local x1 = exit_center_x - exit_width/2
local y1 = exit_center_y - exit_height/2
local x2 = exit_center_x + exit_width/2
local y2 = exit_center_y + exit_height/2

if arrow_dir then WindowDrawImage (win, arrow_dir, x1+2, y1+2, x2-2, y2-2, 2) end

WindowCircleOp (win, 2,
x1, y1, x2, y2,
ColourNameToRGB(exit_colour), 0, 1,
ColourNameToRGB("black"), miniwin.brush_null)
end

-- I commented out the WindowDragImage line and the code ran literally 100x faster. I emulate mush on wine, perhaps that's why I'm having performance issues?
Top

Posted by Fiendish   USA  (2,534 posts)  Bio   Global Moderator
Date Reply #3 on Mon 11 Nov 2019 07:04 PM (UTC)

Amended on Mon 11 Nov 2019 07:06 PM (UTC) by Fiendish

Message
Is it faster if you change the last 2 in your WindowDrawImage call to 1? You shouldn't be stretching the images.

https://github.com/fiendish/aardwolfclientpackage
Top

Posted by Zimmy   (31 posts)  Bio
Date Reply #4 on Mon 11 Nov 2019 07:40 PM (UTC)
Message
Fiendish said:

Is it faster if you change the last 2 in your WindowDrawImage call to 1? You shouldn't be stretching the images.


This is 10x faster. Is there a way to shrink the images when I load them so they'll be the right size? Even so, its still 10x slower than drawing no images. To be fair the images themselves are way bigger than they need to be.
Top

Posted by Fiendish   USA  (2,534 posts)  Bio   Global Moderator
Date Reply #5 on Mon 11 Nov 2019 10:41 PM (UTC)

Amended on Mon 11 Nov 2019 10:44 PM (UTC) by Fiendish

Message
Quote:
To be fair the images themselves are way bigger than they need to be.

Yeah. So make them smaller.

Quote:
Is there a way to shrink the images when I load them so they'll be the right size?

Yes. First make a new hidden miniwindow with the final size you want, then draw the image to that secret miniwindow stretched to fill it, and then make a new image in your real miniwindow from the contents of the hidden miniwindow using WindowImageFromWindow.

https://github.com/fiendish/aardwolfclientpackage
Top

Posted by Zimmy   (31 posts)  Bio
Date Reply #6 on Mon 11 Nov 2019 11:12 PM (UTC)
Message
Oh, I see. So I do a separate secret mini window for each image I plan on reusing. And I only need to do this once?
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #7 on Tue 12 Nov 2019 03:28 AM (UTC)
Message
Surely the simple way is to use ImageMagick to resize your images in advance? Why load the client up with this work? Resizing images is slow (comparatively) and should only be done once if you can help it.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Fiendish   USA  (2,534 posts)  Bio   Global Moderator
Date Reply #8 on Tue 12 Nov 2019 04:56 PM (UTC)

Amended on Tue 12 Nov 2019 04:57 PM (UTC) by Fiendish

Message
Yurt said:

Oh, I see. So I do a separate secret mini window for each image I plan on reusing. And I only need to do this once?

You only need to do this once. You can use the same secret miniwindow for all of your images. The secret miniwindow just gives you a place to stretch into and then copy out of.

But Nick is right. If you're not dynamically changing the size of your images, you should probably just update the actual images themselves.

https://github.com/fiendish/aardwolfclientpackage
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


20,239 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.