Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Any plugin for fast image to image pasting?

Author
Message
Fallout
23
Years of Service
User Offline
Joined: 1st Sep 2002
Location: Basingstoke, England
Posted: 18th Sep 2012 15:58
I remember someone telling me about a good 2D manipulation plugin made by the community, but can't seem to find the post about it.

What I need to be able to do is paste a small image onto a larger image, complete with working transparency. So I have my character skin image, and I am pasting a load of wound images onto it (potentially over 100 in a single frame). The transparency blending around the outside of the wound images needs to be preserved as it's pasted onto the skin.

So far I am using a memblock based approach. It's been working fine, but I'm just moving onto large damage scenarios for multiple enemies (i.e. blowing 10 people up at the same time with a grenade!) and I get half a second delay as the wounds are drawn.

Anyone know of a suitable plugin, paid or free?

TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 18th Sep 2012 18:26
ImageKit V2 by Sven B

TheComet

"Why geeks like computers: unzip, strip, touch, finger, grep, mount, fsck, more, yes, fsck, fsck, fsck, umount, sleep." - Unknown
Fallout
23
Years of Service
User Offline
Joined: 1st Sep 2002
Location: Basingstoke, England
Posted: 18th Sep 2012 18:55
That was the one mentioned before. Cheers for that. I looked at image kit briefly in a search but for some reason didn't think it was the one. Now it's open source, I might be able to learn from it and change it into something to suit my project exactly. Massive props to SvenB!

Cheers for the link mr Comet.

Mage
Valued Member
19
Years of Service
User Offline
Joined: 3rd Feb 2007
Location:
Posted: 19th Sep 2012 04:37
I did this without the need of a plugin. You have 2 images, run the function and no fuss one image is layered onto the other.

This code was done years ago, so you might decide to tweak it a little. On a quick look, "Width" in the function call does absolutely nothing for example. But the code is simple to use and works really well.

http://forum.thegamecreators.com/?m=forum_view&t=107662&b=1

WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 19th Sep 2012 07:17 Edited at: 19th Sep 2012 07:17
Depending on how fast you actually need it, I did a function that pasted an image to another image a while ago using just assembly code and was lightning fast. However, at the time I didn't require any blending functionality or alpha processing.

If you are interested, and need that extra boost then I could write one that will handle any blending you need or alpha processing and do it in assembler for any comparisons.

I'll do it for 'free' too. Just gives me something to do...

