#include #include #include #include "PlaqueResult.h" #include "PlaqueInterfaceDLL.h" // Header file for AS3 interop APIs // this is linked in by the compiler (when using flacon) #include "AS3.h" using namespace plaque; plaque::PlaqueResult m_result; //Method exposed to ActionScript static AS3_Val AlchemyinitializeFromRaw(void* /*self*/, AS3_Val args) { bool success = false; AS3_Val retVal; AS3_Val e_data = AS3_Undefined(); AS3_Val e_data2 = AS3_Undefined(); unsigned int width; unsigned int height; unsigned int bitsPerPixel; double mmPerPixelX; double mmPerPixelY; unsigned int upsideDown; unsigned int bpp, n; int x1, y1, x2, y2; int nbPts; int k; //parse the arguments. AS3_ArrayValue( args, "IntType, IntType, IntType, IntType, IntType, IntType, IntType, IntType, DoubleType, DoubleType, AS3ValType, AS3ValType", &x1, &y1, &x2, &y2, &width, &height, &bitsPerPixel, &upsideDown, &mmPerPixelX, &mmPerPixelY, &e_data, &e_data2); retVal = AS3_Array("AS3ValType", NULL); bpp = bitsPerPixel / 8; n = bpp * width * height; char *datab = (char *) malloc(sizeof(char) * (n)); AS3_ByteArray_seek(e_data, AS3_IntValue(0), SEEK_SET); AS3_ByteArray_readBytes((void *)datab, e_data, n); nbPts = x2; unsigned char *datab2 = (unsigned char *) malloc(sizeof(unsigned char) * 8 * (nbPts)); AS3_ByteArray_seek(e_data2, AS3_IntValue(0), SEEK_SET); AS3_ByteArray_readBytes((void *)datab2, e_data2, nbPts * 8); // Appel de la fonction de la librairie success = plaque::initializeFromRaw(datab, width, height, bitsPerPixel, 0, mmPerPixelX, mmPerPixelY); plaque::PlaqueResult result; // success = plaque::computePlaque(x1, y1, nbPts, datab2, &result); AS3_Val data = AS3_Array("DoubleType, DoubleType, DoubleType, DoubleType, IntType, IntType, IntType, IntType, IntType, IntType, IntType, IntType, IntType, IntType, IntType, IntType, IntType, IntType, IntType", result.plaque_max_thickness, result.plaque_mean_thickness, result.plaque_area, result.plaque_mean_density, result.numberOfMeasures, result.m_nPtLongeantPlaque, result.m_nPtList, result.m_ptInferieur.x, result.m_ptInferieur.y, result.m_type, result.m_Etape, result.code_retour, result.m_nVecteursTrouves, result.code_debug1, result.code_debug2, result.code_debug3, result.code_debug4, result.code_debug5); AS3_Set(retVal, AS3_Int(0), data); // for (k = 0; k < result.m_nVecteursTrouves; k++) { AS3_Val data4 = AS3_Array("IntType, IntType", result.m_tbPtsTrouvesFin[k].x, result.m_tbPtsTrouvesFin[k].y); AS3_Set(retVal, AS3_Int(k+1), data4); } delete[] plaque::getPixelArray(); free(datab); free(datab2); return retVal; } static AS3_Val computePlaque(void* /*self*/, AS3_Val args) { bool success = false; unsigned int x, y, nbPts; AS3_Val retVal; AS3_Val e_data = AS3_Undefined(); AS3_Val e_data2 = AS3_Undefined(); // int i, j; int k; double mmPerPixelX; unsigned int bpp, n; int seuil1, seuil2; //parse the arguments. AS3_ArrayValue( args, "IntType, IntType, IntType, DoubleType, AS3ValType, AS3ValType, IntType, IntType", &x, &y, &nbPts, &mmPerPixelX, &e_data, &e_data2, &seuil1, &seuil2); retVal = AS3_Array("AS3ValType", NULL); bpp = 32 / 8; n = bpp * 768 * 576; char *datab = (char *) malloc(sizeof(char) * (n)); AS3_ByteArray_seek(e_data, AS3_IntValue(0), SEEK_SET); AS3_ByteArray_readBytes((void *)datab, e_data, n); unsigned char *datab2 = (unsigned char *) malloc(sizeof(unsigned char) * 8 * (nbPts)); AS3_ByteArray_seek(e_data2, AS3_IntValue(0), SEEK_SET); AS3_ByteArray_readBytes((void *)datab2, e_data2, nbPts * 8); // Appel de la fonction de la librairie success = plaque::initializeFromRaw(datab, 768, 576, 32, 0, mmPerPixelX, mmPerPixelX); success = plaque::computePlaque(x, y, nbPts, datab2, &m_result, seuil1, seuil2); AS3_Val data = AS3_Array("DoubleType, DoubleType, DoubleType, DoubleType, IntType, IntType, IntType, IntType, IntType, IntType, IntType, IntType, IntType, IntType, IntType, IntType, IntType, IntType", m_result.plaque_max_thickness, m_result.plaque_mean_thickness, m_result.plaque_area, m_result.plaque_mean_density, m_result.numberOfMeasures, m_result.m_nPtLongeantPlaque, m_result.m_nPtList, m_result.m_ptInferieur.x, m_result.m_ptInferieur.y, m_result.m_type, m_result.m_Etape, m_result.code_retour, m_result.m_nVecteursTrouves, m_result.code_debug1, m_result.code_debug2, m_result.code_debug3, m_result.code_debug4, m_result.code_debug5); AS3_Set(retVal, AS3_Int(0), data); /* for (i = 0; i < m_result.m_nPtLongeantPlaque; i++) { AS3_Val data2 = AS3_Array("IntType, IntType", m_result.m_tPtLongeantPlaque[i].x, m_result.m_tPtLongeantPlaque[i].y); AS3_Set(retVal, AS3_Int(i+1), data2); } for (j = 0; j < m_result.m_nPtList; j++) { AS3_Val data3 = AS3_Array("IntType, IntType", m_result.m_ptList[j].x, m_result.m_ptList[j].y); AS3_Set(retVal, AS3_Int(i+j+1), data3); } */ for (k = 0; k < m_result.m_nVecteursTrouves; k++) { AS3_Val data4 = AS3_Array("IntType, IntType", m_result.m_tbPtsTrouvesFin[k].x, m_result.m_tbPtsTrouvesFin[k].y); AS3_Set(retVal, AS3_Int(k+1), data4); } free(datab); free(datab2); return retVal; } static AS3_Val getAnalyse(void* /*self*/, AS3_Val args) { return AS3_Ptr(m_result.m_dataImg); } static AS3_Val getAnalyse2(void* /*self*/, AS3_Val args) { AS3_Val retVal; retVal = AS3_Array("AS3ValType", NULL); AS3_Val data4 = AS3_Array("DoubleType, DoubleType", m_result.plaque_max_thickness, m_result.plaque_mean_thickness); AS3_Set(retVal, AS3_Int(0), data4); return retVal; } static AS3_Val fonctionDebug(void* /*self*/, AS3_Val args) { AS3_Val retVal; int k; // int param; bool success = false; AS3_Val e_data = AS3_Undefined(); unsigned int width; unsigned int height; unsigned int bitsPerPixel; double mmPerPixelX; double mmPerPixelY; unsigned int upsideDown; unsigned int bpp, n; int x1, y1, x2, y2; //parse the arguments. AS3_ArrayValue( args, "IntType, IntType, IntType, IntType, IntType, IntType, IntType, IntType, DoubleType, DoubleType, AS3ValType", &x1, &y1, &x2, &y2, &width, &height, &bitsPerPixel, &upsideDown, &mmPerPixelX, &mmPerPixelY, &e_data); retVal = AS3_Array("AS3ValType", NULL); bpp = bitsPerPixel / 8; n = bpp * width * height; char *datab = (char *) malloc(sizeof(char) * (n)); AS3_ByteArray_seek(e_data, AS3_IntValue(0), SEEK_SET); AS3_ByteArray_readBytes((void *)datab, e_data, n); // Appel de la fonction de la librairie success = plaque::initializeFromRaw(datab, width, height, bitsPerPixel, 0, mmPerPixelX, mmPerPixelY); //parse the arguments. plaque::PlaqueResult result; success = plaque::fonctionDebug(&result); AS3_Val data = AS3_Array("DoubleType, DoubleType, DoubleType, DoubleType, IntType, IntType, IntType, IntType, IntType, IntType, IntType, IntType, IntType, IntType, IntType, IntType, IntType, IntType", result.plaque_max_thickness, result.plaque_mean_thickness, result.plaque_area, result.plaque_mean_density, result.numberOfMeasures, result.m_nPtLongeantPlaque, result.m_nPtList, result.m_ptInferieur.x, result.m_ptInferieur.y, result.m_type, result.m_Etape, result.code_retour, result.m_nVecteursTrouves, result.code_debug1, result.code_debug2, result.code_debug3, result.code_debug4, result.code_debug5); AS3_Set(retVal, AS3_Int(0), data); /* for (i = 0; i < result.m_nPtLongeantPlaque; i++) { AS3_Val data2 = AS3_Array("IntType, IntType", result.m_tPtLongeantPlaque[i].x, result.m_tPtLongeantPlaque[i].y); AS3_Set(retVal, AS3_Int(i+1), data2); } for (j = 0; j < result.m_nPtList; j++) { AS3_Val data3 = AS3_Array("IntType, IntType", result.m_ptList[j].x, result.m_ptList[j].y); AS3_Set(retVal, AS3_Int(i+j), data3); } */ for (k = 0; k < result.m_nVecteursTrouves; k++) { AS3_Val data4 = AS3_Array("IntType, IntType", result.m_tbPtsTrouvesFin[k].x, result.m_tbPtsTrouvesFin[k].y); AS3_Set(retVal, AS3_Int(k+1), data4); } free(datab); return retVal; } static AS3_Val OnLButtonUp(void* /*self*/, AS3_Val args) { bool success = false; int x; int y; AS3_Val retVal; int i; int j; //parse the arguments. AS3_ArrayValue( args, "IntType, IntType", &x, &y ); retVal = AS3_Array("AS3ValType", NULL); plaque::PlaqueResult result; // Appel de la fonction de la librairie // Le retour de fonction Alchemy sont des Booleans success = plaque::OnLButtonUp(x, y, &result); AS3_Val data = AS3_Array("DoubleType, DoubleType, DoubleType, DoubleType, IntType, IntType, IntType, IntType, IntType, IntType, IntType, IntType, IntType, IntType, IntType, IntType, IntType, IntType", result.plaque_max_thickness, result.plaque_mean_thickness, result.plaque_area, result.plaque_mean_density, result.numberOfMeasures, result.m_nPtLongeantPlaque, result.m_nPtList, result.m_ptInferieur.x, result.m_ptInferieur.y, result.m_type, result.m_Etape, result.code_retour, result.m_nVecteursTrouves, result.code_debug1, result.code_debug2, result.code_debug3, result.code_debug4, result.code_debug5); AS3_Set(retVal, AS3_Int(0), data); for (i = 0; i < result.m_nPtLongeantPlaque; i++) { AS3_Val data2 = AS3_Array("IntType, IntType", result.m_tPtLongeantPlaque[i].x, result.m_tPtLongeantPlaque[i].y); AS3_Set(retVal, AS3_Int(i+1), data2); } for (j = 0; j < result.m_nPtList; j++) { AS3_Val data3 = AS3_Array("IntType, IntType", result.m_ptList[j].x, result.m_ptList[j].y); AS3_Set(retVal, AS3_Int(i+j), data3); } return retVal; } //entry point for code int main() { const rlim_t kStackSize = 32 * 1024 * 1024; // min stack size = 32 MB struct rlimit rl; int resultStack; resultStack = getrlimit(RLIMIT_STACK, &rl); if (resultStack == 0) { if (rl.rlim_cur < kStackSize) { rl.rlim_cur = kStackSize; resultStack = setrlimit(RLIMIT_STACK, &rl); } } //define the methods exposed to ActionScript //typed as an ActionScript Function instance AS3_Val initMethod = AS3_Function( NULL, AlchemyinitializeFromRaw ); AS3_Val computePlaqueMethod = AS3_Function( NULL, computePlaque ); AS3_Val getAnalyseMethod = AS3_Function( NULL, getAnalyse ); AS3_Val getAnalyse2Method = AS3_Function( NULL, getAnalyse2 ); AS3_Val fonctionDebugMethod = AS3_Function( NULL, fonctionDebug ); AS3_Val onLButtonUpMethod = AS3_Function( NULL, OnLButtonUp ); // construct an object that holds references to the functions AS3_Val result = AS3_Object( "AlchemyinitializeFromRaw: AS3ValType, computePlaque: AS3ValType, fonctionDebug: AS3ValType, getAnalyse: AS3ValType, getAnalyse2: AS3ValType, OnLButtonUp: AS3ValType", initMethod, computePlaqueMethod, fonctionDebugMethod, getAnalyseMethod, getAnalyse2Method, onLButtonUpMethod ); // Release AS3_Release( initMethod ); AS3_Release( computePlaqueMethod ); AS3_Release( fonctionDebugMethod ); AS3_Release( getAnalyseMethod ); AS3_Release( getAnalyse2Method ); AS3_Release( onLButtonUpMethod ); // notify that we initialized -- THIS DOES NOT RETURN! AS3_LibInit( result ); // should never get here! return 0; }