We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexSuggestions & BugsSoftware Bugs › mask does not work quite like alpha
Page Index Toggle Pages: 1
mask does not work quite like alpha (Read 2106 times)
mask does not work quite like alpha
Sep 8th, 2005, 11:29am
 
Hi all,

In updating code that used the BImage alpha function (setting individual pixel alpha values using a list of integers) to use the new PImage and it's respective mask function, it seems to me that passing the exact same list of integers to both the BImage alpha function and the PImage mask function produces quite different results.

The mask function seems to have a far steeper curve from opaque to clear, seemingly confined mostly to the last 100 of the 255, where with the old alpha function the curve was more gradual producing noticeable results over the whole 255 range.

Can anyone verify / refute or shed any light on my suspicion?

cheers,

james
Re: mask does not work quite like alpha
Reply #1 - Sep 8th, 2005, 11:55am
 
Fry wrote in this thread (http://processing.org/discourse/yabb_beta/YaBB.cgi?board=Syntax;action=display;num=1124271574):

"nope, alpha() is now mask() as of beta:
http://processing.org/reference/PImage_mask_.html
i'll add it to the faq on updating alpha -> beta code"


So it should be the same, but maybe there were some internal changes? do you have a quick example?
Re: mask does not work quite like alpha
Reply #2 - Sep 8th, 2005, 1:35pm
 
the code is identical, except for the renderers.

one possibility would be that your monitor is set at 16 bit depth so it's not giving you the subtlety you're looking for (after making changes, you'll need to restart processing).

since the renderers are different, you might try using P3D to see if that gives results more similar to what was there before. it's possible the JAVA2D stuff is problematic.
Re: mask does not work quite like alpha
Reply #3 - Sep 8th, 2005, 3:35pm
 
I'm pretty convinced that the results are different with mask than they were with alpha. I'm sure it's not my monitor as the two functions produce clearly different results.(see gifs linked below)

here's test code using BImage and alpha in v0069:
----------------
size(255,255);
background(255);
BImage pixelblack;
pixelblack = loadImage("pen0.gif");
imageMode(CENTER_DIAMETER);
int[] alphaVList = new int [1];

for(int i=0;i<255;i++){
 alphaVList[0] = i;
 pixelblack.alpha(alphaVList);
 image(pixelblack,150,i);
}
---------------------
this produces : http://www.atomless.com/images/v0069_alpha.gif

and here's test code using PImage and mask in v0091:
---------------------
size(255,255);
background(255);
PImage pixelblack;
pixelblack = loadImage("pen0.gif");
imageMode(CORNERS);
int[] alphaVList = new int [1];

for(int i=0;i<255;i++){
 alphaVList[0] = i;
 pixelblack.mask(alphaVList);
 pixelblack.updatePixels();
 image(pixelblack,150,i);
}
------------------------
this produces : http://www.atomless.com/images/v0091_mask.gif


Re: mask does not work quite like alpha
Reply #4 - Sep 8th, 2005, 4:22pm
 
k, so give it a shot with P3D and see what happens.

and how come you're using different imageModes?
Re: mask does not work quite like alpha
Reply #5 - Sep 8th, 2005, 5:04pm
 
Hi Ben,

I was originally using the centre_diameter image mode when using 0069 but had to change it when porting to 0091 beta. I just tried to recreate a couple of test programs that matched the code I'm using in the full programs.

Using the P3D renderer makes no difference. Must be changes in the renderers since 0069 I guess. To my eyes the gradient possible with the old alpha function is smoother, more gradual and seems more evenly spread.

I feel I'm nit picking to a certain extent but it does seem more difficult to achieve the pleasing smooth gradients with mask that I was able to achieve with alpha.

Re: mask does not work quite like alpha
Reply #6 - Sep 8th, 2005, 5:23pm
 
here's a gif that shows the comparison more clearly.
http://www.atomless.com/images/alpha_mask_comparison.gif
produced  by test programs shown above.
Re: mask does not work quite like alpha
Reply #7 - Sep 9th, 2005, 11:06am
 
actually, as this code illustrates :

------------------
size(255,255);
background(255);
PImage pixelblack;
pixelblack = loadImage("pen0.gif");
imageMode(CORNERS);
int[] alphaVList = new int [1];

for(int i=0;i<255;i++){
 alphaVList[0] = i;
 pixelblack.mask(alphaVList);
 pixelblack.updatePixels();
 for(int j=0;j<50;j++){
   image(pixelblack,150+j,i);
   color c = color(255-i, 255-i, 255-i);
   set(205+j,i, c);
 }
 
}
-------------------------

when you lay out all of the greyscale values between 0 and 255 end to end from top to bottom alongside the mask gradient the two are identicle.

The mask function does give different results to that of the old alpha function but as the mask gradient matches a uniform gradient between greyscale 0 and 255 then maybe it's  an improvement on the alpha function which does not match the uniform grayscale gradient.

I still prefer the resulting aesthetic I was getting in my programs with the alpha gradient but I'm sure I can tweak things to recapture this. I would, however, be intrigued to know what caused the change as it's the same both with the JAVA2D renderer and the P3D renderer.

Re: mask does not work quite like alpha
Reply #8 - Sep 9th, 2005, 2:28pm
 
i just don't know and am quite baffled. my guess is that there's something different about the image() function, not the mask() function, because as i keep saying, it has not changed since the earlier releases.

this is the code from the alpha:
http://dev.processing.org/viewcvs/index.cgi/trunk/processing/core/PImage.java?rev=847&view=markup

and this is beta:
http://dev.processing.org/viewcvs/index.cgi/trunk/processing/core/PImage.java?rev=1525&view=markup

it's only a couple lines of code that nothing has happened to.

could you file this as a bug? http://dev.processing.org/bugs/
and when doing so, include those output images and the two sketches (zip up the whole sketch folder, not just the text of the code.. makes it easier to unzip and run the sketch because i need that .gif test file).
Re: mask does not work quite like alpha
Reply #9 - Sep 14th, 2005, 2:25pm
 
now filed in the bugs db:
http://dev.processing.org/bugs/show_bug.cgi?id=148
Page Index Toggle Pages: 1