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 Discussion / Fade image

Author
Message
BN2 Productions
20
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 3rd Feb 2009 19:47
Just had this idea the other day for how to create an image fading function. Worked it out here it is. Would like some feedback. I have noticed though that it can get REALLY slow with larger images (the second image being 640x480). Any suggestions on how to deal with that?

The idea is that it takes the color of the pixel it is on from both pictures. Then using pic 1 as a base, it will change the color data based off a percent difference from the other. Like this:

Red1=rgbr(PIC1)
Red2=rgbr(PIC2)
red3=red1-(percent*(red1-red2))/100

For some reason it doesn't always like 100 though. Percent is noted by opacity (100 is fully visible and 0 is completely transparent).

here is the code:


I appreciate any advice or help given!

Great Quote:
"Time...LINE??? Time isn't made out of lines...it is made out of circles. That is why clocks are round!" -Caboose
Ashingda 27
16
Years of Service
User Offline
Joined: 15th Feb 2008
Location:
Posted: 3rd Feb 2009 20:22 Edited at: 3rd Feb 2009 20:25
When you do this line:

Change the /100 into /100.0 That should fix your problem.


[edit]

Ohh yeah nice function by the way, you dont mind if I use it would ya?
BN2 Productions
20
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 3rd Feb 2009 20:42
Nope not at all

Great Quote:
"Time...LINE??? Time isn't made out of lines...it is made out of circles. That is why clocks are round!" -Caboose
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 3rd Feb 2009 21:07
Not bad, but its been done over 4 years ago. :-p


http://forum.thegamecreators.com/?m=forum_view&t=32791&b=6

Your signature has been erased by a mod because it's larger than 600x120
Caleb1994
15
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 3rd Feb 2009 22:38
Um i'm getting a error :/
"Memory block position is not in range at line 43"

rgb1=memblock dword(1,12+4*(y*width2+x))


any ideas?
Ashingda 27
16
Years of Service
User Offline
Joined: 15th Feb 2008
Location:
Posted: 3rd Feb 2009 23:43
You get an error because the display mode is by default 16bit. You have to set it to 32bits. BN2 don't have a 16bit adaption yet.
BN2 Productions
20
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 4th Feb 2009 00:35
No, I haven't added 16 bit support just yet.

@Phaelex
Ahhh, didn't check there.

Great Quote:
"Time...LINE??? Time isn't made out of lines...it is made out of circles. That is why clocks are round!" -Caboose
Caleb1994
15
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 4th Feb 2009 17:31
oh ok thanks i'll try it a little later it looks very useful though
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 4th Feb 2009 18:21
Kenmo made a whole image library awhile back, tons of commands.

Your signature has been erased by a mod because it's larger than 600x120
TheComet
16
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 4th Feb 2009 18:41
Wouldn't it be faster if you load the image as a bitmap, use "fade bitmap" and get the image?

Nice function

TheComet

Peachy, and the Chaos of the Gems

Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 4th Feb 2009 19:38
Quote: "Not bad, but its been done over 4 years ago. :-p"

I'm not quite sure of the reason for discrediting BN2's function... unless I'm misreading the above quote and it's intentions were different.

We're all learning; and figuring out how to do something not directly obvious is worth some merit.

Quote: "Wouldn't it be faster if you load the image as a bitmap, use "fade bitmap" and get the image?"


Although I haven't tried the code yet, from the look of it, it seems to be an alpha blending routine. That means it mixes two pictures a pixel at a time to come up with another picture that is a cross-fade of the 2. The FADE BITMAP command is known to be notoriously slow - but even if it were faster, it doesn't perform a cross-fade of two images.

Enjoy your day.
Kevin Picone
21
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Australia
Posted: 5th Feb 2009 05:50 Edited at: 11th Aug 2010 22:33
Quote: "have noticed though that it can get REALLY slow with larger images (the second image being 640x480). Any suggestions on how to deal with that?"


Well, this is really the nature of beast. There's some redundant calculations being made in the cross fader inner loop. So you could possibly win some performance back by rearranging the structure of the loops. Namely by moving any calc's that are 'constant' for the scan line, outside of the inner X loop and into the Y loop..

Some examples could be,

*) move stuff like newy=y-ypos outside of the X loop since y is constant for the span.

*) Rather than fully calculate the pixel address inside each time the pixel is accessed. Precalc the address at the start of the row, than BUMP this address each iteration. This type of thing will save you a lot of calc's per iteration.

ie. This sort of thing.



*) The mem bank size never changes during the loop so you could precache the SIZE into a variable. This avoids calling the get memblock size(2) function each iteration.

While on the subject, you can remove the BankSize sanity test completely by pre-clipping the Row length (addresses). By that I mean, if you make sure the X loops width will never overrun the either buffers width, this would make checking for overflows inside the loop redundant. So it can be removed.

* The compare if rgb2<>0, could simply be if rgb2. Since the compare will consider zero to be false and any other value to be true.


Could also Precalc the end of span in the inner for next loop. Although DB Classic might do this already, but Dbpro doesn't.


These type of opt's will help. But for big images i'd look into pre-calc of the blending. My gut feeling is the a 2D array might be best option in DB classic. But that's just a hunch. Can't test it, don't DB installed on this machine.

Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 5th Feb 2009 15:56
Quote: "I'm not quite sure of the reason for discrediting BN2's function... unless I'm misreading the above quote and it's intentions were different."


Wasn't trying to discredit, just letting him know there's existing code with additional image functions already floating out there.

Your signature has been erased by a mod because it's larger than 600x120
Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 5th Feb 2009 19:20
That's good. The way I first read it sounded a bit strange to me - unlike your usual helpfulness.

Enjoy your day.

Login to post a reply

Server time is: 2024-05-17 05:51:18
Your offset time is: 2024-05-17 05:51:18