qoi_pipe style animation encoding

This commit is contained in:
Green Sky 2025-05-07 15:43:34 +02:00
parent 12893ac743
commit 3b5874739b
No known key found for this signature in database
GPG Key ID: DBE05085D874AB4A

View File

@ -137,11 +137,6 @@ std::vector<uint8_t> ImageEncoderQOI::encodeToMemoryRGBA(const ImageResult& inpu
return {}; return {};
} }
if (input_image.frames.size() > 1) {
std::cerr << "IEQOI warning: image with animation, only first frame will be encoded!\n";
return {};
}
// TODO: look into RDO (eg https://github.com/richgel999/rdopng) // TODO: look into RDO (eg https://github.com/richgel999/rdopng)
//int png_compression_level = 8; //int png_compression_level = 8;
//if (extra_options.count("png_compression_level")) { //if (extra_options.count("png_compression_level")) {
@ -154,22 +149,30 @@ std::vector<uint8_t> ImageEncoderQOI::encodeToMemoryRGBA(const ImageResult& inpu
desc.channels = 4; desc.channels = 4;
desc.colorspace = QOI_SRGB; // TODO: decide desc.colorspace = QOI_SRGB; // TODO: decide
int out_len {0}; std::vector<uint8_t> new_data;
uint8_t* enc_data = static_cast<uint8_t*>(qoi_encode( for (const auto& frame : input_image.frames) {
input_image.frames.front().data.data(), int out_len {0};
&desc, uint8_t* enc_data = static_cast<uint8_t*>(qoi_encode(
&out_len frame.data.data(),
)); &desc,
&out_len
));
if (enc_data == nullptr) { if (enc_data == nullptr) {
std::cerr << "IEQOI error: qoi_encode failed!\n"; std::cerr << "IEQOI error: qoi_encode failed!\n";
return {}; break;
}
// qoi_pipe like animation support. simple concatination of images
if (new_data.empty()) {
new_data = std::vector<uint8_t>(enc_data, enc_data+out_len);
} else {
new_data.insert(new_data.cend(), enc_data, enc_data+out_len);
}
free(enc_data); // TODO: a streaming encoder would be better
} }
std::vector<uint8_t> new_data(enc_data, enc_data+out_len);
free(enc_data); // TODO: a streaming encoder would be better
return new_data; return new_data;
} }