fix(sender): 修正串流画面红蓝通道对调,颜色与被控端一致

- video_texture: NV12→BGRA 转换改为 B,G,R 字节序,与 StretchDIBits 32bpp
  BI_RGB 布局一致;原先写成 RGBA,蓝色壁纸在窗口里显示成土黄/粉
- video_texture: 注明 FrameStore 帧序为 BGRA,Flutter 纹理复用需自行交换
- 用手机截图逐点比对验证:互换后误差 1~6/255,转换公式平均误差 1.5/255
This commit is contained in:
tongtong committed 2026-11-27 12:26:06 +08:00
1 parent 32e7ca26d8
commit d4cd497a44
1 file changed
+7 -2
@@ -308,6 +308,9 @@ void ClampToByte(int value, uint8_t* out) {
} }
// BT.601 有限范围 NV12 -> BGRA(按显示区域裁剪掉解码补齐的行)。 // BT.601 有限范围 NV12 -> BGRA(按显示区域裁剪掉解码补齐的行)。
//
// 注意字节序是 B,G,R,A:窗口用 StretchDIBits + 32bpp BI_RGB 直接把这块内存贴屏,
// DIB 的内存布局就是 BGRA。写成 RGBA 会让红蓝对调(蓝色壁纸变土黄/粉)。
void ConvertNv12(const uint8_t* data, void ConvertNv12(const uint8_t* data,
size_t length, size_t length,
int coded_width, int coded_width,
@@ -343,9 +346,9 @@ void ConvertNv12(const uint8_t* data,
const int u = static_cast<int>(uv_row[(column & ~1)]) - 128; const int u = static_cast<int>(uv_row[(column & ~1)]) - 128;
const int v = static_cast<int>(uv_row[(column & ~1) + 1]) - 128; const int v = static_cast<int>(uv_row[(column & ~1) + 1]) - 128;
const int scaled = c < 0 ? 0 : c; const int scaled = c < 0 ? 0 : c;
ClampToByte((298 * scaled + 409 * v + 128) >> 8, dst); ClampToByte((298 * scaled + 516 * u + 128) >> 8, dst);
ClampToByte((298 * scaled - 100 * u - 208 * v + 128) >> 8, dst + 1); ClampToByte((298 * scaled - 100 * u - 208 * v + 128) >> 8, dst + 1);
ClampToByte((298 * scaled + 516 * u + 128) >> 8, dst + 2); ClampToByte((298 * scaled + 409 * v + 128) >> 8, dst + 2);
dst[3] = 0xff; dst[3] = 0xff;
dst += 4; dst += 4;
} }
@@ -860,6 +863,8 @@ class VideoTexturePlugin : public flutter::Plugin {
int width = 0; int width = 0;
int height = 0; int height = 0;
uint64_t pts = 0; uint64_t pts = 0;
// FrameStore 里的帧是 BGRA(GDI 贴屏用的顺序)。若将来重新用 Flutter 纹理
// 显示画面,必须在这里把 R/B 换回 Flutter 需要的 RGBA 顺序。
const uint8_t* pixels = store->Acquire(&width, &height, &pts); const uint8_t* pixels = store->Acquire(&width, &height, &pts);
if (pixels == nullptr) { if (pixels == nullptr) {
return nullptr; return nullptr;