directshow Renderstream 因灰度位图失败

发布于 2024-09-05 15:21:36 字数 2041 浏览 8 评论 0原文

我正在尝试创建一个 directshow 图形来播放由 8 位灰度位图组成的视频。 (使用 directshow.net。)

我正在使用源过滤器和 vmr9 渲染器。

源过滤器的输出引脚使用以下代码定义:

            bmi.Size = Marshal.SizeOf(typeof(BitmapInfoHeader));
            bmi.Width = width;
            bmi.Height = height;;
            bmi.Planes = 1;
            bmi.BitCount = (short)bitcount;
            bmi.Compression = 0;
            bmi.ImageSize = Math.Abs(bmi.Height) * bmi.Width * bmi.BitCount / 8;
            bmi.ClrUsed = bmi.BitCount <= 8 ? 256 : 0;
            bmi.ClrImportant = 0;

            //bmi.XPelsPerMeter = 0;
            //bmi.YPelsPerMeter = 0;
            bool isGrayScale = bmi.BitCount <= 8 ? true : false;
            int formatSize = Marshal.SizeOf(typeof(BitmapInfoHeader));
            if (isGrayScale == true)
            {
                MessageWriter.Log.WriteTrace("Playback is grayscale.");
                /// Color table holds an array of 256 RGBQAD values
                /// Those are relevant only for grayscale bitmaps
                formatSize += Marshal.SizeOf(typeof(RGBQUAD)) * bmi.ClrUsed;
            }
            IntPtr ptr = Marshal.AllocHGlobal(formatSize);
            Marshal.StructureToPtr(bmi, ptr, false);
            if (isGrayScale == true)
            {
                /// Adjust the pointer to the beginning of the 
                /// ColorTable address and create the grayscale color table
                IntPtr ptrNext = (IntPtr)((int)ptr + Marshal.SizeOf(typeof(BitmapInfoHeader)));

                for (int i = 0; i < bmi.ClrUsed; i++)
                {
                    RGBQUAD rgbCell = new RGBQUAD();
                    rgbCell.rgbBlue = rgbCell.rgbGreen = rgbCell.rgbRed = (byte)i;
                    rgbCell.rgbReserved = 0;
                    Marshal.StructureToPtr(rgbCell, ptrNext, false);
                    ptrNext = (IntPtr)((int)ptrNext + Marshal.SizeOf(typeof(RGBQUAD)));
                }
            }

这会导致 Renderstream 返回“无法找到用于建立连接的中间过滤器组合”。

请帮忙!

谢谢。

I'm trying to create a directshow graph to playback a video composed of 8bit grayscale bitmaps. (using directshow.net.)

I'm using a source filter and the vmr9 renderer.

The source filter's output pin is defined using the following code :

            bmi.Size = Marshal.SizeOf(typeof(BitmapInfoHeader));
            bmi.Width = width;
            bmi.Height = height;;
            bmi.Planes = 1;
            bmi.BitCount = (short)bitcount;
            bmi.Compression = 0;
            bmi.ImageSize = Math.Abs(bmi.Height) * bmi.Width * bmi.BitCount / 8;
            bmi.ClrUsed = bmi.BitCount <= 8 ? 256 : 0;
            bmi.ClrImportant = 0;

            //bmi.XPelsPerMeter = 0;
            //bmi.YPelsPerMeter = 0;
            bool isGrayScale = bmi.BitCount <= 8 ? true : false;
            int formatSize = Marshal.SizeOf(typeof(BitmapInfoHeader));
            if (isGrayScale == true)
            {
                MessageWriter.Log.WriteTrace("Playback is grayscale.");
                /// Color table holds an array of 256 RGBQAD values
                /// Those are relevant only for grayscale bitmaps
                formatSize += Marshal.SizeOf(typeof(RGBQUAD)) * bmi.ClrUsed;
            }
            IntPtr ptr = Marshal.AllocHGlobal(formatSize);
            Marshal.StructureToPtr(bmi, ptr, false);
            if (isGrayScale == true)
            {
                /// Adjust the pointer to the beginning of the 
                /// ColorTable address and create the grayscale color table
                IntPtr ptrNext = (IntPtr)((int)ptr + Marshal.SizeOf(typeof(BitmapInfoHeader)));

                for (int i = 0; i < bmi.ClrUsed; i++)
                {
                    RGBQUAD rgbCell = new RGBQUAD();
                    rgbCell.rgbBlue = rgbCell.rgbGreen = rgbCell.rgbRed = (byte)i;
                    rgbCell.rgbReserved = 0;
                    Marshal.StructureToPtr(rgbCell, ptrNext, false);
                    ptrNext = (IntPtr)((int)ptrNext + Marshal.SizeOf(typeof(RGBQUAD)));
                }
            }

This causes Renderstream to return "No combination of intermediate filters could be found to make the connection."

Please help!

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

蓝眼泪 2024-09-12 15:21:36

老实说,我有一段时间没有看到任何调色板处理代码了。对于它不再起作用我并不感到惊讶。

定义灰度的标准方法是使用 U 和 V 为 0 位的 YUV。这占用相同的空间,但不需要查表,因为 Y 位按原样有效。标准 FOURCC 是“Y800”,使用 FOURCCMap 作为子类型创建一个 guid。我不知道VMR是否会直接接受这个,但如果没有,您可以使用www.gdcl.co.uk的YUV变换将其转换为可接受的东西,例如YUY2,通过插入零(YUY2被广泛接受)但空间加倍)。

G

to be honest, I've not seen any palette handling code for a little while. I'm not that surprised that it no longer works.

The standard way to define grey scale is using YUV with 0 bits for U and V. That takes the same space, but does not require a table lookup, since the Y bits are valid as they are. The standard FOURCC is 'Y800', with a guid created using FOURCCMap as the subtype. I don't know if the VMR will accept this directly, but if not, you could use the YUV transform from www.gdcl.co.uk to convert it to something acceptable, such as YUY2, by inserting zeros (YUY2 is widely accepted but double the space).

G

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文