Skip to content

Commit

Permalink
libcamera: support transform to orientation rename
Browse files Browse the repository at this point in the history
  • Loading branch information
ayufan committed Nov 27, 2023
1 parent 3c116f2 commit bc23191
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
16 changes: 11 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 $</%, $^) $(LDLIBS)

install: $(TARGET)
Expand Down
10 changes: 10 additions & 0 deletions device/libcamera/buffer_list.cc
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,15 @@ int libcamera_buffer_list_open(buffer_list_t *buf_list)
if (configurations->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;
}
Expand All @@ -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");
Expand Down
5 changes: 5 additions & 0 deletions device/libcamera/libcamera.hh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ extern "C" {
#include <stdint.h>
#include <stdlib.h>

#include "version.h"
#include "device/device.h"
#include "device/buffer_list.h"
#include "device/buffer.h"
Expand All @@ -29,7 +30,11 @@ extern "C" {
#include <libcamera/request.h>
#include <libcamera/stream.h>
#include <libcamera/formats.h>
#ifdef LIBCAMERA_USES_ORIENTATION
#include <libcamera/orientation.h>
#else // LIBCAMERA_USES_ORIENTATION
#include <libcamera/transform.h>
#endif // LIBCAMERA_USES_ORIENTATION

typedef struct buffer_s buffer_t;
typedef struct buffer_list_s buffer_list_t;
Expand Down
1 change: 1 addition & 0 deletions tests/libcamera/orientation.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include <libcamera/orientation.h>

0 comments on commit bc23191

Please sign in to comment.