58#define MOD_NAME "[logo] "
73 if (strcasecmp(filename + (
MAX(strlen(filename), 4) - 4),
".pam") == 0) {
77 if (!
pam_read(filename, &info, &data, malloc)) {
80 s->
width = info.width;
82 if (info.depth != 3 && info.depth != 4) {
87 rgb = info.depth == 3;
91 unsigned char * tmp = malloc(datalen);
113 if (strlen(cfg) == 0 || strcasecmp(cfg,
"help") == 0) {
114 printf(
"Draws overlay logo over video:\n\n");
115 printf(
"'logo' usage:\n");
116 printf(
"\tlogo:<file>[:<x>[:<y>]]\n");
117 printf(
"\t\t<file> - is path to logo to be added in PAM format with alpha\n");
121 char *tmp = strdup(cfg);
122 char *save_ptr = NULL;
124 if ((
item = strtok_r(tmp,
":", &save_ptr)) == NULL) {
125 fprintf(stderr,
"File name with logo required!\n");
133 if ((
item = strtok_r(NULL,
":", &save_ptr))) {
135 if ((
item = strtok_r(NULL,
":", &save_ptr))) {
165 if (decoder == NULL) {
166 MSG(ERROR,
"Cannot find decoder from %s to RGB!\n",
171 MSG(ERROR,
"Cannot find encoder from %s to RGB!\n",
174 if (decoder == NULL || coder == NULL)
190 if (rect_x < 0 || rect_y < 0)
193 int dec_width = s->
width;
195 int linesize = dec_width * 3;
197 unsigned char *segment = (
unsigned char *) malloc(linesize * s->
height);
199 for (
unsigned int y = 0;
y < s->
height; ++
y) {
200 decoder(segment +
y * linesize, (
unsigned char *) in->
tiles[0].
data + (
y + rect_y) *
206 const unsigned char *overlay_data = s->
logo;
207 for (
unsigned int y = 0;
y < s->
height; ++
y) {
208 unsigned char *image_data = segment +
y * linesize;
209 for (
unsigned int x = 0;
x < s->
width; ++
x) {
210 int alpha = overlay_data[3];
211 for (
int i = 0; i < 3; ++i) {
212 *image_data = (*image_data * (255 - alpha) + *overlay_data++ * alpha) / 255;
219 for (
unsigned int y = 0;
y < s->
height; ++
y) {
220 coder((
unsigned char *) in->
tiles[0].
data + (rect_y +
y) *
223 segment +
y * linesize,
int vc_get_linesize(unsigned int width, codec_t codec)
const char * get_codec_name(codec_t codec)
#define CAPTURE_FILTER_ABI_VERSION
void log_msg(int level, const char *format,...)
#define LOG_LEVEL_ERROR
general errors
@ LIBRARY_CLASS_CAPTURE_FILTER
#define REGISTER_MODULE(name, info, lclass, abi)
Registers module to global modules' registry.
static struct video_frame * filter(void *state, struct video_frame *in)
static const struct capture_filter_info capture_filter_logo
static bool load_logo_data_from_file(struct state_capture_filter_logo *s, const char *filename)
static void done(void *state)
static int init(struct module *parent, const char *cfg, void **state)
bool pam_read(const char *filename, struct pam_metadata *info, unsigned char **data, void *(*allocator)(size_t))
decoder_t get_decoder_from_to(codec_t in, codec_t out)
decoder_func_t vc_copylineRGBtoRGBA
decoder_func_t * decoder_t
char * data
Raw tile data. Pointer must be at least 4B aligned.
Struct video_frame represents a video frame and contains video description.
struct tile tiles[FLEXIBLE_ARRAY_MEMBER]
@ RGB
RGB 8-bit (packed into 24-bit word)
int get_pf_block_bytes(codec_t codec)
returns codec_info_t::block_size_bytes