Back to index

lightning-sunbird  0.9+nobinonly
xlibrgb.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
00002  *
00003  * ***** BEGIN LICENSE BLOCK *****
00004  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00005  *
00006  * The contents of this file are subject to the Mozilla Public License Version
00007  * 1.1 (the "License"); you may not use this file except in compliance with
00008  * the License. You may obtain a copy of the License at
00009  * http://www.mozilla.org/MPL/
00010  *
00011  * Software distributed under the License is distributed on an "AS IS" basis,
00012  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00013  * for the specific language governing rights and limitations under the
00014  * License.
00015  *
00016  * The Original Code is mozilla.org Code.
00017  *
00018  * The Initial Developer of the Original Code is
00019  * Netscape Communications Corporation.
00020  * Portions created by the Initial Developer are Copyright (C) 2001
00021  * the Initial Developer. All Rights Reserved.
00022  *
00023  * Contributor(s):
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either of the GNU General Public License Version 2 or later (the "GPL"),
00027  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00028  * in which case the provisions of the GPL or the LGPL are applicable instead
00029  * of those above. If you wish to allow use of your version of this file only
00030  * under the terms of either the GPL or the LGPL, and not to allow others to
00031  * use your version of this file under the terms of the MPL, indicate your
00032  * decision by deleting the provisions above and replace them with the notice
00033  * and other provisions required by the GPL or the LGPL. If you do not delete
00034  * the provisions above, a recipient may use your version of this file under
00035  * the terms of any one of the MPL, the GPL or the LGPL.
00036  *
00037  * ***** END LICENSE BLOCK ***** */
00038 
00039 /*
00040  * This code is derived from GdkRgb.
00041  * For more information on GdkRgb, see http://www.levien.com/gdkrgb/
00042  * Raph Levien <raph@acm.org>
00043  */
00044 
00045 /* Ported by Christopher Blizzard to Xlib.  With permission from the
00046  * original authors of this file, the contents of this file are also
00047  * redistributable under the terms of the Mozilla Public license.  For
00048  * information about the Mozilla Public License, please see the
00049  * license information at http://www.mozilla.org/MPL/
00050  */
00051 
00052 /* This code is copyright the following authors:
00053  * Raph Levien          <raph@acm.org>
00054  * Manish Singh         <manish@gtk.org>
00055  * Tim Janik            <timj@gtk.org>
00056  * Peter Mattis         <petm@xcf.berkeley.edu>
00057  * Spencer Kimball      <spencer@xcf.berkeley.edu>
00058  * Josh MacDonald       <jmacd@xcf.berkeley.edu>
00059  * Christopher Blizzard <blizzard@redhat.com>
00060  * Owen Taylor          <otaylor@redhat.com>
00061  * Shawn T. Amundson    <amundson@gtk.org>
00062  * Roland Mainz         <roland.mainz@informatik.med.uni-giessen.de> 
00063  */
00064 
00065 
00066 #ifndef __XLIB_RGB_H__
00067 #define __XLIB_RGB_H__
00068 
00069 /* Force ANSI C prototypes from X11 headers */
00070 #undef FUNCPROTO
00071 #define FUNCPROTO 15
00072 
00073 #include <X11/Xlib.h>
00074 #include <X11/Xutil.h>
00075 #include <X11/Xos.h>
00076 #include <X11/Intrinsic.h>
00077 
00078 _XFUNCPROTOBEGIN
00079 
00080 /* Porting Note:
00081  * If you are going to use this code somewhere other than mozilla
00082  * you will need to set these defines.  It's pretty easy for Intel
00083  * but I'm not sure about other platforms.
00084  */
00085 #ifdef USE_MOZILLA_TYPES
00086 /* prtypes contains definitions for uint32/int32 and uint16/int16 */
00087 #include "prtypes.h"
00088 #include "prcpucfg.h"
00089 #include "nscore.h"
00090 
00091 #ifdef _IMPL_XLIBRGB_API
00092 #define NS_XLIBRGB_API(type) NS_EXPORT_(type)
00093 #else
00094 #define NS_XLIBRGB_API(type) NS_IMPORT_(type)
00095 #endif
00096 
00097 #define NS_TO_XXLIB_RGB(ns) (ns & 0xff) << 16 | (ns & 0xff00) | ((ns >> 16) & 0xff)
00098 #else
00099 typedef unsigned int uint32;
00100 typedef int int32;
00101 typedef unsigned short uint16;
00102 typedef short int16;
00103 
00104 #define NS_XLIBRGB_API(type) type
00105 #endif /* USE_MOZILLA_TYPES */
00106 
00107 typedef struct _XlibRgbCmap XlibRgbCmap;
00108 typedef struct _XlibRgbHandle XlibRgbHandle;
00109 
00110 struct _XlibRgbCmap {
00111   unsigned int colors[256];
00112   unsigned char lut[256]; /* for 8-bit modes */
00113 };
00114 
00115 
00116 typedef enum
00117 {
00118   XLIB_RGB_DITHER_NONE,
00119   XLIB_RGB_DITHER_NORMAL,
00120   XLIB_RGB_DITHER_MAX
00121 } XlibRgbDither;
00122 
00123 typedef struct
00124 {
00125   const char *handle_name;
00126   int         pseudogray; /* emulate GrayScale via PseudoColor visuals */
00127   int         install_colormap;
00128   int         disallow_image_tiling;
00129   int         disallow_mit_shmem;
00130   int         verbose;
00131   XVisualInfo xtemplate;
00132   long        xtemplate_mask;
00133 } XlibRgbArgs;
00134 
00135 NS_XLIBRGB_API(XlibRgbHandle *)
00136 xxlib_rgb_create_handle (Display *display, Screen *screen, 
00137                          XlibRgbArgs *args);
00138                                   
00139 NS_XLIBRGB_API(void)
00140 xxlib_rgb_destroy_handle (XlibRgbHandle *handle);
00141 
00142 NS_XLIBRGB_API(unsigned long)
00143 xxlib_rgb_xpixel_from_rgb (XlibRgbHandle *handle, uint32 rgb);
00144 
00145 NS_XLIBRGB_API(void)
00146 xxlib_rgb_gc_set_foreground (XlibRgbHandle *handle, GC gc, uint32 rgb);
00147 
00148 NS_XLIBRGB_API(void)
00149 xxlib_rgb_gc_set_background (XlibRgbHandle *handle, GC gc, uint32 rgb);
00150 
00151 NS_XLIBRGB_API(void)
00152 xxlib_draw_rgb_image (XlibRgbHandle *handle, Drawable drawable,
00153                       GC gc,
00154                       int x,
00155                       int y,
00156                       int width,
00157                       int height,
00158                       XlibRgbDither dith,
00159                       unsigned char *rgb_buf,
00160                       int rowstride);
00161 
00162 NS_XLIBRGB_API(void)
00163 xxlib_draw_rgb_image_dithalign (XlibRgbHandle *handle, Drawable drawable,
00164                                 GC gc,
00165                                 int x,
00166                                 int y,
00167                                 int width,
00168                                 int height,
00169                                 XlibRgbDither dith,
00170                                 unsigned char *rgb_buf,
00171                                 int rowstride,
00172                                 int xdith,
00173                                 int ydith);
00174 
00175 NS_XLIBRGB_API(void)
00176 xxlib_draw_rgb_32_image (XlibRgbHandle *handle, Drawable drawable,
00177                          GC gc,
00178                          int x,
00179                          int y,
00180                          int width,
00181                          int height,
00182                          XlibRgbDither dith,
00183                          unsigned char *buf,
00184                          int rowstride);
00185 
00186 NS_XLIBRGB_API(void)
00187 xxlib_draw_gray_image (XlibRgbHandle *handle, Drawable drawable,
00188                        GC gc,
00189                        int x,
00190                        int y,
00191                        int width,
00192                        int height,
00193                        XlibRgbDither dith,
00194                        unsigned char *buf,
00195                        int rowstride);
00196 
00197 NS_XLIBRGB_API(XlibRgbCmap *)
00198 xxlib_rgb_cmap_new (XlibRgbHandle *handle, uint32 *colors, int n_colors);
00199 
00200 NS_XLIBRGB_API(void)
00201 xxlib_rgb_cmap_free (XlibRgbHandle *handle, XlibRgbCmap *cmap);
00202 
00203 NS_XLIBRGB_API(void)
00204 xxlib_draw_indexed_image (XlibRgbHandle *handle, Drawable drawable,
00205                           GC gc,
00206                           int x,
00207                           int y,
00208                           int width,
00209                           int height,
00210                           XlibRgbDither dith,
00211                           unsigned char *buf,
00212                           int rowstride,
00213                           XlibRgbCmap *cmap);
00214 
00215 NS_XLIBRGB_API(void)
00216 xxlib_draw_xprint_scaled_rgb_image( XlibRgbHandle *handle,
00217                                     Drawable drawable,
00218                                     long paper_resolution,
00219                                     long image_resolution,
00220                                     GC gc,
00221                                     int x,
00222                                     int y,
00223                                     int width,
00224                                     int height,
00225                                     XlibRgbDither dith,
00226                                     unsigned char *rgb_buf,
00227                                     int rowstride);
00228 
00229 /* Below are some functions which are primarily useful for debugging
00230    and experimentation. */
00231 NS_XLIBRGB_API(Bool)
00232 xxlib_rgb_ditherable (XlibRgbHandle *handle);
00233 
00234 NS_XLIBRGB_API(void)
00235 xxlib_rgb_set_verbose (XlibRgbHandle *handle, Bool verbose);
00236 
00237 NS_XLIBRGB_API(void)
00238 xxlib_rgb_set_min_colors (XlibRgbHandle *handle, int min_colors);
00239 
00240 NS_XLIBRGB_API(Colormap)
00241 xxlib_rgb_get_cmap (XlibRgbHandle *handle);
00242 
00243 NS_XLIBRGB_API(Visual *)
00244 xxlib_rgb_get_visual (XlibRgbHandle *handle);
00245 
00246 NS_XLIBRGB_API(XVisualInfo *)
00247 xxlib_rgb_get_visual_info (XlibRgbHandle *handle);
00248 
00249 NS_XLIBRGB_API(int)
00250 xxlib_rgb_get_depth (XlibRgbHandle *handle);
00251 
00252 /* hint: if you don't how to obtain a handle - use |xxlib_find_handle()| :-) */
00253 NS_XLIBRGB_API(Display *)
00254 xxlib_rgb_get_display (XlibRgbHandle *handle);
00255 
00256 NS_XLIBRGB_API(Screen *)
00257 xxlib_rgb_get_screen (XlibRgbHandle *handle);
00258 
00259 NS_XLIBRGB_API(unsigned long)
00260 xxlib_get_prec_from_mask(unsigned long);
00261 
00262 NS_XLIBRGB_API(unsigned long)
00263 xxlib_get_shift_from_mask(unsigned long);
00264 
00265 /* default name - for cases where there is only one XlibRgbHandle required */
00266 #define XXLIBRGB_DEFAULT_HANDLE ("xxlib-default")
00267 
00268 NS_XLIBRGB_API(Bool)
00269 xxlib_register_handle(const char *name, XlibRgbHandle *handle);
00270 
00271 NS_XLIBRGB_API(Bool)
00272 xxlib_deregister_handle(const char *name);
00273 
00274 NS_XLIBRGB_API(XlibRgbHandle *)
00275 xxlib_find_handle(const char *name);
00276 
00277 _XFUNCPROTOEND
00278 
00279 #endif /* !__XLIB_RGB_H__ */
00280