Repairing Windows build.

This commit is contained in:
jmsgrogan 2022-08-17 09:04:52 +01:00
parent 877d96462d
commit a95439d419
12 changed files with 144 additions and 55 deletions

View file

@ -2,11 +2,13 @@
#include "RandomUtils.h"
#ifdef __linux__
#include <unistd.h>
#include <sys/types.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <fcntl.h>
#endif
void SharedMemory::allocate(const std::string& namePrefix, std::size_t size)
{
@ -17,6 +19,7 @@ void SharedMemory::allocate(const std::string& namePrefix, std::size_t size)
return;
}
#ifdef __linux__
int ret{-1};
do {
ret = ftruncate(mFileDescriptor, size);
@ -27,6 +30,7 @@ void SharedMemory::allocate(const std::string& namePrefix, std::size_t size)
close(mFileDescriptor);
mIsValid = false;
}
#endif
}
int SharedMemory::getFileDescriptor() const
@ -41,6 +45,7 @@ bool SharedMemory::isValid() const
void SharedMemory::createFile(const std::string& namePrefix)
{
#ifdef __linux__
unsigned retries = 100;
do {
const auto name = getRandomName(namePrefix);
@ -55,6 +60,7 @@ void SharedMemory::createFile(const std::string& namePrefix)
break;
}
} while (retries > 0 && errno == EEXIST);
#endif
}
std::string SharedMemory::getRandomName(const std::string& namePrefix) const

View file

@ -1,22 +1,37 @@
list(APPEND image_HEADERS
Image.h
PngWriter.h
PngWriterBasic.h
PngWriterImpl.h
)
list(APPEND image_LIB_INCLUDES
Image.cpp
PngWriter.cpp
PngWriterBasic.cpp
PngReader.cpp
)
list(APPEND image_LIBS core)
find_package(PNG QUIET)
if(PNG_FOUND)
list(APPEND image_LIBS PNG::PNG)
list(APPEND image_LIB_INCLUDES
PngWriterLibPng.cpp
)
target_compile_definitions(image PRIVATE HAS_LIBPNG)
else()
message(STATUS "LIBRARY CHECK: libPNG not found - disabling libPNG based image i/o.")
endif()
add_library(image SHARED ${image_LIB_INCLUDES} ${image_HEADERS})
target_include_directories(image PUBLIC
"${CMAKE_CURRENT_SOURCE_DIR}"
)
set_target_properties( image PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON )
set_target_properties( image PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON )
find_package(PNG REQUIRED)
target_link_libraries( image PUBLIC PNG::PNG core)
target_link_libraries( image PUBLIC ${image_LIBS})
set_property(TARGET image PROPERTY FOLDER src)

View file

@ -4,6 +4,7 @@
#include "Image.h"
#include <iostream>
#include <sstream>
PngReader::~PngReader()
{

View file

@ -2,9 +2,23 @@
#include "Image.h"
#ifdef HAS_LIBPNG
#include <png.h>
#include "PngWriterLibPng.h"
#else
#include "PngWriterBasic.h"
#endif
#include <stdio.h>
PngWriter::PngWriter()
{
#ifdef HAS_LIBPNG
mImpl = std::make_unique<PngWriterLibPng>();
#else
mImpl = std::make_unique<PngWriterBasic>();
#endif
}
std::unique_ptr<PngWriter> PngWriter::Create()
{
return std::make_unique<PngWriter>();
@ -12,63 +26,64 @@ std::unique_ptr<PngWriter> PngWriter::Create()
void PngWriter::SetPath(const std::string& path)
{
mPath = path;
mImpl->setPath(path);
}
void PngWriter::Write(const std::unique_ptr<Image>& image) const
{
auto fp = fopen(mPath.c_str(), "wb");
mImpl->write(image);
//auto fp = fopen(mPath.c_str(), "wb");
auto png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, nullptr, nullptr, nullptr);
auto info_ptr = png_create_info_struct(png_ptr);
//auto png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, nullptr, nullptr, nullptr);
//auto info_ptr = png_create_info_struct(png_ptr);
if (setjmp(png_jmpbuf(png_ptr)))
{
return;
}
png_init_io(png_ptr, fp);
//if (setjmp(png_jmpbuf(png_ptr)))
//{
// return;
//}
//png_init_io(png_ptr, fp);
if (setjmp(png_jmpbuf(png_ptr)))
{
return;
}
auto color_type = PNG_COLOR_TYPE_RGB;
png_set_IHDR(png_ptr, info_ptr, image->GetWidth(), image->GetHeight(),
image->GetBitDepth(), color_type, PNG_INTERLACE_NONE,
PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
//if (setjmp(png_jmpbuf(png_ptr)))
//{
// return;
//}
//auto color_type = PNG_COLOR_TYPE_RGB;
//png_set_IHDR(png_ptr, info_ptr, image->GetWidth(), image->GetHeight(),
// image->GetBitDepth(), color_type, PNG_INTERLACE_NONE,
// PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
png_write_info(png_ptr, info_ptr);
//png_write_info(png_ptr, info_ptr);
if (setjmp(png_jmpbuf(png_ptr)))
{
return;
}
//if (setjmp(png_jmpbuf(png_ptr)))
//{
// return;
//}
png_bytep* row_pointers = (png_bytep*)malloc(sizeof(png_bytep) * image->GetHeight());
auto row_size = image->GetBytesPerRow();
for(unsigned jdx=0;jdx<image->GetHeight();jdx++)
{
row_pointers[jdx]=(png_byte*)malloc(sizeof(png_byte)*row_size);
for(unsigned idx=0;idx<row_size;idx++)
{
row_pointers[jdx][idx] = image->GetByte(idx, jdx);
}
}
png_write_image(png_ptr, row_pointers);
if (setjmp(png_jmpbuf(png_ptr)))
{
return;
}
//png_bytep* row_pointers = (png_bytep*)malloc(sizeof(png_bytep) * image->GetHeight());
//auto row_size = image->GetBytesPerRow();
//for(unsigned jdx=0;jdx<image->GetHeight();jdx++)
//{
// row_pointers[jdx]=(png_byte*)malloc(sizeof(png_byte)*row_size);
// for(unsigned idx=0;idx<row_size;idx++)
// {
// row_pointers[jdx][idx] = image->GetByte(idx, jdx);
// }
//}
//png_write_image(png_ptr, row_pointers);
//if (setjmp(png_jmpbuf(png_ptr)))
//{
// return;
//}
png_write_end(png_ptr, nullptr);
//png_write_end(png_ptr, nullptr);
for (unsigned y=0; y<image->GetHeight(); y++)
{
free(row_pointers[y]);
}
free(row_pointers);
//for (unsigned y=0; y<image->GetHeight(); y++)
//{
// free(row_pointers[y]);
//}
//free(row_pointers);
fclose(fp);
return;
//fclose(fp);
//return;
}

View file

@ -4,10 +4,13 @@
#include <string>
class Image;
class PngWriterImpl;
class PngWriter
{
public:
PngWriter();
static std::unique_ptr<PngWriter> Create();
void SetPath(const std::string& path);
@ -15,8 +18,8 @@ public:
void Write(const std::unique_ptr<Image>& image) const;
private:
std::unique_ptr<PngWriterImpl> mImpl;
std::string mPath;
};
using PngWriterPtr = std::unique_ptr<PngWriter>;

View file

@ -0,0 +1,11 @@
#include "PngWriterBasic.h"
void PngWriterBasic::setPath(const std::string& path)
{
}
void PngWriterBasic::write(const std::unique_ptr<Image>& image) const
{
}

View file

@ -0,0 +1,14 @@
#pragma once
#include "PngWriterImpl.h"
class PngWriterBasic : public PngWriterImpl
{
public:
void setPath(const std::string& path) override;
void write(const std::unique_ptr<Image>& image) const override;
private:
std::string mPath;
};

14
src/image/PngWriterImpl.h Normal file
View file

@ -0,0 +1,14 @@
#pragma once
#include <string>
#include <memory>
class Image;
class PngWriterImpl
{
public:
virtual void setPath(const std::string& path) = 0;
virtual void write(const std::unique_ptr<Image>& image) const = 0;
};

View file

View file

View file

@ -15,8 +15,12 @@ target_include_directories(video PUBLIC
)
set_target_properties( video PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON )
find_package(PkgConfig REQUIRED)
pkg_check_modules(LIBAV REQUIRED IMPORTED_TARGET
list(APPEND video_LIBS image)
find_package(PkgConfig QUIET)
if(PkgConfig)
pkg_check_modules(LIBAV IMPORTED_TARGET
libavdevice
libavfilter
libavformat
@ -24,7 +28,13 @@ pkg_check_modules(LIBAV REQUIRED IMPORTED_TARGET
libswresample
libswscale
libavutil
)
target_link_libraries( video PUBLIC image PkgConfig::LIBAV)
)
list(APPEND video_LIBS PkgConfig::LIBAV)
else()
message(STATUS "LIBRARY CHECK: PkgConfig not found - disabling ffmpeg based video i/o.")
endif()
set_property(TARGET image PROPERTY FOLDER src)
target_link_libraries( video PUBLIC ${video_LIBS})
set_property(TARGET video PROPERTY FOLDER src)

View file

@ -48,7 +48,7 @@ list(APPEND TestNames
TestXmlParser)
find_package(PkgConfig)
pkg_check_modules(DBUS REQUIRED dbus-1)
pkg_check_modules(DBUS dbus-1)
include_directories(${DBUS_INCLUDE_DIRS})
link_directories(${DBUS_LIBRARY_DIRS})