Linux kernel & device driver programming

Cross-Referenced Linux and Device Driver Code

[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ]
Version: [ 2.6.11.8 ] [ 2.6.25 ] [ 2.6.25.8 ] [ 2.6.31.13 ] Architecture: [ i386 ]
  1 /*
  2  * simple libng filter -- just invert the image
  3  *
  4  * (c) 2001 Gerd Knorr <kraxel@bytesex.org>
  5  *
  6  */
  7 
  8 #include "config.h"
  9 
 10 #include <stdio.h>
 11 #include <stdlib.h>
 12 #include <pthread.h>
 13 
 14 #include "grab-ng.h"
 15 
 16 /* ------------------------------------------------------------------- */
 17 
 18 static void inline
 19 invert_bytes(unsigned char *dst, unsigned char *src, int bytes)
 20 {
 21     while (bytes--)
 22         *(dst++) = 0xff - *(src++);
 23 }
 24 
 25 static void inline
 26 invert_native_rgb15(void *d, void *s, int pixels)
 27 {
 28     unsigned short *dst = d;
 29     unsigned short *src = s;
 30     unsigned short r,g,b;
 31 
 32     while (pixels--) {
 33         r = 0x1f - ((*src >> 10)  &  0x1f);
 34         g = 0x1f - ((*src >>  5)  &  0x1f);
 35         b = 0x1f - ( *src         &  0x1f);
 36         *dst = (r << 10) | (g << 5) | b;
 37         src++; dst++;
 38     }
 39 }
 40 
 41 static void inline
 42 invert_native_rgb16(void *d, void *s, int pixels)
 43 {
 44     unsigned short *dst = d;
 45     unsigned short *src = s;
 46     unsigned short r,g,b;
 47 
 48     while (pixels--) {
 49         r = 0x1f - ((*src >> 11)  &  0x1f);
 50         g = 0x3f - ((*src >>  5)  &  0x3f);
 51         b = 0x1f - ( *src         &  0x1f);
 52         *dst = (r << 11) | (g << 5) | b;
 53         src++; dst++;
 54     }
 55 }
 56 
 57 /* ------------------------------------------------------------------- */
 58 
 59 static void *init(struct ng_video_fmt *out)
 60 {
 61     /* don't have to carry around status info */
 62     static int dummy;
 63     return &dummy;
 64 }
 65 
 66 static struct ng_video_buf*
 67 frame(void *handle, struct ng_video_buf *in)
 68 {
 69     struct ng_video_buf *out;
 70     unsigned char *dst;
 71     unsigned char *src;
 72     unsigned int y,cnt;
 73 
 74     out = ng_malloc_video_buf(&in->fmt, in->fmt.height * in->fmt.bytesperline);
 75     out->info = in->info;
 76 
 77     dst = out->data;
 78     src = in->data;
 79     cnt = in->fmt.width * ng_vfmt_to_depth[in->fmt.fmtid] / 8;
 80     for (y = 0; y < in->fmt.height; y++) {
 81         switch (in->fmt.fmtid) {
 82         case VIDEO_GRAY:
 83         case VIDEO_BGR24:
 84         case VIDEO_RGB24:
 85         case VIDEO_BGR32:
 86         case VIDEO_RGB32:
 87         case VIDEO_YUYV:
 88         case VIDEO_UYVY:
 89             invert_bytes(dst,src,cnt);
 90             break;
 91         case VIDEO_RGB15_NATIVE:
 92             invert_native_rgb15(dst,src,in->fmt.width);
 93             break;
 94         case VIDEO_RGB16_NATIVE:
 95             invert_native_rgb16(dst,src,in->fmt.width);
 96             break;
 97         }
 98         dst += out->fmt.bytesperline;
 99         src += in->fmt.bytesperline;
100     }
101 
102     ng_release_video_buf(in);
103     return out;
104 }
105 
106 static void fini(void *handle)
107 {
108     /* nothing to clean up */
109 }
110 
111 /* ------------------------------------------------------------------- */
112 
113 static struct ng_filter filter = {
114     name:    "invert",
115     fmts:
116     (1 << VIDEO_GRAY)         |
117     (1 << VIDEO_RGB15_NATIVE) |
118     (1 << VIDEO_RGB16_NATIVE) |
119     (1 << VIDEO_BGR24)        |
120     (1 << VIDEO_RGB24)        |
121     (1 << VIDEO_BGR32)        |
122     (1 << VIDEO_RGB32)        |
123     (1 << VIDEO_YUYV)         |
124     (1 << VIDEO_UYVY),
125     init:    init,
126     frame:   frame,
127     fini:    fini,
128 };
129 
130 extern void ng_plugin_init(void);
131 void ng_plugin_init(void)
132 {
133     ng_filter_register(NG_PLUGIN_MAGIC,__FILE__,&filter);
134 }
135 
  This page was automatically generated by the LXR engine.