alchemyplaque.cpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <sys/resource.h>
  4. #include "PlaqueResult.h"
  5. #include "PlaqueInterfaceDLL.h"
  6. // Header file for AS3 interop APIs
  7. // this is linked in by the compiler (when using flacon)
  8. #include "AS3.h"
  9. using namespace plaque;
  10. plaque::PlaqueResult m_result;
  11. //Method exposed to ActionScript
  12. static AS3_Val AlchemyinitializeFromRaw(void* /*self*/, AS3_Val args)
  13. {
  14. bool success = false;
  15. AS3_Val retVal;
  16. AS3_Val e_data = AS3_Undefined();
  17. AS3_Val e_data2 = AS3_Undefined();
  18. unsigned int width;
  19. unsigned int height;
  20. unsigned int bitsPerPixel;
  21. double mmPerPixelX;
  22. double mmPerPixelY;
  23. unsigned int upsideDown;
  24. unsigned int bpp, n;
  25. int x1, y1, x2, y2;
  26. int nbPts;
  27. int k;
  28. //parse the arguments.
  29. 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);
  30. retVal = AS3_Array("AS3ValType", NULL);
  31. bpp = bitsPerPixel / 8;
  32. n = bpp * width * height;
  33. char *datab = (char *) malloc(sizeof(char) * (n));
  34. AS3_ByteArray_seek(e_data, AS3_IntValue(0), SEEK_SET);
  35. AS3_ByteArray_readBytes((void *)datab, e_data, n);
  36. nbPts = x2;
  37. unsigned char *datab2 = (unsigned char *) malloc(sizeof(unsigned char) * 8 * (nbPts));
  38. AS3_ByteArray_seek(e_data2, AS3_IntValue(0), SEEK_SET);
  39. AS3_ByteArray_readBytes((void *)datab2, e_data2, nbPts * 8);
  40. // Appel de la fonction de la librairie
  41. success = plaque::initializeFromRaw(datab, width, height, bitsPerPixel, 0, mmPerPixelX, mmPerPixelY);
  42. plaque::PlaqueResult result;
  43. // success = plaque::computePlaque(x1, y1, nbPts, datab2, &result);
  44. 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);
  45. AS3_Set(retVal, AS3_Int(0), data);
  46. //
  47. for (k = 0; k < result.m_nVecteursTrouves; k++)
  48. {
  49. AS3_Val data4 = AS3_Array("IntType, IntType", result.m_tbPtsTrouvesFin[k].x, result.m_tbPtsTrouvesFin[k].y);
  50. AS3_Set(retVal, AS3_Int(k+1), data4);
  51. }
  52. delete[] plaque::getPixelArray();
  53. free(datab);
  54. free(datab2);
  55. return retVal;
  56. }
  57. static AS3_Val computePlaque(void* /*self*/, AS3_Val args)
  58. {
  59. bool success = false;
  60. unsigned int x, y, nbPts;
  61. AS3_Val retVal;
  62. AS3_Val e_data = AS3_Undefined();
  63. AS3_Val e_data2 = AS3_Undefined();
  64. // int i, j;
  65. int k;
  66. double mmPerPixelX;
  67. unsigned int bpp, n;
  68. int seuil1, seuil2;
  69. //parse the arguments.
  70. AS3_ArrayValue( args, "IntType, IntType, IntType, DoubleType, AS3ValType, AS3ValType, IntType, IntType", &x, &y, &nbPts, &mmPerPixelX, &e_data, &e_data2, &seuil1, &seuil2);
  71. retVal = AS3_Array("AS3ValType", NULL);
  72. bpp = 32 / 8;
  73. n = bpp * 768 * 576;
  74. char *datab = (char *) malloc(sizeof(char) * (n));
  75. AS3_ByteArray_seek(e_data, AS3_IntValue(0), SEEK_SET);
  76. AS3_ByteArray_readBytes((void *)datab, e_data, n);
  77. unsigned char *datab2 = (unsigned char *) malloc(sizeof(unsigned char) * 8 * (nbPts));
  78. AS3_ByteArray_seek(e_data2, AS3_IntValue(0), SEEK_SET);
  79. AS3_ByteArray_readBytes((void *)datab2, e_data2, nbPts * 8);
  80. // Appel de la fonction de la librairie
  81. success = plaque::initializeFromRaw(datab, 768, 576, 32, 0, mmPerPixelX, mmPerPixelX);
  82. success = plaque::computePlaque(x, y, nbPts, datab2, &m_result, seuil1, seuil2);
  83. 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);
  84. AS3_Set(retVal, AS3_Int(0), data);
  85. /* for (i = 0; i < m_result.m_nPtLongeantPlaque; i++)
  86. {
  87. AS3_Val data2 = AS3_Array("IntType, IntType", m_result.m_tPtLongeantPlaque[i].x, m_result.m_tPtLongeantPlaque[i].y);
  88. AS3_Set(retVal, AS3_Int(i+1), data2);
  89. }
  90. for (j = 0; j < m_result.m_nPtList; j++)
  91. {
  92. AS3_Val data3 = AS3_Array("IntType, IntType", m_result.m_ptList[j].x, m_result.m_ptList[j].y);
  93. AS3_Set(retVal, AS3_Int(i+j+1), data3);
  94. }
  95. */
  96. for (k = 0; k < m_result.m_nVecteursTrouves; k++)
  97. {
  98. AS3_Val data4 = AS3_Array("IntType, IntType", m_result.m_tbPtsTrouvesFin[k].x, m_result.m_tbPtsTrouvesFin[k].y);
  99. AS3_Set(retVal, AS3_Int(k+1), data4);
  100. }
  101. free(datab);
  102. free(datab2);
  103. return retVal;
  104. }
  105. static AS3_Val getAnalyse(void* /*self*/, AS3_Val args)
  106. {
  107. return AS3_Ptr(m_result.m_dataImg);
  108. }
  109. static AS3_Val getAnalyse2(void* /*self*/, AS3_Val args)
  110. {
  111. AS3_Val retVal;
  112. retVal = AS3_Array("AS3ValType", NULL);
  113. AS3_Val data4 = AS3_Array("DoubleType, DoubleType", m_result.plaque_max_thickness, m_result.plaque_mean_thickness);
  114. AS3_Set(retVal, AS3_Int(0), data4);
  115. return retVal;
  116. }
  117. static AS3_Val fonctionDebug(void* /*self*/, AS3_Val args)
  118. {
  119. AS3_Val retVal;
  120. int k;
  121. // int param;
  122. bool success = false;
  123. AS3_Val e_data = AS3_Undefined();
  124. unsigned int width;
  125. unsigned int height;
  126. unsigned int bitsPerPixel;
  127. double mmPerPixelX;
  128. double mmPerPixelY;
  129. unsigned int upsideDown;
  130. unsigned int bpp, n;
  131. int x1, y1, x2, y2;
  132. //parse the arguments.
  133. 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);
  134. retVal = AS3_Array("AS3ValType", NULL);
  135. bpp = bitsPerPixel / 8;
  136. n = bpp * width * height;
  137. char *datab = (char *) malloc(sizeof(char) * (n));
  138. AS3_ByteArray_seek(e_data, AS3_IntValue(0), SEEK_SET);
  139. AS3_ByteArray_readBytes((void *)datab, e_data, n);
  140. // Appel de la fonction de la librairie
  141. success = plaque::initializeFromRaw(datab, width, height, bitsPerPixel, 0, mmPerPixelX, mmPerPixelY);
  142. //parse the arguments.
  143. plaque::PlaqueResult result;
  144. success = plaque::fonctionDebug(&result);
  145. 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);
  146. AS3_Set(retVal, AS3_Int(0), data);
  147. /*
  148. for (i = 0; i < result.m_nPtLongeantPlaque; i++)
  149. {
  150. AS3_Val data2 = AS3_Array("IntType, IntType", result.m_tPtLongeantPlaque[i].x, result.m_tPtLongeantPlaque[i].y);
  151. AS3_Set(retVal, AS3_Int(i+1), data2);
  152. }
  153. for (j = 0; j < result.m_nPtList; j++)
  154. {
  155. AS3_Val data3 = AS3_Array("IntType, IntType", result.m_ptList[j].x, result.m_ptList[j].y);
  156. AS3_Set(retVal, AS3_Int(i+j), data3);
  157. }
  158. */
  159. for (k = 0; k < result.m_nVecteursTrouves; k++)
  160. {
  161. AS3_Val data4 = AS3_Array("IntType, IntType", result.m_tbPtsTrouvesFin[k].x, result.m_tbPtsTrouvesFin[k].y);
  162. AS3_Set(retVal, AS3_Int(k+1), data4);
  163. }
  164. free(datab);
  165. return retVal;
  166. }
  167. static AS3_Val OnLButtonUp(void* /*self*/, AS3_Val args)
  168. {
  169. bool success = false;
  170. int x;
  171. int y;
  172. AS3_Val retVal;
  173. int i;
  174. int j;
  175. //parse the arguments.
  176. AS3_ArrayValue( args, "IntType, IntType", &x, &y );
  177. retVal = AS3_Array("AS3ValType", NULL);
  178. plaque::PlaqueResult result;
  179. // Appel de la fonction de la librairie
  180. // Le retour de fonction Alchemy sont des Booleans
  181. success = plaque::OnLButtonUp(x, y, &result);
  182. 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);
  183. AS3_Set(retVal, AS3_Int(0), data);
  184. for (i = 0; i < result.m_nPtLongeantPlaque; i++)
  185. {
  186. AS3_Val data2 = AS3_Array("IntType, IntType", result.m_tPtLongeantPlaque[i].x, result.m_tPtLongeantPlaque[i].y);
  187. AS3_Set(retVal, AS3_Int(i+1), data2);
  188. }
  189. for (j = 0; j < result.m_nPtList; j++)
  190. {
  191. AS3_Val data3 = AS3_Array("IntType, IntType", result.m_ptList[j].x, result.m_ptList[j].y);
  192. AS3_Set(retVal, AS3_Int(i+j), data3);
  193. }
  194. return retVal;
  195. }
  196. //entry point for code
  197. int main()
  198. {
  199. const rlim_t kStackSize = 32 * 1024 * 1024; // min stack size = 32 MB
  200. struct rlimit rl;
  201. int resultStack;
  202. resultStack = getrlimit(RLIMIT_STACK, &rl);
  203. if (resultStack == 0)
  204. {
  205. if (rl.rlim_cur < kStackSize)
  206. {
  207. rl.rlim_cur = kStackSize;
  208. resultStack = setrlimit(RLIMIT_STACK, &rl);
  209. }
  210. }
  211. //define the methods exposed to ActionScript
  212. //typed as an ActionScript Function instance
  213. AS3_Val initMethod = AS3_Function( NULL, AlchemyinitializeFromRaw );
  214. AS3_Val computePlaqueMethod = AS3_Function( NULL, computePlaque );
  215. AS3_Val getAnalyseMethod = AS3_Function( NULL, getAnalyse );
  216. AS3_Val getAnalyse2Method = AS3_Function( NULL, getAnalyse2 );
  217. AS3_Val fonctionDebugMethod = AS3_Function( NULL, fonctionDebug );
  218. AS3_Val onLButtonUpMethod = AS3_Function( NULL, OnLButtonUp );
  219. // construct an object that holds references to the functions
  220. AS3_Val result = AS3_Object( "AlchemyinitializeFromRaw: AS3ValType, computePlaque: AS3ValType, fonctionDebug: AS3ValType, getAnalyse: AS3ValType, getAnalyse2: AS3ValType, OnLButtonUp: AS3ValType", initMethod, computePlaqueMethod, fonctionDebugMethod, getAnalyseMethod, getAnalyse2Method, onLButtonUpMethod );
  221. // Release
  222. AS3_Release( initMethod );
  223. AS3_Release( computePlaqueMethod );
  224. AS3_Release( fonctionDebugMethod );
  225. AS3_Release( getAnalyseMethod );
  226. AS3_Release( getAnalyse2Method );
  227. AS3_Release( onLButtonUpMethod );
  228. // notify that we initialized -- THIS DOES NOT RETURN!
  229. AS3_LibInit( result );
  230. // should never get here!
  231. return 0;
  232. }