[cmake] build using external lodepng

This commit is contained in:
Armin Novak 2023-07-26 15:55:06 +02:00 committed by akallabeth
parent bb9c32ed72
commit 605b6b6233
6 changed files with 47 additions and 8232 deletions

19
cmake/Findlodepng.cmake Normal file
View File

@ -0,0 +1,19 @@
# - Try to find lodepng
# Once done this will define
# lodepng_FOUND - cJSON was found
# lodepng_INCLUDE_DIRS - cJSON include directories
# lodepng_LIBRARIES - cJSON libraries for linking
find_path(lodepng_INCLUDE_DIR
NAMES lodepng.h)
find_library(lodepng_LIBRARY
NAMES lodepng)
if (lodepng_INCLUDE_DIR AND lodepng_LIBRARY)
set(lodepng_FOUND ON)
set(lodepng_INCLUDE_DIRS ${lodepng_INCLUDE_DIR})
set(lodepng_LIBRARIES ${lodepng_LIBRARY})
endif()
mark_as_advanced(lodepng_INCLUDE_DIRS lodepng_LIBRARIES)

View File

@ -35,10 +35,6 @@ set(COLLECTIONS_SRCS
collections/MessageQueue.c
collections/MessagePipe.c)
set(LODEPNG_SRCS
lodepng/lodepng.c
lodepng/lodepng.h)
if (WINPR_HAVE_SYSLOG_H)
set(SYSLOG_SRCS
wlog/SyslogAppender.c
@ -142,14 +138,22 @@ endif()
winpr_module_add(${SRCS}
${COLLECTIONS_SRCS}
${LODEPNG_SRCS}
${WLOG_SRCS}
${ASN1_SRCS}
)
winpr_include_directory_add(
"lodepng"
".")
"."
)
option(WITH_LODEPNG "build WinPR with PNG support" OFF)
if (WITH_LODEPNG)
find_package(lodepng REQUIRED)
winpr_definition_add(-DWITH_LODEPNG)
winpr_include_directory_add(${lodepng_INCLUDE_DIRS})
winpr_library_add_private(${lodepng_LIBRARIES})
endif()
if(OPENSSL_FOUND)
winpr_include_directory_add(${OPENSSL_INCLUDE_DIR})

View File

@ -27,7 +27,9 @@
#include <winpr/image.h>
#include "lodepng/lodepng.h"
#if defined(WITH_LODEPNG)
#include <lodepng.h>
#endif
#include <winpr/stream.h>
#include "../log.h"
@ -205,16 +207,18 @@ int winpr_image_write(wImage* image, const char* filename)
status = winpr_bitmap_write(filename, image->data, image->width, image->height,
image->bitsPerPixel);
}
#if defined(WITH_LODEPNG)
else
{
unsigned lodepng_status;
lodepng_status = lodepng_encode32_file(filename, image->data, image->width, image->height);
status = (lodepng_status) ? -1 : 1;
}
#endif
return status;
}
#if defined(WITH_LODEPNG)
static int winpr_image_png_read_fp(wImage* image, FILE* fp)
{
INT64 size;
@ -269,6 +273,7 @@ static int winpr_image_png_read_buffer(wImage* image, const BYTE* buffer, size_t
image->scanline = image->bytesPerPixel * image->width;
return 1;
}
#endif
static int winpr_image_bitmap_read_fp(wImage* image, FILE* fp)
{
@ -463,12 +468,14 @@ int winpr_image_read(wImage* image, const char* filename)
image->type = WINPR_IMAGE_BITMAP;
status = winpr_image_bitmap_read_fp(image, fp);
}
#if defined(WITH_LODEPNG)
else if ((sig[0] == 0x89) && (sig[1] == 'P') && (sig[2] == 'N') && (sig[3] == 'G') &&
(sig[4] == '\r') && (sig[5] == '\n') && (sig[6] == 0x1A) && (sig[7] == '\n'))
{
image->type = WINPR_IMAGE_PNG;
status = winpr_image_png_read_fp(image, fp);
}
#endif
fclose(fp);
return status;
@ -489,12 +496,14 @@ int winpr_image_read_buffer(wImage* image, const BYTE* buffer, size_t size)
image->type = WINPR_IMAGE_BITMAP;
status = winpr_image_bitmap_read_buffer(image, buffer, size);
}
#if defined(WITH_LODEPNG)
else if ((sig[0] == 0x89) && (sig[1] == 'P') && (sig[2] == 'N') && (sig[3] == 'G') &&
(sig[4] == '\r') && (sig[5] == '\n') && (sig[6] == 0x1A) && (sig[7] == '\n'))
{
image->type = WINPR_IMAGE_PNG;
status = winpr_image_png_read_buffer(image, buffer, size);
}
#endif
return status;
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -7,7 +7,6 @@ set(${MODULE_PREFIX}_DRIVER ${MODULE_NAME}.c)
set(${MODULE_PREFIX}_TESTS
TestIni.c
TestVersion.c
TestImage.c
TestBacktrace.c
TestQueue.c
TestPrint.c
@ -27,6 +26,12 @@ set(${MODULE_PREFIX}_TESTS
TestMessageQueue.c
TestMessagePipe.c)
if (WITH_LODEPNG)
list(APPEND ${MODULES_PREFIX}_TESTS
TestImage.c
)
endif()
create_test_sourcelist(${MODULE_PREFIX}_SRCS
${${MODULE_PREFIX}_DRIVER}
${${MODULE_PREFIX}_TESTS})