ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/mintv/mintv.cpp
(Generate patch)

Comparing mintv/mintv.cpp (file contents):
Revision 1.1 by cebix, 2003-02-08T17:51:47Z vs.
Revision 1.3 by cebix, 2003-03-01T15:23:26Z

# Line 27 | Line 27
27   #include <X11/extensions/Xv.h>
28   #include <X11/extensions/Xvlib.h>
29  
30 + static bool ntsc = false;
31 +
32   const int PAL_WIDTH = 384;
33   const int PAL_HEIGHT = 288;
34   const int NTSC_WIDTH = 320;
# Line 41 | Line 43 | const int NTSC_FPS = 60;
43  
44   static int fps;
45  
46 + static int brightness = 50, contrast = 50, color = 50;
47 +
48 + static int channel = 1;
49 +
50   #define XV_FORMAT 0x32595559
51   #define BYTES_PER_PIXEL 2
52  
# Line 77 | Line 83 | static void quit(Widget widget, XEvent *
83          exit(0);
84   }
85  
86 + static void set_bcc(void)
87 + {
88 +        video_picture pict;
89 +        if (ioctl(fd, VIDIOCGPICT, &pict) < 0) {
90 +                fprintf(stderr, "ioctl VIDIOCGPICT: %s\n", strerror(errno));
91 +                exit(1);
92 +        }
93 +        pict.brightness = brightness * 65536 / 100;
94 +        pict.contrast = contrast * 65536 / 100;
95 +        pict.colour = color * 65536 / 100;
96 +        if (ioctl(fd, VIDIOCSPICT, &pict) < 0) {
97 +                fprintf(stderr, "ioctl VIDIOCSPICT: %s\n", strerror(errno));
98 +                exit(1);
99 +        }
100 + }
101 +
102 + static void inc_brightness(Widget widget, XEvent *event, String *params, Cardinal *num_params)
103 + {
104 +        if (brightness < 100)
105 +                brightness++;
106 +        set_bcc();
107 + }
108 +
109 + static void dec_brightness(Widget widget, XEvent *event, String *params, Cardinal *num_params)
110 + {
111 +        if (brightness > 0)
112 +                brightness--;
113 +        set_bcc();
114 + }
115 +
116 + static void reset_brightness(Widget widget, XEvent *event, String *params, Cardinal *num_params)
117 + {
118 +        brightness = 50;
119 +        set_bcc();
120 + }
121 +
122 + static void inc_contrast(Widget widget, XEvent *event, String *params, Cardinal *num_params)
123 + {
124 +        if (contrast < 100)
125 +                contrast++;
126 +        set_bcc();
127 + }
128 +
129 + static void dec_contrast(Widget widget, XEvent *event, String *params, Cardinal *num_params)
130 + {
131 +        if (contrast > 0)
132 +                contrast--;
133 +        set_bcc();
134 + }
135 +
136 + static void reset_contrast(Widget widget, XEvent *event, String *params, Cardinal *num_params)
137 + {
138 +        contrast = 50;
139 +        set_bcc();
140 + }
141 +
142 + static void inc_color(Widget widget, XEvent *event, String *params, Cardinal *num_params)
143 + {
144 +        if (color < 100)
145 +                color++;
146 +        set_bcc();
147 + }
148 +
149 + static void dec_color(Widget widget, XEvent *event, String *params, Cardinal *num_params)
150 + {
151 +        if (color > 0)
152 +                color--;
153 +        set_bcc();
154 + }
155 +
156 + static void reset_color(Widget widget, XEvent *event, String *params, Cardinal *num_params)
157 + {
158 +        color = 50;
159 +        set_bcc();
160 + }
161 +
162 + static void set_channel(void)
163 + {
164 +        video_channel chan;
165 +        chan.channel = channel;
166 +        if (ioctl(fd, VIDIOCGCHAN, &chan) < 0) {
167 +                fprintf(stderr, "ioctl VIDIOCGCHAN: %s\n", strerror(errno));
168 +                exit(1);
169 +        }
170 +        if (ntsc)
171 +                chan.norm = VIDEO_MODE_NTSC;
172 +        else
173 +                chan.norm = VIDEO_MODE_PAL;
174 +        if (ioctl(fd, VIDIOCSCHAN, &chan) < 0) {
175 +                fprintf(stderr, "ioctl VIDIOCSCHAN: %s\n", strerror(errno));
176 +                exit(1);
177 +        }
178 + }
179 +
180 + static void select_channel_1(Widget widget, XEvent *event, String *params, Cardinal *num_params)
181 + {
182 +        channel = 1;
183 +        set_channel();
184 + }
185 +
186 + static void select_channel_2(Widget widget, XEvent *event, String *params, Cardinal *num_params)
187 + {
188 +        channel = 2;
189 +        set_channel();
190 + }
191 +
192   static XtActionsRec actionTable[] = {
193 <        {"quit", quit}
193 >        {"quit", quit},
194 >        {"inc_brightness", inc_brightness},
195 >        {"dec_brightness", dec_brightness},
196 >        {"reset_brightness", reset_brightness},
197 >        {"inc_contrast", inc_contrast},
198 >        {"dec_contrast", dec_contrast},
199 >        {"reset_contrast", reset_contrast},
200 >        {"inc_color", inc_color},
201 >        {"dec_color", dec_color},
202 >        {"reset_color", reset_color},
203 >        {"select_channel_1", select_channel_1},
204 >        {"select_channel_2", select_channel_2}
205   };
206  
207   static void resize_event(Widget widget, XtPointer client_data, XEvent *event, Boolean *d)
# Line 205 | Line 328 | int main(int argc, char **argv)
328          log = fopen("log", "w");
329   #endif
330  
208        // Init X11
209        XtAppContext app_context;
210        app_shell = XtAppInitialize(&app_context, "mintv", NULL, 0, &argc, argv, NULL,  NULL, 0);
211        dpy = XtDisplay(app_shell);
212        XtAppAddActions(app_context,actionTable, sizeof(actionTable) / sizeof(XtActionsRec));
213        XtOverrideTranslations(app_shell, XtParseTranslationTable(
214                "<Message>WM_PROTOCOLS: quit()\n"
215                "<Key>q: quit()"
216        ));
217        XtAddEventHandler(app_shell, StructureNotifyMask, True, resize_event, NULL);
218        wm = XInternAtom(XtDisplay(app_shell), "WM_DELETE_WINDOW", False);
219
331          // Parse options
221        bool ntsc = false;
332          for (;;) {
333                  int c;
334                  if ((c = getopt_long(argc, argv, "hnp:", long_opts,NULL)) == -1)
# Line 236 | Line 346 | int main(int argc, char **argv)
346                          case 'h':
347                          default:
348                                  fprintf(stderr,
349 <                                        "This is an xvideo test application.\n"
349 >                                        "50/60Hz video display application\n\n"
350                                          "Options:\n"
351                                          "  -h | --help    this text\n"
352                                          "  -n | --ntsc    NTSC mode\n"
353 <                                        "  -p | --port n  Xv output port\n"
353 >                                        "  -p | --port n  Xv output port\n\n"
354 >                                        "Keyboard commands:\n"
355 >                                        "  q         quit\n"
356 >                                        "  1/2       select channel\n"
357 >                                        "  KP 7/4/1  adjust brightness\n"
358 >                                        "  KP 8/5/2  adjust contrast\n"
359 >                                        "  KP 9/6/3  adjust color\n"
360                                  );
361                                  exit(1);
362                                  break;
363                  }
364          }
365  
366 +        // Init X11
367 +        XtAppContext app_context;
368 +        app_shell = XtAppInitialize(&app_context, "mintv", NULL, 0, &argc, argv, NULL,  NULL, 0);
369 +        dpy = XtDisplay(app_shell);
370 +        XtAppAddActions(app_context,actionTable, sizeof(actionTable) / sizeof(XtActionsRec));
371 +        XtOverrideTranslations(app_shell, XtParseTranslationTable(
372 +                "<Message>WM_PROTOCOLS: quit()\n"
373 +                "<Key>q: quit()\n"
374 +                "<Key>1: select_channel_1()\n"
375 +                "<Key>2: select_channel_2()\n"
376 +                "<Key>KP_7: inc_brightness()\n"
377 +                "<Key>KP_4: reset_brightness()\n"
378 +                "<Key>KP_1: dec_brightness()\n"
379 +                "<Key>KP_8: inc_contrast()\n"
380 +                "<Key>KP_5: reset_contrast()\n"
381 +                "<Key>KP_2: dec_contrast()\n"
382 +                "<Key>KP_9: inc_color()\n"
383 +                "<Key>KP_6: reset_color()\n"
384 +                "<Key>KP_3: dec_color()"
385 +        ));
386 +        XtAddEventHandler(app_shell, StructureNotifyMask, True, resize_event, NULL);
387 +        wm = XInternAtom(XtDisplay(app_shell), "WM_DELETE_WINDOW", False);
388 +
389          // Xvideo available?
390          unsigned ver, rel, req, ev, err, val;
391          if (XvQueryExtension(dpy, &ver, &rel, &req, &ev, &err) != Success) {
# Line 346 | Line 485 | port_found:
485          }
486  
487          // Set channel
488 <        video_channel chan;
489 <        chan.channel = 1;
351 <        if (ioctl(fd, VIDIOCGCHAN, &chan) < 0) {
352 <                fprintf(stderr, "ioctl VIDIOCGCHAN: %s\n", strerror(errno));
353 <                exit(1);
354 <        }
355 <        if (ntsc)
356 <                chan.norm = VIDEO_MODE_NTSC;
357 <        else
358 <                chan.norm = VIDEO_MODE_PAL;
359 <        if (ioctl(fd, VIDIOCSCHAN, &chan) < 0) {
360 <                fprintf(stderr, "ioctl VIDIOCSCHAN: %s\n", strerror(errno));
361 <                exit(1);
362 <        }
488 >        set_channel();
489 >
490          video_audio au;
491          au.audio = 1;
492          if (ioctl(fd, VIDIOCGAUDIO, &au) < 0) {
# Line 373 | Line 500 | port_found:
500          }
501  
502          // Configure frame grabber
503 <        video_picture pict;
377 <        if (ioctl(fd, VIDIOCGPICT, &pict) < 0) {
378 <                fprintf(stderr, "ioctl VIDIOCGPICT: %s\n", strerror(errno));
379 <                exit(1);
380 <        }
381 <        pict.brightness = 45 * 65536 / 100;
382 <        pict.contrast = 55 * 65536 / 100;
383 <        pict.colour = 60 * 65536 / 100;
384 <        if (ioctl(fd, VIDIOCSPICT, &pict) < 0) {
385 <                fprintf(stderr, "ioctl VIDIOCSPICT: %s\n", strerror(errno));
386 <                exit(1);
387 <        }
503 >        set_bcc();
504  
505          if (ioctl(fd, VIDIOCGMBUF, &mbuf) < 0) {
506                  fprintf(stderr, "ioctl VIDIOCGMBUF: %s\n", strerror(errno));

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines