Skip to content

Commit

Permalink
[cmake] build using external lodepng
Browse files Browse the repository at this point in the history
  • Loading branch information
Armin Novak authored and akallabeth committed Jul 26, 2023
1 parent bb9c32e commit 605b6b6
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 8,232 deletions.
19 changes: 19 additions & 0 deletions cmake/Findlodepng.cmake
@@ -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)
18 changes: 11 additions & 7 deletions winpr/libwinpr/utils/CMakeLists.txt
Expand Up @@ -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
Expand Down Expand Up @@ -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})
Expand Down
13 changes: 11 additions & 2 deletions winpr/libwinpr/utils/image.c
Expand Up @@ -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"
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down

0 comments on commit 605b6b6

Please sign in to comment.