add image buffer to reciver py image

This commit is contained in:
jiegeaiai 2024-12-01 01:10:43 +08:00
parent 25c023e479
commit 61b9c17426
17 changed files with 114 additions and 9 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -6,8 +6,8 @@
#include "Constant.h"
#include "Logger.h"
#include "CriticalSection.h"
#include "ScopeLock.h"
#include "Thread/CriticalSection.h"
#include "Thread/ScopeLock.h"
#include "Mesh.h"

View File

@ -1,4 +1,4 @@
#include "Core/CriticalSection.h"
#include "Core/Thread/CriticalSection.h"
CriticalSection::CriticalSection() noexcept {

24
src/ImageBuffer.cpp Normal file
View 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
View 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_;
};

View File

@ -1,6 +1,8 @@
#include "Ipc/Ipc.h"
#include <functional>
#include <locale>
#include <codecvt>
#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
: reader_name_(reader_name)
, writer_name_(writer_name) {
sender_ = std::make_unique<ipc::channel>(reader_name_.c_str(), ipc::sender);
printf("%s, %s", reader_name, writer_name);
sender_ = std::make_unique<ipc::channel>(toUtf8(reader_name_).c_str(), ipc::sender);
fprintf(stderr, "%s, %s\n", reader_name, writer_name);
}
Ipc::~Ipc() {
@ -101,3 +103,9 @@ void Ipc::onReciveer(const char* buffer, unsigned int 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);
}

View File

@ -31,6 +31,8 @@ private:
void onReciveer(const char* buffer, unsigned int size);
std::string toUtf8(const std::string& str);
private:
std::string reader_name_;
std::string writer_name_;

View File

@ -1,10 +1,44 @@
#include "Ipc/IpcMoudle.h"
#include <iostream>
#define STB_IMAGE_WRITE_IMPLEMENTATION
#include <stb/stb_image_write.h>
#include "Core/Core.h"
#include "Ipc/ipclib.h"
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() {
if (!initialize("ipc_sender", "ipc_sender")) {
ERRORLOG("ipc initialize failed");
@ -12,7 +46,8 @@ bool IpcMoudle::Initialize() {
}
setReaderCallback([](const char* data, unsigned int size) {
INFOLOG("ipc recive data:{}", size);
//INFOLOG("ipc recive data:{}", size);
OnParseImageData(data, size);
}
);

View File

@ -11,7 +11,7 @@ public:
ReaderCallback() = default;
~ReaderCallback() override = default;
void onRead(const char* buffer, unsigned int size) override {
printf("%s", buffer);
//printf("%s", buffer);
if (nullptr != m_readerCallbackFunc) {
m_readerCallbackFunc(buffer, size);
}

View File

@ -9,7 +9,6 @@
#include <stb/stb_image.h>
#include "Core/Logger.h"
#include "Core/ScopeLock.h"
#include "Ipc/IpcMoudle.h"
#include "shader_s.h"

View File

@ -1,7 +1,6 @@
#include "RHI/RHI.h"
#include "Core/Core.h"
#include "Core/SpinLock.h"
#include "OpenGLDrv/GLDrvAPI.h"
#include "RHI/RHICommondList.h"