Skip to content

Commit bc23191

Browse files
committed
libcamera: support transform to orientation rename
1 parent 3c116f2 commit bc23191

File tree

4 files changed

+27
-5
lines changed

4 files changed

+27
-5
lines changed

Makefile

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ endif
6161

6262
HTML_SRC = $(addsuffix .c,$(HTML))
6363
OBJS = $(patsubst %.cc,%.o,$(patsubst %.c,%.o,$(SRC) $(HTML_SRC)))
64+
TARGET_OBJS = $(filter-out third_party/%, $(filter-out tests/%, $(OBJS)))
6465

6566
all: version
6667
+make $(TARGET)
@@ -73,11 +74,16 @@ endif
7374

7475
.PHONY: version
7576
version:
76-
echo "#define GIT_VERSION \"$(GIT_VERSION)\"\n#define GIT_REVISION \"$(GIT_REVISION)\"" > version.h.tmp; \
77-
diff -u version.h version.h.tmp || mv version.h.tmp version.h; \
78-
rm -f version.h.tmp
79-
80-
%: cmd/% $(filter-out third_party/%, $(OBJS))
77+
echo "#define GIT_VERSION \"$(GIT_VERSION)\"\n#define GIT_REVISION \"$(GIT_REVISION)\"" > version.h.tmp
78+
if $(CXX) $(CFLAGS) -o /dev/null -c tests/libcamera/orientation.cc 2>/dev/null; then \
79+
echo "#define LIBCAMERA_USES_ORIENTATION" >> version.h.tmp; \
80+
else \
81+
echo "#define LIBCAMERA_USES_TRANSFORM" >> version.h.tmp; \
82+
fi
83+
diff -u version.h version.h.tmp || mv version.h.tmp version.h
84+
-rm -f version.h.tmp
85+
86+
%: cmd/% $(TARGET_OBJS)
8187
$(CCACHE) $(CXX) $(CFLAGS) -o $@ $(filter-out cmd/%, $^) $(filter $</%, $^) $(LDLIBS)
8288

8389
install: $(TARGET)

device/libcamera/buffer_list.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,15 @@ int libcamera_buffer_list_open(buffer_list_t *buf_list)
9999
if (configurations->validate() == libcamera::CameraConfiguration::Invalid) {
100100
LOG_ERROR(buf_list, "Camera configuration invalid");
101101
}
102+
#ifdef LIBCAMERA_USES_ORIENTATION
103+
if (buf_list->dev->libcamera->vflip && buf_list->dev->libcamera->hflip) {
104+
configurations->orientation = libcamera::Orientation::Rotate180;
105+
} else if (buf_list->dev->libcamera->vflip) {
106+
configurations->orientation = libcamera::Orientation::Rotate180Mirror;
107+
} else if (buf_list->dev->libcamera->hflip) {
108+
configurations->orientation = libcamera::Orientation::Rotate0Mirror;
109+
}
110+
#else // LIBCAMERA_USES_ORIENTATION
102111
if (buf_list->dev->libcamera->vflip) {
103112
configurations->transform |= libcamera::Transform::VFlip;
104113
}
@@ -108,6 +117,7 @@ int libcamera_buffer_list_open(buffer_list_t *buf_list)
108117
if (!!(configurations->transform & libcamera::Transform::Transpose)) {
109118
LOG_ERROR(buf_list, "Transformation requiring transpose not supported");
110119
}
120+
#endif // LIBCAMERA_USES_ORIENTATION
111121

112122
if (buf_list->dev->libcamera->camera->configure(configurations.get()) < 0) {
113123
LOG_ERROR(buf_list, "Failed to configure camera");

device/libcamera/libcamera.hh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ extern "C" {
77
#include <stdint.h>
88
#include <stdlib.h>
99

10+
#include "version.h"
1011
#include "device/device.h"
1112
#include "device/buffer_list.h"
1213
#include "device/buffer.h"
@@ -29,7 +30,11 @@ extern "C" {
2930
#include <libcamera/request.h>
3031
#include <libcamera/stream.h>
3132
#include <libcamera/formats.h>
33+
#ifdef LIBCAMERA_USES_ORIENTATION
34+
#include <libcamera/orientation.h>
35+
#else // LIBCAMERA_USES_ORIENTATION
3236
#include <libcamera/transform.h>
37+
#endif // LIBCAMERA_USES_ORIENTATION
3338

3439
typedef struct buffer_s buffer_t;
3540
typedef struct buffer_list_s buffer_list_t;

tests/libcamera/orientation.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#include <libcamera/orientation.h>

0 commit comments

Comments
 (0)