Fast loading of bitmaps
Fast loading of bitmaps
Fast loading of bitmaps
Fast loading of bitmaps
Fast loading of bitmaps
Fast loading of bitmaps Fast loading of bitmaps Fast loading of bitmaps Fast loading of bitmaps Fast loading of bitmaps Fast loading of bitmaps Fast loading of bitmaps Fast loading of bitmaps
Fast loading of bitmaps Fast loading of bitmaps
Fast loading of bitmaps
Go Back  Xtreme Visual Basic Talk > > > > Fast loading of bitmaps


Reply
 
Thread Tools Display Modes
  #1  
Old 09-13-2008, 11:01 AM
Richard87 Richard87 is offline
Junior Contributor
 
Join Date: Sep 2004
Posts: 235
Question Fast loading of bitmaps into Textures


Hello, Ive started a new thread from the last one because it went way off mo original post.

Here is the thing:
I have a webcam set up with DirectShow, so I get a function called 30 times pr secunds(30FPS), with a pointer to a buffer and a bufferlen of the image captured(640x480).

Now, if I copy this into a bitmap and add it to a texture, it works, but is extremly slow.

What I then tried is texture.LockRect and just copy the source in there, wich I managed to do without problem(sort of), the problem is that I cannot create a Texture with the correct format( I need R8G8B8, but the only formats that seems to work is A8R8G8B8 and X8R8G8B8)

Does anyone have anyidea how I can get this to work (fast)? I have searched a lot, and the only thing I have cmoe across is a hint to that my GPU cant handle R8G8B8 ????

btw, here is my code:
Code:
Public Function BufferCB(ByVal SampleTime As Double, ByVal pBuffer As System.IntPtr, ByVal BufferLen As Integer) As Integer Implements DirectShowLib.ISampleGrabberCB.BufferCB SyncLock Me 'DirectX Stuff Try 'Fast Way: '--------------------------- Dim bm2() As Byte Dim m_text2 = New Texture(Display, rect.Width, rect.Height, 0, Usage.Dynamic, Format.R8G8B8, Pool.Default) bm2 = m_text2.LockRectangle(GetType(Byte), 0, rect, Microsoft.DirectX.Direct3D.LockFlags.None, IPA) Marshal.Copy(pBuffer, bm2, 0, BufferLen) m_text2.UnlockRectangle(0) ' 'Slow Way: '--------------------------- 'bm = b.LockBits(rect, ImageLockMode.ReadWrite, System.Drawing.Imaging.PixelFormat.Format24bppRgb) 'CopyMemory(bm.Scan0, pBuffer, BufferLen - 1) 'b.UnlockBits(bm) 'Dim m_text2 As New Texture(Display, b, Usage.Dynamic, Pool.Default) ''...render stuff... Display.Clear(ClearFlags.Target, Color.Yellow, 1, 0) Display.BeginScene() 'Sett opp 'viewport' SetupMatrices() Display.SetTexture(0, m_text2) 'Tegn Display.Material = mat Display.VertexFormat = CustomVertex.PositionTextured.Format 'Display.VertexFormat = CustomVertex.PositionColored.Format Display.SetTexture(0, m_text2) Display.SetStreamSource(0, m_VertexBuffer, 0) Display.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2) Display.EndScene() Display.Present() Catch ex As Exception MsgBox(ex.Message) Me.Form1_FormClosing(Nothing, Nothing) Me.Dispose() Application.Exit() End Try End SyncLock Application.DoEvents() End Function

The complete code is in the attachment...
Attached Files
File Type: vb Form1.vb (18.2 KB, 9 views)

Last edited by Richard87; 09-13-2008 at 11:09 AM.
Reply With Quote
  #2  
Old 09-15-2008, 07:36 AM
jo0lsFast loading of bitmaps jo0ls is offline
Senior Contributor

Forum Leader
* Expert *
 
Join Date: Feb 2005
Location: London
Posts: 1,050
Default

What problems did you have with the 32 bit format? What are the errors when you try to create a texture with a 24 bit format?

I tried getting your code running, but failed. So I did some heavy refactoring and used SlimDX instead of MDX.

GraphEdit shows that my web camera can output 24 bit RGB, or i420, in various dimensions. I found that I could specify allsorts for the media type, and I would get correct buffers that could be used to make correct bitmaps. So the data coming in to the callback is fine.

But, when I tried to make a texture @ (640x480), I found that it had too much room inside - I could read a length property from the object managing the locked texture. It turns out that the dimensions are bumped up to the nearest power of 2. So the input frame was (640x480), but the texture was (1024, 512) - the result is that when you copy the pixel data from the frame into the texture you only use about 60% of the space and get an image like the one you posted in the other thread. Mine's updside down, I need to alter the vertices. The fact that a correctly sized rectangle is locked doesn't make a difference - it must be letting you write data into non-locked portions or something.

I couldn't get a good looking stream with SlimDX at all, as I couldn't use the BItmap.Lockbits technique with it. My code liked to crash in strange ways.

The "proper" way to do it is to create a custom filter in c++. People say that you can use C# to make a custom filter to try code out, but it isn't fast enough. I think your idea of processing the callbacks is going to be slower still.

WPF doesn't talk to DirectShow at all. However there are hacks out there to do it. .This VideoRenderElement control uses a "bridge" written in C++ to get the data in to WPF. It shows a live feed from the webcam that has been altered to include a surface with a reflection in. It's pretty buggy too - though the developer thinks that it's just his DirectShow code. He also mentions that the HLSL patch in the DNF 3.5 sp1 should work with the control.
Reply With Quote
  #3  
Old 09-16-2008, 09:50 AM
jo0lsFast loading of bitmaps jo0ls is offline
Senior Contributor

Forum Leader
* Expert *
 
Join Date: Feb 2005
Location: London
Posts: 1,050
Default

I was just googling in a spare minute and found this:

4. D3DPOOL_SCRATCH

Places resources in system RAM. These resources can be locked and do not need recreating on a lost device. The great advantage of this resource type is that it is not restricted
by the video card e.g. many video cards require texture dimensions to be power of 2 only so if you wish to load a non power of 2 texture this is the only pool into which you can
load it. The disadvantage of course is that resources in this pool cannot be accessed by the device and so cannot be used during rendering. This pool is generally used for
pre-processing of data e.g. you could load a large texture into a scratch memory surface and then slice it into smaller pieces and create normal device textures with it.

toymaker.info

So, maybe using Scratch instead of Default for the Texture flag will sort out that problem:

Dim m_text2 = New Texture(Display, rect.Width, rect.Height, 0, Usage.Dynamic, Format.R8G8B8, Pool.Scratch)
Reply With Quote
  #4  
Old 09-19-2008, 02:07 PM
Richard87 Richard87 is offline
Junior Contributor
 
Join Date: Sep 2004
Posts: 235
Default

Helo, thx for your replies, I have tried the Scratch method, but just got a black screen, no erros when creating the textures at all.

I will look into the other problem with the textures needs do be sized properly, and look into the webcam settings problem..

I dont want to start with WPF just yet

btw, I bet the size is the problem, and will try to sort that out with the webcam options..
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Fast loading of bitmaps
Fast loading of bitmaps
Fast loading of bitmaps Fast loading of bitmaps
Fast loading of bitmaps
Fast loading of bitmaps
Fast loading of bitmaps Fast loading of bitmaps Fast loading of bitmaps Fast loading of bitmaps Fast loading of bitmaps Fast loading of bitmaps Fast loading of bitmaps
Fast loading of bitmaps
Fast loading of bitmaps
 
Fast loading of bitmaps
Fast loading of bitmaps
 
-->