H
hufaunder
I have 16-bit data that I want to display. In order to display it I
compress a certain range of the input data into 8 bit (I need control
over this). All seems to work ok except that it is dead slow both in
release and debug mode. The main problem is the for-loop shown in the
code bellow. Without the for-loop I can get somewhere around 10-20
updates/second. With the for-loop I get an update every 2-3 seconds.
The strange thing is that when I measure the actual time (as shown
bellow) I get values of 400-600ms. That is still VERY slow but what I
observe is even another 5x slower. I don't know where that comes from.
Any idea on how to very significantly improve this or any other
completely different solution is appreciated.
Thanks
Single scale = ...;
bmpData = image.LockBits(rec, ImageLockMode.WriteOnly,
image.PixelFormat);
ptr = bmpData.Scan0;
// DateTime time;
for (i = 0; i < image.Width*image.Height; i++) {
Int32 value;
value = (Int32)((data-l)*scale);
if(value < 0) value = 0;
else if(value > 255) value = 255;
rgbValues[i * 3 + 0] = (Byte)value;
rgbValues[i * 3 + 1] = (Byte)value;
rgbValues[i * 3 + 2] = (Byte)value;
}
//
MessageBox.Show(((TimeSpan)DateTime.Now.Subtract(date)).Milliseconds.ToString());
System.Runtime.InteropServices.Marshal.Copy(rgbValues, 0,
ptr, numberBytes);
image.UnlockBits(bmpData);
compress a certain range of the input data into 8 bit (I need control
over this). All seems to work ok except that it is dead slow both in
release and debug mode. The main problem is the for-loop shown in the
code bellow. Without the for-loop I can get somewhere around 10-20
updates/second. With the for-loop I get an update every 2-3 seconds.
The strange thing is that when I measure the actual time (as shown
bellow) I get values of 400-600ms. That is still VERY slow but what I
observe is even another 5x slower. I don't know where that comes from.
Any idea on how to very significantly improve this or any other
completely different solution is appreciated.
Thanks
Single scale = ...;
bmpData = image.LockBits(rec, ImageLockMode.WriteOnly,
image.PixelFormat);
ptr = bmpData.Scan0;
// DateTime time;
for (i = 0; i < image.Width*image.Height; i++) {
Int32 value;
value = (Int32)((data-l)*scale);
if(value < 0) value = 0;
else if(value > 255) value = 255;
rgbValues[i * 3 + 0] = (Byte)value;
rgbValues[i * 3 + 1] = (Byte)value;
rgbValues[i * 3 + 2] = (Byte)value;
}
//
MessageBox.Show(((TimeSpan)DateTime.Now.Subtract(date)).Milliseconds.ToString());
System.Runtime.InteropServices.Marshal.Copy(rgbValues, 0,
ptr, numberBytes);
image.UnlockBits(bmpData);