00001
00002
00003
00004
00005 #include <stdio.h>
00006 #include <stdlib.h>
00007 #include <unistd.h>
00008
00009 #include "filter.h"
00010 #include "frame.h"
00011
00012 typedef struct ThisFilter
00013 {
00014 VideoFilter vf;
00015 TF_STRUCT;
00016 } ThisFilter;
00017
00018 int invert(VideoFilter *vf, VideoFrame *frame)
00019 {
00020 int size = frame->size;
00021 unsigned char *buf = frame->buf;
00022 TF_VARS;
00023
00024 (void)vf;
00025
00026 TF_START;
00027
00028
00029 while (size--)
00030 {
00031 *buf = 255 - (*buf);
00032 buf++;
00033 }
00034
00035 TF_END((ThisFilter *)vf, "Invert");
00036
00037 return 0;
00038 }
00039
00040 VideoFilter *new_filter(VideoFrameType inpixfmt, VideoFrameType outpixfmt,
00041 int *width, int *height, char *options)
00042 {
00043 ThisFilter *filter;
00044
00045 (void)width;
00046 (void)height;
00047 (void)options;
00048
00049 if ((inpixfmt != outpixfmt) ||
00050 (inpixfmt != FMT_YV12 && inpixfmt != FMT_RGB24 &&
00051 inpixfmt != FMT_YUV422P) )
00052 return NULL;
00053
00054 filter = malloc(sizeof(ThisFilter));
00055
00056 if (filter == NULL)
00057 {
00058 fprintf(stderr,"Couldn't allocate memory for filter\n");
00059 return NULL;
00060 }
00061 filter->vf.filter = &invert;
00062 filter->vf.cleanup = NULL;
00063 TF_INIT(filter)
00064 return (VideoFilter *) filter;
00065 }
00066
00067 static FmtConv FmtList[] =
00068 {
00069 { FMT_YV12, FMT_YV12 },
00070 { FMT_YUV422P, FMT_YUV422P },
00071 { FMT_RGB24, FMT_RGB24 },
00072 FMT_NULL
00073 };
00074
00075 FilterInfo filter_table[] =
00076 {
00077 {
00078 symbol: "new_filter",
00079 name: "invert",
00080 descript: "inverts the colors of the input video",
00081 formats: FmtList,
00082 libname: NULL
00083 },
00084 FILT_NULL
00085 };