Skip navigation
matthewbmedia
Currently Being Moderated

Request: Port AS3 Corelib encoder functionality

Nov 19, 2008 5: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?
  • Currently Being Moderated
    Nov 19, 2008 5:24 PM
    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 6:09 PM
    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
    Community Member
    Nov 19, 2008 10:05 PM
    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 11:22 AM
    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
    Community Member
    Nov 20, 2008 5:15 PM
    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
    Community Member
    Nov 20, 2008 7:06 PM
    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 6:24 PM
    I try compile " http://www.netsieben.com/products/sshlib" without success
    |
    Mark as:
  • Currently Being Moderated
    Community Member
    Nov 24, 2008 8:36 PM
    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
    Community Member
    Dec 15, 2008 2:04 PM
    @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 11:48 AM
    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
    Community Member
    Jan 8, 2009 10:59 AM
    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 4:31 AM
    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 8:18 PM
    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
    Community Member
    Feb 16, 2009 6:13 AM
    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
    Community Member
    Feb 16, 2009 6:17 AM
    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
    Community Member
    Feb 16, 2009 8:04 AM
    Check compiler:
    alc-on;gcc --help;alc-off
    that there can be seen?
    |
    Mark as:
  • Currently Being Moderated
    Community Member
    Feb 16, 2009 8:10 AM
    if before doing. / configure
    in the beginning, do make clean : alc-on;make clean;alc-off
    |
    Mark as:
  • Currently Being Moderated
    Community Member
    Feb 16, 2009 8:31 AM
    $ 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
    Community Member
    Feb 16, 2009 10:29 AM
    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
    Community Member
    Feb 17, 2009 1:36 PM
    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
    Community Member
    Feb 17, 2009 10:46 PM
    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
    Community Member
    Feb 20, 2009 3:11 PM
    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
    Community Member
    Feb 20, 2009 4:51 PM
    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
    Community Member
    Feb 25, 2009 11:25 AM
    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
    Community Member
    Feb 27, 2009 3:02 AM
    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 1:09 PM
    radScientist, Metalbot

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

    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
    Community Member
    Mar 3, 2009 12:04 PM
    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
    Community Member
    Mar 4, 2009 1:39 PM
    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
    Community Member
    Mar 11, 2009 10:15 AM
    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
    Community Member
    Mar 11, 2009 11:56 AM
    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
    Community Member
    Mar 11, 2009 4:37 PM
    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:
  • Currently Being Moderated
    Community Member
    Mar 11, 2009 6:45 PM
    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
    |
    Mark as:
  • Currently Being Moderated
    Community Member
    Mar 13, 2009 3:12 PM
    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!
    |
    Mark as:
  • Currently Being Moderated
    Community Member
    Mar 13, 2009 9:01 PM
    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.
    |
    Mark as:
  • Currently Being Moderated
    Community Member
    Mar 16, 2009 3:39 PM
    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
    |
    Mark as:
  • Currently Being Moderated
    Community Member
    Mar 16, 2009 8:45 PM
    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 :)
    |
    Mark as:
  • Currently Being Moderated
    Community Member
    Mar 16, 2009 9:50 PM
    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.
    |
    Mark as:
  • Currently Being Moderated
    Community Member
    Mar 17, 2009 7:25 PM
    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.
    |
    Mark as:
  • Currently Being Moderated
    Community Member
    Mar 17, 2009 7:44 PM
    //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);

    }

    }
    }
    |
    Mark as:
  • Currently Being Moderated
    Community Member
    Mar 17, 2009 8:51 PM
    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
    |
    Mark as:
  • Currently Being Moderated
    Community Member
    Mar 18, 2009 2:41 AM
    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?
    |
    Mark as:
1 2 Previous Next
Actions

More Like This

  • Retrieving data ...

Bookmarked By (0)

Legend

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