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 =; //myOriginalImg is

var loader:Loader = new Loader();

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

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!!!!


private function ...... :void{
AhWaiGehLoader = new Loader();
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!!

Friday, March 25, 2011

Alchemy + libjpeg (4) - Final Words

The previous finding although allows us to compile with the correct header; it does not include the libjpeg at all. So the final swc is smaller and most importantly, it doesn't know where to look for the functions in libjpeg.h.

To include the library in the final swc, here is the line

gcc jpeg_sample_linker.c -O3 -swc -o jpeg_sample_linker.swc /usr/local/lib/libjpeg.a

SHAAATTTTT.. man...... this is tiring.

To build ur own c library, this post looks decent:

Thursday, March 24, 2011

Alchemy (Array and ObjectArray)

Fiddling with Alchemy furthermore, i was stuck at parsing array of values from AS to C.
Originally, i thought simply by supplying the following code would get me the correct values; however, it turned out to be exactly the opposite of what i was expecting.

AS3_ObjectValue(args, "arg0:IntType, arg1:StrType", &arg0, &arg1); //arg0, arg1 declared correspondingly

It turns out i need to make a slight change in order to get the values.
AS3_ArrayValue(args, "AS3ValType", &arr) // arr declared to be AS3ValType arr;
AS_ObjectValue(arr, "arg0:IntType, arg1:StrType", &arg0, &arg1); //then you will get the proper values

OH MY GOOOOOOOOODNESSSSSSSSSSSSSSSSSSSSSS, spent an hr in the morning just to figure that line out... CHI SIN!

Absolutely Beautiful: World Construction Alchemy + Flex

Box2d Flash Alchemy Port + World Construction Kit

Amazing, Amazing, Amazing!!!!

Alchemy + libjpeg (3) - Solved

I friggin solved the compilation issue by moving
whatever there is in /usr/local/include and /usr/local/lib
to $ALCHEMY_HOME/usr/local/include and $ALCHEMY_HOME/usr/local/lib

What a bummer....

Alchemy + libjpeg (2)

Attacking the same monster again.

after probing a bit further with $ALCHEMY_HOME, i see that the gcc is ignoring my local lib and include directories.

Here is an output of the gcc -v ...

alc-on; gcc -v -swc -I/usr/local/include -L/usr/local/lib -ljpeg jpeg_sample_linker.c ; alc-off;
Using built-in specs.
Target: i686-apple-darwin8
Configured with: ../src/configure --prefix=/Users/lattner/2.1/llvm-gcc4.0-2.1.source/obj/../install --program-prefix=llvm- --enable-llvm=/Users/lattner/2.1/llvm-2.1 --enable-languages=c,c++,objc,obj-c++ --with-arch=nocona --with-tune=generic --build=i686-apple-darwin8 --host=i686-apple-darwin8 --target=i686-apple-darwin8 --with-gxx-include-dir=/usr/include/c++/4.0.0
Thread model: posix
gcc version 4.0.1 (Apple Computer, Inc. build 5449)(LLVM build 2.1)
 /Library/alchemy-darwin-v0.5a/bin/llvm-gcc4-darwin-install/bin/../libexec/gcc/i686-apple-darwin8/4.0.1/cc1 -quiet -nostdinc -v -I/Library/alchemy-darwin-v0.5a/avm2-libc/include -I/Library/alchemy-darwin-v0.5a/usr/local/include -I/Library/alchemy-darwin-v0.5a/usr/local/include -iprefix /Library/alchemy-darwin-v0.5a/bin/llvm-gcc4-darwin-install/bin/../lib/gcc/i686-apple-darwin8/4.0.1/ -D__DYNAMIC__ -include /Library/alchemy-darwin-v0.5a/avm2-libc/avm2/AVM2Env.h jpeg_sample_linker.c -emit-llvm-bc -o /var/folders/Gc/GcsfwfKvHz4ln8pYZNe0RU+++TM/-Tmp-//cc2JJZbX.o -fPIC -quiet -dumpbase jpeg_sample_linker.c -mmacosx-version-min=10.6.6 -mtune=generic -march=nocona -auxbase jpeg_sample_linker -version
ignoring nonexistent directory "/Library/alchemy-darwin-v0.5a/usr/local/include"
ignoring nonexistent directory "/Library/alchemy-darwin-v0.5a/usr/local/include"
#include "..." search starts here:
#include <...> search starts here:
End of search list.
GNU C version 4.0.1 (Apple Computer, Inc. build 5449)(LLVM build 2.1) (i686-apple-darwin8)
compiled by GNU C version 4.0.1 (Apple Computer, Inc. build 5449)(LLVM build ).
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 94b5292347af0582283c78d591f83b23
jpeg_sample_linker.c:4:21: error: jpeglib.h: No such file or directory

alc's gcc clearly ignored my local lib and include directories.. :/

Wednesday, March 23, 2011

Alchemy + libjpeg

It's such a mess!!!!
This error never goes away:

error: jpeglib.h: No such file or directory

1) gcc jpeg_sample_linker.c -O3 -L/usr/local/lib -L../jpeg-8c -ljpeg -swc jpeg_sample_linker.swc
prompts for missing jpeglib.h

2) gcc -c jpeg_sample_linker.c -swc jpeg_sample_linker.swc
prompts for missing jpeglib.h (of course) 

3) gcc -c jpeg_sample.c -ljpeg -swc jpeg_simple_linker.swc 
prompts for missing jpeglib.h, too

4) gcc -Wall -Ijpeg-8c -swc -O3 jpeg_sample_linker.c -o jpeg_sample_linker.swc -Ljpeg-8c -ljpeg -L
prompts for the same missing jpeglib.h error!


Thursday, March 10, 2011

Inheritance and Algorithms

A lot of the time, when we deal with a number of algorithms for a specific application.  We often allow the users to pick one of the algorithms(as one of their choices).

For example, say interpolation of a set of values, a user should be able to select different types of linear interpolations such as 'bilinear', or 'bicubic', or 'trilinear' etc.  Normally, or at the premature level, we might offer three different separate methods or three decoupled classes for this scenarios.  The chance is that a lot of the helper functions are repeated.

However, this very scenario could well be used with inheritance and it's not ROCKET SCIENCE!

Thursday, March 3, 2011

the hassle and the beauty of "bwboundaries" and "imfill"

I'm not sure why other people would want to fill the inside of a set of boundaries.
But i certainly needed that and needed that quick. Having a tired mind after a day of work, i spent more than i should probing the net for such a nifty script.

The results: NONE'd fit what i want...

So i took sometime to make my own.

function filledIm = fillBoundary(boundaries, imWidth, imHeight)
filledIm(1:imHeight, 1:imWidth)=0;
%% this is just my tired mind style, you could go with zeros(...)

for k=1:length(boundaries),

boundary = boundaries{k};

for bIdx = 1:length(boundary)

filledIm( boundary(bIdx,1),boundary(bIdx,2))=255;

filledIm = imfill(filledIm);


My method is rather slow. If you have a better way(im sure you do), please let me know!!!! Thanks!