build system and module refactoring + simple histogram scratch (#20)
* scratch adding histogram to image views Histograms should come from some sort of histogram service. This is currently just a POC. * custom logger implementation w/o spdlog * missing cmake file * fix tests * use operator<< over direct stream exposure * rm print header * add threading test + refactor towards interface libraries omits the need for =target_include_directories= calls /everywhere/ * rm print header * rm constexpr * templated thread_pool * fix doxyfile * default enable doc building * czi reader refactor * rm erroneous include expression * clang-format * single lib include with PUBLIC visibility * compile imgui stdlib * clang format * documentation update centralize `LogLevelToString` to `ILog.hpp` update docs and examples
This commit is contained in:
committed by
Maximilian Kueffner
parent
b37814204f
commit
c00c2c71ac
+14
-10
@@ -1,4 +1,4 @@
|
||||
include(${CMAKE_SOURCE_DIR}/cmake/libCZI.cmake)
|
||||
include(libCZI)
|
||||
|
||||
find_package(OpenCV REQUIRED)
|
||||
|
||||
@@ -6,19 +6,19 @@ message(STATUS "Found opencv: " ${OpenCV_INCLUDE_DIRS})
|
||||
message(STATUS "OpenCV_LIBs from: " ${OpenCV_LIBS})
|
||||
|
||||
set(IMAGELIBSRC
|
||||
IPixelariumImage.hpp
|
||||
include/IPixelariumImage.hpp
|
||||
include/PixelariumImageFactory.hpp
|
||||
impl/include/PixelariumJpg.hpp
|
||||
impl/include/PixelariumPng.hpp
|
||||
impl/include/PixelariumCzi.hpp
|
||||
impl/include/PixelariumTiff.hpp
|
||||
impl/include/PixelariumMem.hpp
|
||||
IPixelariumImage.cpp
|
||||
PixelariumImageFactory.hpp
|
||||
PixelariumImageFactory.cpp
|
||||
impl/PixelariumJpg.hpp
|
||||
impl/PixelariumJpg.cpp
|
||||
impl/PixelariumPng.hpp
|
||||
impl/PixelariumPng.cpp
|
||||
impl/PixelariumCzi.hpp
|
||||
impl/PixelariumCzi.cpp
|
||||
impl/PixelariumTiff.hpp
|
||||
impl/PixelariumTiff.cpp
|
||||
impl/PixelariumMem.hpp
|
||||
impl/PixelariumMem.cpp
|
||||
)
|
||||
|
||||
@@ -27,15 +27,19 @@ set(IMAGELIBLIBNAME pixelariumimagelib)
|
||||
add_library(${IMAGELIBLIBNAME}
|
||||
STATIC ${IMAGELIBSRC})
|
||||
|
||||
add_library(pixelarium::lib::imaging_static ALIAS ${IMAGELIBLIBNAME})
|
||||
|
||||
target_compile_definitions(${IMAGELIBLIBNAME} PUBLIC _LIBCZISTATICLIB)
|
||||
|
||||
target_link_libraries(${IMAGELIBLIBNAME}
|
||||
PUBLIC ${OpenCV_LIBS}
|
||||
PUBLIC pixelariumutilslib
|
||||
PUBLIC pixelarium::lib::utilities_static
|
||||
PRIVATE libCZIStatic)
|
||||
|
||||
|
||||
target_include_directories(${IMAGELIBLIBNAME}
|
||||
PRIVATE ${CMAKE_SOURCE_DIR}/lib
|
||||
INTERFACE
|
||||
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include
|
||||
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/impl/include
|
||||
PUBLIC ${OpenCV_INCLUDE_DIRS}
|
||||
PUBLIC ${LIBCZI_INCLUDE_DIR})
|
||||
|
||||
@@ -3,12 +3,12 @@
|
||||
#include <cctype>
|
||||
#include <memory>
|
||||
|
||||
#include "imaging/IPixelariumImage.hpp"
|
||||
#include "imaging/impl/PixelariumMem.hpp"
|
||||
#include "impl/PixelariumCzi.hpp"
|
||||
#include "impl/PixelariumJpg.hpp"
|
||||
#include "impl/PixelariumPng.hpp"
|
||||
#include "impl/PixelariumTiff.hpp"
|
||||
#include "IPixelariumImage.hpp"
|
||||
#include "PixelariumCzi.hpp"
|
||||
#include "PixelariumJpg.hpp"
|
||||
#include "PixelariumMem.hpp"
|
||||
#include "PixelariumPng.hpp"
|
||||
#include "PixelariumTiff.hpp"
|
||||
|
||||
/*static*/ std::unique_ptr<pixelarium::imaging::IPixelariumImageCvMat>
|
||||
pixelarium::imaging::PixelariumImageFactory::CreateImage(const std::string& uri, const Log& log)
|
||||
|
||||
@@ -7,11 +7,13 @@
|
||||
#include <opencv2/imgcodecs.hpp>
|
||||
#include <optional>
|
||||
#include <stdexcept>
|
||||
#include <utility>
|
||||
|
||||
#include "ILog.hpp"
|
||||
#include "libCZI.h"
|
||||
#include "utilities/ILog.hpp"
|
||||
#include "libCZI_Pixels.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
bool comp_blockinfo_params(const pixelarium::imaging::CziParams& params, const libCZI::SubBlockInfo& info)
|
||||
{
|
||||
bool res{true};
|
||||
@@ -50,94 +52,62 @@ constexpr int try_get_index_match(const pixelarium::imaging::CziParams& params,
|
||||
return index;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
std::optional<cv::Mat> CZISubBlockToCvMat(std::shared_ptr<libCZI::IBitmapData> bitmap, libCZI::PixelType pixeltype,
|
||||
const pixelarium::utils::log::ILog& log)
|
||||
{
|
||||
size_t pixel_size{0};
|
||||
int target_type;
|
||||
std::pair<std::string, std::string> pixel_pair;
|
||||
const auto cv_pixel = GetCVPixelTypeAndSize(pixeltype);
|
||||
|
||||
switch (pixeltype)
|
||||
{
|
||||
case libCZI::PixelType::Gray8:
|
||||
pixel_pair.first = "Gray8";
|
||||
pixel_pair.second = "CV_8U";
|
||||
pixel_size = 1;
|
||||
target_type = CV_8U;
|
||||
break;
|
||||
case libCZI::PixelType::Gray16:
|
||||
pixel_pair.first = "Gray16";
|
||||
pixel_pair.second = "CV_16U";
|
||||
pixel_size = 2;
|
||||
target_type = CV_16U;
|
||||
break;
|
||||
case libCZI::PixelType::Bgr24:
|
||||
pixel_pair.first = "Bgr24";
|
||||
pixel_pair.second = "CV_8UC3";
|
||||
pixel_size = 3;
|
||||
target_type = CV_8UC3;
|
||||
break;
|
||||
case libCZI::PixelType::Bgra32:
|
||||
pixel_pair.first = "Bgra32";
|
||||
pixel_pair.second = "CV_8CU4";
|
||||
target_type = CV_8UC4;
|
||||
case libCZI::PixelType::Gray32:
|
||||
pixel_pair.first = "Gray32";
|
||||
pixel_pair.second = "CV_32S";
|
||||
target_type = CV_32S;
|
||||
case libCZI::PixelType::Gray32Float:
|
||||
pixel_pair.first = "Gray32Float";
|
||||
pixel_pair.second = "CV_32F";
|
||||
target_type = CV_32F;
|
||||
pixel_size = 4;
|
||||
break;
|
||||
default:
|
||||
pixel_size = -1;
|
||||
break;
|
||||
}
|
||||
|
||||
if (pixel_size < 0) return std::nullopt;
|
||||
// ToDo(MAK): fix this makeshift pixel-type-catch
|
||||
if (cv_pixel.size < 0 || cv_pixel.size > 4) return std::nullopt;
|
||||
|
||||
log.Info(std::format("{}: source pixel type {}, target cv pixel type {}, pixel size {}", __PRETTY_FUNCTION__,
|
||||
pixel_pair.first, pixel_pair.second, pixel_size));
|
||||
static_cast<uint8_t>(pixeltype), cv_pixel.type, cv_pixel.size));
|
||||
|
||||
size_t height{bitmap->GetHeight()};
|
||||
size_t width{bitmap->GetWidth()};
|
||||
auto fill_mat = cv::Mat(height, width, target_type);
|
||||
auto fill_mat = cv::Mat(height, width, cv_pixel.type);
|
||||
|
||||
auto bitmap_info = bitmap->Lock();
|
||||
|
||||
for (size_t h{0}; h < height; ++h)
|
||||
if (const auto bitmap_info = bitmap->Lock(); bitmap_info.ptrDataRoi)
|
||||
{
|
||||
unsigned char* source_row = ((unsigned char*)bitmap_info.ptrDataRoi) + bitmap_info.stride * h;
|
||||
unsigned char* target_row = fill_mat.ptr(h);
|
||||
|
||||
for (size_t w{0}; w < width; ++w)
|
||||
for (size_t h{0}; h < height; ++h)
|
||||
{
|
||||
switch (pixel_size)
|
||||
unsigned char* source_row = ((unsigned char*)bitmap_info.ptrDataRoi) + bitmap_info.stride * h;
|
||||
unsigned char* target_row = fill_mat.ptr(h);
|
||||
|
||||
for (size_t w{0}; w < width; ++w)
|
||||
{
|
||||
case 1:
|
||||
target_row[w] = source_row[w];
|
||||
break;
|
||||
case 2:
|
||||
reinterpret_cast<unsigned short*>(target_row)[w] = reinterpret_cast<unsigned short*>(source_row)[w];
|
||||
break;
|
||||
case 3:
|
||||
target_row[3 * w] = source_row[3 * w];
|
||||
target_row[3 * w + 1] = source_row[3 * w + 1];
|
||||
target_row[3 * w + 2] = source_row[3 * w + 2];
|
||||
break;
|
||||
case 4:
|
||||
reinterpret_cast<std::int32_t*>(target_row)[w] = reinterpret_cast<std::int32_t*>(source_row)[w];
|
||||
break;
|
||||
default:
|
||||
throw std::runtime_error("Unknown pixel type requested!");
|
||||
break;
|
||||
switch (cv_pixel.size)
|
||||
{
|
||||
case 1:
|
||||
target_row[w] = source_row[w];
|
||||
break;
|
||||
case 2:
|
||||
reinterpret_cast<unsigned short*>(target_row)[w] =
|
||||
reinterpret_cast<unsigned short*>(source_row)[w];
|
||||
break;
|
||||
case 3:
|
||||
target_row[3 * w] = source_row[3 * w];
|
||||
target_row[3 * w + 1] = source_row[3 * w + 1];
|
||||
target_row[3 * w + 2] = source_row[3 * w + 2];
|
||||
break;
|
||||
case 4:
|
||||
reinterpret_cast<std::int32_t*>(target_row)[w] = reinterpret_cast<std::int32_t*>(source_row)[w];
|
||||
break;
|
||||
default:
|
||||
throw std::runtime_error("Unknown pixel type requested!");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// this is outside of the previous if-clause on purpose:
|
||||
// no matter if we reach the inner scope of this clause, we locked the bitmap,
|
||||
// so here it has to be unlocked.
|
||||
bitmap->Unlock();
|
||||
|
||||
return fill_mat;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,9 +3,41 @@
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "../IPixelariumImage.hpp"
|
||||
#include "ILog.hpp"
|
||||
#include "IPixelariumImage.hpp"
|
||||
#include "libCZI.h"
|
||||
#include "utilities/ILog.hpp"
|
||||
#include "libCZI_Pixels.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
struct CvPixelTypeAndSize
|
||||
{
|
||||
int size{-1};
|
||||
int type{-1};
|
||||
};
|
||||
|
||||
template <typename P>
|
||||
[[nodiscard]] constexpr auto GetCVPixelTypeAndSize(P p) noexcept -> CvPixelTypeAndSize
|
||||
{
|
||||
switch (p)
|
||||
{
|
||||
case libCZI::PixelType::Gray8:
|
||||
return {1, CV_8U};
|
||||
case libCZI::PixelType::Gray16:
|
||||
return {2, CV_16U};
|
||||
case libCZI::PixelType::Bgr24:
|
||||
return {3, CV_8UC3};
|
||||
case libCZI::PixelType::Bgra32:
|
||||
return {4, CV_8UC4};
|
||||
case libCZI::PixelType::Gray32:
|
||||
return {4, CV_32S};
|
||||
case libCZI::PixelType::Gray32Float:
|
||||
return {4, CV_32F};
|
||||
default:
|
||||
return {};
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
namespace pixelarium::imaging
|
||||
{
|
||||
@@ -3,7 +3,7 @@
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
|
||||
#include "../IPixelariumImage.hpp"
|
||||
#include "IPixelariumImage.hpp"
|
||||
|
||||
namespace pixelarium::imaging
|
||||
{
|
||||
@@ -3,8 +3,8 @@
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
|
||||
#include "../IPixelariumImage.hpp"
|
||||
#include "utilities/ILog.hpp"
|
||||
#include "ILog.hpp"
|
||||
#include "IPixelariumImage.hpp"
|
||||
|
||||
namespace pixelarium::imaging
|
||||
{
|
||||
@@ -3,7 +3,7 @@
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
|
||||
#include "../IPixelariumImage.hpp"
|
||||
#include "IPixelariumImage.hpp"
|
||||
|
||||
namespace pixelarium::imaging
|
||||
{
|
||||
@@ -3,8 +3,8 @@
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
|
||||
#include "../IPixelariumImage.hpp"
|
||||
#include "utilities/ILog.hpp"
|
||||
#include "ILog.hpp"
|
||||
#include "IPixelariumImage.hpp"
|
||||
|
||||
namespace pixelarium::imaging
|
||||
{
|
||||
@@ -93,6 +93,8 @@ class IPixelariumImage
|
||||
std::filesystem::path uri_;
|
||||
};
|
||||
|
||||
/// @brief Interface template specialization of IPixelariumImage
|
||||
/// using cv::Mat as the wrapped data type.
|
||||
class IPixelariumImageCvMat : public IPixelariumImage<cv::Mat>
|
||||
{
|
||||
public:
|
||||
+2
-1
@@ -2,8 +2,9 @@
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "ILog.hpp"
|
||||
#include "IPixelariumImage.hpp"
|
||||
#include "utilities/ILog.hpp"
|
||||
|
||||
namespace pixelarium::imaging
|
||||
{
|
||||
constexpr pixelarium::imaging::ImageFileType ExtensionToType(const std::string& extension)
|
||||
Reference in New Issue
Block a user