Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions core/render/image_stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ bool ImageFrame::convertToRgba8(std::vector<std::uint8_t>& output) const {
destination[1] = pixel[1];
destination[2] = pixel[bgra ? 0 : 2];
destination[3] = pixel[3];
destination += 4;
}
}
return true;
Expand Down
36 changes: 36 additions & 0 deletions tests/unit/image_stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,42 @@ int main() {
return 1;
}

// 回归测试:多像素 BGRA8/RGBA8 转换必须逐像素前进,不能只写行首 4 字节。
// 历史 bug:内层循环的 destination 指针从不前进,导致每行只剩最后一个像素。
{
// 4x1 BGRA8:源 4 个像素 B/G/R/A 各不相同
const auto bgraWide = std::make_shared<const std::vector<std::uint8_t>>(
std::vector<std::uint8_t>{
1, 2, 3, 255, // BGRA -> RGBA (3,2,1,255)
4, 5, 6, 255, // BGRA -> RGBA (6,5,4,255)
7, 8, 9, 255, // BGRA -> RGBA (9,8,7,255)
10, 11, 12, 255, // BGRA -> RGBA (12,11,10,255)
});
const core::render::ImageFrame bgraWideFrame{
bgraWide, 4, 1, 16, core::render::ImagePixelFormat::BGRA8, 0};
if (!bgraWideFrame.convertToRgba8(converted) ||
converted != std::vector<std::uint8_t>{
3, 2, 1, 255, 6, 5, 4, 255, 9, 8, 7, 255, 12, 11, 10, 255}) {
return 1;
}
}
{
// 2x2 RGBA8:源 4 个像素 R/G/B/A 各不相同
const auto rgbaWide = std::make_shared<const std::vector<std::uint8_t>>(
std::vector<std::uint8_t>{
10, 20, 30, 255, 40, 50, 60, 255,
70, 80, 90, 255, 100, 110, 120, 255,
});
const core::render::ImageFrame rgbaWideFrame{
rgbaWide, 2, 2, 8, core::render::ImagePixelFormat::RGBA8, 0};
if (!rgbaWideFrame.convertToRgba8(converted) ||
converted != std::vector<std::uint8_t>{
10, 20, 30, 255, 40, 50, 60, 255,
70, 80, 90, 255, 100, 110, 120, 255}) {
return 1;
}
}

const auto nv12Y = bytes({128});
const auto nv12UV = bytes({128, 128});
core::render::ImageFrame nv12{nv12Y, 1, 1, 1, core::render::ImagePixelFormat::NV12, 0,
Expand Down
Loading