00111 {
00112
if (state != CLOSED) {
00113 dprintf_err(
"X11Renderer::open state was not CLOSED but state=%i!\n",state);
00114
return false;
00115 }
00116
00117
if (!
updateDisplayRegion()) {
00118 state = STREAMERR;
00119
return false;
00120 }
00121
00122
char hostname[MAX_STR_LEN];
00123
char *envhost = getenv(
"DISPLAY");
00124
if (!envhost)
00125 strcpy(hostname,
"localhost:0");
00126
else
00127 strcpy(hostname,envhost);
00128
00129 display = XOpenDisplay(hostname);
00130 assert(display);
00131 screennr = XDefaultScreen(display);
00132 screen = XDefaultScreenOfDisplay(display);
00133 depth = XDefaultDepth(display,screennr);
00134 winAttrib.background_pixel = BlackPixel(display, screennr);
00135 winAttrib.border_pixel = BlackPixel(display, screennr);
00136 winAttrib.backing_store = Always;
00137 winAttrib.bit_gravity = StaticGravity;
00138 XVisualInfo visual_info;
00139 Visual *def_visual = XDefaultVisual(display,screennr);
00140
unsigned int attr_val = CWBackingStore | CWBackPixel | CWBorderPixel;
00141
int visualClass = -1;
00142
00143 setOutputDepth(depth);
00144
00145
00146
if (!XMatchVisualInfo(display, screennr, depth, PseudoColor, &visual_info)) {
00147
if (!XMatchVisualInfo(display, screennr, depth, DirectColor, &visual_info)) {
00148
00149
00150
00151
00152 dprintf_err(
"X11Renderer::open() could not find PseudoColor or DirectColor visual!\n");
00153 ::exit(0);
00154 }
else
00155 visualClass = DirectColor;
00156 }
else
00157 visualClass = PseudoColor;
00158
00159 dprintf_full(
"X11Renderer:open outputDepth %i, defaultVisual %p, pseudo/directColor visualID 0x%x\n",
00160 depth, def_visual, (
int)visual_info.visualid);
00161
00162
00163
00164
00165
if (visualClass != DirectColor)
00166 XCreateColormap(display, RootWindowOfScreen(screen), visual_info.visual, AllocNone);
00167
else {
00168 XColor cols[256];
00169
unsigned int cm_size, red_mask, green_mask, blue_mask;
00170
unsigned int k, r, g, b, ru, gu, bu, m, rv, gv, bv, rvu, gvu, bvu;
00171 cm_size = visual_info.colormap_size;
00172 red_mask = visual_info.red_mask;
00173 green_mask = visual_info.green_mask;
00174 blue_mask = visual_info.blue_mask;
00175 ru = (red_mask & (red_mask - 1)) ^ red_mask;
00176 gu = (green_mask & (green_mask - 1)) ^ green_mask;
00177 bu = (blue_mask & (blue_mask - 1)) ^ blue_mask;
00178 rvu = 65536ull * ru / (red_mask + ru);
00179 gvu = 65536ull * gu / (green_mask + gu);
00180 bvu = 65536ull * bu / (blue_mask + bu);
00181 r = g = b = 0;
00182 rv = gv = bv = 0;
00183 m = DoRed | DoGreen | DoBlue;
00184
for (k = 0; k < cm_size; k++) {
00185
unsigned int t;
00186
00187 cols[k].pixel = r | g | b;
00188 cols[k].red = rv;
00189 cols[k].green = gv;
00190 cols[k].blue = bv;
00191 cols[k].flags = m;
00192 t = (r + ru) & red_mask;
00193
if (t < r)
00194 m &= ~DoRed;
00195 r = t;
00196 t = (g + gu) & green_mask;
00197
if (t < g)
00198 m &= ~DoGreen;
00199 g = t;
00200 t = (b + bu) & blue_mask;
00201
if (t < b)
00202 m &= ~DoBlue;
00203 b = t;
00204 rv += rvu;
00205 gv += gvu;
00206 bv += bvu;
00207 }
00208 winAttrib.colormap = XCreateColormap(display, RootWindowOfScreen(screen), visual_info.visual, AllocAll);
00209 XStoreColors(display, winAttrib.colormap, cols, cm_size);
00210 }
00211
00212 XInstallColormap(display, winAttrib.colormap);
00213
00214 attr_val |= CWColormap;
00215
00216 xwin=XCreateWindow(display, XRootWindow(display,screennr)
00217 ,0, 0, out_label_info.width, out_label_info.height, 1
00218 ,depth, InputOutput,
00219 visual_info.visual
00220
00221 , attr_val, &winAttrib);
00222
00223 XStoreName(display, xwin,
"ViTooKi X11Renderer");
00224 XSetIconName(display, xwin,
"ViTooKi X11Renderer");
00225 XSetWindowBackground(display, xwin, 0xFFFFFF);
00226 XMapWindow(display, xwin);
00227 XSync(display, 0);
00228
00229 hideCursor(display,xwin);
00230
00231
00232
if (
frameBuffer) {
00233
delete frameBuffer;
00234
frameBuffer = NULL;
00235 }
00236
00237
bool gray =
false;
00238
switch (
colorSpace) {
00239
case UncompressedVideoFrame::ColorSpaceGRAY8:
00240 dprintf_full(
"X11Renderer::open() ColorSpaceGRAY8\n");
00241 gray=
true;
00242
frame_info.size =
frame_info.width *
frame_info.height;
00243
break;
00244
case UncompressedVideoFrame::ColorSpaceRGB24:
00245 dprintf_full(
"X11Renderer::open() ColorSpaceRGB24\n");
00246
frame_info.size =
frame_info.width *
frame_info.height * 3;
00247
break;
00248
case UncompressedVideoFrame::ColorSpaceRGB32:
00249 dprintf_full(
"X11Renderer::open() ColorSpaceRGB32\n");
00250
frame_info.size =
frame_info.width *
frame_info.height * 4;
00251
break;
00252
case UncompressedVideoFrame::ColorSpaceRGB565:
00253 dprintf_full(
"X11Renderer::open() ColorSpaceRGB565\n");
00254
frame_info.size =
frame_info.width *
frame_info.height * 2;
00255
break;
00256
case UncompressedVideoFrame::ColorSpaceYV12:
00257
case UncompressedVideoFrame::ColorSpaceI420:
00258 dprintf_err(
"X11Renderer::open() ColorSpaceYV12 or I420 NOT SUPPORTED on X11!!!\n");
00259 ::exit(1);
00260
break;
00261
default:
00262 dprintf_err(
"X11Renderer::open(): invalid color space: %d\n", colorSpace);
00263 state = STREAMERR;
00264
return false;
00265 }
00266
00267
if ( (depth == 16) &&
00268 (depth ==
UncompressedVideoFrame::mapColorSpaceToBitDepth(colorSpace) ) &&
00269 (out_label_info.width ==
frame_info.width) && (out_label_info.height ==
frame_info.height) &&
00270 (
display_region.left == 0) && (
display_region.top == 0) )
00271 directBitBlt=
true;
00272
else
00273 directBitBlt=
false;
00274
00275
00276
frameBuffer =
new X11FrameBuffer(display, &xwin, depth, gray,
display_region.width,
display_region.height );
00277
00278
if (!
frameBuffer) {
00279 dprintf_err(
"X11Renderer::open(): X11FrameBuffer creation FAILED! (w = %d, h = %d)\n",
00280
display_region.width,
display_region.height );
00281 state = STREAMERR;
00282
return false;
00283 }
00284
00285 state = OPEN;
00286 framesSeen = 0;
00287 currentFrameNumber = 0;
00288 dprintf_small(
"X11Renderer::open(): initialized frame and display regions:\n"
00289
" frame: width = %d, height = %d, size = %d, scaleX = %5.3f, scaleY = %5.3f\n"
00290
" display: x(%d:%d), y(%d:%d), width = %d, height = %d\n",
00291
frame_info.width,
frame_info.height,
frame_info.size,
00292 FIXED2DOUBLE(
frame_info.scaleX), FIXED2DOUBLE(
frame_info.scaleY),
00293
display_region.left,
display_region.left +
display_region.width,
00294
display_region.top,
display_region.top +
display_region.height,
00295
display_region.width,
display_region.height);
00296
return true;
00297 }