mario tapilouw dot net

excerpts of my dot net experience
See also: Other Geeks@INDC
Visual C# for simulation

 

This is my First blog in .netindonesia.net. For two days I have training session from Mr. Risman Adnan at Microsoft Innovation Center ITB. He was the one who introduce me on how to join this blog.

 

I am a using Visual C# .NET to develop an application for my research. The objective of the research is to develop hardware for MPEG-4/H.264 Variable Block Size Motion Estimation. So I will develop algorithm, prove its functionality and then use it as a reference for the hardware design.

 

In order to achieve my objective, I need something to visualize the result of my algorithm. I choose Visual C# because I can code faster because there’s abundant of information and tutorial on how to use GDI+ using C# and very easy to implement. Codeproject is my primary source for easy to follow tutorials.

 

I have to made this modules in my application :

-         Framereader : to read data from raw image sequences frame by frame (176x144 pixel, QCIF).

-         Partitioner : to split the frame into smaller blocks called the Macroblock (16x16 pixel).

-         SADEngine : this is the engine of Motion Estimation, I used Sum of Absolute Differences for block matching criteria.

 

Visualization is made using GDI+, I choose to display everything using the OnPaint() method, so every time I want to refresh the visualization I have to set a flag and call the

Invalidate() method. I don’t know the ‘Best Practice’ for using GDI+ since I didn’t found it, I would really appreciate if anyone could help me on coding for GDI+.

 

Here’s a part of my code:

private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)

{

            float brushwidth = 1.5F;

            pen = new Pen(Color.White, brushwidth);

            SolidBrush colorizer = new SolidBrush(Color.Lime);

            graph = panelMainTop.CreateGraphics();

            graph2 = panelMainBottom.CreateGraphics();

 

            String Str = "";

            Font drawFont = new Font("Arial", 10);

            SolidBrush drawBrush = new SolidBrush(Color.Black);

            StringFormat drawFormat = new StringFormat();

            drawFormat.FormatFlags = StringFormatFlags.NoClip;

 

            //display frames

            if(displayFrame)

            {

                        int left1 = 10;

                        int left2 = 220;

                        int top = 30;

                        int topText = 15;

                        int stepLength = 1;

                        int width = 1;

                        int height = 1;

                                               

                                               

 

                        // Create string to draw.

                        Str = "Reference Frame (-1)";

                        graph.DrawString(Str, drawFont, drawBrush, left1, topText, drawFormat);

 

                        Str = "Current Frame (0)";

                        graph.DrawString(Str, drawFont, drawBrush, left2, topText, drawFormat);

 

                        //create 176x144 picture                      

                        for(int i=0;i<144;i++) //144

                        {

                                    for(int j=0;j<176;j++) //176

                                    {

                                                colorizer.Color =

Color.FromArgb((int)refFrame[i,j],(int)refFrame[i,j],(int)refFrame[i,j]);                         

                                                graph.FillRectangle(colorizer, left1+(stepLength*j), top+(stepLength*i), width, height);

 

                                                colorizer.Color = Color.FromArgb(

(int)currFrame[i,j],(int)currFrame[i,j],(int)currFrame[i,j]);                                  

                                                graph.FillRectangle(colorizer,

                                             left2+(stepLength*j),top+(stepLength*i), width, height);

                                    }

                        }

            }

 

 

 

Those codes are for displaying a frame into the Form. I have to set the displayFrame to true in order to show the frame. If I want to show something else I have to set other flags.

 

 

 

Share this post: | | | |