ClassFlowTakeImage.cpp 20 KB

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