2010-06-13 42 views
1

我試圖創建一個directshow圖形來播放由8位灰度位圖組成的視頻。 (使用directshow.net。)directshow Renderstream失敗,灰度位圖

我正在使用源過濾器和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返回「中間濾波器否組合可以發現進行連接」。

請幫忙!

謝謝。

回答

1

說實話,我還沒有看到任何調色板處理代碼的一段時間。我並不感到驚訝,它不再有效。

定義灰度的標準方法是使用YUV,U和V爲0位。這取得相同的空間,但不需要查表,因爲Y位是有效的。標準FOURCC是'Y800',其中使用FOURCCMap作爲子類型創建了一個guid。我不知道VMR是否會直接接受這個,但如果沒有,你可以使用www.gdcl.co.uk的YUV變換將它轉換成可接受的東西,比如YUY2,插入零(YUY2被廣泛接受但空間加倍)。

G

+0

我不明白...我創建了bitmapinfoheader以提供源過濾器的輸出引腳。 我在哪裏可以將它設置爲YUV,或者您提到的任何其他類型? – Roey 2010-06-13 11:02:14