Skip to content

Commit

Permalink
Merge pull request #3 from sot-tech/gif_alpha
Browse files Browse the repository at this point in the history
Implement GIF transparency
  • Loading branch information
sot-tech committed Nov 12, 2021
2 parents e515646 + 34e7e04 commit 77ada8e
Show file tree
Hide file tree
Showing 33 changed files with 1,943 additions and 1,769 deletions.
7 changes: 3 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/.idea
/build
/dist
/nbproject/private
/AnimatedSticker.tgs
/AnimatedSticker.json
/out*
/cmake-build*
/test/out
9 changes: 9 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[submodule "3p/giflib"]
path = lib/giflib
url = git://git.code.sf.net/p/giflib/code
[submodule "3p/rlottie"]
path = lib/rlottie
url = https://github.com/Samsung/rlottie.git
[submodule "3p/libpng"]
path = lib/libpng
url = git://git.code.sf.net/p/libpng/code
143 changes: 143 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
cmake_minimum_required(VERSION 3.18 FATAL_ERROR)
project(lottieconverter)
include(ExternalProject)
include(FindPackageMessage)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_C_STANDARD 99)
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(CMAKE_C_STANDARD_REQUIRED True)
set(ZLIB_MINIMUM 1.2.3)
set(PNG_MINIMUM 1.6.0)

set(COMPILE_PARAMS -Wall)
set(SOURCE_FILES lottie_export.cpp)
set(LIBS z)
set(INCLUDES)
add_executable(${PROJECT_NAME})

if (CMAKE_BUILD_TYPE EQUAL "RELEASE")
set(COMPILE_PARAMS ${COMPILE_PARAMS} -O2)
else(CMAKE_BUILD_TYPE)
set(COMPILE_PARAMS ${COMPILE_PARAMS} -O0 -g3)
endif()

option(SYSTEM_PNG "Use system dynamic libpng" 1)
option(SYSTEM_RL "Use system dynamic rlottie" 0)
option(SYSTEM_GL "Use system shared giflib" 0)

enable_testing()


find_package(ZLIB ${ZLIB_MINIMUM} REQUIRED)

if(SYSTEM_PNG)
find_package(PNG ${PNG_MINIMUM} REQUIRED)
set(LIBS ${LIBS} png)
else()
message(NOTICE "-- Building static libpng")
ExternalProject_Add(
png
URL "${CMAKE_SOURCE_DIR}/lib/libpng"
${ARGN}
PREFIX "${CMAKE_BINARY_DIR}/lib/libpng"
CMAKE_ARGS
-Wno-dev
"-DCMAKE_TOOLCHAIN_FILE:PATH=${CMAKE_TOOLCHAIN_FILE}"
"-DCMAKE_USER_MAKE_RULES_OVERRIDE=${CMAKE_USER_MAKE_RULES_OVERRIDE}"
"-DCMAKE_C_FLAGS:STRING=${CMAKE_C_FLAGS}"
"-DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}"
"-DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>"
"-DBUILD_SHARED_LIBS=OFF"
"-DPNG_SHARED=OFF"
"-DPNG_TESTS=OFF"
"-DCMAKE_INSTALL_LIBDIR=${CMAKE_BINARY_DIR}/lib/libpng"
BUILD_BYPRODUCTS "${CMAKE_BINARY_DIR}/lib/libpng/libpng.a"
)
set(INCLUDES ${INCLUDES} "${CMAKE_BINARY_DIR}/lib/libpng/include")
set(LIBS ${LIBS} pthread "${CMAKE_BINARY_DIR}/lib/libpng/libpng.a")
add_dependencies(${PROJECT_NAME} png)
endif()

