Merge branch 'Increase-max-JPG-size'

This commit is contained in:
jomjol
2023-02-05 16:00:52 +01:00
4 changed files with 48 additions and 38 deletions

View File

@@ -2,8 +2,6 @@
## [Unreleased] ## [Unreleased]
## [14.0.0] - 2023-02-02
**Stabilization and Improved User Experience** **Stabilization and Improved User Experience**
Thanks to over 80 Pull Requests from 6 contributors, we can anounce another great release with many many improvements and new features: Thanks to over 80 Pull Requests from 6 contributors, we can anounce another great release with many many improvements and new features:
@@ -152,8 +150,8 @@ Improve **u**ser e**x**perience
5. Now you can reboot. 5. Now you can reboot.
If anything breaks you can try to If anything breaks you can try to
1\. Call `http://<IP>/ota?task=update&file=firmware.bin` resp. `http://<IP>/ota?task=update&file=html.zip` if the upload successed but the extraction failed. 1. Call `http://<IP>/ota?task=update&file=firmware.bin` resp. `http://<IP>/ota?task=update&file=html.zip` if the upload successed but the extraction failed.
1\. Use the initial_esp32_setup.zip ( <https://github.com/jomjol/AI-on-the-edge-device/wiki/Installation> ) as alternative. 1. Use the initial_esp32_setup.zip ( <https://github.com/jomjol/AI-on-the-edge-device/wiki/Installation> ) as alternative.
### Added ### Added
@@ -823,6 +821,4 @@ External Illumination
[11.3.9]: https://github.com/haverland/AI-on-the-edge-device/compare/v10.6.2...v11.3.9 [11.3.9]: https://github.com/haverland/AI-on-the-edge-device/compare/v10.6.2...v11.3.9
[Unreleased]: https://github.com/jomjol/AI-on-the-edge-device/compare/14.0.0...HEAD [Unreleased]: https://github.com/jomjol/AI-on-the-edge-device/compare/v14.0.0-RC8...HEAD
[14.0.0]: https://github.com/jomjol/AI-on-the-edge-device/compare/13.0.8...14.0.0

View File

@@ -208,6 +208,10 @@ bool ClassFlowAlignment::doFlow(string time)
int _zw = ImageBasis->height; int _zw = ImageBasis->height;
ImageBasis->height = ImageBasis->width; ImageBasis->height = ImageBasis->width;
ImageBasis->width = _zw; ImageBasis->width = _zw;
_zw = ImageTMP->width;
ImageTMP->width = ImageTMP->height;
ImageTMP->height = _zw;
} }
if (initialmirror) if (initialmirror)
@@ -246,13 +250,6 @@ bool ClassFlowAlignment::doFlow(string time)
if (SaveAllFiles) if (SaveAllFiles)
{ {
if (initialflip)
{
int _zw = ImageTMP->width;
ImageTMP->width = ImageTMP->height;
ImageTMP->height = _zw;
}
AlignAndCutImage->SaveToFile(FormatFileName("/sdcard/img_tmp/alg.jpg")); AlignAndCutImage->SaveToFile(FormatFileName("/sdcard/img_tmp/alg.jpg"));
ImageTMP->SaveToFile(FormatFileName("/sdcard/img_tmp/alg_roi.jpg")); ImageTMP->SaveToFile(FormatFileName("/sdcard/img_tmp/alg_roi.jpg"));
} }

View File

@@ -755,7 +755,8 @@ esp_err_t ClassFlowControll::GetJPGStream(std::string _fn, httpd_req_t *req)
fseek(file, 0, SEEK_SET); /* reset */ fseek(file, 0, SEEK_SET); /* reset */
if (flowalignment->AlgROI->size > MAX_JPG_SIZE) { if (flowalignment->AlgROI->size > MAX_JPG_SIZE) {
LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "File /sdcard/html/Flowstate_take_image.jpg too large: " + std::to_string(flowalignment->AlgROI->size)); LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "File /sdcard/html/Flowstate_take_image.jpg (" + std::to_string(flowalignment->AlgROI->size) +
") > allocated buffer (" + std::to_string(MAX_JPG_SIZE) + ")");
fclose(file); fclose(file);
return ESP_FAIL; return ESP_FAIL;
} }

View File

