From afd1e274fd0a21d50ae88dfe45cc0db18eedb97e Mon Sep 17 00:00:00 2001 From: Pavel Krajcevski Date: Sun, 26 Aug 2012 20:31:41 -0400 Subject: [PATCH] Add support for cmake to look for libpng and then add the proper files if available. --- IO/CMakeLists.txt | 9 +++++++++ IO/ImageFile.cpp | 6 +++++- IO/ImageLoader.h.in | 2 ++ IO/ImageLoaderPNG.cpp | 14 ++++++++++++++ IO/ImageLoaderPNG.h | 6 +++--- 5 files changed, 33 insertions(+), 4 deletions(-) create mode 100644 IO/ImageLoaderPNG.cpp diff --git a/IO/CMakeLists.txt b/IO/CMakeLists.txt index e62b223..89ced9d 100644 --- a/IO/CMakeLists.txt +++ b/IO/CMakeLists.txt @@ -8,6 +8,15 @@ SET( HEADERS ImageFile.h ) +FIND_PACKAGE( PNG ) +IF( PNG_FOUND ) + INCLUDE_DIRECTORIES( ${PNG_INCLUDE_DIR} ) + TARGET_LINK_LIBRARIES( ${PNG_LIBRARY} ) + + SET( SOURCES ${SOURCES} ImageLoaderPNG.cpp ) + SET( HEADERS ${HEADERS} ImageLoaderPNG.h ) +ENDIF() + CONFIGURE_FILE( "ImageLoader.h.in" "ImageLoader.h" diff --git a/IO/ImageFile.cpp b/IO/ImageFile.cpp index 00ee9a4..19d9e75 100644 --- a/IO/ImageFile.cpp +++ b/IO/ImageFile.cpp @@ -1,5 +1,9 @@ -#include "ImageFile.h" #include +#include "ImageFile.h" + +#ifdef PNG_FOUND +# include "ImageLoaderPNG.h" +#endif ImageFile::ImageFile(const char *filename) : m_PixelData(0), diff --git a/IO/ImageLoader.h.in b/IO/ImageLoader.h.in index 4ce6473..9b54d9b 100644 --- a/IO/ImageLoader.h.in +++ b/IO/ImageLoader.h.in @@ -43,4 +43,6 @@ class ImageLoader { unsigned char * GetAlphaPixelData() const { return m_AlphaData; } }; +#cmakedefine PNG_FOUND + #endif // _IMAGE_LOADER_H_ diff --git a/IO/ImageLoaderPNG.cpp b/IO/ImageLoaderPNG.cpp new file mode 100644 index 0000000..9c8f8a6 --- /dev/null +++ b/IO/ImageLoaderPNG.cpp @@ -0,0 +1,14 @@ +#include "ImageLoaderPNG.h" + +#include + +ImageLoaderPNG::ImageLoaderPNG(const unsigned char *rawData) + : ImageLoader(rawData) +{ +} + +ImageLoaderPNG::~ImageLoaderPNG() { +} + +void ImageLoaderPNG::ReadData() { +} diff --git a/IO/ImageLoaderPNG.h b/IO/ImageLoaderPNG.h index d2bf7cf..dfb80e0 100644 --- a/IO/ImageLoaderPNG.h +++ b/IO/ImageLoaderPNG.h @@ -5,10 +5,10 @@ class ImageLoaderPNG : public ImageLoader { public: - ImageLoader(const unsigned char *rawData); - virtual ~ImageLoader(); + ImageLoaderPNG(const unsigned char *rawData); + virtual ~ImageLoaderPNG(); - void ReadData(); + virtual void ReadData(); }; #endif // _IMAGE_LOADER_H_