add image buffer to reciver py image
This commit is contained in:
parent
25c023e479
commit
61b9c17426
BIN
Thirdparty/libipc/lib/ipc.lib
vendored
BIN
Thirdparty/libipc/lib/ipc.lib
vendored
Binary file not shown.
BIN
Thirdparty/libipc/lib/ipc_o.lib
vendored
BIN
Thirdparty/libipc/lib/ipc_o.lib
vendored
Binary file not shown.
BIN
Thirdparty/libipc/lib/ipcd.lib
vendored
BIN
Thirdparty/libipc/lib/ipcd.lib
vendored
Binary file not shown.
BIN
Thirdparty/libipc/lib/ipcd.pdb
vendored
BIN
Thirdparty/libipc/lib/ipcd.pdb
vendored
Binary file not shown.
@ -6,8 +6,8 @@
|
|||||||
#include "Constant.h"
|
#include "Constant.h"
|
||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
|
|
||||||
#include "CriticalSection.h"
|
#include "Thread/CriticalSection.h"
|
||||||
#include "ScopeLock.h"
|
#include "Thread/ScopeLock.h"
|
||||||
|
|
||||||
#include "Mesh.h"
|
#include "Mesh.h"
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#include "Core/CriticalSection.h"
|
#include "Core/Thread/CriticalSection.h"
|
||||||
|
|
||||||
|
|
||||||
CriticalSection::CriticalSection() noexcept {
|
CriticalSection::CriticalSection() noexcept {
|
24
src/ImageBuffer.cpp
Normal file
24
src/ImageBuffer.cpp
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
#include "ImageBuffer.h"
|
||||||
|
|
||||||
|
#include "Core/Thread/ScopeLock.h"
|
||||||
|
|
||||||
|
void ImageBuffer::PushImage(ImageBuffer::IBType type, std::vector<unsigned char> data,
|
||||||
|
uint32 width, uint32 height, uint32 comp) {
|
||||||
|
switch (type) {
|
||||||
|
case ImageBuffer::IBType::Background:
|
||||||
|
PushBackgroundImage(std::move(data), width, height, comp);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ImageBuffer::PushBackgroundImage(std::vector<uint8> data, uint32 width, uint32 height, uint32 comp) {
|
||||||
|
ScopeLock<CriticalSection> lock(&cs_);
|
||||||
|
if (background_.size() >= 10) {
|
||||||
|
background_.pop();
|
||||||
|
}
|
||||||
|
|
||||||
|
Image newImage{ std::move(data), width, height, comp };
|
||||||
|
background_.push(std::move(newImage));
|
||||||
|
}
|
38
src/ImageBuffer.h
Normal file
38
src/ImageBuffer.h
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <queue>
|
||||||
|
|
||||||
|
#include "Core/Core.h"
|
||||||
|
#include "Core/Singleton.h"
|
||||||
|
|
||||||
|
class ImageBuffer : public Singleton<ImageBuffer> {
|
||||||
|
public:
|
||||||
|
enum class IBType {
|
||||||
|
Background,
|
||||||
|
|
||||||
|
};
|
||||||
|
public:
|
||||||
|
explicit ImageBuffer() noexcept = default;
|
||||||
|
~ImageBuffer() = default;
|
||||||
|
|
||||||
|
ImageBuffer(const ImageBuffer&) = delete;
|
||||||
|
ImageBuffer& operator=(const ImageBuffer&) = delete;
|
||||||
|
|
||||||
|
void PushImage(IBType type, std::vector<uint8> data, uint32 width, uint32 height, uint32 comp);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void PushBackgroundImage(std::vector<uint8> data, uint32 width, uint32 height, uint32 comp);
|
||||||
|
|
||||||
|
private:
|
||||||
|
struct Image {
|
||||||
|
std::vector<uint8> data;
|
||||||
|
uint32 width;
|
||||||
|
uint32 height;
|
||||||
|
uint32 comp;
|
||||||
|
};
|
||||||
|
CriticalSection cs_;
|
||||||
|
std::queue<Image> background_;
|
||||||
|
|
||||||
|
|
||||||
|
};
|
@ -1,6 +1,8 @@
|
|||||||
#include "Ipc/Ipc.h"
|
#include "Ipc/Ipc.h"
|
||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
#include <locale>
|
||||||
|
#include <codecvt>
|
||||||
|
|
||||||
#include "Ipc/ReadCallback.h"
|
#include "Ipc/ReadCallback.h"
|
||||||
|
|
||||||
@ -15,8 +17,8 @@ std::shared_ptr<Ipc> Ipc::create(const char* reader_name, const char* writer_nam
|
|||||||
Ipc::Ipc(const char* reader_name, const char* writer_name) noexcept
|
Ipc::Ipc(const char* reader_name, const char* writer_name) noexcept
|
||||||
: reader_name_(reader_name)
|
: reader_name_(reader_name)
|
||||||
, writer_name_(writer_name) {
|
, writer_name_(writer_name) {
|
||||||
sender_ = std::make_unique<ipc::channel>(reader_name_.c_str(), ipc::sender);
|
sender_ = std::make_unique<ipc::channel>(toUtf8(reader_name_).c_str(), ipc::sender);
|
||||||
printf("%s, %s", reader_name, writer_name);
|
fprintf(stderr, "%s, %s\n", reader_name, writer_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ipc::~Ipc() {
|
Ipc::~Ipc() {
|
||||||
@ -101,3 +103,9 @@ void Ipc::onReciveer(const char* buffer, unsigned int size) {
|
|||||||
read->onRead(buffer, size);
|
read->onRead(buffer, size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string Ipc::toUtf8(const std::string& str) {
|
||||||
|
std::wstring_convert<std::codecvt_utf8<wchar_t>> converter;
|
||||||
|
std::wstring wide_str = converter.from_bytes(str);
|
||||||
|
return converter.to_bytes(wide_str);
|
||||||
|
}
|
||||||
|
@ -31,6 +31,8 @@ private:
|
|||||||
|
|
||||||
void onReciveer(const char* buffer, unsigned int size);
|
void onReciveer(const char* buffer, unsigned int size);
|
||||||
|
|
||||||
|
std::string toUtf8(const std::string& str);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string reader_name_;
|
std::string reader_name_;
|
||||||
std::string writer_name_;
|
std::string writer_name_;
|
||||||
|
@ -1,10 +1,44 @@
|
|||||||
#include "Ipc/IpcMoudle.h"
|
#include "Ipc/IpcMoudle.h"
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
#define STB_IMAGE_WRITE_IMPLEMENTATION
|
||||||
|
#include <stb/stb_image_write.h>
|
||||||
|
|
||||||
#include "Core/Core.h"
|
#include "Core/Core.h"
|
||||||
#include "Ipc/ipclib.h"
|
#include "Ipc/ipclib.h"
|
||||||
|
|
||||||
IpcMoudle* Singleton<IpcMoudle>::instance_ = nullptr;
|
IpcMoudle* Singleton<IpcMoudle>::instance_ = nullptr;
|
||||||
|
|
||||||
|
void OnParseImageData(const char* data, size_t size) {
|
||||||
|
if (size < 13) { // Minimum size check: 1 byte identifier + 4 bytes width + 4 bytes height + 4 bytes bit depth
|
||||||
|
std::cerr << "Invalid data size" << std::endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Extract identifier
|
||||||
|
char identifier = data[0];
|
||||||
|
|
||||||
|
// Extract width
|
||||||
|
int width;
|
||||||
|
std::memcpy(&width, data + 1, sizeof(int));
|
||||||
|
|
||||||
|
// Extract height
|
||||||
|
int height;
|
||||||
|
std::memcpy(&height, data + 5, sizeof(int));
|
||||||
|
|
||||||
|
// Extract bit depth
|
||||||
|
int bit_depth;
|
||||||
|
std::memcpy(&bit_depth, data + 9, sizeof(int));
|
||||||
|
|
||||||
|
// Extract image bytes
|
||||||
|
const char* img_bytes = data + 13;
|
||||||
|
size_t img_size = size - 13;
|
||||||
|
|
||||||
|
|
||||||
|
// Further processing of img_bytes can be done here
|
||||||
|
}
|
||||||
|
|
||||||
bool IpcMoudle::Initialize() {
|
bool IpcMoudle::Initialize() {
|
||||||
if (!initialize("ipc_sender", "ipc_sender")) {
|
if (!initialize("ipc_sender", "ipc_sender")) {
|
||||||
ERRORLOG("ipc initialize failed");
|
ERRORLOG("ipc initialize failed");
|
||||||
@ -12,7 +46,8 @@ bool IpcMoudle::Initialize() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setReaderCallback([](const char* data, unsigned int size) {
|
setReaderCallback([](const char* data, unsigned int size) {
|
||||||
INFOLOG("ipc recive data:{}", size);
|
//INFOLOG("ipc recive data:{}", size);
|
||||||
|
OnParseImageData(data, size);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@ public:
|
|||||||
ReaderCallback() = default;
|
ReaderCallback() = default;
|
||||||
~ReaderCallback() override = default;
|
~ReaderCallback() override = default;
|
||||||
void onRead(const char* buffer, unsigned int size) override {
|
void onRead(const char* buffer, unsigned int size) override {
|
||||||
printf("%s", buffer);
|
//printf("%s", buffer);
|
||||||
if (nullptr != m_readerCallbackFunc) {
|
if (nullptr != m_readerCallbackFunc) {
|
||||||
m_readerCallbackFunc(buffer, size);
|
m_readerCallbackFunc(buffer, size);
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,6 @@
|
|||||||
#include <stb/stb_image.h>
|
#include <stb/stb_image.h>
|
||||||
|
|
||||||
#include "Core/Logger.h"
|
#include "Core/Logger.h"
|
||||||
#include "Core/ScopeLock.h"
|
|
||||||
#include "Ipc/IpcMoudle.h"
|
#include "Ipc/IpcMoudle.h"
|
||||||
#include "shader_s.h"
|
#include "shader_s.h"
|
||||||
|
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
#include "RHI/RHI.h"
|
#include "RHI/RHI.h"
|
||||||
|
|
||||||
#include "Core/Core.h"
|
#include "Core/Core.h"
|
||||||
#include "Core/SpinLock.h"
|
|
||||||
#include "OpenGLDrv/GLDrvAPI.h"
|
#include "OpenGLDrv/GLDrvAPI.h"
|
||||||
|
|
||||||
#include "RHI/RHICommondList.h"
|
#include "RHI/RHICommondList.h"
|
||||||
|
Loading…
Reference in New Issue
Block a user