diff options
| author | Tomi Valkeinen <tomi.valkeinen@ideasonboard.com> | 2022-10-04 10:09:53 +0300 |
|---|---|---|
| committer | Tomi Valkeinen <tomi.valkeinen@ideasonboard.com> | 2022-10-04 11:02:45 +0300 |
| commit | dfa9e526a43086a1b0936b74ec243f23396d5f69 (patch) | |
| tree | 6eb3f9dad18d4a6754a5d6722f30d82cb234c2a7 | |
| parent | 1bba3eca5ddbfa8fb7ed05994207b1c329ab58ee (diff) | |
v4l2: add DRMFourCCToPixelFormat
Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
| -rw-r--r-- | py/pyv4l2/pyv4l2.cpp | 2 | ||||
| -rw-r--r-- | v4l2++/inc/v4l2++/pixelformats.h | 2 | ||||
| -rw-r--r-- | v4l2++/src/pixelformats.cpp | 15 | ||||
| -rw-r--r-- | v4l2++/src/videodevice.cpp | 2 |
4 files changed, 18 insertions, 3 deletions
diff --git a/py/pyv4l2/pyv4l2.cpp b/py/pyv4l2/pyv4l2.cpp index ec96835..fd3982f 100644 --- a/py/pyv4l2/pyv4l2.cpp +++ b/py/pyv4l2/pyv4l2.cpp @@ -150,4 +150,6 @@ PYBIND11_MODULE(pyv4l2, m) m.def("fourcc_to_pixelformat", &FourCCToPixelFormat); + m.def("pixelformat_to_fourcc", &PixelFormatToFourCC); + m.def("drm_fourcc_to_pixelformat", &DRMFourCCToPixelFormat); } diff --git a/v4l2++/inc/v4l2++/pixelformats.h b/v4l2++/inc/v4l2++/pixelformats.h index 609ff4f..c7eda25 100644 --- a/v4l2++/inc/v4l2++/pixelformats.h +++ b/v4l2++/inc/v4l2++/pixelformats.h @@ -78,6 +78,8 @@ static inline PixelFormat FourCCToPixelFormat(const std::string& fourcc) return (PixelFormat)MakeFourCC(fourcc.c_str()); } +PixelFormat DRMFourCCToPixelFormat(const std::string& fourcc); + static inline std::string PixelFormatToFourCC(PixelFormat f) { char buf[5] = { (char)(((uint32_t)f >> 0) & 0xff), diff --git a/v4l2++/src/pixelformats.cpp b/v4l2++/src/pixelformats.cpp index 1c8453f..b7ecc7b 100644 --- a/v4l2++/src/pixelformats.cpp +++ b/v4l2++/src/pixelformats.cpp @@ -290,10 +290,23 @@ static const map<PixelFormat, PixelFormatInfo> format_info_array = { } }, }; +PixelFormat DRMFourCCToPixelFormat(const std::string& fourcc) +{ + // Handle the formats which differ between DRM and V4L2 + if (fourcc == "RG16") + return PixelFormat::RGB565; + if (fourcc == "XR24") + return PixelFormat::XRGB8888; + if (fourcc == "RG24") + return PixelFormat::RGB888; + + return FourCCToPixelFormat(fourcc); +} + const struct PixelFormatInfo& get_pixel_format_info(PixelFormat format) { if (!format_info_array.count(format)) - throw invalid_argument("get_pixel_format_info: Unsupported pixelformat"); + throw invalid_argument("v4l2: get_pixel_format_info: Unsupported pixelformat"); return format_info_array.at(format); } diff --git a/v4l2++/src/videodevice.cpp b/v4l2++/src/videodevice.cpp index 5ab7099..858b82b 100644 --- a/v4l2++/src/videodevice.cpp +++ b/v4l2++/src/videodevice.cpp @@ -133,8 +133,6 @@ static void v4l2_set_format(int fd, PixelFormat fmt, uint32_t width, uint32_t he ASSERT(p.sizeimage == p.bytesperline * height / pfpi.ysub); } } else { - ASSERT(pfi.num_planes == 1); - v4lfmt.fmt.pix.pixelformat = (uint32_t)fmt; v4lfmt.fmt.pix.width = width; v4lfmt.fmt.pix.height = height; |
