Back to index

lightning-sunbird  0.9+nobinonly
Classes | Defines | Typedefs | Enumerations | Functions | Variables
xlibrgb.c File Reference
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include "xlibrgb.h"

Go to the source code of this file.

Classes

struct  _XlibRgbHandle
struct  _RegisteredHandle

Defines

#define ENABLE_GRAYSCALE
#define G_LITTLE_ENDIAN   1
#define G_BIG_ENDIAN   2
#define G_BYTE_ORDER   G_LITTLE_ENDIAN
#define MIN(a, b)   (((a) < (b)) ? (a) : (b))
#define MAX(a, b)   (((a) > (b)) ? (a) : (b))
#define IMAGE_WIDTH   256
#define STAGE_ROWSTRIDE   (IMAGE_WIDTH * 3)
#define IMAGE_HEIGHT   128
#define N_IMAGES   6
#define HAIRY_CONVERT_8
#define DM_WIDTH   128
#define DM_WIDTH_SHIFT   7
#define DM_HEIGHT   128
#define HAIRY_CONVERT_565
#define HAIRY_CONVERT_888
#define XLIB_USE_FAST_BUT_UGLY_CODE   1
#define XLIB_STATIC_IMAGE_BUFFER_SIZE   (256 * 128 * (32/4))

Typedefs

typedef void(* XlibRgbConvFunc )(XlibRgbHandle *handle, XImage *image, int ax, int ay, int width, int height, unsigned char *buf, int rowstride, int x_align, int y_align, XlibRgbCmap *cmap)
typedef struct _RegisteredHandle RegisteredHandle

Enumerations

enum  ByteOrder { LSB_FIRST, MSB_FIRST }

Functions

static void xxlib_deregister_handle_by_handle (XlibRgbHandle *handle)
static XImage * xxlib_normal_ximage (XlibRgbHandle *handle)
static void xxlib_image_put (XlibRgbHandle *handle, Drawable drawable, GC gc, XImage *image, int xsrc, int ysrc, int xdest, int ydest, int width, int height)
unsigned long xxlib_get_prec_from_mask (unsigned long val)
unsigned long xxlib_get_shift_from_mask (unsigned long val)
static int xxlib_rgb_cmap_fail (XlibRgbHandle *handle, const char *msg, Colormap cmap, unsigned long *pixels)
static void xxlib_rgb_make_colorcube (XlibRgbHandle *handle, unsigned long *pixels, int nr, int ng, int nb)
static void xxlib_rgb_make_colorcube_d (XlibRgbHandle *handle, unsigned long *pixels, int nr, int ng, int nb)
static int xxlib_rgb_try_colormap (XlibRgbHandle *handle, int nr, int ng, int nb)
static Bool xxlib_rgb_do_colormaps (XlibRgbHandle *handle)
static void xxlib_rgb_colorcube_222 (XlibRgbHandle *handle)
static void xxlib_rgb_colorcube_676 (XlibRgbHandle *handle)
void xxlib_rgb_set_verbose (XlibRgbHandle *handle, Bool verbose)
void xxlib_rgb_set_min_colors (XlibRgbHandle *handle, int min_colors)
static uint32 xxlib_rgb_score_visual (XlibRgbHandle *handle, XVisualInfo *visual)
static Bool xxlib_rgb_choose_visual (XlibRgbHandle *handle, XVisualInfo *xtemplate, long xtemplate_mask)
static void xxlib_rgb_select_conv (XlibRgbHandle *handle, XImage *image, ByteOrder byte_order)
static void xxlib_rgb_set_gray_cmap (XlibRgbHandle *handle, Colormap cmap)
void xxlib_rgb_destroy_handle (XlibRgbHandle *handle)
XlibRgbHandle * xxlib_rgb_create_handle (Display *display, Screen *screen, XlibRgbArgs *args)
unsigned long xxlib_rgb_xpixel_from_rgb (XlibRgbHandle *handle, uint32 rgb)
void xxlib_rgb_gc_set_foreground (XlibRgbHandle *handle, GC gc, uint32 rgb)
void xxlib_rgb_gc_set_background (XlibRgbHandle *handle, GC gc, uint32 rgb)
static void xxlib_rgb_convert_8 (XlibRgbHandle *handle, XImage *image, int ax, int ay, int width, int height, unsigned char *buf, int rowstride, int x_align, int y_align, XlibRgbCmap *cmap)
static void xxlib_rgb_preprocess_dm_565 (XlibRgbHandle *handle)
static void xxlib_rgb_convert_8_d666 (XlibRgbHandle *handle, XImage *image, int ax, int ay, int width, int height, unsigned char *buf, int rowstride, int x_align, int y_align, XlibRgbCmap *cmap)
static void xxlib_rgb_convert_8_d (XlibRgbHandle *handle, XImage *image, int ax, int ay, int width, int height, unsigned char *buf, int rowstride, int x_align, int y_align, XlibRgbCmap *cmap)
static void xxlib_rgb_convert_8_indexed (XlibRgbHandle *handle, XImage *image, int ax, int ay, int width, int height, unsigned char *buf, int rowstride, int x_align, int y_align, XlibRgbCmap *cmap)
static void xxlib_rgb_convert_gray8 (XlibRgbHandle *handle, XImage *image, int ax, int ay, int width, int height, unsigned char *buf, int rowstride, int x_align, int y_align, XlibRgbCmap *cmap)
static void xxlib_rgb_convert_gray8_gray (XlibRgbHandle *handle, XImage *image, int ax, int ay, int width, int height, unsigned char *buf, int rowstride, int x_align, int y_align, XlibRgbCmap *cmap)
static void xxlib_rgb_convert_565 (XlibRgbHandle *handle, XImage *image, int ax, int ay, int width, int height, unsigned char *buf, int rowstride, int x_align, int y_align, XlibRgbCmap *cmap)
static void xxlib_rgb_convert_565_gray (XlibRgbHandle *handle, XImage *image, int ax, int ay, int width, int height, unsigned char *buf, int rowstride, int x_align, int y_align, XlibRgbCmap *cmap)
static void xxlib_rgb_convert_565_br (XlibRgbHandle *handle, XImage *image, int ax, int ay, int width, int height, unsigned char *buf, int rowstride, int x_align, int y_align, XlibRgbCmap *cmap)
static void xxlib_rgb_convert_565_d (XlibRgbHandle *handle, XImage *image, int ax, int ay, int width, int height, unsigned char *buf, int rowstride, int x_align, int y_align, XlibRgbCmap *cmap)
static void xxlib_rgb_convert_555 (XlibRgbHandle *handle, XImage *image, int ax, int ay, int width, int height, unsigned char *buf, int rowstride, int x_align, int y_align, XlibRgbCmap *cmap)
static void xxlib_rgb_convert_555_br (XlibRgbHandle *handle, XImage *image, int ax, int ay, int width, int height, unsigned char *buf, int rowstride, int x_align, int y_align, XlibRgbCmap *cmap)
static void xxlib_rgb_convert_888_msb (XlibRgbHandle *handle, XImage *image, int ax, int ay, int width, int height, unsigned char *buf, int rowstride, int x_align, int y_align, XlibRgbCmap *cmap)
static void xxlib_rgb_convert_888_lsb (XlibRgbHandle *handle, XImage *image, int ax, int ay, int width, int height, unsigned char *buf, int rowstride, int x_align, int y_align, XlibRgbCmap *cmap)
static void xxlib_rgb_convert_0888 (XlibRgbHandle *handle, XImage *image, int ax, int ay, int width, int height, unsigned char *buf, int rowstride, int x_align, int y_align, XlibRgbCmap *cmap)
static void xxlib_rgb_convert_0888_br (XlibRgbHandle *handle, XImage *image, int ax, int ay, int width, int height, unsigned char *buf, int rowstride, int x_align, int y_align, XlibRgbCmap *cmap)
static void xxlib_rgb_convert_8880_br (XlibRgbHandle *handle, XImage *image, int ax, int ay, int width, int height, unsigned char *buf, int rowstride, int x_align, int y_align, XlibRgbCmap *cmap)
static void xxlib_rgb_convert_truecolor_lsb (XlibRgbHandle *handle, XImage *image, int ax, int ay, int width, int height, unsigned char *buf, int rowstride, int x_align, int y_align, XlibRgbCmap *cmap)
static void xxlib_rgb_convert_truecolor_lsb_d (XlibRgbHandle *handle, XImage *image, int ax, int ay, int width, int height, unsigned char *buf, int rowstride, int x_align, int y_align, XlibRgbCmap *cmap)
static void xxlib_rgb_convert_truecolor_msb (XlibRgbHandle *handle, XImage *image, int ax, int ay, int width, int height, unsigned char *buf, int rowstride, int x_align, int y_align, XlibRgbCmap *cmap)
static void xxlib_rgb_convert_truecolor_msb_d (XlibRgbHandle *handle, XImage *image, int ax, int ay, int width, int height, unsigned char *buf, int rowstride, int x_align, int y_align, XlibRgbCmap *cmap)
static void xxlib_rgb_convert_4 (XlibRgbHandle *handle, XImage *image, int ax, int ay, int width, int height, unsigned char *buf, int rowstride, int x_align, int y_align, XlibRgbCmap *cmap)
static void xxlib_rgb_convert_gray4 (XlibRgbHandle *handle, XImage *image, int ax, int ay, int width, int height, unsigned char *buf, int rowstride, int x_align, int y_align, XlibRgbCmap *cmap)
static void xxlib_rgb_convert_gray4_pack (XlibRgbHandle *handle, XImage *image, int ax, int ay, int width, int height, unsigned char *buf, int rowstride, int x_align, int y_align, XlibRgbCmap *cmap)
static void xxlib_rgb_convert_gray4_d (XlibRgbHandle *handle, XImage *image, int ax, int ay, int width, int height, unsigned char *buf, int rowstride, int x_align, int y_align, XlibRgbCmap *cmap)
static void xxlib_rgb_convert_gray4_d_pack (XlibRgbHandle *handle, XImage *image, int ax, int ay, int width, int height, unsigned char *buf, int rowstride, int x_align, int y_align, XlibRgbCmap *cmap)
static void xxlib_rgb_convert_1 (XlibRgbHandle *handle, XImage *image, int ax, int ay, int width, int height, unsigned char *buf, int rowstride, int x_align, int y_align, XlibRgbCmap *cmap)
static unsigned char * xxlib_rgb_ensure_stage (XlibRgbHandle *handle)
static void xxlib_rgb_32_to_stage (XlibRgbHandle *handle, unsigned char *buf, int rowstride, int width, int height)
static void xxlib_rgb_convert_32_generic (XlibRgbHandle *handle, XImage *image, int ax, int ay, int width, int height, unsigned char *buf, int rowstride, int x_align, int y_align, XlibRgbCmap *cmap)
static void xxlib_rgb_convert_32_generic_d (XlibRgbHandle *handle, XImage *image, int ax, int ay, int width, int height, unsigned char *buf, int rowstride, int x_align, int y_align, XlibRgbCmap *cmap)
static void xxlib_rgb_gray_to_stage (XlibRgbHandle *handle, unsigned char *buf, int rowstride, int width, int height)
static void xxlib_rgb_convert_gray_generic (XlibRgbHandle *handle, XImage *image, int ax, int ay, int width, int height, unsigned char *buf, int rowstride, int x_align, int y_align, XlibRgbCmap *cmap)
static void xxlib_rgb_convert_gray_generic_d (XlibRgbHandle *handle, XImage *image, int ax, int ay, int width, int height, unsigned char *buf, int rowstride, int x_align, int y_align, XlibRgbCmap *cmap)
static void xxlib_rgb_convert_gray_cmap (XlibRgbHandle *handle, XImage *image, int ax, int ay, int width, int height, unsigned char *buf, int rowstride, int x_align, int y_align, XlibRgbCmap *cmap)
static void xxlib_rgb_indexed_to_stage (XlibRgbHandle *handle, unsigned char *buf, int rowstride, int width, int height, XlibRgbCmap *cmap)
static void xxlib_rgb_convert_indexed_generic (XlibRgbHandle *handle, XImage *image, int ax, int ay, int width, int height, unsigned char *buf, int rowstride, int x_align, int y_align, XlibRgbCmap *cmap)
static void xxlib_rgb_convert_indexed_generic_d (XlibRgbHandle *handle, XImage *image, int ax, int ay, int width, int height, unsigned char *buf, int rowstride, int x_align, int y_align, XlibRgbCmap *cmap)
static int xxlib_rgb_alloc_scratch_image (XlibRgbHandle *handle)
static XImage * xxlib_rgb_alloc_scratch (XlibRgbHandle *handle, int width, int height, int *ax, int *ay)
static int xxlib_get_bits_per_pixel (XlibRgbHandle *handle, int depth)
static void xxlib_draw_rgb_image_core (XlibRgbHandle *handle, Drawable drawable, GC gc, int x, int y, int width, int height, unsigned char *buf, int pixstride, int rowstride, XlibRgbConvFunc conv, XlibRgbCmap *cmap, int xdith, int ydith)
void xxlib_draw_rgb_image (XlibRgbHandle *handle, Drawable drawable, GC gc, int x, int y, int width, int height, XlibRgbDither dith, unsigned char *rgb_buf, int rowstride)
void xxlib_draw_rgb_image_dithalign (XlibRgbHandle *handle, Drawable drawable, GC gc, int x, int y, int width, int height, XlibRgbDither dith, unsigned char *rgb_buf, int rowstride, int xdith, int ydith)
void xxlib_draw_rgb_32_image (XlibRgbHandle *handle, Drawable drawable, GC gc, int x, int y, int width, int height, XlibRgbDither dith, unsigned char *buf, int rowstride)
static void xxlib_rgb_make_gray_cmap (XlibRgbHandle *handle)
void xxlib_draw_gray_image (XlibRgbHandle *handle, Drawable drawable, GC gc, int x, int y, int width, int height, XlibRgbDither dith, unsigned char *buf, int rowstride)
XlibRgbCmap * xxlib_rgb_cmap_new (XlibRgbHandle *handle, uint32 *colors, int n_colors)
void xxlib_rgb_cmap_free (XlibRgbHandle *handle, XlibRgbCmap *cmap)
void xxlib_draw_indexed_image (XlibRgbHandle *handle, Drawable drawable, GC gc, int x, int y, int width, int height, XlibRgbDither dith, unsigned char *buf, int rowstride, XlibRgbCmap *cmap)
void xxlib_draw_xprint_scaled_rgb_image (XlibRgbHandle *handle, Drawable drawable, long paper_resolution, long image_resolution, GC gc, int x, int y, int width, int height, XlibRgbDither dith, unsigned char *rgb_buf, int rowstride)
Bool xxlib_rgb_ditherable (XlibRgbHandle *handle)
Colormap xxlib_rgb_get_cmap (XlibRgbHandle *handle)
Visual * xxlib_rgb_get_visual (XlibRgbHandle *handle)
XVisualInfo * xxlib_rgb_get_visual_info (XlibRgbHandle *handle)
int xxlib_rgb_get_depth (XlibRgbHandle *handle)
Displayxxlib_rgb_get_display (XlibRgbHandle *handle)
Screen * xxlib_rgb_get_screen (XlibRgbHandle *handle)
static RegisteredHandlexxlib_find_registered_handle (const char *name)
Bool xxlib_register_handle (const char *name, XlibRgbHandle *handle)
Bool xxlib_deregister_handle (const char *name)
XlibRgbHandle * xxlib_find_handle (const char *name)

Variables

static const unsigned char DM [128][128]
static RegisteredHandleregistered_handles = NULL
static unsigned int registered_handles_size = 0

Class Documentation

struct _XlibRgbHandle

Definition at line 152 of file xlibrgb.c.

Collaboration diagram for _XlibRgbHandle:
Class Members
Bool bitmap
unsigned long blue_prec
unsigned long blue_shift
unsigned int bpp
Colormap cmap
unsigned int cmap_alloced
unsigned long * color_pixels
unsigned char * colorcube
unsigned char * colorcube_d
XlibRgbConvFunc conv
XlibRgbConvFunc conv_32
XlibRgbConvFunc conv_32_d
XlibRgbConvFunc conv_d
XlibRgbConvFunc conv_gray
XlibRgbConvFunc conv_gray_d
XlibRgbConvFunc conv_indexed
XlibRgbConvFunc conv_indexed_d
Colormap default_colormap
Visual * default_visualid
Bool disallow_image_tiling
Display * display
Bool dith_default
uint32 * DM_565
double gamma_val
XlibRgbCmap * gray_cmap
unsigned long * gray_pixels
unsigned long green_prec
unsigned long green_shift
int horiz_idx
int horiz_y
long max_request_size
unsigned int nblue_shades
unsigned int ngray_shades
unsigned int ngreen_shades
unsigned int nred_shades
unsigned int nreserved
GC own_gc
unsigned long red_prec
unsigned long red_shift
unsigned long * reserved_pixels
Screen * screen
int screen_num
unsigned char * stage_buf
char * static_buffer
XImage * static_image
int static_image_idx
int tile_idx
int tile_x
int tile_y1
int tile_y2
int vert_idx
int vert_x
XVisualInfo * x_visual_info
Bool xlib_rgb_install_cmap
int xlib_rgb_min_colors
Bool xlib_rgb_verbose
struct _RegisteredHandle

