static struct flipctx * ctx_init(xmlNodePtr node) { struct flipctx *ctx; char *cont; ctx = malloc(sizeof(*ctx)); memset(ctx, 0, sizeof(*ctx)); for (node = node->xml_children; node; node = node->next) { if (xml_isnode(node, "horiz")) { cont = xml_getcontent(node); if (cont && (!strcmp(cont, "yes") || !strcmp(cont, "on") || !strcmp(cont, "1"))) ctx->h = 1; } else if (xml_isnode(node, "vert")) { cont = xml_getcontent(node); if (cont && (!strcmp(cont, "yes") || !strcmp(cont, "on") || !strcmp(cont, "1"))) ctx->v = 1; } } return ctx; }
int filter(struct image *img, xmlNodePtr node) { struct image work; unsigned int x, y, vy; unsigned char *r, *w; int h, v; char *cont; h = v = 0; for (node = node->xml_children; node; node = node->next) { if (xml_isnode(node, "horiz")) { cont = xml_getcontent(node); if (cont && (!strcmp(cont, "yes") || !strcmp(cont, "on") || !strcmp(cont, "1"))) h = 1; } else if (xml_isnode(node, "vert")) { cont = xml_getcontent(node); if (cont && (!strcmp(cont, "yes") || !strcmp(cont, "on") || !strcmp(cont, "1"))) v = 1; } } if (!h && !v) return 0; image_dup(&work, img); /* 3x3 * 0/00 RGBRGBRGB * 1/09 RGBRGBRGB * 2/18 RGBRGBRGB */ r = img->buf; for (y = 0; y < img->y; y++) { if (v) vy = img->y - y - 1; else vy = y; if (h) w = work.buf + (vy + 1) * work.x * 3 - 3; else w = work.buf + vy * work.x * 3; for (x = 0; x < img->x; x++) { w[0] = *r++; w[1] = *r++; w[2] = *r++; if (h) w -= 3; else w += 3; } } image_move(img, &work); return 0; }
static int fw_load_conf(struct fw_ctx *fctx, xmlNodePtr node) { int mult, val; char *s; if (!node) return -1; memset(fctx, 0, sizeof(*fctx)); fctx->chmod = -1; for (node = node->xml_children; node; node = node->next) { if (xml_isnode(node, "path")) fctx->path = xml_getcontent(node); else if (xml_isnode(node, "cmd")) fctx->cmd = xml_getcontent(node); else if (xml_isnode(node, "interval")) { mult = 1; s = xml_attrval(node, "unit"); if (!s) s = xml_attrval(node, "units"); if (s) { if (!strcmp(s, "sec") || !strcmp(s, "secs") || !strcmp(s, "seconds")) ; else if (!strcmp(s, "min") || !strcmp(s, "mins") || !strcmp(s, "minutes")) mult = 60; else if (!strcmp(s, "hour") || !strcmp(s, "hours")) mult = 3600; else if (!strcmp(s, "day") || !strcmp(s, "days")) mult = 86400; else { log_log(MODNAME, "Invalid \"unit\" attribute value \"%s\"\n", s); return -1; } } val = xml_atoi(node, 0); if (val == 0) { log_log(MODNAME, "Invalid interval (%s) specified\n", xml_getcontent(node)); return -1; } fctx->interval = val * mult; } else if (xml_isnode(node, "chmod") || xml_isnode(node, "mode")) fctx->chmod = xml_atoi(node, fctx->chmod); } if (!fctx->path || fctx->interval == 0) { log_log(MODNAME, "Either path or interval not specified\n"); return -1; } fctx->path = config_homedir(fctx->path); fctx->cmd = config_homedir(fctx->cmd); return 0; }
int camdev_open(struct camdev *camdev, xmlNodePtr node) { struct camdev newcamdev; int ret; struct video_window vidwin; char *path; int x, y, fps; int channel; struct video_channel vidchan; path = "/dev/video0"; x = y = fps = 0; channel = -1; if (node) { for (node = node->xml_children; node; node = node->next) { if (xml_isnode(node, "path")) path = xml_getcontent_def(node, path); else if (xml_isnode(node, "width")) x = camdev_size_def(node); else if (xml_isnode(node, "height")) y = camdev_size_def(node); else if (xml_isnode(node, "fps")) fps = xml_atoi(node, 0); else if (xml_isnode(node, "channel")) channel = xml_atoi(node, -1); } } newcamdev.fd = open(path, O_RDONLY); if (newcamdev.fd < 0) { printf("Unable to open %s (%s)\n", path, strerror(errno)); return -1; } ret = ioctl(newcamdev.fd, VIDIOCGCAP, &newcamdev.vidcap); if (ret != 0) { printf("ioctl \"get video cap\" failed: %s\n", strerror(errno)); closenerr: close(newcamdev.fd); return -1; } if (!(newcamdev.vidcap.type & VID_TYPE_CAPTURE)) { printf("Video device doesn't support grabbing to memory\n"); goto closenerr; } if (channel >= 0) { memset(&vidchan, 0, sizeof(vidchan)); vidchan.channel = channel; ret = ioctl(newcamdev.fd, VIDIOCSCHAN, &vidchan); if (ret) printf("ioctl \"set input channel\" failed, continuing anyway: %s\n", strerror(errno)); } memset(&vidwin, 0, sizeof(vidwin)); x = camdev_size_set(x, newcamdev.vidcap.minwidth, newcamdev.vidcap.maxwidth, "width"); y = camdev_size_set(y, newcamdev.vidcap.minheight, newcamdev.vidcap.maxheight, "height"); if (x <= 0 || y <= 0) goto closenerr; vidwin.width = x; vidwin.height = y; vidwin.flags |= (fps & 0x3f) << 16; ret = ioctl(newcamdev.fd, VIDIOCSWIN, &vidwin); if (ret != 0) { printf("ioctl \"set grab window\" failed: %s\n", strerror(errno)); printf("Check your <camdev> config section for width/height and fps settings\n"); goto closenerr; } ret = ioctl(newcamdev.fd, VIDIOCGWIN, &vidwin); if (ret != 0) { printf("ioctl \"get grab window\" failed: %s\n", strerror(errno)); goto closenerr; } ioctl(newcamdev.fd, VIDIOCSWIN, &vidwin); newcamdev.x = vidwin.width; newcamdev.y = vidwin.height; ret = ioctl(newcamdev.fd, VIDIOCGPICT, &newcamdev.vidpic); if (ret != 0) { printf("ioctl \"get pict props\" failed: %s\n", strerror(errno)); goto closenerr; } for (newcamdev.pal = palettes; newcamdev.pal->val >= 0; newcamdev.pal++) { newcamdev.vidpic.palette = newcamdev.pal->val; newcamdev.vidpic.depth = newcamdev.pal->depth; ioctl(newcamdev.fd, VIDIOCSPICT, &newcamdev.vidpic); ioctl(newcamdev.fd, VIDIOCGPICT, &newcamdev.vidpic); if (newcamdev.vidpic.palette == newcamdev.pal->val) goto palfound; /* break */ } printf("No common supported palette found\n"); goto closenerr; palfound: memcpy(camdev, &newcamdev, sizeof(*camdev)); return 0; }