Monday, March 28, 2011

Alchemy + libJPEG cont'd

My version of jpegencoder(compressor, really) (with decoder, (decompressor, really!) as a side dish) is finished yesterday. However, the output was a bit unexpected. It has all the jpeg information correct; however, the output image is a blank image. So it did the compression, that's for sure. I have also unplugged the AS Wrappers and just tested the C codes. It went perfectly correct. So i suspected it would have been the source that had toyed my efforts. And, i was correct.

Right now, im not entirely worried about my AS-C wrappers. As stated, it's the AS that is causing the chaos.

in AS

myOriginalImg.source = event.target.data; //myOriginalImg is

var loader:Loader = new Loader();
loader.loadBytes(event.target.data);

var bmpData:BitmapData = new BitmapData(myOriginalImg.width, myOriginalImg.height, true, 0x00000000);
bmpData.draw(myOriginalImg);


With the above code, if you output the values of each pixel, you will get 0x00000000 or 0.

I have tested a few more ways, almost all of them printed a blank image.


SO I AM SO SO STUCK AT THIS!!! If you know to turn into BitmapData with correct pixel values(as it SHOULD!). PLEASE LET ME KNOW!!!!




###############################################
THANKS TO AH WAI, THE PROBLEM IS SOLVED!


private function ...... :void{
AhWaiGehLoader = new Loader();
AhWaiGehLoader.loadBytes(event.target.data);
AhWaiGehLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoaderInfoComplete);

...
}
private function onLoaderInfoComplete(event:Event):void
{
var bmpData:BitmapData = Bitmap(AhWaiGehLoader.content).bitmapData; // Ah Wai's one liner solution
var byteArray:ByteArray = bmpData.getPixels(new Rectangle(0,0, myOriginalImg.width, myOriginalImg.height)); // continue with the usual implementation!!
...
}

No comments:

Post a Comment