Skip to content

Commit

Permalink
Add test files, fix GIF palette ENOMEM error
Browse files Browse the repository at this point in the history
  • Loading branch information
sot-tech committed Nov 12, 2021
1 parent 5dffc2c commit 34e7e04
Show file tree
Hide file tree
Showing 16 changed files with 592 additions and 86 deletions.
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,4 @@
/build
/dist
/cmake-build*
/AnimatedSticker.tgs
/AnimatedSticker.json
/out*
/test/out
25 changes: 19 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@ 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} ${SOURCE_FILES})
add_executable(${PROJECT_NAME})

if (CMAKE_BUILD_TYPE EQUAL "RELEASE")
set(COMPILE_PARAMS ${COMPILE_PARAMS} -O2)
Expand All @@ -24,6 +26,9 @@ 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)
Expand Down Expand Up @@ -57,8 +62,9 @@ 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}" "_")
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(
Expand Down Expand Up @@ -87,8 +93,10 @@ 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}" "_")
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)
Expand Down Expand Up @@ -119,12 +127,17 @@ else()

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

if(INCLUDES)
include_directories(${INCLUDES})
endif()

target_compile_options(${PROJECT_NAME} PUBLIC PRIVATE -std=c++${CMAKE_CXX_STANDARD} ${COMPILE_PARAMS})
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"
)
33 changes: 17 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ Uses:

Parameters:

* input_file - path to lottie json or tgs (gzip-ed json), if set to `-` stdin is used
* output_file - file to be written, if set `-` stdout is used, **note, that for `pngs` type, file name prefix is required**
* type - output format, currently supported: `png`, `gif`, `pngs`
* resolution - size in pixels of out image, should be in `SIZExSIZE` format, default `128x128`
* input_file - path to lottie json or tgs (gzip-ed json), if set to `-` stdin is used;
* output_file - file to be written, if set `-` stdout is used, **note, that for `pngs` type, file name prefix is required**;
* type - output format, currently supported: `png`, `gif`, `pngs`;
* resolution - **desired** size in pixels of out image, should be in `SIZExSIZE` format, default `128x128`. Resulting resolution depends on input;
* option - depends on type, default **10** for all:
* `png` - which frame in percents to extract;
* `pngs` and `gif` - desired frame rate.
Expand Down Expand Up @@ -55,18 +55,19 @@ and if 25 - delay will be exactly 4 'ticks' (5/100 sec.).
Another GIF's problem is transparency. GIF does not support alpha channel,
but one of colors from frame's image palette can be marked as transparent.

Now, transparent color is hardcoded to 0'th (nearest to 000 RGB), so if image contains non-background
elements with this color, they will be marked as transparent.
Now, transparent color is hardcoded to 0'th color in palette, so if image contains non-background
elements with this color, they will be marked as transparent and some artifacts will appear.

## Build
### Basics
1. Clone this repo or download sources from releases page
1. Clone this repo or download sources from releases page;
2. If cloned AND you need included `libpng`, `rlottie` or `giflib`, fetch submodules
by executing `git submodule update --init`
by executing `git submodule update --init`;
3. Execute CMake build:
1. `mkdir build && cd build`
2. `cmake -DCMAKE_BUILD_TYPE=Release .. && cmake --build .`
4. Copy or execute ready `lottieconverter` in `build` subdirectory.
1. `mkdir build && cd build`;
2. `cmake -DCMAKE_BUILD_TYPE=Release .. && cmake --build .`;
4. (optional) Perform test conversions with `ctest` (results will appear in `test/out` directory);
5. Copy or execute ready `lottieconverter` in `build` subdirectory.

### External libraries
By default, project uses system's shared `libpng` library,
Expand All @@ -76,13 +77,13 @@ You can change behaviour by providing cmake options
(`-DSYSTEM_PNG=0 -DSYSTEM_RL=1 -DSYSTEM_GL=0` or any).

Linux's development packages are usually named:
* `libpng-dev`
* `libgif-dev` or `giflib-dev`
* `librlottie-dev`
* `libpng-dev`;
* `libgif-dev` or `giflib-dev`;
* `librlottie-dev`.

and regular library packages:
* `libpng` or `libpng16`
* `libgif` or `libgif7` or `giflib`
* `libpng` or `libpng16`;
* `libgif` or `libgif7` or `giflib`;
* `rlottie` or `librlottie`.

_NB: `zlib` (`zlib1g`) or `zlib-dev` (`zlib1g-dev`) must be pre-installed in your system._
Expand Down
Loading

0 comments on commit 34e7e04

Please sign in to comment.