Improving Image Display Performance

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

In an application I have to display a video composed of several frames that
I capture from a camera embedded in a Pocket PC. For each captured frame, I
create a Bitmap object, and display it in a PictureBox.

I get around 15 frames per seconds in 160x120, which is quite good. But when
I looked in details, I could see that 75% of the computational costs are due
to the bitmap creation and bitmap display!... only 25% are due to the frame
capture, and frame treatments.

Do you think of any alternative way to improve image display performance ?
Frames are stored as an array of byte, (RGB16bit:565 format) what would be
the most efficient way to display them to the screen ?

Thanks a lot!

Lionel Reyero

Here is a piece of the code I used so far :


pictureBox.Image = CreateBitmap(width, height, bpp, false, frameBytes);

// Creates System.Drawing.Bitmap from raw 16- or 24-bit data provided
protected static Bitmap CreateBitmap(int width, int height, int bpp, bool
inverted, byte[] bits)
{
// Size of BITMAPFILEHEADER structure
const uint fileHeaderSize = 14;

// Size of BITMAPINFOHEADER structure
const uint bitmapInfoHeaderSize = 40;

// Size of bitmap bits
uint bitsSize = (uint)(((width * bpp + 3) & ~3) * height);

// Size of the entire BMP-file
uint bitmapSize = fileHeaderSize + bitmapInfoHeaderSize + bitsSize;

// Creating memory stream to place our BMP-file to
MemoryStream stream = new MemoryStream(new byte[bitmapSize]);
BinaryWriter writer = new BinaryWriter(stream);

// Writing BITMAPFILEHEADER
writer.Write((byte)'B');
writer.Write((byte)'M');
writer.Write(bitmapSize);
writer.Write((ushort)0);
writer.Write((ushort)0);
writer.Write(fileHeaderSize + bitmapInfoHeaderSize);

// Writing BITMAPINFOHEADER
writer.Write((uint)bitmapInfoHeaderSize);
writer.Write(width);
writer.Write(!inverted ? -height : height);
writer.Write((ushort)1);
writer.Write((ushort)(bpp * 8));
writer.Write((uint)(0));
writer.Write((uint)0);
writer.Write((int)0);
writer.Write((int)0);
writer.Write((uint)(0));
writer.Write((uint)0);

// Writing actual bitmap bits. We do not perform any alignment padding here
// because all preview and capture modes are typically aligned properly, i.e.
// have their width a multiple of 4
writer.Write(bits);

return new Bitmap(stream);
}
 
The most efficient way would be probably using GAPI in 5:6:5 mode. You will
be able to copy blocks of bytes directly to video frame buffer.
Using GAPI might require copying gx.dll from SDK\Target\ARMv4 directory (if
it's not on the deivice).
P/Invoking GAPI functions is not exactly straightforward. You might find
some help here (code is kind of dirty, but you'll get the bits that you
need): http://www.alexfeinman.com/download.asp?doc=GAPITest.zip


--
Alex Feinman
---
Visit http://www.opennetcf.org
Lionel Reyero said:
Hi,

In an application I have to display a video composed of several frames
that
I capture from a camera embedded in a Pocket PC. For each captured frame,
I
create a Bitmap object, and display it in a PictureBox.

I get around 15 frames per seconds in 160x120, which is quite good. But
when
I looked in details, I could see that 75% of the computational costs are
due
to the bitmap creation and bitmap display!... only 25% are due to the
frame
capture, and frame treatments.

Do you think of any alternative way to improve image display performance ?
Frames are stored as an array of byte, (RGB16bit:565 format) what would be
the most efficient way to display them to the screen ?

Thanks a lot!

Lionel Reyero

Here is a piece of the code I used so far :


pictureBox.Image = CreateBitmap(width, height, bpp, false, frameBytes);

// Creates System.Drawing.Bitmap from raw 16- or 24-bit data provided
protected static Bitmap CreateBitmap(int width, int height, int bpp, bool
inverted, byte[] bits)
{
// Size of BITMAPFILEHEADER structure
const uint fileHeaderSize = 14;

// Size of BITMAPINFOHEADER structure
const uint bitmapInfoHeaderSize = 40;

// Size of bitmap bits
uint bitsSize = (uint)(((width * bpp + 3) & ~3) * height);

// Size of the entire BMP-file
uint bitmapSize = fileHeaderSize + bitmapInfoHeaderSize + bitsSize;

// Creating memory stream to place our BMP-file to
MemoryStream stream = new MemoryStream(new byte[bitmapSize]);
BinaryWriter writer = new BinaryWriter(stream);

// Writing BITMAPFILEHEADER
writer.Write((byte)'B');
writer.Write((byte)'M');
writer.Write(bitmapSize);
writer.Write((ushort)0);
writer.Write((ushort)0);
writer.Write(fileHeaderSize + bitmapInfoHeaderSize);

// Writing BITMAPINFOHEADER
writer.Write((uint)bitmapInfoHeaderSize);
writer.Write(width);
writer.Write(!inverted ? -height : height);
writer.Write((ushort)1);
writer.Write((ushort)(bpp * 8));
writer.Write((uint)(0));
writer.Write((uint)0);
writer.Write((int)0);
writer.Write((int)0);
writer.Write((uint)(0));
writer.Write((uint)0);

// Writing actual bitmap bits. We do not perform any alignment padding
here
// because all preview and capture modes are typically aligned properly,
i.e.
// have their width a multiple of 4
writer.Write(bits);

return new Bitmap(stream);
}
 
Thanks Alex,
However, there is something wrong with your link, I.E. fails to open the link.

Lionel
 
Sorry, sometimes file permissions on my server get screwed. Should be ok
now.
 
Back
Top