1 /*
2  * Simple xawtv deinterlacing plugin - line doubling
3  *
4  * CAVEATS: Effectively halves framerate and vertical resolution
5  * Framerate problem is to be addressed, vertical resolution problem is
6  * inherent in line doubling.  Use one of the interpolating (or blending, when
7  * we write them) filters.
8  *
9  * BENEFITS: It's no longer interlaced ;) thats about it.
10  *
11  * AUTHORS:
12  * Conrad Kreyling <conrad@conrad.nerdland.org>
13  * Patrick Barrett <yebyen@nerdland.org>
14  *
15  * This is licenced under the GNU GPL until someone tells me I'm stealing code
16  * and can't do that ;) www.gnu.org for any version of the license.
17  *
18  * Based on xawtv-3.67/libng/plugins/flt-nop.c (also GPL)
19  */
20 
21 
22 #include "config.h"
23 
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <pthread.h>
27 
28 #include "grab-ng.h"
29 
30 static void inline
deinterlace(struct ng_video_buf * frame)31 deinterlace(struct ng_video_buf *frame)
32 {
33    unsigned int x,y;
34 
35    for (y = 1; y < frame->fmt.height; y += 2)
36 	  for (x = 0; x < frame->fmt.bytesperline + 1; x++)
37 		 frame->data[(y * frame->fmt.bytesperline) + x] =
38 			frame->data[((y - 1) * frame->fmt.bytesperline) + x];
39 }
40 
41 
init(struct ng_video_fmt * out)42 static void *init(struct ng_video_fmt *out)
43 {
44     /* don't have to carry around status info */
45     static int dummy;
46     return &dummy;
47 }
48 
49 static struct ng_video_buf*
frame(void * handle,struct ng_video_buf * frame)50 frame(void *handle, struct ng_video_buf *frame)
51 {
52    deinterlace(frame); // In hindsight, we may not have needed the function ;)
53 					   // Added clarity when we make it more complicated.
54    return frame;
55 }
56 
fini(void * handle)57 static void fini(void *handle)
58 {
59     /* nothing to clean up */
60 }
61 
62 /* ------------------------------------------------------------------- */
63 
64 static struct ng_filter filter = {
65     .name =    "line doubler deinterlace",
66     .fmts =
67     (1 << VIDEO_GRAY)         |
68     (1 << VIDEO_RGB15_NATIVE) |
69     (1 << VIDEO_RGB16_NATIVE) |
70     (1 << VIDEO_BGR24)        |
71     (1 << VIDEO_RGB24)        |
72     (1 << VIDEO_BGR32)        |
73     (1 << VIDEO_RGB32)        |
74     (1 << VIDEO_YUYV)         |
75     (1 << VIDEO_UYVY),
76     .init =    init,
77     .frame =   frame,
78     .fini =    fini,
79 };
80 
81 extern void ng_plugin_init(void);
ng_plugin_init(void)82 void ng_plugin_init(void)
83 {
84     ng_filter_register(NG_PLUGIN_MAGIC,__FILE__,&filter);
85 }
86