Repairing Windows build.
This commit is contained in:
parent
877d96462d
commit
a95439d419
12 changed files with 144 additions and 55 deletions
|
@ -2,11 +2,13 @@
|
||||||
|
|
||||||
#include "RandomUtils.h"
|
#include "RandomUtils.h"
|
||||||
|
|
||||||
|
#ifdef __linux__
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
void SharedMemory::allocate(const std::string& namePrefix, std::size_t size)
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef __linux__
|
||||||
int ret{-1};
|
int ret{-1};
|
||||||
do {
|
do {
|
||||||
ret = ftruncate(mFileDescriptor, size);
|
ret = ftruncate(mFileDescriptor, size);
|
||||||
|
@ -27,6 +30,7 @@ void SharedMemory::allocate(const std::string& namePrefix, std::size_t size)
|
||||||
close(mFileDescriptor);
|
close(mFileDescriptor);
|
||||||
mIsValid = false;
|
mIsValid = false;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
int SharedMemory::getFileDescriptor() const
|
int SharedMemory::getFileDescriptor() const
|
||||||
|
@ -41,6 +45,7 @@ bool SharedMemory::isValid() const
|
||||||
|
|
||||||
void SharedMemory::createFile(const std::string& namePrefix)
|
void SharedMemory::createFile(const std::string& namePrefix)
|
||||||
{
|
{
|
||||||
|
#ifdef __linux__
|
||||||
unsigned retries = 100;
|
unsigned retries = 100;
|
||||||
do {
|
do {
|
||||||
const auto name = getRandomName(namePrefix);
|
const auto name = getRandomName(namePrefix);
|
||||||
|
@ -55,6 +60,7 @@ void SharedMemory::createFile(const std::string& namePrefix)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} while (retries > 0 && errno == EEXIST);
|
} while (retries > 0 && errno == EEXIST);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string SharedMemory::getRandomName(const std::string& namePrefix) const
|
std::string SharedMemory::getRandomName(const std::string& namePrefix) const
|
||||||
|
|
|
@ -1,14 +1,30 @@
|
||||||
list(APPEND image_HEADERS
|
list(APPEND image_HEADERS
|
||||||
Image.h
|
Image.h
|
||||||
PngWriter.h
|
PngWriter.h
|
||||||
|
PngWriterBasic.h
|
||||||
|
PngWriterImpl.h
|
||||||
)
|
)
|
||||||
|
|
||||||
list(APPEND image_LIB_INCLUDES
|
list(APPEND image_LIB_INCLUDES
|
||||||
Image.cpp
|
Image.cpp
|
||||||
PngWriter.cpp
|
PngWriter.cpp
|
||||||
|
PngWriterBasic.cpp
|
||||||
PngReader.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})
|
add_library(image SHARED ${image_LIB_INCLUDES} ${image_HEADERS})
|
||||||
|
|
||||||
target_include_directories(image PUBLIC
|
target_include_directories(image PUBLIC
|
||||||
|
@ -16,7 +32,6 @@ target_include_directories(image PUBLIC
|
||||||
)
|
)
|
||||||
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 ${image_LIBS})
|
||||||
target_link_libraries( image PUBLIC PNG::PNG core)
|
|
||||||
|
|
||||||
set_property(TARGET image PROPERTY FOLDER src)
|
set_property(TARGET image PROPERTY FOLDER src)
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
#include "Image.h"
|
#include "Image.h"
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
PngReader::~PngReader()
|
PngReader::~PngReader()
|
||||||
{
|
{
|
||||||
|
|
|
@ -2,9 +2,23 @@
|
||||||
|
|
||||||
#include "Image.h"
|
#include "Image.h"
|
||||||
|
|
||||||
|
#ifdef HAS_LIBPNG
|
||||||
#include <png.h>
|
#include <png.h>
|
||||||
|
#include "PngWriterLibPng.h"
|
||||||
|
#else
|
||||||
|
#include "PngWriterBasic.h"
|
||||||
|
#endif
|
||||||
#include <stdio.h>
|
#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()
|
std::unique_ptr<PngWriter> PngWriter::Create()
|
||||||
{
|
{
|
||||||
return std::make_unique<PngWriter>();
|
return std::make_unique<PngWriter>();
|
||||||
|
@ -12,63 +26,64 @@ std::unique_ptr<PngWriter> PngWriter::Create()
|
||||||
|
|
||||||
void PngWriter::SetPath(const std::string& path)
|
void PngWriter::SetPath(const std::string& path)
|
||||||
{
|
{
|
||||||
mPath = path;
|
mImpl->setPath(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PngWriter::Write(const std::unique_ptr<Image>& image) const
|
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 png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, nullptr, nullptr, nullptr);
|
||||||
auto info_ptr = png_create_info_struct(png_ptr);
|
//auto info_ptr = png_create_info_struct(png_ptr);
|
||||||
|
|
||||||
if (setjmp(png_jmpbuf(png_ptr)))
|
//if (setjmp(png_jmpbuf(png_ptr)))
|
||||||
{
|
//{
|
||||||
return;
|
// return;
|
||||||
}
|
//}
|
||||||
png_init_io(png_ptr, fp);
|
//png_init_io(png_ptr, fp);
|
||||||
|
|
||||||
|
|
||||||
if (setjmp(png_jmpbuf(png_ptr)))
|
//if (setjmp(png_jmpbuf(png_ptr)))
|
||||||
{
|
//{
|
||||||
return;
|
// return;
|
||||||
}
|
//}
|
||||||
auto color_type = PNG_COLOR_TYPE_RGB;
|
//auto color_type = PNG_COLOR_TYPE_RGB;
|
||||||
png_set_IHDR(png_ptr, info_ptr, image->GetWidth(), image->GetHeight(),
|
//png_set_IHDR(png_ptr, info_ptr, image->GetWidth(), image->GetHeight(),
|
||||||
image->GetBitDepth(), color_type, PNG_INTERLACE_NONE,
|
// image->GetBitDepth(), color_type, PNG_INTERLACE_NONE,
|
||||||
PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
|
// 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)))
|
//if (setjmp(png_jmpbuf(png_ptr)))
|
||||||
{
|
//{
|
||||||
return;
|
// return;
|
||||||
}
|
//}
|
||||||
|
|
||||||
png_bytep* row_pointers = (png_bytep*)malloc(sizeof(png_bytep) * image->GetHeight());
|
//png_bytep* row_pointers = (png_bytep*)malloc(sizeof(png_bytep) * image->GetHeight());
|
||||||
auto row_size = image->GetBytesPerRow();
|
//auto row_size = image->GetBytesPerRow();
|
||||||
for(unsigned jdx=0;jdx<image->GetHeight();jdx++)
|
//for(unsigned jdx=0;jdx<image->GetHeight();jdx++)
|
||||||
{
|
//{
|
||||||
row_pointers[jdx]=(png_byte*)malloc(sizeof(png_byte)*row_size);
|
// row_pointers[jdx]=(png_byte*)malloc(sizeof(png_byte)*row_size);
|
||||||
for(unsigned idx=0;idx<row_size;idx++)
|
// for(unsigned idx=0;idx<row_size;idx++)
|
||||||
{
|
// {
|
||||||
row_pointers[jdx][idx] = image->GetByte(idx, jdx);
|
// row_pointers[jdx][idx] = image->GetByte(idx, jdx);
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
png_write_image(png_ptr, row_pointers);
|
//png_write_image(png_ptr, row_pointers);
|
||||||
if (setjmp(png_jmpbuf(png_ptr)))
|
//if (setjmp(png_jmpbuf(png_ptr)))
|
||||||
{
|
//{
|
||||||
return;
|
// return;
|
||||||
}
|
//}
|
||||||
|
|
||||||
png_write_end(png_ptr, nullptr);
|
//png_write_end(png_ptr, nullptr);
|
||||||
|
|
||||||
for (unsigned y=0; y<image->GetHeight(); y++)
|
//for (unsigned y=0; y<image->GetHeight(); y++)
|
||||||
{
|
//{
|
||||||
free(row_pointers[y]);
|
// free(row_pointers[y]);
|
||||||
}
|
//}
|
||||||
free(row_pointers);
|
//free(row_pointers);
|
||||||
|
|
||||||
fclose(fp);
|
//fclose(fp);
|
||||||
return;
|
//return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,10 +4,13 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
class Image;
|
class Image;
|
||||||
|
class PngWriterImpl;
|
||||||
|
|
||||||
class PngWriter
|
class PngWriter
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
PngWriter();
|
||||||
|
|
||||||
static std::unique_ptr<PngWriter> Create();
|
static std::unique_ptr<PngWriter> Create();
|
||||||
|
|
||||||
void SetPath(const std::string& path);
|
void SetPath(const std::string& path);
|
||||||
|
@ -15,8 +18,8 @@ public:
|
||||||
void Write(const std::unique_ptr<Image>& image) const;
|
void Write(const std::unique_ptr<Image>& image) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
std::unique_ptr<PngWriterImpl> mImpl;
|
||||||
|
|
||||||
std::string mPath;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
using PngWriterPtr = std::unique_ptr<PngWriter>;
|
using PngWriterPtr = std::unique_ptr<PngWriter>;
|
||||||
|
|
11
src/image/PngWriterBasic.cpp
Normal file
11
src/image/PngWriterBasic.cpp
Normal 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
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
14
src/image/PngWriterBasic.h
Normal file
14
src/image/PngWriterBasic.h
Normal 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
14
src/image/PngWriterImpl.h
Normal 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;
|
||||||
|
};
|
0
src/image/PngWriterLibPng.cpp
Normal file
0
src/image/PngWriterLibPng.cpp
Normal file
0
src/image/PngWriterLibPng.h
Normal file
0
src/image/PngWriterLibPng.h
Normal file
|
@ -15,8 +15,12 @@ target_include_directories(video PUBLIC
|
||||||
)
|
)
|
||||||
set_target_properties( video PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON )
|
set_target_properties( video PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON )
|
||||||
|
|
||||||
find_package(PkgConfig REQUIRED)
|
list(APPEND video_LIBS image)
|
||||||
pkg_check_modules(LIBAV REQUIRED IMPORTED_TARGET
|
|
||||||
|
find_package(PkgConfig QUIET)
|
||||||
|
|
||||||
|
if(PkgConfig)
|
||||||
|
pkg_check_modules(LIBAV IMPORTED_TARGET
|
||||||
libavdevice
|
libavdevice
|
||||||
libavfilter
|
libavfilter
|
||||||
libavformat
|
libavformat
|
||||||
|
@ -25,6 +29,12 @@ pkg_check_modules(LIBAV REQUIRED IMPORTED_TARGET
|
||||||
libswscale
|
libswscale
|
||||||
libavutil
|
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)
|
|
@ -48,7 +48,7 @@ list(APPEND TestNames
|
||||||
TestXmlParser)
|
TestXmlParser)
|
||||||
|
|
||||||
find_package(PkgConfig)
|
find_package(PkgConfig)
|
||||||
pkg_check_modules(DBUS REQUIRED dbus-1)
|
pkg_check_modules(DBUS dbus-1)
|
||||||
include_directories(${DBUS_INCLUDE_DIRS})
|
include_directories(${DBUS_INCLUDE_DIRS})
|
||||||
link_directories(${DBUS_LIBRARY_DIRS})
|
link_directories(${DBUS_LIBRARY_DIRS})
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue