Hi,
Please consider the following code sample:
public static class StringExtender
{
public static byte[] GetLedBitmapBytes(this string text, Font font, int width, int height, int x = 0, int y = 0)
{
byte[] data = new byte[width * height];
using (var bitmap = new Bitmap(width, height))
{
bitmap.DrawText(text, font, Color.White, x, y);
bitmap.Flush();
data = bitmap.GetLedBitmapBytes();
}
return data;
}
}
And
public static byte[] GetLedBitmapBytes(this Bitmap bitmap)
{
int threshold = 127;
int index = 0;
int dimensions = bitmap.Height * bitmap.Width;
byte[] data = new byte[dimensions / 8];
for (int horizontalLine = 0; horizontalLine < bitmap.Height / 16; horizontalLine++)
for (int column = 0; column < bitmap.Width / 8; column++)
for (int row = horizontalLine * 16; row < 16 * horizontalLine + 16; row++)
for (int x = 0; x < 8; x++)
{
var c = bitmap.GetPixel(column * 8 + x, row);
var r = ColorUtility.GetRValue(c);
var g = ColorUtility.GetGValue(c);
var b = ColorUtility.GetBValue(c);
int luminance = (int)(r * 0.3 + g * 0.59 + b * 0.11);
if (luminance > threshold)
data.SetBit(index);
index++;
}
return data;
}
This is an example of bitmap processing I need to do very frequently
and at a high speed. Of course when I wrote this stuff for the desktop framework I didn’t have to worry about speed issues or anything.
But on an embedded device it’s a completely different story.
The code takes a string, converts it to a bitmap and then converts
the bitmap to a byte[] that is sent to an LED panel which then displays it.
The data is created on the managed side, and send to the device on the native side (rlp).
The bitmap operations are the bottleneck here,
and the example is just a very very very simple example of what we really need. So I’m thinking there is no way this will ever be fast enough for let’s say: making text scroll. As I need to redraw the bitmap every time.
(I can send data to the panel at extremely high speed using RLP, but
compared to that the bitmap code takes an eternity to process)
So I’m wondering…
How to embedded device developers normally deal with bitmaps?
Are there C libraries we can use, or other resources that might help ?