52 const std::string& encoded) {
54 static constexpr int kTable[256] = {
55 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
56 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
57 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,62,-1,-1,-1,63,
58 52,53,54,55,56,57,58,59,60,61,-1,-1,-1,-1,-1,-1,
59 -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,
60 15,16,17,18,19,20,21,22,23,24,25,-1,-1,-1,-1,-1,
61 -1,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,
62 41,42,43,44,45,46,47,48,49,50,51,-1,-1,-1,-1,-1,
63 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
64 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
65 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
66 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
67 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
68 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
69 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
70 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
74 std::vector<uint8_t> out;
75 out.reserve((encoded.size() / 4) * 3);
80 for (
unsigned char c : encoded) {
82 if (val < 0)
continue;
83 accum = (accum << 6) | static_cast<uint32_t>(val);
87 out.push_back(
static_cast<uint8_t
>((accum >> bits) & 0xFF));
99 std::vector<uint8_t>& rgba_out,
100 int& width_out,
int& height_out) {
101#if !defined(YAZE_WITH_LIBPNG)
108 if (png_data.size() < 8)
return false;
111 if (png_sig_cmp(
reinterpret_cast<png_bytep
>(
112 const_cast<uint8_t*
>(png_data.data())),
117 png_structp png_ptr =
118 png_create_read_struct(PNG_LIBPNG_VER_STRING,
nullptr,
nullptr,
nullptr);
119 if (!png_ptr)
return false;
121 png_infop info_ptr = png_create_info_struct(png_ptr);
123 png_destroy_read_struct(&png_ptr,
nullptr,
nullptr);
127 if (setjmp(png_jmpbuf(png_ptr))) {
128 png_destroy_read_struct(&png_ptr, &info_ptr,
nullptr);
132 PngMemoryReader reader{png_data.data(), 0, png_data.size()};
133 png_set_read_fn(png_ptr, &reader, PngReadFromMemory);
135 png_read_info(png_ptr, info_ptr);
137 png_uint_32 w = png_get_image_width(png_ptr, info_ptr);
138 png_uint_32 h = png_get_image_height(png_ptr, info_ptr);
139 png_byte color_type = png_get_color_type(png_ptr, info_ptr);
140 png_byte bit_depth = png_get_bit_depth(png_ptr, info_ptr);
143 if (bit_depth == 16) png_set_strip_16(png_ptr);
144 if (color_type == PNG_COLOR_TYPE_PALETTE) png_set_palette_to_rgb(png_ptr);
145 if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8)
146 png_set_expand_gray_1_2_4_to_8(png_ptr);
147 if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS))
148 png_set_tRNS_to_alpha(png_ptr);
149 if (color_type == PNG_COLOR_TYPE_RGB || color_type == PNG_COLOR_TYPE_GRAY ||
150 color_type == PNG_COLOR_TYPE_PALETTE)
151 png_set_filler(png_ptr, 0xFF, PNG_FILLER_AFTER);
152 if (color_type == PNG_COLOR_TYPE_GRAY ||
153 color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
154 png_set_gray_to_rgb(png_ptr);
156 png_read_update_info(png_ptr, info_ptr);
158 width_out =
static_cast<int>(w);
159 height_out =
static_cast<int>(h);
160 rgba_out.resize(w * h * 4);
162 std::vector<png_bytep> row_pointers(h);
163 for (png_uint_32 y = 0; y < h; ++y) {
164 row_pointers[y] = rgba_out.data() + y * w * 4;
167 png_read_image(png_ptr, row_pointers.data());
168 png_destroy_read_struct(&png_ptr, &info_ptr,
nullptr);
512 ImVec2 avail = ImGui::GetContentRegionAvail();
516 float placeholder_h = std::max(avail.y - 40.0f, 100.0f);
517 ImVec2 center(avail.x * 0.5f, placeholder_h * 0.5f);
518 ImGui::BeginChild(
"##ss_placeholder", ImVec2(0, placeholder_h),
true);
519 ImGui::SetCursorPos(ImVec2(center.x - 80, center.y - 10));
520 ImGui::TextDisabled(
"No screenshot captured");
528 float max_h = std::max(avail.y - 60.0f, 100.0f);
529 float display_w = avail.x;
530 float display_h = display_w / src_aspect;
532 if (display_h > max_h) {
534 display_w = display_h * src_aspect;
538 float offset_x = (avail.x - display_w) * 0.5f;
540 ImGui::SetCursorPosX(ImGui::GetCursorPosX() + offset_x);
543 ImGui::Image(
reinterpret_cast<ImTextureID
>(
texture_),
544 ImVec2(display_w, display_h), ImVec2(0, 0), ImVec2(1, 1));
548 ImVec2 img_min = ImGui::GetItemRectMin();
549 ImGui::GetWindowDrawList()->AddRectFilled(
550 img_min, ImVec2(img_min.x + 50, img_min.y + 20),
551 IM_COL32(200, 60, 60, 200));
552 ImGui::GetWindowDrawList()->AddText(ImVec2(img_min.x + 4, img_min.y + 2),
553 IM_COL32(255, 255, 255, 255),
"Stale");
558 ImGui::TextColored(theme.text_secondary_color,
559 "Frame #%llu | %dx%d | Latency: %.1f ms",