Compare commits

..

3 Commits

Author SHA1 Message Date
Green Sky
02600a3bc6
fix taking as copy instead of ref
Some checks are pending
ContinuousDelivery / linux-ubuntu (push) Waiting to run
ContinuousDelivery / android (map[ndk_abi:arm64-v8a vcpkg_toolkit:arm64-android]) (push) Waiting to run
ContinuousDelivery / android (map[ndk_abi:armeabi-v7a vcpkg_toolkit:arm-neon-android]) (push) Waiting to run
ContinuousDelivery / android (map[ndk_abi:x86_64 vcpkg_toolkit:x64-android]) (push) Waiting to run
ContinuousDelivery / windows (push) Waiting to run
ContinuousDelivery / windows-asan (push) Waiting to run
ContinuousDelivery / release (push) Blocked by required conditions
ContinuousIntegration / linux (push) Waiting to run
ContinuousIntegration / android (map[ndk_abi:arm64-v8a vcpkg_toolkit:arm64-android]) (push) Waiting to run
ContinuousIntegration / android (map[ndk_abi:armeabi-v7a vcpkg_toolkit:arm-neon-android]) (push) Waiting to run
ContinuousIntegration / android (map[ndk_abi:x86_64 vcpkg_toolkit:x64-android]) (push) Waiting to run
ContinuousIntegration / macos (push) Waiting to run
ContinuousIntegration / windows (push) Waiting to run
major cause for temporary allocations
2024-11-30 16:01:29 +01:00
Green Sky
1faa7e5510
light cg reformatting 2024-11-29 19:25:45 +01:00
Green Sky
a0cc3c3fe7
fix webp encoder memory leak 2024-11-29 18:34:44 +01:00
2 changed files with 38 additions and 45 deletions

View File

@ -668,7 +668,7 @@ float ChatGui4::render(float time_delta) {
// TODO: dedup? // TODO: dedup?
ImGui::TextDisabled("_"); ImGui::TextDisabled("_");
} else { } else {
const auto list = msg_reg.get<Message::Components::ReceivedBy>(e).ts; const auto& list = msg_reg.get<Message::Components::ReceivedBy>(e).ts;
// wrongly assumes contacts never get removed from a group // wrongly assumes contacts never get removed from a group
if (sub_contacts != nullptr && list.size() < sub_contacts->size()) { if (sub_contacts != nullptr && list.size() < sub_contacts->size()) {
// if partically delivered // if partically delivered
@ -915,7 +915,6 @@ float ChatGui4::render(float time_delta) {
); );
} }
{
// TODO: add support for more than images // TODO: add support for more than images
// !!! polling each frame can be VERY expensive !!! // !!! polling each frame can be VERY expensive !!!
//const auto* mime_type = clipboardHasImage(); //const auto* mime_type = clipboardHasImage();
@ -926,7 +925,6 @@ float ChatGui4::render(float time_delta) {
} else if (const auto* fpmt = clipboardHasFileList(); fpmt != nullptr) { } else if (const auto* fpmt = clipboardHasFileList(); fpmt != nullptr) {
pasteFile(fpmt); pasteFile(fpmt);
} }
//} else if (ImGui::IsItemClicked(ImGuiMouseButton_Right)) {
} else if (ImGui::BeginPopupContextItem(nullptr, ImGuiMouseButton_Right)) { } else if (ImGui::BeginPopupContextItem(nullptr, ImGuiMouseButton_Right)) {
// TODO: use list instead // TODO: use list instead
const static std::vector<const char*> image_mime_types { const static std::vector<const char*> image_mime_types {
@ -948,7 +946,6 @@ float ChatGui4::render(float time_delta) {
} }
//ImGui::EndDisabled(); //ImGui::EndDisabled();
} }
}
ImGui::EndChild(); ImGui::EndChild();
#if 0 #if 0

View File

