Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
yushulx committed Jan 13, 2025
1 parent 42091aa commit f8a5507
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 88 deletions.
44 changes: 0 additions & 44 deletions litecam/dist/include/Camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,50 +43,6 @@ struct Buffer
};
#endif

unsigned char clamp(double value, double min, double max)
{
if (value < min)
return static_cast<unsigned char>(min);
if (value > max)
return static_cast<unsigned char>(max);
return static_cast<unsigned char>(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
{
Expand Down
Binary file modified litecam/dist/lib/linux/liblitecam.so
Binary file not shown.
Binary file modified litecam/dist/lib/windows/debug/litecam.dll
Binary file not shown.
Binary file modified litecam/dist/lib/windows/release/litecam.dll
Binary file not shown.
44 changes: 0 additions & 44 deletions litecam/include/Camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,50 +43,6 @@ struct Buffer
};
#endif

unsigned char clamp(double value, double min, double max)
{
if (value < min)
return static_cast<unsigned char>(min);
if (value > max)
return static_cast<unsigned char>(max);
return static_cast<unsigned char>(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
{
Expand Down
44 changes: 44 additions & 0 deletions litecam/src/CameraLinux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,50 @@
#include <map>
#include <cstring>

unsigned char clamp(double value, double min, double max)
{
if (value < min)
return static_cast<unsigned char>(min);
if (value > max)
return static_cast<unsigned char>(max);
return static_cast<unsigned char>(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);
Expand Down
44 changes: 44 additions & 0 deletions litecam/src/CameraWindows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,50 @@

using Microsoft::WRL::ComPtr;

unsigned char clamp(double value, double min, double max)
{
if (value < min)
return static_cast<unsigned char>(min);
if (value > max)
return static_cast<unsigned char>(max);
return static_cast<unsigned char>(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
Expand Down

0 comments on commit f8a5507

Please sign in to comment.