Virtual Display

Are you sure? Here is a copy paste.

// Create flush event
            Graphics.OnFlushEvent += Graphics_OnFlushEvent;
1 Like

Ok, got events. The byte array is encoded in bitmap format ? Is there anything in the libraries to convert it to a bitmap file ?

We have an issue to offer a library to give you BMP file. It is easy but we haven’t implemented yet

The data is 5:6:5

I think I figured out the correct header (54 bytes). However, I’m not sure what the compression value should be at offset 0x1e

If you are getting it from the internal buffer, then there would be no compression unless you are doing compression to the file?

Got the bitmap file built. However, the original screen shot:

And the resulting bitmap:

is the difference a result of the 5-6-5 format ?

1 Like

Maybe the 2 bytes need to be swapped? An endianess issue.

Tried swapping the bytes. Did change the colors, but still the wrong colors. Also, opening in paint, the image is rotated 180 and flipped.

I assume you have written code to build a bmp file?

If so, you are asking us to debug your code by looking at an image?

Write a program in .net to read the file and build a bitmap. Look at the pixels and see if you can figure out what is happening.

the code to write a bitmap only include writing the header. The data cam right from the on_flush event. The image is the data from the event, not the code I wrote. So just supllying information on the content of the data. No debug of code needed

Then where is the problem?

Did you understand what Gus mean when he said:

The data is 5:6:5

it doesnt matter the format of the data. I am not modifying the data at all. It is just being copied into the file preceeded by the header which I did build and is apparently correct… However, the established windows programs display an image that is rotated 180 degrees and flipped with the colors no where near the original 20260/ud700 screen image. See above comparison images.

it doesnt matter the format of the data

What if you are wrong?

Perhaps you need to modify the data?

Look at the allowable data formats in the BMP specification. If there is not one that says “5:6:5”, then you need to covert to an allowable pixel format.

If the image is rotated, then you will need to either transform the original image, or set some parameter in the header. TinyClr is giving you a byte array compatible with the hardware display, not necessarily in BMP format.

The BMP specification has a color palette section, maybe you need to do some color transformation?

If I was writing this code, the image i would use would be white, red, green and blue rectangles on a black background. This would make it easier to understand what color transformations are occurring.

I believe that is the question I am asking. I am willing to massage the data if I knew what the current data is. ie the first pixel in the data array is apparently at coordinates 0,480 (where origin is at upper left) The first 2 bytes (16 bits) are stated to be in 5-6-5 format but apparently not 5 bits red, 6 bits green, 5 bits blue, at least not in that order. So the question is, what format is the data in ?

I do not know…

First thing I would do is search the forums for “display buffer format”. Maybe this has been discussed before.

If that didn’t work, I would experiment.

I think that the data is a copy or modified copy of the buffer used to refresh the display. Somewhere that format should be known. I’ll search the forum

At a guess you want to do a reverse of this:

using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConvertBitmap
{
    class Program
    {
        static void Main(string[] args)
        {
             try
            {
                if (args.Length == 0)
                {
                    throw new ArgumentException("Invalid arguments");
                }

                using (var image = (Bitmap)Bitmap.FromFile(args[0]))
                {
                    byte[] raw = new byte[2 * (image.Width * image.Height)];
                    int rawIndex = 0;
                    for (int y = 0; y < image.Height; y++)
                    {
                        for (int x = 0; x < image.Width; x++)
                        {
                            var c = image.GetPixel(x, y);
                            byte r = (byte)(31 * (c.R / 255.0));
                            byte g = (byte)(63 * (c.G / 255.0));
                            byte b = (byte)(31 * (c.B / 255.0));
                            
                            short p = (short)((r << 11) | (g << 5) | b);
                            raw[rawIndex++] = Hi(p);
                            raw[rawIndex++] = Lo(p);
                        }
                    }
                    File.WriteAllBytes(Path.GetFileNameWithoutExtension(args[0]) + ".tinybmp", raw);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                ShowUsage();                
            }
        }

        static void ShowUsage()
        {
            Console.WriteLine("TinyBitmap Converter");
            Console.WriteLine("Convert desktop bitmaps to TinyBitmaps which are compatible with GHI FEZ Devices");
            Console.WriteLine();
            Console.WriteLine("Usage:");
            Console.WriteLine("\tTinyBitmapConverter <source-image>");
        }

        static byte Hi(short s)
        {
            return (byte)(s >> 8);
        }

        static byte Lo(short s)
        {
            return (byte)(s & 0xff);
        }
        }
    }

Thanks, that will come in handy

I need to know the format of the data received from the On_Flush event. It is supposed to be bitmap 5-6-5, but windows paint, etc show much different colors than the original lcd screen

the answer is in the code that justin posted.