16
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-07-17 23:39:18 +02:00

cleanup: remove VSDev camera implementation, remove symbols from CI because they are unreasonably big, mac CI tmp upload

This commit is contained in:
milek7
2021-01-24 23:38:13 +01:00
parent 610ae75b17
commit 158c42b5f0
11 changed files with 15 additions and 284 deletions

View File

@@ -1,135 +0,0 @@
#include "stdafx.h"
#include "widgets/cameraview_vsdev.h"
#include "stb/stb_image.h"
#include "Globals.h"
#include "Logs.h"
ui::cameraview_panel::cameraview_panel()
: ui_panel(STR_C("Camera preview"), false)
{
size_min = { -2, -2 };
}
void cameraview_window_callback(ImGuiSizeCallbackData *data) {
data->DesiredSize.y = data->DesiredSize.x * 9.0f / 16.0f;
}
ui::cameraview_panel::~cameraview_panel() {
if (!exit_thread) {
exit_thread = true;
{
std::lock_guard<std::mutex> lock(mutex);
stbi_image_free(image_ptr);
image_ptr = nullptr;
}
cv.notify_all();
}
if (workthread.joinable())
workthread.join();
}
void ui::cameraview_panel::render()
{
if (!is_open && !exit_thread) {
exit_thread = true;
{
std::lock_guard<std::mutex> lock(mutex);
stbi_image_free(image_ptr);
image_ptr = nullptr;
}
cv.notify_all();
}
if (is_open)
ImGui::SetNextWindowSizeConstraints(ImVec2(200, 200), ImVec2(2500, 2500), cameraview_window_callback);
ui_panel::render();
}
bool ui::cameraview_panel::set_state(state_e e)
{
if (state != e) {
state = e;
is_open = (state != IDLE);
return true;
}
return false;
}
void ui::cameraview_panel::render_contents()
{
if (exit_thread) {
if (workthread.joinable())
workthread.join();
exit_thread = false;
workthread = std::thread(&cameraview_panel::workthread_func, this);
}
if (!texture) {
texture.emplace();
texture->make_stub();
}
texture->bind(0);
{
std::lock_guard<std::mutex> lock(mutex);
if (image_ptr) {
glActiveTexture(GL_TEXTURE0);
glTexImage2D(
GL_TEXTURE_2D, 0,
GL_SRGB8_ALPHA8,
image_w, image_h, 0,
GL_RGBA, GL_UNSIGNED_BYTE, image_ptr);
stbi_image_free(image_ptr);
if (Global.python_mipmaps) {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glGenerateMipmap(GL_TEXTURE_2D);
}
else {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
}
image_ptr = nullptr;
}
}
cv.notify_all();
ImVec2 surface_size = ImGui::GetContentRegionAvail();
ImGui::Image(reinterpret_cast<void*>(texture->id), surface_size);
}
void ui::cameraview_panel::workthread_func()
{
if (!device)
device = std::make_unique<VSDev>();
while (!exit_thread) {
uint8_t *buffer = nullptr;
size_t len = device->GetFrameFromStream((char**)&buffer);
if (buffer) {
int w, h;
stbi_set_flip_vertically_on_load(0);
uint8_t *image = stbi_load_from_memory(buffer, len, &w, &h, nullptr, 4);
if (!image)
ErrorLog(std::string(stbi_failure_reason()));
device->FreeFrameBuffer((char*)buffer);
std::unique_lock<std::mutex> lock(mutex);
if (image_ptr)
cv.wait(lock, [this]{return !image_ptr;});
image_w = w;
image_h = h;
image_ptr = image;
}
else
std::this_thread::sleep_for(std::chrono::milliseconds(5));
}
}

View File

@@ -1,41 +0,0 @@
#include "stdafx.h"
#include "uilayer.h"
#include "translation.h"
#include "extras/VS_Dev.h"
namespace ui
{
class cameraview_panel : public ui_panel
{
public:
enum state_e {
IDLE,
PREVIEW,
RECORDING
};
private:
std::atomic_bool exit_thread = true;
std::thread workthread;
uint8_t* image_ptr = nullptr;
int image_w, image_h;
std::mutex mutex;
std::condition_variable cv;
std::optional<opengl_texture> texture;
std::unique_ptr<VSDev> device;
void workthread_func();
public:
cameraview_panel();
~cameraview_panel();
void render() override;
void render_contents() override;
bool set_state(state_e e);
};
} // namespace ui