Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (799)
Games in Android Showcase (237)
games submitted by our members
Games in WIP (865)
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  
  All-Integral Alpha Compositing Using Bitwise Operators - Also New to JGO!  (Read 13013 times)
0 Members and 1 Guest are viewing this topic.
Offline A-Bomb

Junior Devvie

Medals: 3
Exp: 4 years

« Posted 2017-04-08 06:39:01 »

So I'm new to the site and I figured what better way to introduce myself than to post some cool code I wrote recently? Just as the name suggests I've written some code that allows me to blend partially transparent images using only bitwise operations. Not to be confused with transparency masking (although my engine supports that too), arbitrarily translucent colors can be blended to within a modest granularity without relying on floating point or even fixed point arithmetic, but by direct manipulation of the bits comprising the composite images. It's a surprisingly accurate solution despite its rather quantized domain...! Anywho, for those of you who might find it useful or are curious I've provided a link to a demonstration video so you can see it in action! Feel free to ask if you have any questions!

Anywho, glad to be here; thanks!

int alpha = ...;//can be retrieved or set depending on needs, therefor per pixel alpha is possible
alpha = (alpha >>> 8) | (alpha >>> 16) | (alpha >>> 24);//copy the alpha to rgb components in this variable
int spritePixel = spritePixels[i];
int lsb = 0x000000ff; //least significant byte; sign correction
int flag = ((spritePixel >> 16) & (spritePixel >> 8) & spritePixel & lsb) + 1;//it gets complicated here; basically it ensures pixel values
int mask = (flag << 23) >> 31;                                                             //of 0xffffff (white) generate a mask of 0xffffff and anything
                                                                                                          //else generates a mask of 0 (this is the automatic bit mask)
if(lsb - (alpha & lsb) <= 0)//completely opaque?
    this.pixels[i] &= mask;//transparency mask "AND" phase (black silhouette over background)
    this.pixels[i] |= ~mask & spritePixel;//transparency mask "OR" phase (full color sprite over background)
else//arbitrarily translucent
    this.pixels[i] &= spritePixel | alpha;//BLACK MAGIC, I SWEAR

<a href=";hl=en_US&amp;start=" target="_blank">;hl=en_US&amp;start=</a>
Offline nsigma
« Reply #1 - Posted 2017-04-08 11:52:19 »

Nice!  This old thread might interest you too - - mostly bitwise operation and multiplication.

Praxis LIVE - hybrid visual IDE for (live) creative coding
Offline A-Bomb

Junior Devvie

Medals: 3
Exp: 4 years

« Reply #2 - Posted 2017-04-08 12:04:25 »

Nice!  This old thread might interest you too - - mostly bitwise operation and multiplication.

Ooooooooooooooooooooooooooh! It most certainly DOES! Thank you!!! You don't know how much I love finding neat things you can do with bitwise operation! It's certainly a unique class of challenges, that's for sure! And graphics fx to boot, well this is right up my alley!
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline orange451

JGO Kernel

Medals: 544
Projects: 8
Exp: 8 years

Your face? Your ass? What's the difference?

« Reply #3 - Posted 2017-04-08 17:24:29 »

I almost did a double take when I saw BlueJay...

Haven't seen that software in a long time!

First Recon. A java made online first person shooter!
Offline A-Bomb

Junior Devvie

Medals: 3
Exp: 4 years

« Reply #4 - Posted 2017-04-08 17:51:04 »

I almost did a double take when I saw BlueJay...

Haven't seen that software in a long time!

Not a surprise xD! Truth is I love Blue J and I never grew out of it. I tend to prefer something more simplistic when programming anyway; something that doesn't have a lot of clutter to bog down my concentration. I also just love it because it just gets things right that I wish other IDEs would also, like how it organizes open classes and packages into windows on the task bar rather than in tabs on the UI (which I personally hate) and also you'll never find an IDE that gets code highlighting right the way Blue J does. Colored keywords and changeable background colors are ok but being able to easily visually distinguish entire code blocks just by their color is even better I feel. It helps me visually step through my program flow much more easily. So anywho, yeah that's why I still use Blue J lol!
Pages: [1]
  ignore  |  Print  

Riven (197 views)
2019-09-04 15:33:17

hadezbladez (4882 views)
2018-11-16 13:46:03

hadezbladez (1800 views)
2018-11-16 13:41:33

hadezbladez (5154 views)
2018-11-16 13:35:35

hadezbladez (1021 views)
2018-11-16 13:32:03

EgonOlsen (4384 views)
2018-06-10 19:43:48

EgonOlsen (5226 views)
2018-06-10 19:43:44

EgonOlsen (2969 views)
2018-06-10 19:43:20

DesertCoockie (3872 views)
2018-05-13 18:23:11

nelsongames (4303 views)
2018-04-24 18:15:36
Java Gaming Resources
by philfrei
2019-05-14 16:15:13

Deployment and Packaging
by philfrei
2019-05-08 15:15:36

Deployment and Packaging
by philfrei
2019-05-08 15:13:34

Deployment and Packaging
by philfrei
2019-02-17 20:25:53

Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08

Deployment and Packaging
by gouessej
2018-08-22 08:03:45 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‑
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!