From bc231917d811e4a6661fc0b01b3e3750c6babd59 Mon Sep 17 00:00:00 2001 From: Kamil Trzcinski Date: Mon, 27 Nov 2023 22:21:18 +0100 Subject: [PATCH] libcamera: support `transform` to `orientation` rename --- Makefile | 16 +++++++++++----- device/libcamera/buffer_list.cc | 10 ++++++++++ device/libcamera/libcamera.hh | 5 +++++ tests/libcamera/orientation.cc | 1 + 4 files changed, 27 insertions(+), 5 deletions(-) create mode 100644 tests/libcamera/orientation.cc diff --git a/Makefile b/Makefile index 3c301e6..8d955d4 100644 --- a/Makefile +++ b/Makefile @@ -61,6 +61,7 @@ endif HTML_SRC = $(addsuffix .c,$(HTML)) OBJS = $(patsubst %.cc,%.o,$(patsubst %.c,%.o,$(SRC) $(HTML_SRC))) +TARGET_OBJS = $(filter-out third_party/%, $(filter-out tests/%, $(OBJS))) all: version +make $(TARGET) @@ -73,11 +74,16 @@ endif .PHONY: version version: - echo "#define GIT_VERSION \"$(GIT_VERSION)\"\n#define GIT_REVISION \"$(GIT_REVISION)\"" > version.h.tmp; \ - diff -u version.h version.h.tmp || mv version.h.tmp version.h; \ - rm -f version.h.tmp - -%: cmd/% $(filter-out third_party/%, $(OBJS)) + echo "#define GIT_VERSION \"$(GIT_VERSION)\"\n#define GIT_REVISION \"$(GIT_REVISION)\"" > version.h.tmp + if $(CXX) $(CFLAGS) -o /dev/null -c tests/libcamera/orientation.cc 2>/dev/null; then \ + echo "#define LIBCAMERA_USES_ORIENTATION" >> version.h.tmp; \ + else \ + echo "#define LIBCAMERA_USES_TRANSFORM" >> version.h.tmp; \ + fi + diff -u version.h version.h.tmp || mv version.h.tmp version.h + -rm -f version.h.tmp + +%: cmd/% $(TARGET_OBJS) $(CCACHE) $(CXX) $(CFLAGS) -o $@ $(filter-out cmd/%, $^) $(filter $validate() == libcamera::CameraConfiguration::Invalid) { LOG_ERROR(buf_list, "Camera configuration invalid"); } +#ifdef LIBCAMERA_USES_ORIENTATION + if (buf_list->dev->libcamera->vflip && buf_list->dev->libcamera->hflip) { + configurations->orientation = libcamera::Orientation::Rotate180; + } else if (buf_list->dev->libcamera->vflip) { + configurations->orientation = libcamera::Orientation::Rotate180Mirror; + } else if (buf_list->dev->libcamera->hflip) { + configurations->orientation = libcamera::Orientation::Rotate0Mirror; + } +#else // LIBCAMERA_USES_ORIENTATION if (buf_list->dev->libcamera->vflip) { configurations->transform |= libcamera::Transform::VFlip; } @@ -108,6 +117,7 @@ int libcamera_buffer_list_open(buffer_list_t *buf_list) if (!!(configurations->transform & libcamera::Transform::Transpose)) { LOG_ERROR(buf_list, "Transformation requiring transpose not supported"); } +#endif // LIBCAMERA_USES_ORIENTATION if (buf_list->dev->libcamera->camera->configure(configurations.get()) < 0) { LOG_ERROR(buf_list, "Failed to configure camera"); diff --git a/device/libcamera/libcamera.hh b/device/libcamera/libcamera.hh index 723c7ce..67b380b 100644 --- a/device/libcamera/libcamera.hh +++ b/device/libcamera/libcamera.hh @@ -7,6 +7,7 @@ extern "C" { #include #include +#include "version.h" #include "device/device.h" #include "device/buffer_list.h" #include "device/buffer.h" @@ -29,7 +30,11 @@ extern "C" { #include #include #include +#ifdef LIBCAMERA_USES_ORIENTATION +#include +#else // LIBCAMERA_USES_ORIENTATION #include +#endif // LIBCAMERA_USES_ORIENTATION typedef struct buffer_s buffer_t; typedef struct buffer_list_s buffer_list_t; diff --git a/tests/libcamera/orientation.cc b/tests/libcamera/orientation.cc new file mode 100644 index 0000000..28247d6 --- /dev/null +++ b/tests/libcamera/orientation.cc @@ -0,0 +1 @@ +#include