MCPcopy Create free account
hub / github.com/WallBreaker2/op / copy_raw_image

Function copy_raw_image

libop/capture/sources/MemoryImageSource.cpp:85–110  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

83}
84
85bool copy_raw_image(std::span<const std::byte> src, int width, int height, const std::wstring &fmt, Image &dst) {
86 dst.create(width, height);
87 if (fmt == L"bgra") {
88 const auto rowBytes = static_cast<size_t>(width) * 4;
89 for (int y = 0; y < height; ++y) {
90 const auto row = src.subspan(static_cast<size_t>(y) * rowBytes, rowBytes);
91 memcpy(dst.ptr<uchar>(y), row.data(), row.size());
92 }
93 return true;
94 }
95 if (fmt == L"bgr") {
96 const auto rowBytes = static_cast<size_t>(width) * 3;
97 for (int y = 0; y < height; ++y) {
98 const auto src_row = src.subspan(static_cast<size_t>(y) * rowBytes, rowBytes);
99 auto dst_row = dst.ptr<uchar>(y);
100 for (int x = 0; x < width; ++x) {
101 dst_row[x * 4 + 0] = std::to_integer<uchar>(src_row[x * 3 + 0]);
102 dst_row[x * 4 + 1] = std::to_integer<uchar>(src_row[x * 3 + 1]);
103 dst_row[x * 4 + 2] = std::to_integer<uchar>(src_row[x * 3 + 2]);
104 dst_row[x * 4 + 3] = 0xff;
105 }
106 }
107 return true;
108 }
109 return false;
110}
111
112bool read_bmp_image(const std::byte *ptr, Image &dst) {
113 std::span<const std::byte> header(ptr, sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER));

Callers 1

ParseMemoryImageSourceFunction · 0.85

Calls 3

createMethod · 0.45
dataMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected