ClassFlowTakeImage.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <regex>
  5. #include "ClassFlowTakeImage.h"
  6. #include <new>
  7. #include "Helper.h"
  8. #include "ClassLogFile.h"
  9. #include "CImageBasis.h"
  10. #include "ClassControllCamera.h"
  11. #include "MainFlowControl.h"
  12. #include "esp_wifi.h"
  13. #include "esp_log.h"
  14. #include "../../include/defines.h"
  15. #include "psram.h"
  16. #include <time.h>
  17. // #define DEBUG_DETAIL_ON
  18. // #define WIFITURNOFF
  19. static const char *TAG = "TAKEIMAGE";
  20. esp_err_t ClassFlowTakeImage::camera_capture(void)
  21. {
  22. string nm = namerawimage;
  23. Camera.CaptureToFile(nm);
  24. time(&TimeImageTaken);
  25. localtime(&TimeImageTaken);
  26. return ESP_OK;
  27. }
  28. bool ClassFlowTakeImage::takePictureWithFlash(int flash_duration)
  29. {
  30. if (rawImage == NULL || !rawImage->ImageOkay()) {
  31. LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "takePictureWithFlash: raw image buffer is unavailable");
  32. return false;
  33. }
  34. ESP_LOGD(TAG, "flash_duration: %d", flash_duration);
  35. if (Camera.CaptureToBasisImage(rawImage, flash_duration) != ESP_OK) return false;
  36. time(&TimeImageTaken);
  37. localtime(&TimeImageTaken);
  38. if (CCstatus.SaveAllFiles) rawImage->SaveToFile(namerawimage);
  39. return true;
  40. }
  41. void ClassFlowTakeImage::SetInitialParameter(void)
  42. {
  43. TimeImageTaken = 0;
  44. rawImage = NULL;
  45. disabled = false;
  46. namerawimage = "/sdcard/img_tmp/raw.jpg";
  47. }
  48. // auslesen der Kameraeinstellungen aus der config.ini
  49. // wird beim Start aufgerufen
  50. bool ClassFlowTakeImage::ReadParameter(FILE *pfile, string &aktparamgraph)
  51. {
  52. Camera.getSensorDatenToCCstatus(); // Kamera >>> CCstatus
  53. std::vector<string> splitted;
  54. aktparamgraph = trim(aktparamgraph);
  55. if (aktparamgraph.size() == 0)
  56. {
  57. if (!this->GetNextParagraph(pfile, aktparamgraph))
  58. {
  59. return false;
  60. }
  61. }
  62. if (aktparamgraph.compare("[TakeImage]") != 0)
  63. {
  64. // Paragraph does not fit TakeImage
  65. return false;
  66. }
  67. while (this->getNextLine(pfile, &aktparamgraph) && !this->isNewParagraph(aktparamgraph))
  68. {
  69. splitted = ZerlegeZeile(aktparamgraph);
  70. if ((toUpper(splitted[0]) == "RAWIMAGESLOCATION") && (splitted.size() > 1))
  71. {
  72. imagesLocation = "/sdcard" + splitted[1];
  73. isLogImage = true;
  74. }
  75. else if ((toUpper(splitted[0]) == "RAWIMAGESRETENTION") && (splitted.size() > 1))
  76. {
  77. if (isStringNumeric(splitted[1]))
  78. {
  79. this->imagesRetention = std::stod(splitted[1]);
  80. }
  81. }
  82. else if ((toUpper(splitted[0]) == "SAVEALLFILES") && (splitted.size() > 1))
  83. {
  84. CCstatus.SaveAllFiles = alphanumericToBoolean(splitted[1]);
  85. }
  86. else if ((toUpper(splitted[0]) == "WAITBEFORETAKINGPICTURE") && (splitted.size() > 1))
  87. {
  88. if (isStringNumeric(splitted[1]))
  89. {
  90. int _WaitBeforePicture = std::stoi(splitted[1]);
  91. if (_WaitBeforePicture != 0)
  92. {
  93. CCstatus.WaitBeforePicture = _WaitBeforePicture;
  94. }
  95. else
  96. {
  97. CCstatus.WaitBeforePicture = 2;
  98. }
  99. }
  100. }
  101. else if ((toUpper(splitted[0]) == "CAMGAINCEILING") && (splitted.size() > 1))
  102. {
  103. std::string _ImageGainceiling = toUpper(splitted[1]);
  104. if (isStringNumeric(_ImageGainceiling))
  105. {
  106. int _ImageGainceiling_ = std::stoi(_ImageGainceiling);
  107. switch (_ImageGainceiling_)
  108. {
  109. case 1:
  110. CCstatus.ImageGainceiling = GAINCEILING_4X;
  111. break;
  112. case 2:
  113. CCstatus.ImageGainceiling = GAINCEILING_8X;
  114. break;
  115. case 3:
  116. CCstatus.ImageGainceiling = GAINCEILING_16X;
  117. break;
  118. case 4:
  119. CCstatus.ImageGainceiling = GAINCEILING_32X;
  120. break;
  121. case 5:
  122. CCstatus.ImageGainceiling = GAINCEILING_64X;
  123. break;
  124. case 6:
  125. CCstatus.ImageGainceiling = GAINCEILING_128X;
  126. break;
  127. default:
  128. CCstatus.ImageGainceiling = GAINCEILING_2X;
  129. }
  130. }
  131. else
  132. {
  133. if (_ImageGainceiling == "X4")
  134. {
  135. CCstatus.ImageGainceiling = GAINCEILING_4X;
  136. }
  137. else if (_ImageGainceiling == "X8")
  138. {
  139. CCstatus.ImageGainceiling = GAINCEILING_8X;
  140. }
  141. else if (_ImageGainceiling == "X16")
  142. {
  143. CCstatus.ImageGainceiling = GAINCEILING_16X;
  144. }
  145. else if (_ImageGainceiling == "X32")
  146. {
  147. CCstatus.ImageGainceiling = GAINCEILING_32X;
  148. }
  149. else if (_ImageGainceiling == "X64")
  150. {
  151. CCstatus.ImageGainceiling = GAINCEILING_64X;
  152. }
  153. else if (_ImageGainceiling == "X128")
  154. {
  155. CCstatus.ImageGainceiling = GAINCEILING_128X;
  156. }
  157. else
  158. {
  159. CCstatus.ImageGainceiling = GAINCEILING_2X;
  160. }
  161. }
  162. }
  163. else if ((toUpper(splitted[0]) == "CAMQUALITY") && (splitted.size() > 1))
  164. {
  165. if (isStringNumeric(splitted[1]))
  166. {
  167. int _ImageQuality = std::stoi(splitted[1]);
  168. CCstatus.ImageQuality = clipInt(_ImageQuality, 63, 6);
  169. }
  170. }
  171. else if ((toUpper(splitted[0]) == "CAMBRIGHTNESS") && (splitted.size() > 1))
  172. {
  173. if (isStringNumeric(splitted[1]))
  174. {
  175. int _ImageBrightness = std::stoi(splitted[1]);
  176. CCstatus.ImageBrightness = clipInt(_ImageBrightness, 2, -2);
  177. }
  178. }
  179. else if ((toUpper(splitted[0]) == "CAMCONTRAST") && (splitted.size() > 1))
  180. {
  181. if (isStringNumeric(splitted[1]))
  182. {
  183. int _ImageContrast = std::stoi(splitted[1]);
  184. CCstatus.ImageContrast = clipInt(_ImageContrast, 2, -2);
  185. }
  186. }
  187. else if ((toUpper(splitted[0]) == "CAMSATURATION") && (splitted.size() > 1))
  188. {
  189. if (isStringNumeric(splitted[1]))
  190. {
  191. int _ImageSaturation = std::stoi(splitted[1]);
  192. CCstatus.ImageSaturation = clipInt(_ImageSaturation, 2, -2);
  193. }
  194. }
  195. else if ((toUpper(splitted[0]) == "CAMSHARPNESS") && (splitted.size() > 1))
  196. {
  197. if (isStringNumeric(splitted[1]))
  198. {
  199. int _ImageSharpness = std::stoi(splitted[1]);
  200. if (CCstatus.CamSensor_id == OV2640_PID)
  201. {
  202. CCstatus.ImageSharpness = clipInt(_ImageSharpness, 2, -2);
  203. }
  204. else
  205. {
  206. CCstatus.ImageSharpness = clipInt(_ImageSharpness, 3, -3);
  207. }
  208. }
  209. }
  210. else if ((toUpper(splitted[0]) == "CAMAUTOSHARPNESS") && (splitted.size() > 1))
  211. {
  212. CCstatus.ImageAutoSharpness = alphanumericToBoolean(splitted[1]);
  213. }
  214. else if ((toUpper(splitted[0]) == "CAMSPECIALEFFECT") && (splitted.size() > 1))
  215. {
  216. std::string _ImageSpecialEffect = toUpper(splitted[1]);
  217. if (isStringNumeric(_ImageSpecialEffect))
  218. {
  219. int _ImageSpecialEffect_ = std::stoi(_ImageSpecialEffect);
  220. CCstatus.ImageSpecialEffect = clipInt(_ImageSpecialEffect_, 6, 0);
  221. }
  222. else
  223. {
  224. if (_ImageSpecialEffect == "NEGATIVE")
  225. {
  226. CCstatus.ImageSpecialEffect = 1;
  227. }
  228. else if (_ImageSpecialEffect == "GRAYSCALE")
  229. {
  230. CCstatus.ImageSpecialEffect = 2;
  231. }
  232. else if (_ImageSpecialEffect == "RED")
  233. {
  234. CCstatus.ImageSpecialEffect = 3;
  235. }
  236. else if (_ImageSpecialEffect == "GREEN")
  237. {
  238. CCstatus.ImageSpecialEffect = 4;
  239. }
  240. else if (_ImageSpecialEffect == "BLUE")
  241. {
  242. CCstatus.ImageSpecialEffect = 5;
  243. }
  244. else if (_ImageSpecialEffect == "RETRO")
  245. {
  246. CCstatus.ImageSpecialEffect = 6;
  247. }
  248. else
  249. {
  250. CCstatus.ImageSpecialEffect = 0;
  251. }
  252. }
  253. }
  254. else if ((toUpper(splitted[0]) == "CAMWBMODE") && (splitted.size() > 1))
  255. {
  256. std::string _ImageWbMode = toUpper(splitted[1]);
  257. if (isStringNumeric(_ImageWbMode))
  258. {
  259. int _ImageWbMode_ = std::stoi(_ImageWbMode);
  260. CCstatus.ImageWbMode = clipInt(_ImageWbMode_, 4, 0);
  261. }
  262. else
  263. {
  264. if (_ImageWbMode == "SUNNY")
  265. {
  266. CCstatus.ImageWbMode = 1;
  267. }
  268. else if (_ImageWbMode == "CLOUDY")
  269. {
  270. CCstatus.ImageWbMode = 2;
  271. }
  272. else if (_ImageWbMode == "OFFICE")
  273. {
  274. CCstatus.ImageWbMode = 3;
  275. }
  276. else if (_ImageWbMode == "HOME")
  277. {
  278. CCstatus.ImageWbMode = 4;
  279. }
  280. else
  281. {
  282. CCstatus.ImageWbMode = 0;
  283. }
  284. }
  285. }
  286. else if ((toUpper(splitted[0]) == "CAMAWB") && (splitted.size() > 1))
  287. {
  288. CCstatus.ImageAwb = alphanumericToBoolean(splitted[1]);
  289. }
  290. else if ((toUpper(splitted[0]) == "CAMAWBGAIN") && (splitted.size() > 1))
  291. {
  292. CCstatus.ImageAwbGain = alphanumericToBoolean(splitted[1]);
  293. }
  294. else if ((toUpper(splitted[0]) == "CAMAEC") && (splitted.size() > 1))
  295. {
  296. CCstatus.ImageAec = alphanumericToBoolean(splitted[1]);
  297. }
  298. else if ((toUpper(splitted[0]) == "CAMAEC2") && (splitted.size() > 1))
  299. {
  300. CCstatus.ImageAec2 = alphanumericToBoolean(splitted[1]);
  301. }
  302. else if ((toUpper(splitted[0]) == "CAMAELEVEL") && (splitted.size() > 1))
  303. {
  304. if (isStringNumeric(splitted[1]))
  305. {
  306. int _ImageAeLevel = std::stoi(splitted[1]);
  307. if (CCstatus.CamSensor_id == OV2640_PID)
  308. {
  309. CCstatus.ImageAeLevel = clipInt(_ImageAeLevel, 2, -2);
  310. }
  311. else
  312. {
  313. CCstatus.ImageAeLevel = clipInt(_ImageAeLevel, 5, -5);
  314. }
  315. }
  316. }
  317. else if ((toUpper(splitted[0]) == "CAMAECVALUE") && (splitted.size() > 1))
  318. {
  319. if (isStringNumeric(splitted[1]))
  320. {
  321. int _ImageAecValue = std::stoi(splitted[1]);
  322. CCstatus.ImageAecValue = clipInt(_ImageAecValue, 1200, 0);
  323. }
  324. }
  325. else if ((toUpper(splitted[0]) == "CAMAGC") && (splitted.size() > 1))
  326. {
  327. CCstatus.ImageAgc = alphanumericToBoolean(splitted[1]);
  328. }
  329. else if ((toUpper(splitted[0]) == "CAMAGCGAIN") && (splitted.size() > 1))
  330. {
  331. if (isStringNumeric(splitted[1]))
  332. {
  333. int _ImageAgcGain = std::stoi(splitted[1]);
  334. CCstatus.ImageAgcGain = clipInt(_ImageAgcGain, 30, 0);
  335. }
  336. }
  337. else if ((toUpper(splitted[0]) == "CAMBPC") && (splitted.size() > 1))
  338. {
  339. CCstatus.ImageBpc = alphanumericToBoolean(splitted[1]);
  340. }
  341. else if ((toUpper(splitted[0]) == "CAMWPC") && (splitted.size() > 1))
  342. {
  343. CCstatus.ImageWpc = alphanumericToBoolean(splitted[1]);
  344. }
  345. else if ((toUpper(splitted[0]) == "CAMRAWGMA") && (splitted.size() > 1))
  346. {
  347. CCstatus.ImageRawGma = alphanumericToBoolean(splitted[1]);
  348. }
  349. else if ((toUpper(splitted[0]) == "CAMLENC") && (splitted.size() > 1))
  350. {
  351. CCstatus.ImageLenc = alphanumericToBoolean(splitted[1]);
  352. }
  353. else if ((toUpper(splitted[0]) == "CAMHMIRROR") && (splitted.size() > 1))
  354. {
  355. CCstatus.ImageHmirror = alphanumericToBoolean(splitted[1]);
  356. }
  357. else if ((toUpper(splitted[0]) == "CAMVFLIP") && (splitted.size() > 1))
  358. {
  359. CCstatus.ImageVflip = alphanumericToBoolean(splitted[1]);
  360. }
  361. else if ((toUpper(splitted[0]) == "CAMDCW") && (splitted.size() > 1))
  362. {
  363. CCstatus.ImageDcw = alphanumericToBoolean(splitted[1]);
  364. }
  365. else if ((toUpper(splitted[0]) == "CAMDENOISE") && (splitted.size() > 1))
  366. {
  367. if (isStringNumeric(splitted[1]))
  368. {
  369. int _ImageDenoiseLevel = std::stoi(splitted[1]);
  370. if (CCstatus.CamSensor_id == OV2640_PID)
  371. {
  372. CCstatus.ImageDenoiseLevel = 0;
  373. }
  374. else
  375. {
  376. CCstatus.ImageDenoiseLevel = clipInt(_ImageDenoiseLevel, 8, 0);
  377. }
  378. }
  379. }
  380. else if ((toUpper(splitted[0]) == "CAMZOOM") && (splitted.size() > 1))
  381. {
  382. CCstatus.ImageZoomEnabled = alphanumericToBoolean(splitted[1]);
  383. }
  384. else if ((toUpper(splitted[0]) == "CAMZOOMOFFSETX") && (splitted.size() > 1))
  385. {
  386. if (isStringNumeric(splitted[1]))
  387. {
  388. int _ImageZoomOffsetX = std::stoi(splitted[1]);
  389. if (CCstatus.CamSensor_id == OV2640_PID)
  390. {
  391. CCstatus.ImageZoomOffsetX = clipInt(_ImageZoomOffsetX, 480, -480);
  392. }
  393. else if (CCstatus.CamSensor_id == OV3660_PID)
  394. {
  395. CCstatus.ImageZoomOffsetX = clipInt(_ImageZoomOffsetX, 704, -704);
  396. }
  397. else if (CCstatus.CamSensor_id == OV5640_PID)
  398. {
  399. CCstatus.ImageZoomOffsetX = clipInt(_ImageZoomOffsetX, 960, -960);
  400. }
  401. }
  402. }
  403. else if ((toUpper(splitted[0]) == "CAMZOOMOFFSETY") && (splitted.size() > 1))
  404. {
  405. if (isStringNumeric(splitted[1]))
  406. {
  407. int _ImageZoomOffsetY = std::stoi(splitted[1]);
  408. if (CCstatus.CamSensor_id == OV2640_PID)
  409. {
  410. CCstatus.ImageZoomOffsetY = clipInt(_ImageZoomOffsetY, 360, -360);
  411. }
  412. else if (CCstatus.CamSensor_id == OV3660_PID)
  413. {
  414. CCstatus.ImageZoomOffsetY = clipInt(_ImageZoomOffsetY, 528, -528);
  415. }
  416. else if (CCstatus.CamSensor_id == OV5640_PID)
  417. {
  418. CCstatus.ImageZoomOffsetY = clipInt(_ImageZoomOffsetY, 720, -720);
  419. }
  420. }
  421. }
  422. else if ((toUpper(splitted[0]) == "CAMZOOMSIZE") && (splitted.size() > 1))
  423. {
  424. if (isStringNumeric(splitted[1]))
  425. {
  426. int _ImageZoomSize = std::stoi(splitted[1]);
  427. if (CCstatus.CamSensor_id == OV2640_PID)
  428. {
  429. CCstatus.ImageZoomSize = clipInt(_ImageZoomSize, 29, 0);
  430. }
  431. else if (CCstatus.CamSensor_id == OV3660_PID)
  432. {
  433. CCstatus.ImageZoomSize = clipInt(_ImageZoomSize, 43, 0);
  434. }
  435. else if (CCstatus.CamSensor_id == OV5640_PID)
  436. {
  437. CCstatus.ImageZoomSize = clipInt(_ImageZoomSize, 59, 0);
  438. }
  439. }
  440. }
  441. else if ((toUpper(splitted[0]) == "LEDINTENSITY") && (splitted.size() > 1))
  442. {
  443. if (isStringNumeric(splitted[1]))
  444. {
  445. int ledintensity = std::stoi(splitted[1]);
  446. CCstatus.ImageLedIntensity = Camera.SetLEDIntensity(ledintensity);
  447. }
  448. }
  449. else if ((toUpper(splitted[0]) == "DEMO") && (splitted.size() > 1))
  450. {
  451. CCstatus.DemoMode = alphanumericToBoolean(splitted[1]);
  452. if (CCstatus.DemoMode == true)
  453. {
  454. Camera.useDemoMode();
  455. }
  456. }
  457. }
  458. Camera.setSensorDatenFromCCstatus(); // CCstatus >>> Kamera
  459. Camera.SetQualityZoomSize(CCstatus.ImageQuality, CCstatus.ImageFrameSize, CCstatus.ImageZoomEnabled, CCstatus.ImageZoomOffsetX, CCstatus.ImageZoomOffsetY, CCstatus.ImageZoomSize, CCstatus.ImageVflip);
  460. delete rawImage;
  461. rawImage = new (std::nothrow) CImageBasis("rawImage");
  462. if (rawImage == NULL) {
  463. LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Unable to allocate raw image object");
  464. return false;
  465. }
  466. rawImage->CreateEmptyImage(CCstatus.ImageWidth, CCstatus.ImageHeight, 3);
  467. if (!rawImage->ImageOkay()) {
  468. LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Unable to allocate raw image PSRAM buffer");
  469. delete rawImage;
  470. rawImage = NULL;
  471. return false;
  472. }
  473. return true;
  474. }
  475. ClassFlowTakeImage::ClassFlowTakeImage(std::vector<ClassFlow *> *lfc) : ClassFlowImage(lfc, TAG)
  476. {
  477. imagesLocation = "/log/source";
  478. imagesRetention = 5;
  479. SetInitialParameter();
  480. }
  481. string ClassFlowTakeImage::getHTMLSingleStep(string host)
  482. {
  483. string result;
  484. result = "Raw Image: <br>\n<img src=\"" + host + "/img_tmp/raw.jpg\">\n";
  485. return result;
  486. }
  487. // wird bei jeder Auswertrunde aufgerufen
  488. bool ClassFlowTakeImage::doFlow(string zwtime)
  489. {
  490. const bool sharedMemoryLeaseAcquired = psram_init_shared_memory_for_take_image_step();
  491. if (!sharedMemoryLeaseAcquired) {
  492. LogFile.WriteToFile(ESP_LOG_WARN, TAG, "Shared PSRAM image lease unavailable; STBI will use independent PSRAM allocations");
  493. }
  494. string logPath = CreateLogFolder(zwtime);
  495. int flash_duration = (int)(CCstatus.WaitBeforePicture * 1000);
  496. #ifdef DEBUG_DETAIL_ON
  497. LogFile.WriteHeapInfo("ClassFlowTakeImage::doFlow - Before takePictureWithFlash");
  498. #endif
  499. #ifdef WIFITURNOFF
  500. esp_wifi_stop(); // to save power usage and
  501. #endif
  502. // wenn die Kameraeinstellungen durch Erstellen eines neuen Referenzbildes verändert wurden, müssen sie neu gesetzt werden
  503. if (CFstatus.changedCameraSettings)
  504. {
  505. Camera.setSensorDatenFromCCstatus(); // CCstatus >>> Kamera
  506. Camera.SetQualityZoomSize(CCstatus.ImageQuality, CCstatus.ImageFrameSize, CCstatus.ImageZoomEnabled, CCstatus.ImageZoomOffsetX, CCstatus.ImageZoomOffsetY, CCstatus.ImageZoomSize, CCstatus.ImageVflip);
  507. Camera.LedIntensity = CCstatus.ImageLedIntensity;
  508. CFstatus.changedCameraSettings = false;
  509. }
  510. const bool captured = takePictureWithFlash(flash_duration);
  511. #ifdef WIFITURNOFF
  512. esp_wifi_start();
  513. #endif
  514. #ifdef DEBUG_DETAIL_ON
  515. LogFile.WriteHeapInfo("ClassFlowTakeImage::doFlow - After takePictureWithFlash");
  516. #endif
  517. if (!captured) {
  518. if (sharedMemoryLeaseAcquired) psram_deinit_shared_memory_for_take_image_step();
  519. LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Image capture failed; aborting this flow round");
  520. return false;
  521. }
  522. LogImage(logPath, "raw", NULL, NULL, zwtime, rawImage);
  523. RemoveOldLogs();
  524. #ifdef DEBUG_DETAIL_ON
  525. LogFile.WriteHeapInfo("ClassFlowTakeImage::doFlow - After RemoveOldLogs");
  526. #endif
  527. if (sharedMemoryLeaseAcquired) psram_deinit_shared_memory_for_take_image_step();
  528. return true;
  529. }
  530. esp_err_t ClassFlowTakeImage::SendRawJPG(httpd_req_t *req)
  531. {
  532. int flash_duration = (int)(CCstatus.WaitBeforePicture * 1000);
  533. time(&TimeImageTaken);
  534. localtime(&TimeImageTaken);
  535. return Camera.CaptureToHTTP(req, flash_duration);
  536. }
  537. ImageData *ClassFlowTakeImage::SendRawImage(void)
  538. {
  539. if (rawImage == NULL || !rawImage->ImageOkay()) return NULL;
  540. CImageBasis *zw = new (std::nothrow) CImageBasis("SendRawImage", rawImage);
  541. if (zw == NULL || !zw->ImageOkay()) {
  542. delete zw;
  543. LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "SendRawImage: unable to allocate an image copy");
  544. return NULL;
  545. }
  546. const int flash_duration = static_cast<int>(CCstatus.WaitBeforePicture * 1000);
  547. if (Camera.CaptureToBasisImage(zw, flash_duration) != ESP_OK) {
  548. delete zw;
  549. LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "SendRawImage: camera capture failed");
  550. return NULL;
  551. }
  552. time(&TimeImageTaken);
  553. localtime(&TimeImageTaken);
  554. ImageData *id = zw->writeToMemoryAsJPG();
  555. delete zw;
  556. // The caller owns the returned ImageData and must release it with delete.
  557. return id;
  558. }
  559. time_t ClassFlowTakeImage::getTimeImageTaken(void)
  560. {
  561. return TimeImageTaken;
  562. }
  563. ClassFlowTakeImage::~ClassFlowTakeImage(void)
  564. {
  565. delete rawImage;
  566. }