Mental arithmetic? Me? (That's for computers) I can't subtract a fart from a plate of beans!
Warning! May contain Nuts!
Fallout
23
Years of Service
User Offline
Joined: 1st Sep 2002
Location: Basingstoke, England
Posted: 19th Sep 2012 09:51
@Mage - That's exactly the technique I'm currently using. Our code blocks are spookily similar. It's the actual conversion from memblock back to a texture which is the bottleneck though, although I have some ideas for optimisation that I'm going to try out today.

@WLGfx - Thanks for that offer matey. That's very kind. Someone else has actually offered the same thing though and is currently looking at it, so best not to duplicate effort. I appreciate the offer though!

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 19th Sep 2012 12:36
@WLGfx

Quote: "If you are interested, and need that extra boost then I could write one that will handle any blending you need or alpha processing and do it in assembler for any comparisons."


I'd be very interested in having a copy of that function. It's something I often want to do but haven't bothered because native DBP is too slow. I've wondered about using a procedural shader solution but a more direct solution using a function would be better.

Don't be alarmed if I don't reply for about 2 weeks - off on holiday tomorrow for some sun.
Van B
Moderator
23
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 19th Sep 2012 12:59
I would recommend trying ImageKit first - its very fast, and I've used it for decal stuff before, works really nicely. Of course, I'm not sure how it works with GDK, I'm just going by DBPro.

In fact, you could probably write a game that just uses images pasted onto a texture - like an arcade cabinet model with the screen textured... that'd be pretty cool I think... handy for things like score displays in your actual game world, like a big score board somewhere made from LED's, that sort of thing. Also, damage clothing by pasting alpha images, like the player might start with a nice clean t-shirt on, but by the end of the game, it might be splattered with blood, sweat, and even covered in holes, burns, frays, rips. Also ImageKit supports DOT, which is really fast, might be cool for dribbling blood - like start at a location on your texture and move towards the ground, drawing a red dot each time. I'm sure I've bugged you with this idea already.

Health, Ammo, and bacon and eggs!
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 19th Sep 2012 17:41
Sounds like it's time I tried IK. It would be interesting to compare it with a GPU shader solution as well.
Van B
Moderator
23
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 19th Sep 2012 17:51
Sure is GG

Especially the ability to paste normal map sprites about the place, for bullet holes and stuff.

Health, Ammo, and bacon and eggs!
Fallout
23
Years of Service
User Offline
Joined: 1st Sep 2002
Location: Basingstoke, England
Posted: 19th Sep 2012 18:39
The only problem with ImageKit is it's DBP only, so I'd have to do a small amount of working converting it to GDK.

Yes, I'm posting about a GDK game in the DBPro forum, but look at what you've all learnt in the process!

Btw Van, I will definitely explore those suggestions. I wanted to do the blood dribbling, but it's just striking the balance. Since my character models are usually viewed quite far away, I don't want to go OTT with detail people will never see.

WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 19th Sep 2012 19:47 Edited at: 19th Sep 2012 23:12
I first thought of IK too but as of yet I've never used it so I can't compare speed myself with even my old function. The idea I'll prob work on to start will just be to paste an image to an image using blending and/or alpha (with the use of assembler and the MMX for the boost). For the extra optimizations I'll just start with a 32 bit image format too. Maybe later I'll add other formats if required or asked for.

The simpler version I did only handled 32 bit images and accounted for clipping too.

Let you know when it's done and tested.

EDIT: I'll even leave the source code for it available.

EDIT2: Not wasting another post...

The simple function for fast pasting image to image which works a dream with clipping too without blending or alpha and only for 32 bit images:


And now that I'm very up on the MMX set the blending and alpha controls will be optimized too... Anyone can use this.

Mental arithmetic? Me? (That's for computers) I can't subtract a fart from a plate of beans!
Warning! May contain Nuts!
Mage
Valued Member
19
Years of Service
User Offline
Joined: 3rd Feb 2007
Location:
Posted: 20th Sep 2012 05:44 Edited at: 20th Sep 2012 06:23
Quote: "@Mage - That's exactly the technique I'm currently using. Our code blocks are spookily similar. It's the actual conversion from memblock back to a texture which is the bottleneck though, although I have some ideas for optimisation that I'm going to try out today."


This method isn't used very rapidly by me, so I can get away with using it. It's fast, just not each and every frame fast. It's definitely fast enough to stream content in during live play.

I also employ a very complicated system of managing loaded and merged images. It doesn't load or merge anything that is already in memory somewhere.

However this method doesn't support mipmaps. For some reason DBP retains the old mipmaps of the original image.


Some parts of clothing are layered over skin textures.

The quick fix was to disable mipmapping on layered bodies. But I'm planning to fix the issue soon. I didn't find any performance decrease turning off those few mipmaps, since the effect is only used on people, a small part of the scene. So low priority.

Let me know how you do with this because it'll probably help.

WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 20th Sep 2012 13:26 Edited at: 20th Sep 2012 15:54
@Green Gandalf - Just putting the dll and ini files together and I'll add it shortly after a quick test but this is the complete function so far:


I've cheated yet again for speed after finding a quicker algorithm that doesn't even need SSE/2. I'll put a test DBP program together and then post it up... Although as of yet I not checked but I can tell by looking at the ASM code that it is very CPU cache friendly...

I'm posting this snippet because you never know that it might be useful for something to learn from...

EDIT: So far it's 90% working, the clipping of the source image is out somewhere and I'm trying to find it...

Mental arithmetic? Me? (That's for computers) I can't subtract a fart from a plate of beans!
Warning! May contain Nuts!
WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 21st Sep 2012 20:33 Edited at: 21st Sep 2012 20:39
Fast pasting of an image to another image in DBP with Alpha and full clipping...

Attached is a test program and the dll.

The final working version of the paste function used (optimised with assembler):



I don't have Image Kit by Sven B, but if anyone could maybe compare that would be great. With the quick method I have used I've not needed any MMX/SSE instructions. The assembler optimisation took some time because as usual I had plenty of typos to fix...

Oh yeah, the DBP code to test this alpha pasting of images to other images:



Mental arithmetic? Me? (That's for computers) I can't subtract a fart from a plate of beans!
Warning! May contain Nuts!
Mage
Valued Member
19
Years of Service
User Offline
Joined: 3rd Feb 2007
Location:
Posted: 22nd Sep 2012 21:17
Quote: "Fast pasting of an image to another image in DBP with Alpha and full clipping..."


Thank you.

How is it's capability with merging images of differing sizes. Is this supported at all? If so which image defines the output images dimensions? What kind of scaling is used? Nearest Neighbor? Does the output image overlap one of the existing images or is a new image created?

WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 22nd Sep 2012 23:50 Edited at: 22nd Sep 2012 23:52
The input image is cropped to fit in the output images dimensions. If the input image is larger and/or negative coords are used then all the cropping is done within the function. The above function only works though with 32 bit images. Basically it pastes one image to another so both images have to exist.

@Fallout - The above function should be able to run with GDK too with very little tweaking at the beginning of it...

Mental arithmetic? Me? (That's for computers) I can't subtract a fart from a plate of beans!
Warning! May contain Nuts!

Login to post a reply

Server time is: 2026-07-08 00:25:59
Your offset time is: 2026-07-08 00:25:59