| 83 | } |
| 84 | |
| 85 | bool 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 | |
| 112 | bool read_bmp_image(const std::byte *ptr, Image &dst) { |
| 113 | std::span<const std::byte> header(ptr, sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER)); |
no test coverage detected