Skip navigation

Request: Port AS3 Corelib encoder functionality

Nov 19, 2008 4:07 PM

  Latest reply: sectore, Jun 21, 2009 8:39 AM
Replies 1 2 3 2 Previous Next
  • Currently Being Moderated
    Mar 18, 2009 10:01 AM   in reply to notnick
    Yes indeed is noticeable faster, and yes I do have problems with the use of the library. For example lets take a look at MetalBot's project. The following is his as3_jpeg_wrapper.gg

    { // start pass-thru C code

    #include <stdlib.h>
    #include <stdio.h>
    #include <jpeglib.h> //This is the library I want to use

    #include "badatadst.h"

    void sztrace(char*);

    AS3_Val no_params = NULL;
    AS3_Val zero_param = NULL;
    AS3_Val ByteArray_class = NULL;

    #define GGINIT_DEFINED true
    static void ggInit()
    {
    sztrace("setting up as3_jpeg_wrapper library");

    no_params = AS3_Array("");
    zero_param = AS3_Int(0);
    AS3_Val flash_utils_namespace = AS3_String("flash.utils");
    ByteArray_class = AS3_NSGetS(flash_utils_namespace, "ByteArray");
    AS3_Release(flash_utils_namespace);
    }

    /* Copy the byteArray data into a malloc'd buffer */
    static void* newMallocFromByteArray(AS3_Val byteArray, unsigned int* size)
    {
    AS3_Val byteArraySize = AS3_GetS(byteArray, "length");
    *size = AS3_IntValue(byteArraySize);
    AS3_Release(byteArraySize);
    void* bytes = malloc(*size);
    AS3_SetS(byteArray, "position", zero_param);
    AS3_ByteArray_readBytes((char*)bytes, byteArray, (int)*size);
    return bytes;
    }

    /* end pass-thru C code */
    }

    import flash.utils.ByteArray;

    public function write_jpeg_file(data:ByteArray, width:int, height:int, bytes_per_pixel:int, color_space:int):ByteArray {
    struct jpeg_compress_struct cinfo;
    struct jpeg_error_mgr jerr;

    unsigned int size = 0;
    unsigned char* raw_image32 = newMallocFromByteArray(data, &size);
    unsigned char* raw_image24 = (unsigned char*)malloc(size*3/4);

    AS3_Val array = AS3_New(ByteArray_class, no_params);

    /* this is a pointer to one row of image data */
    JSAMPROW row_pointer[1];

    /* semi-lame conversion from 32bit pixels to 24bit pixels. */
    int i=0,j=0;
    while (i++<size) {
    raw_image24[j++]=raw_image32[i++];
    raw_image24[j++]=raw_image32[i++];
    raw_image24[j++]=raw_image32[i++];
    }

    cinfo.err = jpeg_std_error( &jerr ); // From this line and on I get errors when trying to compile and use in flash / flex, etc.
    jpeg_create_compress(&cinfo);
    jpeg_bytearray_dest(&cinfo, array);

    /* Setting the parameters of the output file here */
    cinfo.image_width = width;
    cinfo.image_height = height;
    cinfo.input_components = bytes_per_pixel;
    cinfo.in_color_space = color_space;
    /* default compression parameters, we shouldn't be worried about these */
    jpeg_set_defaults( &cinfo );
    /* Now do the compression .. */
    jpeg_start_compress( &cinfo, TRUE );
    /* 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 );
    }
    /* clean up after we're done compressing */
    jpeg_finish_compress( &cinfo );
    jpeg_destroy_compress( &cinfo );

    free(raw_image32);
    free(raw_image24);

    return array;
    }

    In the function write_jpeg_file is all the functionality that will be used later on in flash / flex through the .SWC file.

    Now when I try to compile this .gg file with gluegen and then through gcc, to make a NEW as3_jpeg_wrapper.swc that should be just like MetalBot original .SWC file. I do not seem to get any error compiling, BUT at the moment I go into flash and replace the new SWC for the old and test the swf movie, it throws me an error,

    Undefined sym: _jpeg_std_error
    at <anonymous>()
    at <anonymous>()

    According to the Undefined sym: _jpeg_std_error, that would have to do with the line cinfo.err = jpeg_std_error( &jerr );
    I never changed a thing from this file and so that is the main issue I have. Without changing a thing, a project that was working properly, I just recompiled the SWC and it does not work anymore. I hope this makes everything clear.
     
    |
    Mark as:
  • Currently Being Moderated
    Mar 18, 2009 10:03 AM   in reply to notnick
    Sorry I sent the message twice.
     
    |
    Mark as:
  • Currently Being Moderated
    Mar 18, 2009 5:46 PM   in reply to piolo96
    Take this Archive
    Try to compile your swc using files from the archive.
    Unfortunately I can not repeat the problem. I have everything compiled without any problems
     
    |
    Mark as:
  • Currently Being Moderated
    Mar 18, 2009 9:02 PM   in reply to notnick
    Is there a way you could walk me through the way you get to the end of it ( the whole process).
    (assuming we don't have the jpeg lib installed) Starting from the point where we download MetalBot's project and we start building from the as3_jpeg_wrapper.gg he has until we get the as3_jpeg_wrapper.swc and we go inside flash / flex and try it with the JpegTest.as

    Thank you
     
    |
    Mark as:
  • Currently Being Moderated
    Apr 2, 2009 2:47 AM   in reply to matthewbmedia
    hello i need your help.
    I use ONLY Abode Flash CS4 (i haven`t any FlashDevelop, Adobe Flex SDK).

    I make flash uploader, and i need use as3_jpeg_wrapper.swc, but i can`t.


    my action:
    1) I add as3_jpeg_wrapper.swc to "C:\Program Files\Adobe\Adobe Flash CS4\Common\Configuration\ActionScript 3.0\libs"
    2) download This file is <a href=" http://flexlife.googlegroups.com/web/jpeg_enc.zip?hl=ru">a project of Metalbot </a>
    3) i Create empty fla
    4) add JpegTest class to empty fla
    5) run and i have error: ReferenceError: Error #1065: varaible DocJpgEncoder isn`t defenition

    Tell me please what can i do to imrove this situation ?
     
    |
    Mark as:
  • Currently Being Moderated
    May 5, 2009 7:46 AM   in reply to matthewbmedia

    Hello,

    I have test the library for record some Jpeg file.

    It's very fast, but i have a problem, how can I modify the source for add a new variable for change the compression ( Number between 0 to 100 )

     

    Do you have any idea, because in the actual state, it's impossible to work with this code...

     

    Thanks a lot for your help.

     

    -Geo

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 21, 2009 8:39 AM   in reply to Geoffrey Morelle

    @Geo: Check this blog post: http://www.websector.de/blog/2009/06/21/speed-up-jpeg-encoding-using-a lchemy/

    There you will find a modification of metalbots example for changing the quality of a compression.

     

    -Jens

     
    |
    Mark as:
1 2 3 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