Main Page | Alphabetical List | Data Structures | File List | Data Fields | Globals

xdvshow-x11.c File Reference

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/keysym.h>
#include <libdv/dv.h>
#include "xdvshow-x11.h"
#include "xdvshow-flags.h"

Include dependency graph for xdvshow-x11.c:

Include dependency graph

Go to the source code of this file.

Defines

#define USE_COLOR   0x00000001
#define USE_GREY   0x00000002
#define WIDTH   720
#define PAL_HEIGHT   576
#define NTSC_HEIGHT   480

Functions

int _init_color_table __P ((int))
int _init_color_table (int type)
 alocates the memory for x11 color table.

int xdvshow_x11_open_window (char *window_name, struct x_params *param)
 creates the simple x11 window, sets its name and allocates an image within the window.

int xdvshow_x11_close_window (void)
 should free the rgb image, unmap the window and then destroy it.

int xdvshow_x11_render (void)
 renders the decoded video into the rgb image within the x11 window.


Variables

int flags
u_long *** color_table
u_long color_depth = 4
Display * display
int screen
Window root
Window window
XImage * ximage
GC gc
int width
int height
int real_width
int real_height
x_paramsx_param


Define Documentation

#define NTSC_HEIGHT   480
 

Definition at line 58 of file xdvshow-x11.c.

Referenced by xdvshow_x11_open_window().

#define PAL_HEIGHT   576
 

Definition at line 57 of file xdvshow-x11.c.

Referenced by xdvshow_x11_open_window().

#define USE_COLOR   0x00000001
 

Definition at line 52 of file xdvshow-x11.c.

#define USE_GREY   0x00000002
 

Definition at line 53 of file xdvshow-x11.c.

#define WIDTH   720
 

Definition at line 55 of file xdvshow-x11.c.

Referenced by xdvshow_x11_open_window().


Function Documentation

int _init_color_table __P (int)   )  [static]
 

int _init_color_table int  type  )  [static]
 

alocates the memory for x11 color table.

Returns:
1 on success. -1 otherwise.

Definition at line 83 of file xdvshow-x11.c.

References color_depth, color_table, display, and screen.

Referenced by xdvshow_x11_open_window().

00084 { 00085 int r, g, b; 00086 XColor color; 00087 u_long tmp_depth = (1 << color_depth); 00088 00089 memset(&color, 0, sizeof(color)); 00090 00091 color_table = (u_long ***)malloc(sizeof(u_long ***) * tmp_depth); 00092 if (color_table == NULL) { 00093 perror("malloc"); 00094 return(-1); 00095 } 00096 00097 for (r=0; r<tmp_depth; r++) { 00098 color_table[r] = (u_long **)malloc(sizeof(u_long **) * tmp_depth); 00099 if (color_table[r] == NULL) { 00100 perror("malloc"); 00101 return(-1); 00102 } 00103 00104 for (g=0; g<tmp_depth; g++) { 00105 color_table[r][g] = (u_long *)malloc(sizeof(u_long *) * tmp_depth); 00106 if (color_table[r][g] == NULL) { 00107 perror("malloc"); 00108 return(-1); 00109 } 00110 00111 for (b=0; b<tmp_depth; b++) { 00112 color.red = 65535 / tmp_depth * r; 00113 color.green = 65535 / tmp_depth * g; 00114 color.blue = 65535 / tmp_depth * b; 00115 if (!XAllocColor(display, DefaultColormap(display, screen), &color)) { 00116 printf("XAllocColor failed, r=%d, g=%d, b=%d\n", r, g, b); 00117 return(-1); 00118 } 00119 color_table[r][g][b] = color.pixel; 00120 } 00121 } 00122 } 00123 00124 return(1); 00125 }

int xdvshow_x11_close_window void   ) 
 

should free the rgb image, unmap the window and then destroy it.

Returns:
1 on success.

Definition at line 224 of file xdvshow-x11.c.

References display, window, and ximage.

Referenced by sigint_signal().

00225 { 00226 XDestroyImage(ximage); 00227 00228 XUnmapWindow(display, window); 00229 00230 XDestroyWindow(display, window); 00231 00232 return(1); 00233 }

int xdvshow_x11_open_window char *  window_name,
struct x_params param
 

creates the simple x11 window, sets its name and allocates an image within the window.

Parameters:
*window_name (cahr) is the name of the created window.
*param (x_params) stores the type of the DV video, color depth, decode format and the decoded frame buffer.
Returns:
1 on success. -1 on failure.

Definition at line 135 of file xdvshow-x11.c.

References _init_color_table(), color_table, display, gc, height, NTSC_HEIGHT, PAL_HEIGHT, x_params::pixels, real_height, real_width, root, screen, WIDTH, width, window, x_param, and ximage.

Referenced by video_thread_func().

