Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (523)
Games in Android Showcase (127)
games submitted by our members
Games in WIP (592)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Additive blitting?  (Read 2537 times)
0 Members and 1 Guest are viewing this topic.
Offline CheekyRipley

Junior Devvie


Projects: 1



« Posted 2007-06-18 08:23:07 »

OK I give up Cheesy  Googled, looked through the forum, and the answer eludes me....

I want to blit an image on the screen, then draw another image on top of it.

With the second image though, I want to use an ADD rop - in other words, the RGB of the second image is added to the destination (rather than the source replacing the dest, with transparency, as normal). To make things more complicated the second image has alpha, so it's semi transparent.

Is there a nice easy render op mode I can set to do this? Cheesy

Thanks,

M

Mark Ripley<br />Cheeky
Offline keldon85

Senior Devvie


Medals: 1



« Reply #1 - Posted 2007-06-18 09:05:16 »

getGraphics().paint(...)  Smiley

Offline broumbroum

Junior Devvie





« Reply #2 - Posted 2007-06-18 09:13:17 »

This is quite easy. Refering to AlphaComposite class, add the setComposite(AlphaComposite) to the Graphics2D instance of the dest' image then draw the source on it. I use AlphaComposite.SRC_OVER as default alpha-rendering mode. You'll get an "ADD r. op." as requested.
it looks like:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
Image dest = ImageIO.read("myImageFile.bmp");
Image src = ImageIO.read("myImageFile2.bmp");
static Image addROP(Image dest, Image src) {
    JComponent obs = new JLabel("virtual observer");
    MediaTracker mt = new MediaTracker(obs);
    mt.addImage(dest, 0);
    mt.addImage(src, 0);
    try{
       mt.waitForAll();
       Graphics2D g2 = (Graphics2D)dest.getGraphics();
       g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.3f));
       g2.drawImage(src, null, obs);
       g2.dispose();
    }  catch(InterruptedException e) {} finally {
       return dest;
    }
}

consider the 2 images, they must be the same size or you should add an extra AffineTransform scaling-op to the drawImage method.

::::... :..... :::::: ;;;:::™ b23:production 2006 GNU/GPL @ http://b23prodtm.webhop.info
on sf.net: /projects/sf3jswing
Java (1.6u10 plz) Web Start pool
dev' VODcast[/ur
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline CheekyRipley

Junior Devvie


Projects: 1



« Reply #3 - Posted 2007-06-18 11:29:43 »

Ah thanks Smiley

I looked into SRC_OVER, but I thought it just did a normal "destructive" blit....

I'll bung that code in and see what happens Cheesy

Mark Ripley<br />Cheeky
Offline CheekyRipley

Junior Devvie


Projects: 1



« Reply #4 - Posted 2007-06-20 05:28:28 »

Hmm, no different to a normal drawImage (as far as I can tell).....

Just to be clear, what I'm trying to do is, for example:

Source pixel RGB: 128, 128, 128
Dest pixel RGB:        64, 200, 64

Result:                      192, 255, 192

Mark Ripley<br />Cheeky
Offline brackeen

Junior Devvie





« Reply #5 - Posted 2007-06-20 06:01:59 »

Well, there is no additive blending in Java 2D. So you've got to use OpenGL, or write the additive blending code by hand.

PulpCore (http://www.interactivepulp.com/pulpcore/) does additive blending via software rendering, but it's just for applets.
Offline keldon85

Senior Devvie


Medals: 1



« Reply #6 - Posted 2007-06-20 08:05:21 »

Oops, I meant drawImage(...) not paint lol; I remember using it way back and it did alpha blending using the alpha channels of the pixels. Also the MemoryImageSource's newPixels() method does additive blending, using your alpha values taking the RGB components as pre multiplied values.

Offline campbell

Junior Devvie




Java games rock!


« Reply #7 - Posted 2007-06-20 16:40:58 »

Well, there is no additive blending in Java 2D.

Not yet anyway... It's planned for JDK 7 though in a new class called PhotoComposite, which will offer other PhotoShop-style blending modes as well.  See this RFE:
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5094232

Chris
Offline keldon85

Senior Devvie


Medals: 1



« Reply #8 - Posted 2007-06-20 16:46:29 »

Well, there is no additive blending in Java 2D

[there's no blending in Java2D] Not yet anyway... It's planned for JDK 7 though in a new class called PhotoComposite

But the MemoryImageSource does it in newPixels()!!!

Offline Linuxhippy

Senior Devvie


Medals: 1


Java games rock!


« Reply #9 - Posted 2007-06-21 14:12:40 »

But the MemoryImageSource does it in newPixels()!!!

Sorry, what do you mean? Do you mean bleding my hand - because that could be also done with BufferedImage (MemoryImageSource is more or less deprecated).

lg Clemens
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline keldon85

Senior Devvie


Medals: 1



« Reply #10 - Posted 2007-06-21 23:50:53 »

Sorry, what do you mean? Do you mean blending my hand - because that could be also done with BufferedImage (MemoryImageSource is more or less deprecated).

lg Clemens

Well yes and no. It takes pre-multiplied values so the RGB values would want to correspond to your alpha values (if you want to be pedantic with the pixel maths). Having said that if you just wanted to work with 50% transparency then you just write color = 0x80000000 | ((color&fefefe)>>1)! That premultiplies the pixel with 50% alpha in one shot - however BufferedImage allows for non-premultiplied RGBA values.

And deprecated is a harsh word for a class that isn't yet deprecated  Wink

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

SHC (24 views)
2014-11-25 12:00:59

SHC (24 views)
2014-11-25 11:53:45

Norakomi (22 views)
2014-11-25 11:26:43

Gibbo3771 (22 views)
2014-11-24 19:59:16

trollwarrior1 (36 views)
2014-11-22 12:13:56

xFryIx (74 views)
2014-11-13 12:34:49

digdugdiggy (52 views)
2014-11-12 21:11:50

digdugdiggy (46 views)
2014-11-12 21:10:15

digdugdiggy (41 views)
2014-11-12 21:09:33

kovacsa (69 views)
2014-11-07 19:57:14
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!