MythTV  0.26-pre
filter_invert.c
Go to the documentation of this file.
00001 /*
00002  *  filter_invert
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, int field)
00019 {
00020     (void)field;
00021     int size = frame->size;
00022     unsigned char *buf = frame->buf;
00023     TF_VARS;
00024 
00025     (void)vf;
00026 
00027     TF_START;
00028 
00029 
00030     while (size--)
00031     {
00032         *buf = 255 - (*buf);
00033         buf++;
00034     }
00035 
00036     TF_END((ThisFilter *)vf, "Invert");
00037 
00038     return 0;
00039 }
00040 
00041 static VideoFilter *new_filter(VideoFrameType inpixfmt,
00042                                VideoFrameType outpixfmt,
00043                                int *width, int *height, char *options,
00044                                int threads)
00045 {
00046     ThisFilter *filter;
00047     
00048     (void)width;
00049     (void)height;
00050     (void)options;
00051     (void)threads;
00052 
00053     if ((inpixfmt != outpixfmt) || 
00054         (inpixfmt != FMT_YV12 && inpixfmt != FMT_RGB24 && 
00055          inpixfmt != FMT_YUV422P) )
00056         return NULL;
00057     
00058     filter = malloc(sizeof(ThisFilter));
00059 
00060     if (filter == NULL)
00061     {
00062         fprintf(stderr,"Couldn't allocate memory for filter\n");
00063         return NULL;
00064     }
00065     filter->vf.filter = &invert;
00066     filter->vf.cleanup = NULL;
00067     TF_INIT(filter)
00068     return (VideoFilter *) filter;
00069 }
00070 
00071 static FmtConv FmtList[] =
00072 {
00073     { FMT_YV12, FMT_YV12 },
00074     { FMT_YUV422P, FMT_YUV422P },
00075     { FMT_RGB24, FMT_RGB24 },
00076     FMT_NULL
00077 };
00078 
00079 ConstFilterInfo filter_table[] =
00080 {
00081     {
00082         filter_init: &new_filter,
00083         name:       "invert",
00084         descript:   "inverts the colors of the input video",
00085         formats:    FmtList,
00086         libname:    NULL
00087     },
00088     FILT_NULL
00089 };
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends