Skip to content

Commit 6020d94

Browse files
committed
misc: move from static_cast<type>() to type()
maybe bad idea, or idk
1 parent 777713e commit 6020d94

6 files changed

Lines changed: 106 additions & 104 deletions

File tree

src/main.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ static std::string wide_to_utf8(const wchar_t* w)
258258
if (needed <= 0)
259259
return {};
260260
std::string out;
261-
out.resize(static_cast<size_t>(needed) - 1);
261+
out.resize(size_t(needed) - 1);
262262
WideCharToMultiByte(CP_UTF8, 0, w, -1, out.data(), needed, nullptr, nullptr);
263263
return out;
264264
}
@@ -331,7 +331,7 @@ int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
331331
setvbuf(stderr, nullptr, _IOLBF, 0);
332332
}
333333

334-
auto file = std::make_shared<spdlog::sinks::basic_file_sink_mt>("oshot.log", true);
334+
auto file = std::make_shared<spdlog::sinks::basic_file_sink_mt("oshot.log", true);
335335
#else
336336
int main(int argc, char* argv[])
337337
{
@@ -445,7 +445,7 @@ int main(int argc, char* argv[])
445445
const fs::path& png_path = fs::temp_directory_path(ec) / "oshot.png";
446446
std::ofstream out(png_path.string(), std::ios::binary | std::ios::out | std::ios::trunc);
447447

448-
out.write(reinterpret_cast<const char*>(oshot_png), static_cast<std::streamsize>(oshot_png_len));
448+
out.write(reinterpret_cast<const char*>(oshot_png), std::streamsize(oshot_png_len));
449449
out.close();
450450
TrayIcon tray = { png_path.string(), "oshot.ico", "oshot", menu };
451451
#endif

src/main_tool_opengl3.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ static GLFWmonitor* get_monitor_at_cursor()
4444
POINT pt{};
4545
if (GetCursorPos(&pt))
4646
{
47-
cursor_x = static_cast<int>(pt.x);
48-
cursor_y = static_cast<int>(pt.y);
47+
cursor_x = int(pt.x);
48+
cursor_y = int(pt.y);
4949
cursor_ok = true;
5050
}
5151
# elif defined(__linux__)

src/screen_capture.cpp

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ Result<capture_result_t> capture_full_screen_spectacle()
234234

235235
result.w = w;
236236
result.h = h;
237-
result.data.assign(rgba, rgba + static_cast<size_t>(w) * h * 4);
237+
result.data.assign(rgba, rgba + size_t(w) * h * 4);
238238
stbi_image_free(rgba);
239239

240240
return Ok(std::move(result));
@@ -267,7 +267,7 @@ Result<capture_result_t> capture_full_screen_wayland()
267267
return Err("Screenshot too large to decode (buffer > INT_MAX).");
268268

269269
int w = 0, h = 0, comp = 0;
270-
uint8_t* rgba = stbi_load_from_memory(buf.data(), static_cast<int>(buf.size()), &w, &h, &comp, STBI_rgb_alpha);
270+
uint8_t* rgba = stbi_load_from_memory(buf.data(), int(buf.size()), &w, &h, &comp, STBI_rgb_alpha);
271271

272272
if (!rgba)
273273
{
@@ -277,7 +277,7 @@ Result<capture_result_t> capture_full_screen_wayland()
277277

278278
result.w = w;
279279
result.h = h;
280-
result.data.assign(rgba, rgba + (static_cast<size_t>(w) * static_cast<size_t>(h) * 4));
280+
result.data.assign(rgba, rgba + (size_t(w) * size_t(h) * 4));
281281
stbi_image_free(rgba);
282282

283283
return Ok(std::move(result));
@@ -470,7 +470,7 @@ Result<capture_result_t> capture_full_screen_portal()
470470

471471
st.cap.w = w;
472472
st.cap.h = h;
473-
st.cap.data.assign(rgba, rgba + (static_cast<size_t>(w) * h * 4));
473+
st.cap.data.assign(rgba, rgba + (size_t(w) * h * 4));
474474
stbi_image_free(rgba);
475475

476476
// The portal backend (on KDE mostly) writes a permanent file to ~/Pictures named "Screenshot_*.png".
@@ -496,12 +496,12 @@ Result<capture_result_t> capture_full_screen_portal()
496496
if (new_w > 0 && new_h > 0)
497497
{
498498
const int src_stride = st.cap.w;
499-
std::vector<uint8_t> cropped(static_cast<size_t>(new_w) * new_h * 4);
499+
std::vector<uint8_t> cropped(size_t(new_w) * new_h * 4);
500500
for (int row = 0; row < new_h; ++row)
501501
{
502-
const uint8_t* src = st.cap.data.data() + (static_cast<size_t>(y0 + row) * src_stride + x0) * 4;
503-
uint8_t* dst = cropped.data() + static_cast<size_t>(row) * new_w * 4;
504-
std::memcpy(dst, src, static_cast<size_t>(new_w) * 4);
502+
const uint8_t* src = st.cap.data.data() + (size_t(y0 + row) * src_stride + x0) * 4;
503+
uint8_t* dst = cropped.data() + size_t(row) * new_w * 4;
504+
std::memcpy(dst, src, size_t(new_w) * 4);
505505
}
506506
st.cap.data = std::move(cropped);
507507
st.cap.w = new_w;
@@ -561,8 +561,8 @@ static int cursor_display_index()
561561
{
562562
if (active[i] == hit)
563563
{
564-
debug("macOS capture: display index {} (CGDirectDisplayID {})", i + 1, static_cast<unsigned>(hit));
565-
return static_cast<int>(i + 1);
564+
debug("macOS capture: display index {} (CGDirectDisplayID {})", i + 1, unsigned(hit));
565+
return int(i + 1);
566566
}
567567
}
568568

@@ -604,7 +604,7 @@ Result<capture_result_t> capture_full_screen_macos()
604604

605605
result.w = w;
606606
result.h = h;
607-
result.data.assign(rgba, rgba + static_cast<size_t>(w) * h * 4);
607+
result.data.assign(rgba, rgba + size_t(w) * h * 4);
608608
stbi_image_free(rgba);
609609

610610
return Ok(std::move(result));
@@ -646,7 +646,7 @@ Result<capture_result_t> capture_full_screen_windows_fallback()
646646

647647
result.w = width;
648648
result.h = height;
649-
result.data.resize(static_cast<size_t>(width) * height * 4);
649+
result.data.resize(size_t(width) * height * 4);
650650

651651
// Get Device Contexts
652652
HDC hScreenDC = GetDC(nullptr); // virtual-desktop DC
@@ -712,7 +712,7 @@ static bool hr_failed(HRESULT hr, const char* what)
712712
{
713713
if (FAILED(hr))
714714
{
715-
debug("{} failed: 0x{:08X}", what, static_cast<unsigned>(hr));
715+
debug("{} failed: 0x{:08X}", what, unsigned(hr));
716716
return true;
717717
}
718718
return false;
@@ -730,7 +730,7 @@ struct com_ptr
730730
}
731731

732732
T** operator&() { return &ptr; }
733-
T* operator->() const { return ptr; }
733+
T* operator-() const { return ptr; }
734734
operator T*() const { return ptr; }
735735
operator bool() const { return ptr != nullptr; }
736736

@@ -906,7 +906,7 @@ Result<capture_result_t> capture_full_screen_windows()
906906
desc.Format != DXGI_FORMAT_R8G8B8A8_UNORM && desc.Format != DXGI_FORMAT_R8G8B8A8_UNORM_SRGB)
907907
{
908908
duplication->ReleaseFrame();
909-
debug("Unsupported DXGI format: {}", static_cast<unsigned>(desc.Format));
909+
debug("Unsupported DXGI format: {}", unsigned(desc.Format));
910910
return capture_full_screen_windows_fallback();
911911
}
912912

@@ -937,20 +937,20 @@ Result<capture_result_t> capture_full_screen_windows()
937937
}
938938

939939
// Copy to RGBA buffer
940-
const uint8_t* src = static_cast<const uint8_t*>(mapped.pData);
940+
const uint8_t* src = const uint8_t*(mapped.pData);
941941
const uint32_t width = desc.Width;
942942
const uint32_t height = desc.Height;
943943

944-
result.w = static_cast<int>(width);
945-
result.h = static_cast<int>(height);
946-
result.data.resize(static_cast<size_t>(width) * height * 4);
944+
result.w = int(width);
945+
result.h = int(height);
946+
result.data.resize(size_t(width) * height * 4);
947947

948948
if (desc.Format == DXGI_FORMAT_B8G8R8A8_UNORM || desc.Format == DXGI_FORMAT_B8G8R8A8_UNORM_SRGB)
949949
{
950950
for (uint32_t y = 0; y < height; ++y)
951951
{
952-
const uint8_t* row = src + static_cast<size_t>(y) * mapped.RowPitch;
953-
uint8_t* out = result.data.data() + static_cast<size_t>(y) * width * 4;
952+
const uint8_t* row = src + size_t(y) * mapped.RowPitch;
953+
uint8_t* out = result.data.data() + size_t(y) * width * 4;
954954

955955
for (uint32_t x = 0; x < width; ++x)
956956
{
@@ -966,9 +966,9 @@ Result<capture_result_t> capture_full_screen_windows()
966966
// R8G8B8A8
967967
for (uint32_t y = 0; y < height; ++y)
968968
{
969-
const uint8_t* row = src + static_cast<size_t>(y) * mapped.RowPitch;
970-
uint8_t* out = result.data.data() + static_cast<size_t>(y) * width * 4;
971-
std::memcpy(out, row, static_cast<size_t>(width) * 4);
969+
const uint8_t* row = src + size_t(y) * mapped.RowPitch;
970+
uint8_t* out = result.data.data() + size_t(y) * width * 4;
971+
std::memcpy(out, row, size_t(width) * 4);
972972
}
973973
}
974974

0 commit comments

Comments
 (0)