Welcome Guest ( Log In | Register )

[ Big| Medium| Small] -



Post new topic Reply to topic  [ 6 posts ] 
    ForeverZer0
  Tue Feb 21, 2012 12:26 am
ARC Developer
User avatar
Sponsor


Location: United tates
I am trying to emulate a similar feature to that of RMXP's "blend_type" for the Sprite class, and I can't seem to get it quite right. I was curious, does anyone know the calculation that is performed to do the addition and subtraction blends on an image? I'm using C#, and have been getting familiar with the ColorMatrix class, have created functions for altering brightness, saturation, color blending, opacity, color shearing, contrast, etc., but fail at this seemingly simple function.

I am using for creating a small utility for RMXP, and it is kinda important that it is accurate to the method that RMXP uses. This is basically the final thing to implement, and I can finish up pretty quickly after that.

_________________
Use DropBox to upload your files. Much simpler than other upload sites, you can simply place a folder on your desktop that will sync with your DropBox account. ;)

Looking for a more powerful RMXP? Check out Image

My complete script list on Pastebin


Top Top
Profile      
 

    Kingdom Ablaze
  Wed Feb 22, 2012 12:34 pm
Smile, you never know when you are on camera!
User avatar



Location: Usa
in XNA its:
Expand to see the code.

if you want non-xna let me know

_________________
Image
Kingdom Ablaze Twitter: https://twitter.com/KingdomAblaze
Kingdom Ablaze Deviant Art: http://kingdomablaze.deviantart.com/
Kingdom Ablaze: Facebook: https://www.facebook.com/KingdomAblazeTradingCardGame


Top Top
Profile      
 

    Brewmeister
  Wed Feb 22, 2012 1:02 pm
Paste above Main
User avatar


lv 99 Balance Wizard

Location: 42.655713 N 82.619282 W
Here's a description of how PhotoShop does it...

Add and Subtract blending modes

The Add and Subtract blending modes are available only for the Apply Image and Calculations commands.

Add

Adds the pixel values in two channels. This is a good way to combine non-overlapping images in two channels.

Because higher pixel values represent lighter colors, adding channels with overlapping pixels lightens the image. Black areas in both channels remain black (0 + 0 = 0). White in either channel results in white (255 + any value = 255 or greater).

Add mode divides the sum of the pixel values by the Scale amount, and then adds the Offset value to the sum. For example, to find the average of the pixels in two channels, add them, divide by 2, and enter no Offset value.

The Scale factor may be any number between 1.000 and 2.000. Entering a higher Scale value darkens the image.

The Offset value lets you lighten or darken the pixels in the destination channel by any brightness value between +255 and –255. Negative values darken the image; positive values lighten the image.

Subtract

Subtracts the pixel values in the source channel from the corresponding pixels in the target channel. As with Add mode, the result is then divided by the Scale factor and added to the Offset value.

The Scale factor may be any number between 1.000 and 2.000. The Offset value lets you lighten or darken the pixels in the destination channel by any brightness value between +255 and –255.



I can only assume that RM applies it's own "Scaling Factor" & "Offset" to keep the combinations from getting too light or dark.

Try a couple tests with primary colors to determine the factors. (e.g. make a 50% pure red map, and add a 50% pure green sprite to it with both ADD & SUBTRACT modes. Capture the resulting image & analyze the pixels.)

_________________
"Of course that's just my opinion. I could be wrong!"


Image


Top Top
Profile      
 

    zeus81
  Wed Feb 22, 2012 6:47 pm
prout
User avatar
Member


Location: France
It's fairly simple :
Add :
buffer_pixel.red += sprite_pixel.red * sprite_pixel.alpha / 255 * sprite.opacity / 255
buffer_pixel.green += sprite_pixel.green * sprite_pixel.alpha / 255 * sprite.opacity / 255
buffer_pixel.blue += sprite_pixel.blue * sprite_pixel.alpha / 255 * sprite.opacity / 255
And results should be maintened between 0 and 255.

Substract :
same with -=

Blending is not something we can apply to the bitmap, we use it when merging all the sprites for the display.
Anyway I don't know wich library you use but usally you have builtin functions for that.

_________________
>> The Ark of Gladoria <<


Top Top
Profile      
 

    ForeverZer0
  Thu Feb 23, 2012 12:06 am
ARC Developer
User avatar
Sponsor


Location: United tates
I'm not using DirectX, OpenGL, or anything. I'm simply using GDI+, which doesn't have this function. I have found a few different ways of doing the addition actually, its the subtraction that is eluding me, including the methods above. I'm thinking about simply including an XNA redistributable and making it easy, but I would rather not.

Here's the method I got, it works good for addition, but subtraction is results in always black.

Expand to see the code.

_________________
Use DropBox to upload your files. Much simpler than other upload sites, you can simply place a folder on your desktop that will sync with your DropBox account. ;)

Looking for a more powerful RMXP? Check out Image

My complete script list on Pastebin


Top Top
Profile      
 

    Brewmeister
  Thu Feb 23, 2012 12:18 pm
Paste above Main
User avatar


lv 99 Balance Wizard

Location: 42.655713 N 82.619282 W
wouldn't the subtract be the same as the add (with the sign changed)???

i.e. r = destColor.R - (int)(srcColor.R * alpha);

if your srcColor.A is 255, then alpha = 1. (1 - alpha) = 0


I don't see the prototype for a GDI+ COLOR object, but isn't color usually returned as (r, g, b, a) ??


and I still don't see any "scaling". The inherent problem with just adding or subtracting is you end up with too many values
less than 0, or greater than 255. Clamp only compresses 'out of limit' values to 0 or 255.

If you have a pixel that's 50% green, and you add 50% green to it, should you get 100% green?
Or, should you get 50% MORE green, resulting in 75% green?

_________________
"Of course that's just my opinion. I could be wrong!"


Image


Top Top
Profile      
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 


Who is online

Users browsing this forum: No users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

We are an independent, not-for-profit game making community.
Homepage
Board Index
About Us
Downloadable Games
Free Browser Games
Games in Development
RPG Maker Support
Game Maker Support
Construct 2 Support
HBGames the eZine
Advanced RPG Maker
Site Announcements
Powered by phpBB © phpBB Group