View Full Version : UYVY format in the image buffer ?

June 27, 2010, 18:23:57
Dear Stefan,

With the DBK41AG02.AS camera, when asking the ICImagingControl component to issue images using UYVY format, what is the format really used in the imagebuffer ??

Is it really UYVY ? or is it something else ?

I'm trying to decode the contents of the imagebuffer using an algorithm (UYVYtoRGB) that I have already used in the past, and the image is all scrambled.
When I don't decode the image, I just get a proper greyscale image.

Am I missing something ?

Thank you.
Best regards

Stefan Geissler
June 28, 2010, 09:55:15
Hello Axel,

the pixel format in the image buffer should be a real UYVY. Please keep in mind, it is stored bottom up, but this should not have influence on your algorithm.

If you do not decode, then you should not get a proper grayscale image, except someone does a color space transformation.

At least: disable the overlay bitmap by
Icimagigncontrol1.OverlayPathpostion = ePP_NONE

(That is C++ code, but should be similar in VB6)

June 28, 2010, 20:46:49
Hello Stefan,

I'm already doing the following when setting the video format, but nothing special happens :

ICImagingControl.OverlayBitmapPosition := PATHPOSITION_NONE;

The OverlayPathposition property that you indicate in your message does not seem to exist...

Best regards

Stefan Geissler
June 29, 2010, 10:00:46

did you set the "MemoryCurrentGrabberColorFormat" propert to the appropriate value?

June 29, 2010, 10:17:26
Hello Stefan,

I cannot set the MemoryCurrentGrabberColorFormat property.
Every time I try I get the following error :

"EOleException : An option is not available, e.g. you called setFlipH and the VideoCaptureDevice does not support flipping"

I already mentioned this error in a thread in december last year :


I tried to set directly the following values :

and the error message always appears whatever value I give.

Thank You
Best regards

Stefan Geissler
June 29, 2010, 11:14:37
This property can only be set, before the live video has been started. Then it must work fine.

Seems you use Delphi. Maybe Delphi has a problem with the enumeration?

June 29, 2010, 12:32:58

The LiveVideoRunning property is always false when I set the MemoryCurrentGrabberColorFormat property :

procedure TFRM_CamPropertyDlg.CBX_VideoFormatsChange(Sender: TObject);
If ICImagingControl.DeviceValid then
If ICImagingControl.LiveVideoRunning then
// Sleep(500);
ICImagingControl.VideoFormat := ICImagingControl.VideoFormats[CBX_VideoFormats.ItemIndex+1].Name;
ICImagingControl.OverlayBitmapPosition := PATHPOSITION_NONE;
//crashes here
ICImagingControl.MemoryCurrentGrabberColorFormat := ICUYVY;//GetGrabberColorFormat(ICImagingControl.VideoFormat );
ICImagingControl.VideoFormat := ICImagingControl.VideoFormats[CBX_VideoFormats.ItemIndex+1].Name;
ICImagingControl.OverlayBitmapPosition := PATHPOSITION_NONE;
//crashes here
ICImagingControl.MemoryCurrentGrabberColorFormat := ICUYVY;//GetGrabberColorFormat(ICImagingControl.VideoFormat );
If @VideoFormatChangeCB <> Nil then
VideoFormatChangeCB(Self.Camera,CBX_VideoFormats.T ext);



Yes, I use Delphi, and have used enumerations in the past without any problems (ASCOM interface, http://ascom-standards.org, which uses COM models).

Best regards

Stefan Geissler
June 29, 2010, 13:32:30
What does "crashes here" mean? Do you receive an error message?

Maybe you can create a simple project, just place an IC Control on the form and call

ICImagingControl.MemoryCurrentGrabberColorFormat := ICUYVY

Do not open a video capture device.

Also please keep in mind, there is no filter available, that converts any format into UYVY. That means, the video format must be UYVY and nothing else.

July 4, 2010, 11:03:38
Hello Stefan,

I tried what you said, and it's still the same. I even get the error message when changing the property manually in delphi's "object inspector".
When changing from RGB24 to UYVY or to any other value, I get the same error message as before, without even running the program.

I completely uninstalled all versions of ICImagingControl and reinstalled only ICImagingControl V3.0.7.

Now I found a property called SinkCompatibilityMode that when it 's set to "true" seems to allow the MemoryCurrentGrabberColorFormat to be changed without getting the error.
So I set the SinkCompatibilityMode property to "true".

But now, when I change the MemoryCurrentGrabberColorFormat in my "real" program, I get the following message :

Text version:
Protection Error
Debugger detected - please close it down and restart !
Windows NT users: Please note that having the WinIce/SoftIce service installed means that you are running a debugger !

NO. I'm Not running Softice nor WinIce.
YES. I use Delphi's integrated debugger to debug my program.
Why do I suddenly have this message ? ICImaging Control is a SDK, so why shouldn't we be allowed to use a debugger ?

Thank you again for your help.

Best regards

Stefan Geissler
July 5, 2010, 08:18:04

the error message "Debugger detected" is not an error message of Delphi or The Imaging Source. It is an error message created by third party DirectShow filters. For example Nero installs some filters in the system and they show this error message if they are loaded by a program running in a debugging environment. These filters are loaded automatically by DirectShow while it negotiates the video formats between the different inputs and outputs. I suggest to find out, which filter(s) create this error message and try to uninstall them.

July 5, 2010, 08:48:31
Dear Stefan,

After a little search this morning I also started to suspect this but I wasn't sure... I have to seek out what .ax file is loaded when this happens.

Thank you.

July 5, 2010, 11:35:16
Dear Stefan,

Great news ! :-)

