views:

84

answers:

1

Hi all.

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.

A: 

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

Geraint Davies
I don't get it... I'm creating the bitmapinfoheader in order to provide the output pin of the source filter.Where do I set it to YUV, or any of the other types you've mentioned?
Roey