@@ -18,6 +18,9 @@ using namespace std;
static const char *TAG = "C IMG BASIS"; static const char *TAG = "C IMG BASIS";
bool jpgFileTooLarge = false; // JPG creation verfication
//#define DEBUG_DETAIL_ON //#define DEBUG_DETAIL_ON
@@ -63,6 +66,8 @@ void writejpghelp(void *context, void *data, int size)
ImageData* _zw = (ImageData*) context; ImageData* _zw = (ImageData*) context;
uint8_t *voidstart = _zw->data; uint8_t *voidstart = _zw->data;
uint8_t *datastart = (uint8_t*) data; uint8_t *datastart = (uint8_t*) data;
if ((_zw->size < MAX_JPG_SIZE)) { // Abort copy to prevent buffer overflow
voidstart += _zw->size; voidstart += _zw->size;
for (int i = 0; i < size; ++i) for (int i = 0; i < size; ++i)
@@ -70,6 +75,10 @@ void writejpghelp(void *context, void *data, int size)
_zw->size += size; _zw->size += size;
} }
else {
jpgFileTooLarge = true;
}
}
ImageData* CImageBasis::writeToMemoryAsJPG(const int quality) ImageData* CImageBasis::writeToMemoryAsJPG(const int quality)
@@ -80,6 +89,10 @@ ImageData* CImageBasis::writeToMemoryAsJPG(const int quality)
stbi_write_jpg_to_func(writejpghelp, ii, width, height, channels, rgb_image, quality); stbi_write_jpg_to_func(writejpghelp, ii, width, height, channels, rgb_image, quality);
RGBImageRelease(); RGBImageRelease();
if (jpgFileTooLarge) {
jpgFileTooLarge = false;
LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "writeToMemoryAsJPG: Creation aborted! JPG size > preallocated buffer: " + std::to_string(MAX_JPG_SIZE));
}
return ii; return ii;
} }
@@ -92,6 +105,10 @@ void CImageBasis::writeToMemoryAsJPG(ImageData* i, const int quality)
stbi_write_jpg_to_func(writejpghelp, ii, width, height, channels, rgb_image, quality); stbi_write_jpg_to_func(writejpghelp, ii, width, height, channels, rgb_image, quality);
RGBImageRelease(); RGBImageRelease();
if (jpgFileTooLarge) {
jpgFileTooLarge = false;
LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "writeToMemoryAsJPG: Creation aborted! JPG size > preallocated buffer: " + std::to_string(MAX_JPG_SIZE));
}
memCopy((uint8_t*) ii, (uint8_t*) i, sizeof(ImageData)); memCopy((uint8_t*) ii, (uint8_t*) i, sizeof(ImageData));
delete ii; delete ii;
} }
@@ -364,7 +381,7 @@ void CImageBasis::CreateEmptyImage(int _width, int _height, int _channels)
RGBImageLock(); RGBImageLock();
#ifdef DEBUG_DETAIL_ON #ifdef DEBUG_DETAIL_ON
LogFile.WriteHeapInfo("CImageBasis::CreateEmptyImage"); LogFile.WriteHeapInfo("CreateEmptyImage");
#endif #endif
int memsize = width * height * channels; int memsize = width * height * channels;
@@ -372,9 +389,8 @@ void CImageBasis::CreateEmptyImage(int _width, int _height, int _channels)
if (rgb_image == NULL) if (rgb_image == NULL)
{ {
//ESP_LOGE(TAG, "CImageBasis::CreateEmptyImage: No more free memory!! Needed: %d %d %d %d", width, height, channels, memsize); LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "CreateEmptyImage: Can't allocate enough memory: " + std::to_string(memsize));
LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "CImageBasis::CreateEmptyImage: Can't allocate enough memory: " + std::to_string(memsize)); LogFile.WriteHeapInfo("CreateEmptyImage");
LogFile.WriteHeapInfo("CImageBasis::CreateEmptyImage");
RGBImageRelease(); RGBImageRelease();
return; return;
} }
@@ -396,7 +412,7 @@ void CImageBasis::CreateEmptyImage(int _width, int _height, int _channels)
void CImageBasis::EmptyImage() void CImageBasis::EmptyImage()
{ {
#ifdef DEBUG_DETAIL_ON #ifdef DEBUG_DETAIL_ON
LogFile.WriteHeapInfo("CImageBasis::EmptyImage"); LogFile.WriteHeapInfo("EmptyImage");
#endif #endif
stbi_uc* p_source; stbi_uc* p_source;
@@ -430,7 +446,7 @@ void CImageBasis::LoadFromMemory(stbi_uc *_buffer, int len)
{ {
LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Image with size 0 loaded --> reboot to be done! " LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Image with size 0 loaded --> reboot to be done! "
"Check that your camera module is working and connected properly."); "Check that your camera module is working and connected properly.");
LogFile.WriteHeapInfo("CImageBasis::LoadFromMemory"); LogFile.WriteHeapInfo("LoadFromMemory");
doReboot(); doReboot();
} }
@@ -450,7 +466,7 @@ CImageBasis::CImageBasis(CImageBasis *_copyfrom)
RGBImageLock(); RGBImageLock();
#ifdef DEBUG_DETAIL_ON #ifdef DEBUG_DETAIL_ON
LogFile.WriteHeapInfo("CImageBasis::CImageBasis_copyfrom - Start"); LogFile.WriteHeapInfo("CImageBasis_copyfrom - Start");
#endif #endif
int memsize = width * height * channels; int memsize = width * height * channels;
@@ -458,8 +474,8 @@ CImageBasis::CImageBasis(CImageBasis *_copyfrom)
if (rgb_image == NULL) if (rgb_image == NULL)
{ {
LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "CImageBasis::CImageBasis-Copyfrom: Can't allocate enough memory: " + std::to_string(memsize)); LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "CImageBasis-Copyfrom: Can't allocate enough memory: " + std::to_string(memsize));
LogFile.WriteHeapInfo("CImageBasis::CImageBasis-Copyfrom"); LogFile.WriteHeapInfo("CImageBasis-Copyfrom");
RGBImageRelease(); RGBImageRelease();
return; return;
} }
@@ -468,7 +484,7 @@ CImageBasis::CImageBasis(CImageBasis *_copyfrom)
RGBImageRelease(); RGBImageRelease();
#ifdef DEBUG_DETAIL_ON #ifdef DEBUG_DETAIL_ON
LogFile.WriteHeapInfo("CImageBasis::CImageBasis_copyfrom - done"); LogFile.WriteHeapInfo("CImageBasis_copyfrom - done");
#endif #endif
} }
@@ -485,7 +501,7 @@ CImageBasis::CImageBasis(int _width, int _height, int _channels)
RGBImageLock(); RGBImageLock();
#ifdef DEBUG_DETAIL_ON #ifdef DEBUG_DETAIL_ON
LogFile.WriteHeapInfo("CImageBasis::CImageBasis_width,height,ch - Start"); LogFile.WriteHeapInfo("CImageBasis_width,height,ch - Start");
#endif #endif
int memsize = width * height * channels; int memsize = width * height * channels;
@@ -493,8 +509,8 @@ CImageBasis::CImageBasis(int _width, int _height, int _channels)
if (rgb_image == NULL) if (rgb_image == NULL)
{ {
LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "CImageBasis::CImageBasis-width,height,ch: Can't allocate enough memory: " + std::to_string(memsize)); LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "CImageBasis-width,height,ch: Can't allocate enough memory: " + std::to_string(memsize));
LogFile.WriteHeapInfo("CImageBasis::CImageBasis-width,height,ch"); LogFile.WriteHeapInfo("CImageBasis-width,height,ch");
RGBImageRelease(); RGBImageRelease();
return; return;
} }
@@ -502,7 +518,7 @@ CImageBasis::CImageBasis(int _width, int _height, int _channels)
RGBImageRelease(); RGBImageRelease();
#ifdef DEBUG_DETAIL_ON #ifdef DEBUG_DETAIL_ON
LogFile.WriteHeapInfo("CImageBasis::CImageBasis_width,height,ch - done"); LogFile.WriteHeapInfo("CImageBasis_width,height,ch - done");
#endif #endif
} }
@@ -522,14 +538,14 @@ CImageBasis::CImageBasis(std::string _image)
RGBImageLock(); RGBImageLock();
#ifdef DEBUG_DETAIL_ON #ifdef DEBUG_DETAIL_ON
LogFile.WriteHeapInfo("CImageBasis::CImageBasis_image - Start"); LogFile.WriteHeapInfo("CImageBasis_image - Start");
#endif #endif
rgb_image = stbi_load(_image.c_str(), &width, &height, &bpp, channels); rgb_image = stbi_load(_image.c_str(), &width, &height, &bpp, channels);
if (rgb_image == NULL) { if (rgb_image == NULL) {
LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "CImageBasis::CImageBasis-image: Failed to load " + _image + "! Is it corrupted?"); LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "CImageBasis-image: Failed to load " + _image + "! Is it corrupted?");
LogFile.WriteHeapInfo("CImageBasis::CImageBasis-image"); LogFile.WriteHeapInfo("CImageBasis-image");
RGBImageRelease(); RGBImageRelease();
return; return;
} }
@@ -543,7 +559,7 @@ CImageBasis::CImageBasis(std::string _image)
#endif #endif
#ifdef DEBUG_DETAIL_ON #ifdef DEBUG_DETAIL_ON
LogFile.WriteHeapInfo("CImageBasis::CImageBasis_image - done"); LogFile.WriteHeapInfo("CImageBasis_image - done");
#endif #endif
} }
@@ -643,7 +659,7 @@ void CImageBasis::Resize(int _new_dx, int _new_dy, CImageBasis *_target)
{ {
if ((_target->height != _new_dy) || (_target->width != _new_dx) || (_target->channels != channels)) if ((_target->height != _new_dy) || (_target->width != _new_dx) || (_target->channels != channels))
{ {
ESP_LOGE(TAG, "CImageBasis::Resize - Target image size does not fit!"); ESP_LOGE(TAG, "Resize - Target image size does not fit!");
return; return;
} }