1 - The "Protection Error" message does not appear anymore, even though I did not find what the cause was... :confused:

2 - The UYVY decoding now works flawlessly ! The solution to my not being able to set the "MemoryCurrentGrabberColorFormat" property was indeed to set the "SinkCompatibilityMode" property to "True" before doing so.

Thank you again !

Best regards

Stefan Geissler
July 5, 2010, 13:41:37

good to read!

October 4, 2010, 13:14:26
The UYVY color format is basically a 16 bit color format. In contrast to the RGB formats, it contains no values for red, green or blue. It uses values for luminance and chrominance instead. Y stands for the luminance. U (or Cb) and V (or Cr) describe the chrominance. For further details refer to the following link:


The organization of the pixels in the image buffer is from left to right and top down.

How to read and write pixel data
A video capture device, video format, FrameHandlerSink with a MemBufferCollection, which defines the image data color format must first have been setup. The following code fragments show step-by-step how to access and manipulate the pixel data of UYVY.

First of all, we have to capture an image. Otherwise, the image buffer would be empty. To do so, we start live mode and call Grabber::snapImages.

Accessing the buffer
The following code retrieves a byte pointer to the image data. We use a structure UYVYQuad to access the different components of the pixel pairs:

// UYVY Images are stored top-down, so the upper left pixel starts at byte 0.
// Each 4 bytes represent the color for 2 neighboring pixels:
// [ U0 | Y0 | V0 | Y1 ]
// Y0 is the brightness of pixel 0, Y1 the brightness of pixel 1.
// U0 and V0 is the color of both pixels.
struct UYVYQuad
UYVYQuad* pImgData = (UYVYQuad*)pActiveBuf->getPtr();

In this example, we want to output the first (upper left hand) four pixels of the image. In a second step, we are going to manipulate the first six pixels. Because UYVY images are stored top-down, the index of the upper left two pixels is 0:

// Calculate the index of the upper left pixel
// Images are stored top-down in the image buffer, so the first two pixels have index 0.
int iOffsUpperLeft = 0;
Now that we have the offset to the the first pixel, we can read it out:

printf( "\nImage buffer pixel format is eUYVY\n" );
printf( "Pixel 1 (Y U V): %d %d %d\n", pImgData[iOffsUpperLeft].Y0,
pImgData[iOffsUpperLeft].U0, pImgData[iOffsUpperLeft].V0 );
printf( "Pixel 2 (Y U V): %d %d %d\n", pImgData[iOffsUpperLeft].Y1,
pImgData[iOffsUpperLeft].U0, pImgData[iOffsUpperLeft].V0 );
printf( "Pixel 3 (Y U V): %d %d %d\n", pImgData[iOffsUpperLeft+1].Y0,
pImgData[iOffsUpperLeft+1].U0, pImgData[iOffsUpperLeft+1].V0 );
printf( "Pixel 4 (Y U V): %d %d %d\n", pImgData[iOffsUpperLeft+1].Y1,
pImgData[iOffsUpperLeft+1].U0, pImgData[iOffsUpperLeft+1].V0 );
Please note, that while the two pixels of a pixel pair have separate Y (brightness) values, they share the color values U and V.

Manipulating Image Data
Instead of only reading pixel data, it is, of course, possible to manipulate the data as well. The following code sets the upper left six pixels to red, light red, green, dark green, blue and light blue. After this manipulation, the image is saved as a BMP file.

// Overwrite the first 6 pixels and save image to disk
// set the first 2 pixels to RED
pImgData[0].U0 = 90;
pImgData[0].V0 = 240;
pImgData[0].Y0 = 82;
pImgData[0].Y1 = 164; // Make the 2nd pixel brighter

// set the 3rd and 4th to GREEN
pImgData[1].U0 = 54;
pImgData[1].V0 = 34;
pImgData[1].Y0 = 145;
pImgData[1].Y1 = 72; // Make the 2nd pixel darker

// set the 5th and 6th pixel to BLUE
pImgData[2].U0 = 240;
pImgData[2].V0 = 110;
pImgData[2].Y0 = 41;
pImgData[2].Y1 = 82; // Make the 2nd pixel brighter

// The values above were calculated using the following formulas:
// Y = (0.257 * R) + (0.504 * G) + (0.098 * B) + 16
// V = (0.439 * R) - (0.368 * G) - (0.071 * B) + 128
// U = -(0.148 * R) - (0.291 * G) + (0.439 * B) + 128

// We save the buffer as RGB24, so that other software can view it.
saveToFileBMP( *pActiveBuf, "UYVY.bmp", eRGB24 );

October 29, 2010, 07:43:19
hello stefan,
there any way to program a site with an image flush at the top of the page - no background pixel buffer involved at all?

Stefan Geissler
October 29, 2010, 08:07:59

I am very sorry, but I do not understand your question.