Glen's approach seems right.
I've been playing a bit with Pixel Bender in the last few days and just put
together a map gradient filter using his suggestions and it seems to be
working fine.
Probably using PB is a bit too much here, though. But in case anyone is
interested in taking a look, here it goes.
<languageVersion : 1.0;>
kernel GradientMap
< namespace : "ar::com::califa010";
vendor : "califa010";
version : 1;
description : "gradient map";
>
{
input image4 src;
input image4 grad;
output pixel4 dst;
void
evaluatePixel()
{
float4 px = sampleNearest(src,outCoord());
float r_lum = 0.212671;
float g_lum = 0.715160;
float b_lum = 0.072169;
float grey = px.r * r_lum + px.g * g_lum + px.b * b_lum;
float4 outVal = sampleNearest(grad,float2(grey * 255.0,0.0));
dst.a = 1.0;
dst.r = outVal.r;
dst.g = outVal.g;
dst.b = outVal.b;
}
}
Cheers
Juan Pablo Califano
2008/11/10, Glen Pike <[EMAIL PROTECTED]>:
>
> Hi,
>
> I also remembered where I had seen the 1 x 256 gradient rectangle shape
> used as a lookup table for colours - it was not my idea originally:
>
> Check out the LightMaps class in PaperVision3D - this deals with creating
> an array of colour values used for looking up the colour of something which
> you could adapt for your idea.
>
> org.papervision3d.materials.utils.LightMap is the class you want -
> getFlatMapArray is the method.
>
>
> http://papervision3d.googlecode.com/svn/trunk/as3/trunk/src/org/papervision3d/materials/utils/LightMaps.as
>
> Glen
>
> Glen Pike wrote:
>
>> Hi,
>>
>> From what I can see of the gradient map, it multiplies a grayscale value
>> by a gradient??
>> To do this, you need to get your bitmap data into grayscale - use the
>> ColorMatrixFilter like here:
>>
>> http://www.actionscript.org/forums/showthread.php3?p=766173
>>
>> Then you will need to map your grayscale values to a colour value. I
>> guess one way to do this would be to create a 1 * 256 rectangle filled with
>> a gradient of your choice. You would then convert this to a bitmap, then
>> map the value of each pixel in your image you want to gradient map to the
>> RBG value of the corresponding pixel in your 256 long rectangle:
>>
>> e.g.
>> //convert bitmap data to grayscale using the above method,
>> //pseudocode - you would probably need to call getPixel / setPixel and
>> other methods...
>> mapped = new Bitmap(grayscaleW, grayscaleH);
>> for(each pixel in grayscale) {
>> var luminance = grayscale[x][y].red; //0-255 could use .green or
>> .blue as they are all the same value
>> mapped[x][y] = gradientRBG[luminance];
>> }
>>
>> //This means you could use any gradient you want and create it
>> dynamically, or create it at authortime as long as it is 1 x 256 (you can
>> make it larger, but you just sample the pixel RGB values from the first row.
>>
>> There is probably a quicker way of mapping the values from a grayscale
>> image to colour values, so have a scout around - maybe play with
>> FlashFilterLab, but I am guessing the ColourMatrix filter may help again
>> here...
>>
>> HTH
>>
>> Glen
>>
>> ACE Flash wrote:
>>
>>> any suggestions? please...
>>>
>>> On Mon, Nov 10, 2008 at 11:36 AM, ACE Flash <[EMAIL PROTECTED]> wrote:
>>>
>>>
>>>
>>>> Hey there, I am going to apply the gradient map effect on a image ( the
>>>> name called in photoshop => image => ajustments => gradient map ) . do
>>>> you
>>>> know how to deal with it in action script 3?
>>>> *http://yarra.ath.cx/zmzm/upload/Picture_1.png*<
>>>> http://yarra.ath.cx/upload/Picture_1.png>
>>>>
>>>>
>>>> Thank you
>>>>
>>>>
>>>>
>>> _______________________________________________
>>> Flashcoders mailing list
>>> [email protected]
>>> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>>>
>>>
>>>
>>>
>>
>>
> --
>
> Glen Pike
> 01326 218440
> www.glenpike.co.uk <http://www.glenpike.co.uk>
>
> _______________________________________________
> Flashcoders mailing list
> [email protected]
> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>
_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders