auto buffer = std::unique_ptr<uint32_t[]>(new uint32_t[w * h]);
size_t frameCount = player->totalFrame();
- GifBuilder builder(baseName.data(), w, h, bgColor);
+ GifBuilder builder(gifName.data(), w, h, bgColor);
for (size_t i = 0; i < frameCount ; i++) {
rlottie::Surface surface(buffer.get(), w, h, w * 4);
player->renderSync(i, surface);
if (!fileName || !jsonFile(fileName) ) return help();
- baseName = absoloutePath;
-#ifdef _WIN32
- char *base = strrchr(baseName.data(), '\\');
- if (base)
- {
- base++;
- base = strrchr(baseName.data(), '\\');
- if (base) base++;
- else return 1;
- }
-#else
- char *base = basename(baseName.data());
-#endif
- snprintf(baseName.data(), baseName.size(), "%s.gif",base);
+ gifName = basename(fileName);
+ gifName.append(".gif");
return 0;
}
private:
+ std::string basename(const std::string &str)
+ {
+ if (str.empty()) return {};
+
+ auto ptr = str.c_str();
+ auto pos = str.size();
+ while (--pos) {
+ if ( ptr[pos] == '/' || ptr[pos] == '\\') {
+ return str.substr(pos+1);
+ }
+ }
+ return str;
+ }
bool jsonFile(const char *filename) {
const char *dot = strrchr(filename, '.');
}
int result() {
- std::cout<<"Generated GIF file : "<<baseName.data()<<std::endl;
+ std::cout<<"Generated GIF file : "<<gifName<<std::endl;
return 0;
}
char *fileName{nullptr};
int bgColor = 0xffffffff;
std::array<char, 5000> absoloutePath;
- std::array<char, 5000> baseName;
+ std::string gifName;
};
int