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.