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

xdvshow-x11.c

Go to the documentation of this file.
00001 /* 00002 * Copyright (c) 1999, 2000, 2001, 2002 WIDE Project 00003 * All rights reserved. 00004 * 00005 * Author : Akimichi OGAWA (akimichi@sfc.wide.ad.jp) 00006 * 00007 * Redistribution and use in source and binary forms, with or without 00008 * modification, are permitted provided that the following conditions 00009 * are met: 00010 * 1. Redistributions of source code MUST retain the above copyright 00011 * notice, this list of conditions and the following disclaimer. 00012 * 2. Redistributions in binary form MUST reproduce the above copyright 00013 * notice, this list of conditions and the following disclaimer in the 00014 * documentation and/or other materials provided with the distribution. 00015 * 3. All advertising materials mentioning features or use of this software 00016 * MUST display the following acknowledgement: 00017 * This product includes software developed by Akimichi OGAWA. 00018 * 4. The name of the author MAY NOT be used to endorse or promote products 00019 * derived from this software without specific prior written permission. 00020 * 00021 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 00022 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 00023 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00024 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 00025 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00026 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00027 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 00028 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 00029 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 00030 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00031 * POSSIBILITY OF SUCH DAMAGE. 00032 * 00033 */ 00034 00035 #ifdef HAVE_CONFIG_H 00036 #include <config.h> 00037 #endif /* HAVE_CONFIG_H */ 00038 00039 #include <stdio.h> 00040 #include <stdlib.h> 00041 #include <string.h> 00042 #include <sys/types.h> 00043 #include <X11/Xlib.h> 00044 #include <X11/Xutil.h> 00045 #include <X11/keysym.h> 00046 00047 #include <libdv/dv.h> 00048 00049 #include "xdvshow-x11.h" 00050 #include "xdvshow-flags.h" 00051 00052 #define USE_COLOR 0x00000001 00053 #define USE_GREY 0x00000002 00054 00055 #define WIDTH 720 00056 00057 #define PAL_HEIGHT 576 00058 #define NTSC_HEIGHT 480 00059 00060 extern int flags; 00061 00062 static u_long ***color_table; 00063 static u_long color_depth = 4; 00064 00065 static Display *display; 00066 static int screen; 00067 static Window root, window; 00068 static XImage *ximage; 00069 static GC gc; 00070 static int width, height; 00071 static int real_width, real_height; 00072 00073 static int _init_color_table __P((int)); 00074 00075 struct x_params *x_param; 00076 00082 static int 00083 _init_color_table(int type) 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 } 00126 00134 int 00135 xdvshow_x11_open_window(char *window_name, struct x_params *param) 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 } 00217 00223 int 00224 xdvshow_x11_close_window(void) 00225 { 00226 XDestroyImage(ximage); 00227 00228 XUnmapWindow(display, window); 00229 00230 XDestroyWindow(display, window); 00231 00232 return(1); 00233 } 00234 00240 int 00241 xdvshow_x11_render(void) 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 }

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