Initial commit

This commit is contained in:
ave 2020-12-05 00:02:42 +03:00
commit 450bc86905
7 changed files with 8626 additions and 0 deletions

35
.gitignore vendored Normal file
View file

@ -0,0 +1,35 @@
# ---> C++
# Prerequisites
*.d
# Compiled Object files
*.slo
*.lo
*.o
*.obj
# Precompiled Headers
*.gch
*.pch
# Compiled Dynamic libraries
*.so
*.dylib
*.dll
# Fortran module files
*.mod
*.smod
# Compiled Static libraries
*.lai
*.la
*.a
*.lib
# Executables
*.exe
*.out
*.app
lfe

19
LICENSE Normal file
View file

@ -0,0 +1,19 @@
MIT License Copyright (c) <year> <copyright holders>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:
The above copyright notice and this permission notice (including the next
paragraph) shall be included in all copies or substantial portions of the
Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

13
Makefile Normal file
View file

@ -0,0 +1,13 @@
CC = g++
CFLAGS = -O3 -Wall
LIBS = -lrlottie
DEPS = lodepng.cpp
TARGET = lfe
all: $(TARGET)
$(TARGET): $(TARGET).cpp
$(CC) $(CFLAGS) $(LIBS) -o $(TARGET) $(DEPS) $(TARGET).cpp
clean:
$(RM) $(TARGET)

31
README.md Normal file
View file

@ -0,0 +1,31 @@
# LFE
Tool to extract PNG frames from Lottie animations using rlottie.
Codebase is a mess. You've been warned.
## Deps
- https://github.com/Samsung/rlottie -> Don't forget to do make install
- https://github.com/lvandeve/lodepng -> Already included here. Licensed Zlib.
## How to build
```bash
make
```
You'll need g++.
## How to use
```bash
./lfe mylottieanimation.json 420x420
```
This will extract all frames as PNG files in the working directory.
## Credit where it's due
- Most of the rlottie code is based on lottie2gif.cpp example from https://github.com/Samsung/rlottie (MIT)
- The PNG encoding related code is based on lodepng's examples

87
lfe.cpp Normal file
View file

@ -0,0 +1,87 @@
#include "lodepng.h"
#include <rlottie.h>
#include<iostream>
#include<string>
#include<vector>
#include<array>
void encodePNG(const char* filename, std::vector<unsigned char>& image, unsigned width, unsigned height) {
unsigned error = lodepng::encode(filename, image, width, height);
if(error) std::cout << "encoder error " << error << ": "<< lodepng_error_text(error) << std::endl;
}
void renderFrame(size_t i, rlottie::Surface &s)
{
uint8_t *buffer = reinterpret_cast<uint8_t *>(s.buffer());
char filename [50];
sprintf (filename, "frame-%ld.png", i + 1);
std::cout << "Working on " << filename << std::endl;
unsigned width = s.width(), height = s.height();
std::vector<unsigned char> image;
image.resize(width * height * 4);
for(unsigned y = 0; y < height; y++)
for(unsigned x = 0; x < width; x++) {
uint32_t i = 4 * width * y + 4 * x;
unsigned char r = buffer[i+2];
unsigned char g = buffer[i+1];
unsigned char b = buffer[i];
unsigned char a = buffer[i+3];
image[4 * width * y + 4 * x + 0] = r;
image[4 * width * y + 4 * x + 1] = g;
image[4 * width * y + 4 * x + 2] = b;
image[4 * width * y + 4 * x + 3] = a;
}
encodePNG(filename, image, width, height);
}
void intro() {
std::cout<<"Welcome to LFE.";
std::cout<<"https://gitdab.com/distok/lfe | Licensed MIT";
}
int help() {
std::cout<<"Usage: \n lfe [lottieFileName] [Resolution]\n\nExamples: \n $ lfe input.json\n $ lfe input.json 200x200\n";
return 1;
}
int main(int argc, char **argv)
{
intro();
char *path{nullptr};
size_t w = 500;
size_t h = 500;
if (argc > 1) path = argv[1];
if (argc > 2) {
char tmp[20];
char *x = strstr(argv[2], "x");
if (x) {
snprintf(tmp, x - argv[2] + 1, "%s", argv[2]);
w = atoi(tmp);
snprintf(tmp, sizeof(tmp), "%s", x + 1);
h = atoi(tmp);
}
}
if (!path) return help();
auto player = rlottie::Animation::loadFromFile(path);
if (!player) return help();
auto buffer = std::unique_ptr<uint32_t[]>(new uint32_t[w * h]);
size_t frameCount = player->totalFrame();
for (size_t i = 0; i < frameCount ; i++) {
rlottie::Surface surface(buffer.get(), w, h, w * 4);
player->renderSync(i, surface);
renderFrame(i, surface);
}
return 0;
}

6464
lodepng.cpp Normal file

File diff suppressed because it is too large Load diff

1977
lodepng.h Normal file

File diff suppressed because it is too large Load diff