我正在尝试实现Func
输出到 3 个单独缓冲区的颜色转换。该rgb_to_ycocg
函数有一个 4x8 位通道交错缓冲区 (BGRA) 和 3 个输出缓冲区(Y、Co 和 Cg),每个缓冲区都是 16 位值。目前,我正在使用这段代码:
void rgb_to_ycocg(const uint8_t *pSrc, int32_t srcStep, int16_t *pDst[3], int32_t dstStep[3], int width, int height)
{
Buffer<uint8_t> inRgb((uint8_t *)pSrc, 4, width, height);
Buffer<int16_t> outY(pDst[0], width, height);
Buffer<int16_t> outCo(pDst[1], width, height);
Buffer<int16_t> outCg(pDst[2], width, height);
Var x, y, c;
Func calcY, calcCo, calcCg, inRgb16;
inRgb16(c, x, y) = cast<int16_t>(inRgb(c, x, y));
calcY(x, y) = (inRgb16(0, x, y) + ((inRgb16(2, x, y) - inRgb16(0, x, y)) >> 1)) + ((inRgb16(1, x, y) - (inRgb16(0, x, y) + ((inRgb16(2, x, y) - inRgb16(0, x, y)) >> 1))) >> 1);
calcCo(x, y) = inRgb16(2, x, y) - inRgb16(0, x, y);
calcCg(x, y) = inRgb16(1, x, y) - (inRgb16(0, x, y) + ((inRgb16(2, x, y) - inRgb16(0, x, y)) >> 1));
Pipeline p =Pipeline({calcY, calcCo, calcCg});
p.vectorize(x, 16).parallel(y);
p.realize({ outY, outCo, outCg });
}
问题是,与参考实现(c 中的基本 for 循环)相比,我的性能很差。我知道我需要尝试更好的调度,但我认为我在输入/输出缓冲区方面做错了。我看过教程并试图想出一种输出到多个缓冲区的方法。使用 aPipeline
是我能找到的唯一方法。Func
制作 3 s 并单独调用它们会更好吗?这是对Pipeline
类的正确使用吗?