if (SYSTEM_RL)
find_path(RL_INCLUDEDIR NAMES rlottie.h HINTS ${_RL_INCLUDEDIR} REQUIRED)
find_library(RL_LIBDIR NAMES rlottie HINTS ${_RL_LIBDIR} REQUIRED)
find_package_message(rlottie "Found RLOTTIE: ${RL_LIBDIR}" "Include path: ${RL_INCLUDEDIR}")
set(LIBS ${LIBS} "${RL_LIBDIR}")
set(INCLUDES ${INCLUDES} "${RL_INCLUDEDIR}")
else ()
message(NOTICE "-- Building static rlottie")
ExternalProject_Add(
rlottie
URL "${CMAKE_SOURCE_DIR}/lib/rlottie"
${ARGN}
PREFIX "${CMAKE_BINARY_DIR}/lib/rlottie"
CMAKE_ARGS
-Wno-dev
"-DCMAKE_TOOLCHAIN_FILE:PATH=${CMAKE_TOOLCHAIN_FILE}"
"-DCMAKE_USER_MAKE_RULES_OVERRIDE=${CMAKE_USER_MAKE_RULES_OVERRIDE}"
"-DCMAKE_C_FLAGS:STRING=${CMAKE_C_FLAGS}"
"-DCMAKE_CXX_FLAGS:STRING=${CMAKE_CXX_FLAGS}"
"-DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}"
"-DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>"
"-DLOTTIE_MODULE=OFF"
"-DBUILD_SHARED_LIBS=OFF"
"-DLIB_INSTALL_DIR=${CMAKE_BINARY_DIR}/lib/rlottie"
BUILD_BYPRODUCTS "${CMAKE_BINARY_DIR}/lib/rlottie/librlottie.a"
)
set(INCLUDES ${INCLUDES} "${CMAKE_BINARY_DIR}/lib/rlottie/include")
set(LIBS ${LIBS} pthread "${CMAKE_BINARY_DIR}/lib/rlottie/librlottie.a")
add_dependencies(${PROJECT_NAME} rlottie)
endif ()

if(SYSTEM_GL)
find_path(GL_INCLUDEDIR NAMES gif_lib.h HINTS ${_GL_INCLUDEDIR} REQUIRED)
find_library(GL_LIBDIR NAMES gif HINTS ${_GL_LIBDIR} REQUIRED)
find_package_message(gif "Found GIF: ${GL_LIBDIR}" "Include path: ${GL_INCLUDEDIR}")
set(INCLUDES ${INCLUDES} "${GL_INCLUDEDIR}")
set(LIBS ${LIBS} "${GL_LIBDIR}")
set(SOURCE_FILES ${SOURCE_FILES} gif_quantize.c)
else()
message(NOTICE "-- Building static giflib")
file(COPY ${CMAKE_SOURCE_DIR}/lib/giflib DESTINATION ${CMAKE_BINARY_DIR}/lib)

add_custom_target(
giflibProject
COMMAND make libgif.a libutil.a
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/lib/giflib"
BYPRODUCTS "${CMAKE_BINARY_DIR}/lib/giflib/libgif.a" "${CMAKE_BINARY_DIR}/lib/giflib/libutil.a"
)

add_library(giflibUtil STATIC IMPORTED)
add_dependencies(giflibUtil giflibProject)
set_target_properties(giflibUtil
PROPERTIES IMPORTED_LOCATION "${CMAKE_BINARY_DIR}/lib/giflib/libutil.a"
)

add_library(giflibMain STATIC IMPORTED)
add_dependencies(giflibMain giflibProject)
set_target_properties(giflibMain
PROPERTIES IMPORTED_LOCATION "${CMAKE_BINARY_DIR}/lib/giflib/libgif.a"
)

add_library(giflib INTERFACE IMPORTED)
set_property(TARGET giflib PROPERTY
INTERFACE_LINK_LIBRARIES giflibUtil giflibMain)
#add_dependencies(giflib giflibMain giflibUtil)

set(LIBS ${LIBS} giflib)
add_dependencies(${PROJECT_NAME} giflib)
set(INCLUDES ${INCLUDES} "${CMAKE_BINARY_DIR}/lib/giflib")
endif()

if(INCLUDES)
include_directories(${INCLUDES})
endif()
target_sources(${PROJECT_NAME} PRIVATE ${SOURCE_FILES})
target_compile_options(${PROJECT_NAME} PUBLIC PRIVATE ${COMPILE_PARAMS})
target_link_libraries(${PROJECT_NAME} PUBLIC ${LIBS})

add_test(NAME convert
COMMAND run.sh $<TARGET_FILE:lottieconverter>
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/test"
)
24 changes: 24 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
BSD-3-Clause
Copyright 2021 sot

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
128 changes: 0 additions & 128 deletions Makefile

This file was deleted.

0 comments on commit 77ada8e

Please sign in to comment.