【问题标题】:directshow Renderstream fails with grayscale bitmapsdirectshow Renderstream 因灰度位图而失败
【发布时间】:2010-06-13 05:19:19
【问题描述】:

我正在尝试创建一个 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 返回“找不到中间过滤器的组合来建立连接。”

请帮忙!

谢谢。

【问题讨论】:

    标签: c# directshow directshow.net


    【解决方案1】:

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

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

    G

    【讨论】:

    • 我不明白...我正在创建 bitmapinfoheader 以提供源过滤器的输出引脚。我在哪里将其设置为 YUV 或您提到的任何其他类型?
    猜你喜欢
    • 2015-06-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-09
    • 1970-01-01
    • 1970-01-01
    • 2018-02-16
    • 1970-01-01
    相关资源
    最近更新 更多