Skip to content

Commit 15c305b

Browse files
authored
RGB24 and BGR24 cleanup (#1749)
* RGB24 and BGR24 cleanup * Fix MF-Grabber * Add BGR32 to V42L Grabber * Add BGR32 to V42L Grabber * Add BGR16 to V42L * Revert "Add BGR16 to V42L" This reverts commit 4297538.
1 parent 76fff98 commit 15c305b

File tree

4 files changed

+62
-12
lines changed

4 files changed

+62
-12
lines changed

include/utils/PixelFormat.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ enum class PixelFormat {
1010
YUYV,
1111
UYVY,
1212
BGR16,
13+
RGB24,
1314
BGR24,
1415
RGB32,
1516
BGR32,
@@ -36,6 +37,10 @@ inline PixelFormat parsePixelFormat(const QString& pixelFormat)
3637
{
3738
return PixelFormat::BGR16;
3839
}
40+
else if (format.compare("rgb24") == 0)
41+
{
42+
return PixelFormat::RGB24;
43+
}
3944
else if (format.compare("bgr24") == 0)
4045
{
4146
return PixelFormat::BGR24;
@@ -80,6 +85,10 @@ inline QString pixelFormatToString(const PixelFormat& pixelFormat)
8085
{
8186
return "BGR16";
8287
}
88+
else if (pixelFormat == PixelFormat::RGB24)
89+
{
90+
return "RGB24";
91+
}
8392
else if (pixelFormat == PixelFormat::BGR24)
8493
{
8594
return "BGR24";

libsrc/grabber/video/mediafoundation/MFSourceReaderCB.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
static PixelFormat GetPixelFormatForGuid(const GUID guid)
2828
{
2929
if (IsEqualGUID(guid, MFVideoFormat_RGB32)) return PixelFormat::RGB32;
30-
if (IsEqualGUID(guid, MFVideoFormat_RGB24)) return PixelFormat::BGR24;
30+
if (IsEqualGUID(guid, MFVideoFormat_RGB24)) return PixelFormat::RGB24;
3131
if (IsEqualGUID(guid, MFVideoFormat_YUY2)) return PixelFormat::YUYV;
3232
if (IsEqualGUID(guid, MFVideoFormat_UYVY)) return PixelFormat::UYVY;
3333
#ifdef HAVE_TURBO_JPEG
@@ -145,9 +145,9 @@ class SourceReaderCB : public IMFSourceReaderCallback
145145
}
146146

147147
#ifdef HAVE_TURBO_JPEG
148-
if (_pixelformat != PixelFormat::MJPEG && _pixelformat != PixelFormat::BGR24 && _pixelformat != PixelFormat::NO_CHANGE)
148+
if (_pixelformat != PixelFormat::MJPEG && _pixelformat != PixelFormat::RGB24 && _pixelformat != PixelFormat::NO_CHANGE)
149149
#else
150-
if (_pixelformat != PixelFormat::BGR24 && _pixelformat != PixelFormat::NO_CHANGE)
150+
if (_pixelformat != PixelFormat::RGB24 && _pixelformat != PixelFormat::NO_CHANGE)
151151
#endif
152152
pSample = TransformSample(_transform, pSample);
153153

@@ -181,9 +181,9 @@ class SourceReaderCB : public IMFSourceReaderCallback
181181
_bEOS = TRUE; // Reached the end of the stream.
182182

183183
#ifdef HAVE_TURBO_JPEG
184-
if (_pixelformat != PixelFormat::MJPEG && _pixelformat != PixelFormat::BGR24 && _pixelformat != PixelFormat::NO_CHANGE)
184+
if (_pixelformat != PixelFormat::MJPEG && _pixelformat != PixelFormat::RGB24 && _pixelformat != PixelFormat::NO_CHANGE)
185185
#else
186-
if (_pixelformat != PixelFormat::BGR24 && _pixelformat != PixelFormat::NO_CHANGE)
186+
if (_pixelformat != PixelFormat::RGB24 && _pixelformat != PixelFormat::NO_CHANGE)
187187
#endif
188188
SAFE_RELEASE(pSample);
189189

@@ -196,9 +196,9 @@ class SourceReaderCB : public IMFSourceReaderCallback
196196
{
197197
_pixelformat = format;
198198
#ifdef HAVE_TURBO_JPEG
199-
if (format == PixelFormat::MJPEG || format == PixelFormat::BGR24 || format == PixelFormat::NO_CHANGE)
199+
if (format == PixelFormat::MJPEG || format == PixelFormat::RGB24 || format == PixelFormat::NO_CHANGE)
200200
#else
201-
if (format == PixelFormat::BGR24 || format == PixelFormat::NO_CHANGE)
201+
if (format == PixelFormat::RGB24 || format == PixelFormat::NO_CHANGE)
202202
#endif
203203
return S_OK;
204204

@@ -392,10 +392,10 @@ class SourceReaderCB : public IMFSourceReaderCallback
392392
private:
393393
long _nRefCount;
394394
CRITICAL_SECTION _critsec;
395-
MFGrabber* _grabber;
395+
MFGrabber* _grabber;
396396
BOOL _bEOS;
397397
HRESULT _hrStatus;
398-
IMFTransform* _transform;
398+
IMFTransform* _transform;
399399
PixelFormat _pixelformat;
400400
std::atomic<bool> _isBusy;
401401
};

libsrc/grabber/video/v4l2/V4L2Grabber.cpp

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ Q_GLOBAL_STATIC_WITH_ARGS(ControlIDPropertyMap, _controlIDPropertyMap, (initCont
5454
static PixelFormat GetPixelFormat(const unsigned int format)
5555
{
5656
if (format == V4L2_PIX_FMT_RGB32) return PixelFormat::RGB32;
57+
if (format == V4L2_PIX_FMT_BGR32) return PixelFormat::BGR32;
58+
if (format == V4L2_PIX_FMT_RGB24) return PixelFormat::RGB24;
5759
if (format == V4L2_PIX_FMT_BGR24) return PixelFormat::BGR24;
5860
if (format == V4L2_PIX_FMT_YUYV) return PixelFormat::YUYV;
5961
if (format == V4L2_PIX_FMT_UYVY) return PixelFormat::UYVY;
@@ -557,6 +559,14 @@ void V4L2Grabber::init_device(VideoStandard videoStandard)
557559
fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_RGB32;
558560
break;
559561

562+
case PixelFormat::BGR32:
563+
fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_BGR32;
564+
break;
565+
566+
case PixelFormat::RGB24:
567+
fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_RGB24;
568+
break;
569+
560570
case PixelFormat::BGR24:
561571
fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_BGR24;
562572
break;
@@ -691,6 +701,22 @@ void V4L2Grabber::init_device(VideoStandard videoStandard)
691701
}
692702
break;
693703

704+
case V4L2_PIX_FMT_BGR32:
705+
{
706+
_pixelFormat = PixelFormat::BGR32;
707+
_frameByteSize = _width * _height * 4;
708+
Debug(_log, "Pixel format=BGR32");
709+
}
710+
break;
711+
712+
case V4L2_PIX_FMT_RGB24:
713+
{
714+
_pixelFormat = PixelFormat::RGB24;
715+
_frameByteSize = _width * _height * 3;
716+
Debug(_log, "Pixel format=RGB24");
717+
}
718+
break;
719+
694720
case V4L2_PIX_FMT_BGR24:
695721
{
696722
_pixelFormat = PixelFormat::BGR24;
@@ -699,7 +725,6 @@ void V4L2Grabber::init_device(VideoStandard videoStandard)
699725
}
700726
break;
701727

702-
703728
case V4L2_PIX_FMT_YUYV:
704729
{
705730
_pixelFormat = PixelFormat::YUYV;
@@ -743,9 +768,9 @@ void V4L2Grabber::init_device(VideoStandard videoStandard)
743768

744769
default:
745770
#ifdef HAVE_TURBO_JPEG
746-
throw_exception("Only pixel formats RGB32, BGR24, YUYV, UYVY, NV12, I420 and MJPEG are supported");
771+
throw_exception("Only pixel formats RGB32, BGR32, RGB24, BGR24, YUYV, UYVY, NV12, I420 and MJPEG are supported");
747772
#else
748-
throw_exception("Only pixel formats RGB32, BGR24, YUYV, UYVY, NV12 and I420 are supported");
773+
throw_exception("Only pixel formats RGB32, BGR32, RGB24, BGR24, YUYV, UYVY, NV12 and I420 are supported");
749774
#endif
750775
return;
751776
}

libsrc/utils/ImageResampler.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,22 @@ void ImageResampler::processImage(const uint8_t * data, int width, int height, i
133133
break;
134134
}
135135

136+
case PixelFormat::RGB24:
137+
{
138+
for (int yDest = yDestStart, ySource = cropTop + (_verticalDecimation >> 1); yDest <= yDestEnd; ySource += _verticalDecimation, ++yDest)
139+
{
140+
for (int xDest = xDestStart, xSource = cropLeft + (_horizontalDecimation >> 1); xDest <= xDestEnd; xSource += _horizontalDecimation, ++xDest)
141+
{
142+
ColorRgb & rgb = outputImage(abs(xDest), abs(yDest));
143+
int index = lineLength * ySource + (xSource << 1) + xSource;
144+
rgb.red = data[index ];
145+
rgb.green = data[index+1];
146+
rgb.blue = data[index+2];
147+
}
148+
}
149+
break;
150+
}
151+
136152
case PixelFormat::BGR24:
137153
{
138154
for (int yDest = yDestStart, ySource = cropTop + (_verticalDecimation >> 1); yDest <= yDestEnd; ySource += _verticalDecimation, ++yDest)

0 commit comments

Comments
 (0)