Class ColorspaceConverter
- Namespace
- VisioForge.Core.Helpers
- Assembly
- VisioForge.Core.dll
Provides methods for converting between different color space formats such as RGB, RGBA, ARGB, BGRA, YUV, and others. Supports hardware-accelerated conversions using Intel IPP when available on Windows platforms.
public static class ColorspaceConverterInheritance
Inherited Members
Methods
ARGBToBGRA(nint, int, nint, int, int, int, BaseContext?)
Converts image data from ARGB format (Alpha, Red, Green, Blue) to BGRA format (Blue, Green, Red, Alpha).
public static void ARGBToBGRA(nint inputPtr, int inputStride, nint outputPtr, int outputStride, int width, int height, BaseContext? context = null)Parameters
inputPtrnint-
Pointer to the source ARGB image data.
inputStrideint-
The number of bytes per row in the source image (including padding).
outputPtrnint-
Pointer to the destination buffer for BGRA image data.
outputStrideint-
The number of bytes per row in the destination image (including padding).
widthint-
The width of the image in pixels.
heightint-
The height of the image in pixels.
contextBaseContext?-
Optional context for error logging and diagnostics.
ARGBToRGB(nint, int, nint, int, int, int, BaseContext?)
Converts ARGB image data (4 bytes per pixel) to RGB format (3 bytes per pixel), discarding the alpha channel.
public static void ARGBToRGB(nint inputPtr, int inputStride, nint outputPtr, int outputStride, int width, int height, BaseContext? context = null)Parameters
inputPtrnint-
Pointer to the source ARGB image data.
inputStrideint-
The number of bytes per row in the source image (including padding).
outputPtrnint-
Pointer to the destination buffer for RGB image data.
outputStrideint-
The number of bytes per row in the destination image (including padding).
widthint-
The width of the image in pixels.
heightint-
The height of the image in pixels.
contextBaseContext?-
Optional context for error logging and diagnostics.
BGR24ToBGRA(nint, nint, int, int, byte)
Converts BGR24 format (3 bytes per pixel) to BGRA format (4 bytes per pixel) with specified alpha value.
public static void BGR24ToBGRA(nint srcPixels, nint dstPixels, int width, int height, byte alpha)Parameters
srcPixelsnint-
Pointer to the source BGR24 image data.
dstPixelsnint-
Pointer to the destination buffer for BGRA image data.
widthint-
The width of the image in pixels.
heightint-
The height of the image in pixels.
alphabyte-
The alpha value (0-255) to apply to all pixels.
BGRAToARGB(nint, int, nint, int, int, int, BaseContext?)
Converts image data from BGRA format (Blue, Green, Red, Alpha) to ARGB format (Alpha, Red, Green, Blue).
public static void BGRAToARGB(nint inputPtr, int inputStride, nint outputPtr, int outputStride, int width, int height, BaseContext? context = null)Parameters
inputPtrnint-
Pointer to the source BGRA image data.
inputStrideint-
The number of bytes per row in the source image (including padding).
outputPtrnint-
Pointer to the destination buffer for ARGB image data.
outputStrideint-
The number of bytes per row in the destination image (including padding).
widthint-
The width of the image in pixels.
heightint-
The height of the image in pixels.
contextBaseContext?-
Optional context for error logging and diagnostics.
BGRToBGRA(nint, int, nint, int, int, int, BaseContext?)
Converts BGR image data (3 bytes per pixel) to BGRA format (4 bytes per pixel) with full opacity (alpha = 255).
public static void BGRToBGRA(nint inputPtr, int inputStride, nint outputPtr, int outputStride, int width, int height, BaseContext? context = null)Parameters
inputPtrnint-
Pointer to the source BGR image data.
inputStrideint-
The number of bytes per row in the source image (including padding).
outputPtrnint-
Pointer to the destination buffer for BGRA image data.
outputStrideint-
The number of bytes per row in the destination image (including padding).
widthint-
The width of the image in pixels.
heightint-
The height of the image in pixels.
contextBaseContext?-
Optional context for error logging and diagnostics.
BGRToRGBA(nint, int, nint, int, int, int, BaseContext?)
Converts BGR image data (3 bytes per pixel) to RGBA format (4 bytes per pixel) with full opacity (alpha = 255). Swaps red and blue channels during conversion.
public static void BGRToRGBA(nint inputPtr, int inputStride, nint outputPtr, int outputStride, int width, int height, BaseContext? context = null)Parameters
inputPtrnint-
Pointer to the source BGR image data.
inputStrideint-
The number of bytes per row in the source image (including padding).
outputPtrnint-
Pointer to the destination buffer for RGBA image data.
outputStrideint-
The number of bytes per row in the destination image (including padding).
widthint-
The width of the image in pixels.
heightint-
The height of the image in pixels.
contextBaseContext?-
Optional context for error logging and diagnostics.
NV12ToRGBSlow(nint, int, int, int, nint, int)
Converts NV12 YUV format to RGB format using software conversion (slower than hardware-accelerated methods). NV12 format stores Y plane followed by interleaved UV plane.
public static void NV12ToRGBSlow(nint nv12Data, int stride, int width, int height, nint rgbData, int rgbStride)Parameters
nv12Datanint-
Pointer to the source NV12 data containing Y plane and UV plane.
strideint-
The stride of the NV12 data (bytes per row).
widthint-
The width of the image in pixels.
heightint-
The height of the image in pixels.
rgbDatanint-
Pointer to the destination buffer for RGB data.
rgbStrideint-
The stride of the RGB data (bytes per row).
RGB24ToBGR24(nint, nint, int, int, int)
Converts RGB24 format to BGR24 format by swapping the red and blue channels.
public static void RGB24ToBGR24(nint srcPixels, nint dstPixels, int width, int height, int stride)Parameters
srcPixelsnint-
Pointer to the source RGB24 image data.
dstPixelsnint-
Pointer to the destination buffer for BGR24 image data.
widthint-
The width of the image in pixels.
heightint-
The height of the image in pixels.
strideint-
The number of bytes per row in both source and destination images (including padding).
RGB24ToRGB32(nint, nint, int, int)
Converts RGB24 format (3 bytes per pixel) to RGB32 format (4 bytes per pixel with unused alpha byte).
public static void RGB24ToRGB32(nint srcPixels, nint dstPixels, int width, int height)Parameters
srcPixelsnint-
Pointer to the source RGB24 image data.
dstPixelsnint-
Pointer to the destination buffer for RGB32 image data.
widthint-
The width of the image in pixels.
heightint-
The height of the image in pixels.
RGB24ToRGBA(nint, nint, int, int, byte)
Converts RGB24 format (3 bytes per pixel) to RGBA format (4 bytes per pixel) with specified alpha value.
public static void RGB24ToRGBA(nint srcPixels, nint dstPixels, int width, int height, byte alpha)Parameters
srcPixelsnint-
Pointer to the source RGB24 image data.
dstPixelsnint-
Pointer to the destination buffer for RGBA image data.
widthint-
The width of the image in pixels.
heightint-
The height of the image in pixels.
alphabyte-
The alpha value (0-255) to apply to all pixels.
RGB24ToUYVY_HDYC(nint, nint, int, int, int, int)
Converts RGB24 format to UYVY (also known as HDYC) format. UYVY is a YUV 4:2:2 format that stores two pixels in 4 bytes as U Y0 V Y1 pattern.
public static void RGB24ToUYVY_HDYC(nint pSource, nint pDest, int width, int height, int srcStride, int destStride)Parameters
pSourcenint-
Pointer to the source RGB24 image data.
pDestnint-
Pointer to the destination buffer for UYVY image data.
widthint-
The width of the image in pixels.
heightint-
The height of the image in pixels.
srcStrideint-
The number of bytes per row in the source image (including padding).
destStrideint-
The number of bytes per row in the destination image (including padding).
RGB24ToYUY2(nint, nint, int, int, int, int)
Converts RGB24 format to YUY2 (YUV 4:2:2) format. YUY2 stores two pixels in 4 bytes as Y0 U Y1 V pattern.
public static void RGB24ToYUY2(nint srcPixels, nint dstPixels, int width, int height, int srcStride, int dstStride)Parameters
srcPixelsnint-
Pointer to the source RGB24 image data.
dstPixelsnint-
Pointer to the destination buffer for YUY2 image data.
widthint-
The width of the image in pixels.
heightint-
The height of the image in pixels.
srcStrideint-
The number of bytes per row in the source image (including padding).
dstStrideint-
The number of bytes per row in the destination image (including padding).
RGB24ToYV12(nint, nint, int, int, int)
Converts RGB24 format to YV12 (YUV 4:2:0 planar) format. YV12 stores Y plane followed by V and U planes at quarter resolution.
public static void RGB24ToYV12(nint srcPixels, nint dstPixels, int width, int height, int srcStride)Parameters
srcPixelsnint-
Pointer to the source RGB24 image data.
dstPixelsnint-
Pointer to the destination buffer for YV12 image data.
widthint-
The width of the image in pixels.
heightint-
The height of the image in pixels.
srcStrideint-
The number of bytes per row in the source image (including padding).
RGB32ToRGB24(nint, nint, int, int)
Converts RGB32 format (4 bytes per pixel with unused alpha) to RGB24 format (3 bytes per pixel).
public static void RGB32ToRGB24(nint srcPixels, nint dstPixels, int width, int height)Parameters
srcPixelsnint-
Pointer to the source RGB32 image data.
dstPixelsnint-
Pointer to the destination buffer for RGB24 image data.
widthint-
The width of the image in pixels.
heightint-
The height of the image in pixels.
RGB32ToUYVY_HDYC(nint, nint, int, int, int, int)
Converts RGB32 format to UYVY (also known as HDYC) format. UYVY is a YUV 4:2:2 format that stores two pixels in 4 bytes as U Y0 V Y1 pattern.
public static void RGB32ToUYVY_HDYC(nint pSource, nint pDest, int width, int height, int srcStride, int destStride)Parameters
pSourcenint-
Pointer to the source RGB32 image data.
pDestnint-
Pointer to the destination buffer for UYVY image data.
widthint-
The width of the image in pixels.
heightint-
The height of the image in pixels.
srcStrideint-
The number of bytes per row in the source image (including padding).
destStrideint-
The number of bytes per row in the destination image (including padding).
RGB32ToYUY2(nint, nint, int, int, int, int)
Converts RGB32 format to YUY2 (YUV 4:2:2) format. YUY2 stores two pixels in 4 bytes as Y0 U Y1 V pattern.
public static void RGB32ToYUY2(nint pSource, nint pDest, int width, int height, int srcStride, int destStride)Parameters
pSourcenint-
Pointer to the source RGB32 image data.
pDestnint-
Pointer to the destination buffer for YUY2 image data.
widthint-
The width of the image in pixels.
heightint-
The height of the image in pixels.
srcStrideint-
The number of bytes per row in the source image (including padding).
destStrideint-
The number of bytes per row in the destination image (including padding).
RGBAToARGB(nint, int, nint, int, int, int, BaseContext?)
Converts image data from RGBA format (Red, Green, Blue, Alpha) to ARGB format (Alpha, Red, Green, Blue).
public static void RGBAToARGB(nint inputPtr, int inputStride, nint outputPtr, int outputStride, int width, int height, BaseContext? context = null)Parameters
inputPtrnint-
Pointer to the source RGBA image data.
inputStrideint-
The number of bytes per row in the source image (including padding).
outputPtrnint-
Pointer to the destination buffer for ARGB image data.
outputStrideint-
The number of bytes per row in the destination image (including padding).
widthint-
The width of the image in pixels.
heightint-
The height of the image in pixels.
contextBaseContext?-
Optional context for error logging and diagnostics.
RGBAToBGRA(nint, int, nint, int, int, int, BaseContext?)
Converts image data from RGBA format (Red, Green, Blue, Alpha) to BGRA format (Blue, Green, Red, Alpha).
public static void RGBAToBGRA(nint inputPtr, int inputStride, nint outputPtr, int outputStride, int width, int height, BaseContext? context = null)Parameters
inputPtrnint-
Pointer to the source RGBA image data.
inputStrideint-
The number of bytes per row in the source image (including padding).
outputPtrnint-
Pointer to the destination buffer for BGRA image data.
outputStrideint-
The number of bytes per row in the destination image (including padding).
widthint-
The width of the image in pixels.
heightint-
The height of the image in pixels.
contextBaseContext?-
Optional context for error logging and diagnostics.
RGBAToCairo32(byte[], double)
Converts RGBA image data to Cairo32 format with pre-multiplied alpha. Cairo32 format stores pixels in pre-multiplied BGRA order for efficient rendering.
public static byte[] RGBAToCairo32(byte[] data, double alpha)Parameters
databyte[]-
The source RGBA image data as a byte array.
alphadouble-
Additional alpha multiplier (0.0 to 1.0) to apply to all pixels.
Returns
- byte[]
-
A new byte array containing the converted Cairo32 format data.
RGBAToCairo32Ptr(byte[], double)
Converts RGBA image data to Cairo32 format and returns a pointer to the converted data. The caller is responsible for freeing the allocated memory using Marshal.FreeHGlobal.
public static nint RGBAToCairo32Ptr(byte[] data, double alpha)Parameters
databyte[]-
The source RGBA image data as a byte array.
alphadouble-
Additional alpha multiplier (0.0 to 1.0) to apply to all pixels.
Returns
- nint
-
A pointer to the newly allocated Cairo32 format data. Must be freed by the caller.
RGBToARGB(nint, int, nint, int, int, int, BaseContext?)
Converts RGB image data (3 bytes per pixel) to ARGB format (4 bytes per pixel) with full opacity (alpha = 255).
public static void RGBToARGB(nint inputPtr, int inputStride, nint outputPtr, int outputStride, int width, int height, BaseContext? context = null)Parameters
inputPtrnint-
Pointer to the source RGB image data.
inputStrideint-
The number of bytes per row in the source image (including padding).
outputPtrnint-
Pointer to the destination buffer for ARGB image data.
outputStrideint-
The number of bytes per row in the destination image (including padding).
widthint-
The width of the image in pixels.
heightint-
The height of the image in pixels.
contextBaseContext?-
Optional context for error logging and diagnostics.
RGBToBGRA(nint, int, nint, int, int, int, BaseContext?)
Converts RGB image data (3 bytes per pixel) to BGRA format (4 bytes per pixel) with full opacity (alpha = 255). Swaps red and blue channels during conversion.
public static void RGBToBGRA(nint inputPtr, int inputStride, nint outputPtr, int outputStride, int width, int height, BaseContext? context = null)Parameters
inputPtrnint-
Pointer to the source RGB image data.
inputStrideint-
The number of bytes per row in the source image (including padding).
outputPtrnint-
Pointer to the destination buffer for BGRA image data.
outputStrideint-
The number of bytes per row in the destination image (including padding).
widthint-
The width of the image in pixels.
heightint-
The height of the image in pixels.
contextBaseContext?-
Optional context for error logging and diagnostics.
RGBToRGBA(byte[], nint, int, int, int, BaseContext?)
Converts RGB image data (3 bytes per pixel) to RGBA format (4 bytes per pixel) with full opacity. This overload accepts input data as a byte array.
public static void RGBToRGBA(byte[] inputData, nint outputPtr, int outputStride, int width, int height, BaseContext? context = null)Parameters
inputDatabyte[]-
The source RGB image data as a byte array.
outputPtrnint-
Pointer to the destination buffer for RGBA image data.
outputStrideint-
The number of bytes per row in the destination image (including padding).
widthint-
The width of the image in pixels.
heightint-
The height of the image in pixels.
contextBaseContext?-
Optional context for error logging and diagnostics.
RGBToRGBA(nint, int, nint, int, int, int, BaseContext?)
Converts RGB image data (3 bytes per pixel) to RGBA format (4 bytes per pixel) with full opacity (alpha = 255).
public static void RGBToRGBA(nint inputPtr, int inputStride, nint outputPtr, int outputStride, int width, int height, BaseContext? context = null)Parameters
inputPtrnint-
Pointer to the source RGB image data.
inputStrideint-
The number of bytes per row in the source image (including padding).
outputPtrnint-
Pointer to the destination buffer for RGBA image data.
outputStrideint-
The number of bytes per row in the destination image (including padding).
widthint-
The width of the image in pixels.
heightint-
The height of the image in pixels.
contextBaseContext?-
Optional context for error logging and diagnostics.
YUY2ToRGB24(nint, nint, int, int)
Converts YUY2 (YUV 4:2:2) format to RGB24 format. YUY2 stores two pixels in 4 bytes as Y0 U Y1 V pattern.
public static void YUY2ToRGB24(nint srcPixels, nint dstPixels, int width, int height)Parameters
srcPixelsnint-
Pointer to the source YUY2 image data.
dstPixelsnint-
Pointer to the destination buffer for RGB24 image data.
widthint-
The width of the image in pixels.
heightint-
The height of the image in pixels.
YV12ToRGB24(nint, nint, int, int)
Converts YV12 (YUV 4:2:0 planar) format to RGB24 format. YV12 stores Y plane followed by V and U planes at quarter resolution.
public static void YV12ToRGB24(nint srcPixels, nint dstPixels, int width, int height)