Definition at line 4025 of file xlibrgb.c.

Class Members
XlibRgbHandle * handle
const char * name

Define Documentation

#define DM_HEIGHT   128

Definition at line 1444 of file xlibrgb.c.

#define DM_WIDTH   128

Definition at line 1442 of file xlibrgb.c.

Definition at line 1443 of file xlibrgb.c.

Definition at line 79 of file xlibrgb.c.

Definition at line 82 of file xlibrgb.c.

Definition at line 114 of file xlibrgb.c.

Definition at line 81 of file xlibrgb.c.

Definition at line 1785 of file xlibrgb.c.

Definition at line 1322 of file xlibrgb.c.

Definition at line 2328 of file xlibrgb.c.

#define IMAGE_HEIGHT   128

Definition at line 143 of file xlibrgb.c.

#define IMAGE_WIDTH   256

Definition at line 141 of file xlibrgb.c.

#define MAX (   a,
  b 
)    (((a) > (b)) ? (a) : (b))

Definition at line 123 of file xlibrgb.c.

#define MIN (   a,
  b 
)    (((a) < (b)) ? (a) : (b))

Definition at line 119 of file xlibrgb.c.

#define N_IMAGES   6

Definition at line 144 of file xlibrgb.c.

Definition at line 142 of file xlibrgb.c.

#define XLIB_STATIC_IMAGE_BUFFER_SIZE   (256 * 128 * (32/4))

Definition at line 3535 of file xlibrgb.c.

Definition at line 3529 of file xlibrgb.c.


Typedef Documentation

typedef void(* XlibRgbConvFunc)(XlibRgbHandle *handle, XImage *image, int ax, int ay, int width, int height, unsigned char *buf, int rowstride, int x_align, int y_align, XlibRgbCmap *cmap)

Definition at line 133 of file xlibrgb.c.


Enumeration Type Documentation

enum ByteOrder
Enumerator:
LSB_FIRST 
MSB_FIRST 

Definition at line 126 of file xlibrgb.c.


Function Documentation

Definition at line 4095 of file xlibrgb.c.

{
  RegisteredHandle *entry;
  if ((entry = xxlib_find_registered_handle(name)) != NULL)
  {
    free((void *)entry->name);
    entry->name   = NULL;
    entry->handle = NULL;
    return True;
  }
  
  return False;  
}

Here is the call graph for this function:

static void xxlib_deregister_handle_by_handle ( XlibRgbHandle *  handle) [static]

Definition at line 4112 of file xlibrgb.c.

{
  unsigned int i;
  
  if (!handle)
    return;
  
  for( i=0 ; i < registered_handles_size ; i++ )
  {
    if (registered_handles[i].handle == handle)
    {
      free((void *)registered_handles[i].name);
      registered_handles[i].name   = NULL;
      registered_handles[i].handle = NULL;    
    }
  }
}

Here is the caller graph for this function:

void xxlib_draw_gray_image ( XlibRgbHandle *  handle,
Drawable  drawable,
GC  gc,
int  x,
int  y,
int  width,
int  height,
XlibRgbDither  dith,
unsigned char *  buf,
int  rowstride 
)

Definition at line 3827 of file xlibrgb.c.

{
  if (handle->bpp == 1 &&
      handle->gray_cmap == NULL &&
      (handle->x_visual_info->class == PseudoColor ||
       handle->x_visual_info->class == GrayScale))
    xxlib_rgb_make_gray_cmap (handle);
  
  if (dith == XLIB_RGB_DITHER_NONE || (dith == XLIB_RGB_DITHER_NORMAL &&
                                      !handle->dith_default))
    xxlib_draw_rgb_image_core (handle, drawable, gc, x, y, width, height,
                              buf, 1, rowstride,
                              handle->conv_gray, NULL, 0, 0);
  else
    xxlib_draw_rgb_image_core (handle, drawable, gc, x, y, width, height,
                              buf, 1, rowstride,
                              handle->conv_gray_d, NULL, 0, 0);
}

Here is the call graph for this function:

void xxlib_draw_indexed_image ( XlibRgbHandle *  handle,
Drawable  drawable,
GC  gc,
int  x,
int  y,
int  width,
int  height,
XlibRgbDither  dith,
unsigned char *  buf,
int  rowstride,
XlibRgbCmap *  cmap 
)

Definition at line 3891 of file xlibrgb.c.

{
  if (dith == XLIB_RGB_DITHER_NONE || (dith == XLIB_RGB_DITHER_NORMAL &&
                                       !handle->dith_default))
    xxlib_draw_rgb_image_core (handle, drawable, gc, x, y, width, height,
                               buf, 1, rowstride,
                               handle->conv_indexed, cmap, 0, 0);
  else
    xxlib_draw_rgb_image_core (handle, drawable, gc, x, y, width, height,
                               buf, 1, rowstride,
                               handle->conv_indexed_d, cmap, 0, 0);
}

Here is the call graph for this function:

void xxlib_draw_rgb_32_image ( XlibRgbHandle *  handle,
Drawable  drawable,
GC  gc,
int  x,
int  y,
int  width,
int  height,
XlibRgbDither  dith,
unsigned char *  buf,
int  rowstride 
)

Definition at line 3794 of file xlibrgb.c.

{
  if (dith == XLIB_RGB_DITHER_NONE || (dith == XLIB_RGB_DITHER_NORMAL &&
                                       !handle->dith_default))
    xxlib_draw_rgb_image_core (handle, drawable, gc, x, y, width, height,
                               buf, 4, rowstride,
                               handle->conv_32, NULL, 0, 0);
  else
    xxlib_draw_rgb_image_core (handle, drawable, gc, x, y, width, height,
                               buf, 4, rowstride,
                               handle->conv_32_d, NULL, 0, 0);
}

Here is the call graph for this function:

void xxlib_draw_rgb_image ( XlibRgbHandle *  handle,
Drawable  drawable,
GC  gc,
int  x,
int  y,
int  width,
int  height,
XlibRgbDither  dith,
unsigned char *  rgb_buf,
int  rowstride 
)

Definition at line 3748 of file xlibrgb.c.

