Mightex TCE1209-U new pictorial application

As a next step from my last blog – utility app, challenge is to write a demo app replacement.

Thanks to Mightex’s software engineering, there already exists some sample code in C++, C#, VB for interfacing with driver and camera.  You can download them from Mightex TCE1209-U page.


My personal copy of Visual Studio is 2008 and it is able to load the solution CSharp_Application under the SDK directory.  The SDK is written in C++ so I am building this as an x86 app for interop.



The sample application is threaded and already has code for interfacing with the driver.  User interface even has a button to start and stop frame grabs.  All I need to do are three tasks, display video rendering, save buffered image to file and offer a ‘run-on’ mode to save frames indefinitely.

Display Video


Sample code provided an unsafe pointer to each 16 bit pixel during after a frame-grab.  All I have to do is bitblit pixels to screen continuously.  For C#, I choose to use pictureBox as my video display.  I create 2 bitmap buffers to handle the alternating process of render and display.

// create 2 buffers for preview

bmps = new Bitmap[2];

bmps[0] = new Bitmap(picBox.Width, picBox.Height, PixelFormat.Format24bppRgb);
bmps[1] = new Bitmap(picBox.Width, picBox.Height, PixelFormat.Format24bppRgb);
rect = new Rectangle(1, 0, picBox.Width – 1, picBox.Height);


// copy previous buffer data to current except current frame.

g = Graphics.FromImage(bmps[notCurrent]);
g.DrawImage(bmps[current], 0, 0, rect, GraphicsUnit.Pixel);


// sample frame-grab pixels into new buffer
for (i = 0; i < frameSize; i++)
// bit shift – 12 bpp to 8bpp
byte p = (byte)((uint)*frameptr >> 4);

// preview – sample 1 out of 10 pixels
if (i % 10 == 0)
*Bmpptr = p; Bmpptr++;
*Bmpptr = p; Bmpptr++;
*Bmpptr = p; Bmpptr += (Bmpdata.Stride-2);


// copy new buffer into pictureBox

picBox.Image = (Image)bmps[current];

Sized at 500 x 205, it is scaling 10X smaller the specified 2048pixels/frame.  So, I am sampling 1 pixel out of 10 for video preview.  All previous frames (1 to n-1) are copied to (0,0) so as to provide a left moving video.

Buffered Image to file


The main goal of this application is to provide Andy a way to specify image size and then save the image in a common format.  The Buffered tab offer a standard saveFileDialog1 to create file name and destination.  .NET Bitmap class saves the 8bpp image into gif, bmp, jpg, png, tif.

How large can our Bitmap be ?  Here is the Microsoft documentation on System.Drawing.Bitmap.  Constructor signature for width and height are Int32 which has a range of 2,147,483,647.  32bit pointer with 2048 image height leaves us 1048575 pixels for width (minus header and padding).  In my tests, writing a 100,000 x 2048 bitmap crashes at bitmap.save() regardless of destination format type.  The largest bitmap I am able to save is 80,000 x 2048 pixels as bmp.


Inherently, the camera is 12bpp and produces 16bpp frames (4bits blank).  Logically I should be able to render and store png16 or bmp16 with indexed colors.  Also, another little quark about working with bitmap 8bpp index palette, one cannot directly set the palette values.  Instead, the following order of value assignments are required.  Read more from Charles Petzold’s article.

// set gray scale palette
ColorPalette pal = buffer.Palette;
for (int i = 0; i < 256; i++)
pal.Entries[i] = Color.FromArgb(255,i,i,i);
buffer.Palette = pal;

Run-On Mode


One advantage of a line scanning camera is that there is no specified image width.  One may wish to scan indefinitely or for a very long time.  So, it would be nice to use this ‘run-on’ mode to continuously scan and save each frame to a separate file.  For combining the frames, use the utility written for the last blog.  I will update it to handle png input next.  It should be noted that run-on mode is a secondary feature because of performance issue.  Writing image to file is a slow process while other frame-grabs get dropped; it takes about 500ms to iterate 1 frame save on my MacBookPro running Vista on VMWare.  We may revisit this feature later if it should be desirable.

To use this feature, you should use an empty directory.  If you prefer otherwise, the selected directory is scanned and displays an error popup if any file(s) with prefix of “frame” is founded.  Sorry I am not offering a choice in name or file format.  I am sticking with png files for now.


Test results

Here are some images I am creating at Lake Calhoun today; the original images are bundled in Github repository under directory exampleResults.




Here is the Microsoft Visual Studio solution source code – CSharp_Application on Github with debug executable.


It is a fun day making panoramic images at lake Calhoun.  I am learning that the software exposure value can speed up the frame rate and change the image brightness.  Unfortunately, the value of 1 locks up the application for unknown reason.


Here is a video demo.  thanks to my better-half for filming.

Next step

1) Update utility to handle png inputs with prefix name “frame”.

2) Debug above mention error with exposure value of “1”. problem in driver, block user from setting value of 1 for now.

3) Debug and implement the ability to use 8bpp gray scale bitmap if possible. done !

4) Sent it back to Andy for feedback !


1) Setting Bitmap Palette – Charles Petzold  http://www.charlespetzold.com/pwcs/PaletteChange.html


Application use direction



  1. plug in camera.
  2. execute application.
  3. select ‘camera1’ in left-upper combo box.
  4. start preview by clicking upper-right-button, ‘start preview’.

Buffered image mode


  1. to save scans by buffering, click on the ‘buffered tab’ (bottom).
  2. enter the numeric line count, (image width).
  3. select or enter destination file name path.
  4. check all the file types that apply (bmp, png, tiff, gif, etc).
  5. if not already selected, select radio button (upper-right) for “buffered image”.
  6. click on button “save” to start recording.
  7. a popup dialog will display when successfully scanned and saved to file.

Run-on mode

  1. to save scans by ‘run-on’, click on the ‘run-on tab’ (bottom).
  2. select a destination directory (preferably empty).
  3. select radio button (upper-right) for “run-on”.
  4. click on button “save’ to start recording.
  5. click on button ‘stop’ (previously ‘save’) or ‘stop preview’ to exit run-on mode.

Leave a Reply