Hi,

If I haven't misread something, this

a = a >> 1;

makes no sense. Unless you're trying to divide alpha by 2, in which case I
obviously missed something.


If you want to extract the 4 components, you can use something like this:


var hexaValue:int = 0x9100ff33;

var a:int = (hexaValue >> 24) & 0xff;
var r:int = (hexaValue >> 16) & 0xff;;
var g:int = (hexaValue >> 8) & 0xff;;
var b:int = hexaValue & 0xff;

var newAlpha:int = 0xcc;
var copyHexaValue:int = newAlpha << 24 | r << 16 | g << 8 | b;
trace(uint(copyHexaValue).toString(16)); // traces  cc00ff33

If you don't bother to get the individual RGB components, just the alpha
channel, try this:

var hexaValue:int = 0x9100ff33;
var a:int = (hexaValue >> 24) & 0xff;
var arg:int = hexaValue & 0xffffff;

var newAlpha:int = 0xcc;
copyHexaValue = newAlpha << 24 | arg;
trace(uint(copyHexaValue).toString(16));    // traces  cc00ff33
Also, I'm casting to uint just to display the value in a more
meaningful/readable way in the trace, but as long as you don't perform
arithmetic on those values, you don't have to (because it's parsed as a bit
pattern, not as numerical value, if that makes sense...).

Cheers
Juan Pablo Califano


