From a39092497e79d55dacf226988b409e4e53288c9c Mon Sep 17 00:00:00 2001 From: jomjol <30766535+jomjol@users.noreply.github.com> Date: Wed, 11 Jan 2023 20:21:14 +0100 Subject: [PATCH] STBI_ONLY_JPEG (#1789) --- .../jomjol_flowcontroll/ClassFlowCNNGeneral.cpp | 12 ++++++------ .../jomjol_image_proc/CAlignAndCutImage.cpp | 6 +++++- code/components/jomjol_image_proc/CImageBasis.cpp | 4 +++- code/include/defines.h | 2 +- 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.cpp b/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.cpp index 18281b8f..54c741de 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.cpp +++ b/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.cpp @@ -502,9 +502,9 @@ bool ClassFlowCNNGeneral::doAlignAndCut(string time) if (SaveAllFiles) { if (GENERAL[_ana]->name == "default") - GENERAL[_ana]->ROI[i]->image->SaveToFile(FormatFileName("/sdcard/img_tmp/" + GENERAL[_ana]->ROI[i]->name + ".bmp")); + GENERAL[_ana]->ROI[i]->image->SaveToFile(FormatFileName("/sdcard/img_tmp/" + GENERAL[_ana]->ROI[i]->name + ".jpg")); else - GENERAL[_ana]->ROI[i]->image->SaveToFile(FormatFileName("/sdcard/img_tmp/" + GENERAL[_ana]->name + "_" + GENERAL[_ana]->ROI[i]->name + ".bmp")); + GENERAL[_ana]->ROI[i]->image->SaveToFile(FormatFileName("/sdcard/img_tmp/" + GENERAL[_ana]->name + "_" + GENERAL[_ana]->ROI[i]->name + ".jpg")); } } @@ -826,20 +826,20 @@ std::vector ClassFlowCNNGeneral::GetHTMLInfo() if (GENERAL[_ana]->ROI[i]->image) { if (GENERAL[_ana]->name == "default") - GENERAL[_ana]->ROI[i]->image->SaveToFile(FormatFileName("/sdcard/img_tmp/" + GENERAL[_ana]->ROI[i]->name + ".bmp")); + GENERAL[_ana]->ROI[i]->image->SaveToFile(FormatFileName("/sdcard/img_tmp/" + GENERAL[_ana]->ROI[i]->name + ".jpg")); else - GENERAL[_ana]->ROI[i]->image->SaveToFile(FormatFileName("/sdcard/img_tmp/" + GENERAL[_ana]->name + "_" + GENERAL[_ana]->ROI[i]->name + ".bmp")); + GENERAL[_ana]->ROI[i]->image->SaveToFile(FormatFileName("/sdcard/img_tmp/" + GENERAL[_ana]->name + "_" + GENERAL[_ana]->ROI[i]->name + ".jpg")); } HTMLInfo *zw = new HTMLInfo; if (GENERAL[_ana]->name == "default") { - zw->filename = GENERAL[_ana]->ROI[i]->name + ".bmp"; + zw->filename = GENERAL[_ana]->ROI[i]->name + ".jpg"; zw->filename_org = GENERAL[_ana]->ROI[i]->name + ".jpg"; } else { - zw->filename = GENERAL[_ana]->name + "_" + GENERAL[_ana]->ROI[i]->name + ".bmp"; + zw->filename = GENERAL[_ana]->name + "_" + GENERAL[_ana]->ROI[i]->name + ".jpg"; zw->filename_org = GENERAL[_ana]->name + "_" + GENERAL[_ana]->ROI[i]->name + ".jpg"; } diff --git a/code/components/jomjol_image_proc/CAlignAndCutImage.cpp b/code/components/jomjol_image_proc/CAlignAndCutImage.cpp index 3629411d..86cbae6c 100644 --- a/code/components/jomjol_image_proc/CAlignAndCutImage.cpp +++ b/code/components/jomjol_image_proc/CAlignAndCutImage.cpp @@ -123,8 +123,12 @@ void CAlignAndCutImage::CutAndSave(std::string _template1, int x1, int y1, int d p_target[_channels] = p_source[_channels]; } - // stbi_write_jpg(_template1.c_str(), dx, dy, channels, odata, 0); +#ifdef STBI_ONLY_JPEG + stbi_write_jpg(_template1.c_str(), dx, dy, channels, odata, 100); +#else stbi_write_bmp(_template1.c_str(), dx, dy, channels, odata); +#endif + RGBImageRelease(); diff --git a/code/components/jomjol_image_proc/CImageBasis.cpp b/code/components/jomjol_image_proc/CImageBasis.cpp index 8e8a658a..cc4e840c 100644 --- a/code/components/jomjol_image_proc/CImageBasis.cpp +++ b/code/components/jomjol_image_proc/CImageBasis.cpp @@ -503,11 +503,13 @@ void CImageBasis::SaveToFile(std::string _imageout) { stbi_write_jpg(_imageout.c_str(), width, height, channels, rgb_image, 0); } - + +#ifndef STBI_ONLY_JPEG if ((typ == "bmp") || (typ == "BMP")) { stbi_write_bmp(_imageout.c_str(), width, height, channels, rgb_image); } +#endif RGBImageRelease(); } diff --git a/code/include/defines.h b/code/include/defines.h index 689ba292..6a24f600 100644 --- a/code/include/defines.h +++ b/code/include/defines.h @@ -111,7 +111,7 @@ //#define STB_IMAGE_IMPLEMENTATION //#define STB_IMAGE_WRITE_IMPLEMENTATION //#define STB_IMAGE_RESIZE_IMPLEMENTATION - //#define STBI_ONLY_JPEG // (save 2% of Flash, but breaks the alignment mark generation, see https://github.com/jomjol/AI-on-the-edge-device/issues/1721) + #define STBI_ONLY_JPEG // (save 2% of Flash, but breaks the alignment mark generation, see https://github.com/jomjol/AI-on-the-edge-device/issues/1721) //interface_influxdb #define MAX_HTTP_OUTPUT_BUFFER 2048