[wpiutil] Rename PixelFormat constants to all caps

This commit is contained in:
Peter Johnson
2026-03-15 22:29:01 -07:00
parent e5107e7e00
commit 9ce9918763
28 changed files with 361 additions and 345 deletions

View File

@@ -13,7 +13,7 @@ class AprilTagGenerationTest {
@Test
void test36h11() {
var frame = AprilTag.generate36h11AprilTagImage(1);
assertEquals(PixelFormat.kGray, frame.getPixelFormat());
assertEquals(PixelFormat.GRAY, frame.getPixelFormat());
assertEquals(10, frame.getWidth());
assertEquals(10, frame.getHeight());
int stride = frame.getStride();

View File

@@ -483,15 +483,15 @@ public final class CameraServer {
/** Provide string description of pixel format. */
private static String pixelFormatToString(PixelFormat pixelFormat) {
return switch (pixelFormat) {
case kMJPEG -> "MJPEG";
case kYUYV -> "YUYV";
case kRGB565 -> "RGB565";
case kBGR -> "BGR";
case kBGRA -> "BGRA";
case kGray -> "Gray";
case kY16 -> "Y16";
case kUYVY -> "UYVY";
case kUnknown -> "Unknown";
case MJPEG -> "MJPEG";
case YUYV -> "YUYV";
case RGB565 -> "RGB565";
case BGR -> "BGR";
case BGRA -> "BGRA";
case GRAY -> "Gray";
case Y16 -> "Y16";
case UYVY -> "UYVY";
case UNKNOWN -> "Unknown";
};
}
@@ -610,7 +610,7 @@ public final class CameraServer {
*/
public static MjpegServer addSwitchedCamera(String name) {
// create a dummy CvSource
CvSource source = new CvSource(name, PixelFormat.kMJPEG, 160, 120, 30);
CvSource source = new CvSource(name, PixelFormat.MJPEG, 160, 120, 30);
MjpegServer server = startAutomaticCapture(source);
synchronized (CameraServer.class) {
m_fixedSources.put(server.getHandle(), source.getHandle());
@@ -725,7 +725,7 @@ public final class CameraServer {
* @return OpenCV source for the MJPEG stream
*/
public static CvSource putVideo(String name, int width, int height) {
CvSource source = new CvSource(name, PixelFormat.kMJPEG, width, height, 30);
CvSource source = new CvSource(name, PixelFormat.MJPEG, width, height, 30);
startAutomaticCapture(source);
return source;
}

View File

@@ -251,15 +251,15 @@ void Instance::UpdateStreamValues() {
static std::string PixelFormatToString(wpi::util::PixelFormat pixelFormat) {
switch (pixelFormat) {
case wpi::util::PixelFormat::kMJPEG:
case wpi::util::PixelFormat::MJPEG:
return "MJPEG";
case wpi::util::PixelFormat::kYUYV:
case wpi::util::PixelFormat::YUYV:
return "YUYV";
case wpi::util::PixelFormat::kRGB565:
case wpi::util::PixelFormat::RGB565:
return "RGB565";
case wpi::util::PixelFormat::kBGR:
case wpi::util::PixelFormat::BGR:
return "BGR";
case wpi::util::PixelFormat::kGray:
case wpi::util::PixelFormat::GRAY:
return "Gray";
default:
return "Unknown";
@@ -508,7 +508,7 @@ cs::UsbCamera CameraServer::StartAutomaticCapture(std::string_view name,
cs::MjpegServer CameraServer::AddSwitchedCamera(std::string_view name) {
auto& inst = ::GetInstance();
// create a dummy CvSource
cs::CvSource source{name, wpi::util::PixelFormat::kMJPEG, 160, 120, 30};
cs::CvSource source{name, wpi::util::PixelFormat::MJPEG, 160, 120, 30};
cs::MjpegServer server = StartAutomaticCapture(source);
inst.m_fixedSources[server.GetHandle()] = source.GetHandle();
@@ -632,7 +632,7 @@ cs::CvSink CameraServer::GetVideo(std::string_view name,
cs::CvSource CameraServer::PutVideo(std::string_view name, int width,
int height) {
::GetInstance();
cs::CvSource source{name, wpi::util::PixelFormat::kMJPEG, width, height, 30};
cs::CvSource source{name, wpi::util::PixelFormat::MJPEG, width, height, 30};
StartAutomaticCapture(source);
return source;
}

View File

@@ -57,13 +57,13 @@ int main() {
for (const auto& mode : camera.EnumerateVideoModes()) {
const char* pixelFormat;
switch (mode.pixelFormat) {
case wpi::util::PixelFormat::kMJPEG:
case wpi::util::PixelFormat::MJPEG:
pixelFormat = "MJPEG";
break;
case wpi::util::PixelFormat::kYUYV:
case wpi::util::PixelFormat::YUYV:
pixelFormat = "YUYV";
break;
case wpi::util::PixelFormat::kRGB565:
case wpi::util::PixelFormat::RGB565:
pixelFormat = "RGB565";
break;
default:

View File

@@ -14,10 +14,10 @@
int main() {
wpi::cs::HttpCamera camera{"httpcam", "http://localhost:8081/?action=stream"};
camera.SetVideoMode(wpi::util::PixelFormat::kMJPEG, 320, 240, 30);
camera.SetVideoMode(wpi::util::PixelFormat::MJPEG, 320, 240, 30);
wpi::cs::CvSink cvsink{"cvsink"};
cvsink.SetSource(camera);
wpi::cs::CvSource cvsource{"cvsource", wpi::util::PixelFormat::kMJPEG, 320,
wpi::cs::CvSource cvsource{"cvsource", wpi::util::PixelFormat::MJPEG, 320,
240, 30};
wpi::cs::MjpegServer cvMjpegServer{"cvhttpserver", 8083};
cvMjpegServer.SetSource(cvsource);

View File

@@ -12,12 +12,12 @@
int main() {
wpi::cs::UsbCamera camera{"usbcam", 0};
camera.SetVideoMode(wpi::util::PixelFormat::kMJPEG, 320, 240, 30);
camera.SetVideoMode(wpi::util::PixelFormat::MJPEG, 320, 240, 30);
wpi::cs::MjpegServer mjpegServer{"httpserver", 8081};
mjpegServer.SetSource(camera);
wpi::cs::CvSink cvsink{"cvsink"};
cvsink.SetSource(camera);
wpi::cs::CvSource cvsource{"cvsource", wpi::util::PixelFormat::kMJPEG, 320,
wpi::cs::CvSource cvsource{"cvsource", wpi::util::PixelFormat::MJPEG, 320,
240, 30};
wpi::cs::MjpegServer cvMjpegServer{"cvhttpserver", 8082};
cvMjpegServer.SetSource(cvsource);

View File

@@ -17,7 +17,7 @@ int main() {
wpi::util::print(" {}\n", addr);
}
wpi::cs::UsbCamera camera{"usbcam", 0};
camera.SetVideoMode(wpi::util::PixelFormat::kMJPEG, 320, 240, 30);
camera.SetVideoMode(wpi::util::PixelFormat::MJPEG, 320, 240, 30);
wpi::cs::MjpegServer mjpegServer{"httpserver", 8081};
mjpegServer.SetSource(camera);

View File

@@ -31,7 +31,7 @@ int main() {
std::atomic<bool> stopCamera{false};
wpi::cs::UsbCamera camera{"usbcam", 0};
camera.SetVideoMode(wpi::util::PixelFormat::kMJPEG, 640, 480, 30);
camera.SetVideoMode(wpi::util::PixelFormat::MJPEG, 640, 480, 30);
wpi::cs::CvSink cvsink{"cvsink"};
cvsink.SetSource(camera);

View File

@@ -34,10 +34,10 @@ public class CvSink extends ImageSink {
private int getCVFormat(PixelFormat pixelFormat) {
return switch (pixelFormat) {
case kYUYV, kRGB565, kY16, kUYVY -> CvType.CV_8UC2;
case kBGR -> CvType.CV_8UC3;
case kBGRA -> CvType.CV_8UC4;
case kGray, kMJPEG, kUnknown -> CvType.CV_8UC1;
case YUYV, RGB565, Y16, UYVY -> CvType.CV_8UC2;
case BGR -> CvType.CV_8UC3;
case BGRA -> CvType.CV_8UC4;
case GRAY, MJPEG, UNKNOWN -> CvType.CV_8UC1;
};
}
@@ -61,7 +61,7 @@ public class CvSink extends ImageSink {
* @param name Source name (arbitrary unique identifier)
*/
public CvSink(String name) {
this(name, PixelFormat.kBGR);
this(name, PixelFormat.BGR);
}
/**

View File

@@ -64,10 +64,10 @@ public class CvSource extends ImageSource {
int channels = finalImage.channels();
PixelFormat format =
switch (channels) {
case 1 -> PixelFormat.kGray; // 1 channel is assumed Grayscale
case 2 -> PixelFormat.kYUYV; // 2 channels is assumed YUYV
case 3 -> PixelFormat.kBGR; // 3 channels is assumed BGR
case 4 -> PixelFormat.kBGRA; // 4 channels is assumed BGRA
case 1 -> PixelFormat.GRAY; // 1 channel is assumed Grayscale
case 2 -> PixelFormat.YUYV; // 2 channels is assumed YUYV
case 3 -> PixelFormat.BGR; // 3 channels is assumed BGR
case 4 -> PixelFormat.BGRA; // 4 channels is assumed BGRA
default ->
throw new VideoException(
"Unable to get pixel format for " + channels + " channels");
@@ -128,42 +128,42 @@ public class CvSource extends ImageSource {
private void verifyFormat(Mat image, PixelFormat pixelFormat) {
int channels = image.channels();
switch (pixelFormat) {
case kBGR:
case BGR:
if (channels == 3) {
return;
}
break;
case kBGRA:
case BGRA:
if (channels == 4) {
return;
}
break;
case kGray:
case GRAY:
if (channels == 1) {
return;
}
break;
case kRGB565:
case RGB565:
if (channels == 2) {
return;
}
break;
case kUYVY:
case UYVY:
if (channels == 2) {
return;
}
break;
case kY16:
case Y16:
if (channels == 2) {
return;
}
break;
case kYUYV:
case YUYV:
if (channels == 2) {
return;
}
break;
case kMJPEG:
case MJPEG:
if (channels == 1) {
return;
}

View File

@@ -94,9 +94,9 @@ Image* Frame::GetNearestImage(int width, int height,
// 2) Same width, height, different (but non-JPEG) pixelFormat (color conv)
// 2a) If we want JPEG output, prefer BGR over other pixel formats
if (pixelFormat == wpi::util::PixelFormat::kMJPEG) {
if (pixelFormat == wpi::util::PixelFormat::MJPEG) {
for (auto i : m_impl->images) {
if (i->Is(width, height, wpi::util::PixelFormat::kBGR)) {
if (i->Is(width, height, wpi::util::PixelFormat::BGR)) {
return i;
}
}
@@ -104,13 +104,13 @@ Image* Frame::GetNearestImage(int width, int height,
for (auto i : m_impl->images) {
if (i->Is(width, height) &&
i->pixelFormat != wpi::util::PixelFormat::kMJPEG) {
i->pixelFormat != wpi::util::PixelFormat::MJPEG) {
return i;
}
}
// 3) Different width, height, same pixelFormat (only if non-JPEG) (resample)
if (pixelFormat != wpi::util::PixelFormat::kMJPEG) {
if (pixelFormat != wpi::util::PixelFormat::MJPEG) {
// 3a) Smallest image at least width/height in size
for (auto i : m_impl->images) {
if (i->IsLarger(width, height) && i->pixelFormat == pixelFormat &&
@@ -138,7 +138,7 @@ Image* Frame::GetNearestImage(int width, int height,
// 4a) Smallest image at least width/height in size
for (auto i : m_impl->images) {
if (i->IsLarger(width, height) &&
i->pixelFormat != wpi::util::PixelFormat::kMJPEG &&
i->pixelFormat != wpi::util::PixelFormat::MJPEG &&
(!found || (i->IsSmaller(*found)))) {
found = i;
}
@@ -149,7 +149,7 @@ Image* Frame::GetNearestImage(int width, int height,
// 4b) Largest image (less than width/height)
for (auto i : m_impl->images) {
if (i->pixelFormat != wpi::util::PixelFormat::kMJPEG &&
if (i->pixelFormat != wpi::util::PixelFormat::MJPEG &&
(!found || (i->IsLarger(*found)))) {
found = i;
}
@@ -161,7 +161,7 @@ Image* Frame::GetNearestImage(int width, int height,
// 5) Same width, height, JPEG pixelFormat (decompression). As there may be
// multiple JPEG images, find the highest quality one.
for (auto i : m_impl->images) {
if (i->Is(width, height, wpi::util::PixelFormat::kMJPEG) &&
if (i->Is(width, height, wpi::util::PixelFormat::MJPEG) &&
(!found || i->jpegQuality > found->jpegQuality)) {
found = i;
// consider one without a quality setting to be the highest quality
@@ -179,7 +179,7 @@ Image* Frame::GetNearestImage(int width, int height,
// 6a) Smallest image at least width/height in size
for (auto i : m_impl->images) {
if (i->IsLarger(width, height) &&
i->pixelFormat == wpi::util::PixelFormat::kMJPEG &&
i->pixelFormat == wpi::util::PixelFormat::MJPEG &&
(!found || (i->IsSmaller(*found)))) {
found = i;
}
@@ -190,7 +190,7 @@ Image* Frame::GetNearestImage(int width, int height,
// 6b) Largest image (less than width/height)
for (auto i : m_impl->images) {
if (i->pixelFormat != wpi::util::PixelFormat::kMJPEG &&
if (i->pixelFormat != wpi::util::PixelFormat::MJPEG &&
(!found || (i->IsLarger(*found)))) {
found = i;
}
@@ -215,171 +215,169 @@ Image* Frame::ConvertImpl(Image* image, wpi::util::PixelFormat pixelFormat,
// anything else with it. Note that if the destination format is JPEG, we
// still need to do this (unless it was already a JPEG, in which case we
// would have returned above).
if (cur->pixelFormat == wpi::util::PixelFormat::kMJPEG) {
if (cur->pixelFormat == wpi::util::PixelFormat::MJPEG) {
cur = ConvertMJPEGToBGR(cur);
if (pixelFormat == wpi::util::PixelFormat::kBGR) {
if (pixelFormat == wpi::util::PixelFormat::BGR) {
return cur;
}
}
// Color convert
switch (pixelFormat) {
case wpi::util::PixelFormat::kRGB565:
case wpi::util::PixelFormat::RGB565:
// If source is YUYV, UYVY, Gray, or Y16, need to convert to BGR first
if (cur->pixelFormat == wpi::util::PixelFormat::kYUYV) {
if (cur->pixelFormat == wpi::util::PixelFormat::YUYV) {
// Check to see if BGR version already exists...
if (Image* newImage = GetExistingImage(cur->width, cur->height,
wpi::util::PixelFormat::kBGR)) {
wpi::util::PixelFormat::BGR)) {
cur = newImage;
} else {
cur = ConvertYUYVToBGR(cur);
}
} else if (cur->pixelFormat == wpi::util::PixelFormat::kUYVY) {
} else if (cur->pixelFormat == wpi::util::PixelFormat::UYVY) {
// Check to see if BGR version already exists...
if (Image* newImage = GetExistingImage(cur->width, cur->height,
wpi::util::PixelFormat::kBGR)) {
wpi::util::PixelFormat::BGR)) {
cur = newImage;
} else {
cur = ConvertUYVYToBGR(cur);
}
} else if (cur->pixelFormat == wpi::util::PixelFormat::kGray) {
} else if (cur->pixelFormat == wpi::util::PixelFormat::GRAY) {
// Check to see if BGR version already exists...
if (Image* newImage = GetExistingImage(cur->width, cur->height,
wpi::util::PixelFormat::kBGR)) {
wpi::util::PixelFormat::BGR)) {
cur = newImage;
} else {
cur = ConvertGrayToBGR(cur);
}
} else if (cur->pixelFormat == wpi::util::PixelFormat::kY16) {
} else if (cur->pixelFormat == wpi::util::PixelFormat::Y16) {
// Check to see if BGR version already exists...
if (Image* newImage = GetExistingImage(cur->width, cur->height,
wpi::util::PixelFormat::kBGR)) {
wpi::util::PixelFormat::BGR)) {
cur = newImage;
} else if (Image* newImage =
GetExistingImage(cur->width, cur->height,
wpi::util::PixelFormat::kGray)) {
} else if (Image* newImage = GetExistingImage(
cur->width, cur->height, wpi::util::PixelFormat::GRAY)) {
cur = ConvertGrayToBGR(newImage);
} else {
cur = ConvertGrayToBGR(ConvertY16ToGray(cur));
}
}
return ConvertBGRToRGB565(cur);
case wpi::util::PixelFormat::kGray:
case wpi::util::PixelFormat::kY16:
case wpi::util::PixelFormat::GRAY:
case wpi::util::PixelFormat::Y16:
// If source is also grayscale, convert directly
if (pixelFormat == wpi::util::PixelFormat::kGray &&
cur->pixelFormat == wpi::util::PixelFormat::kY16) {
if (pixelFormat == wpi::util::PixelFormat::GRAY &&
cur->pixelFormat == wpi::util::PixelFormat::Y16) {
return ConvertY16ToGray(cur);
} else if (pixelFormat == wpi::util::PixelFormat::kY16 &&
cur->pixelFormat == wpi::util::PixelFormat::kGray) {
} else if (pixelFormat == wpi::util::PixelFormat::Y16 &&
cur->pixelFormat == wpi::util::PixelFormat::GRAY) {
return ConvertGrayToY16(cur);
}
// If source is YUYV, UYVY, convert directly to Gray
// If RGB565, need to convert to BGR first
if (cur->pixelFormat == wpi::util::PixelFormat::kYUYV) {
if (cur->pixelFormat == wpi::util::PixelFormat::YUYV) {
cur = ConvertYUYVToGray(cur);
} else if (cur->pixelFormat == wpi::util::PixelFormat::kUYVY) {
} else if (cur->pixelFormat == wpi::util::PixelFormat::UYVY) {
cur = ConvertUYVYToGray(cur);
} else if (cur->pixelFormat == wpi::util::PixelFormat::kRGB565) {
} else if (cur->pixelFormat == wpi::util::PixelFormat::RGB565) {
// Check to see if BGR version already exists...
if (Image* newImage = GetExistingImage(cur->width, cur->height,
wpi::util::PixelFormat::kBGR)) {
wpi::util::PixelFormat::BGR)) {
cur = newImage;
} else {
cur = ConvertRGB565ToBGR(cur);
}
cur = ConvertBGRToGray(cur);
}
if (pixelFormat == wpi::util::PixelFormat::kY16) {
if (pixelFormat == wpi::util::PixelFormat::Y16) {
cur = ConvertGrayToY16(cur);
}
return cur;
case wpi::util::PixelFormat::kBGR:
case wpi::util::PixelFormat::kMJPEG:
if (cur->pixelFormat == wpi::util::PixelFormat::kYUYV) {
case wpi::util::PixelFormat::BGR:
case wpi::util::PixelFormat::MJPEG:
if (cur->pixelFormat == wpi::util::PixelFormat::YUYV) {
cur = ConvertYUYVToBGR(cur);
} else if (cur->pixelFormat == wpi::util::PixelFormat::kUYVY) {
} else if (cur->pixelFormat == wpi::util::PixelFormat::UYVY) {
cur = ConvertUYVYToBGR(cur);
} else if (cur->pixelFormat == wpi::util::PixelFormat::kRGB565) {
} else if (cur->pixelFormat == wpi::util::PixelFormat::RGB565) {
cur = ConvertRGB565ToBGR(cur);
} else if (cur->pixelFormat == wpi::util::PixelFormat::kGray) {
if (pixelFormat == wpi::util::PixelFormat::kBGR) {
} else if (cur->pixelFormat == wpi::util::PixelFormat::GRAY) {
if (pixelFormat == wpi::util::PixelFormat::BGR) {
return ConvertGrayToBGR(cur);
} else {
return ConvertGrayToMJPEG(cur, defaultJpegQuality);
}
} else if (cur->pixelFormat == wpi::util::PixelFormat::kY16) {
} else if (cur->pixelFormat == wpi::util::PixelFormat::Y16) {
// Check to see if Gray version already exists...
if (Image* newImage = GetExistingImage(cur->width, cur->height,
wpi::util::PixelFormat::kGray)) {
wpi::util::PixelFormat::GRAY)) {
cur = newImage;
} else {
cur = ConvertY16ToGray(cur);
}
if (pixelFormat == wpi::util::PixelFormat::kBGR) {
if (pixelFormat == wpi::util::PixelFormat::BGR) {
return ConvertGrayToBGR(cur);
} else {
return ConvertGrayToMJPEG(cur, defaultJpegQuality);
}
}
break;
case wpi::util::PixelFormat::kBGRA:
case wpi::util::PixelFormat::BGRA:
// If source is RGB565, YUYV, UYVY, Gray or Y16, need to convert to BGR
// first
if (cur->pixelFormat == wpi::util::PixelFormat::kRGB565) {
if (cur->pixelFormat == wpi::util::PixelFormat::RGB565) {
// Check to see if BGR version already exists...
if (Image* newImage = GetExistingImage(cur->width, cur->height,
wpi::util::PixelFormat::kBGR)) {
wpi::util::PixelFormat::BGR)) {
cur = newImage;
} else {
cur = ConvertRGB565ToBGR(cur);
}
} else if (cur->pixelFormat == wpi::util::PixelFormat::kYUYV) {
} else if (cur->pixelFormat == wpi::util::PixelFormat::YUYV) {
// Check to see if BGR version already exists...
if (Image* newImage = GetExistingImage(cur->width, cur->height,
wpi::util::PixelFormat::kBGR)) {
wpi::util::PixelFormat::BGR)) {
cur = newImage;
} else {
cur = ConvertYUYVToBGR(cur);
}
} else if (cur->pixelFormat == wpi::util::PixelFormat::kUYVY) {
} else if (cur->pixelFormat == wpi::util::PixelFormat::UYVY) {
// Check to see if BGR version already exists...
if (Image* newImage = GetExistingImage(cur->width, cur->height,
wpi::util::PixelFormat::kBGR)) {
wpi::util::PixelFormat::BGR)) {
cur = newImage;
} else {
cur = ConvertUYVYToBGR(cur);
}
} else if (cur->pixelFormat == wpi::util::PixelFormat::kGray) {
} else if (cur->pixelFormat == wpi::util::PixelFormat::GRAY) {
// Check to see if BGR version already exists...
if (Image* newImage = GetExistingImage(cur->width, cur->height,
wpi::util::PixelFormat::kBGR)) {
wpi::util::PixelFormat::BGR)) {
cur = newImage;
} else {
cur = ConvertGrayToBGR(cur);
}
} else if (cur->pixelFormat == wpi::util::PixelFormat::kY16) {
} else if (cur->pixelFormat == wpi::util::PixelFormat::Y16) {
// Check to see if BGR version already exists...
if (Image* newImage = GetExistingImage(cur->width, cur->height,
wpi::util::PixelFormat::kBGR)) {
wpi::util::PixelFormat::BGR)) {
cur = newImage;
} else if (Image* newImage =
GetExistingImage(cur->width, cur->height,
wpi::util::PixelFormat::kGray)) {
} else if (Image* newImage = GetExistingImage(
cur->width, cur->height, wpi::util::PixelFormat::GRAY)) {
cur = ConvertGrayToBGR(newImage);
} else {
cur = ConvertGrayToBGR(ConvertY16ToGray(cur));
}
}
return ConvertBGRToBGRA(cur);
case wpi::util::PixelFormat::kYUYV:
case wpi::util::PixelFormat::kUYVY:
case wpi::util::PixelFormat::YUYV:
case wpi::util::PixelFormat::UYVY:
default:
return nullptr; // Unsupported
}
// Compress if destination is JPEG
if (pixelFormat == wpi::util::PixelFormat::kMJPEG) {
if (pixelFormat == wpi::util::PixelFormat::MJPEG) {
cur = ConvertBGRToMJPEG(cur, defaultJpegQuality);
}
@@ -387,12 +385,12 @@ Image* Frame::ConvertImpl(Image* image, wpi::util::PixelFormat pixelFormat,
}
Image* Frame::ConvertMJPEGToBGR(Image* image) {
if (!image || image->pixelFormat != wpi::util::PixelFormat::kMJPEG) {
if (!image || image->pixelFormat != wpi::util::PixelFormat::MJPEG) {
return nullptr;
}
// Allocate an BGR image
auto newImage = m_impl->source.AllocImage(wpi::util::PixelFormat::kBGR,
auto newImage = m_impl->source.AllocImage(wpi::util::PixelFormat::BGR,
image->width, image->height,
image->width * image->height * 3);
@@ -410,13 +408,13 @@ Image* Frame::ConvertMJPEGToBGR(Image* image) {
}
Image* Frame::ConvertMJPEGToGray(Image* image) {
if (!image || image->pixelFormat != wpi::util::PixelFormat::kMJPEG) {
if (!image || image->pixelFormat != wpi::util::PixelFormat::MJPEG) {
return nullptr;
}
// Allocate an grayscale image
auto newImage =
m_impl->source.AllocImage(wpi::util::PixelFormat::kGray, image->width,
m_impl->source.AllocImage(wpi::util::PixelFormat::GRAY, image->width,
image->height, image->width * image->height);
// Decode
@@ -433,12 +431,12 @@ Image* Frame::ConvertMJPEGToGray(Image* image) {
}
Image* Frame::ConvertYUYVToBGR(Image* image) {
if (!image || image->pixelFormat != wpi::util::PixelFormat::kYUYV) {
if (!image || image->pixelFormat != wpi::util::PixelFormat::YUYV) {
return nullptr;
}
// Allocate a BGR image
auto newImage = m_impl->source.AllocImage(wpi::util::PixelFormat::kBGR,
auto newImage = m_impl->source.AllocImage(wpi::util::PixelFormat::BGR,
image->width, image->height,
image->width * image->height * 3);
@@ -455,13 +453,13 @@ Image* Frame::ConvertYUYVToBGR(Image* image) {
}
Image* Frame::ConvertYUYVToGray(Image* image) {
if (!image || image->pixelFormat != wpi::util::PixelFormat::kYUYV) {
if (!image || image->pixelFormat != wpi::util::PixelFormat::YUYV) {
return nullptr;
}
// Allocate a grayscale image
auto newImage =
m_impl->source.AllocImage(wpi::util::PixelFormat::kGray, image->width,
m_impl->source.AllocImage(wpi::util::PixelFormat::GRAY, image->width,
image->height, image->width * image->height);
// Convert
@@ -477,12 +475,12 @@ Image* Frame::ConvertYUYVToGray(Image* image) {
}
Image* Frame::ConvertUYVYToBGR(Image* image) {
if (!image || image->pixelFormat != wpi::util::PixelFormat::kUYVY) {
if (!image || image->pixelFormat != wpi::util::PixelFormat::UYVY) {
return nullptr;
}
// Allocate a BGR image
auto newImage = m_impl->source.AllocImage(wpi::util::PixelFormat::kBGR,
auto newImage = m_impl->source.AllocImage(wpi::util::PixelFormat::BGR,
image->width, image->height,
image->width * image->height * 3);
@@ -499,13 +497,13 @@ Image* Frame::ConvertUYVYToBGR(Image* image) {
}
Image* Frame::ConvertUYVYToGray(Image* image) {
if (!image || image->pixelFormat != wpi::util::PixelFormat::kUYVY) {
if (!image || image->pixelFormat != wpi::util::PixelFormat::UYVY) {
return nullptr;
}
// Allocate a grayscale image
auto newImage =
m_impl->source.AllocImage(wpi::util::PixelFormat::kGray, image->width,
m_impl->source.AllocImage(wpi::util::PixelFormat::GRAY, image->width,
image->height, image->width * image->height);
// Convert
@@ -521,12 +519,12 @@ Image* Frame::ConvertUYVYToGray(Image* image) {
}
Image* Frame::ConvertBGRToRGB565(Image* image) {
if (!image || image->pixelFormat != wpi::util::PixelFormat::kBGR) {
if (!image || image->pixelFormat != wpi::util::PixelFormat::BGR) {
return nullptr;
}
// Allocate a RGB565 image
auto newImage = m_impl->source.AllocImage(wpi::util::PixelFormat::kRGB565,
auto newImage = m_impl->source.AllocImage(wpi::util::PixelFormat::RGB565,
image->width, image->height,
image->width * image->height * 2);
@@ -543,12 +541,12 @@ Image* Frame::ConvertBGRToRGB565(Image* image) {
}
Image* Frame::ConvertRGB565ToBGR(Image* image) {
if (!image || image->pixelFormat != wpi::util::PixelFormat::kRGB565) {
if (!image || image->pixelFormat != wpi::util::PixelFormat::RGB565) {
return nullptr;
}
// Allocate a BGR image
auto newImage = m_impl->source.AllocImage(wpi::util::PixelFormat::kBGR,
auto newImage = m_impl->source.AllocImage(wpi::util::PixelFormat::BGR,
image->width, image->height,
image->width * image->height * 3);
@@ -565,13 +563,13 @@ Image* Frame::ConvertRGB565ToBGR(Image* image) {
}
Image* Frame::ConvertBGRToGray(Image* image) {
if (!image || image->pixelFormat != wpi::util::PixelFormat::kBGR) {
if (!image || image->pixelFormat != wpi::util::PixelFormat::BGR) {
return nullptr;
}
// Allocate a Grayscale image
auto newImage =
m_impl->source.AllocImage(wpi::util::PixelFormat::kGray, image->width,
m_impl->source.AllocImage(wpi::util::PixelFormat::GRAY, image->width,
image->height, image->width * image->height);
// Convert
@@ -587,12 +585,12 @@ Image* Frame::ConvertBGRToGray(Image* image) {
}
Image* Frame::ConvertGrayToBGR(Image* image) {
if (!image || image->pixelFormat != wpi::util::PixelFormat::kGray) {
if (!image || image->pixelFormat != wpi::util::PixelFormat::GRAY) {
return nullptr;
}
// Allocate a BGR image
auto newImage = m_impl->source.AllocImage(wpi::util::PixelFormat::kBGR,
auto newImage = m_impl->source.AllocImage(wpi::util::PixelFormat::BGR,
image->width, image->height,
image->width * image->height * 3);
@@ -609,7 +607,7 @@ Image* Frame::ConvertGrayToBGR(Image* image) {
}
Image* Frame::ConvertBGRToMJPEG(Image* image, int quality) {
if (!image || image->pixelFormat != wpi::util::PixelFormat::kBGR) {
if (!image || image->pixelFormat != wpi::util::PixelFormat::BGR) {
return nullptr;
}
if (!m_impl) {
@@ -623,7 +621,7 @@ Image* Frame::ConvertBGRToMJPEG(Image* image, int quality) {
// Per Wikipedia, Q=100 on a sample image results in 8.25 bits per pixel,
// this is a little bit more conservative in assuming 50% space savings over
// the equivalent BGR image.
auto newImage = m_impl->source.AllocImage(wpi::util::PixelFormat::kMJPEG,
auto newImage = m_impl->source.AllocImage(wpi::util::PixelFormat::MJPEG,
image->width, image->height,
image->width * image->height * 1.5);
@@ -644,7 +642,7 @@ Image* Frame::ConvertBGRToMJPEG(Image* image, int quality) {
}
Image* Frame::ConvertGrayToMJPEG(Image* image, int quality) {
if (!image || image->pixelFormat != wpi::util::PixelFormat::kGray) {
if (!image || image->pixelFormat != wpi::util::PixelFormat::GRAY) {
return nullptr;
}
if (!m_impl) {
@@ -659,7 +657,7 @@ Image* Frame::ConvertGrayToMJPEG(Image* image, int quality) {
// this is a little bit more conservative in assuming 25% space savings over
// the equivalent grayscale image.
auto newImage = m_impl->source.AllocImage(
wpi::util::PixelFormat::kMJPEG, image->width, image->height,
wpi::util::PixelFormat::MJPEG, image->width, image->height,
image->width * image->height * 0.75);
// Compress
@@ -679,12 +677,12 @@ Image* Frame::ConvertGrayToMJPEG(Image* image, int quality) {
}
Image* Frame::ConvertGrayToY16(Image* image) {
if (!image || image->pixelFormat != wpi::util::PixelFormat::kGray) {
if (!image || image->pixelFormat != wpi::util::PixelFormat::GRAY) {
return nullptr;
}
// Allocate a Y16 image
auto newImage = m_impl->source.AllocImage(wpi::util::PixelFormat::kY16,
auto newImage = m_impl->source.AllocImage(wpi::util::PixelFormat::Y16,
image->width, image->height,
image->width * image->height * 2);
@@ -701,13 +699,13 @@ Image* Frame::ConvertGrayToY16(Image* image) {
}
Image* Frame::ConvertY16ToGray(Image* image) {
if (!image || image->pixelFormat != wpi::util::PixelFormat::kY16) {
if (!image || image->pixelFormat != wpi::util::PixelFormat::Y16) {
return nullptr;
}
// Allocate a Grayscale image
auto newImage =
m_impl->source.AllocImage(wpi::util::PixelFormat::kGray, image->width,
m_impl->source.AllocImage(wpi::util::PixelFormat::GRAY, image->width,
image->height, image->width * image->height);
// Scale min to 0 and max to 255
@@ -723,12 +721,12 @@ Image* Frame::ConvertY16ToGray(Image* image) {
}
Image* Frame::ConvertBGRToBGRA(Image* image) {
if (!image || image->pixelFormat != wpi::util::PixelFormat::kBGR) {
if (!image || image->pixelFormat != wpi::util::PixelFormat::BGR) {
return nullptr;
}
// Allocate a RGB565 image
auto newImage = m_impl->source.AllocImage(wpi::util::PixelFormat::kBGRA,
auto newImage = m_impl->source.AllocImage(wpi::util::PixelFormat::BGRA,
image->width, image->height,
image->width * image->height * 4);
@@ -765,7 +763,7 @@ Image* Frame::GetImageImpl(int width, int height,
// anything else with it. Note that if the destination format is JPEG, we
// still need to do this (unless the width/height/compression were the same,
// in which case we already returned the existing JPEG above).
if (cur->pixelFormat == wpi::util::PixelFormat::kMJPEG) {
if (cur->pixelFormat == wpi::util::PixelFormat::MJPEG) {
cur = ConvertMJPEGToBGR(cur);
}
@@ -815,7 +813,7 @@ std::unique_ptr<Image> CreateImageFromBGRA(wpi::cs::SourceImpl* source,
cv::Mat finalImage{static_cast<int>(height), static_cast<int>(width), CV_8UC4,
const_cast<uint8_t*>(data), stride};
std::unique_ptr<Image> dest = source->AllocImage(
wpi::util::PixelFormat::kBGR, width, height, width * height * 3);
wpi::util::PixelFormat::BGR, width, height, width * height * 3);
cv::cvtColor(finalImage, dest->AsMat(), cv::COLOR_BGRA2BGR);
return dest;
}

View File

@@ -112,11 +112,11 @@ class Frame {
wpi::util::PixelFormat GetOriginalPixelFormat() const {
if (!m_impl) {
return wpi::util::PixelFormat::kUnknown;
return wpi::util::PixelFormat::UNKNOWN;
}
std::scoped_lock lock(m_impl->mutex);
if (m_impl->images.empty()) {
return wpi::util::PixelFormat::kUnknown;
return wpi::util::PixelFormat::UNKNOWN;
}
return m_impl->images[0]->pixelFormat;
}
@@ -191,14 +191,14 @@ class Frame {
int jpegQuality = -1) const;
Image* Convert(Image* image, wpi::util::PixelFormat pixelFormat) {
if (pixelFormat == wpi::util::PixelFormat::kMJPEG) {
if (pixelFormat == wpi::util::PixelFormat::MJPEG) {
return nullptr;
}
return ConvertImpl(image, pixelFormat, -1, 80);
}
Image* ConvertToMJPEG(Image* image, int requiredQuality,
int defaultQuality = 80) {
return ConvertImpl(image, wpi::util::PixelFormat::kMJPEG, requiredQuality,
return ConvertImpl(image, wpi::util::PixelFormat::MJPEG, requiredQuality,
defaultQuality);
}
Image* ConvertMJPEGToBGR(Image* image);
@@ -218,14 +218,14 @@ class Frame {
Image* ConvertBGRToBGRA(Image* image);
Image* GetImage(int width, int height, wpi::util::PixelFormat pixelFormat) {
if (pixelFormat == wpi::util::PixelFormat::kMJPEG) {
if (pixelFormat == wpi::util::PixelFormat::MJPEG) {
return nullptr;
}
return GetImageImpl(width, height, pixelFormat, -1, 80);
}
Image* GetImageMJPEG(int width, int height, int requiredQuality,
int defaultQuality = 80) {
return GetImageImpl(width, height, wpi::util::PixelFormat::kMJPEG,
return GetImageImpl(width, height, wpi::util::PixelFormat::MJPEG,
requiredQuality, defaultQuality);
}

View File

@@ -304,8 +304,7 @@ bool HttpCameraImpl::DeviceStreamFrame(wpi::util::raw_istream& is,
// We know how big it is! Just get a frame of the right size and read
// the data directly into it.
unsigned int contentLength = v.value();
auto image =
AllocImage(wpi::util::PixelFormat::kMJPEG, 0, 0, contentLength);
auto image = AllocImage(wpi::util::PixelFormat::MJPEG, 0, 0, contentLength);
is.read(image->data(), contentLength);
if (!m_active || is.has_error()) {
return false;
@@ -325,7 +324,7 @@ bool HttpCameraImpl::DeviceStreamFrame(wpi::util::raw_istream& is,
PutError("did not receive a JPEG image", wpi::util::Now());
return false;
}
PutFrame(wpi::util::PixelFormat::kMJPEG, width, height, imageBuf,
PutFrame(wpi::util::PixelFormat::MJPEG, width, height, imageBuf,
wpi::util::Now());
}
@@ -333,9 +332,9 @@ bool HttpCameraImpl::DeviceStreamFrame(wpi::util::raw_istream& is,
// update video mode if not set
std::scoped_lock lock(m_mutex);
if (m_mode.pixelFormat != wpi::util::PixelFormat::kMJPEG ||
if (m_mode.pixelFormat != wpi::util::PixelFormat::MJPEG ||
m_mode.width == 0 || m_mode.height == 0) {
m_mode.pixelFormat = wpi::util::PixelFormat::kMJPEG;
m_mode.pixelFormat = wpi::util::PixelFormat::MJPEG;
m_mode.width = width;
m_mode.height = height;
}
@@ -474,9 +473,9 @@ bool HttpCameraImpl::CacheProperties(CS_Status* status) const {
// Pretty typical set of video modes
m_videoModes.clear();
m_videoModes.emplace_back(wpi::util::PixelFormat::kMJPEG, 640, 480, 30);
m_videoModes.emplace_back(wpi::util::PixelFormat::kMJPEG, 320, 240, 30);
m_videoModes.emplace_back(wpi::util::PixelFormat::kMJPEG, 160, 120, 30);
m_videoModes.emplace_back(wpi::util::PixelFormat::MJPEG, 640, 480, 30);
m_videoModes.emplace_back(wpi::util::PixelFormat::MJPEG, 320, 240, 30);
m_videoModes.emplace_back(wpi::util::PixelFormat::MJPEG, 160, 120, 30);
m_properties_cached = true;
return true;
@@ -525,7 +524,7 @@ void HttpCameraImpl::SetExposureManual(int value, CS_Status* status) {
}
bool HttpCameraImpl::SetVideoMode(const VideoMode& mode, CS_Status* status) {
if (mode.pixelFormat != wpi::util::PixelFormat::kMJPEG) {
if (mode.pixelFormat != wpi::util::PixelFormat::MJPEG) {
return false;
}
std::scoped_lock lock(m_mutex);

View File

@@ -53,20 +53,20 @@ class Image {
cv::Mat AsMat() {
int type;
switch (pixelFormat) {
case wpi::util::PixelFormat::kYUYV:
case wpi::util::PixelFormat::kRGB565:
case wpi::util::PixelFormat::kY16:
case wpi::util::PixelFormat::kUYVY:
case wpi::util::PixelFormat::YUYV:
case wpi::util::PixelFormat::RGB565:
case wpi::util::PixelFormat::Y16:
case wpi::util::PixelFormat::UYVY:
type = CV_8UC2;
break;
case wpi::util::PixelFormat::kBGR:
case wpi::util::PixelFormat::BGR:
type = CV_8UC3;
break;
case wpi::util::PixelFormat::kBGRA:
case wpi::util::PixelFormat::BGRA:
type = CV_8UC4;
break;
case wpi::util::PixelFormat::kGray:
case wpi::util::PixelFormat::kMJPEG:
case wpi::util::PixelFormat::GRAY:
case wpi::util::PixelFormat::MJPEG:
default:
type = CV_8UC1;
break;
@@ -76,18 +76,18 @@ class Image {
int GetStride() const {
switch (pixelFormat) {
case wpi::util::PixelFormat::kYUYV:
case wpi::util::PixelFormat::kRGB565:
case wpi::util::PixelFormat::kY16:
case wpi::util::PixelFormat::kUYVY:
case wpi::util::PixelFormat::YUYV:
case wpi::util::PixelFormat::RGB565:
case wpi::util::PixelFormat::Y16:
case wpi::util::PixelFormat::UYVY:
return 2 * width;
case wpi::util::PixelFormat::kBGR:
case wpi::util::PixelFormat::BGR:
return 3 * width;
case wpi::util::PixelFormat::kBGRA:
case wpi::util::PixelFormat::BGRA:
return 4 * width;
case wpi::util::PixelFormat::kGray:
case wpi::util::PixelFormat::GRAY:
return width;
case wpi::util::PixelFormat::kMJPEG:
case wpi::util::PixelFormat::MJPEG:
default:
return 0;
}
@@ -106,7 +106,7 @@ class Image {
// Consider +/-5 on JPEG quality to be "close enough"
return width == width_ && height == height_ &&
pixelFormat == pixelFormat_ &&
(pixelFormat != wpi::util::PixelFormat::kMJPEG ||
(pixelFormat != wpi::util::PixelFormat::MJPEG ||
jpegQuality_ == -1 ||
(jpegQuality != -1 && std::abs(jpegQuality - jpegQuality_) <= 5));
}
@@ -123,7 +123,7 @@ class Image {
std::vector<uchar> m_data;
public:
wpi::util::PixelFormat pixelFormat{wpi::util::PixelFormat::kUnknown};
wpi::util::PixelFormat pixelFormat{wpi::util::PixelFormat::UNKNOWN};
int width{0};
int height{0};
int jpegQuality{-1};

View File

@@ -445,28 +445,28 @@ void MjpegServerImpl::ConnThread::SendHTML(wpi::util::raw_ostream& os,
for (auto mode : source.EnumerateVideoModes(&status)) {
os << "<tr><td>";
switch (mode.pixelFormat) {
case wpi::util::PixelFormat::kMJPEG:
case wpi::util::PixelFormat::MJPEG:
os << "MJPEG";
break;
case wpi::util::PixelFormat::kYUYV:
case wpi::util::PixelFormat::YUYV:
os << "YUYV";
break;
case wpi::util::PixelFormat::kRGB565:
case wpi::util::PixelFormat::RGB565:
os << "RGB565";
break;
case wpi::util::PixelFormat::kBGR:
case wpi::util::PixelFormat::BGR:
os << "BGR";
break;
case wpi::util::PixelFormat::kBGRA:
case wpi::util::PixelFormat::BGRA:
os << "BGRA";
break;
case wpi::util::PixelFormat::kGray:
case wpi::util::PixelFormat::GRAY:
os << "gray";
break;
case wpi::util::PixelFormat::kY16:
case wpi::util::PixelFormat::Y16:
os << "Y16";
break;
case wpi::util::PixelFormat::kUYVY:
case wpi::util::PixelFormat::UYVY:
os << "UYVY";
break;
default:
@@ -565,25 +565,25 @@ void MjpegServerImpl::ConnThread::SendJSON(wpi::util::raw_ostream& os,
os << '{';
os << "\n\"pixelFormat\": \"";
switch (mode.pixelFormat) {
case wpi::util::PixelFormat::kMJPEG:
case wpi::util::PixelFormat::MJPEG:
os << "MJPEG";
break;
case wpi::util::PixelFormat::kYUYV:
case wpi::util::PixelFormat::YUYV:
os << "YUYV";
break;
case wpi::util::PixelFormat::kRGB565:
case wpi::util::PixelFormat::RGB565:
os << "RGB565";
break;
case wpi::util::PixelFormat::kBGR:
case wpi::util::PixelFormat::BGR:
os << "BGR";
break;
case wpi::util::PixelFormat::kGray:
case wpi::util::PixelFormat::GRAY:
os << "gray";
break;
case wpi::util::PixelFormat::kY16:
case wpi::util::PixelFormat::Y16:
os << "Y16";
break;
case wpi::util::PixelFormat::kUYVY:
case wpi::util::PixelFormat::UYVY:
os << "UYVY";
break;
default:
@@ -752,15 +752,15 @@ void MjpegServerImpl::ConnThread::SendStream(wpi::net::raw_socket_ostream& os) {
bool addDHT = false;
size_t locSOF = size;
switch (image->pixelFormat) {
case wpi::util::PixelFormat::kMJPEG:
case wpi::util::PixelFormat::MJPEG:
// Determine if we need to add DHT to it, and allocate enough space
// for adding it if required.
addDHT = JpegNeedsDHT(data, &size, &locSOF);
break;
case wpi::util::PixelFormat::kUYVY:
case wpi::util::PixelFormat::kRGB565:
case wpi::util::PixelFormat::kYUYV:
case wpi::util::PixelFormat::kY16:
case wpi::util::PixelFormat::UYVY:
case wpi::util::PixelFormat::RGB565:
case wpi::util::PixelFormat::YUYV:
case wpi::util::PixelFormat::Y16:
default:
// Bad frame; sleep for 10 ms so we don't consume all processor time.
std::this_thread::sleep_for(std::chrono::milliseconds(10));

View File

@@ -200,21 +200,21 @@ bool SourceImpl::SetConfigJson(const wpi::util::json& config,
try {
auto str = config.at("pixel format").get<std::string>();
if (wpi::util::equals_lower(str, "mjpeg")) {
mode.pixelFormat = wpi::util::PixelFormat::kMJPEG;
mode.pixelFormat = wpi::util::PixelFormat::MJPEG;
} else if (wpi::util::equals_lower(str, "yuyv")) {
mode.pixelFormat = wpi::util::PixelFormat::kYUYV;
mode.pixelFormat = wpi::util::PixelFormat::YUYV;
} else if (wpi::util::equals_lower(str, "rgb565")) {
mode.pixelFormat = wpi::util::PixelFormat::kRGB565;
mode.pixelFormat = wpi::util::PixelFormat::RGB565;
} else if (wpi::util::equals_lower(str, "bgr")) {
mode.pixelFormat = wpi::util::PixelFormat::kBGR;
mode.pixelFormat = wpi::util::PixelFormat::BGR;
} else if (wpi::util::equals_lower(str, "bgra")) {
mode.pixelFormat = wpi::util::PixelFormat::kBGRA;
mode.pixelFormat = wpi::util::PixelFormat::BGRA;
} else if (wpi::util::equals_lower(str, "gray")) {
mode.pixelFormat = wpi::util::PixelFormat::kGray;
mode.pixelFormat = wpi::util::PixelFormat::GRAY;
} else if (wpi::util::equals_lower(str, "y16")) {
mode.pixelFormat = wpi::util::PixelFormat::kY16;
mode.pixelFormat = wpi::util::PixelFormat::Y16;
} else if (wpi::util::equals_lower(str, "uyvy")) {
mode.pixelFormat = wpi::util::PixelFormat::kUYVY;
mode.pixelFormat = wpi::util::PixelFormat::UYVY;
} else {
SWARNING("SetConfigJson: could not understand pixel format value '{}'",
str);
@@ -252,7 +252,7 @@ bool SourceImpl::SetConfigJson(const wpi::util::json& config,
}
// if all of video mode is set, use SetVideoMode, otherwise piecemeal it
if (mode.pixelFormat != wpi::util::PixelFormat::kUnknown && mode.width != 0 &&
if (mode.pixelFormat != wpi::util::PixelFormat::UNKNOWN && mode.width != 0 &&
mode.height != 0 && mode.fps != 0) {
SINFO(
"SetConfigJson: setting video mode to pixelFormat {}, width {}, height "
@@ -260,7 +260,7 @@ bool SourceImpl::SetConfigJson(const wpi::util::json& config,
static_cast<int>(mode.pixelFormat), mode.width, mode.height, mode.fps);
SetVideoMode(mode, status);
} else {
if (mode.pixelFormat != wpi::util::PixelFormat::kUnknown) {
if (mode.pixelFormat != wpi::util::PixelFormat::UNKNOWN) {
SINFO("SetConfigJson: setting pixelFormat {}",
static_cast<int>(mode.pixelFormat));
SetPixelFormat(mode.pixelFormat, status);
@@ -362,28 +362,28 @@ wpi::util::json SourceImpl::GetConfigJsonObject(CS_Status* status) {
// pixel format
std::string_view pixelFormat;
switch (m_mode.pixelFormat) {
case wpi::util::PixelFormat::kMJPEG:
case wpi::util::PixelFormat::MJPEG:
pixelFormat = "mjpeg";
break;
case wpi::util::PixelFormat::kYUYV:
case wpi::util::PixelFormat::YUYV:
pixelFormat = "yuyv";
break;
case wpi::util::PixelFormat::kRGB565:
case wpi::util::PixelFormat::RGB565:
pixelFormat = "rgb565";
break;
case wpi::util::PixelFormat::kBGR:
case wpi::util::PixelFormat::BGR:
pixelFormat = "bgr";
break;
case wpi::util::PixelFormat::kBGRA:
case wpi::util::PixelFormat::BGRA:
pixelFormat = "bgra";
break;
case wpi::util::PixelFormat::kGray:
case wpi::util::PixelFormat::GRAY:
pixelFormat = "gray";
break;
case wpi::util::PixelFormat::kY16:
case wpi::util::PixelFormat::Y16:
pixelFormat = "y16";
break;
case wpi::util::PixelFormat::kUYVY:
case wpi::util::PixelFormat::UYVY:
pixelFormat = "uyvy";
break;
default:
@@ -467,7 +467,7 @@ std::unique_ptr<Image> SourceImpl::AllocImage(
void SourceImpl::PutFrame(wpi::util::PixelFormat pixelFormat, int width,
int height, std::string_view data, Frame::Time time,
WPI_TimestampSource timeSrc) {
if (pixelFormat == wpi::util::PixelFormat::kBGRA) {
if (pixelFormat == wpi::util::PixelFormat::BGRA) {
// Write BGRA as BGR to save a copy
auto image =
CreateImageFromBGRA(this, width, height, width * 4,

View File

@@ -38,7 +38,7 @@ class CvSink : public ImageSink {
* @param pixelFormat The pixel format to read
*/
explicit CvSink(std::string_view name, wpi::util::PixelFormat pixelFormat =
wpi::util::PixelFormat::kBGR) {
wpi::util::PixelFormat::BGR) {
m_handle = CreateRawSink(name, true, &m_status);
this->pixelFormat = pixelFormat;
}

View File

@@ -73,16 +73,16 @@ class CvSource : public ImageSource {
wpi::util::PixelFormat format;
if (channels == 1) {
// 1 channel is assumed Grayscale
format = wpi::util::PixelFormat::kGray;
format = wpi::util::PixelFormat::GRAY;
} else if (channels == 2) {
// 2 channels is assumed YUYV
format = wpi::util::PixelFormat::kYUYV;
format = wpi::util::PixelFormat::YUYV;
} else if (channels == 3) {
// 3 channels is assumed BGR
format = wpi::util::PixelFormat::kBGR;
format = wpi::util::PixelFormat::BGR;
} else if (channels == 4) {
// 4 channels is assumed BGRA
format = wpi::util::PixelFormat::kBGRA;
format = wpi::util::PixelFormat::BGRA;
} else {
// TODO Error
return;
@@ -138,42 +138,42 @@ class CvSource : public ImageSource {
static bool VerifyFormat(cv::Mat& image, wpi::util::PixelFormat pixelFormat) {
int channels = image.channels();
switch (pixelFormat) {
case wpi::util::PixelFormat::kBGR:
case wpi::util::PixelFormat::BGR:
if (channels == 3) {
return true;
}
break;
case wpi::util::PixelFormat::kBGRA:
case wpi::util::PixelFormat::BGRA:
if (channels == 4) {
return true;
}
break;
case wpi::util::PixelFormat::kGray:
case wpi::util::PixelFormat::GRAY:
if (channels == 1) {
return true;
}
break;
case wpi::util::PixelFormat::kRGB565:
case wpi::util::PixelFormat::RGB565:
if (channels == 2) {
return true;
}
break;
case wpi::util::PixelFormat::kUYVY:
case wpi::util::PixelFormat::UYVY:
if (channels == 2) {
return true;
}
break;
case wpi::util::PixelFormat::kY16:
case wpi::util::PixelFormat::Y16:
if (channels == 2) {
return true;
}
break;
case wpi::util::PixelFormat::kYUYV:
case wpi::util::PixelFormat::YUYV:
if (channels == 2) {
return true;
}
break;
case wpi::util::PixelFormat::kMJPEG:
case wpi::util::PixelFormat::MJPEG:
if (channels == 1) {
return true;
}

View File

@@ -41,7 +41,7 @@ class RawSource : public ImageSource {
* @param height height
* @param fps fps
*/
RawSource(std::string_view name, VideoMode::PixelFormat pixelFormat,
RawSource(std::string_view name, wpi::util::PixelFormat pixelFormat,
int width, int height, int fps) {
m_handle = CreateRawSource(
name, false, VideoMode{pixelFormat, width, height, fps}, &m_status);

View File

@@ -33,7 +33,7 @@ struct VideoMode {
}
explicit operator bool() const {
return pixelFormat == wpi::util::PixelFormat::kUnknown;
return pixelFormat == wpi::util::PixelFormat::UNKNOWN;
}
bool operator==(const VideoMode& other) const {
@@ -46,7 +46,7 @@ struct VideoMode {
height == other.height;
}
wpi::util::PixelFormat pixelFormat = wpi::util::PixelFormat::kUnknown;
wpi::util::PixelFormat pixelFormat = wpi::util::PixelFormat::UNKNOWN;
int width = 0;
int height = 0;
int fps = 0;

View File

@@ -74,44 +74,44 @@ static inline struct v4l2_fract FPSToFract(int fps) {
static wpi::util::PixelFormat ToPixelFormat(__u32 pixelFormat) {
switch (pixelFormat) {
case V4L2_PIX_FMT_MJPEG:
return wpi::util::PixelFormat::kMJPEG;
return wpi::util::PixelFormat::MJPEG;
case V4L2_PIX_FMT_YUYV:
return wpi::util::PixelFormat::kYUYV;
return wpi::util::PixelFormat::YUYV;
case V4L2_PIX_FMT_RGB565:
return wpi::util::PixelFormat::kRGB565;
return wpi::util::PixelFormat::RGB565;
case V4L2_PIX_FMT_BGR24:
return wpi::util::PixelFormat::kBGR;
return wpi::util::PixelFormat::BGR;
case V4L2_PIX_FMT_ABGR32:
return wpi::util::PixelFormat::kBGRA;
return wpi::util::PixelFormat::BGRA;
case V4L2_PIX_FMT_GREY:
return wpi::util::PixelFormat::kGray;
return wpi::util::PixelFormat::GRAY;
case V4L2_PIX_FMT_Y16:
return wpi::util::PixelFormat::kY16;
return wpi::util::PixelFormat::Y16;
case V4L2_PIX_FMT_UYVY:
return wpi::util::PixelFormat::kUYVY;
return wpi::util::PixelFormat::UYVY;
default:
return wpi::util::PixelFormat::kUnknown;
return wpi::util::PixelFormat::UNKNOWN;
}
}
// Conversion from VideoMode::PixelFormat to v4l2_format pixelformat
static __u32 FromPixelFormat(wpi::util::PixelFormat pixelFormat) {
switch (pixelFormat) {
case wpi::util::PixelFormat::kMJPEG:
case wpi::util::PixelFormat::MJPEG:
return V4L2_PIX_FMT_MJPEG;
case wpi::util::PixelFormat::kYUYV:
case wpi::util::PixelFormat::YUYV:
return V4L2_PIX_FMT_YUYV;
case wpi::util::PixelFormat::kRGB565:
case wpi::util::PixelFormat::RGB565:
return V4L2_PIX_FMT_RGB565;
case wpi::util::PixelFormat::kBGR:
case wpi::util::PixelFormat::BGR:
return V4L2_PIX_FMT_BGR24;
case wpi::util::PixelFormat::kBGRA:
case wpi::util::PixelFormat::BGRA:
return V4L2_PIX_FMT_ABGR32;
case wpi::util::PixelFormat::kGray:
case wpi::util::PixelFormat::GRAY:
return V4L2_PIX_FMT_GREY;
case wpi::util::PixelFormat::kY16:
case wpi::util::PixelFormat::Y16:
return V4L2_PIX_FMT_Y16;
case wpi::util::PixelFormat::kUYVY:
case wpi::util::PixelFormat::UYVY:
return V4L2_PIX_FMT_UYVY;
default:
return 0;
@@ -554,7 +554,7 @@ void UsbCameraImpl::CameraThreadMain() {
int width = m_mode.width;
int height = m_mode.height;
bool good = true;
if (m_mode.pixelFormat == wpi::util::PixelFormat::kMJPEG &&
if (m_mode.pixelFormat == wpi::util::PixelFormat::MJPEG &&
!GetJpegSize(image, &width, &height)) {
SWARNING("invalid JPEG image received from camera");
good = false;
@@ -1079,7 +1079,7 @@ void UsbCameraImpl::DeviceCacheMode() {
if (DoIoctl(fd, VIDIOC_G_FMT, &vfmt) != 0) {
SERROR("could not read current video mode");
std::scoped_lock lock(m_mutex);
m_mode = VideoMode{wpi::util::PixelFormat::kMJPEG, 320, 240, 30};
m_mode = VideoMode{wpi::util::PixelFormat::MJPEG, 320, 240, 30};
return;
}
wpi::util::PixelFormat pixelFormat = ToPixelFormat(vfmt.fmt.pix.pixelformat);
@@ -1108,9 +1108,9 @@ void UsbCameraImpl::DeviceCacheMode() {
}
} else {
// Default to MJPEG
if (pixelFormat != wpi::util::PixelFormat::kMJPEG) {
if (pixelFormat != wpi::util::PixelFormat::MJPEG) {
formatChanged = true;
pixelFormat = wpi::util::PixelFormat::kMJPEG;
pixelFormat = wpi::util::PixelFormat::MJPEG;
}
}
@@ -1320,7 +1320,7 @@ void UsbCameraImpl::DeviceCacheVideoModes() {
fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
for (fmt.index = 0; TryIoctl(fd, VIDIOC_ENUM_FMT, &fmt) >= 0; ++fmt.index) {
wpi::util::PixelFormat pixelFormat = ToPixelFormat(fmt.pixelformat);
if (pixelFormat == wpi::util::PixelFormat::kUnknown) {
if (pixelFormat == wpi::util::PixelFormat::UNKNOWN) {
continue;
}
@@ -1360,8 +1360,8 @@ void UsbCameraImpl::DeviceCacheVideoModes() {
// https://picamera.readthedocs.io/en/release-1.10/fov.html
if (modes.empty() && m_picamera) {
for (wpi::util::PixelFormat pixelFormat :
{wpi::util::PixelFormat::kYUYV, wpi::util::PixelFormat::kMJPEG,
wpi::util::PixelFormat::kBGR}) {
{wpi::util::PixelFormat::YUYV, wpi::util::PixelFormat::MJPEG,
wpi::util::PixelFormat::BGR}) {
modes.emplace_back(pixelFormat, 1920, 1080, 30);
modes.emplace_back(pixelFormat, 2592, 1944, 15);
modes.emplace_back(pixelFormat, 1296, 972, 42);

View File

@@ -163,12 +163,12 @@ using namespace wpi::cs;
*status = CS_INVALID_HANDLE;
return;
}
// Make sure properties are cached
if (!self.propertiesCached) {
[self deviceCacheProperties];
}
// Get the property name from the property index
wpi::util::SmallString<128> nameBuf;
std::string_view propName = sharedThis->GetPropertyName(property, nameBuf, status);
@@ -176,9 +176,9 @@ using namespace wpi::cs;
OBJCERROR("Failed to get property name for index {}", property);
return;
}
std::string nameStr(propName);
// Check if it's an auto property
auto& propertyAutoCache = sharedThis->GetPropertyAutoCache();
auto autoIt = propertyAutoCache.find(nameStr);
@@ -190,19 +190,19 @@ using namespace wpi::cs;
*status = CS_INVALID_PROPERTY;
return;
}
if (![self.uvcControl setAutoProperty:propID enabled:enabled status:status]) {
OBJCERROR("Failed to set auto property {} to {}",
nameStr, enabled);
return;
}
// Update property value
sharedThis->UpdatePropertyValuePublic(property, false, value, {});
});
return;
}
// Handle regular property
auto& propertyCache = sharedThis->GetPropertyCache();
auto it = propertyCache.find(nameStr);
@@ -211,22 +211,22 @@ using namespace wpi::cs;
*status = CS_INVALID_PROPERTY;
return;
}
uint32_t propID = it->second;
dispatch_async_and_wait(self.sessionQueue, ^{
if (self.uvcControl == nil) {
*status = CS_INVALID_PROPERTY;
return;
}
// Get the property implementation to access its limits
const PropertyImpl* prop = sharedThis->GetPropertyPublic(property);
if (!prop) {
*status = CS_INVALID_PROPERTY;
return;
}
int32_t realValue = value;
if ([self isPercentageProperty:propID]) {
@@ -241,7 +241,7 @@ using namespace wpi::cs;
OBJCERROR("Failed to set property {} to value {}", nameStr, realValue);
return;
}
// Update property value in the container
sharedThis->UpdatePropertyValuePublic(property, false, value, {});
});
@@ -261,12 +261,12 @@ using namespace wpi::cs;
*status = CS_INVALID_HANDLE;
return;
}
// Make sure properties are cached
if (!self.propertiesCached) {
[self deviceCacheProperties];
}
// Get the property index and set it
int prop = sharedThis->GetPropertyIndex(kPropertyBrightness);
sharedThis->SetProperty(prop, brightness, status);
@@ -278,12 +278,12 @@ using namespace wpi::cs;
*status = CS_INVALID_HANDLE;
return 0;
}
// Make sure properties are cached
if (!self.propertiesCached) {
[self deviceCacheProperties];
}
// Get the property index and its value
int prop = sharedThis->GetPropertyIndex(kPropertyBrightness);
return sharedThis->GetProperty(prop, status);
@@ -295,12 +295,12 @@ using namespace wpi::cs;
*status = CS_INVALID_HANDLE;
return;
}
// Make sure properties are cached
if (!self.propertiesCached) {
[self deviceCacheProperties];
}
int prop = sharedThis->GetPropertyIndex(kPropertyAutoWhiteBalance);
sharedThis->SetProperty(prop, 1, status);
}
@@ -311,12 +311,12 @@ using namespace wpi::cs;
*status = CS_INVALID_HANDLE;
return;
}
// Make sure properties are cached
if (!self.propertiesCached) {
[self deviceCacheProperties];
}
int prop = sharedThis->GetPropertyIndex(kPropertyAutoWhiteBalance);
sharedThis->SetProperty(prop, 0, status);
}
@@ -327,19 +327,19 @@ using namespace wpi::cs;
*status = CS_INVALID_HANDLE;
return;
}
// Make sure properties are cached
if (!self.propertiesCached) {
[self deviceCacheProperties];
}
// First disable auto white balance
int autoProp = sharedThis->GetPropertyIndex(kPropertyAutoWhiteBalance);
sharedThis->SetProperty(autoProp, 0, status);
if (*status != 0) {
return;
}
// Then set the white balance value
int prop = sharedThis->GetPropertyIndex(kPropertyWhiteBalance);
sharedThis->SetProperty(prop, value, status);
@@ -351,12 +351,12 @@ using namespace wpi::cs;
*status = CS_INVALID_HANDLE;
return;
}
// Make sure properties are cached
if (!self.propertiesCached) {
[self deviceCacheProperties];
}
// Set the auto exposure property to enabled (1)
int prop = sharedThis->GetPropertyIndex(kPropertyAutoExposure);
sharedThis->SetProperty(prop, kPropertyAutoExposureOn, status);
@@ -368,12 +368,12 @@ using namespace wpi::cs;
*status = CS_INVALID_HANDLE;
return;
}
// Make sure properties are cached
if (!self.propertiesCached) {
[self deviceCacheProperties];
}
// Set the auto exposure property to disabled (0)
int prop = sharedThis->GetPropertyIndex(kPropertyAutoExposure);
sharedThis->SetProperty(prop, kPropertyAutoExposureOff, status);
@@ -385,19 +385,19 @@ using namespace wpi::cs;
*status = CS_INVALID_HANDLE;
return;
}
// Make sure properties are cached
if (!self.propertiesCached) {
[self deviceCacheProperties];
}
// First disable auto exposure
int autoProp = sharedThis->GetPropertyIndex(kPropertyAutoExposure);
sharedThis->SetProperty(autoProp, kPropertyAutoExposureOff, status);
if (*status != 0) {
return;
}
// Then set the exposure value
int prop = sharedThis->GetPropertyIndex(kPropertyExposure);
sharedThis->SetProperty(prop, value, status);
@@ -580,12 +580,12 @@ using namespace wpi::cs;
[self cacheProperty:CAPPROPID_ZOOM withName:@kPropertyZoom];
[self cacheProperty:CAPPROPID_BACKLIGHTCOMP withName:@kPropertyBackLightCompensation];
[self cacheProperty:CAPPROPID_POWERLINEFREQ withName:@kPropertyPowerLineFrequency];
// Cache auto properties
[self cacheAutoProperty:CAPPROPID_EXPOSURE withName:@kPropertyAutoExposure];
[self cacheAutoProperty:CAPPROPID_WHITEBALANCE withName:@kPropertyAutoWhiteBalance];
[self cacheAutoProperty:CAPPROPID_FOCUS withName:@kPropertyAutoFocus];
self.propertiesCached = true;
}
@@ -595,41 +595,41 @@ using namespace wpi::cs;
OBJCERROR("Cannot cache property: UsbCameraImpl not available");
return;
}
if (self.uvcControl == nil) {
OBJCWARNING("Cannot cache property {}: UVC control not initialized", [name UTF8String]);
return;
}
// Get property limits
int32_t minimum = 0, maximum = 0, defaultValue = 0;
int32_t value = defaultValue;
CS_Status status;
std::string nameStr = std::string([name UTF8String]);
// Get the property limits
if (![self.uvcControl getPropertyLimits:propID
min:&minimum
max:&maximum
defValue:&defaultValue
if (![self.uvcControl getPropertyLimits:propID
min:&minimum
max:&maximum
defValue:&defaultValue
status:&status]) {
OBJCWARNING("Failed to get property limits for {}", nameStr);
return;
}
// Get current value
if (![self.uvcControl getProperty:propID withValue:&value status:&status]) {
value = defaultValue;
OBJCWARNING("Failed to get current value for {}: {}",
OBJCWARNING("Failed to get current value for {}: {}",
nameStr, value);
return;
}
// Create property
auto& propertyCache = sharedThis->GetPropertyCache();
propertyCache[nameStr] = propID;
// Create the property implementation
std::unique_ptr<PropertyImpl> prop;
prop = std::make_unique<PropertyImpl>(nameStr);
@@ -639,11 +639,11 @@ using namespace wpi::cs;
prop->maximum = maximum;
prop->step = 1; // Most camera properties use a step of 1
prop->defaultValue = defaultValue;
// Add the property to the container
std::scoped_lock lock(sharedThis->GetMutex());
int ndx = sharedThis->CreatePropertyPublic(nameStr, [&] { return std::move(prop); });
// Notify that property has been created
sharedThis->NotifyPropertyCreatedPublic(ndx, *sharedThis->GetPropertyPublic(ndx));
}
@@ -654,24 +654,24 @@ using namespace wpi::cs;
OBJCERROR("Cannot cache auto property: UsbCameraImpl not available");
return;
}
if (self.uvcControl == nil) {
OBJCWARNING("Cannot cache auto property {}: UVC control not initialized", [baseName UTF8String]);
return;
}
// Build auto mode property name
std::string nameStr = std::string([baseName UTF8String]);
// Get current auto mode status
bool enabled = false;
CS_Status status = 0;
if(![self.uvcControl getAutoProperty:propID enabled:&enabled status:&status]) {
OBJCWARNING("Failed to get auto property {}", nameStr);
return;
}
// Create property
std::unique_ptr<PropertyImpl> prop;
prop = std::make_unique<PropertyImpl>(nameStr);
@@ -681,14 +681,14 @@ using namespace wpi::cs;
prop->maximum = 1;
prop->step = 1;
prop->defaultValue = 0; // Default is manual mode
// Add property to container
std::scoped_lock lock(sharedThis->GetMutex());
int ndx = sharedThis->CreatePropertyPublic(nameStr, [&] { return std::move(prop); });
// Notify property created
sharedThis->NotifyPropertyCreatedPublic(ndx, *sharedThis->GetPropertyPublic(ndx));
// Map property name to ID
auto& propertyAutoCache = sharedThis->GetPropertyAutoCache();
propertyAutoCache[nameStr] = propID;
@@ -698,9 +698,9 @@ static wpi::util::PixelFormat FourCCToPixelFormat(FourCharCode fourcc) {
switch (fourcc) {
case kCVPixelFormatType_422YpCbCr8_yuvs:
case kCVPixelFormatType_422YpCbCr8FullRange:
return wpi::util::PixelFormat::kYUYV;
return wpi::util::PixelFormat::YUYV;
default:
return wpi::util::PixelFormat::kBGR;
return wpi::util::PixelFormat::BGR;
}
}
@@ -774,7 +774,7 @@ static wpi::util::PixelFormat FourCCToPixelFormat(FourCharCode fourcc) {
toCheck->height, toCheck->fps);
std::vector<CameraModeStore>& platformModes =
sharedThis->objcGetPlatformVideoModes();
// Find all matching modes
std::vector<CameraModeStore*> matchingModes;
for (auto& mode : platformModes) {
@@ -870,23 +870,23 @@ static wpi::util::PixelFormat FourCCToPixelFormat(FourCharCode fourcc) {
for (AVFrameRateRange* range in frameRates) {
CMTime minDuration = range.minFrameDuration;
CMTime maxDuration = range.maxFrameDuration;
// Calculate frame duration for current fps
CMTime targetDuration = CMTimeMake(1, fps);
// Check if within range
if (CMTimeCompare(targetDuration, minDuration) >= 0 &&
if (CMTimeCompare(targetDuration, minDuration) >= 0 &&
CMTimeCompare(targetDuration, maxDuration) <= 0) {
return targetDuration;
}
// Calculate difference with min value
double minDiffValue = fabs(CMTimeGetSeconds(targetDuration) - CMTimeGetSeconds(minDuration));
if (minDiffValue < minDiff) {
minDiff = minDiffValue;
nearestDuration = minDuration;
}
// Calculate difference with max value
double maxDiffValue = fabs(CMTimeGetSeconds(targetDuration) - CMTimeGetSeconds(maxDuration));
if (maxDiffValue < minDiff) {
@@ -896,7 +896,7 @@ static wpi::util::PixelFormat FourCCToPixelFormat(FourCharCode fourcc) {
}
OBJCDEBUG("Nearest fps: {}", nearestDuration.timescale / static_cast<double>(nearestDuration.value));
return nearestDuration;
}
@@ -1030,7 +1030,7 @@ static wpi::util::PixelFormat FourCCToPixelFormat(FourCharCode fourcc) {
} else {
OBJCINFO("UVC control initialized successfully");
}
self.uvcControl.cppImpl = self.cppImpl;
self.callback = [[UsbCameraDelegate alloc] init];

View File

@@ -136,7 +136,7 @@ void UsbCameraImpl::SetExposureManual(int value, CS_Status* status) {
}
bool UsbCameraImpl::SetVideoMode(const VideoMode& mode, CS_Status* status) {
if (mode.pixelFormat == wpi::util::PixelFormat::kUnknown) {
if (mode.pixelFormat == wpi::util::PixelFormat::UNKNOWN) {
*status = CS_UNSUPPORTED_MODE;
return false;
}
@@ -155,7 +155,7 @@ bool UsbCameraImpl::SetVideoMode(const VideoMode& mode, CS_Status* status) {
bool UsbCameraImpl::SetPixelFormat(wpi::util::PixelFormat pixelFormat,
CS_Status* status) {
if (pixelFormat == wpi::util::PixelFormat::kUnknown) {
if (pixelFormat == wpi::util::PixelFormat::UNKNOWN) {
*status = CS_UNSUPPORTED_MODE;
return false;
}
@@ -429,19 +429,19 @@ LRESULT UsbCameraImpl::PumpMain(HWND hwnd, UINT uiMsg, WPARAM wParam,
static wpi::util::PixelFormat GetFromGUID(const GUID& guid) {
// Compare GUID to one of the supported ones
if (IsEqualGUID(guid, MFVideoFormat_L8)) {
return wpi::util::PixelFormat::kGray;
return wpi::util::PixelFormat::GRAY;
} else if (IsEqualGUID(guid, MFVideoFormat_L16)) {
return wpi::util::PixelFormat::kY16;
return wpi::util::PixelFormat::Y16;
} else if (IsEqualGUID(guid, MFVideoFormat_YUY2)) {
return wpi::util::PixelFormat::kYUYV;
return wpi::util::PixelFormat::YUYV;
} else if (IsEqualGUID(guid, MFVideoFormat_MJPG)) {
return wpi::util::PixelFormat::kMJPEG;
return wpi::util::PixelFormat::MJPEG;
} else if (IsEqualGUID(guid, MFVideoFormat_RGB565)) {
return wpi::util::PixelFormat::kRGB565;
return wpi::util::PixelFormat::RGB565;
} else if (IsEqualGUID(guid, MFVideoFormat_UYVY)) {
return wpi::util::PixelFormat::kUYVY;
return wpi::util::PixelFormat::UYVY;
} else {
return wpi::util::PixelFormat::kUnknown;
return wpi::util::PixelFormat::UNKNOWN;
}
}
@@ -992,7 +992,7 @@ void UsbCameraImpl::DeviceCacheVideoModes() {
nativeType->GetGUID(MF_MT_SUBTYPE, &guid);
auto format = GetFromGUID(guid);
if (format == wpi::util::PixelFormat::kUnknown) {
if (format == wpi::util::PixelFormat::UNKNOWN) {
count++;
// Don't put in unknowns
continue;

View File

@@ -13,8 +13,8 @@ import org.wpilib.util.PixelFormat;
class VideoModeTest {
@Test
void equalityTest() {
VideoMode a = new VideoMode(PixelFormat.kMJPEG, 1920, 1080, 30);
VideoMode b = new VideoMode(PixelFormat.kMJPEG, 1920, 1080, 30);
VideoMode a = new VideoMode(PixelFormat.MJPEG, 1920, 1080, 30);
VideoMode b = new VideoMode(PixelFormat.MJPEG, 1920, 1080, 30);
assertEquals(a, b);
assertNotEquals(a, null);

View File

@@ -0,0 +1,19 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#include "wpi/cs/RawSource.hpp"
#include <gtest/gtest.h>
namespace wpi::cs {
TEST(RawSourceTest, CreateEmpty) {
RawSource source;
}
TEST(RawSourceTest, Create) {
RawSource source("test", wpi::util::PixelFormat::BGR, 640, 480, 30);
}
} // namespace wpi::cs

View File

@@ -7,23 +7,23 @@ package org.wpilib.util;
/** Image pixel format. */
public enum PixelFormat {
/** Unknown format. */
kUnknown(0),
UNKNOWN(0),
/** Motion-JPEG (compressed image data). */
kMJPEG(1),
MJPEG(1),
/** YUY 4:2:2, 16 bpp. */
kYUYV(2),
YUYV(2),
/** RGB 5-6-5, 16 bpp. */
kRGB565(3),
RGB565(3),
/** BGR 8-8-8, 24 bpp. */
kBGR(4),
BGR(4),
/** Grayscale, 8 bpp. */
kGray(5),
GRAY(5),
/** Grayscale, 16 bpp. */
kY16(6),
Y16(6),
/** YUV 4:2:2, 16 bpp. */
kUYVY(7),
UYVY(7),
/** BGRA 8-8-8-8. 32 bpp. */
kBGRA(8);
BGRA(8);
private final int value;

View File

@@ -17,7 +17,7 @@ public class RawFrame implements AutoCloseable {
private int m_width;
private int m_height;
private int m_stride;
private PixelFormat m_pixelFormat = PixelFormat.kUnknown;
private PixelFormat m_pixelFormat = PixelFormat.UNKNOWN;
private long m_time;
private TimestampSource m_timeSource = TimestampSource.kUnknown;

View File

@@ -12,15 +12,15 @@ namespace wpi::util {
* Pixel formats
*/
enum class PixelFormat {
kUnknown = WPI_PIXFMT_UNKNOWN,
kMJPEG = WPI_PIXFMT_MJPEG,
kYUYV = WPI_PIXFMT_YUYV,
kRGB565 = WPI_PIXFMT_RGB565,
kBGR = WPI_PIXFMT_BGR,
kGray = WPI_PIXFMT_GRAY,
kY16 = WPI_PIXFMT_Y16,
kUYVY = WPI_PIXFMT_UYVY,
kBGRA = WPI_PIXFMT_BGRA,
UNKNOWN = WPI_PIXFMT_UNKNOWN,
MJPEG = WPI_PIXFMT_MJPEG,
YUYV = WPI_PIXFMT_YUYV,
RGB565 = WPI_PIXFMT_RGB565,
BGR = WPI_PIXFMT_BGR,
GRAY = WPI_PIXFMT_GRAY,
Y16 = WPI_PIXFMT_Y16,
UYVY = WPI_PIXFMT_UYVY,
BGRA = WPI_PIXFMT_BGRA,
};
} // namespace wpi::util