Skip navigation
Currently Being Moderated

Request: Port AS3 Corelib encoder functionality

Nov 19, 2008 4:07 PM

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?
 
Replies 1 2 Previous Next
  • Currently Being Moderated
    Nov 19, 2008 4:24 PM   in reply to matthewbmedia
    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.
     
    |
    Mark as:
  • Currently Being Moderated
    Nov 19, 2008 5:09 PM   in reply to matthewbmedia
    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.

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 19, 2008 9:05 PM   in reply to matthewbmedia
    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.
     
    |
    Mark as:
  • Currently Being Moderated
    Nov 20, 2008 10:22 AM   in reply to matthewbmedia
    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
     
    |
    Mark as:
  • Currently Being Moderated
    Nov 20, 2008 4:15 PM   in reply to metalbot
    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
     
    |
    Mark as:
  • Currently Being Moderated
    Nov 20, 2008 6:06 PM   in reply to matthewbmedia
    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.
     
    |
    Mark as:
  • Currently Being Moderated
    Nov 24, 2008 5:24 PM   in reply to matthewbmedia
    I try compile " http://www.netsieben.com/products/sshlib" without success
     
    |
    Mark as:
  • Currently Being Moderated
    Nov 24, 2008 7:36 PM   in reply to matthewbmedia
    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.

     
    |
    Mark as:
  • Currently Being Moderated
    Dec 15, 2008 1:04 PM   in reply to matthewbmedia
    @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.
     
    |
    Mark as:
  • Currently Being Moderated
    Dec 24, 2008 10:48 AM   in reply to joesteele
    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();
    }
     
    |
    Mark as:
  • Currently Being Moderated
    Jan 8, 2009 9:59 AM   in reply to matthewbmedia
    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.
     
    |
    Mark as:
  • Currently Being Moderated
    Feb 5, 2009 3:31 AM   in reply to matthewbmedia
    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?
     
    |
    Mark as:
  • Currently Being Moderated
    Feb 15, 2009 7:18 PM   in reply to metalbot
    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".
     
    |
    Mark as:
  • Currently Being Moderated
    Feb 16, 2009 5:13 AM   in reply to Bog Imp
    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

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 16, 2009 5:17 AM   in reply to notnick
    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
     
    |
    Mark as:
  • Currently Being Moderated
    Feb 16, 2009 7:04 AM   in reply to matthewbmedia
    Check compiler:
    alc-on;gcc --help;alc-off
    that there can be seen?
     
    |
    Mark as:
  • Currently Being Moderated
    Feb 16, 2009 7:10 AM   in reply to Bog Imp
    if before doing. / configure
    in the beginning, do make clean : alc-on;make clean;alc-off
     
    |
    Mark as:
  • Currently Being Moderated
    Feb 16, 2009 7:31 AM   in reply to matthewbmedia
    $ 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




     
    |
    Mark as:
  • Currently Being Moderated
    Feb 16, 2009 9:29 AM   in reply to Bog Imp
    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.....
     
    |
    Mark as:
  • Currently Being Moderated
    Feb 17, 2009 12:36 PM   in reply to notnick
    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.
     
    |
    Mark as:
  • Currently Being Moderated
    Feb 17, 2009 9:46 PM   in reply to piolo96
    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.
     
    |
    Mark as:
  • Currently Being Moderated
    Feb 20, 2009 2:11 PM   in reply to matthewbmedia
    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.

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 20, 2009 3:51 PM   in reply to piolo96
    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?
     
    |
    Mark as:
  • Currently Being Moderated
    Feb 25, 2009 10:25 AM   in reply to matthewbmedia
    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.
     
    |
    Mark as:
  • Currently Being Moderated
    Feb 27, 2009 2:02 AM   in reply to piolo96
    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.
     
    |
    Mark as:
  • Currently Being Moderated
    Feb 28, 2009 12:09 PM   in reply to matthewbmedia
    radScientist, Metalbot

    Confirming approximately 1.5 sec on a Windows dual core 2.1 GHz.
     
    |
    Mark as:
  • Currently Being Moderated
    Mar 1, 2009 1:11 PM   in reply to piolo96
    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
     
    |
    Mark as:
  • Currently Being Moderated
    Mar 1, 2009 5:05 PM   in reply to matthewbmedia
    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
     
    |
    Mark as:
  • Currently Being Moderated
    Mar 2, 2009 4:11 AM   in reply to MB2

    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;)
     
    |
    Mark as:
  • Currently Being Moderated
    Mar 3, 2009 11:04 AM   in reply to myMacromediaScreenName
    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
     
    |
    Mark as:
  • Currently Being Moderated
    Mar 4, 2009 12:39 PM   in reply to piolo96
    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.
     
    |
    Mark as:
  • Currently Being Moderated
    Mar 11, 2009 9:15 AM   in reply to matthewbmedia
    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
     
    |
    Mark as:
  • Currently Being Moderated
    Mar 11, 2009 10:56 AM   in reply to piolo96
    I do not compile in Flex project.Actionscript project is only. SWC does not require libraries.
    This is the fully compiled.
     
    |
    Mark as:
  • Currently Being Moderated
    Mar 11, 2009 3:37 PM   in reply to matthewbmedia
    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.
     
    |
    Mark as:
1 2 Previous Next
Actions

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points