Jump to content




How to overlay one paintutils image over another


  • You cannot reply to this topic
2 replies to this topic

#1 LDDestroier

  • Members
  • 1,095 posts
  • LocationACDC Town

Posted 11 April 2016 - 02:06 PM

I'm trying to write a function to overlay one picture (using the paintutils.loadImage format, not PAIN) over another, to reduce flickering. Here's what I got so far:
Spoiler

But, it seems to erase all pixels in output that are left of the corresponding pixels in img1. I'm doing this for a game. Help?

#2 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 11 April 2016 - 02:40 PM

Here's the source of paintutils.drawImage() - note that #tImage and #tLine don't evaluate as "the highest index in those tables", but rather as "the highest index before the first nil value is encountered".

More to the point, also note that "leave this pixel blank" isn't always represented by a nil value, but also by the number 0.

#3 LDDestroier

  • Members
  • 1,095 posts
  • LocationACDC Town

Posted 11 April 2016 - 03:08 PM

Never mind, I found out how.
function mixImages(img1,img2)
    local output = img1
    for a = 1, #img2 do
	    if img2[a] then
		    for b = 1, #img2[a] do
			    if not output[a] then output[a] = {} end
			    if not img1[a] then
				    output[a][b] = img2[a][b]
			    elseif (not img1[a][b]) or (img1[a][b] == 0) then
				    output[a][b] = img2[a][b]
			    end
		    end
	    end
    end
    return output
end






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users