I want to adjust the color and brightness of the Frame.

Ask software engineering and SDK questions for developers working on Mac OS X, Windows or Linux.
  • Author
  • Message
Offline

BAEK TS

  • Posts: 3
  • Joined: Wed Apr 03, 2024 2:29 am
  • Real Name: BAEK TAE SEONG

I want to adjust the color and brightness of the Frame.

PostWed Apr 03, 2024 2:43 am

I'm using C#.
I did the following before I rendered the Frame for this task, which works as desired. However, because the operation is performed every frame, it results in the Frame being lowered.

Code: Select all
public IDeckLinkVideoFrame ProcessFrame(IDeckLinkVideoFrame rawFrame, float brightnessFactor, float redFactor, float greenFactor, float blueFactor)
        {
            IntPtr pFrameBuffer;
            rawFrame.GetBytes(out pFrameBuffer);

            int width = rawFrame.GetWidth();
            int height = rawFrame.GetHeight();
            int rowBytes = rawFrame.GetRowBytes();

            // Reuse the frameBytes array if possible, otherwise create a new one
            byte[] frameBytes = new byte[rowBytes * height];

            // Copy frame data to managed array
            Marshal.Copy(pFrameBuffer, frameBytes, 0, frameBytes.Length);

            float redBrightnessFactor = redFactor * brightnessFactor;
            float greenBrightnessFactor = greenFactor * brightnessFactor;
            float blueBrightnessFactor = blueFactor * brightnessFactor;

            // Process each pixel
            Parallel.For(0, height, y =>
            {
                for (int x = 0; x < width; x++)
                {
                    int offset = (y * rowBytes) + (x * 4);

                    // BGRA format
                    byte blue = frameBytes[offset];
                    byte green = frameBytes[offset + 1];
                    byte red = frameBytes[offset + 2];

                    // Apply factors
                    red = (byte)Math.Min(255, red * redBrightnessFactor);
                    green = (byte)Math.Min(255, green * greenBrightnessFactor);
                    blue = (byte)Math.Min(255, blue * blueBrightnessFactor);

                    frameBytes[offset] = blue;
                    frameBytes[offset + 1] = green;
                    frameBytes[offset + 2] = red;
                }
            });

            // Copy modified data back to frame buffer
            Marshal.Copy(frameBytes, 0, pFrameBuffer, frameBytes.Length);
            return rawFrame;
        }


I found another way, if my understanding is correct, is Chroma able to achieve the above effect?
Code: Select all
IDeckLinkConfiguration deckLinkConfiguration = m_deckLink as IDeckLinkConfiguration;
            //deckLinkConfiguration.GetFloat(_BMDDeckLinkConfigurationID.bmdDeckLinkConfigVideoOutputComponentChromaRedGain, out double value);
            deckLinkConfiguration.SetFloat(_BMDDeckLinkConfigurationID.bmdDeckLinkConfigVideoInputComponentChromaRedGain, 1.0f);


However, this also doesn't work, throwing an error called System.NotImplementedException. Both Input/Output will throw an error.
I have verified that the code below works fine.
is there any other solution that I haven't found?
Code: Select all
deckLinkConfiguration.SetString(_BMDDeckLinkConfigurationID.bmdDeckLinkConfigDeviceInformationCompany, "TESTCOMPANY");            deckLinkConfiguration.GetString(_BMDDeckLinkConfigurationID.bmdDeckLinkConfigDeviceInformationCompany, out string value);


I'm eagerly anticipating your assistance.
Offline

BAEK TS

  • Posts: 3
  • Joined: Wed Apr 03, 2024 2:29 am
  • Real Name: BAEK TAE SEONG

Re: I want to adjust the color and brightness of the Frame.

PostFri Apr 05, 2024 1:03 am

I also tried applying DirectShow to find out how to do it. (Previously, I used IDeckLinkDX9ScreenPreviewHelper.)

I used the sample source from DirectShow. It works fine.
Code: Select all
sourceFilter = FindCaptureDevice();

public IBaseFilter FindCaptureDevice()
        {
            int hr = 0;
           
            IEnumMoniker classEnum = null;
            IMoniker[] moniker = new IMoniker[1];

            object source = null;

            // Create the system device enumerator
            ICreateDevEnum devEnum = (ICreateDevEnum)new CreateDevEnum();

            // Create an enumerator for the video capture devices
            hr = devEnum.CreateClassEnumerator(FilterCategory.VideoInputDevice, out classEnum, 0);
            DsError.ThrowExceptionForHR(hr);

            // The device enumerator is no more needed
            Marshal.ReleaseComObject(devEnum);

            if (classEnum == null)
            {
                throw new ApplicationException("No video capture device was detected.\r\n\r\n" +
                                               "This sample requires a video capture device, such as a USB WebCam,\r\n" +
                                               "to be installed and working properly.  The sample will now close.");
            }
            if (classEnum.Next(moniker.Length, moniker, IntPtr.Zero) == 0)
            {
                // Bind Moniker to a filter object
                Guid iid = typeof(IBaseFilter).GUID;
                moniker[0].BindToObject(null, null, ref iid, out source);
            }
            else
            {
                throw new ApplicationException("Unable to access video capture device!");
            }

            // Release COM objects
            Marshal.ReleaseComObject(moniker[0]);
            Marshal.ReleaseComObject(classEnum);

            // An exception is thrown if cast fail
            return (IBaseFilter)source;
        }


I found that IAMVideoProcAmp should be used to adjust brightness and hue, and I wanted to apply it.
But here, IAMVideoProcAmp returns null.

Code: Select all
//IAMVideoProcAmp pVideoAmp = (IAMVideoProcAmp)sourceFilter;
                //VideoProcAmpFlags vpaFlags;
                //pVideoAmp.Get(VideoProcAmpProperty.Brightness, out int iTest, out vpaFlags);
                //Console.WriteLine(iTest);
                videoProcAmp = sourceFilter as IAMVideoProcAmp;
                if (videoProcAmp == null)
                {
                    Console.WriteLine("Color control not supported on this device.");
                }


What I want to do is adjust the brightness and color (the respective values of RGB) of the screen displayed via the DeckLink captureboard.
I've been looking for a way to do this for a few days now, but I'm stuck.
Am I missing something?
Offline

BAEK TS

  • Posts: 3
  • Joined: Wed Apr 03, 2024 2:29 am
  • Real Name: BAEK TAE SEONG

Re: I want to adjust the color and brightness of the Frame.

PostMon Apr 08, 2024 12:01 am

Using OpenCV was the solution. Thanks.

Return to Software Developers

Who is online

Users browsing this forum: No registered users and 5 guests