2008/10/6, sebastian <[EMAIL PROTECTED]>:
>
> hi Glen,
>
> Kudos for the shift >> 1 operation, knew that was a faster operand.
>
> However, this code is still now working, now it simply doesn't change
> anything...
> :(
>
> var val:uint = getPixel32(x,y);
> var a:uint = (val >> 24) & 0xff;
> var rgb:uint = val & 0xffffff;
> a = a >> 1;
> var newval:uint = (a << 32) | rgb;
> setPixel32(x,y,newval);
>
> I also tried changing it to say:
>
> ...
> var rgb:uint = val & 0x00ffffff;
> a = a >> 1;
> var newval:uint = (a << 24) | rgb;
> ...
>
> since I thought that was an error maybe, but that also doesn't influence
> the alpha of the pixel...
> :(
>
> Out of desperation I also tried:
>
> var a:uint = val & 0xff000000;
> var rgb:uint = val & 0x00fffff;
> a = a >> 1;
> var newval:uint = a | rgb;
>
> and
>
> var a:uint = val & 0xff000000;
> var rgb:uint = val & 0x00fffff;
> a = a >> 1;
> var newval:uint = (a << 24) | rgb;
>
> :(
>
> sniff...
>
> Setting alpha for the whole MC is not an option for what I am doing. I'm
> trying to create trails behind things that are moving by having a video-burn
> like effect; by operating on the pixel level. At the moment I am using code
> from 'Adventures in AS', but once i have it working I'll encapsulate it and
> use it in a different project.
>
> The original source is:
>
> http://flashcoding.blogspot.com/2008/03/small-starfield-with-bluring-effect.html
>
> And my current draft-code modification is:
>
> package
> {
>        import flash.events.*;
>        import flash.display.*;
>        import flash.display.Bitmap;
>        import flash.display.BitmapData;
>        import flash.geom.Rectangle;
>
>
>        public class Starfield
>        {
>                var mc:MovieClip =new MovieClip();
>                var screendata:BitmapData;
>
>                var stars:Array=new Array();
>                var antal:Number=500;
>
>                public function Starfield(timeline)
>                {
>
>                        screendata=new BitmapData(320,240,false,0x00000000);
>                        var screen:Bitmap=new Bitmap(screendata);
>                        mc.addChild(screen);
>
>                        for (var i:int=0;i<antal;i++)
>                        {
>                                InitStar(i);
>                        }
>
>                        mc.addEventListener(Event.ENTER_FRAME,this.render);
>                        timeline.addChild(mc);
>                }
>
>                private function MoveStar(index:int)
>                {
>                        if (stars[index][0]<-160 || stars[index][0]>160 ||
> stars[index][1]<-120 || stars[index][1]>120)
>                        {
>                                InitStar(index);
>                        }
>                        else
>                        {
>                                stars[index][0]=
>    stars[index][0]*stars[index][2];
>                                stars[index][1]=
>    stars[index][1]*stars[index][2];
>                        }
>                }
>
>                private function InitStar(index:int)
>                {
>
> stars[index]=[Number(((Math.random()*10)-5)),Number(((Math.random()*10)-5)),Number((Math.random()/10)+1)];
>                }
>
>
>                private function render(e:Event):void
>                {
>                        for(var x:int=0;x<320;x++)
>                        {
>                                for(var y:int=0;y<240;y++)
>                                {
>
>                                        var val:uint = screendata.getPixel32
> (x,y);
>
>                                        var a:uint = (val >> 24) & 0xff;
>                                        var rgb:uint = val & 0xffffff;
>                                        a = a >> 1;
>                                        var newval:uint = (a << 24) | rgb;
>
>                                        screendata.setPixel32(x,y,newval);
>
>                                }
>                        }
>
>                        for(var i:int=0;i<antal;i++)
>                        {
>                                MoveStar(i);
>
>  screendata.setPixel(stars[i][0]+160,stars[i][1]+120,0xFFFFFF);
>                        }
>                }
>        }
> }
>
>
> Regards,
>
> Sebastian.
>
>
> Glen Pike wrote:
>
>> Hi,
>>
>>   I think you need to shift by 24 for alpha, you also need to shift then
>> mask the value.  RGB is just the bottom three bytes masked and shifting by 1
>> rather than divide by 2 may be faster, but google for the speed comparisons
>> in AS3 - I think John Grden may have blogged this:
>>   var a:uint = (val >> 24) & 0xff;
>>   var rgb:uint = val & 0xffffff;
>>   a = a >> 1;
>>   var newval:uint = (a << 32) | rgb;
>>
>>   It would be a good learning exercise to do your own equations for
>> manipulating pixel stuff, but have a look at Mario Klingemann's blog -
>> quasimondo.com - for tips and tricks with images as he is one of the best
>> people at manipulating bitmaps in Flash so he may have some nice examples to
>> stimulate you.  For simpler manipulation have a google.  Also, if you are
>> just setting the alpha to 50% for the whole bitmap, it may be quicker to do
>> this on the MovieClip because FlashPlayer might be optimising composition
>> somehow, but I understand this may just be an example.
>>
>>   HTH
>>
>>   Glen
>>  sebastian wrote:
>>
>>> Thanks Glen and Andrew,
>>>
>>> Thanks for your fast help,
>>>
>>> Tried to use this code [below] but it makes my pixels yellow instead of
>>> 50% alpha on each pass... any ideas why?
>>>
>>> Is there any good tutorial on working with bit operations and bit logic?
>>> Would make it easier for me to trouble shoot/make my own equations.
>>> :)
>>>
>>> Thanks!
>>>
>>> Seb.
>>>
>>> Andrew Murphy wrote:
>>>
>>>> I'm not sure of this, but:  After you grab "val" you could bitshift out
>>>> the
>>>> alpha channel ("a"), subtract that from the original argb value to
>>>> remove
>>>> the alpha channel.  Manipulate "a" and bitshift it back up again before
>>>> adding it to the rgb value to give you a new argb.
>>>>
>>>>
>>>> var a:uint = val >> 32 & 0xff;
>>>> var rgb:uint = val - (a << 32);
>>>> a = a / 2;
>>>> var newval:uint = rgb + (a << 32);
>>>>
>>>>
>>>>
>>>> --------------------------------
>>>> Andrew Murphy
>>>> Interactive Media Specialist
>>>> [EMAIL PROTECTED]
>>>>
>>>> Delvinia
>>>> 214 King Street West, Suite 214 Toronto Canada M5H 3S6
>>>>
>>>> P 416.364.1455 ext. 232  F 416.364.9830  W www.delvinia.com
>>>>
>>>> CONFIDENTIALITY NOTICE
>>>> This email message may contain privileged or confidential information.
>>>> If
>>>> you are not the intended recipient or received this communication by
>>>> error,
>>>> please notify the sender and delete the message without copying or
>>>> disclosing it.
>>>>
>>>> AVIS DE CONFIDENTIALITÉ
>>>> Ce message peut contenir de l'information légalement privilégiée ou
>>>> confidentielle. Si vous n'êtes pas le destinataire ou croyez avoir reçu
>>>> par
>>>> erreur ce message, nous vous saurions gré d'en aviser l'émetteur et d'en
>>>> détruire le contenu sans le communiquer a d'autres ou le reproduire.
>>>>
>>>>
>>>>
>>>>> -----Original Message-----
>>>>> From: [EMAIL PROTECTED] [mailto:
>>>>> [EMAIL PROTECTED] On Behalf Of sebastian
>>>>> Sent: Monday, October 06, 2008 3:18 PM
>>>>> To: Flash Coders List
>>>>> Subject: [Flashcoders] working with getPixel32 and setPixel32,
>>>>>
>>>>> hi folks,
>>>>>
>>>>> can any one shed some light to me on the setpixel32 and getpixel32?
>>>>>
>>>>> I'd like to be able to affect just one of the 4 components: A R G or B
>>>>> independently of another.
>>>>>
>>>>> Essentially, read the current ARGB using getPixel32 and then manipulate
>>>>> just one part of it, in my case, halve the current "A" value of the ARGB 
>>>>> and
>>>>> then re-assign it back to the bitmap.
>>>>>
>>>>>
>>>>> //1: grab the HEX value for the current coordinate:
>>>>> var val:uint = getPixel32(x,y);
>>>>>
>>>>> //2: manipulate the HEX value of just 1 of the 4 parts, in my case the
>>>>> A of the ARGB:
>>>>> ????
>>>>>
>>>>> //3: re-assign it back to the display:
>>>>> setPixel32(x,y,val);
>>>>>
>>>>> Thanks for your help!
>>>>>
>>>>> Sebastian.
>>>>> _______________________________________________
>>>>> Flashcoders mailing list
>>>>> Flashcoders@chattyfig.figleaf.com
>>>>> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>>>>>
>>>>
>>>>
>>>> _______________________________________________
>>>> Flashcoders mailing list
>>>> Flashcoders@chattyfig.figleaf.com
>>>> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>>>>
>>>> _______________________________________________
>>> Flashcoders mailing list
>>> Flashcoders@chattyfig.figleaf.com
>>> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>>>
>>>
>>>
>> _______________________________________________
> Flashcoders mailing list
> Flashcoders@chattyfig.figleaf.com
> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>
_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to