void ResetXILFrameBuffers( void ) { XilMemoryStorage storage_info; if( (xil_state = xil_open()) == NULL ) { Sys_Error( "can't start XIL\n" ); } create_xil_window(); draw_image = xil_create( xil_state, vid.width, vid.height, 1, XIL_BYTE ); xil_export( draw_image ); xil_get_memory_storage( draw_image, &storage_info ); vid.buffer = (byte *)storage_info.byte.data; vid.rowbytes = vid.width; /* * If the window is 24-bit, then create an intermediate image that * is used to convert from 8-bit indexed colour to 24-bit true colour. */ if( use_truecolour ) { static unsigned char tmp_palette[ 256 * 4 ]; tmp8to24_image = xil_create( xil_state, vid.width, vid.height, 3, XIL_BYTE ); xil_8to24_lookup = xil_lookup_create( xil_state, XIL_BYTE, XIL_BYTE, 3, 256, 0, tmp_palette ); } }
XilLookup XILWindowAssistor::create_cmap( Colormap *cmap, int type, XilIndexList *ilist, XilLookup yuvtorgb, XilLookup colorcube ) { unsigned long tmp_colors[256], pixels[256], mask; XColor cdefs[256]; int top_colors = 2; /* colormap indices 255 and 254 */ int i, t; Xil_unsigned8 *data; XilLookup lut; int cmapsize; Display *display = Tk_Display(window_->tkwin()); Window window = Tk_WindowId(window_->tkwin()); int screen = Tk_ScreenNumber(window_->tkwin()); //fprintf(stderr,"XILWindowAssistor::"__FUNCTION__"\n"); /* Get colormap size */ switch(type) { case FT_JPEG: case FT_H261: cmapsize = xil_lookup_get_num_entries(yuvtorgb); break; case FT_CELLB: default: /* hmm */ xil_cis_get_attribute(cis_,"DECOMPRESSOR_MAX_CMAP_SIZE", (void**)&cmapsize); break; } /* Create an X colormap for the cis.*/ *cmap = XCreateColormap(display, window, DefaultVisual(display,screen), AllocNone); /* Allocate X Colormap cells * * If we do not need the entire colormap, allocate `cmapsize' * entries just below the top of the colormap. Here's how: * Temporarily allocate some entries at the front of the cmap. * Don't allocate the top_colors (the top two color indices * are often used by other applications). * Allocate the needed entries in the next cmap section * Free the temporary entries. * This allows the X-Window manager to use them and reduces the * chances of of your window colormap flashing. */ if (cmapsize < 256-top_colors) { if (!XAllocColorCells(display, *cmap, 0, &mask, 0, tmp_colors, 256 - cmapsize - top_colors)) { fprintf(stderr, " XAllocColorCells for cmap_create failed(1)\n"); } } if (!XAllocColorCells(display, *cmap, 0, &mask, 0, pixels, cmapsize)) { fprintf(stderr, " XAllocColorCells for cmap_create failed(2)\n"); } /* The remaining code assumes that the values returned in pixels[0] through * pixels[cmapsize-1] are a contiguous range. */ /* Free the unused colors in the front */ if (cmapsize < 256-top_colors) XFreeColors(display, *cmap, tmp_colors, 256 - cmapsize - top_colors, 0); #if 0 if (type == CELLB) { /* Initialize the XilIndexList to use when setting the RDWR_INDICES * attribute. In this example, we make all of the indices writable. */ if ( (ilist->pixels = (Xil_unsigned32 *) malloc(sizeof(Xil_unsigned32) * cmapsize) ) == NULL ) { fprintf(stderr, " out of memory for ilist->pixels create\n"); } ilist->ncolors = cmapsize; /* Copy the color cells returned by XAllocColorCells into the ilist */ for (i = 0; i < cmapsize; i++) ilist->pixels[i] = (Xil_unsigned32) pixels[i]; } #else UNUSED(ilist); #endif /* Allocate memory to hold colormap data. */ if ( (data = (Xil_unsigned8 *) malloc(sizeof(Xil_unsigned8) * cmapsize * 3) ) == NULL ) { fprintf(stderr, "xilcis_color: out of memory for cmap data create\n"); } /* Get the entries for the colormap. The method depends on the compression * type. For CELL, get the entries in the current default colormap. * For JPEG, get the entries from the standard lookup table * yuv_to_rgb. */ switch(type_) { #if 0 /* case FT_CELLB:*/ /* Get the current values in the colormap */ for (i = 0; i < cmapsize; i++) cdefs[i].pixel = i + pixels[0]; XQueryColors(display, DefaultColormap(display, screen), cdefs, cmapsize); /* Convert the values read from the colormap to an array that can * be read by xil_lookup_create. Note that the colormap values are * are stored in the XilLookup in BGR order. */ for (i = 0, j = 0; i < cmapsize; i++, j += 3) { data[j] = cdefs[i].blue >> 8; data[j + 1] = cdefs[i].green >> 8; data[j + 2] = cdefs[i].red >> 8; } lut = xil_lookup_create(xil_, XIL_BYTE, XIL_BYTE, 3, cmapsize, (int)pixels[0], data); break; #endif case FT_JPEG: case FT_H261: case FT_CELLB: xil_lookup_get_values(yuvtorgb, xil_lookup_get_offset(yuvtorgb), cmapsize, data); xil_lookup_set_offset(colorcube, (unsigned int)pixels[0]); for (i = 0, t = 0; i < cmapsize; i++, t += 3) { cdefs[i].pixel = pixels[i]; cdefs[i].flags = DoRed | DoGreen | DoBlue; cdefs[i].blue = data[t] << 8; cdefs[i].green = data[t+1] << 8; cdefs[i].red = data[t+2] << 8; } XStoreColors(display, *cmap, cdefs, cmapsize); lut = yuvtorgb; break; } Tk_SetWindowColormap(window_->tkwin(),*cmap); free(data); return(lut); }