00136 { 00137 /* 00138 XEvent xevent; 00139 */ 00140 00141 x_param = param; 00142 00143 param->pixels[0] = malloc(720 * 576 * 3); 00144 memset(param->pixels[0], 0, 720 * 576 * 3); 00145 param->pixels[1] = NULL; 00146 param->pixels[2] = NULL; 00147 00148 param->pitches[0] = 720 * 3; 00149 param->pitches[1] = 0; 00150 param->pitches[2] = 0; 00151 00152 param->decode_format = e_dv_color_rgb; 00153 00154 switch (param->dv_format_type) { 00155 case e_dv_system_525_60: 00156 width = WIDTH; 00157 height = NTSC_HEIGHT; 00158 real_width = WIDTH; 00159 real_height = NTSC_HEIGHT; 00160 break; 00161 00162 case e_dv_system_625_50: 00163 width = WIDTH; 00164 height = PAL_HEIGHT; 00165 real_width = WIDTH; 00166 real_height = PAL_HEIGHT; 00167 break; 00168 00169 default: 00170 return(-1); 00171 } 00172 00173 display = XOpenDisplay(NULL); 00174 if (display == NULL) { 00175 perror("XOpenDisplay"); 00176 return(-1); 00177 } 00178 00179 screen = DefaultScreen(display); 00180 root = RootWindow(display, screen); 00181 00182 _init_color_table(0); 00183 00184 window = XCreateSimpleWindow(display, root, 0, 0, width, height, 00185 2, color_table[0][0][0], 00186 color_table[0][0][0]); 00187 gc = XCreateGC(display, window, 0, 0); 00188 00189 XMapWindow(display, window); 00190 00191 XStoreName(display, window, window_name); 00192 XFlush(display); 00193 00194 /* 00195 XSelectInput(display, window, ExposureMask); 00196 XWindowEvent(display, window, ExposureMask, &xevent); 00197 */ 00198 00199 ximage = XCreateImage(display, DefaultVisual(display, screen), 00200 DefaultDepth(display, screen), 00201 ZPixmap, 0, 0, width, height, 32, 0); 00202 if (ximage == NULL) { 00203 printf("XCreateImage() failed\n"); 00204 return(-1); 00205 } 00206 00207 ximage->data = (char *)malloc(ximage->bytes_per_line*height); 00208 if (ximage->data == NULL) { 00209 perror("XCreateImage data failed\n"); 00210 return(-1); 00211 } 00212 00213 XFlush(display); 00214 00215 return(1); 00216 }

Here is the call graph for this function:

int xdvshow_x11_render void   ) 
 

renders the decoded video into the rgb image within the x11 window.

Returns:
1 on success.

Definition at line 241 of file xdvshow-x11.c.

References color_depth, color_table, display, gc, height, x_params::pixels, width, window, x_param, and ximage.

Referenced by video_thread_func().

00242 { 00243 u_char r, g, b; 00244 int16_t x, y; 00245 register u_char *ptr; 00246 00247 u_long color_shift; 00248 00249 ptr = &x_param->pixels[0][0]; 00250 00251 color_shift = (8 - color_depth); 00252 00253 for (y=0; y<height; y++) { 00254 for (x=0; x<width; x++) { 00255 r = *ptr; 00256 r >>= color_shift; 00257 ptr++; 00258 00259 g = *ptr; 00260 g >>= color_shift; 00261 ptr++; 00262 00263 b = *ptr; 00264 b >>= color_shift; 00265 ptr++; 00266 00267 XPutPixel(ximage, x, y, color_table[r][g][b]); 00268 } 00269 } 00270 00271 XPutImage(display, window, gc, ximage, 0, 0, 0, 0, width, height); 00272 XFlush(display); 00273 00274 return(1); 00275 }


Variable Documentation

u_long color_depth = 4 [static]
 

Definition at line 63 of file xdvshow-x11.c.

Referenced by _init_color_table(), and xdvshow_x11_render().

u_long*** color_table [static]
 

Definition at line 62 of file xdvshow-x11.c.

Referenced by _init_color_table(), xdvshow_x11_open_window(), and xdvshow_x11_render().

Display* display [static]
 

Definition at line 65 of file xdvshow-x11.c.

Referenced by _init_color_table(), xdvshow_x11_close_window(), xdvshow_x11_open_window(), and xdvshow_x11_render().

int flags
 

Definition at line 60 of file xdvshow-x11.c.

GC gc [static]
 

Definition at line 69 of file xdvshow-x11.c.

Referenced by xdvshow_x11_open_window(), and xdvshow_x11_render().

int height [static]
 

Definition at line 70 of file xdvshow-x11.c.

int real_height [static]
 

Definition at line 71 of file xdvshow-x11.c.

Referenced by xdvshow_x11_open_window().

int real_width [static]
 

Definition at line 71 of file xdvshow-x11.c.

Referenced by xdvshow_x11_open_window().

Window root [static]
 

Definition at line 67 of file xdvshow-x11.c.

Referenced by xdvshow_x11_open_window().

int screen [static]
 

Definition at line 66 of file xdvshow-x11.c.

Referenced by _init_color_table(), and xdvshow_x11_open_window().

int width [static]
 

Definition at line 70 of file xdvshow-x11.c.

Window window [static]
 

Definition at line 67 of file xdvshow-x11.c.

Referenced by xdvshow_x11_close_window(), xdvshow_x11_open_window(), and xdvshow_x11_render().

struct x_params* x_param
 

Definition at line 75 of file xdvshow-x11.c.

Referenced by xdvshow_x11_open_window(), and xdvshow_x11_render().

XImage* ximage [static]
 

Definition at line 68 of file xdvshow-x11.c.

Referenced by xdvshow_x11_close_window(), xdvshow_x11_open_window(), and xdvshow_x11_render().


Generated on Wed Nov 3 19:19:02 2004 for xdvshow by doxygen 1.3.7