color anim + fix crop w/h sanitization + hack to determine if png

This commit is contained in:
Green Sky 2023-10-05 18:26:35 +02:00
parent 8633c5eafd
commit b479db4989
No known key found for this signature in database
2 changed files with 55 additions and 10 deletions

View File

@ -47,7 +47,7 @@ bool SendImagePopup::load(void) {
continue; continue;
} }
#if 0 #if 1
crop_rect.x = 0; crop_rect.x = 0;
crop_rect.y = 0; crop_rect.y = 0;
crop_rect.w = original_image.width; crop_rect.w = original_image.width;
@ -66,7 +66,18 @@ bool SendImagePopup::load(void) {
if (original_image.file_ext != nullptr) { if (original_image.file_ext != nullptr) {
original_file_ext += original_image.file_ext; original_file_ext += original_image.file_ext;
} else { } else {
original_file_ext += "unk"; // HACK: manually probe for png
if (!original_raw
&& original_data.size() >= 4
&& original_data.at(0) == 0x89
&& original_data.at(1) == 'P'
&& original_data.at(2) == 'N'
&& original_data.at(3) == 'G'
) {
original_file_ext += "png";
} else {
original_file_ext += "unk"; // very meh, default to png?
}
} }
preview_image.timestamp_last_rendered = getNowMS(); preview_image.timestamp_last_rendered = getNowMS();
@ -210,15 +221,15 @@ SendImagePopup::Rect SendImagePopup::sanitizeCrop(Rect crop_rect, int32_t image_
crop_rect.y = 0; crop_rect.y = 0;
} }
if (crop_rect.w > crop_rect.x + image_width) { if (crop_rect.w > image_width - crop_rect.x) {
crop_rect.w = crop_rect.x + image_width; crop_rect.w = image_width - crop_rect.x;
} else if (crop_rect.w < 1) { } else if (crop_rect.w < 1) {
crop_rect.w = 1; crop_rect.w = 1;
// TODO: adjust X // TODO: adjust X
} }
if (crop_rect.h > crop_rect.y + image_height) { if (crop_rect.h > image_height - crop_rect.y) {
crop_rect.h = crop_rect.y + image_height; crop_rect.h = image_height - crop_rect.y;
} else if (crop_rect.h < 1) { } else if (crop_rect.h < 1) {
crop_rect.h = 1; crop_rect.h = 1;
// TODO: adjust Y // TODO: adjust Y
@ -267,6 +278,9 @@ void SendImagePopup::render(void) {
preview_image.doAnimation(getNowMS()); preview_image.doAnimation(getNowMS());
time += 1.f/60.f; // TODO: actual delay
time = fmod(time, 1.f); // fract()
//ImGui::Text("send file....\n......"); //ImGui::Text("send file....\n......");
{ {
@ -371,11 +385,40 @@ void SendImagePopup::render(void) {
crop_rect = sanitizeCrop(crop_rect, original_image.width, original_image.height); crop_rect = sanitizeCrop(crop_rect, original_image.width, original_image.height);
{ // 4 lines delimiting the crop result { // 4 lines delimiting the crop result
ImU32 line_color = 0xffffffff;
{ // calc color
auto rgb = [](float x) -> ImVec4 {
auto f = [](float x) {
while (x < 0.f) {
x += 1.f;
}
x = std::fmod(x, 1.f); // fract()
if (x < 1.f/3) {
return x * 3;
} else if (x < 2.f/3) {
return (1 - (x - (1.f/3))) * 3 - 2;
} else {
return 0.f;
}
};
float red = f(x);
float green = f(x - (1.f/3));
float blue = f(x - (2.f/3));
return {red, green, blue, 1.f};
};
line_color = ImGui::GetColorU32(rgb(time));
}
// x vertical // x vertical
ImGui::GetWindowDrawList()->AddLine( ImGui::GetWindowDrawList()->AddLine(
{pre_img_curser_screen.x + ul_clipper_pos.x * width, pre_img_curser_screen.y}, {pre_img_curser_screen.x + ul_clipper_pos.x * width, pre_img_curser_screen.y},
{pre_img_curser_screen.x + ul_clipper_pos.x * width, pre_img_curser_screen.y + height}, {pre_img_curser_screen.x + ul_clipper_pos.x * width, pre_img_curser_screen.y + height},
0xffffffff, line_color,
1.f 1.f
); );
@ -383,7 +426,7 @@ void SendImagePopup::render(void) {
ImGui::GetWindowDrawList()->AddLine( ImGui::GetWindowDrawList()->AddLine(
{pre_img_curser_screen.x, pre_img_curser_screen.y + ul_clipper_pos.y * height}, {pre_img_curser_screen.x, pre_img_curser_screen.y + ul_clipper_pos.y * height},
{pre_img_curser_screen.x + width, pre_img_curser_screen.y + ul_clipper_pos.y * height}, {pre_img_curser_screen.x + width, pre_img_curser_screen.y + ul_clipper_pos.y * height},
0xffffffff, line_color,
1.f 1.f
); );
@ -391,7 +434,7 @@ void SendImagePopup::render(void) {
ImGui::GetWindowDrawList()->AddLine( ImGui::GetWindowDrawList()->AddLine(
{pre_img_curser_screen.x + lr_clipper_pos.x * width, pre_img_curser_screen.y}, {pre_img_curser_screen.x + lr_clipper_pos.x * width, pre_img_curser_screen.y},
{pre_img_curser_screen.x + lr_clipper_pos.x * width, pre_img_curser_screen.y + height}, {pre_img_curser_screen.x + lr_clipper_pos.x * width, pre_img_curser_screen.y + height},
0xffffffff, line_color,
1.f 1.f
); );
@ -399,7 +442,7 @@ void SendImagePopup::render(void) {
ImGui::GetWindowDrawList()->AddLine( ImGui::GetWindowDrawList()->AddLine(
{pre_img_curser_screen.x, pre_img_curser_screen.y + lr_clipper_pos.y * height}, {pre_img_curser_screen.x, pre_img_curser_screen.y + lr_clipper_pos.y * height},
{pre_img_curser_screen.x + width, pre_img_curser_screen.y + lr_clipper_pos.y * height}, {pre_img_curser_screen.x + width, pre_img_curser_screen.y + lr_clipper_pos.y * height},
0xffffffff, line_color,
1.f 1.f
); );
} }

View File

@ -41,6 +41,8 @@ struct SendImagePopup {
bool compress {false}; bool compress {false};
uint32_t quality {80u}; uint32_t quality {80u};
float time {0.f}; // cycling form 0 to 1 over time
bool _open_popup {false}; bool _open_popup {false};
std::function<void(const std::vector<uint8_t>&, std::string_view)> _on_send = [](const auto&, auto){}; std::function<void(const std::vector<uint8_t>&, std::string_view)> _on_send = [](const auto&, auto){};