Skip navigation
Home/Support/

Forums

1 2 Previous Next 45586 Views 56 Replies Latest reply: Jun 21, 2009 9:39 AM by sectore RSS
matthewbmedia User 12 posts since
Nov 19, 2008
Currently Being Moderated

Nov 19, 2008 5:07 PM

Request: Port AS3 Corelib encoder functionality

Ted Patrick had a post a while back asking the community about adding native encoder support to the player. Now that alchemy is available, would it make sense to move the functionality of the "corelib" as3 encoder libraries over to C++ equivalents?

I currently have a client side publishing app that generates 300 dpi jpeg images out of bitmapdata objects, and even with a quad core 3ghz machine, encoding a jpeg using the AS3 corelib still takes 10-15 seconds.

Would anyone at Adobe, or anyone in the community like to take a crack at bringing in a C++ jpeg encoder via alchemy? Is this possible?
  • Manfred Weber User 1 posts since
    Nov 18, 2008
    I was asking me the same today. Actually I was researching for valid usecases. I think that Alchemy could speed up some slow algorithms like f.e. the encoder stuff you mentioned. Can anyone give some feedback on this?
    However I played with Alchemy today and hope to see some tests regarding performance.
  • metalbot User 15 posts since
    Nov 18, 2008
    I'm taking a quick stab at it (downloaded http://www.ijg.org/files/jpegsrc.v6b.tar.gz , then ran ./configure on it.)

    It feels kinda weird to see that ./configure is repeatedly invoking AIR apps created on the fly to test if various features exist, but it works all the same.

    It compiled without a problem, and I know have a 377KB file named jpeg.l.bc.

    I still have to write some glue to call it from as3, but that shouldn't be a big deal, except I'll have to engage my brain long enough to learn what functions are exposed by the jpeg library.

  • metalbot User 15 posts since
    Nov 18, 2008
    Currently Being Moderated
    3. Nov 19, 2008 10:05 PM (in response to matthewbmedia)
    Re: Request: Port AS3 Corelib encoder functionality
    There appears to be little red ***** things hiding in my details.

    Various findings so far:

    - Using gluegen with functions that return a Boolean results in generated code that calls an AS3_Boolean() function. That function doesn't exist in the current release, although it's not hard to define an approximation of it as static AS3_Val AS3_Boolean(int val) { return val?AS3_True():AS3_False(); }

    - You can use "import" statements in .gg file, so you don't have to patch the resulting .as file afterward simply because you like ByteArrays.

    - However, gluegen-generated .as files don't seem to expose the .supplyFile() method and that does seem to require patching.

    - talking about .supplyFile(), the method works great to fake file reads, but is not written to handle file writes. That's a downer as libjpeg apparently wants to write encoded JPEG data into a FILE* structure.

    - minor quibble: if you're thinking of writing an AIR app with Alchemy that would read humongous files, don't. At least, not yet. The current implementation of open() reads the entire file in memory before returning a handle.

    - dead code removal isn't quite as good as I'd hope. whatever your glue file doesn't use gets compiled away. But that's it. The entire code in the final .swc will be included in any project that references it. That's probably because the CLibInit class hardcodes references to every other chunk in the .swc. So to optimize for size, you'll have to cut through your glue files and rebuild SWCs that contain only what you use.


    Anyway, at this point, I'm hoping I overlooked some way of using libjpeg without FILE* handles.
  • Branden_Hall User 20 posts since
    Nov 20, 2008
    Currently Being Moderated
    5. Nov 20, 2008 11:22 AM (in response to matthewbmedia)
    Re: Request: Port AS3 Corelib encoder functionality
    I'm not super familiar with GlueGen (when I started working with Alchemy it wasn't available yet) but I hope I can help a little bit.

    The FILE* handles can be dealt with by using a C standare library function called funopen - this lets you create a file handle that goes and calls functions for read, write, lseek, and close.

    http://www.gsp.com/cgi-bin/man.cgi?section=3&topic=funopen
  • joesteele User 68 posts since
    Nov 16, 2008
    Currently Being Moderated
    6. Nov 20, 2008 5:15 PM (in response to metalbot)
    Re: Request: Port AS3 Corelib encoder functionality
    Great feedback! I am looking into posting a sample of using libpng (the one demo'ed during MAX). It did not make it into the package unfortunately.

    Regarding the various performance/codesize woes -- yes there are a bunch of improvements that can be made. If there is enough interest in the community we may get the chance to make them.

    Regarding gluegen and AS3_Boolean -- yup -- that's a bug. It's on my queue now. Thanks.

    Regarding gluegen and import -- yes -- that was my error in the README for as3_crypto_wrapper. I will try to put some docs together for gluegen and get them up which address this.

    Regarding gluegen and supplyFile() -- hmm that should be exposed. I will investigate more.

    Joe
  • metalbot User 15 posts since
    Nov 18, 2008
    Currently Being Moderated
    7. Nov 20, 2008 7:06 PM (in response to matthewbmedia)
    Request: Port AS3 Corelib encoder functionality
    Alrighty, here's a simple wrapper around the encoding part of libjpeg.
    It uses a custom destination manager (some semi-obscure libjpeg feature) to avoid the whole FILE* issue.

    http://hurlant.com/as3_encoder_jpeg.tgz

    You'll need to get libjpeg separately. there's a README.txt in my .tgz file that glosses over the steps.
  • vevedh User 13 posts since
    Oct 15, 2005
    I try compile " http://www.netsieben.com/products/sshlib" without success
  • metalbot User 15 posts since
    Nov 18, 2008
    vevedh, I suspect the OpenSSH portable library would be a smoother ride.

    You'd need to compile OpenSSL first (see the code sample Adobe made available for instructions on how to do that) and the zlib library.

    Once you get the basic stuff compiled, you'd probably want to start hacking the C code a bit, as Alchemy's libc doesn't implement network-related commands yet. Also, calls to the zlib library should be replaced by builtin ByteArray methods where possible, to make things faster.

  • joesteele User 68 posts since
    Nov 16, 2008
    @matthewbmedia - You can use flyield() to release control back to Flash for processing events.
    Here is an example from some code Scott wrote:

    const int LoopSize = 20;

    // don't let gcc inline you
    void loopGuts(int loops) __attribute__((noinline));

    // do the guts of the loop here -- unroll if you want
    void loopGuts(int loops)
    {
    for(int j=0; j<loops; j++) {
    // do a unit of processing
    }
    }

    // here is your main looping routine
    void bigLoop(int loops)
    {
    for(int i=0; i<loops; i++) {
    if((loop % LoopSize) == 0)
    flyield();
    loopGuts(LoopSize);
    }
    }

    The idea is that the inner "guts" routine will run synchronously and the outer routine will run asynchronously. Flash should be more responsive and you will still get most of the speed.
  • Darrin M User 11 posts since
    May 12, 2006
    Currently Being Moderated
    14. Dec 24, 2008 11:48 AM (in response to joesteele)
    Re: Request: Port AS3 Corelib encoder functionality
    I inserted a flyield call into metalbot's as3_jpeg_wrapper.gg and it didn't appear to make any difference, either to the performance of the encoding or the responsiveness of the UI. Encoding still halts UI and rendering. I've made other successful changes so I think I'm building it right.

    /* like reading a file, this time write one row at a time */
    while( cinfo.next_scanline < cinfo.image_height )
    {
    row_pointer[0] = &raw_image24[ cinfo.next_scanline * cinfo.image_width * cinfo.input_components];
    jpeg_write_scanlines( &cinfo, row_pointer, 1 );
    flyield();
    }
  • joesteele User 68 posts since
    Nov 16, 2008
    One additional bit -- Scott mentioned that the (noinline) attribute was not always working. You can tweak the gcc script in achacks to add your function to the $internsyms list. This should prevent the function from being inlined.
  • ethan1el User 1 posts since
    Feb 5, 2009
    Guys, I am interesting in hiring a freelancer to make me this kind of flash applet. The basics required will be - resize before upload using this method (Alchemy + IJQ lib), ability to rotate and preview before upload.

    How much will it cost me? And is there anyone here interested to help me with this project?
  • Bog Imp User 12 posts since
    Feb 15, 2009
    Currently Being Moderated
    18. Feb 15, 2009 8:18 PM (in response to metalbot)
    Re: Request: Port AS3 Corelib encoder functionality
    Hello
    (Sorry if noob questions)
    But i trying make work jpeg-6b on my pc but i have problems, can you help me?
    i have Win XP, simple test like "samples/stringecho/" or smth else work fine(compile c to swc).

    But when i try compile "jpeg-6b" i am stuck
    what i do:
    1.unpack
    2.open cygwin
    3.cd to folder and run
    $./configure
    4.wait all is ok i have "Makefile"
    5 when i try run
    $make
    i have troubles with
    "$ make
    MAKE Version 5.2 Copyright (c) 1987, 1998 Inprise Corp.
    rm -f libjpeg.a
    ar rc libjpeg.a jcapimin.o jcapistd.o jctrans.o jcparam.o jdatadst.o j
    cinit.o jcmaster.o jcmarker.o jcmainct.o jcprepct.o jccoefct.o jccolor.o jcsam
    ple.o jchuff.o jcphuff.o jcdctmgr.o jfdctfst.o jfdctflt.o jfdctint.o jdapimi
    n.o jdapistd.o jdtrans.o jdatasrc.o jdmaster.o jdinput.o jdmarker.o jdhuff.o j
    dphuff.o jdmainct.o jdcoefct.o jdpostct.o jddctmgr.o jidctfst.o jidctflt.o j
    idctint.o jidctred.o jdsample.o jdcolor.o jquant1.o jquant2.o jdmerge.o jcomap
    i.o jutils.o jerror.o jmemmgr.o jmemnobs.o
    /usr/bin/ar: jcapimin.o: No such file or directory

    ** error 1 ** deleting libjpeg.a"
    Can you help me ?
    Also where i must take "jcapimin.o" and who must generate "jpeg.l.bc".
  • notnick User 76 posts since
    Jul 1, 2007
    Currently Being Moderated
    19. Feb 16, 2009 6:13 AM (in response to Bog Imp)
    Re: Request: Port AS3 Corelib encoder functionality
    try this option
    1.open cygwin
    quote:

    tar xvf jpegsrc.v6b.tar.gz

    2.cd jpeg-6b
    quote:

    alc-on;./configure CFLAGS='-E';alc-off
    alc-on;make CFLAGS='-O3';alc-off
    alc-on;make clean;alc-off


    take jpeg.l.bc in the directory - /jpeg-6b

  • Bog Imp User 12 posts since
    Feb 15, 2009
    Currently Being Moderated
    20. Feb 16, 2009 6:17 AM (in response to notnick)
    Re: Request: Port AS3 Corelib encoder functionality
    when i run
    $alc-on;make CFLAGS='-O3';alc-off

    i have
    Bog Imp@imp /cygdrive/c/alchemy/samples/as3_encoder_jpeg/jpeg-6b
    $ alc-on;make CFLAGS='-O3';alc-off
    MAKE Version 5.2 Copyright (c) 1987, 1998 Inprise Corp.
    rm -f libjpeg.a
    ar rc libjpeg.a jcapimin.o jcapistd.o jctrans.o jcparam.o jdatadst.o j
    cinit.o jcmaster.o jcmarker.o jcmainct.o jcprepct.o jccoefct.o jccolor.o jcsam
    ple.o jchuff.o jcphuff.o jcdctmgr.o jfdctfst.o jfdctflt.o jfdctint.o jdapimi
    n.o jdapistd.o jdtrans.o jdatasrc.o jdmaster.o jdinput.o jdmarker.o jdhuff.o j
    dphuff.o jdmainct.o jdcoefct.o jdpostct.o jddctmgr.o jidctfst.o jidctflt.o j
    idctint.o jidctred.o jdsample.o jdcolor.o jquant1.o jquant2.o jdmerge.o jcomap
    i.o jutils.o jerror.o jmemmgr.o jmemnobs.o
    /usr/bin/ar: jcapistd.o: No such file or directory

    ** error 1 ** deleting libjpeg.a
  • notnick User 76 posts since
    Jul 1, 2007
    Check compiler:
    alc-on;gcc --help;alc-off
    that there can be seen?
  • notnick User 76 posts since
    Jul 1, 2007
    Currently Being Moderated
    22. Feb 16, 2009 8:10 AM (in response to Bog Imp)
    Re: Request: Port AS3 Corelib encoder functionality
    if before doing. / configure
    in the beginning, do make clean : alc-on;make clean;alc-off
  • Bog Imp User 12 posts since
    Feb 15, 2009
    $ alc-on;gcc --help;alc-off
    Usage: llvm-gcc [options] file...
    Options:
    -pass-exit-codes Exit with highest error code from a phase
    --help Display this information
    --target-help Display target specific command line options
    (Use '-v --help' to display command line options of sub-processes)
    -dumpspecs Display all of the built in spec strings
    -dumpversion Display the version of the compiler
    -dumpmachine Display the compiler's target processor
    -print-search-dirs Display the directories in the compiler's search path

    ****

    after that i try

    Bog Imp@imp /cygdrive/c/alchemy/samples/as3_encoder_jpeg/jpeg-6b
    $ alc-on;make clean;alc-off
    MAKE Version 5.2 Copyright (c) 1987, 1998 Inprise Corp.
    rm -f *.o *.lo libjpeg.a libjpeg.la
    rm -f cjpeg djpeg jpegtran rdjpgcom wrjpgcom
    rm -f ansi2knr core testout* config.log config.status
    rm -f -r knr .libs _libs

    Bog Imp@imp /cygdrive/c/alchemy/samples/as3_encoder_jpeg/jpeg-6b
    $ alc-on;make;alc-off
    MAKE Version 5.2 Copyright (c) 1987, 1998 Inprise Corp.
    rm -f libjpeg.a
    ar rc libjpeg.a jcapimin.o jcapistd.o jctrans.o jcparam.o jdatadst.o j
    cinit.o jcmaster.o jcmarker.o jcmainct.o jcprepct.o jccoefct.o jccolor.o jcsam
    ple.o jchuff.o jcphuff.o jcdctmgr.o jfdctfst.o jfdctflt.o jfdctint.o jdapimi
    n.o jdapistd.o jdtrans.o jdatasrc.o jdmaster.o jdinput.o jdmarker.o jdhuff.o j
    dphuff.o jdmainct.o jdcoefct.o jdpostct.o jddctmgr.o jidctfst.o jidctflt.o j
    idctint.o jidctred.o jdsample.o jdcolor.o jquant1.o jquant2.o jdmerge.o jcomap
    i.o jutils.o jerror.o jmemmgr.o jmemnobs.o
    /usr/bin/ar: jcapimin.o: No such file or directory

    ** error 1 ** deleting libjpeg.a




  • Bog Imp User 12 posts since
    Feb 15, 2009
    Currently Being Moderated
    24. Feb 16, 2009 10:29 AM (in response to Bog Imp)
    Re: Request: Port AS3 Corelib encoder functionality
    Sorry for my offtope but i have problem with make its my delphi he also have "Make"
    in result i try use delphi make in Cygwin
    if you have mak and response
    MAKE Version 5.2 Copyright (c) 1987, 1998 Inprise Corp.
    Fatal: Unable to open makefile

    It's delphi.
    Now i install make from devel folder
    seems work all corrects.....
  • piolo96 User 19 posts since
    Feb 17, 2009
    Currently Being Moderated
    25. Feb 17, 2009 1:36 PM (in response to notnick)
    Request: Port AS3 Corelib encoder functionality
    hi Notnick I followed what you mentioned on post 46 and everything ran just right.
    I was wondering what the next step for this to build the .swc file I need would be.
    what am I suppose to do with the jpeg.l.bc in the directory - /jpeg-6b

    Thanks so much for all the help.
  • notnick User 76 posts since
    Jul 1, 2007
    Currently Being Moderated
    26. Feb 17, 2009 10:46 PM (in response to piolo96)
    Request: Port AS3 Corelib encoder functionality
    Depending on the purpose:
    if you write own module on Alchemy - С/C ++ for example example.c. Then use for compilation in SWC.
    alc-on;gcc example.c -O3- Wall -swc -o example.swc -L.../jpeg-6b -ljpeg;alc-off
    But if you ask in a theme context - look above...
    The post from - Metalbot.There is a link on archive with an example and is used - Makefile.

    quote:

    There it is written - GLUEGEN a file (a mix "C(Alchemy)" and "AS3") with extention *.gg and accordingly all will be on another. Look an example at Metalbot and it Makefile

    Process in this case the such:
    It is taken separately "С" a part from gluegen *.gg a file - glue.c and AS3 a part glue.as
    And in SWC it is compiled only - glue.c
    glue.as It is used as a class in AS3.
  • piolo96 User 19 posts since
    Feb 17, 2009
    I tried doing what Metalbot sugested but as I went through it all and was on the last step to make the .swc file. This errors comes up:

    ===================================================
    Macintosh-2:jpeg-6b userName$ make
    gcc -o cjpeg cjpeg.o rdppm.o rdgif.o rdtarga.o rdrle.o rdbmp.o rdswitch.o cdjpeg.o libjpeg.a
    ld warning: in cjpeg.o, file is not of required architecture
    ld warning: in rdppm.o, file is not of required architecture
    ld warning: in rdgif.o, file is not of required architecture
    ld warning: in rdtarga.o, file is not of required architecture
    ld warning: in rdrle.o, file is not of required architecture
    ld warning: in rdbmp.o, file is not of required architecture
    ld warning: in rdswitch.o, file is not of required architecture
    ld warning: in cdjpeg.o, file is not of required architecture
    ld warning: in libjpeg.a, file is not of required architecture
    Undefined symbols:
    "_main", referenced from:
    start in crt1.10.5.o
    ld: symbol(s) not found
    collect2: ld returned 1 exit status
    make: *** [cjpeg] Error 1
    ===================================================

    Step 5 when it says to run make. That is when the error comes up.

    thanks in advance for any help.

  • notnick User 76 posts since
    Jul 1, 2007
    Currently Being Moderated
    28. Feb 20, 2009 4:51 PM (in response to piolo96)
    Re: Request: Port AS3 Corelib encoder functionality
    Open a file in HEX editor, for example cjpeg.o -- The first two bytes must be 00000000h: 42 43; or in text two simbol - BC.
    This is necessary. LLVM unnecessarily just to understand its format.
    How did you met -. / Configure?
    Have alc-on; with this?
  • piolo96 User 19 posts since
    Feb 17, 2009
    Currently Being Moderated
    29. Feb 25, 2009 11:25 AM (in response to matthewbmedia)
    Request: Port AS3 Corelib encoder functionality
    I followed the following:
    Download jpegsrc.v6b.tar.gz
    Through terminal I ran the following lines:
    tar xvf jpegsrc.v6b.tar.gz
    cd jpeg-6b
    alc-on;./configure CFLAGS='-E';alc-off
    alc-on;make CFLAGS='-O3';alc-off
    alc-on;make clean;alc-off

    After this steps I followed the steps on the Metabolt link.
    Make a new directory jpeg
    take jpeg.l.bc in the directory - /jpeg
    Go on to the directory jpeg
    run the following:
    cd ../jpeg-6b
    make

    After this I get the error that I already mentioned in the last post.
    I did open the file jpeg.l.bc on a HEX Editor and got the (42, 43) which in symbol would be BC at the beginning

    Any suggestions on what I am doing wrong? Any help would be greatly appreciated.

    Thanks for all the help.
  • notnick User 76 posts since
    Jul 1, 2007
    Currently Being Moderated
    30. Feb 27, 2009 3:02 AM (in response to piolo96)
    Re: Request: Port AS3 Corelib encoder functionality
    Sorry for the Mac may be what is the option(
    I will try later on MAC OS)
    try to install VirtualBox with Ubuntu8.10 and it works there fine.
  • myMacromediaScreenName User 22 posts since
    Jun 15, 2006
    radScientist, Metalbot

    Confirming approximately 1.5 sec on a Windows dual core 2.1 GHz.
  • notnick User 76 posts since
    Jul 1, 2007
    Currently Being Moderated
    32. Mar 1, 2009 2:11 PM (in response to piolo96)
    Re: Request: Port AS3 Corelib encoder functionality
    Today checked alchemy to MAKOSX-leo10.5
    Everything works fine
    The latest version of Xcode 3.1.2
    i686-apple-darwin9-gcc-4.0.1
    perl, v5.8.8
    java version "1.5.0_16"
    Edit the file: / private / etc / bashrc
    PATH=/Users/tester/flex_sdk_3/bin:$ALCHEMY_HOME/achacks:$PATH
    source /Users/tester/alchemy/alchemy-setup
  • MB2 User 4 posts since
    Jan 20, 2008
    For us here just joining the thread could we get a summary of what is working (and what is not working) on the jpeg encoder port / build with Alchemy on Windows? Perhaps an overview of what stage the port is at? Working, or not... -MB
  • notnick User 76 posts since
    Jul 1, 2007
    Currently Being Moderated
    34. Mar 2, 2009 5:11 AM (in response to MB2)
    Re: Request: Port AS3 Corelib encoder functionality

    You can port the library from source http://www.ijg.org/files/, in LLVM c help - alchemy sdk (on any OS-mac, windows, linux), and connect to jpeg.l.bc project alchemy.
    For example - you can take the archive from Metalbot (see above) and try.
    This example works and converts Bitmap array of jpeg.
    How fast compared to AS3/Alchemy? a little faster:)
    But speed - This is the main goal.
    Alchemy has not yet been released. Let's wait for improvements, and especially support for multithreading - today, this important function is turned off. Why? Let us ask the support ... to the MAX2007 is shown;)
  • piolo96 User 19 posts since
    Feb 17, 2009
    Thanks notnick for all that, hey myMacromediaScreenName you mentioned you were able to successfully test the jpeg lib, I was wondering if you could share with us the c file you used to compile the swc. I been trying something here and there but haven't gotten any results yet. thanks a lot
  • notnick User 76 posts since
    Jul 1, 2007
    Currently Being Moderated
    36. Mar 4, 2009 1:39 PM (in response to piolo96)
    Re: Request: Port AS3 Corelib encoder functionality
    This is a project of Metalbot
    file included
    i am change in make flag -O5
    test results
    AS3 JPEG ENCODING: 606ms.
    jpg.length = 2362
    setting up as3_jpeg_wrapper library
    C JPEG ENCODING: 206ms.
  • piolo96 User 19 posts since
    Feb 17, 2009
    great example notnick thank you very much. did you ever run into a problem with the jpeg_std_error().

    Undefined sym: _jpeg_std_error
    at <anonymous>()
    at <anonymous>()
    at com.hurlant.jpeg::as3_jpeg_wrapper$/write_jpeg_file()[/Users/user/Doc uments/Flex Builder 3/jpegTest/src/com/hurlant/jpeg/as3_jpeg_wrapper.as:8]
    at jpegTest/testWrite()[/Users/user/Documents/Flex Builder 3/jpegTest/src/jpegTest.mxml:32]
    at jpegTest/___jpegTest_Button1_click()[/Users/user/Documents/Flex Builder 3/jpegTest/src/jpegTest.mxml:44]

    I tried this example with your swc then I went and compiled it myself to double check. When I did, I ran into this. I made sure I had my jpeg-6b library installed and on the right path and everything looks right, I dont have any error in the moment of compiling. thank you
  • notnick User 76 posts since
    Jul 1, 2007
    Currently Being Moderated
    38. Mar 11, 2009 11:56 AM (in response to piolo96)
    Re: Request: Port AS3 Corelib encoder functionality
    I do not compile in Flex project.Actionscript project is only. SWC does not require libraries.
    This is the fully compiled.
  • piolo96 User 19 posts since
    Feb 17, 2009
    I am not sure I understand what you are saying. Once the SWC is compiled I use it on my Flash / Flex projects. You mean you did not use the jpeg library on your project? I think you did because on the .gg file you have the line in which you include the jpeg lib (#include <jpeglib.h>) and then you are using this dealing with the ByteArray you pass into it through the write_jpeg_file method. Does that make any sense? My issue is that even though I do include this file and it seems to be working correctly, for some reason I have some limits on using it because I can't use any methods that this is supposed to bring in.
    Thank you.
  • notnick User 76 posts since
    Jul 1, 2007
    Currently Being Moderated
    40. Mar 11, 2009 6:45 PM (in response to piolo96)
    Request: Port AS3 Corelib encoder functionality
    It seemed to me that you need is an example:) I gave this as there is a project of "Metalbot"
    My there's nothing:)
    I can compile jpeg.l.bc but I just did not handle the porting of alchemy.
    Accordingly, you will need for this example of "Metalbot" (perhaps it will appear here) to write a class in C -alchemy where the will support any metod of the library
  • piolo96 User 19 posts since
    Feb 17, 2009
    yes if you could, that would be awesome. What do we need to compile the jpeg.l.bc for? what's the use for it? And if you could please help me on why I can't seem to be able to use jpeg lib or any other lib that'd be great!
  • notnick User 76 posts since
    Jul 1, 2007
    Currently Being Moderated
    42. Mar 13, 2009 9:01 PM (in response to piolo96)
    Re: Request: Port AS3 Corelib encoder functionality
    The fact that you can write in C you can not write in AS3.
    To use C libraries, together with AS3 - using C alchemy.
    To do this you need to compile the C library in alchemy and
    write a class in C Alchemy serves as a mediator between the C and AS3.
    Where a minimum must be agreed upon data types.
    You can see an example of Metalbot in action.
    Or that it does not work?
    If you write something to show the code for clarity.
  • piolo96 User 19 posts since
    Feb 17, 2009
    Currently Being Moderated
    43. Mar 16, 2009 3:39 PM (in response to notnick)
    Request: Port AS3 Corelib encoder functionality
    I did try Metabolt's sample in action. It does work, BUT at the moment I compile the C file that serves as the mediator with Alchemy to build a new SWC file, and it does not work. Metabol are you around? Can you get in here and explain me why my JPEG library is not getting compiled or something. I have a very simple example that I apply standard alchemy methods but as soon as I start writing some of the lines of Metabolts C file, it throws me an error. The error that I mentioned before,, like 2 posts ago. Here we go: jpegCompression
    If you could take a look at that and tell me where I went wrong, and how will I be able to use the jpeg lib for the compression of images that would be great.
    Thank you
  • notnick User 76 posts since
    Jul 1, 2007
    Currently Being Moderated
    44. Mar 16, 2009 8:45 PM (in response to piolo96)
    Request: Port AS3 Corelib encoder functionality
    It is clear now.
    A few questions I do not see the logic in your application where load jpg. What goal? Decoding? Resizing?
    At the moment I run your example but I do not see any errors.
    If it is possible to give exact information.
    From the documentation for the jpeg-6b note:
    quote:

    We provide a set of library routines for reading and writing JPEG image files,
    plus two sample applications "cjpeg" and "djpeg", which use the library to
    perform conversion between JPEG and some other popular image file formats..


    Sorry that I do not quite understand :)
  • piolo96 User 19 posts since
    Feb 17, 2009
    Currently Being Moderated
    45. Mar 16, 2009 9:50 PM (in response to notnick)
    Re: Request: Port AS3 Corelib encoder functionality
    Ok so now that you have seen what I have done. The purpose of the application is to resize images down from however big they are, bring them down to usable size. On my C file if you look from line 83 to 109 they are commented out. These are the methods I believe I will be using with the jpeg lib to make it happen. The main issue is that the library is just not working for me and I am not able to get it working. I am using what the "cjpeg" would apply to compress a image to jpeg format, only difference is I am getting a ByteArray, making it into a file so that I could inserted and used on the library. Hope that helps.
  • notnick User 76 posts since
    Jul 1, 2007
    Currently Being Moderated
    46. Mar 17, 2009 7:25 PM (in response to piolo96)
    Re: Request: Port AS3 Corelib encoder functionality
    This minimal changed
    Try changing it from Metalbot project the file - JpegTest.as

    quote:

    package {
    import flash.display.BitmapData;
    import flash.display.Bitmap;
    import flash.display.Sprite;
    import flash.geom.Rectangle;
    import flash.utils.ByteArray;
    import flash.utils.getTimer;
    import flash.events.Event;
    import flash.display.Loader;
    import flash.net.URLRequest;

    import hurlant.jpeg.as3_jpeg_wrapper;
    import com.adobe.images.JPGEncoder;

    public class JpegTest extends Sprite {
    private var _loader:Loader = new Loader();
    public function JpegTest() {

    trace("hello.");

    testWrite();

    }
    private function testWrite():void {


    _loader.contentLoaderInfo.addEventListener(Event.COMPLETE,onComplete) ;
    _loader.load(new URLRequest("acura.jpg"));
    }
    public function onComplete(event:Event):ByteArray{
    var image:Bitmap = Bitmap(_loader.content);
    var b:BitmapData = image.bitmapData;
    addChild(image);

    // as3 way
    var t1:int = getTimer();
    var s:JPGEncoder = new JPGEncoder();
    var jpg:ByteArray = s.encode(b);
    trace("AS3 JPEG ENCODING: "+(getTimer()-t1)+"ms.");
    trace("jpg.length = "+jpg.length);


    // C way
    var t2:int = getTimer();
    var ba:ByteArray = b.getPixels(new Rectangle(0,0,320,200));
    var ret:ByteArray = as3_jpeg_wrapper.write_jpeg_file(ba, 320, 200, 3, 2);
    trace(" C JPEG ENCODING: "+(getTimer()-t2)+"ms.");

    trace(" ret.length="+ret.length);
    return ret;
    }

    }
    }

    AS3 JPEG ENCODING: 1199ms.
    jpg.length = 17388
    setting up as3_jpeg_wrapper library
    C JPEG ENCODING: 245ms.
    ret.length=8963
    But still need to resize the image. Probably what is the manipulation of the Matrix. Unfortunately this has not happened.
    But mostly it works.
  • notnick User 76 posts since
    Jul 1, 2007
    Currently Being Moderated
    47. Mar 17, 2009 7:44 PM (in response to notnick)
    Request: Port AS3 Corelib encoder functionality
    //It added the conversion from ByteArray to Bitmap
    package {
    import com.adobe.images.JPGEncoder;

    import flash.display.Bitmap;
    import flash.display.BitmapData;
    import flash.display.Loader;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.geom.Rectangle;
    import flash.net.URLRequest;
    import flash.utils.ByteArray;
    import flash.utils.getTimer;

    import hurlant.jpeg.as3_jpeg_wrapper;

    public class JpegTest extends Sprite {
    private var _loader:Loader = new Loader();
    private var nJpg:Loader = new Loader();
    public function JpegTest() {

    trace("hello.");

    testWrite();

    }
    private function testWrite():void {


    _loader.contentLoaderInfo.addEventListener(Event.COMPLETE,onComplete) ;
    _loader.load(new URLRequest("acura.jpg"));
    }
    public function onComplete(event:Event):void{
    var image:Bitmap = Bitmap(_loader.content);
    image.width = image.width/2;
    image.height =image.height/2;
    var b:BitmapData = image.bitmapData;
    addChild(image);

    // as3 way
    var t1:int = getTimer();
    var s:JPGEncoder = new JPGEncoder();
    var jpg:ByteArray = s.encode(b);
    trace("AS3 JPEG ENCODING: "+(getTimer()-t1)+"ms.");
    trace("jpg.length = "+jpg.length);
    trace(image.width);
    trace(image.height);

    // C way
    var t2:int = getTimer();
    var ba:ByteArray = b.getPixels(new Rectangle(0,0,image.width,image.height));
    var ret:ByteArray = as3_jpeg_wrapper.write_jpeg_file(ba, image.width, image.height, 3, 2);
    trace(" C JPEG ENCODING: "+(getTimer()-t2)+"ms.");


    //It added the conversion from ByteArray to Bitmap
    nJpg.contentLoaderInfo.addEventListener(Event.COMPLETE,addnewjpg);
    nJpg.loadBytes(ret,null);

    }
    private function addnewjpg(event:Event):void{
    var im:Bitmap = Bitmap(nJpg.content);
    var bmpd:BitmapData = im.bitmapData;
    trace(bmpd.width);
    trace(bmpd.height);
    im.x = 200;
    this.addChild(im);

    }

    }
    }
  • piolo96 User 19 posts since
    Feb 17, 2009
    cool man that's great so we got the AS3 part covered. I appreciate the help. Now the C part where I got to use the library and apply some kind of routine to compress the image and spit it back out the ByteArrat so that I could use the compressed image in my flash application. That's the part where I am struggling. Thanks again
  • notnick User 76 posts since
    Jul 1, 2007
    Currently Being Moderated
    49. Mar 18, 2009 2:41 AM (in response to piolo96)
    Re: Request: Port AS3 Corelib encoder functionality
    All ok! I was interested but there is the main point
    I noticed that the real picture is very big difference in speed, between AS3 and Alchemy
    I do not deepened in the reasons. But look at it.
    AS3 JPEG ENCODING: 1199ms.
    C JPEG ENCODING: 245ms.
    In the original example, where used only generic BitmapData differences were much smaller.
    AS3 JPEG ENCODING: 606ms.
    C JPEG ENCODING: 206ms.
    It seemed to me that you have a problem with C? You can not use the library? What are the causes?
1 2 Previous Next

Actions

More Like This

  • Retrieving data ...

Bookmarked By (0)

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points