Skip to content

Commit

Permalink
Optional PNG support
Browse files Browse the repository at this point in the history
As discussed in google#591, this CL sets lodepng as an optional library.
  • Loading branch information
jaebaek committed Jul 24, 2019
1 parent 6e5c1c4 commit 8c4b075
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
13 changes: 11 additions & 2 deletions samples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,16 @@ set(AMBER_SOURCES
config_helper.cc
log.cc
ppm.cc
png.cc
timestamp.cc
${CMAKE_BINARY_DIR}/src/build-versions.h.fake
)

set(AMBER_EXTRA_LIBS "lodepng")
set(AMBER_EXTRA_LIBS "")

if (EXISTS ${PROJECT_SOURCE_DIR}/third_party/lodepng)
set(AMBER_SOURCES ${AMBER_SOURCES} png.cc)
list(APPEND AMBER_EXTRA_LIBS "lodepng")
endif()

if (${Vulkan_FOUND})
set(AMBER_SOURCES ${AMBER_SOURCES} config_helper_vulkan.cc)
Expand All @@ -45,6 +49,11 @@ endif()

add_executable(amber ${AMBER_SOURCES})
target_include_directories(amber PRIVATE "${CMAKE_BINARY_DIR}")

if (EXISTS ${PROJECT_SOURCE_DIR}/third_party/lodepng)
target_compile_definitions(amber PRIVATE LODEPNG_EXIST=1)
endif()

set_target_properties(amber PROPERTIES OUTPUT_NAME "amber")
target_link_libraries(amber libamber ${AMBER_EXTRA_LIBS})
amber_default_compile_options(amber)
Expand Down
10 changes: 9 additions & 1 deletion samples/amber.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,15 @@

#include "amber/recipe.h"
#include "samples/config_helper.h"
#include "samples/png.h"
#include "samples/ppm.h"
#include "samples/timestamp.h"
#include "src/build-versions.h"
#include "src/make_unique.h"

#if LODEPNG_EXIST
#include "samples/png.h"
#endif // LODEPNG_EXIST

namespace {

const char* kGeneratedColorBuffer = "framebuffer";
Expand Down Expand Up @@ -431,8 +434,13 @@ int main(int argc, const char** argv) {
for (const amber::BufferInfo& buffer_info : amber_options.extractions) {
if (buffer_info.buffer_name == options.fb_name) {
if (usePNG) {
#if LODEPNG_EXIST
result = png::ConvertToPNG(buffer_info.width, buffer_info.height,
buffer_info.values, &out_buf);
#else // LODEPNG_EXIST
result =
amber::Result("lodepng does not exit and PNG is not supported");
#endif // LODEPNG_EXIST
} else {
ppm::ConvertToPPM(buffer_info.width, buffer_info.height,
buffer_info.values, &out_buf);
Expand Down
6 changes: 4 additions & 2 deletions third_party/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ endif()

if (${AMBER_ENABLE_SAMPLES})
# Lodepng
set(LODEPNG_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/lodepng/lodepng.cpp)
add_library(lodepng STATIC ${LODEPNG_SOURCES})
if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/lodepng)
set(LODEPNG_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/lodepng/lodepng.cpp)
add_library(lodepng STATIC ${LODEPNG_SOURCES})
endif()
endif()

if (${AMBER_USE_LOCAL_VULKAN})
Expand Down

0 comments on commit 8c4b075

Please sign in to comment.