{
  if (dith == XLIB_RGB_DITHER_NONE || (dith == XLIB_RGB_DITHER_NORMAL &&
                                      !handle->dith_default))
    xxlib_draw_rgb_image_core (handle, drawable, gc, x, y, width, height,
                              rgb_buf, 3, rowstride, handle->conv, NULL,
                              0, 0);
  else
    xxlib_draw_rgb_image_core (handle, drawable, gc, x, y, width, height,
                              rgb_buf, 3, rowstride, handle->conv_d, NULL,
                              0, 0);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void xxlib_draw_rgb_image_core ( XlibRgbHandle *  handle,
Drawable  drawable,
GC  gc,
int  x,
int  y,
int  width,
int  height,
unsigned char *  buf,
int  pixstride,
int  rowstride,
XlibRgbConvFunc  conv,
XlibRgbCmap *  cmap,
int  xdith,
int  ydith 
) [static]

Definition at line 3538 of file xlibrgb.c.

{
  Bool do_tile;
  
  if (handle->bitmap)
  {
    if (handle->own_gc == None)
    {
      XColor color;

      handle->own_gc = XCreateGC(handle->display,
                                 drawable,
                                 0, NULL);
      color.pixel = XWhitePixel(handle->display,
                                handle->screen_num);
      XSetForeground(handle->display, handle->own_gc, color.pixel);
      color.pixel = XBlackPixel(handle->display,
                                handle->screen_num);
      XSetBackground(handle->display, handle->own_gc, color.pixel);
    }
    gc = handle->own_gc;
  }

  /* Avoid image tiling for small images (1/32 of the maximum request size -
   * guranteed to be at least 16384 bytes). Tiling buffers are rare - and 
   * in the case of MIT-SHM require a XFlush() if all tile images have been used-up.
   */
  do_tile = ((handle->x_visual_info->depth+7)/8 * width * height) > (handle->max_request_size/32);
      
  if( (!handle->disallow_image_tiling) && do_tile )
  {
    int ay, ax;
    int xs0, ys0;
    int width1, height1;
    unsigned char *buf_ptr;
    XImage *image;
          
    for (ay = 0; ay < height; ay += IMAGE_HEIGHT)
    {
      height1 = MIN (height - ay, IMAGE_HEIGHT);
      for (ax = 0; ax < width; ax += IMAGE_WIDTH)
      {
        width1 = MIN (width - ax, IMAGE_WIDTH);
        buf_ptr = buf + ay * rowstride + ax * pixstride;

        image = xxlib_rgb_alloc_scratch (handle, width1, height1, &xs0, &ys0);

        conv (handle, image, xs0, ys0, width1, height1, buf_ptr, rowstride,
              x + ax + xdith, y + ay + ydith, cmap);

#ifndef DONT_ACTUALLY_DRAW
        xxlib_image_put(handle, drawable, gc, image,
                       xs0, ys0, x + ax, y + ay,
                       (unsigned int)width1, (unsigned int)height1);
#endif /* !DONT_ACTUALLY_DRAW */
      }
    }
  }
  else
#ifdef XLIB_USE_FAST_BUT_UGLY_CODE
  /* This is a heavily optimized version of the implementation used when  
   * XLIB_USE_FAST_BUT_UGLY_CODE is not set. It tries to avoid malloc()/XCreateImage() 
   * by using a static buffer if possible - but uses malloc() when the image data are 
   * too large to fit info that buffer...
   */
  {    
    XImage ximage;
    int    format;
    int    depth;
    int    xpad;
    long   image_data_size;
    
    /* allocate static buffer if we do not have one yet... */      
    if( handle->static_buffer == NULL )
    {
      handle->static_buffer = malloc(XLIB_STATIC_IMAGE_BUFFER_SIZE);
      if(!handle->static_buffer)
        return; /* error - no memory */
    }
    
    /* fill the XImage structure... */
    memset(&ximage, 0, sizeof(ximage));
    
    if (handle->bitmap) 
    {
      format = XYBitmap;
      depth  = 1;
      xpad   = 8;
    }
    else 
    {
      format = ZPixmap;
      depth  = handle->x_visual_info->depth;
      xpad   = 32;
    }

    ximage.width            = width;
    ximage.height           = height;
    ximage.format           = format;
    ximage.byte_order       = XImageByteOrder(handle->display);
    ximage.bitmap_unit      = XBitmapUnit(handle->display);
    ximage.bitmap_bit_order = XBitmapBitOrder(handle->display);
    ximage.red_mask         = handle->x_visual_info->visual->red_mask;
    ximage.green_mask       = handle->x_visual_info->visual->green_mask;
    ximage.blue_mask        = handle->x_visual_info->visual->blue_mask;
    if (format == ZPixmap) 
      ximage.bits_per_pixel = xxlib_get_bits_per_pixel(handle, depth);
    ximage.xoffset          = 0;
    ximage.bitmap_pad       = xpad;
    ximage.depth            = depth;
    ximage.data             = NULL;
    ximage.bytes_per_line   = 0; /* let XInitImage() calculate that... */
    ximage.obdata           = NULL;
    ximage.bitmap_bit_order = MSBFirst;
    ximage.byte_order       = MSBFirst;

    if(!XInitImage(&ximage))
    {
#ifdef DSIABLED_FOR_NOW_DUE_LINK_ISSUES
      NS_ERROR("xlib_draw_rgb_image_core: XInitImage() failure - should not happen...\n");
#endif /* DSIABLED_FOR_NOW_DUE_LINK_ISSUES */    
      return; /* error - should not happen... */
    }
    
    image_data_size = height*ximage.bytes_per_line;     

    if (image_data_size > XLIB_STATIC_IMAGE_BUFFER_SIZE)
    {
#ifdef VERBOSE
      printf("xlib_draw_rgb_image_core: Allocating extra large buffer(%ld > %ld)...\n",
             (long)image_data_size, (long)XLIB_STATIC_IMAGE_BUFFER_SIZE);
#endif /* VERBOSE */
      ximage.data = malloc(image_data_size);
      if (!ximage.data)
        return; /* error - no memory */
    }
    else
    {
      ximage.data = handle->static_buffer; 
    }

    conv (handle, &ximage, 0, 0, width, height, buf, rowstride,
          0, 0, cmap);

#ifndef DONT_ACTUALLY_DRAW
    XPutImage(handle->display, drawable, gc, &ximage,
    0, 0, x, y, (unsigned int)width, (unsigned int)height);
#endif

    /* free any extra memory we may have allocated above */
    if (ximage.data != handle->static_buffer)
      free(ximage.data);
  }
#else
  /* this is the clean&pretty version of the code above... */
  {
    XImage *image;
    
    if (handle->bitmap) 
    {
      image = XCreateImage(handle->display,
                           handle->x_visual_info->visual,
                           1,
                           XYBitmap,
                           0, 0, width, height,
                           8, 0);
    }
    else 
    {
      image = XCreateImage(handle->display,
                           handle->x_visual_info->visual,
                           (unsigned int)handle->x_visual_info->depth,
                           ZPixmap,
                           0, 0, width, height,
                           32, 0);
    }

    /* Use malloc() instead of g_malloc since X will free() this mem */
    image->data = malloc(height*image->bytes_per_line);
    image->bitmap_bit_order = MSBFirst;
    image->byte_order       = MSBFirst;      

    conv( handle, image, 0, 0, width, height, buf, rowstride,
          0, 0, cmap);

#ifndef DONT_ACTUALLY_DRAW
    XPutImage(handle->display, drawable, gc, image,
    0, 0, x, y, (unsigned int)width, (unsigned int)height);
#endif

    XDestroyImage(image);
  }
#endif /* XLIB_USE_FAST_BUT_UGLY_CODE */  
}

Here is the call graph for this function:

Here is the caller graph for this function:

void xxlib_draw_rgb_image_dithalign ( XlibRgbHandle *  handle,
Drawable  drawable,
GC  gc,
int  x,
int  y,
int  width,
int  height,
XlibRgbDither  dith,
unsigned char *  rgb_buf,
int  rowstride,
int  xdith,
int  ydith 
)

Definition at line 3770 of file xlibrgb.c.

{
  if (dith == XLIB_RGB_DITHER_NONE || (dith == XLIB_RGB_DITHER_NORMAL &&
                                       !handle->dith_default))
    xxlib_draw_rgb_image_core (handle, drawable, gc, x, y, width, height,
                              rgb_buf, 3, rowstride, handle->conv, NULL,
                              xdith, ydith);
  else
    xxlib_draw_rgb_image_core (handle, drawable, gc, x, y, width, height,
                               rgb_buf, 3, rowstride, handle->conv_d, NULL,
                               xdith, ydith);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void xxlib_draw_xprint_scaled_rgb_image ( XlibRgbHandle *  handle,
Drawable  drawable,
long  paper_resolution,
long  image_resolution,
GC  gc,
int  x,
int  y,
int  width,
int  height,
XlibRgbDither  dith,
unsigned char *  rgb_buf,
int  rowstride 
)

Definition at line 3914 of file xlibrgb.c.

{
  long available = ((65536 < handle->max_request_size) ? 
                    (65536 << 1):(handle->max_request_size << 1))
                 - 512 /* SIZEOF(xPutImageReq) */;
                
  if (image_resolution == 0)
    image_resolution = paper_resolution;

  if( (rowstride * height) < available )
  {
    xxlib_draw_rgb_image(handle,
                         drawable,
                         gc,
                         x, y, width, height,
                         dith,
                         rgb_buf, rowstride);
  }
  else
  {
    int    subimageheight = available / rowstride;
    double scaling_factor = (double)paper_resolution / (double)image_resolution;

#ifdef DEBUG    
    printf("xxlib_draw_xprint_scaled_rgb_image: "
           "splitting image x=%d, y=%d, width=%d, height=%d, subimageheight=%d, scaling_factor=%g, max_request_size=%ld, available=%ld\n",
           x, y, width, height, subimageheight, scaling_factor, (long)handle->max_request_size, (long)available);
#endif /* DEBUG */

    if (subimageheight == 0)
        subimageheight = 1;

      xxlib_draw_xprint_scaled_rgb_image(handle,
                                         drawable,
                                         paper_resolution, image_resolution,
                                         gc,
                                         x, y,
                                         width, subimageheight,
                                         dith,
                                         rgb_buf,
                                         rowstride);

      xxlib_draw_xprint_scaled_rgb_image(handle,
                                         drawable,
                                         paper_resolution, image_resolution,
                                         gc,
                                         x, y+(int)((double)subimageheight*scaling_factor), 
                                         width, (height-subimageheight),
                                         dith,
                                         (rgb_buf+(subimageheight*rowstride)),
                                         rowstride);
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

XlibRgbHandle* xxlib_find_handle ( const char *  name)

Definition at line 4131 of file xlibrgb.c.

{
  RegisteredHandle *entry = xxlib_find_registered_handle(name);
  return (entry)?(entry->handle):(NULL);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static RegisteredHandle* xxlib_find_registered_handle ( const char *  name) [static]

Definition at line 4036 of file xlibrgb.c.

{
  unsigned int i;
  
  for( i=0 ; i < registered_handles_size ; i++ )
  {
    if (name && registered_handles[i].name && 
        !strcmp(name, registered_handles[i].name))
      return &registered_handles[i];
  }
  
  return NULL;
}

Here is the caller graph for this function:

static int xxlib_get_bits_per_pixel ( XlibRgbHandle *  handle,
int  depth 
) [static]

Definition at line 3517 of file xlibrgb.c.

{
  if (depth <= 4)
      return 4;
  if (depth <= 8)
      return 8;
  if (depth <= 16)
      return 16;
  return 32;
}

Here is the caller graph for this function:

unsigned long xxlib_get_prec_from_mask ( unsigned long  val)

Definition at line 394 of file xlibrgb.c.

{
  unsigned long retval = 0;
  unsigned int cur_bit = 0;
  /* walk through the number, incrementing the value if
     the bit in question is set. */
  while (cur_bit < (sizeof(unsigned long) * 8)) {
    if ((val >> cur_bit) & 0x1) {
      retval++;
    }
    cur_bit++;
  }
  return retval;
}

Here is the caller graph for this function:

unsigned long xxlib_get_shift_from_mask ( unsigned long  val)

Definition at line 410 of file xlibrgb.c.

{
  unsigned long cur_bit = 0;
  /* walk through the number, looking for the first 1 */
  while (cur_bit < (sizeof(unsigned long) * 8)) {
    if ((val >> cur_bit) & 0x1) {
      return cur_bit;
    }
    cur_bit++;
  }
  return cur_bit;
}

Here is the caller graph for this function:

static void xxlib_image_put ( XlibRgbHandle *  handle,
Drawable  drawable,
GC  gc,
XImage *  image,
int  xsrc,
int  ysrc,
int  xdest,
int  ydest,
int  width,
int  height 
) [static]

Definition at line 351 of file xlibrgb.c.

{
#ifdef XLIBRGB_ENABLE_MITSHM_SUPPORT
  if (handle->xlib_use_shm)
  {
    XShmPutImage(handle->display, drawable,
                 gc, image,
                 xsrc, ysrc, xdest, ydest, width, height, False);
  }  
  else
#endif /* XLIBRGB_ENABLE_MITSHM_SUPPORT */  
  {
    XPutImage(handle->display, drawable, gc, image,
              xsrc, ysrc, xdest, ydest,
              (unsigned int)width, (unsigned int)height);
  }
}

Here is the caller graph for this function:

static XImage* xxlib_normal_ximage ( XlibRgbHandle *  handle) [static]

Definition at line 239 of file xlibrgb.c.

{
  XImage *ximage;

  if (handle->bitmap) {
    ximage = XCreateImage(handle->display,
                          handle->x_visual_info->visual,
                          1,
                          XYBitmap,
                          0, 0, IMAGE_WIDTH, IMAGE_HEIGHT,
                          8,
                          0);
  }
  else 
  {  
    ximage = XCreateImage(handle->display,
                          handle->x_visual_info->visual,
                          (unsigned int)handle->x_visual_info->depth,
                          ZPixmap,
                          0, 0,
                          IMAGE_WIDTH,
                          IMAGE_HEIGHT,
                          32, 0);
  }

  if (!ximage)
    return NULL;
    
  ximage->data = malloc(ximage->height * ximage->bytes_per_line);
  if (!ximage->data)
  {
    XDestroyImage(ximage);
    return NULL;
  }
  
  ximage->bitmap_bit_order = MSBFirst;
  ximage->byte_order = MSBFirst;
    
  return ximage;
}

Here is the caller graph for this function:

Bool xxlib_register_handle ( const char *  name,
XlibRgbHandle *  handle 
)

Definition at line 4055 of file xlibrgb.c.

{
  RegisteredHandle *entry = NULL;
  unsigned int i;
  
  if (xxlib_find_handle(name) || (handle == NULL))
    return False;
  
  /* search for a free slot... */  
  for( i=0 ; i < registered_handles_size ; i++ )
  {
    if (!registered_handles[i].handle)
    {
      entry = &registered_handles[i];
      break;
    }
  }
  
  /* ... no unused entry found ? Then allocate a new one... */
  if (!entry)
  {
    registered_handles_size++;
    registered_handles = realloc(registered_handles, sizeof(RegisteredHandle)*registered_handles_size);
  
    if (!registered_handles)
      abort();
    entry = &registered_handles[registered_handles_size-1];
  }

  entry->name   = strdup(name);
  entry->handle = handle;
  
  return True;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void xxlib_rgb_32_to_stage ( XlibRgbHandle *  handle,
unsigned char *  buf,
int  rowstride,
int  width,
int  height 
) [static]

Definition at line 3051 of file xlibrgb.c.

{
  int x, y;
  unsigned char *pi_start, *po_start;
  unsigned char *pi, *po;

  pi_start = buf;
  po_start = xxlib_rgb_ensure_stage (handle);
  for (y = 0; y < height; y++)
    {
      pi = pi_start;
      po = po_start;
      for (x = 0; x < width; x++)
        {
          *po++ = *pi++;
          *po++ = *pi++;
          *po++ = *pi++;
          pi++;
        }
      pi_start += rowstride;
      po_start += STAGE_ROWSTRIDE;
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static XImage* xxlib_rgb_alloc_scratch ( XlibRgbHandle *  handle,
int  width,
int  height,
int ax,
int ay 
) [static]

Definition at line 3446 of file xlibrgb.c.

{
  XImage *image;
  int idx;

  if (width >= (IMAGE_WIDTH >> 1))
  {
    if (height >= (IMAGE_HEIGHT >> 1))
    {
      idx = xxlib_rgb_alloc_scratch_image (handle);
      *ax = 0;
      *ay = 0;
    }
    else
    {
      if (height + handle->horiz_y > IMAGE_HEIGHT)
      {
        handle->horiz_idx = xxlib_rgb_alloc_scratch_image (handle);
        handle->horiz_y = 0;
      }
      idx = handle->horiz_idx;
      *ax = 0;
      *ay = handle->horiz_y;
      handle->horiz_y += height;
    }
  }
  else
  {
    if (height >= (IMAGE_HEIGHT >> 1))
    {
      if (width + handle->vert_x > IMAGE_WIDTH)
      {
        handle->vert_idx = xxlib_rgb_alloc_scratch_image (handle);
        handle->vert_x = 0;
      }
      idx = handle->vert_idx;
      *ax = handle->vert_x;
      *ay = 0;
      /* using 3 and -4 would be slightly more efficient on 32-bit machines
         with > 1bpp displays */
      handle->vert_x += (width + 7) & -8;
    }
    else
    {
      if (width + handle->tile_x > IMAGE_WIDTH)
      {
        handle->tile_y1 = handle->tile_y2;
        handle->tile_x = 0;
      }
      if (height + handle->tile_y1 > IMAGE_HEIGHT)
      {
        handle->tile_idx = xxlib_rgb_alloc_scratch_image (handle);
        handle->tile_x = 0;
        handle->tile_y1 = 0;
        handle->tile_y2 = 0;
      }
      if (height + handle->tile_y1 > handle->tile_y2)
        handle->tile_y2 = height + handle->tile_y1;
      idx = handle->tile_idx;
      *ax = handle->tile_x;
      *ay = handle->tile_y1;
      handle->tile_x += (width + 7) & -8;
    }
  }
  image = handle->static_image[idx];

  return image;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int xxlib_rgb_alloc_scratch_image ( XlibRgbHandle *  handle) [static]

Definition at line 3426 of file xlibrgb.c.

{
  if (handle->static_image_idx == N_IMAGES)
  {
#ifdef XLIBRGB_ENABLE_MITSHM_SUPPORT
    if (handle->xlib_use_shm)
      XFlush(handle->display);
#endif /* XLIBRGB_ENABLE_MITSHM_SUPPORT */
      
    handle->static_image_idx = 0;
    handle->horiz_y = IMAGE_HEIGHT;
    handle->vert_x  = IMAGE_WIDTH;
    handle->tile_x  = IMAGE_WIDTH;
    handle->tile_y1 = handle->tile_y2 = IMAGE_HEIGHT;
  }
  
  return handle->static_image_idx++;
}

Here is the caller graph for this function:

static Bool xxlib_rgb_choose_visual ( XlibRgbHandle *  handle,
XVisualInfo *  xtemplate,
long  xtemplate_mask 
) [static]

Definition at line 833 of file xlibrgb.c.

{
  XVisualInfo *visuals;
  XVisualInfo *visual;
  XVisualInfo *best_visual;
  XVisualInfo *final_visual;
  int num_visuals;
  uint32 score, best_score;
  int cur_visual = 1;
  int i;
   
  xtemplate_mask |= VisualScreenMask;
  xtemplate->screen = handle->screen_num;
  visuals = XGetVisualInfo(handle->display, xtemplate_mask,
                           xtemplate, &num_visuals);
  if (!visuals)
    return False;
    
  best_visual = visuals;
  best_score = xxlib_rgb_score_visual (handle, best_visual);

  for (i = cur_visual; i < num_visuals; i++)
  {
    visual = &visuals[i];
    score = xxlib_rgb_score_visual (handle, visual);
    if (score > best_score)
    {
      best_score = score;
      best_visual = visual;
    }
  }
  /* make a copy of the visual so that we can free
   * the allocated visual list above. */
  final_visual = malloc(sizeof(XVisualInfo));
  memcpy(final_visual, best_visual, sizeof(XVisualInfo));
  handle->x_visual_info = final_visual;
  XFree(visuals);
  
  return True;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int xxlib_rgb_cmap_fail ( XlibRgbHandle *  handle,
const char *  msg,
Colormap  cmap,
unsigned long pixels 
) [static]

Definition at line 425 of file xlibrgb.c.

{
  unsigned long free_pixels[256];
  int n_free;
  int i;

#ifdef VERBOSE
  printf ("%s", msg);
#endif
  n_free = 0;
  for (i = 0; i < 256; i++)
    if (pixels[i] < 256)
      free_pixels[n_free++] = pixels[i];
  
  if (n_free)
    XFreeColors(handle->display,
                cmap,
                free_pixels,
                n_free,
                0);
  return 0;
}

Here is the caller graph for this function:

void xxlib_rgb_cmap_free ( XlibRgbHandle *  handle,
XlibRgbCmap *  cmap 
)

Definition at line 3885 of file xlibrgb.c.

{
  free (cmap);
}
XlibRgbCmap* xxlib_rgb_cmap_new ( XlibRgbHandle *  handle,
uint32 colors,
int  n_colors 
)

Definition at line 3855 of file xlibrgb.c.

{
  XlibRgbCmap *cmap;
  int i, j;
  uint32 rgb;

  if (n_colors < 0)
    return NULL;
  if (n_colors > 256)
    return NULL;
  cmap = malloc(sizeof(XlibRgbCmap));
  memcpy (cmap->colors, colors, n_colors * sizeof(uint32));
  if (handle->bpp == 1 &&
      (handle->x_visual_info->class == PseudoColor ||
       handle->x_visual_info->class == GrayScale))
    for (i = 0; i < n_colors; i++)
      {
        rgb = colors[i];
        j = ((rgb & 0xf00000) >> 12) |
                   ((rgb & 0xf000) >> 8) |
                   ((rgb & 0xf0) >> 4);
#ifdef VERBOSE
        printf ("%d %x %x %d\n", i, j, handle->colorcube[j]);
#endif
        cmap->lut[i] = handle->colorcube[j];
      }
  return cmap;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void xxlib_rgb_colorcube_222 ( XlibRgbHandle *  handle) [static]

Definition at line 660 of file xlibrgb.c.

{
  int i;
  XColor color;
  Colormap cmap;

  if (handle->cmap_alloced)
    cmap = handle->cmap;
  else
    cmap = handle->default_colormap;

  handle->colorcube_d = malloc(sizeof(unsigned char) * 512);

  for (i = 0; i < 8; i++)
  {
    color.red = ((i & 4) >> 2) * 65535;
    color.green = ((i & 2) >> 1) * 65535;
    color.blue = (i & 1) * 65535;
    XAllocColor (handle->display, cmap, &color);
    handle->colorcube_d[((i & 4) << 4) | ((i & 2) << 2) | (i & 1)] = color.pixel;
  }
}

Here is the caller graph for this function:

static void xxlib_rgb_colorcube_676 ( XlibRgbHandle *  handle) [static]

Definition at line 685 of file xlibrgb.c.

{
  int i = 0;
  XColor color;
  Colormap cmap;
  int r, g, b, r_max, g_max, b_max;
  unsigned long pixels[256];
  
  r_max = 6;
  g_max = 7;
  b_max = 6;

  if (handle->cmap_alloced)
    cmap = handle->cmap;
  else
    cmap = handle->default_colormap;

  for (r = 0; r < r_max; r++)
  {
    for (g = 0; g < g_max; g++)
    {
      for (b = 0; b < b_max; b++)
      {        
        color.red   = r * 65535 / (r_max-1);
        color.green = g * 65535 / (g_max-1);
        color.blue  = b * 65535 / (b_max-1);
        XAllocColor (handle->display, cmap, &color);
        pixels[i++] = color.pixel;
      }
    }
  }    
      
  handle->nred_shades   = r_max;
  handle->ngreen_shades = g_max;
  handle->nblue_shades  = b_max;
  xxlib_rgb_make_colorcube   (handle, pixels, r_max, g_max, b_max);
  xxlib_rgb_make_colorcube_d (handle, pixels, r_max, g_max, b_max);      
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void xxlib_rgb_convert_0888 ( XlibRgbHandle *  handle,
XImage *  image,
int  ax,
int  ay,
int  width,
int  height,
unsigned char *  buf,
int  rowstride,
int  x_align,
int  y_align,
XlibRgbCmap *  cmap 
) [static]

Definition at line 2443 of file xlibrgb.c.

{
  int x, y;
  unsigned char *obuf;
  int bpl;
  unsigned char *bptr, *bp2;
  int r, g, b;

  bptr = buf;
  bpl = image->bytes_per_line;
  obuf = ((unsigned char *)image->data) + ay * bpl + ax * 4;
  for (y = 0; y < height; y++)
    {
      bp2 = bptr;
      for (x = 0; x < width; x++)
        {
          r = bp2[0];
          g = bp2[1];
          b = bp2[2];
          ((uint32 *)obuf)[x] = (r << 16) | (g << 8) | b;
          bp2 += 3;
        }
      bptr += rowstride;
      obuf += bpl;
    }
}

Here is the caller graph for this function:

static void xxlib_rgb_convert_0888_br ( XlibRgbHandle *  handle,
XImage *  image,
int  ax,
int  ay,
int  width,
int  height,
unsigned char *  buf,
int  rowstride,
int  x_align,
int  y_align,
XlibRgbCmap *  cmap 
) [static]

Definition at line 2474 of file xlibrgb.c.

{
  int x, y;
  unsigned char *obuf;
  int bpl;
  unsigned char *bptr, *bp2;
  int r, g, b;

  bptr = buf;
  bpl = image->bytes_per_line;
  obuf = ((unsigned char *)image->data) + ay * bpl + ax * 4;
  for (y = 0; y < height; y++)
    {
      bp2 = bptr;
      for (x = 0; x < width; x++)
        {
          r = bp2[0];
          g = bp2[1];
          b = bp2[2];
          ((uint32 *)obuf)[x] = (b << 24) | (g << 16) | (r << 8);
          bp2 += 3;
        }
      bptr += rowstride;
      obuf += bpl;
    }
}

Here is the caller graph for this function:

static void xxlib_rgb_convert_1 ( XlibRgbHandle *  handle,
XImage *  image,
int  ax,
int  ay,
int  width,
int  height,
unsigned char *  buf,
int  rowstride,
int  x_align,
int  y_align,
XlibRgbCmap *  cmap 
) [static]

Definition at line 2996 of file xlibrgb.c.

{
  int x, y;
  int bpl;
  unsigned char *obuf, *obptr;
  unsigned char *bptr, *bp2;
  int r, g, b;
  const unsigned char *dmp;
  int dith;
  unsigned char byte;

  bptr = buf;
  bpl = image->bytes_per_line;
  obuf = ((unsigned char *)image->data) + ay * bpl + (ax >> 3);
  byte = 0; /* unnecessary, but it keeps gcc from complaining */
  for (y = 0; y < height; y++)
    {
      dmp = DM[(y_align + y) & (DM_HEIGHT - 1)];
      bp2 = bptr;
      obptr = obuf;
      for (x = 0; x < width; x++)
        {
          r = *bp2++;
          g = *bp2++;
          b = *bp2++;
          dith = (dmp[(x_align + x) & (DM_WIDTH - 1)] << 4) | 4;
          byte += byte + (r + g + g + b + dith > 1020);
          if ((x & 7) == 7)
            {
              obptr[0] = byte;
              obptr++;
            }
        }
      if (x & 7)
        obptr[0] = byte << (8 - (x & 7));
      bptr += rowstride;
      obuf += bpl;
    }
}

Here is the caller graph for this function:

static void xxlib_rgb_convert_32_generic ( XlibRgbHandle *  handle,
XImage *  image,
int  ax,
int  ay,
int  width,
int  height,
unsigned char *  buf,
int  rowstride,
int  x_align,
int  y_align,
XlibRgbCmap *  cmap 
) [static]

Definition at line 3078 of file xlibrgb.c.

{
  xxlib_rgb_32_to_stage (handle, buf, rowstride, width, height);

  (*handle->conv) (handle, image, ax, ay, width, height,
                       handle->stage_buf, STAGE_ROWSTRIDE,
                       x_align, y_align, cmap);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void xxlib_rgb_convert_32_generic_d ( XlibRgbHandle *  handle,
XImage *  image,
int  ax,
int  ay,
int  width,
int  height,
unsigned char *  buf,
int  rowstride,
int  x_align,
int  y_align,
XlibRgbCmap *  cmap 
) [static]

Definition at line 3093 of file xlibrgb.c.

{
  xxlib_rgb_32_to_stage (handle, buf, rowstride, width, height);

  (*handle->conv_d) (handle, image, ax, ay, width, height,
                         handle->stage_buf, STAGE_ROWSTRIDE,
                         x_align, y_align, cmap);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void xxlib_rgb_convert_4 ( XlibRgbHandle *  handle,
XImage *  image,
int  ax,
int  ay,
int  width,
int  height,
unsigned char *  buf,
int  rowstride,
int  x_align,
int  y_align,
XlibRgbCmap *  cmap 
) [static]

Definition at line 2773 of file xlibrgb.c.

{
  int x, y;
  int bpl;
  unsigned char *obuf, *obptr;
  unsigned char *bptr, *bp2;
  int r, g, b;
  const unsigned char *dmp;
  int dith;

  bptr = buf;
  bpl = image->bytes_per_line;
  obuf = ((unsigned char *)image->data) + ay * bpl + ax;
  for (y = 0; y < height; y++)
    {
      dmp = DM[(y_align + y) & (DM_HEIGHT - 1)];
      bp2 = bptr;
      obptr = obuf;
      for (x = 0; x < width; x += 1)
        {
          r = *bp2++;
          g = *bp2++;
          b = *bp2++;
          dith = (dmp[(x_align + x) & (DM_WIDTH - 1)] << 2) | 3;
          obptr[0] = handle->colorcube_d[(((r + dith) & 0x100) >> 2) |
                                (((g + 258 - dith) & 0x100) >> 5) |
                                (((b + dith) & 0x100) >> 8)];
          obptr++;
        }
      bptr += rowstride;
      obuf += bpl;
    }
}

Here is the caller graph for this function:

static void xxlib_rgb_convert_555 ( XlibRgbHandle *  handle,
XImage *  image,
int  ax,
int  ay,
int  width,
int  height,
unsigned char *  buf,
int  rowstride,
int  x_align,
int  y_align,
XlibRgbCmap *  cmap 
) [static]

Definition at line 2237 of file xlibrgb.c.

{
  int x, y;
  unsigned char *obuf;
  int bpl;
  unsigned char *bptr, *bp2;
  unsigned char r, g, b;

  bptr = buf;
  bpl = image->bytes_per_line;
  obuf = ((unsigned char *)image->data) + ay * bpl + ax * 2;
  for (y = 0; y < height; y++)
    {
      bp2 = bptr;
      for (x = 0; x < width; x++)
        {
          r = *bp2++;
          g = *bp2++;
          b = *bp2++;
          ((unsigned short *)obuf)[x] = ((r & 0xf8) << 7) |
            ((g & 0xf8) << 2) |
            (b >> 3);
        }
      bptr += rowstride;
      obuf += bpl;
    }
}

Here is the caller graph for this function:

static void xxlib_rgb_convert_555_br ( XlibRgbHandle *  handle,
XImage *  image,
int  ax,
int  ay,
int  width,
int  height,
unsigned char *  buf,
int  rowstride,
int  x_align,
int  y_align,
XlibRgbCmap *  cmap 
) [static]

Definition at line 2269 of file xlibrgb.c.

{
  int x, y;
  unsigned char *obuf;
  int bpl;
  unsigned char *bptr, *bp2;
  unsigned char r, g, b;

  bptr = buf;
  bpl = image->bytes_per_line;
  obuf = ((unsigned char *)image->data) + ay * bpl + ax * 2;
  for (y = 0; y < height; y++)
    {
      bp2 = bptr;
      for (x = 0; x < width; x++)
        {
          r = *bp2++;
          g = *bp2++;
          b = *bp2++;
          /* final word is:
             g5 g4 g3 b7 b6 b5 b4 b3  0 r7 r6 r5 r4 r3 g7 g6
           */
          ((unsigned short *)obuf)[x] = ((r & 0xf8) >> 1) |
            ((g & 0xc0) >> 6) |
            ((g & 0x18) << 10) |
            ((b & 0xf8) << 5);
        }
      bptr += rowstride;
      obuf += bpl;
    }
}

Here is the caller graph for this function:

static void xxlib_rgb_convert_565 ( XlibRgbHandle *  handle,
XImage *  image,
int  ax,
int  ay,
int  width,
int  height,
unsigned char *  buf,
int  rowstride,
int  x_align,
int  y_align,
XlibRgbCmap *  cmap 
) [static]

Definition at line 1798 of file xlibrgb.c.

{
  int x, y;
  unsigned char *obuf, *obptr;
  int bpl;
  unsigned char *bptr, *bp2;
  unsigned char r, g, b;

  bptr = buf;
  bpl = image->bytes_per_line;
  obuf = ((unsigned char *)image->data) + ay * bpl + ax * 2;
  for (y = 0; y < height; y++)
    {
      bp2 = bptr;
      obptr = obuf;
      if (((unsigned long)obuf | (unsigned long) bp2) & 3)
        {
          for (x = 0; x < width; x++)
            {
              r = *bp2++;
              g = *bp2++;
              b = *bp2++;
              ((uint16 *)obptr)[0] = ((r & 0xf8) << 8) |
                ((g & 0xfc) << 3) |
                (b >> 3);
              obptr += 2;
            }
        }
      else
        {
          for (x = 0; x < width - 3; x += 4)
            {
              uint32 r1b0g0r0;
              uint32 g2r2b1g1;
              uint32 b3g3r3b2;

              r1b0g0r0 = ((uint32 *)bp2)[0];
              g2r2b1g1 = ((uint32 *)bp2)[1];
              b3g3r3b2 = ((uint32 *)bp2)[2];
              ((uint32 *)obptr)[0] =
                ((r1b0g0r0 & 0xf8) << 8) |
                ((r1b0g0r0 & 0xfc00) >> 5) |
                ((r1b0g0r0 & 0xf80000) >> 19) |
                (r1b0g0r0 & 0xf8000000) |
                ((g2r2b1g1 & 0xfc) << 19) |
                ((g2r2b1g1 & 0xf800) << 5);
              ((uint32 *)obptr)[1] =
                ((g2r2b1g1 & 0xf80000) >> 8) |
                ((g2r2b1g1 & 0xfc000000) >> 21) |
                ((b3g3r3b2 & 0xf8) >> 3) |
                ((b3g3r3b2 & 0xf800) << 16) |
                ((b3g3r3b2 & 0xfc0000) << 3) |
                ((b3g3r3b2 & 0xf8000000) >> 11);
              bp2 += 12;
              obptr += 8;
            }
          for (; x < width; x++)
            {
              r = *bp2++;
              g = *bp2++;
              b = *bp2++;
              ((uint16 *)obptr)[0] = ((r & 0xf8) << 8) |
                ((g & 0xfc) << 3) |
                (b >> 3);
              obptr += 2;
            }
        }
      bptr += rowstride;
      obuf += bpl;
    }
}

Here is the caller graph for this function:

static void xxlib_rgb_convert_565_br ( XlibRgbHandle *  handle,
XImage *  image,
int  ax,
int  ay,
int  width,
int  height,
unsigned char *  buf,
int  rowstride,
int  x_align,
int  y_align,
XlibRgbCmap *  cmap 
) [static]

Definition at line 2028 of file xlibrgb.c.

{
  int x, y;
  unsigned char *obuf;
  int bpl;
  unsigned char *bptr, *bp2;
  unsigned char r, g, b;

  bptr = buf;
  bpl = image->bytes_per_line;
  obuf = ((unsigned char *)image->data) + ay * bpl + ax * 2;
  for (y = 0; y < height; y++)
    {
      bp2 = bptr;
      for (x = 0; x < width; x++)
        {
          r = *bp2++;
          g = *bp2++;
          b = *bp2++;
          /* final word is:
             g4 g3 g2 b7 b6 b5 b4 b3  r7 r6 r5 r4 r3 g7 g6 g5
           */
          ((unsigned short *)obuf)[x] = (r & 0xf8) |
            ((g & 0xe0) >> 5) |
            ((g & 0x1c) << 11) |
            ((b & 0xf8) << 5);
        }
      bptr += rowstride;
      obuf += bpl;
    }
}

Here is the caller graph for this function:

static void xxlib_rgb_convert_565_d ( XlibRgbHandle *  handle,
XImage *  image,
int  ax,
int  ay,
int  width,
int  height,
unsigned char *  buf,
int  rowstride,
int  x_align,
int  y_align,
XlibRgbCmap *  cmap 
) [static]

Definition at line 2067 of file xlibrgb.c.

{
  /* Now this is what I'd call some highly tuned code! */
  int x, y;
  unsigned char *obuf, *obptr;
  int bpl;
  unsigned char *bptr, *bp2;

  width += x_align;
  height += y_align;
  
  bptr = buf;
  bpl = image->bytes_per_line;
  obuf = ((unsigned char *)image->data) + ay * bpl + ax * 2;
  for (y = y_align; y < height; y++)
    {
      uint32 *dmp = handle->DM_565 + ((y & (DM_HEIGHT - 1)) << DM_WIDTH_SHIFT);
      bp2 = bptr;
      obptr = obuf;
      if (((unsigned long)obuf | (unsigned long) bp2) & 3)
        {
          for (x = x_align; x < width; x++)
            {
              int32 rgb = *bp2++ << 20;
              rgb += *bp2++ << 10;
              rgb += *bp2++;
              rgb += dmp[x & (DM_WIDTH - 1)];
              rgb += 0x10040100
                - ((rgb & 0x1e0001e0) >> 5)
                - ((rgb & 0x00070000) >> 6);

              ((unsigned short *)obptr)[0] =
                ((rgb & 0x0f800000) >> 12) |
                ((rgb & 0x0003f000) >> 7) |
                ((rgb & 0x000000f8) >> 3);
              obptr += 2;
            }
        }
      else
        {
          for (x = x_align; x < width - 3; x += 4)
            {
              uint32 r1b0g0r0;
              uint32 g2r2b1g1;
              uint32 b3g3r3b2;
              uint32 rgb02, rgb13;

              r1b0g0r0 = ((uint32 *)bp2)[0];
              g2r2b1g1 = ((uint32 *)bp2)[1];
              b3g3r3b2 = ((uint32 *)bp2)[2];
              rgb02 =
                ((r1b0g0r0 & 0xff) << 20) +
                ((r1b0g0r0 & 0xff00) << 2) +
                ((r1b0g0r0 & 0xff0000) >> 16) +
                dmp[x & (DM_WIDTH - 1)];
              rgb02 += 0x10040100
                - ((rgb02 & 0x1e0001e0) >> 5)
                - ((rgb02 & 0x00070000) >> 6);
              rgb13 =
                ((r1b0g0r0 & 0xff000000) >> 4) +
                ((g2r2b1g1 & 0xff) << 10) +
                ((g2r2b1g1 & 0xff00) >> 8) +
                dmp[(x + 1) & (DM_WIDTH - 1)];
              rgb13 += 0x10040100
                - ((rgb13 & 0x1e0001e0) >> 5)
                - ((rgb13 & 0x00070000) >> 6);
              ((uint32 *)obptr)[0] =
                ((rgb02 & 0x0f800000) >> 12) |
                ((rgb02 & 0x0003f000) >> 7) |
                ((rgb02 & 0x000000f8) >> 3) |
                ((rgb13 & 0x0f800000) << 4) |
                ((rgb13 & 0x0003f000) << 9) |
                ((rgb13 & 0x000000f8) << 13);
              rgb02 =
                ((g2r2b1g1 & 0xff0000) << 4) +
                ((g2r2b1g1 & 0xff000000) >> 14) +
                (b3g3r3b2 & 0xff) +
                dmp[(x + 2) & (DM_WIDTH - 1)];
              rgb02 += 0x10040100
                - ((rgb02 & 0x1e0001e0) >> 5)
                - ((rgb02 & 0x00070000) >> 6);
              rgb13 =
                ((b3g3r3b2 & 0xff00) << 12) +
                ((b3g3r3b2 & 0xff0000) >> 6) +
                ((b3g3r3b2 & 0xff000000) >> 24) +
                dmp[(x + 3) & (DM_WIDTH - 1)];
              rgb13 += 0x10040100
                - ((rgb13 & 0x1e0001e0) >> 5)
                - ((rgb13 & 0x00070000) >> 6);
              ((uint32 *)obptr)[1] =
                ((rgb02 & 0x0f800000) >> 12) |
                ((rgb02 & 0x0003f000) >> 7) |
                ((rgb02 & 0x000000f8) >> 3) |
                ((rgb13 & 0x0f800000) << 4) |
                ((rgb13 & 0x0003f000) << 9) |
                ((rgb13 & 0x000000f8) << 13);
              bp2 += 12;
              obptr += 8;
            }
          for (; x < width; x++)
            {
              int32 rgb = *bp2++ << 20;
              rgb += *bp2++ << 10;
              rgb += *bp2++;
              rgb += dmp[x & (DM_WIDTH - 1)];
              rgb += 0x10040100
                - ((rgb & 0x1e0001e0) >> 5)
                - ((rgb & 0x00070000) >> 6);

              ((unsigned short *)obptr)[0] =
                ((rgb & 0x0f800000) >> 12) |
                ((rgb & 0x0003f000) >> 7) |
                ((rgb & 0x000000f8) >> 3);
              obptr += 2;
            }
        }
      bptr += rowstride;
      obuf += bpl;
    }
}

Here is the caller graph for this function:

static void xxlib_rgb_convert_565_gray ( XlibRgbHandle *  handle,
XImage *  image,
int  ax,
int  ay,
int  width,
int  height,
unsigned char *  buf,
int  rowstride,
int  x_align,
int  y_align,
XlibRgbCmap *  cmap 
) [static]

Definition at line 1929 of file xlibrgb.c.

{
  int x, y;
  unsigned char *obuf, *obptr;
  int bpl;
  unsigned char *bptr, *bp2;
  unsigned char g;

  bptr = buf;
  bpl = image->bytes_per_line;
  obuf = ((unsigned char *)image->data) + ay * bpl + ax * 2;
  for (y = 0; y < height; y++)
    {
      bp2 = bptr;
      obptr = obuf;
      if (((unsigned long)obuf | (unsigned long) bp2) & 3)
        {
          for (x = 0; x < width; x++)
            {
              g = *bp2++;
              ((uint16 *)obptr)[0] = ((g & 0xf8) << 8) |
                ((g & 0xfc) << 3) |
                (g >> 3);
              obptr += 2;
            }
        }
      else
        {
          for (x = 0; x < width - 3; x += 4)
            {
              uint32 g3g2g1g0;

              g3g2g1g0 = ((uint32 *)bp2)[0];
              ((uint32 *)obptr)[0] =
                ((g3g2g1g0 & 0xf8) << 8) |
                ((g3g2g1g0 & 0xfc) << 3) |
                ((g3g2g1g0 & 0xf8) >> 3) |
                (g3g2g1g0 & 0xf800) << 16 |
                ((g3g2g1g0 & 0xfc00) << 11) |
                ((g3g2g1g0 & 0xf800) << 5);
              ((uint32 *)obptr)[1] =
                ((g3g2g1g0 & 0xf80000) >> 8) |
                ((g3g2g1g0 & 0xfc0000) >> 13) |
                ((g3g2g1g0 & 0xf80000) >> 19) |
                (g3g2g1g0 & 0xf8000000) |
                ((g3g2g1g0 & 0xfc000000) >> 5) |
                ((g3g2g1g0 & 0xf8000000) >> 11);
              bp2 += 4;
              obptr += 8;
            }
          for (; x < width; x++)
            {
              g = *bp2++;
              ((uint16 *)obptr)[0] = ((g & 0xf8) << 8) |
                ((g & 0xfc) << 3) |
                (g >> 3);
              obptr += 2;
            }
        }
      bptr += rowstride;
      obuf += bpl;
    }
}

Here is the caller graph for this function:

static void xxlib_rgb_convert_8 ( XlibRgbHandle *  handle,
XImage *  image,
int  ax,
int  ay,
int  width,
int  height,
unsigned char *  buf,
int  rowstride,
int  x_align,
int  y_align,
XlibRgbCmap *  cmap 
) [static]

Definition at line 1327 of file xlibrgb.c.

{
  int x, y;
  int bpl;
  unsigned char *obuf, *obptr;
  unsigned char *bptr, *bp2;
  int r, g, b;

  bptr = buf;
  bpl = image->bytes_per_line;
  obuf = ((unsigned char *)image->data) + ay * bpl + ax;
  for (y = 0; y < height; y++)
    {
      bp2 = bptr;
      obptr = obuf;
      if (((unsigned long)obuf | (unsigned long) bp2) & 3)
        {
          for (x = 0; x < width; x++)
            {
              r = *bp2++;
              g = *bp2++;
              b = *bp2++;
              obptr[0] = handle->colorcube[((r & 0xf0) << 4) |
                                  (g & 0xf0) |
                                  (b >> 4)];
              obptr++;
            }
        }
      else
        {
          for (x = 0; x < width - 3; x += 4)
            {
              uint32 r1b0g0r0;
              uint32 g2r2b1g1;
              uint32 b3g3r3b2;

              r1b0g0r0 = ((uint32 *)bp2)[0];
              g2r2b1g1 = ((uint32 *)bp2)[1];
              b3g3r3b2 = ((uint32 *)bp2)[2];
              ((uint32 *)obptr)[0] =
                handle->colorcube[((r1b0g0r0 & 0xf0) << 4) | 
                         ((r1b0g0r0 & 0xf000) >> 8) |
                         ((r1b0g0r0 & 0xf00000) >> 20)] |
                (handle->colorcube[((r1b0g0r0 & 0xf0000000) >> 20) |
                          (g2r2b1g1 & 0xf0) |
                          ((g2r2b1g1 & 0xf000) >> 12)] << 8) |
                (handle->colorcube[((g2r2b1g1 & 0xf00000) >> 12) |
                          ((g2r2b1g1 & 0xf0000000) >> 24) |
                          ((b3g3r3b2 & 0xf0) >> 4)] << 16) |
                (handle->colorcube[((b3g3r3b2 & 0xf000) >> 4) |
                          ((b3g3r3b2 & 0xf00000) >> 16) |
                          (b3g3r3b2 >> 28)] << 24);
              bp2 += 12;
              obptr += 4;
            }
          for (; x < width; x++)
            {
              r = *bp2++;
              g = *bp2++;
              b = *bp2++;
              obptr[0] = handle->colorcube[((r & 0xf0) << 4) |
                                  (g & 0xf0) |
                                  (b >> 4)];
              obptr++;
            }
        }
      bptr += rowstride;
      obuf += bpl;
    }
}

Here is the caller graph for this function:

static void xxlib_rgb_convert_8880_br ( XlibRgbHandle *  handle,
XImage *  image,
int  ax,
int  ay,
int  width,
int  height,
unsigned char *  buf,
int  rowstride,
int  x_align,
int  y_align,
XlibRgbCmap *  cmap 
) [static]

Definition at line 2505 of file xlibrgb.c.

{
  int x, y;
  unsigned char *obuf;
  int bpl;
  unsigned char *bptr, *bp2;
  int r, g, b;

  bptr = buf;
  bpl = image->bytes_per_line;
  obuf = ((unsigned char *)image->data) + ay * bpl + ax * 4;
  for (y = 0; y < height; y++)
    {
      bp2 = bptr;
      for (x = 0; x < width; x++)
        {
          r = bp2[0];
          g = bp2[1];
          b = bp2[2];
          ((uint32 *)obuf)[x] = (b << 16) | (g << 8) | r;
          bp2 += 3;
        }
      bptr += rowstride;
      obuf += bpl;
    }
}

Here is the caller graph for this function:

static void xxlib_rgb_convert_888_lsb ( XlibRgbHandle *  handle,
XImage *  image,
int  ax,
int  ay,
int  width,
int  height,
unsigned char *  buf,
int  rowstride,
int  x_align,
int  y_align,
XlibRgbCmap *  cmap 
) [static]

Definition at line 2333 of file xlibrgb.c.

{
  int x, y;
  unsigned char *obuf, *obptr;
  int bpl;
  unsigned char *bptr, *bp2;
  int r, g, b;

  bptr = buf;
  bpl = image->bytes_per_line;
  obuf = ((unsigned char *)image->data) + ay * bpl + ax * 3;
  for (y = 0; y < height; y++)
    {
      bp2 = bptr;
      obptr = obuf;
      if (((unsigned long)obuf | (unsigned long) bp2) & 3)
        {
          for (x = 0; x < width; x++)
            {
              r = bp2[0];
              g = bp2[1];
              b = bp2[2];
              *obptr++ = b;
              *obptr++ = g;
              *obptr++ = r;
              bp2 += 3;
            }
        }
      else
        {
          for (x = 0; x < width - 3; x += 4)
            {
              uint32 r1b0g0r0;
              uint32 g2r2b1g1;
              uint32 b3g3r3b2;

              r1b0g0r0 = ((uint32 *)bp2)[0];
              g2r2b1g1 = ((uint32 *)bp2)[1];
              b3g3r3b2 = ((uint32 *)bp2)[2];
              ((uint32 *)obptr)[0] =
                (r1b0g0r0 & 0xff00) |
                ((r1b0g0r0 & 0xff0000) >> 16) |
                (((g2r2b1g1 & 0xff00) | (r1b0g0r0 & 0xff)) << 16);
              ((uint32 *)obptr)[1] =
                (g2r2b1g1 & 0xff0000ff) |
                ((r1b0g0r0 & 0xff000000) >> 16) |
                ((b3g3r3b2 & 0xff) << 16);
              ((uint32 *)obptr)[2] =
                (((g2r2b1g1 & 0xff0000) | (b3g3r3b2 & 0xff000000)) >> 16) |
                ((b3g3r3b2 & 0xff00) << 16) |
                ((b3g3r3b2 & 0xff0000));
              bp2 += 12;
              obptr += 12;
            }
          for (; x < width; x++)
            {
              r = bp2[0];
              g = bp2[1];
              b = bp2[2];
              *obptr++ = b;
              *obptr++ = g;
              *obptr++ = r;
              bp2 += 3;
            }
        }
      bptr += rowstride;
      obuf += bpl;
    }
}

Here is the caller graph for this function:

static void xxlib_rgb_convert_888_msb ( XlibRgbHandle *  handle,
XImage *  image,
int  ax,
int  ay,
int  width,
int  height,
unsigned char *  buf,
int  rowstride,
int  x_align,
int  y_align,
XlibRgbCmap *  cmap 
) [static]

Definition at line 2305 of file xlibrgb.c.

{
  int y;
  unsigned char *obuf;
  int bpl;
  unsigned char *bptr;

  bptr = buf;
  bpl = image->bytes_per_line;
  obuf = ((unsigned char *)image->data) + ay * bpl + ax * 3;
  for (y = 0; y < height; y++)
    {
      memcpy (obuf, bptr, (unsigned int)(width + width + width));
      bptr += rowstride;
      obuf += bpl;
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void xxlib_rgb_convert_8_d ( XlibRgbHandle *  handle,
XImage *  image,
int  ax,
int  ay,
int  width,
int  height,
unsigned char *  buf,
int  rowstride,
int  x_align,
int  y_align,
XlibRgbCmap *  cmap 
) [static]

Definition at line 1655 of file xlibrgb.c.

{
  int x, y;
  int bpl;
  unsigned char *obuf, *obptr;
  unsigned char *bptr, *bp2;
  int r, g, b;
  const unsigned char *dmp;
  int dith;
  int rs, gs, bs;

  bptr = buf;
  bpl = image->bytes_per_line;
  rs = handle->nred_shades - 1;
  gs = handle->ngreen_shades - 1;
  bs = handle->nblue_shades - 1;
  obuf = ((unsigned char *)image->data) + ay * bpl + ax;
  for (y = 0; y < height; y++)
    {
      dmp = DM[(y_align + y) & (DM_HEIGHT - 1)];
      bp2 = bptr;
      obptr = obuf;
      for (x = 0; x < width; x++)
        {
          r = *bp2++;
          g = *bp2++;
          b = *bp2++;
          dith = (dmp[(x_align + x) & (DM_WIDTH - 1)] << 2) | 7;
          r = ((r * rs) + dith) >> 8;
          g = ((g * gs) + (262 - dith)) >> 8;
          b = ((b * bs) + dith) >> 8;
          obptr[0] = handle->colorcube_d[(r << 6) | (g << 3) | b];
          obptr++;
        }
      bptr += rowstride;
      obuf += bpl;
    }
}

Here is the caller graph for this function:

static void xxlib_rgb_convert_8_d666 ( XlibRgbHandle *  handle,
XImage *  image,
int  ax,
int  ay,
int  width,
int  height,
unsigned char *  buf,
int  rowstride,
int  x_align,
int  y_align,
XlibRgbCmap *  cmap 
) [static]

Definition at line 1616 of file xlibrgb.c.

{
  int x, y;
  int bpl;
  unsigned char *obuf, *obptr;
  unsigned char *bptr, *bp2;
  int r, g, b;
  const unsigned char *dmp;
  int dith;

  bptr = buf;
  bpl = image->bytes_per_line;
  obuf = ((unsigned char *)image->data) + ay * bpl + ax;
  for (y = 0; y < height; y++)
    {
      dmp = DM[(y_align + y) & (DM_HEIGHT - 1)];
      bp2 = bptr;
      obptr = obuf;
      for (x = 0; x < width; x++)
        {
          r = *bp2++;
          g = *bp2++;
          b = *bp2++;
          dith = (dmp[(x_align + x) & (DM_WIDTH - 1)] << 2) | 7;
          r = ((r * 5) + dith) >> 8;
          g = ((g * 5) + (262 - dith)) >> 8;
          b = ((b * 5) + dith) >> 8;
          obptr[0] = handle->colorcube_d[(r << 6) | (g << 3) | b];
          obptr++;
        }
      bptr += rowstride;
      obuf += bpl;
    }
}

Here is the caller graph for this function:

static void xxlib_rgb_convert_8_indexed ( XlibRgbHandle *  handle,
XImage *  image,
int  ax,
int  ay,
int  width,
int  height,
unsigned char *  buf,
int  rowstride,
int  x_align,
int  y_align,
XlibRgbCmap *  cmap 
) [static]

Definition at line 1699 of file xlibrgb.c.

{
  int x, y;
  int bpl;
  unsigned char *obuf, *obptr;
  unsigned char *bptr, *bp2;
  unsigned char c;
  unsigned char *lut;

  lut = cmap->lut;
  bptr = buf;
  bpl = image->bytes_per_line;
  obuf = ((unsigned char *)image->data) + ay * bpl + ax;
  for (y = 0; y < height; y++)
    {
      bp2 = bptr;
      obptr = obuf;
      for (x = 0; x < width; x++)
        {
          c = *bp2++;
          obptr[0] = lut[c];
          obptr++;
        }
      bptr += rowstride;
      obuf += bpl;
    }
}

Here is the caller graph for this function:

static void xxlib_rgb_convert_gray4 ( XlibRgbHandle *  handle,
XImage *  image,
int  ax,
int  ay,
int  width,
int  height,
unsigned char *  buf,
int  rowstride,
int  x_align,
int  y_align,
XlibRgbCmap *  cmap 
) [static]

Definition at line 2813 of file xlibrgb.c.

{
  int x, y;
  int bpl;
  unsigned char *obuf, *obptr;
  unsigned char *bptr, *bp2;
  int r, g, b;
  int shift;

  bptr = buf;
  bpl = image->bytes_per_line;
  obuf = ((unsigned char *)image->data) + ay * bpl + ax;
  shift = 9 - handle->x_visual_info->depth;
  for (y = 0; y < height; y++)
    {
      bp2 = bptr;
      obptr = obuf;
      for (x = 0; x < width; x++)
        {
          r = *bp2++;
          g = *bp2++;
          b = *bp2++;
          obptr[0] = (g + ((b + r) >> 1)) >> shift;
          obptr++;
        }
      bptr += rowstride;
      obuf += bpl;
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void xxlib_rgb_convert_gray4_d ( XlibRgbHandle *  handle,
XImage *  image,
int  ax,
int  ay,
int  width,
int  height,
unsigned char *  buf,
int  rowstride,
int  x_align,
int  y_align,
XlibRgbCmap *  cmap 
) [static]

Definition at line 2897 of file xlibrgb.c.

{
  int x, y;
  int bpl;
  unsigned char *obuf, *obptr;
  unsigned char *bptr, *bp2;
  int r, g, b;
  const unsigned char *dmp;
  int prec, right;
  int gray;

  bptr = buf;
  bpl = image->bytes_per_line;
  obuf = ((unsigned char *)image->data) + ay * bpl + ax;
  prec = handle->x_visual_info->depth;
  right = 8 - prec;
  for (y = 0; y < height; y++)
    {
      bp2 = bptr;
      obptr = obuf;
      dmp = DM[(y_align + y) & (DM_HEIGHT - 1)];
      for (x = 0; x < width; x++)
        {
          r = *bp2++;
          g = *bp2++;
          b = *bp2++;
          gray = (g + ((b + r) >> 1)) >> 1;
          gray += (dmp[(x_align + x) & (DM_WIDTH - 1)] << 2) >> prec;
          obptr[0] = (gray - (gray >> prec)) >> right;
          obptr++;
        }
      bptr += rowstride;
      obuf += bpl;
    }
}

Here is the caller graph for this function:

static void xxlib_rgb_convert_gray4_d_pack ( XlibRgbHandle *  handle,
XImage *  image,
int  ax,
int  ay,
int  width,
int  height,
unsigned char *  buf,
int  rowstride,
int  x_align,
int  y_align,
XlibRgbCmap *  cmap 
) [static]

Definition at line 2937 of file xlibrgb.c.

{
  int x, y;
  int bpl;
  unsigned char *obuf, *obptr;
  unsigned char *bptr, *bp2;
  int r, g, b;
  const unsigned char *dmp;
  int prec, right;
  int gray;
  unsigned char pix0, pix1;
  /* todo: this is hardcoded to big-endian. Make endian-agile. */

  bptr = buf;
  bpl = image->bytes_per_line;
  obuf = ((unsigned char *)image->data) + ay * bpl + (ax >> 1);
  prec = handle->x_visual_info->depth;
  right = 8 - prec;
  for (y = 0; y < height; y++)
    {
      bp2 = bptr;
      obptr = obuf;
      dmp = DM[(y_align + y) & (DM_HEIGHT - 1)];
      for (x = 0; x < width; x += 2)
        {
          r = *bp2++;
          g = *bp2++;
          b = *bp2++;
          gray = (g + ((b + r) >> 1)) >> 1;
          gray += (dmp[(x_align + x) & (DM_WIDTH - 1)] << 2) >> prec;
          pix0 = (gray - (gray >> prec)) >> right;
          r = *bp2++;
          g = *bp2++;
          b = *bp2++;
          gray = (g + ((b + r) >> 1)) >> 1;
          gray += (dmp[(x_align + x + 1) & (DM_WIDTH - 1)] << 2) >> prec;
          pix1 = (gray - (gray >> prec)) >> right;
          obptr[0] = (pix0 << 4) | pix1;
          obptr++;
        }
      if (width & 1)
        {
          r = *bp2++;
          g = *bp2++;
          b = *bp2++;
          gray = (g + ((b + r) >> 1)) >> 1;
          gray += (dmp[(x_align + x + 1) & (DM_WIDTH - 1)] << 2) >> prec;
          pix0 = (gray - (gray >> prec)) >> right;
          obptr[0] = (pix0 << 4);
        }
      bptr += rowstride;
      obuf += bpl;
    }
}

Here is the caller graph for this function:

static void xxlib_rgb_convert_gray4_pack ( XlibRgbHandle *  handle,
XImage *  image,
int  ax,
int  ay,
int  width,
int  height,
unsigned char *  buf,
int  rowstride,
int  x_align,
int  y_align,
XlibRgbCmap *  cmap 
) [static]

Definition at line 2847 of file xlibrgb.c.

{
  int x, y;
  int bpl;
  unsigned char *obuf, *obptr;
  unsigned char *bptr, *bp2;
  int r, g, b;
  int shift;
  unsigned char pix0, pix1;
  /* todo: this is hardcoded to big-endian. Make endian-agile. */

  bptr = buf;
  bpl = image->bytes_per_line;
  obuf = ((unsigned char *)image->data) + ay * bpl + (ax >> 1);
  shift = 9 - handle->x_visual_info->depth;
  for (y = 0; y < height; y++)
    {
      bp2 = bptr;
      obptr = obuf;
      for (x = 0; x < width; x += 2)
        {
          r = *bp2++;
          g = *bp2++;
          b = *bp2++;
          pix0 = (g + ((b + r) >> 1)) >> shift;
          r = *bp2++;
          g = *bp2++;
          b = *bp2++;
          pix1 = (g + ((b + r) >> 1)) >> shift;
          obptr[0] = (pix0 << 4) | pix1;
          obptr++;
        }
      if (width & 1)
        {
          r = *bp2++;
          g = *bp2++;
          b = *bp2++;
          pix0 = (g + ((b + r) >> 1)) >> shift;
          obptr[0] = (pix0 << 4);
        }
      bptr += rowstride;
      obuf += bpl;
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void xxlib_rgb_convert_gray8 ( XlibRgbHandle *  handle,
XImage *  image,
int  ax,
int  ay,
int  width,
int  height,
unsigned char *  buf,
int  rowstride,
int  x_align,
int  y_align,
XlibRgbCmap *  cmap 
) [static]

Definition at line 1731 of file xlibrgb.c.

{
  int x, y;
  int bpl;
  unsigned char *obuf, *obptr;
  unsigned char *bptr, *bp2;
  int r, g, b;

  bptr = buf;
  bpl = image->bytes_per_line;
  obuf = ((unsigned char *)image->data) + ay * bpl + ax;
  for (y = 0; y < height; y++)
    {
      bp2 = bptr;
      obptr = obuf;
      for (x = 0; x < width; x++)
        {
          r = *bp2++;
          g = *bp2++;
          b = *bp2++;
          obptr[0] = (g + ((b + r) >> 1)) >> 1;
          obptr++;
        }
      bptr += rowstride;
      obuf += bpl;
    }
}

Here is the caller graph for this function:

static void xxlib_rgb_convert_gray8_gray ( XlibRgbHandle *  handle,
XImage *  image,
int  ax,
int  ay,
int  width,
int  height,
unsigned char *  buf,
int  rowstride,
int  x_align,
int  y_align,
XlibRgbCmap *  cmap 
) [static]

Definition at line 1763 of file xlibrgb.c.

{
  int y;
  int bpl;
  unsigned char *obuf;
  unsigned char *bptr;

  bptr = buf;
  bpl = image->bytes_per_line;
  obuf = ((unsigned char *)image->data) + ay * bpl + ax;
  for (y = 0; y < height; y++)
    {
      memcpy (obuf, bptr, (unsigned int)width);
      bptr += rowstride;
      obuf += bpl;
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void xxlib_rgb_convert_gray_cmap ( XlibRgbHandle *  handle,
XImage *  image,
int  ax,
int  ay,
int  width,
int  height,
unsigned char *  buf,
int  rowstride,
int  x_align,
int  y_align,
XlibRgbCmap *  cmap 
) [static]

Definition at line 3162 of file xlibrgb.c.

{
  (*handle->conv_indexed) (handle, image, ax, ay, width, height,
                               buf, rowstride,
                               x_align, y_align, handle->gray_cmap);
}

Here is the caller graph for this function:

static void xxlib_rgb_convert_gray_generic ( XlibRgbHandle *  handle,
XImage *  image,
int  ax,
int  ay,
int  width,
int  height,
unsigned char *  buf,
int  rowstride,
int  x_align,
int  y_align,
XlibRgbCmap *  cmap 
) [static]

Definition at line 3135 of file xlibrgb.c.

{
  xxlib_rgb_gray_to_stage (handle, buf, rowstride, width, height);

  (*handle->conv) (handle, image, ax, ay, width, height,
                       handle->stage_buf, STAGE_ROWSTRIDE,
                       x_align, y_align, cmap);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void xxlib_rgb_convert_gray_generic_d ( XlibRgbHandle *  handle,
XImage *  image,
int  ax,
int  ay,
int  width,
int  height,
unsigned char *  buf,
int  rowstride,
int  x_align,
int  y_align,
XlibRgbCmap *  cmap 
) [static]

Definition at line 3148 of file xlibrgb.c.

{
  xxlib_rgb_gray_to_stage (handle, buf, rowstride, width, height);

  (*handle->conv_d) (handle, image, ax, ay, width, height,
                         handle->stage_buf, STAGE_ROWSTRIDE,
                         x_align, y_align, cmap);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void xxlib_rgb_convert_indexed_generic ( XlibRgbHandle *  handle,
XImage *  image,
int  ax,
int  ay,
int  width,
int  height,
unsigned char *  buf,
int  rowstride,
int  x_align,
int  y_align,
XlibRgbCmap *  cmap 
) [static]

Definition at line 3216 of file xlibrgb.c.

{
  xxlib_rgb_indexed_to_stage (handle, buf, rowstride, width, height, cmap);

  (*handle->conv) (handle, image, ax, ay, width, height,
                       handle->stage_buf, STAGE_ROWSTRIDE,
                       x_align, y_align, cmap);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void xxlib_rgb_convert_indexed_generic_d ( XlibRgbHandle *  handle,
XImage *  image,
int  ax,
int  ay,
int  width,
int  height,
unsigned char *  buf,
int  rowstride,
int  x_align,
int  y_align,
XlibRgbCmap *  cmap 
) [static]

Definition at line 3229 of file xlibrgb.c.

{
  xxlib_rgb_indexed_to_stage (handle, buf, rowstride, width, height, cmap);

  (*handle->conv_d) (handle, image, ax, ay, width, height,
                         handle->stage_buf, STAGE_ROWSTRIDE,
                         x_align, y_align, cmap);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void xxlib_rgb_convert_truecolor_lsb ( XlibRgbHandle *  handle,
XImage *  image,
int  ax,
int  ay,
int  width,
int  height,
unsigned char *  buf,
int  rowstride,
int  x_align,
int  y_align,
XlibRgbCmap *  cmap 
) [static]

Definition at line 2538 of file xlibrgb.c.

{
  int x, y;
  unsigned char *obuf, *obptr;
  int bpl;
  unsigned char *bptr, *bp2;
  int r, g, b;
  int r_right, r_left;
  int g_right, g_left;
  int b_right, b_left;
  int bpp;
  uint32 pixel;
  int i;

  r_right = 8 - handle->red_prec;
  r_left = handle->red_shift;
  g_right = 8 - handle->green_prec;
  g_left = handle->green_shift;
  b_right = 8 - handle->blue_prec;
  b_left = handle->blue_shift;
  bpp = handle->bpp;
  bptr = buf;
  bpl = image->bytes_per_line;
  obuf = ((unsigned char *)image->data) + ay * bpl + ax * bpp;
  for (y = 0; y < height; y++)
    {
      obptr = obuf;
      bp2 = bptr;
      for (x = 0; x < width; x++)
        {
          r = bp2[0];
          g = bp2[1];
          b = bp2[2];
          pixel = ((r >> r_right) << r_left) |
            ((g >> g_right) << g_left) |
            ((b >> b_right) << b_left);
          for (i = 0; i < bpp; i++)
            {
              *obptr++ = pixel & 0xff;
              pixel >>= 8;
            }
          bp2 += 3;
        }
      bptr += rowstride;
      obuf += bpl;
    }
}

Here is the caller graph for this function:

static void xxlib_rgb_convert_truecolor_lsb_d ( XlibRgbHandle *  handle,
XImage *  image,
int  ax,
int  ay,
int  width,
int  height,
unsigned char *  buf,
int  rowstride,
int  x_align,
int  y_align,
XlibRgbCmap *  cmap 
) [static]

Definition at line 2591 of file xlibrgb.c.

{
  int x, y;
  unsigned char *obuf, *obptr;
  int bpl;
  unsigned char *bptr, *bp2;
  int r, g, b;
  int r_right, r_left, r_prec;
  int g_right, g_left, g_prec;
  int b_right, b_left, b_prec;
  int bpp;
  uint32 pixel;
  int i;
  int dith;
  int r1, g1, b1;
  const unsigned char *dmp;

  r_right = 8 - handle->red_prec;
  r_left = handle->red_shift;
  r_prec = handle->red_prec;
  g_right = 8 - handle->green_prec;
  g_left = handle->green_shift;
  g_prec = handle->green_prec;
  b_right = 8 - handle->blue_prec;
  b_left = handle->blue_shift;
  b_prec = handle->blue_prec;
  bpp = handle->bpp;
  bptr = buf;
  bpl = image->bytes_per_line;
  obuf = ((unsigned char *)image->data) + ay * bpl + ax * bpp;
  for (y = 0; y < height; y++)
    {
      dmp = DM[(y_align + y) & (DM_HEIGHT - 1)];
      obptr = obuf;
      bp2 = bptr;
      for (x = 0; x < width; x++)
        {
          r = bp2[0];
          g = bp2[1];
          b = bp2[2];
          dith = dmp[(x_align + x) & (DM_WIDTH - 1)] << 2;
          r1 = r + (dith >> r_prec);
          g1 = g + ((252 - dith) >> g_prec);
          b1 = b + (dith >> b_prec);
          pixel = (((r1 - (r1 >> r_prec)) >> r_right) << r_left) |
            (((g1 - (g1 >> g_prec)) >> g_right) << g_left) |
            (((b1 - (b1 >> b_prec)) >> b_right) << b_left);
          for (i = 0; i < bpp; i++)
            {
              *obptr++ = pixel & 0xff;
              pixel >>= 8;
            }
          bp2 += 3;
        }
      bptr += rowstride;
      obuf += bpl;
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void xxlib_rgb_convert_truecolor_msb ( XlibRgbHandle *  handle,
XImage *  image,
int  ax,
int  ay,
int  width,
int  height,
unsigned char *  buf,
int  rowstride,
int  x_align,
int  y_align,
XlibRgbCmap *  cmap 
) [static]

Definition at line 2655 of file xlibrgb.c.

{
  int x, y;
  unsigned char *obuf, *obptr;
  int bpl;
  unsigned char *bptr, *bp2;
  int r, g, b;
  int r_right, r_left;
  int g_right, g_left;
  int b_right, b_left;
  int bpp;
  uint32 pixel;
  int shift, shift_init;

  r_right = 8 - handle->red_prec;
  r_left = handle->red_shift;
  g_right = 8 - handle->green_prec;
  g_left = handle->green_shift;
  b_right = 8 - handle->blue_prec;
  b_left = handle->blue_shift;
  bpp = handle->bpp;
  bptr = buf;
  bpl = image->bytes_per_line;
  obuf = ((unsigned char *)image->data) + ay * bpl + ax * bpp;
  shift_init = (bpp - 1) << 3;
  for (y = 0; y < height; y++)
    {
      obptr = obuf;
      bp2 = bptr;
      for (x = 0; x < width; x++)
        {
          r = bp2[0];
          g = bp2[1];
          b = bp2[2];
          pixel = ((r >> r_right) << r_left) |
            ((g >> g_right) << g_left) |
            ((b >> b_right) << b_left);
          for (shift = shift_init; shift >= 0; shift -= 8)
            {
              *obptr++ = (pixel >> shift) & 0xff;
            }
          bp2 += 3;
        }
      bptr += rowstride;
      obuf += bpl;
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void xxlib_rgb_convert_truecolor_msb_d ( XlibRgbHandle *  handle,
XImage *  image,
int  ax,
int  ay,
int  width,
int  height,
unsigned char *  buf,
int  rowstride,
int  x_align,
int  y_align,
XlibRgbCmap *  cmap 
) [static]

Definition at line 2708 of file xlibrgb.c.

{
  int x, y;
  unsigned char *obuf, *obptr;
  int bpl;
  unsigned char *bptr, *bp2;
  int r, g, b;
  int r_right, r_left, r_prec;
  int g_right, g_left, g_prec;
  int b_right, b_left, b_prec;
  int bpp;
  uint32 pixel;
  int shift, shift_init;
  int dith;
  int r1, g1, b1;
  const unsigned char *dmp;

  r_right = 8 - handle->red_prec;
  r_left = handle->red_shift;
  r_prec = handle->red_prec;
  g_right = 8 - handle->green_prec;
  g_left = handle->green_shift;
  g_prec = handle->green_prec;
  b_right = 8 - handle->blue_prec;
  b_left = handle->blue_shift;
  b_prec = handle->blue_prec;
  bpp = handle->bpp;
  bptr = buf;
  bpl = image->bytes_per_line;
  obuf = ((unsigned char *)image->data) + ay * bpl + ax * bpp;
  shift_init = (bpp - 1) << 3;
  for (y = 0; y < height; y++)
    {
      dmp = DM[(y_align + y) & (DM_HEIGHT - 1)];
      obptr = obuf;
      bp2 = bptr;
      for (x = 0; x < width; x++)
        {
          r = bp2[0];
          g = bp2[1];
          b = bp2[2];
          dith = dmp[(x_align + x) & (DM_WIDTH - 1)] << 2;
          r1 = r + (dith >> r_prec);
          g1 = g + ((252 - dith) >> g_prec);
          b1 = b + (dith >> b_prec);
          pixel = (((r1 - (r1 >> r_prec)) >> r_right) << r_left) |
            (((g1 - (g1 >> g_prec)) >> g_right) << g_left) |
            (((b1 - (b1 >> b_prec)) >> b_right) << b_left);
          for (shift = shift_init; shift >= 0; shift -= 8)
            {
              *obptr++ = (pixel >> shift) & 0xff;
            }
          bp2 += 3;
        }
      bptr += rowstride;
      obuf += bpl;
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

XlibRgbHandle* xxlib_rgb_create_handle ( Display display,
Screen *  screen,
XlibRgbArgs args 
)

Definition at line 965 of file xlibrgb.c.

{
  XlibRgbHandle *handle = NULL;
  int i;
  static const int byte_order[1] = { 1 };

#ifdef DEBUG
  printf("xxlib_rgb_create_handle: pseudogray=%d, install_colormap=%d, "
         "disallow_image_tiling=%d, disallow_mit_shmem=%d, verbose=%d\n",
         (int)args->pseudogray,
         (int)args->install_colormap,
         (int)args->disallow_image_tiling,
         (int)args->disallow_mit_shmem,
         (int)args->verbose);
#endif /* DEBUG */

  /* check endian sanity */
#if G_BYTE_ORDER == G_BIG_ENDIAN
  if (((char *)byte_order)[0] == 1) {
    fprintf (stderr, "xxlib_rgb_create_handle_with_depth: "
             "compiled for big endian, but this is a little endian machine.\n\n");
    abort();
  }
#else
  if (((char *)byte_order)[0] != 1) {
    fprintf (stderr, "xxlib_rgb_create_handle_with_depth: "
             "compiled for little endian, but this is a big endian machine.\n\n");
    abort();
  }
#endif /* G_BYTE_ORDER == G_BIG_ENDIAN */

#ifndef XLIBRGB_MIT_SHM_SUPPORT_HAS_BEEN_FIXED
    /* We still have issues with MIT_SHM support on LSB platforms... ;-( */
    args->disallow_mit_shmem = True;
#endif /* XLIBRGB_MIT_SHM_SUPPORT_HAS_BEEN_FIXED */    
       
    if (!(handle = malloc(sizeof(XlibRgbHandle))))
      return NULL;      
    memset(handle, 0, sizeof(XlibRgbHandle));

    /* should we register this handle ? */
    if (args->handle_name)
    {
      if (!xxlib_register_handle(args->handle_name, handle))
      {
#ifdef DEBUG
        puts("xxlib_rgb_create_handle: cannot register handle");
#endif /* DEBUG */      
        free(handle);
        return NULL;
      }  
    }
    
    /* Emulate StaticGray via PseudoColor visual ? */
    if (args->pseudogray)
    {
      args->xtemplate.class = PseudoColor;
      args->xtemplate.depth = 8;
      args->xtemplate_mask |= VisualClassMask|VisualDepthMask;
    } 
        
    handle->display = display;
    handle->screen = screen;
    handle->screen_num = XScreenNumberOfScreen(screen);
    handle->x_visual_info = NULL;
    handle->cmap = None;
    handle->default_visualid = XDefaultVisual(display, handle->screen_num);
    handle->default_colormap = XDefaultColormap(display, handle->screen_num);
    handle->max_request_size = XMaxRequestSize(display);

#ifdef XLIBRGB_ENABLE_MITSHM_SUPPORT
    xshm_image_check(handle, args);
#endif /* XLIBRGB_ENABLE_MITSHM_SUPPORT */
    handle->disallow_image_tiling  = args->disallow_image_tiling;
    handle->xlib_rgb_install_cmap  = args->install_colormap;
    
    handle->color_pixels = NULL;
    handle->gray_pixels = NULL;
    handle->reserved_pixels = NULL;

    handle->nred_shades = 6;
    handle->ngreen_shades = 6;
    handle->nblue_shades = 4;
    handle->ngray_shades = 24;
    handle->nreserved = 0;

    handle->bpp = 0;
    handle->cmap_alloced = False;
    handle->gamma_val = 1.0;

    handle->stage_buf = NULL;

    handle->own_gc = None;
    
    handle->red_shift = 0;
    handle->red_prec = 0;
    handle->green_shift = 0;
    handle->green_prec = 0;
    handle->blue_shift = 0;
    handle->blue_prec = 0;

    handle->xlib_rgb_min_colors = 5 * 5 * 5;

    handle->horiz_y = IMAGE_HEIGHT;
    handle->vert_x  = IMAGE_WIDTH;
    handle->tile_x  = IMAGE_WIDTH;
    handle->tile_y1 = IMAGE_HEIGHT;
    handle->tile_y2 = IMAGE_HEIGHT;  

    if (!xxlib_rgb_choose_visual (handle, &args->xtemplate, args->xtemplate_mask))
    {
#ifdef DEBUG
      puts("xxlib_rgb_choose_visual failure");
#endif /* DEBUG */
      xxlib_rgb_destroy_handle(handle);
      return NULL;
    }

    handle->bitmap = (handle->x_visual_info->depth == 1);
      
    /* set up the shift and the precision for the red, green and blue.
       this only applies to cool visuals like true color and direct color. */
    if (handle->x_visual_info->class == TrueColor ||
        handle->x_visual_info->class == DirectColor) {
      handle->red_shift   = xxlib_get_shift_from_mask(handle->x_visual_info->red_mask);
      handle->red_prec    = xxlib_get_prec_from_mask(handle->x_visual_info->red_mask);
      handle->green_shift = xxlib_get_shift_from_mask(handle->x_visual_info->green_mask);
      handle->green_prec  = xxlib_get_prec_from_mask(handle->x_visual_info->green_mask);
      handle->blue_shift  = xxlib_get_shift_from_mask(handle->x_visual_info->blue_mask);
      handle->blue_prec   = xxlib_get_prec_from_mask(handle->x_visual_info->blue_mask);
    }
    
    if (args->pseudogray)
    {
      if (handle->xlib_rgb_install_cmap)
      {
        handle->cmap = XCreateColormap(handle->display,
                                       XRootWindow(handle->display, handle->screen_num),
                                       handle->x_visual_info->visual,
                                       AllocNone);
        xxlib_rgb_set_gray_cmap (handle, handle->cmap);
        handle->cmap_alloced = TRUE;
      }
      else
      {
        handle->cmap = handle->default_colormap;
        xxlib_rgb_set_gray_cmap (handle, handle->cmap);
      }  
    }
    else if ((handle->x_visual_info->class == PseudoColor ||
           handle->x_visual_info->class == StaticColor) &&
           handle->x_visual_info->depth < 8 &&
           handle->x_visual_info->depth >= 3)
    {
      handle->cmap = handle->default_colormap;
      xxlib_rgb_colorcube_222 (handle);
    }
    else if (handle->x_visual_info->class == StaticColor)
    {
      handle->cmap = XCreateColormap(handle->display,
                                     XRootWindow(handle->display, handle->screen_num),
                                     handle->x_visual_info->visual,
                                     AllocNone);
      handle->cmap_alloced = TRUE;
      xxlib_rgb_colorcube_676(handle);
    }
    else if (handle->x_visual_info->class == PseudoColor)
    {
      if (handle->xlib_rgb_install_cmap ||
          handle->x_visual_info->visualid != handle->default_visualid->visualid)
      {
        handle->cmap = XCreateColormap(handle->display,
                                       XRootWindow(handle->display, handle->screen_num),
                                       handle->x_visual_info->visual,
                                       AllocNone);
        handle->cmap_alloced = TRUE;
      }
      
      if (!xxlib_rgb_do_colormaps (handle))
      {
        handle->cmap = XCreateColormap(handle->display,
                                       XRootWindow(handle->display, handle->screen_num),
                                       handle->x_visual_info->visual,
                                       AllocNone);
        handle->cmap_alloced = TRUE;
        xxlib_rgb_do_colormaps (handle);
      }
      if (handle->xlib_rgb_verbose)
        printf ("color cube: %d x %d x %d\n",
                handle->nred_shades,
                handle->ngreen_shades,
                handle->nblue_shades);

      if (!handle->cmap_alloced)
        handle->cmap = handle->default_colormap;
     }
#ifdef ENABLE_GRAYSCALE
    else if (handle->x_visual_info->class == GrayScale)
    {
      handle->cmap = XCreateColormap(handle->display,
                                     XRootWindow(handle->display, handle->screen_num),
                                     handle->x_visual_info->visual,
                                     AllocNone);
      xxlib_rgb_set_gray_cmap (handle, handle->cmap);
      handle->cmap_alloced = TRUE;
    }
#endif /* ENABLE_GRAYSCALE */
    else if (handle->x_visual_info->class != DirectColor && 
             handle->x_visual_info->visualid == handle->default_visualid->visualid)
    {
      handle->cmap = handle->default_colormap;
    }  
    else
    {
      /* Always install colormap in direct color. */
      handle->cmap = XCreateColormap(handle->display,
                                     XRootWindow(handle->display, handle->screen_num),
                                     handle->x_visual_info->visual,
                                     AllocNone);
      handle->cmap_alloced = TRUE;
    }

#ifdef XLIBRGB_ENABLE_MITSHM_SUPPORT
    if (handle->xlib_use_shm)
    {
      /* try to allocate N_IMAGES shm X images */
      for (i = 0; i < N_IMAGES; i++)
      {
        handle->static_image[i] = xshm_image_new(handle);
        if (!handle->static_image[i])
        {
          handle->xlib_use_shm = False;
          break;
        }
      }
      
      /* Failure ? Then clean-up and use the standard method below... */
      if (!handle->xlib_use_shm)
      {
#ifdef DEBUG
        printf("Failed to set-up MIT-SHMEM after %d images\n", i);
#endif /* DEBUG */
        for (i = 0; i < N_IMAGES; i++)
        {
          if (handle->static_image[i])
          {
            XDestroyImage(handle->static_image[i]);
            handle->static_image[i] = NULL;
          }  
        } 
      }
    }  

    /* Allocate "normal" images "*/
    if (!handle->xlib_use_shm)
#endif /* XLIBRGB_ENABLE_MITSHM_SUPPORT */
    {    
      for (i = 0; i < N_IMAGES; i++) 
      {
        handle->static_image[i] = xxlib_normal_ximage(handle);
      }
    }  

    /* ok, so apparently, handle->bpp is actually
     * BYTES per pixel.  What fun! */
    handle->bpp = (handle->static_image[0]->bits_per_pixel + 7) / 8;

    xxlib_rgb_select_conv (handle, handle->static_image[0], MSB_FIRST);
    
    return handle;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void xxlib_rgb_destroy_handle ( XlibRgbHandle *  handle)

Definition at line 918 of file xlibrgb.c.

{
  int i;

  for( i = 0 ; i < N_IMAGES ; i++ )
  {
    if (handle->static_image[i])
      XDestroyImage(handle->static_image[i]);
  }
  
  if (handle->cmap_alloced)
  {
    XFreeColormap(handle->display, handle->cmap);
  }
  
  if (handle->own_gc)
    XFreeGC(handle->display, handle->own_gc);
  
  if (handle->colorcube)
    free(handle->colorcube);

  if (handle->colorcube_d && (handle->colorcube_d != handle->colorcube))
    free(handle->colorcube_d);
  
  if (handle->DM_565)
    free(handle->DM_565);
  
  if (handle->stage_buf)
    free(handle->stage_buf);

  xxlib_deregister_handle_by_handle(handle);
  
#ifdef DEBUG
    /* force crash if someone tries to touch the handle... */
    memset(handle, 0, sizeof(XlibRgbHandle));
#endif  
            
  /* done... */
  free(handle); 
}

Here is the call graph for this function:

Here is the caller graph for this function:

Bool xxlib_rgb_ditherable ( XlibRgbHandle *  handle)

Definition at line 3980 of file xlibrgb.c.

{
  return (handle->conv != handle->conv_d);
}
static Bool xxlib_rgb_do_colormaps ( XlibRgbHandle *  handle) [static]

Definition at line 634 of file xlibrgb.c.

{
  static const int sizes[][3] = 
  {
    /*    { 6, 7, 6 }, */
    { 6, 6, 6 }, 
    { 6, 6, 5 }, 
    { 6, 6, 4 }, 
    { 5, 5, 5 }, 
    { 5, 5, 4 }, 
    { 4, 4, 4 }, 
    { 4, 4, 3 }, 
    { 3, 3, 3 }, 
    { 2, 2, 2 }
  };
  static const int n_sizes = sizeof(sizes) / (3 * sizeof(int));
  int i;
  
  for (i = 0; i < n_sizes; i++)
    if (xxlib_rgb_try_colormap (handle, sizes[i][0], sizes[i][1], sizes[i][2]))
      return TRUE;
  return FALSE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static unsigned char* xxlib_rgb_ensure_stage ( XlibRgbHandle *  handle) [static]

Definition at line 3042 of file xlibrgb.c.

{
  if (handle->stage_buf == NULL)
    handle->stage_buf = malloc (IMAGE_HEIGHT * STAGE_ROWSTRIDE);
  return handle->stage_buf;
}

Here is the caller graph for this function:

void xxlib_rgb_gc_set_background ( XlibRgbHandle *  handle,
GC  gc,
uint32  rgb 
)

Definition at line 1313 of file xlibrgb.c.

{
  unsigned long color;

  color = xxlib_rgb_xpixel_from_rgb (handle, rgb);
  XSetBackground(handle->display, gc, color);
}

Here is the call graph for this function:

void xxlib_rgb_gc_set_foreground ( XlibRgbHandle *  handle,
GC  gc,
uint32  rgb 
)

Definition at line 1304 of file xlibrgb.c.

{
  unsigned long color;

  color = xxlib_rgb_xpixel_from_rgb (handle, rgb);
  XSetForeground(handle->display, gc, color);
}

Here is the call graph for this function:

Colormap xxlib_rgb_get_cmap ( XlibRgbHandle *  handle)

Definition at line 3986 of file xlibrgb.c.

{
  return (handle)?(handle->cmap):(None);
}

Here is the caller graph for this function:

int xxlib_rgb_get_depth ( XlibRgbHandle *  handle)

Definition at line 4006 of file xlibrgb.c.

{
  XVisualInfo *v = xxlib_rgb_get_visual_info(handle);

  return (v)?(v->depth):(0);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Display* xxlib_rgb_get_display ( XlibRgbHandle *  handle)

Definition at line 4014 of file xlibrgb.c.

{ 
  return (handle)?(handle->display):(NULL);
}

Here is the caller graph for this function:

Screen* xxlib_rgb_get_screen ( XlibRgbHandle *  handle)

Definition at line 4020 of file xlibrgb.c.

{
  return (handle)?(handle->screen):(NULL);
}

Here is the caller graph for this function:

Visual* xxlib_rgb_get_visual ( XlibRgbHandle *  handle)

Definition at line 3992 of file xlibrgb.c.

{
  /* xxlib_rgb_init (); */
  return (handle)?(handle->x_visual_info->visual):(NULL);
}

Here is the caller graph for this function:

XVisualInfo* xxlib_rgb_get_visual_info ( XlibRgbHandle *  handle)

Definition at line 3999 of file xlibrgb.c.

{
  /* xxlib_rgb_init (); */
  return (handle)?(handle->x_visual_info):(NULL);
}

Here is the caller graph for this function:

static void xxlib_rgb_gray_to_stage ( XlibRgbHandle *  handle,
unsigned char *  buf,
int  rowstride,
int  width,
int  height 
) [static]

Definition at line 3107 of file xlibrgb.c.

{
  int x, y;
  unsigned char *pi_start, *po_start;
  unsigned char *pi, *po;
  unsigned char gray;

  pi_start = buf;
  po_start = xxlib_rgb_ensure_stage (handle);
  for (y = 0; y < height; y++)
    {
      pi = pi_start;
      po = po_start;
      for (x = 0; x < width; x++)
        {
          gray = *pi++;
          *po++ = gray;
          *po++ = gray;
          *po++ = gray;
        }
      pi_start += rowstride;
      po_start += STAGE_ROWSTRIDE;
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void xxlib_rgb_indexed_to_stage ( XlibRgbHandle *  handle,
unsigned char *  buf,
int  rowstride,
int  width,
int  height,
XlibRgbCmap *  cmap 
) [static]

Definition at line 3187 of file xlibrgb.c.

{
  int x, y;
  unsigned char *pi_start, *po_start;
  unsigned char *pi, *po;
  int rgb;

  pi_start = buf;
  po_start = xxlib_rgb_ensure_stage (handle);
  for (y = 0; y < height; y++)
    {
      pi = pi_start;
      po = po_start;
      for (x = 0; x < width; x++)
        {
          rgb = cmap->colors[*pi++];
          *po++ = rgb >> 16;
          *po++ = (rgb >> 8) & 0xff;
          *po++ = rgb & 0xff;
        }
      pi_start += rowstride;
      po_start += STAGE_ROWSTRIDE;
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void xxlib_rgb_make_colorcube ( XlibRgbHandle *  handle,
unsigned long pixels,
int  nr,
int  ng,
int  nb 
) [static]

Definition at line 449 of file xlibrgb.c.

{
  unsigned char rt[16], gt[16], bt[16];
  int i;

  handle->colorcube = calloc(4096, 1);
  for (i = 0; i < 16; i++)
  {
    rt[i] = ng * nb * ((i * 17 * (nr - 1) + 128) >> 8);
    gt[i] = nb * ((i * 17 * (ng - 1) + 128) >> 8);
    bt[i] = ((i * 17 * (nb - 1) + 128) >> 8);
  }

  for (i = 0; i < 4096; i++)
  {
    handle->colorcube[i] = pixels[rt[i >> 8] + gt[(i >> 4) & 0x0f] + bt[i & 0x0f]];
#ifdef VERBOSE
    printf ("%03x %02x %x %x %x\n", i, handle->colorcube[i], rt[i >> 8], gt[(i >> 4) & 0x0f], bt[i & 0x0f]);
#endif
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void xxlib_rgb_make_colorcube_d ( XlibRgbHandle *  handle,
unsigned long pixels,
int  nr,
int  ng,
int  nb 
) [static]

Definition at line 473 of file xlibrgb.c.

{
  int r, g, b;
  int i;

  handle->colorcube_d = calloc(512, 1);
  for (i = 0; i < 512; i++)
  {
    r = MIN (nr - 1, i >> 6);
    g = MIN (ng - 1, (i >> 3) & 7);
    b = MIN (nb - 1, i & 7);
    handle->colorcube_d[i] = pixels[(r * ng + g) * nb + b];
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void xxlib_rgb_make_gray_cmap ( XlibRgbHandle *  handle) [static]

Definition at line 3816 of file xlibrgb.c.

{
  uint32 rgb[256];
  int i;

  for (i = 0; i < 256; i++)
    rgb[i] = (i << 16)  | (i << 8) | i;
  handle->gray_cmap = xxlib_rgb_cmap_new (handle, rgb, 256);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void xxlib_rgb_preprocess_dm_565 ( XlibRgbHandle *  handle) [static]

Definition at line 1596 of file xlibrgb.c.

{
  int i;
  uint32 dith;

  if (handle->DM_565 == NULL)
    {
      handle->DM_565 = malloc(sizeof(uint32) * DM_WIDTH * DM_HEIGHT);
      for (i = 0; i < DM_WIDTH * DM_HEIGHT; i++)
        {
          dith = DM[i / DM_WIDTH][i % DM_WIDTH] >> 3;
          handle->DM_565[i] = (dith << 20) | dith | (((7 - dith) >> 1) << 10);
#ifdef VERBOSE
          printf ("%i %x %x\n", i, dith, handle->DM_565[i]);
#endif
        }
    }
}

Here is the caller graph for this function:

static uint32 xxlib_rgb_score_visual ( XlibRgbHandle *  handle,
XVisualInfo *  visual 
) [static]

Definition at line 753 of file xlibrgb.c.

{
  uint32 quality, speed, pseudo, sys;
#ifdef DEBUG
  static const char* visual_names[] =
  {
    "static gray",
    "grayscale",
    "static color",
    "pseudo color",
    "true color",
    "direct color",
  };
#endif /* DEBUG */
  
  quality = 0;
  speed = 1;
  sys = 0;
  if (visual->class == TrueColor ||
      visual->class == DirectColor)
  {
    if (visual->depth == 24)
    {
      quality = 9;
      /* Should test for MSB visual here, and set speed if so. */
    }
    else if (visual->depth == 16)
      quality = 8;
    else if (visual->depth == 15)
      quality = 7;
    else if (visual->depth == 8)
      quality = 4;
    }
    else if (visual->class == PseudoColor ||
           visual->class == StaticColor)
    {
      if (visual->depth == 8)
        quality = 4;
      else if (visual->depth == 4)
        quality = 2;
      else if (visual->depth == 1)
        quality = 1;
    }
  else if (visual->class == StaticGray
#ifdef ENABLE_GRAYSCALE
           || visual->class == GrayScale
#endif /* ENABLE_GRAYSCALE */
           )
    {
      if (visual->depth == 8)
        quality = 4;
      else if (visual->depth == 4)
        quality = 2;
      else if (visual->depth == 1)
        quality = 1;
    }

  if (quality == 0)
    return 0;

  sys = (visual->visualid == handle->default_visualid->visualid);
  
  pseudo = (visual->class == PseudoColor || visual->class == TrueColor);

#ifdef DEBUG
  if (handle->xlib_rgb_verbose)
    printf ("Visual 0x%x, type = %s, depth = %d, %ld:%ld:%ld%s; score=%x\n",
            (int)visual->visualid,
            visual_names[visual->class],
            visual->depth,
            visual->red_mask,
            visual->green_mask,
            visual->blue_mask,
            sys ? " (system)" : "",
            (quality << 12) | (speed << 8) | (sys << 4) | pseudo);
#endif /* DEBUG */
  return (quality << 12) | (speed << 8) | (sys << 4) | pseudo;
}

Here is the caller graph for this function:

static void xxlib_rgb_select_conv ( XlibRgbHandle *  handle,
XImage *  image,
ByteOrder  byte_order 
) [static]

Definition at line 3245 of file xlibrgb.c.

{
  int depth, byterev;
  int vtype; /* visual type */
  int bpp; /* bits per pixel - from the visual */
  uint32 red_mask, green_mask, blue_mask;
  XlibRgbConvFunc conv, conv_d;
  XlibRgbConvFunc conv_32, conv_32_d;
  XlibRgbConvFunc conv_gray, conv_gray_d;
  XlibRgbConvFunc conv_indexed, conv_indexed_d;
  Bool mask_rgb, mask_bgr;

  depth = handle->x_visual_info->depth;
  bpp = image->bits_per_pixel;
  if (handle->xlib_rgb_verbose)
    printf ("Chose visual 0x%x, image bpp=%d, %s first\n",
            (int)handle->x_visual_info->visual->visualid,
            bpp, byte_order == LSB_FIRST ? "lsb" : "msb");

#if G_BYTE_ORDER == G_BIG_ENDIAN
  byterev = (byte_order == LSB_FIRST);
#else
  byterev = (byte_order == MSB_FIRST);
#endif

  vtype = handle->x_visual_info->class;
  if (vtype == DirectColor)
    vtype = TrueColor;

  red_mask = handle->x_visual_info->red_mask;
  green_mask = handle->x_visual_info->green_mask;
  blue_mask = handle->x_visual_info->blue_mask;

  mask_rgb = red_mask == 0xff0000 && green_mask == 0xff00 && blue_mask == 0xff;
  mask_bgr = red_mask == 0xff && green_mask == 0xff00 && blue_mask == 0xff0000;

  conv   = NULL;
  conv_d = NULL;

  conv_32     = xxlib_rgb_convert_32_generic;
  conv_32_d   = xxlib_rgb_convert_32_generic_d;

  conv_gray   = xxlib_rgb_convert_gray_generic;
  conv_gray_d = xxlib_rgb_convert_gray_generic_d;

  conv_indexed   = xxlib_rgb_convert_indexed_generic;
  conv_indexed_d = xxlib_rgb_convert_indexed_generic_d;

  handle->dith_default = FALSE;

  if (handle->bitmap)
    conv = xxlib_rgb_convert_1;
  else if (bpp == 16 && depth == 16 && !byterev &&
      red_mask == 0xf800 && green_mask == 0x7e0 && blue_mask == 0x1f)
    {
      conv = xxlib_rgb_convert_565;
      conv_d = xxlib_rgb_convert_565_d;
      conv_gray = xxlib_rgb_convert_565_gray;
      xxlib_rgb_preprocess_dm_565 (handle);
    }
  else if (bpp == 16 && depth == 16 &&
           vtype == TrueColor&& byterev &&
      red_mask == 0xf800 && green_mask == 0x7e0 && blue_mask == 0x1f)
    conv = xxlib_rgb_convert_565_br;

  else if (bpp == 16 && depth == 15 &&
           vtype == TrueColor && !byterev &&
      red_mask == 0x7c00 && green_mask == 0x3e0 && blue_mask == 0x1f)
    conv = xxlib_rgb_convert_555;

  else if (bpp == 16 && depth == 15 &&
           vtype == TrueColor && byterev &&
      red_mask == 0x7c00 && green_mask == 0x3e0 && blue_mask == 0x1f)
    conv = xxlib_rgb_convert_555_br;

  /* I'm not 100% sure about the 24bpp tests - but testing will show*/
  else if (bpp == 24 && depth == 24 && vtype == TrueColor &&
           ((mask_rgb && byte_order == LSB_FIRST) ||
            (mask_bgr && byte_order == MSB_FIRST)))
    conv = xxlib_rgb_convert_888_lsb;
  else if (bpp == 24 && depth == 24 && vtype == TrueColor &&
           ((mask_rgb && byte_order == MSB_FIRST) ||
            (mask_bgr && byte_order == LSB_FIRST)))
    conv = xxlib_rgb_convert_888_msb;
#if G_BYTE_ORDER == G_BIG_ENDIAN
  else if (bpp == 32 && depth == 24 && vtype == TrueColor &&
           (mask_rgb && byte_order == LSB_FIRST))
    conv = xxlib_rgb_convert_0888_br;
  else if (bpp == 32 && depth == 24 && vtype == TrueColor &&
           (mask_rgb && byte_order == MSB_FIRST))
    conv = xxlib_rgb_convert_0888;
  else if (bpp == 32 && depth == 24 && vtype == TrueColor &&
           (mask_bgr && byte_order == MSB_FIRST))
    conv = xxlib_rgb_convert_8880_br;
#else
  else if (bpp == 32 && depth == 24 && vtype == TrueColor &&
           (mask_rgb && byte_order == MSB_FIRST))
    conv = xxlib_rgb_convert_0888_br;
  else if (bpp == 32 && (depth == 32 || depth == 24) && vtype == TrueColor &&
           (mask_rgb && byte_order == LSB_FIRST))
    conv = xxlib_rgb_convert_0888;
  else if (bpp == 32 && depth == 24 && vtype == TrueColor &&
           (mask_bgr && byte_order == LSB_FIRST))
    conv = xxlib_rgb_convert_8880_br;
#endif

  else if (vtype == TrueColor && byte_order == LSB_FIRST)
    {
      conv = xxlib_rgb_convert_truecolor_lsb;
      conv_d = xxlib_rgb_convert_truecolor_lsb_d;
    }
  else if (vtype == TrueColor && byte_order == MSB_FIRST)
    {
      conv = xxlib_rgb_convert_truecolor_msb;
      conv_d = xxlib_rgb_convert_truecolor_msb_d;
    }
  else if (bpp == 8 && depth == 8 && (vtype == PseudoColor || vtype == StaticColor
#ifdef ENABLE_GRAYSCALE
                                      || vtype == GrayScale
#endif
                                      ))
    {
      handle->dith_default = TRUE;
      conv = xxlib_rgb_convert_8;
      if (vtype != GrayScale)
        {
          if (handle->nred_shades == 6 &&
              handle->ngreen_shades == 6 &&
              handle->nblue_shades == 6)
            conv_d = xxlib_rgb_convert_8_d666;
          else
            conv_d = xxlib_rgb_convert_8_d;
        }
      conv_indexed = xxlib_rgb_convert_8_indexed;
      conv_gray = xxlib_rgb_convert_gray_cmap;
    }
  else if (bpp == 8 && depth == 8 && (vtype == StaticGray
#ifdef not_ENABLE_GRAYSCALE
                                      || vtype == GrayScale
#endif
                                      ))
    {
      conv = xxlib_rgb_convert_gray8;
      conv_gray = xxlib_rgb_convert_gray8_gray;
    }
  else if (bpp == 8 && depth < 8 && depth >= 2 &&
           (vtype == StaticGray
            || vtype == GrayScale))
    {
      conv = xxlib_rgb_convert_gray4;
      conv_d = xxlib_rgb_convert_gray4_d;
    }
  else if (bpp == 8 && depth < 8 && depth >= 3)
    {
      conv = xxlib_rgb_convert_4;
    }
  else if (bpp == 4 && depth <= 4 && depth >= 2 &&
           (vtype == StaticGray
            || vtype == GrayScale))
    {
      conv = xxlib_rgb_convert_gray4_pack;
      conv_d = xxlib_rgb_convert_gray4_d_pack;
    }

  if (conv_d == NULL)
    conv_d = conv;

  handle->conv = conv;
  handle->conv_d = conv_d;

  handle->conv_32 = conv_32;
  handle->conv_32_d = conv_32_d;

  handle->conv_gray = conv_gray;
  handle->conv_gray_d = conv_gray_d;

  handle->conv_indexed = conv_indexed;
  handle->conv_indexed_d = conv_indexed_d;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void xxlib_rgb_set_gray_cmap ( XlibRgbHandle *  handle,
Colormap  cmap 
) [static]

Definition at line 877 of file xlibrgb.c.

{
  int i;
  XColor color;
  int status;
  unsigned long pixels[256];
  int r, g, b, gray;

  for (i = 0; i < 256; i++)
  {
    color.pixel = i;
    color.red   = i * 257;
    color.green = i * 257;
    color.blue  = i * 257;
    status = XAllocColor(handle->display, cmap, &color);
    pixels[i] = color.pixel;
#ifdef VERBOSE
    printf ("allocating pixel %d, %x %x %x, result %d\n",
            color.pixel, color.red, color.green, color.blue, status);
#endif /* VERBOSE */
  }

  /* Now, we make fake colorcubes - we ultimately just use the pseudocolor
     methods. */

  handle->colorcube = handle->colorcube_d = malloc(sizeof(unsigned char) * 4096);

  for (i = 0; i < 4096; i++)
  {
    r = (i >> 4) & 0xf0;
    r = r | r >> 4;
    g = i & 0xf0;
    g = g | g >> 4;
    b = (i << 4 & 0xf0);
    b = b | b >> 4;
    gray = (g + ((r + b) >> 1)) >> 1;
    handle->colorcube[i] = handle->colorcube_d[i] = pixels[gray];
  }
}

Here is the caller graph for this function:

void xxlib_rgb_set_min_colors ( XlibRgbHandle *  handle,
int  min_colors 
)

Definition at line 731 of file xlibrgb.c.

{
  handle->xlib_rgb_min_colors = min_colors;
}
void xxlib_rgb_set_verbose ( XlibRgbHandle *  handle,
Bool  verbose 
)

Definition at line 725 of file xlibrgb.c.

{
  handle->xlib_rgb_verbose = verbose;
}
static int xxlib_rgb_try_colormap ( XlibRgbHandle *  handle,
int  nr,
int  ng,
int  nb 
) [static]

Definition at line 491 of file xlibrgb.c.

{
  int r, g, b;
  int ri, gi, bi;
  int r0, g0, b0;
  Colormap     cmap;
  XVisualInfo *visual;
  XColor      *colors = NULL;
  XColor       color;
  unsigned long pixels[256];
  unsigned long junk[256];
  int i;
  int d2;
  unsigned int colors_needed;
  int idx;
  int best[256];

  if (nr * ng * nb < handle->xlib_rgb_min_colors)
    return FALSE;

  if (handle->cmap_alloced) {
    cmap = handle->cmap;
    visual = handle->x_visual_info;
  }
  else {
    cmap = handle->default_colormap;
    visual = handle->x_visual_info;
  }
  colors_needed = nr * ng * nb;
  for (i = 0; i < 256; i++)
  {
    best[i] = 192;
    pixels[i] = 256;
  }

#ifndef GAMMA
  if (!handle->xlib_rgb_install_cmap) {
    /* go out and get the colors for this colormap. */
    colors = malloc(sizeof(XColor) * visual->colormap_size);
    for (i=0; i < visual->colormap_size; i++){
      colors[i].pixel = i;
    }
    XQueryColors (handle->display,
                  cmap,
                  colors, visual->colormap_size);
    /* find color cube colors that are already present */
    for (i = 0; i < MIN (256, visual->colormap_size); i++)
    {
      r = colors[i].red >> 8;
      g = colors[i].green >> 8;
      b = colors[i].blue >> 8;
      ri = (r * (nr - 1) + 128) >> 8;
      gi = (g * (ng - 1) + 128) >> 8;
      bi = (b * (nb - 1) + 128) >> 8;
      r0 = ri * 255 / (nr - 1);
      g0 = gi * 255 / (ng - 1);
      b0 = bi * 255 / (nb - 1);
      idx = ((ri * nr) + gi) * nb + bi;
      d2 = (r - r0) * (r - r0) + (g - g0) * (g - g0) + (b - b0) * (b - b0);
      if (d2 < best[idx]) 
      {
        if (pixels[idx] < 256)
        XFreeColors(handle->display,
                    cmap,
                    pixels + idx,
                    1, 0);
        else
          colors_needed--;
        color.pixel = colors[i].pixel;
        color.red = colors[i].red;
        color.green = colors[i].green;
        color.blue = colors[i].blue;
        color.flags = 0;
        if (!XAllocColor(handle->display, cmap, &color))
          return xxlib_rgb_cmap_fail (handle, "error allocating system color\n",
        cmap, pixels);
        pixels[idx] = color.pixel; /* which is almost certainly i */
        best[idx] = d2;
      }
    }
  }

#endif /* !GAMMA */

  if (colors_needed)
  {
    if (!XAllocColorCells(handle->display, cmap, 0, NULL, 0, junk, colors_needed))
    {
      char tmp_str[80];
      
      sprintf (tmp_str,
               "%d %d %d colormap failed (in XAllocColorCells)\n",
               nr, ng, nb);
      return xxlib_rgb_cmap_fail (handle, tmp_str, cmap, pixels);
    }
    XFreeColors(handle->display, cmap, junk, (int)colors_needed, 0);
  }

  for (r = 0, i = 0; r < nr; r++)
    for (g = 0; g < ng; g++)
      for (b = 0; b < nb; b++, i++)
      {
        if (pixels[i] == 256)
          {
            color.red = r * 65535 / (nr - 1);
            color.green = g * 65535 / (ng - 1);
            color.blue = b * 65535 / (nb - 1);

#ifdef GAMMA
            color.red = 65535 * pow (color.red / 65535.0, 0.5);
            color.green = 65535 * pow (color.green / 65535.0, 0.5);
            color.blue = 65535 * pow (color.blue / 65535.0, 0.5);
#endif /* GAMMA */

            /* This should be a raw XAllocColor call */
            if (!XAllocColor(handle->display, cmap, &color))
            {
              char tmp_str[80];

              sprintf (tmp_str, "%d %d %d colormap failed\n",
                       nr, ng, nb);
              return xxlib_rgb_cmap_fail (handle, tmp_str,
                                          cmap, pixels);
            }
            pixels[i] = color.pixel;
          }
#ifdef VERBOSE
          printf ("%d: %lx\n", i, pixels[i]);
#endif /* VERBOSE */
        }

  handle->nred_shades = nr;
  handle->ngreen_shades = ng;
  handle->nblue_shades = nb;
  xxlib_rgb_make_colorcube (handle, pixels, nr, ng, nb);
  xxlib_rgb_make_colorcube_d (handle, pixels, nr, ng, nb);
  if (colors)
    free(colors);
  return TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

unsigned long xxlib_rgb_xpixel_from_rgb ( XlibRgbHandle *  handle,
uint32  rgb 
)

Definition at line 1240 of file xlibrgb.c.

{
  unsigned long pixel = 0;

  if (handle->bitmap)
  {
    return ((rgb & 0xff0000) >> 16) +
           ((rgb & 0xff00) >> 7) +
            (rgb & 0xff) > 510;
  }
  else if (handle->x_visual_info->class == PseudoColor)
    pixel = handle->colorcube[((rgb & 0xf00000) >> 12) |
                              ((rgb & 0xf000) >> 8) |
                              ((rgb & 0xf0) >> 4)];
  else if (handle->x_visual_info->depth < 8 &&
           handle->x_visual_info->class == StaticColor)
  {
    pixel = handle->colorcube_d[((rgb & 0x800000) >> 17) |
                                ((rgb & 0x8000) >> 12) |
                                ((rgb & 0x80) >> 7)];
  }
  else if (handle->x_visual_info->class == StaticColor)
  {
    pixel = handle->colorcube[((rgb & 0xf00000) >> 12) |
                              ((rgb & 0xf000) >> 8) |
                              ((rgb & 0xf0) >> 4)];  
  }
  else if (handle->x_visual_info->class == TrueColor ||
           handle->x_visual_info->class == DirectColor)
  {
#ifdef VERBOSE
    printf ("shift, prec: r %d %d g %d %d b %d %d\n",
            handle->red_shift,
            handle->red_prec,
            handle->green_shift,
            handle->green_prec,
            handle->blue_shift,
            handle->blue_prec);
#endif

    pixel = (((((rgb & 0xff0000) >> 16) >>
               (8 - handle->red_prec)) <<
              handle->red_shift) +
             ((((rgb & 0xff00) >> 8)  >>
               (8 - handle->green_prec)) <<
              handle->green_shift) +
             (((rgb & 0xff) >>
               (8 - handle->blue_prec)) <<
              handle->blue_shift));
  }
  else if (handle->x_visual_info->class == StaticGray ||
           handle->x_visual_info->class == GrayScale)
  {
    int gray = ((rgb & 0xff0000) >> 16) +
               ((rgb & 0xff00) >> 7) +
                (rgb & 0xff);

    return gray >> (10 - handle->x_visual_info->depth);
  }

  return pixel;
}

Here is the caller graph for this function:


Variable Documentation

const unsigned char DM[128][128] [static]

Definition at line 1445 of file xlibrgb.c.

Definition at line 4031 of file xlibrgb.c.

unsigned int registered_handles_size = 0 [static]

Definition at line 4032 of file xlibrgb.c.