Can't get Bitmap displayed as DX11DynamicTexture

Hi!

I based my attempts on the VideoIn(DX11.Texture DShow) Node, but without the threading and extra class.
What I’d like to achieve is to get a Bitmap into a DX11DynamicTexture - what I’m doing right now:

public unsafe void TextureFromBitmap(Bitmap bitmap)
    	{
	        
	     
	        //Lock bitmap so it can be accessed for texture loading
	        BitmapData bitmapData = bitmap.LockBits(
	            new Rectangle(0, 0, bitmap.Width, bitmap.Height),
	            ImageLockMode.ReadOnly, PixelFormat.Format8bppIndexed);
    		
	        SlimDX.DataStream dataStream = new SlimDX.DataStream(
	            bitmapData.Scan0,
	            bitmapData.Stride * bitmapData.Height,
	            true, false);
	        
    		
    		
            byte* brgba = (byte*)this.buffer0.ToPointer();
	    	
	     
	        try
	        {
	        	
    		
    			for (int i = 0; i < bitmap.Width*bitmap.Height; i++)
                {
                    brgba[i * 4](i * 4) = (byte)dataStream.ReadByte();
                    brgba[i * 4 + 1](i * 4 + 1) = (byte)dataStream.ReadByte();
                    brgba[i * 4 + 2](i * 4 + 2) = (byte)dataStream.ReadByte();
                    brgba[i * 4 + 3](i * 4 + 3) = 255;
                }
    		
    		
    		
    		
    		IntPtr temp = this.buffer0;
            this.buffer0 = this.buffer1;
            this.buffer1 = temp;
	            
	        }
	        finally
	        {
	            //Free bitmap-access resources
	            dataStream.Dispose();
	      
	            bitmap.UnlockBits(bitmapData);
	        }
	     
	        
    	}

buffer1 gets passed onto Update() as frontbuffer where this happens:

this.TextureFromBitmap(this.bmp);
            this.FTextureOutput[0](0)[context](context).WriteData(this.frontBuffer, this.bmp.Width*this.bmp.Height*4);

Well, and I don’t see any Output :(
I assume the Bmp is loaded correctly, as I get the dimensions as DebugInfo.

Does anyone know where I’m going wrong?

Or maybe if there is a more direct way of accessing the bitmapData and writing it to the DX11DynamicTexture?

Thanks!

DX11.TextureDynamicBitmapTexture.zip (193.1 kB)

Just trying my luck by wildly guessing:

public void TextureFromBitmap( Bitmap bitmap)
    	{
	        
	     	
	        //Lock bitmap so it can be accessed for texture loading
	        BitmapData bitmapData = bitmap.LockBits(
	            new Rectangle(0, 0, bitmap.Width, bitmap.Height),
	            ImageLockMode.ReadOnly, PixelFormat.Format8bppIndexed);
    		
	        
	        
    		
    		
	     
	        try
	        {
	        	
    		
    		
    		IntPtr temp = bitmapData.Scan0;
            this.buffer0 = this.buffer1;
            this.buffer1 = temp;
	        	
	        	if (this.OnFrameReady != null)
                {
                    this.OnFrameReady(this, new EventArgs());
                }
	            
	        }
	        finally
	        {
	            //Free bitmap-access resources
	            //dataStream.Dispose();
	      
	            bitmap.UnlockBits(bitmapData);
	        	
	        }
	     
	        
    	}

results in the tty not stopping to shout:

00:02:16  -  : Stack Trace
00:02:16  -  :    at VVVV.DX11.Nodes.DX11_TextureDynamicBitmapTextureNode.Update(IPluginIO pin, DX11RenderContext context)
   at VVVV.DX11.Lib.RenderGraph.DX11DeviceRenderer.ProcessNode(DX11Node node)
00:02:16 ERR : Exception caused by node during update :/73/6/0
00:02:16 ERR : System.NullReferenceException in -1095118248._dynamic_.10: Object reference not set to an instance of an object.

Stacktrace:
   at VVVV.DX11.Nodes.DX11_TextureDynamicBitmapTextureNode.Update(IPluginIO pin, DX11RenderContext context)
   at VVVV.DX11.Lib.RenderGraph.DX11DeviceRenderer.ProcessNode(DX11Node node)

EDIT: managed to display something - both versions work kind of, but they are not assigned correctly… right now I get this instead of the vvvv/assets/ring.bmp

haha.

stupid bitmap.fileformat…
managed to get it right with PixelFormat.Format32Pargb

that’s pretty nice job ;]
whould love to add that code in to collection.

I probably won’t have it cleaned up before next week, but how would I go about adding it to the collection?

wait, what is here different (or better) than in Filetexture?

to be honest, I don’t know how useful it will be for anyone, haha, but filetexture creates the texture by doing something like

DX11Texture2D.FromFile(this.Context, filepath);

this approach takes a c# system.drawing.bitmap from memory or file(I also implemented an approach for reading the bitmapData straight form a IntPtr)

The reason for me to want this was a video capturing library that returns bitmapData (and I guess a couple of c# libraries do so)

cool… no text …