diff --git a/litecam/dist/include/Camera.h b/litecam/dist/include/Camera.h index bb1329a..30214c3 100644 --- a/litecam/dist/include/Camera.h +++ b/litecam/dist/include/Camera.h @@ -43,50 +43,6 @@ struct Buffer }; #endif -unsigned char clamp(double value, double min, double max) -{ - if (value < min) - return static_cast(min); - if (value > max) - return static_cast(max); - return static_cast(value); -} - -void ConvertYUY2ToRGB(const unsigned char *yuy2Data, unsigned char *rgbData, int width, int height) -{ - int rgbIndex = 0; - for (int i = 0; i < width * height * 2; i += 4) - { - // Extract YUV values - unsigned char y1 = yuy2Data[i]; - unsigned char u = yuy2Data[i + 1]; - unsigned char y2 = yuy2Data[i + 2]; - unsigned char v = yuy2Data[i + 3]; - -#ifdef _WIN32 - // Convert first pixel (Y1, U, V) to RGB - rgbData[rgbIndex++] = clamp(y1 + 1.772 * (u - 128), 0.0, 255.0); - rgbData[rgbIndex++] = clamp(y1 - 0.344136 * (u - 128) - 0.714136 * (v - 128), 0.0, 255.0); - rgbData[rgbIndex++] = clamp(y1 + 1.402 * (v - 128), 0.0, 255.0); - - // Convert second pixel (Y2, U, V) to RGB - rgbData[rgbIndex++] = clamp(y2 + 1.772 * (u - 128), 0.0, 255.0); - rgbData[rgbIndex++] = clamp(y2 - 0.344136 * (u - 128) - 0.714136 * (v - 128), 0.0, 255.0); - rgbData[rgbIndex++] = clamp(y2 + 1.402 * (v - 128), 0.0, 255.0); -#else - // Convert first pixel (Y1, U, V) to RGB - rgbData[rgbIndex++] = clamp(y1 + 1.402 * (v - 128), 0.0, 255.0); - rgbData[rgbIndex++] = clamp(y1 - 0.344136 * (u - 128) - 0.714136 * (v - 128), 0.0, 255.0); - rgbData[rgbIndex++] = clamp(y1 + 1.772 * (u - 128), 0.0, 255.0); - - // Convert second pixel (Y2, U, V) to RGB - rgbData[rgbIndex++] = clamp(y2 + 1.402 * (v - 128), 0.0, 255.0); - rgbData[rgbIndex++] = clamp(y2 - 0.344136 * (u - 128) - 0.714136 * (v - 128), 0.0, 255.0); - rgbData[rgbIndex++] = clamp(y2 + 1.772 * (u - 128), 0.0, 255.0); -#endif - } -} - // Struct definitions struct CAMERA_API FrameData { diff --git a/litecam/dist/lib/linux/liblitecam.so b/litecam/dist/lib/linux/liblitecam.so index eb8b23c..e3aa126 100644 Binary files a/litecam/dist/lib/linux/liblitecam.so and b/litecam/dist/lib/linux/liblitecam.so differ diff --git a/litecam/dist/lib/windows/debug/litecam.dll b/litecam/dist/lib/windows/debug/litecam.dll index 7ee7ee0..b0fd641 100644 Binary files a/litecam/dist/lib/windows/debug/litecam.dll and b/litecam/dist/lib/windows/debug/litecam.dll differ diff --git a/litecam/dist/lib/windows/release/litecam.dll b/litecam/dist/lib/windows/release/litecam.dll index 1ef968c..dc56015 100644 Binary files a/litecam/dist/lib/windows/release/litecam.dll and b/litecam/dist/lib/windows/release/litecam.dll differ diff --git a/litecam/include/Camera.h b/litecam/include/Camera.h index bb1329a..30214c3 100644 --- a/litecam/include/Camera.h +++ b/litecam/include/Camera.h @@ -43,50 +43,6 @@ struct Buffer }; #endif -unsigned char clamp(double value, double min, double max) -{ - if (value < min) - return static_cast(min); - if (value > max) - return static_cast(max); - return static_cast(value); -} - -void ConvertYUY2ToRGB(const unsigned char *yuy2Data, unsigned char *rgbData, int width, int height) -{ - int rgbIndex = 0; - for (int i = 0; i < width * height * 2; i += 4) - { - // Extract YUV values - unsigned char y1 = yuy2Data[i]; - unsigned char u = yuy2Data[i + 1]; - unsigned char y2 = yuy2Data[i + 2]; - unsigned char v = yuy2Data[i + 3]; - -#ifdef _WIN32 - // Convert first pixel (Y1, U, V) to RGB - rgbData[rgbIndex++] = clamp(y1 + 1.772 * (u - 128), 0.0, 255.0); - rgbData[rgbIndex++] = clamp(y1 - 0.344136 * (u - 128) - 0.714136 * (v - 128), 0.0, 255.0); - rgbData[rgbIndex++] = clamp(y1 + 1.402 * (v - 128), 0.0, 255.0); - - // Convert second pixel (Y2, U, V) to RGB - rgbData[rgbIndex++] = clamp(y2 + 1.772 * (u - 128), 0.0, 255.0); - rgbData[rgbIndex++] = clamp(y2 - 0.344136 * (u - 128) - 0.714136 * (v - 128), 0.0, 255.0); - rgbData[rgbIndex++] = clamp(y2 + 1.402 * (v - 128), 0.0, 255.0); -#else - // Convert first pixel (Y1, U, V) to RGB - rgbData[rgbIndex++] = clamp(y1 + 1.402 * (v - 128), 0.0, 255.0); - rgbData[rgbIndex++] = clamp(y1 - 0.344136 * (u - 128) - 0.714136 * (v - 128), 0.0, 255.0); - rgbData[rgbIndex++] = clamp(y1 + 1.772 * (u - 128), 0.0, 255.0); - - // Convert second pixel (Y2, U, V) to RGB - rgbData[rgbIndex++] = clamp(y2 + 1.402 * (v - 128), 0.0, 255.0); - rgbData[rgbIndex++] = clamp(y2 - 0.344136 * (u - 128) - 0.714136 * (v - 128), 0.0, 255.0); - rgbData[rgbIndex++] = clamp(y2 + 1.772 * (u - 128), 0.0, 255.0); -#endif - } -} - // Struct definitions struct CAMERA_API FrameData { diff --git a/litecam/src/CameraLinux.cpp b/litecam/src/CameraLinux.cpp index 545bb5a..842dd8a 100644 --- a/litecam/src/CameraLinux.cpp +++ b/litecam/src/CameraLinux.cpp @@ -5,6 +5,50 @@ #include #include +unsigned char clamp(double value, double min, double max) +{ + if (value < min) + return static_cast(min); + if (value > max) + return static_cast(max); + return static_cast(value); +} + +void ConvertYUY2ToRGB(const unsigned char *yuy2Data, unsigned char *rgbData, int width, int height) +{ + int rgbIndex = 0; + for (int i = 0; i < width * height * 2; i += 4) + { + // Extract YUV values + unsigned char y1 = yuy2Data[i]; + unsigned char u = yuy2Data[i + 1]; + unsigned char y2 = yuy2Data[i + 2]; + unsigned char v = yuy2Data[i + 3]; + +#ifdef _WIN32 + // Convert first pixel (Y1, U, V) to RGB + rgbData[rgbIndex++] = clamp(y1 + 1.772 * (u - 128), 0.0, 255.0); + rgbData[rgbIndex++] = clamp(y1 - 0.344136 * (u - 128) - 0.714136 * (v - 128), 0.0, 255.0); + rgbData[rgbIndex++] = clamp(y1 + 1.402 * (v - 128), 0.0, 255.0); + + // Convert second pixel (Y2, U, V) to RGB + rgbData[rgbIndex++] = clamp(y2 + 1.772 * (u - 128), 0.0, 255.0); + rgbData[rgbIndex++] = clamp(y2 - 0.344136 * (u - 128) - 0.714136 * (v - 128), 0.0, 255.0); + rgbData[rgbIndex++] = clamp(y2 + 1.402 * (v - 128), 0.0, 255.0); +#else + // Convert first pixel (Y1, U, V) to RGB + rgbData[rgbIndex++] = clamp(y1 + 1.402 * (v - 128), 0.0, 255.0); + rgbData[rgbIndex++] = clamp(y1 - 0.344136 * (u - 128) - 0.714136 * (v - 128), 0.0, 255.0); + rgbData[rgbIndex++] = clamp(y1 + 1.772 * (u - 128), 0.0, 255.0); + + // Convert second pixel (Y2, U, V) to RGB + rgbData[rgbIndex++] = clamp(y2 + 1.402 * (v - 128), 0.0, 255.0); + rgbData[rgbIndex++] = clamp(y2 - 0.344136 * (u - 128) - 0.714136 * (v - 128), 0.0, 255.0); + rgbData[rgbIndex++] = clamp(y2 + 1.772 * (u - 128), 0.0, 255.0); +#endif + } +} + bool Camera::Open(int cameraIndex) { std::string devicePath = "/dev/video" + std::to_string(cameraIndex); diff --git a/litecam/src/CameraWindows.cpp b/litecam/src/CameraWindows.cpp index c0ebb18..1967124 100644 --- a/litecam/src/CameraWindows.cpp +++ b/litecam/src/CameraWindows.cpp @@ -12,6 +12,50 @@ using Microsoft::WRL::ComPtr; +unsigned char clamp(double value, double min, double max) +{ + if (value < min) + return static_cast(min); + if (value > max) + return static_cast(max); + return static_cast(value); +} + +void ConvertYUY2ToRGB(const unsigned char *yuy2Data, unsigned char *rgbData, int width, int height) +{ + int rgbIndex = 0; + for (int i = 0; i < width * height * 2; i += 4) + { + // Extract YUV values + unsigned char y1 = yuy2Data[i]; + unsigned char u = yuy2Data[i + 1]; + unsigned char y2 = yuy2Data[i + 2]; + unsigned char v = yuy2Data[i + 3]; + +#ifdef _WIN32 + // Convert first pixel (Y1, U, V) to RGB + rgbData[rgbIndex++] = clamp(y1 + 1.772 * (u - 128), 0.0, 255.0); + rgbData[rgbIndex++] = clamp(y1 - 0.344136 * (u - 128) - 0.714136 * (v - 128), 0.0, 255.0); + rgbData[rgbIndex++] = clamp(y1 + 1.402 * (v - 128), 0.0, 255.0); + + // Convert second pixel (Y2, U, V) to RGB + rgbData[rgbIndex++] = clamp(y2 + 1.772 * (u - 128), 0.0, 255.0); + rgbData[rgbIndex++] = clamp(y2 - 0.344136 * (u - 128) - 0.714136 * (v - 128), 0.0, 255.0); + rgbData[rgbIndex++] = clamp(y2 + 1.402 * (v - 128), 0.0, 255.0); +#else + // Convert first pixel (Y1, U, V) to RGB + rgbData[rgbIndex++] = clamp(y1 + 1.402 * (v - 128), 0.0, 255.0); + rgbData[rgbIndex++] = clamp(y1 - 0.344136 * (u - 128) - 0.714136 * (v - 128), 0.0, 255.0); + rgbData[rgbIndex++] = clamp(y1 + 1.772 * (u - 128), 0.0, 255.0); + + // Convert second pixel (Y2, U, V) to RGB + rgbData[rgbIndex++] = clamp(y2 + 1.402 * (v - 128), 0.0, 255.0); + rgbData[rgbIndex++] = clamp(y2 - 0.344136 * (u - 128) - 0.714136 * (v - 128), 0.0, 255.0); + rgbData[rgbIndex++] = clamp(y2 + 1.772 * (u - 128), 0.0, 255.0); +#endif + } +} + struct GUIDComparator { bool operator()(const GUID &lhs, const GUID &rhs) const