00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
#ifdef HAVE_CONFIG_H
00036
#include <config.h>
00037
#endif
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
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
00196
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 }