mirror of
https://github.com/Harshit-Dhanwalkar/AsciiCam.git
synced 2026-06-15 10:45:13 +02:00
Work on support for MacOS
This commit is contained in:
parent
5f98c5b633
commit
49b58febba
8 changed files with 73 additions and 29 deletions
50
C/Makefile
50
C/Makefile
|
|
@ -1,19 +1,31 @@
|
|||
CC = gcc
|
||||
CFLAGS = -Wall -Wextra -O2 -Iinclude -Ilib -fno-stack-protector
|
||||
# LDFLAGS = -lm
|
||||
LDFLAGS += -nostdlib # drops crt startup files and default libs
|
||||
# LDFLAGS += -nodefaultlibs # drops default libs but keeps crt startup files
|
||||
LDFLAGS += -Wl,--no-as-needed
|
||||
# LDFLAGS += -Wl,-rpath,/lib/x86_64-linux-gnu # for libdl.so # TEST:
|
||||
# LDFLAGS += /lib/x86_64-linux-gnu/libdl.so.2
|
||||
LDFLAGS += -Wl,-dynamic-linker,/lib64/ld-linux-x86-64.so.2
|
||||
LDFLAGS += /usr/lib/x86_64-linux-gnu/crti.o
|
||||
LDFLAGS += /usr/lib/x86_64-linux-gnu/crtn.o
|
||||
LDFLAGS += -ldl # Dynamic loading symbols
|
||||
LDFLAGS += -lpthread # Multi-threaded capture-render, pthreads producer/consumer
|
||||
LDFLAGS += -lc
|
||||
LDFLAGS += -msse4.1 # SIMD - SSE2 for the YUYV to gray conversion
|
||||
# LDFLAGS += -static
|
||||
CFLAGS = -Wall -Wextra -O2 -Iinclude -Ilib
|
||||
|
||||
UNAME_S := $(shell uname -s)
|
||||
ifeq ($(UNAME_S),Linux)
|
||||
CFLAGS += -fno-stack-protector -D__LINUX_NOLIBC__
|
||||
# LDFLAGS = -lm
|
||||
LDFLAGS += -nostdlib # drops crt startup files and default libs
|
||||
# LDFLAGS += -nodefaultlibs # drops default libs but keeps crt startup files
|
||||
LDFLAGS += -Wl,--no-as-needed
|
||||
LDLIBS := -ldl -lpthread -lc
|
||||
# LDFLAGS += -Wl,-rpath,/lib/x86_64-linux-gnu
|
||||
# LDFLAGS += /lib/x86_64-linux-gnu/libdl.so.2
|
||||
LDFLAGS += -Wl,-dynamic-linker,/lib64/ld-linux-x86-64.so.2
|
||||
LDFLAGS += /usr/lib/x86_64-linux-gnu/crti.o
|
||||
LDFLAGS += /usr/lib/x86_64-linux-gnu/crtn.o
|
||||
LDFLAGS += -ldl # Dynamic loading symbols
|
||||
LDFLAGS += -lpthread # Multi-threaded capture-render, pthreads producer/consumer
|
||||
LDFLAGS += -lc
|
||||
LDFLAGS += -msse4.1 # SIMD - SSE2 for the YUYV to gray conversion
|
||||
# LDFLAGS += -static
|
||||
LIBSRCS = $(wildcard lib/*.c)
|
||||
else ifeq ($(UNAME_S),Darwin)
|
||||
CFLAGS +=
|
||||
LDFLAGS +=
|
||||
LDLIBS :=
|
||||
LIBSRCS =
|
||||
endif
|
||||
|
||||
SRCDIR = src
|
||||
INCDIR = include
|
||||
|
|
@ -21,10 +33,10 @@ LIBDIR = lib
|
|||
BUILDDIR = build
|
||||
OBJDIR = $(BUILDDIR)/obj
|
||||
|
||||
LIBSRCS = $(wildcard $(LIBDIR)/*.c)
|
||||
SOURCES = $(wildcard $(SRCDIR)/*.c) $(LIBSRCS)
|
||||
OBJECTS = $(patsubst $(SRCDIR)/%.c,$(OBJDIR)/%.o,$(SOURCES))
|
||||
TARGET = $(BUILDDIR)/webcam_ascii
|
||||
LIBSRCS = $(wildcard $(LIBDIR)/*.c)
|
||||
SOURCES = $(wildcard $(SRCDIR)/*.c) $(LIBSRCS)
|
||||
OBJECTS = $(patsubst $(SRCDIR)/%.c,$(OBJDIR)/%.o,$(SOURCES))
|
||||
TARGET = $(BUILDDIR)/webcam_ascii
|
||||
PLUGIN_SRCS = $(wildcard filters/*.c)
|
||||
PLUGIN_C_SRCS = $(filter-out filters/%.h, $(PLUGIN_SRCS))
|
||||
PLUGIN_TARGETS = $(patsubst filters/%.c,$(BUILDDIR)/%.so,$(PLUGIN_C_SRCS))
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
#ifndef NL_ALLOC_H
|
||||
#define NL_ALLOC_H
|
||||
|
||||
#ifdef __LINUX_NOLIBC__
|
||||
#include <stddef.h>
|
||||
|
||||
void *nl_malloc(size_t n);
|
||||
|
|
@ -11,4 +12,8 @@ void nl_free(void *ptr);
|
|||
#define calloc(nm, sz) nl_calloc(nm, sz)
|
||||
#define free(p) nl_free(p)
|
||||
|
||||
#else // MACOS
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -6,9 +6,10 @@
|
|||
inotify
|
||||
*/
|
||||
|
||||
#include "nl_syscall.h"
|
||||
#include <time.h>
|
||||
|
||||
#ifdef __LINUX_NOLIBC__
|
||||
#include "nl_syscall.h"
|
||||
/* Basic I/O */
|
||||
static inline ssize_t nl_write(int fd, const void *buf, size_t n) {
|
||||
return (ssize_t)__sc3(SYS_write, fd, (long)buf, (long)n);
|
||||
|
|
@ -121,4 +122,10 @@ static inline int nl_tcsetattr(int fd, int action, const struct termios *t) {
|
|||
#define inotify_init1(f) nl_inotify_init1(f)
|
||||
#define inotify_add_watch(f, p, m) nl_inotify_add_watch(f, p, m)
|
||||
|
||||
#else
|
||||
// #include <sys/mmap.h>
|
||||
#include <sys/select.h>
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
#include "nl_printf.h"
|
||||
// #include "nolibc.h"
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
|
||||
|
|
|
|||
|
|
@ -31,7 +31,8 @@ static inline int nl_fmt_fps(char *buf, size_t sz, double fps) {
|
|||
char _fb[1024]; \
|
||||
int _fn = nl_snprintf(_fb, sizeof(_fb), fmt, ##__VA_ARGS__); \
|
||||
if (_fn > 0) { \
|
||||
size_t _nwrite = (_fn < (int)sizeof(_fb) - 1) ? _fn : sizeof(_fb) - 1; \
|
||||
size_t _nwrite = \
|
||||
(_fn < (int)sizeof(_fb) - 1) ? (size_t)_fn : sizeof(_fb) - 1; \
|
||||
nl_write((int)(long)(fd), _fb, _nwrite); \
|
||||
} \
|
||||
} while (0)
|
||||
|
|
|
|||
|
|
@ -12,10 +12,15 @@ static inline size_t nl_strlen(const char *s) {
|
|||
}
|
||||
|
||||
static inline void *nl_memcpy(void *dst, const void *src, size_t n) {
|
||||
uint8_t *d = (uint8_t *)dst;
|
||||
const uint8_t *s = (const uint8_t *)src;
|
||||
while (n--)
|
||||
*d++ = *s++;
|
||||
// uint8_t *d = (uint8_t *)dst;
|
||||
// const uint8_t *s = (const uint8_t *)src;
|
||||
// while (n--)
|
||||
// *d++ = *s++;
|
||||
unsigned char *d = (unsigned char *)dst;
|
||||
const unsigned char *s = (const unsigned char *)src;
|
||||
for (size_t i = 0; i < n; i++) {
|
||||
d[i] = s[i];
|
||||
}
|
||||
return dst;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
#include "ascii.h"
|
||||
|
||||
#include <immintrin.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "nolibc.h"
|
||||
|
|
@ -9,11 +8,12 @@
|
|||
static inline uint8_t clamp_u8(int v) {
|
||||
return (v < 0) ? 0 : (v > 255) ? 255 : (uint8_t)v;
|
||||
}
|
||||
static inline int my_abs(int x) {
|
||||
return x < 0 ? -x : x;
|
||||
}
|
||||
static inline int my_abs(int x) { return x < 0 ? -x : x; }
|
||||
|
||||
// Image conversion
|
||||
#ifdef __x86_64__
|
||||
#include <immintrin.h>
|
||||
|
||||
void yuyv_to_gray_simd(const uint8_t *yuyv, uint8_t *gray, int width,
|
||||
int height) {
|
||||
int total_pixels = width * height;
|
||||
|
|
@ -36,6 +36,15 @@ void yuyv_to_gray_simd(const uint8_t *yuyv, uint8_t *gray, int width,
|
|||
for (; i < total_pixels; i++)
|
||||
gray[i] = yuyv[i * 2];
|
||||
}
|
||||
#else
|
||||
void yuyv_to_gray_simd(const uint8_t *yuyv, uint8_t *gray, int width,
|
||||
int height) {
|
||||
int total = width * height;
|
||||
for (int i = 0; i < total; i++) {
|
||||
gray[i] = yuyv[i * 2];
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void yuyv_to_rgb(const uint8_t *yuyv, uint8_t *rgb, int width, int height) {
|
||||
int pairs = (width * height) / 2;
|
||||
|
|
|
|||
|
|
@ -105,6 +105,10 @@ gcc -O2 -fPIC -shared -Iinclude filters/my_filter.c -o build/my_filter.so
|
|||
- [ ] Replace `pthread` with raw `futex` syscalls
|
||||
- [ ] Replace `dlopen` with a minimal ELF loader
|
||||
|
||||
## Fixes
|
||||
- [ ] [Issue #2](https://github.com/Harshit-Dhanwalkar/AsciiCam/issues/2) MacOS support
|
||||
- Rewrite `capture.c` for MacOS port using [AVFoundation](https://developer.apple.com/library/archive/documentation/AudioVideo/Conceptual/AVFoundationPG/Articles/04_MediaCapture.html). ([Stackoverflow : how do I set up a video input using the AVFoundation framework](https://stackoverflow.com/questions/32053460/how-do-i-set-up-a-video-input-using-the-avfoundation-framework))
|
||||
|
||||
---
|
||||
|
||||
Project is under [PolyForm Noncommercial License BY-NC](LICENCE).
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue