mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-08-02 00:17:02 +00:00
example:refactor to remove naked malloc and RAII warning
This commit is contained in:
parent
23115b9092
commit
89a72b6e9c
@ -4,15 +4,19 @@
|
||||
#include<iostream>
|
||||
#include<vector>
|
||||
#include<array>
|
||||
#include<cstdlib>
|
||||
#include<libgen.h>
|
||||
|
||||
class GifBuilder {
|
||||
public:
|
||||
GifBuilder(const std::string &fileName , const uint32_t width,
|
||||
const uint32_t height, const uint32_t delay = 2)
|
||||
explicit GifBuilder(const std::string &fileName , const uint32_t width,
|
||||
const uint32_t height, const uint32_t delay = 2)
|
||||
{
|
||||
GifBegin(&handle, fileName.c_str(), width, height, delay);
|
||||
}
|
||||
~GifBuilder()
|
||||
{
|
||||
GifEnd(&handle);
|
||||
}
|
||||
void addFrame(rlottie::Surface &s, uint32_t delay = 2)
|
||||
{
|
||||
argbTorgba(s);
|
||||
@ -56,10 +60,7 @@ public:
|
||||
}
|
||||
}
|
||||
}
|
||||
void commit()
|
||||
{
|
||||
GifEnd(&handle);
|
||||
}
|
||||
|
||||
private:
|
||||
GifWriter handle;
|
||||
};
|
||||
@ -71,18 +72,15 @@ public:
|
||||
auto player = rlottie::Animation::loadFromFile(fileName);
|
||||
if (!player) return help();
|
||||
|
||||
uint32_t* buffer = (uint32_t *) malloc(w * h * 4);
|
||||
auto buffer = std::make_unique<uint32_t[]>(w * h);
|
||||
size_t frameCount = player->totalFrame();
|
||||
|
||||
GifBuilder builder(baseName.data(), w, h);
|
||||
for (size_t i = 0; i < frameCount ; i++) {
|
||||
rlottie::Surface surface(buffer, w, h, w * 4);
|
||||
rlottie::Surface surface(buffer.get(), w, h, w * 4);
|
||||
player->renderSync(i, surface);
|
||||
builder.addFrame(surface);
|
||||
}
|
||||
builder.commit();
|
||||
|
||||
free(buffer);
|
||||
return result();
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user