@ -104,8 +104,11 @@ std::vector<uint8_t> ImageEncoderWebP::encodeToMemoryRGBA(const ImageResult& inp
// Tune 'enc_options' as needed. // Tune 'enc_options' as needed.
enc_options.minimize_size = 1; // might be slow? optimize for size, no key-frame insertion enc_options.minimize_size = 1; // might be slow? optimize for size, no key-frame insertion
WebPAnimEncoder* enc = WebPAnimEncoderNew(input_image.width, input_image.height, &enc_options); std::unique_ptr<WebPAnimEncoder, decltype(&WebPAnimEncoderDelete)> enc {
if (enc == nullptr) { WebPAnimEncoderNew(input_image.width, input_image.height, &enc_options),
&WebPAnimEncoderDelete
};
if (!enc) {
std::cerr << "IEWebP error: WebPAnimEncoderNew()\n"; std::cerr << "IEWebP error: WebPAnimEncoderNew()\n";
return {}; return {};
} }
@ -113,10 +116,8 @@ std::vector<uint8_t> ImageEncoderWebP::encodeToMemoryRGBA(const ImageResult& inp
int prev_timestamp = 0; int prev_timestamp = 0;
for (const auto& frame : input_image.frames) { for (const auto& frame : input_image.frames) {
WebPConfig config; WebPConfig config;
//WebPConfigInit(&config);
if (!WebPConfigPreset(&config, WebPPreset::WEBP_PRESET_DEFAULT, quality)) { if (!WebPConfigPreset(&config, WebPPreset::WEBP_PRESET_DEFAULT, quality)) {
std::cerr << "IEWebP error: WebPConfigPreset()\n"; std::cerr << "IEWebP error: WebPConfigPreset()\n";
WebPAnimEncoderDelete(enc);
return {}; return {};
} }
//WebPConfigLosslessPreset(&config, 6); // 9 for max compression //WebPConfigLosslessPreset(&config, 6); // 9 for max compression
@ -124,39 +125,34 @@ std::vector<uint8_t> ImageEncoderWebP::encodeToMemoryRGBA(const ImageResult& inp
WebPPicture frame_webp; WebPPicture frame_webp;
if (!WebPPictureInit(&frame_webp)) { if (!WebPPictureInit(&frame_webp)) {
std::cerr << "IEWebP error: WebPPictureInit()\n"; std::cerr << "IEWebP error: WebPPictureInit()\n";
WebPAnimEncoderDelete(enc);
return {}; return {};
} }
frame_webp.width = input_image.width; frame_webp.width = input_image.width;
frame_webp.height = input_image.height; frame_webp.height = input_image.height;
if (!WebPPictureImportRGBA(&frame_webp, frame.data.data(), 4*input_image.width)) { if (!WebPPictureImportRGBA(&frame_webp, frame.data.data(), 4*input_image.width)) {
std::cerr << "IEWebP error: WebPPictureImportRGBA()\n"; std::cerr << "IEWebP error: WebPPictureImportRGBA()\n";
WebPAnimEncoderDelete(enc);
return {}; return {};
} }
if (!WebPAnimEncoderAdd(enc, &frame_webp, prev_timestamp, &config)) { if (!WebPAnimEncoderAdd(enc.get(), &frame_webp, prev_timestamp, &config)) {
std::cerr << "IEWebP error: WebPAnimEncoderAdd()\n"; std::cerr << "IEWebP error: WebPAnimEncoderAdd()\n";
WebPPictureFree(&frame_webp); WebPPictureFree(&frame_webp);
WebPAnimEncoderDelete(enc);
return {}; return {};
} }
prev_timestamp += frame.ms; prev_timestamp += frame.ms;
WebPPictureFree(&frame_webp);
} }
if (!WebPAnimEncoderAdd(enc, NULL, prev_timestamp, NULL)) { // tell anim encoder its the end if (!WebPAnimEncoderAdd(enc.get(), NULL, prev_timestamp, NULL)) { // tell anim encoder its the end
std::cerr << "IEWebP error: WebPAnimEncoderAdd(NULL)\n"; std::cerr << "IEWebP error: WebPAnimEncoderAdd(NULL)\n";
WebPAnimEncoderDelete(enc);
return {}; return {};
} }
WebPData webp_data; WebPData webp_data;
WebPDataInit(&webp_data); WebPDataInit(&webp_data);
if (!WebPAnimEncoderAssemble(enc, &webp_data)) { if (!WebPAnimEncoderAssemble(enc.get(), &webp_data)) {
std::cerr << "IEWebP error: WebPAnimEncoderAdd(NULL)\n"; std::cerr << "IEWebP error: WebPAnimEncoderAdd(NULL)\n";
WebPAnimEncoderDelete(enc);
return {}; return {};
} }
WebPAnimEncoderDelete(enc);
// Write the 'webp_data' to a file, or re-mux it further. // Write the 'webp_data' to a file, or re-mux it further.
// TODO: make it not a copy // TODO: make it not a copy