You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

585 lines
24 KiB

5 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
5 years ago
​
​
​
​
​
​
​
​
​
​
​
5 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
5 years ago
​
​
​
​
4 years ago
5 years ago
​
​
​
​
​
​
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
5 years ago
​
​
​
4 years ago
​
5 years ago
​
4 years ago
5 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
5 years ago
​
​
​
​
4 years ago
5 years ago
​
​
​
​
​
4 years ago
5 years ago
​
​
​
​
​
​
​
​
​
4 years ago
5 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
5 years ago
4 years ago
5 years ago
4 years ago
5 years ago
4 years ago
5 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
5 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #include "rgooseNodeSensor.h"
  2. #include <opencv2/opencv.hpp>
  3. #define LOG( X ) m_pLog->Log( "NODSEN", this, X )
  4. #define LOG_ERROR( X ) m_pLog->Log( "NODSEN", this, _LOG_ERROR, X )
  5. argusNodeSensor::argusNodeSensor( uint32_t id ):argusNetNode( id ),m_oPosition(){
  6. m_pTargetFilter = NULL;
  7. m_pLog = basicLogCollection::getInstance();
  8. memset( &m_sLRF_DATA, 0, sizeof(DBC_LRF_DATA));
  9. if( m_pDBC ){
  10. DBC_LRF_DATA *tDATA = m_pDBC->getLRFData(m_sNodeData.aux_id);
  11. if( tDATA != NULL ) {
  12. memcpy( &m_sLRF_DATA, tDATA, sizeof(DBC_LRF_DATA));
  13. free( tDATA );
  14. };
  15. };
  16. };
  17. argusNodeSensor::argusNodeSensor( DBC_NODE_DATA *Data ):argusNetNode( Data ),m_oPosition(){
  18. m_pTargetFilter = NULL;
  19. m_pLog = basicLogCollection::getInstance();
  20. memset( &m_sLRF_DATA, 0, sizeof(DBC_LRF_DATA));
  21. if( m_pDBC ){
  22. DBC_LRF_DATA *tDATA = m_pDBC->getLRFData(m_sNodeData.aux_id);
  23. if( tDATA != NULL ) {
  24. memcpy( &m_sLRF_DATA, tDATA, sizeof(DBC_LRF_DATA));
  25. free( tDATA );
  26. };
  27. };
  28. };
  29. argusNodeSensor::~argusNodeSensor(){
  30. };
  31. #define SKIP_LINE_PIXELS 28
  32. #define HEIGHT 512
  33. #define WIDTH 1024
  34. // scale factor -> 4/9
  35. uint8_t *argusNodeSensor::create2dDraw( uint32_t *out_size, uint32_t *th_data, size_t th_size, uint16_t max_digital, int radial_shift, CSTR tpl, bool byMinimum ){
  36. uint8_t *RetVal = NULL;
  37. *out_size = 0;
  38. LOG("C2DD");
  39. if( th_data != NULL && th_size != 0 ) {
  40. if ( fileExist( tpl ) ) {
  41. LOG(tpl);
  42. cv::Mat tImage = cv::imread( tpl, cv::IMREAD_UNCHANGED );
  43. int psize = th_size / ( sizeof( uint32_t ));
  44. float stp = 2.0f * ( M_PI / (float) psize );
  45. //float MR = m_sLRF_DATA.max_range;
  46. float S = ( M_PI / 3000.0f) * (float) radial_shift;
  47. int x0 = (tImage.cols >> 1);
  48. int y0 = (tImage.rows >> 1);
  49. float maxR = ((float) x0 ) * 0.98f;
  50. LOG("C2DD - Start");
  51. cv::Point pts[(psize << 1)];
  52. cv::Point ptt[(psize+2)];
  53. const cv::Point * ppt[1];
  54. int npp[1];
  55. const cv::Point * ppz[1];
  56. int npz[1];
  57. float rst;
  58. int rpt;
  59. uint16_t RANGE = 0;
  60. ptt[0].x = x0;
  61. ptt[0].y = y0;
  62. rst = maxR / ((float)(max_digital+1));
  63. rpt = 1;
  64. for( int i=0; i < psize; i++ ){
  65. if( byMinimum ) {
  66. RANGE = ( th_data[i] >> 16 ) & 0xFFFF;
  67. } else {
  68. RANGE = th_data[i] & 0xFFFF;
  69. };
  70. float ca = 0.0 - ( S + i * stp );
  71. if( RANGE > 0 ){
  72. pts[psize+i].x = x0 + maxR * cosf( ca );
  73. pts[psize+i].y = y0 + maxR * sinf( ca );
  74. if( RANGE > max_digital ){
  75. pts[i].x = pts[psize+i].x;
  76. pts[i].y = pts[psize+i].y;
  77. } else {
  78. float cr = (rst * RANGE);
  79. pts[i].x = x0 + cr * cosf( ca );
  80. pts[i].y = y0 + cr * sinf( ca );
  81. };
  82. } else {
  83. ptt[rpt].x = pts[psize+i].x = pts[i].x = x0 + maxR * cosf( ca );
  84. ptt[rpt].y = pts[psize+i].y = pts[i].y = y0 + maxR * sinf( ca );
  85. rpt++;
  86. };
  87. };
  88. ppt[0] = pts;
  89. npp[0] = ( psize<<1 );
  90. ppz[0] = ptt;
  91. npz[0] = ( rpt - 1);
  92. LOG("C2DD -> draw finish");
  93. cv::Mat ttMOMO = cv::imread( tpl, cv::IMREAD_UNCHANGED );
  94. LOG("C2DD -> read tpl2 finish");
  95. cv::fillPoly( ttMOMO, ppt, npp, 1, cv::Scalar( 0, 128, 255, 50 ), cv::LINE_8 );
  96. LOG("C2DD -> poly1 finish");
  97. //try {
  98. // cv::fillPoly(ttMOMO, ppz, npz, 1, cv::Scalar(0, 0, 0, 100), cv::LINE_8);
  99. // LOG("C2DD -> poly2 finish");
  100. //} catch ( cv::Exception& e ) {
  101. // LOG("C2DD -> poly2 Error!");
  102. // LOG( e.what() );
  103. //};
  104. cv::addWeighted( tImage, 0.5, ttMOMO, 0.5, 0.0, tImage );
  105. LOG("C2DD -> add img finish");
  106. ttMOMO.release();
  107. LOG("C2DD -> img release finish");
  108. vector<int> compression_params;
  109. compression_params.push_back( cv::IMWRITE_PNG_COMPRESSION );
  110. compression_params.push_back(9);
  111. vector<uchar> buf;
  112. cv::imencode( ".png", tImage, buf, compression_params );
  113. tImage.release();
  114. LOG("C2DD -> compress finish");
  115. *out_size = buf.size();
  116. RetVal = (uint8_t *) malloc( *out_size );
  117. if( RetVal ) {
  118. memcpy( RetVal, buf.data(), *out_size );
  119. } else *out_size =0;
  120. buf.clear();
  121. };
  122. };
  123. return RetVal;
  124. };
  125. bool argusNodeSensor::handleDeviceDraw( uint8_t kID, void *th_data, size_t th_size, bool byMinimum ){
  126. if( th_data == NULL ) return false;
  127. if( th_size == 0 ) return false;
  128. if( m_pDBC == NULL ) return false;
  129. m_pDBC->addDeviceDraw( getNodeID(), DRAW_MODE_RAW_DATA, kID, th_data, th_size );
  130. /*
  131. //Clear Old Draw
  132. CSTR old = m_pDBC->getLRFDraw( getNodeID() );
  133. if ( old ) {
  134. // delete old draw
  135. char filename[256];
  136. sprintf( filename, "data/device_draws/%s_100.png", old );
  137. if( fileExist( filename ) ){
  138. unlink( filename );
  139. };
  140. sprintf( filename, "data/device_draws/%s_50.png", old );
  141. if( fileExist( filename ) ){
  142. unlink( filename );
  143. };
  144. sprintf( filename, "data/device_draws/%s_25.png", old );
  145. if( fileExist( filename ) ){
  146. unlink( filename );
  147. };
  148. sprintf( filename, "data/device_draws/%s_12.png", old );
  149. if( fileExist( filename ) ){
  150. unlink( filename );
  151. };
  152. sprintf( filename, "data/device_draws/%s_map.png", old );
  153. if( fileExist( filename ) ){
  154. unlink( filename );
  155. };
  156. free( old );
  157. };
  158. */
  159. CSTR uid = getUniqID_MD5();
  160. if( uid == NULL ) return false;
  161. switch( getNodeType() ){
  162. case ARGUS_ALS_SENSOR:
  163. case ARGUS_LFS_SENSOR:
  164. case ARGUS_PLS_200_SENSOR:
  165. case ARGUS_PLS_360_SENSOR:
  166. case ARGUS_NET_PLS_200:{
  167. uint32_t tSize;
  168. uint8_t *tBuff = create2dDraw( &tSize, (uint32_t *) th_data, th_size, 1024, m_sLRF_DATA.base_shift, "data/assets/images/lfs_draw_empty_100.png" );
  169. if ( tBuff ) {
  170. m_pDBC->addDeviceDraw( getNodeID(), DRAW_MODE_2D_100, kID, tBuff, tSize );
  171. free( tBuff );
  172. };
  173. tBuff = create2dDraw( &tSize, (uint32_t *) th_data, th_size, 512, m_sLRF_DATA.base_shift, "data/assets/images/lfs_draw_empty_50.png" );
  174. if ( tBuff ) {
  175. m_pDBC->addDeviceDraw( getNodeID(), DRAW_MODE_2D_50, kID, tBuff, tSize );
  176. free( tBuff );
  177. };
  178. tBuff = create2dDraw( &tSize, (uint32_t *) th_data, th_size, 256, m_sLRF_DATA.base_shift, "data/assets/images/lfs_draw_empty_25.png" );
  179. if ( tBuff ) {
  180. m_pDBC->addDeviceDraw( getNodeID(), DRAW_MODE_2D_25, kID, tBuff, tSize );
  181. free( tBuff );
  182. };
  183. tBuff = create2dDraw( &tSize, (uint32_t *) th_data, th_size, 128, m_sLRF_DATA.base_shift, "data/assets/images/lfs_draw_empty_12.png" );
  184. if ( tBuff ) {
  185. m_pDBC->addDeviceDraw( getNodeID(), DRAW_MODE_2D_12, kID, tBuff, tSize );
  186. free( tBuff );
  187. };
  188. tBuff = create2dDraw( &tSize, (uint32_t *) th_data, th_size, 1024, m_sLRF_DATA.base_shift, "data/assets/images/2d_MAP.png" );
  189. if ( tBuff ) {
  190. m_pDBC->addDeviceDraw( getNodeID(), DRAW_MODE_MAP, kID, tBuff, tSize );
  191. free( tBuff );
  192. };
  193. break;
  194. };
  195. case ARGUS_3D_SENSOR:{
  196. char * emptyBG = "data/assets/images/empty_3d.png";
  197. thresholdNode * ptr = (thresholdNode *) th_data;
  198. if ( fileExist( emptyBG ) ) {
  199. cv::Mat tImage = cv::imread( emptyBG, cv::IMREAD_UNCHANGED );
  200. if( tImage.rows != 512 || tImage.cols != 1024 ){
  201. LOG_ERROR( "Background Image wrong size (should be 1024x512)!" );
  202. free( uid );
  203. return false;
  204. };
  205. uint8_t * tMemory = tImage.data;
  206. thresholdNode * cNode = NULL;
  207. uint8_t * cPixel = NULL;
  208. int pix = 0;
  209. int mem = 0;
  210. bool s_bit = false;
  211. bool no_data = false;
  212. float tVal;
  213. bool master = ( kID < 16 );
  214. for( int idx = 0; idx < ( TH_SIZE_NODES << 2 ); idx++ ) { // tik-tak
  215. if( ( idx % 4 ) == 0 ){
  216. mem++;
  217. if ( master ) {
  218. cNode = ptr + TH_SIZE_NODES - mem - 1;
  219. } else {
  220. cNode = ptr + mem - 1;
  221. };
  222. if( !s_bit ) s_bit = cNode->values.sbit;
  223. if( !no_data ) no_data = ( cNode->values.cnt == 0 );
  224. if( !s_bit && !no_data ){
  225. if( byMinimum ) {
  226. tVal = ((float)cNode->values.min) / 4096.f;
  227. } else {
  228. tVal = ((float)cNode->values.max) / 4096.f;
  229. };
  230. };
  231. };
  232. if( ( idx % 9 ) == 0 ){
  233. if( mem > ( SKIP_LINE_PIXELS * TH_LINE_NODES ) ) {
  234. cPixel = tMemory + (pix << 2);
  235. pix++;
  236. if( s_bit ) { // Set Red
  237. cPixel[0] = 0x00; cPixel[1] = 0x00; cPixel[2] = 0xff; cPixel[3] = 0xff;
  238. } else {
  239. if( no_data ) { // Set Blue
  240. cPixel[0] = 0xff; cPixel[1] = 0x00; cPixel[2] = 0x00; cPixel[3] = 0xff;
  241. } else {
  242. uint32_t tColor;
  243. tColor = interpolate( 0x000000ff, 0xffffffff, tVal );
  244. cPixel[0] = ( tColor >> 24 ) & 0xFF;
  245. cPixel[1] = ( tColor >> 16 ) & 0xFF;
  246. cPixel[2] = ( tColor >> 8 ) & 0xFF;
  247. cPixel[3] = tColor & 0xFF;
  248. };
  249. };
  250. s_bit = false;
  251. no_data = false;
  252. };
  253. };
  254. };
  255. char filename[256];
  256. sprintf( filename, "data/device_draws/%s_100.png", uid );
  257. //int RetVal = stbi_write_png( filename, 1024, 512, cSpace, tMemory, 1024 * cSpace );
  258. vector<int> compression_params;
  259. compression_params.push_back( cv::IMWRITE_PNG_COMPRESSION );
  260. compression_params.push_back(9);
  261. if(! cv::imwrite( filename, tImage, compression_params ) ){
  262. tImage.release();
  263. free( uid );
  264. return false;
  265. };
  266. tImage.release();
  267. #ifdef DEBUG_EXTRA
  268. LOG("Draw Saved!");
  269. #endif
  270. cv::Mat tMap( Q_SCAN_COUNT, TH_LINE_NODES, CV_8UC4 );
  271. #ifdef DEBUG_EXTRA
  272. LOG("Map Creating");
  273. #endif
  274. tMemory = tMap.data;
  275. for( int j = 0; j < Q_SCAN_COUNT; j++ ){
  276. for( int i = 0; i < TH_LINE_NODES; i++ ){
  277. //cNode = ptr+(j*i);
  278. //cNode = &ptr[ ( TH_LINE_NODES * j ) + i ];
  279. int ids = 0;
  280. int idd = 0;
  281. if ( master ) {
  282. //cNode = ptr+makeIds( i, j , true );
  283. //cPixel = tMemory+( cSpace * makeIds( i, j , false ));
  284. ids = makeIds( i, j , true );
  285. idd = 4 * makeIds( i, j , false );
  286. //cNode = ptr + ( i * j );
  287. //cPixel = tMemory + ( cSpace * i * j );
  288. } else {
  289. //cNode = ptr+makeIds( i, j , false );
  290. //cPixel = tMemory+( cSpace * makeIds( i, j , false ));
  291. ids = makeIds( i, j , false );
  292. idd = 4 * makeIds( i, j , false );
  293. };
  294. cNode = ptr + ids ;
  295. cPixel = tMemory + idd;
  296. if( 0 ) { // Monochrome
  297. #ifdef CHECK_SUN_BIT
  298. if( cNode->values.sbit ) {
  299. cPixel[0] = 0;
  300. } else {
  301. cPixel[0] = (uint8_t)((((float) cNode->values.min ) * 255.f ) / 4096.f );
  302. };
  303. #else
  304. cPixel[0] = (uint8_t)((((float) cNode->values.min ) * 255.f ) / 4096.f );
  305. #endif
  306. } else {
  307. #ifdef CHECK_SUN_BIT
  308. if( cNode->values.sbit ) {
  309. // Set Red
  310. cPixel[0] = 0x00;
  311. cPixel[1] = 0x00;
  312. cPixel[2] = 0xff;
  313. cPixel[3] = 0xff;
  314. } else {
  315. if( cNode->values.cnt == 0 ) {
  316. // Set Blue
  317. cPixel[0] = 0xff;
  318. cPixel[1] = 0x00;
  319. cPixel[2] = 0x00;
  320. cPixel[3] = 0xff;
  321. } else {
  322. uint32_t tColor;
  323. float tVal = ((float) cNode->values.min ) / 4096.f;
  324. tColor = interpolate( 0x000000ff, 0xffffffff, tVal );
  325. cPixel[0] = ( tColor >> 24 ) & 0xFF;
  326. cPixel[1] = ( tColor >> 16 ) & 0xFF;
  327. cPixel[2] = ( tColor >> 8 ) & 0xFF;
  328. cPixel[3] = tColor & 0xFF;
  329. };
  330. };
  331. #else
  332. if( cNode->values.cnt == 0 ) {
  333. // Set Blue
  334. cPixel[0] = 0xff;
  335. cPixel[1] = 0x00;
  336. cPixel[2] = 0x00;
  337. cPixel[3] = 0xff;
  338. } else {
  339. uint32_t tColor;
  340. float tVal = ((float) cNode->values.min ) / 4096.f;
  341. tColor = interpolate( 0x000000ff, 0xffffffff, tVal );
  342. cPixel[0] = ( tColor >> 24 ) & 0xFF;
  343. cPixel[1] = ( tColor >> 16 ) & 0xFF;
  344. cPixel[2] = ( tColor >> 8 ) & 0xFF;
  345. cPixel[3] = tColor & 0xFF;
  346. };
  347. #endif
  348. };
  349. };
  350. };
  351. sprintf( filename, "data/device_draws/%s_map.png", uid );
  352. LOG(filename);
  353. if(! cv::imwrite( filename, tMap, compression_params ) ){
  354. tMap.release();
  355. free( uid );
  356. return false;
  357. };
  358. tMap.release();
  359. m_pDBC->addLRFDraw( getNodeID(), TH_SIZE_NODES, uid, kID, 1, true );
  360. } else {
  361. LOG_ERROR( "Background Image is Not Found!" );
  362. free( uid );
  363. return false;
  364. };
  365. break;
  366. };
  367. };
  368. free( uid );
  369. return true;
  370. };
  371. /*
  372. #define STB_IMAGE_IMPLEMENTATION
  373. #include "../data/stbi/stb_image.h"
  374. #define STB_IMAGE_WRITE_IMPLEMENTATION
  375. #include "../data/stbi/stb_image_write.h"
  376. #undef STB_IMAGE_WRITE_IMPLEMENTATION
  377. #undef STB_IMAGE_IMPLEMENTATION
  378. bool argus3DLIDAR::saveTHPicture( thresholdNode *ptr, CSTR uid, bool master, bool byMinimum, bool monochrome ){
  379. uint8_t *tMemory = NULL;
  380. thresholdNode *cNode = NULL;
  381. uint8_t *cPixel = NULL;
  382. int cSpace;
  383. int x, y;
  384. tMemory = stbi_load( "data/assets/images/empty_3d.png", &x, &y, &cSpace, STBI_default );
  385. if( tMemory == NULL ){
  386. LOG_ERROR("Draw Memory Alloc Eror!");
  387. return false;
  388. };
  389. if( x != 1024 || y != 512 ){
  390. LOG("Wrong IMG Size!");
  391. free( tMemory );
  392. return NULL;
  393. };
  394. int pix = 0;
  395. int mem = 0;
  396. bool s_bit = false;
  397. bool no_data = false;
  398. float tVal;
  399. for ( int idx = 0; idx < ( TH_SIZE_NODES << 2 ); idx++ ) { // tik-tak
  400. if( ( idx % 4 ) == 0 ){
  401. mem++;
  402. if ( master ) {
  403. cNode = ptr + TH_SIZE_NODES - mem - 1;
  404. } else {
  405. cNode = ptr + mem - 1;
  406. };
  407. if( !s_bit ) s_bit = cNode->values.sbit;
  408. if( !no_data ) no_data = ( cNode->values.cnt == 0 );
  409. if( !s_bit && !no_data ){
  410. if( byMinimum ) {
  411. tVal = ((float)cNode->values.min) / 4096.f;
  412. } else {
  413. tVal = ((float)cNode->values.max) / 4096.f;
  414. };
  415. };
  416. };
  417. if( ( idx % 9 ) == 0 ){
  418. if( mem > ( SKIP_LINE_PIXELS * TH_LINE_NODES ) ) {
  419. cPixel = tMemory + (pix << 2);
  420. pix++;
  421. if( s_bit ) { // Set Red
  422. cPixel[0] = 0x00; cPixel[1] = 0xff; cPixel[2] = 0x00; cPixel[3] = 0xff;
  423. } else {
  424. if( no_data ) { // Set Blue
  425. cPixel[0] = 0x00; cPixel[1] = 0x00; cPixel[2] = 0xff; cPixel[3] = 0xff;
  426. } else {
  427. uint32_t tColor;
  428. tColor = interpolate( 0x000000ff, 0xffffffff, tVal );
  429. cPixel[0] = ( tColor >> 24 ) & 0xFF;
  430. cPixel[1] = ( tColor >> 16 ) & 0xFF;
  431. cPixel[2] = ( tColor >> 8 ) & 0xFF;
  432. cPixel[3] = tColor & 0xFF;
  433. };
  434. };
  435. s_bit = false;
  436. no_data = false;
  437. }
  438. };
  439. };
  440. char filename[256];
  441. sprintf( filename, "data/device_draws/%s_100.png", uid );
  442. int RetVal = stbi_write_png( filename, 1024, 512, cSpace, tMemory, 1024 * cSpace );
  443. free( tMemory );
  444. if( RetVal == 0 ) return false;
  445. if( monochrome ) {
  446. cSpace = 1;
  447. } else {
  448. cSpace = 4;
  449. };
  450. tMemory = (uint8_t *) malloc( TH_SIZE_NODES * cSpace );
  451. if( tMemory == NULL ){
  452. LOG_ERROR("Map Memory Alloc Eror!");
  453. return false;
  454. };
  455. for (int j = 0; j < Q_SCAN_COUNT; j++) {
  456. for ( int i = 0; i < TH_LINE_NODES; i++ ) {
  457. //cNode = ptr+(j*i);
  458. //cNode = &ptr[ ( TH_LINE_NODES * j ) + i ];
  459. int ids = 0;
  460. int idd = 0;
  461. if ( master ) {
  462. //cNode = ptr+makeIds( i, j , true );
  463. //cPixel = tMemory+( cSpace * makeIds( i, j , false ));
  464. ids = makeIds( i, j , true );
  465. idd = cSpace * makeIds( i, j , false );
  466. //cNode = ptr + ( i * j );
  467. //cPixel = tMemory + ( cSpace * i * j );
  468. } else {
  469. //cNode = ptr+makeIds( i, j , false );
  470. //cPixel = tMemory+( cSpace * makeIds( i, j , false ));
  471. ids = makeIds( i, j , false );
  472. idd = cSpace * makeIds( i, j , false );
  473. };
  474. cNode = ptr + ids ;
  475. cPixel = tMemory + idd;
  476. if( monochrome ) {
  477. #ifdef CHECK_SUN_BIT
  478. if( cNode->values.sbit ) {
  479. cPixel[0] = 0;
  480. } else {
  481. cPixel[0] = (uint8_t)((((float) cNode->values.min ) * 255.f ) / 4096.f );
  482. };
  483. #else
  484. cPixel[0] = (uint8_t)((((float) cNode->values.min ) * 255.f ) / 4096.f );
  485. #endif
  486. } else {
  487. #ifdef CHECK_SUN_BIT
  488. if( cNode->values.sbit ) {
  489. // Set Red
  490. cPixel[0] = 0x00;
  491. cPixel[1] = 0xff;
  492. cPixel[2] = 0x00;
  493. cPixel[3] = 0xff;
  494. } else {
  495. if( cNode->values.cnt == 0 ) {
  496. // Set Blue
  497. cPixel[0] = 0x00;
  498. cPixel[1] = 0x00;
  499. cPixel[2] = 0xff;
  500. cPixel[3] = 0xff;
  501. } else {
  502. uint32_t tColor;
  503. float tVal = ((float) cNode->values.min ) / 4096.f;
  504. tColor = interpolate( 0x000000ff, 0xffffffff, tVal );
  505. cPixel[0] = ( tColor >> 24 ) & 0xFF;
  506. cPixel[1] = ( tColor >> 16 ) & 0xFF;
  507. cPixel[2] = ( tColor >> 8 ) & 0xFF;
  508. cPixel[3] = tColor & 0xFF;
  509. };
  510. };
  511. #else
  512. if( cNode->values.cnt == 0 ) {
  513. // Set Blue
  514. cPixel[0] = 0x00;
  515. cPixel[1] = 0x00;
  516. cPixel[2] = 0xff;
  517. cPixel[3] = 0xff;
  518. } else {
  519. uint32_t tColor;
  520. float tVal = ((float) cNode->values.min ) / 4096.f;
  521. tColor = interpolate( 0x000000ff, 0xffffffff, tVal );
  522. cPixel[0] = ( tColor >> 24 ) & 0xFF;
  523. cPixel[1] = ( tColor >> 16 ) & 0xFF;
  524. cPixel[2] = ( tColor >> 8 ) & 0xFF;
  525. cPixel[3] = tColor & 0xFF;
  526. };
  527. #endif
  528. };
  529. };
  530. };
  531. sprintf( filename, "data/device_draws/%s_map.png", uid );
  532. RetVal = stbi_write_png( filename, TH_LINE_NODES, Q_SCAN_COUNT, cSpace, tMemory, TH_LINE_NODES * cSpace );
  533. free( tMemory );
  534. if( RetVal == 0 ) return false;
  535. return true;
  536. };
  537. */
  538. #undef LOG
  539. #undef LOG_ERROR