Main Page   Modules   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

Fl_Renderer.h

00001 /*
00002  * $Id: Fl_Renderer.h,v 1.20 2003/07/03 20:36:35 laza2000 Exp $
00003  *
00004  * Extended Fast Light Toolkit (EFLTK)
00005  * Copyright (C) 2002-2003 by EDE-Team
00006  * WWW: http://www.sourceforge.net/projects/ede
00007  *
00008  * Fast Light Toolkit (FLTK)
00009  * Copyright (C) 1998-2003 by Bill Spitzak and others.
00010  * WWW: http://www.fltk.org
00011  *
00012  * This library is distributed under the GNU LIBRARY GENERAL PUBLIC LICENSE
00013  * version 2. See COPYING for details.
00014  *
00015  * Author : Mikko Lahteenmaki
00016  * Email  : mikko@fltk.net
00017  *
00018  * Please report all bugs and problems to "efltk-bugs@fltk.net"
00019  *
00020  */
00021 
00022 #ifndef _Fl_RENDERER_H_
00023 #define _Fl_RENDERER_H_
00024 
00025 #include "Enumerations.h"
00026 #include "Fl_Util.h"
00027 #include "x.h"
00028 
00029 // Mask types:
00030 enum {
00031     FL_MASK_NONE = 0,
00032     FL_MASK_ALPHA,
00033     FL_MASK_COLORKEY,
00034     FL_MASK_PIXELKEY,
00035 
00036     // Backward compatibility:
00037     MASK_NONE = FL_MASK_NONE,
00038     MASK_ALPHA = FL_MASK_ALPHA,
00039     MASK_COLORKEY = FL_MASK_COLORKEY,
00040     MASK_PIXELKEY = FL_MASK_PIXELKEY
00041 };
00042 
00043 //Internally used only
00044 
00046 typedef struct {
00047     uint8 r;
00048     uint8 g;
00049     uint8 b;
00050     uint8 a;
00051 } Fl_Colormap_Color;
00052 
00054 class Fl_Colormap
00055 {
00056 public:
00057     Fl_Colormap(int cols=0);
00058     ~Fl_Colormap();
00059     void realloc(int cols);
00060     void copy(Fl_Colormap *map);
00061 
00062     // Calculate an 8-bit (3 red, 3 green, 2 blue) dithered palette of colors
00063     void dither_colors(int bitspp);
00064 
00065     // Match an RGB value to a particular palette index
00066     uint8 find_color(uint8 R, uint8 G, uint8 B);
00067 
00068     Fl_Colormap_Color *colors;
00069     int ncolors;
00070 };
00071 
00073 class FL_API Fl_PixelFormat
00074 {
00075 public:
00076     Fl_PixelFormat();
00077     ~Fl_PixelFormat();
00078     void init(int bits_pp, uint32 Rmask, uint32 Gmask, uint32 Bmask, uint32 Amask);
00079     void realloc(int bits_pp, uint32 Rmask, uint32 Gmask, uint32 Bmask, uint32 Amask);
00080     void copy(Fl_PixelFormat *fmt);
00081 
00082     uint32 map_rgb(uint8 r, uint8 g, uint8 b);
00083     uint32 map_rgba(uint8 r, uint8 g, uint8 b, uint8 a);
00084 
00085     void get_rgb(uint32 pixel, uint8 &r, uint8 &g, uint8 &b);
00086     void get_rgba(uint32 pixel, uint8 &r, uint8 &g, uint8 &b, uint8 &a);
00087 
00088     Fl_Colormap *palette;
00089     uint8  bitspp;
00090     uint8  bytespp;
00091 
00092     uint8  Rloss, Rshift;
00093     uint8  Gloss, Gshift;
00094     uint8  Bloss, Bshift;
00095     uint8  Aloss, Ashift;
00096     uint32 Rmask;
00097     uint32 Gmask;
00098     uint32 Bmask;
00099     uint32 Amask;
00100     /* RGB color key information */
00101     uint32 colorkey;
00102     /* Alpha value information (per-surface alpha) */
00103     uint8  alpha;
00104     /* Mask type */
00105     int masktype;
00106 
00107     // Mapping
00108     void invalidate_map();
00109     bool map_this(Fl_PixelFormat *dstfmt);
00110     Fl_PixelFormat *dst;
00111     uint8 *table;
00112     int format_version;
00113     bool identity;
00114 };
00115 
00116 // Blitting flags for Fl_Renderer blit functions:
00117 // Number of blitting flags may grow in future.
00118 #define FL_BLIT_COLOR_KEY     (1<<1) // Blits using colorkey.
00119 #define FL_BLIT_HW_PALETTE    (1<<2) // Blits using system allocated palette
00120 
00122 class Fl_Renderer {
00123 public:
00124     static bool alpha_blit(uint8 *src, Fl_Rect *src_rect, Fl_PixelFormat *src_fmt, int src_pitch,
00125                            uint8 *dst, Fl_Rect *dst_rect, Fl_PixelFormat *fmt_fmt, int dst_pitch, int flags);
00126 
00127     static bool stretch(uint8 *src, int src_bpp, int src_pitch, Fl_Rect *srcrect,
00128                         uint8 *dst, int dst_bpp, int dst_pitch, Fl_Rect *dstrect);
00129 
00130     // General blitting, copies src -> dst, does also conversion
00131     static bool blit(uint8 *src, Fl_Rect *src_rect, Fl_PixelFormat *src_fmt, int src_pitch,
00132                      uint8 *dst, Fl_Rect *dst_rect, Fl_PixelFormat *dst_fmt, int dst_pitch, int flags);
00133 
00134     static bool render_to_pixmap(uint8 *src, Fl_Rect *src_rect, Fl_PixelFormat *src_fmt, int src_pitch,
00135                                  Pixmap dst, Fl_Rect *dst_rect, GC dst_gc, int flags);
00136 
00137     // Returns root/desktop window handle
00138     static Window root_window();
00139 
00140     // Returns data, either from PIXMAP or WINDOW. data is in "desired" format
00141     static uint8 *data_from_pixmap(Pixmap src, Fl_Rect &rect, Fl_PixelFormat *desired);
00142     static uint8 *data_from_window(Window src, Fl_Rect &rect, Fl_PixelFormat *desired);
00143 
00144 #ifndef _WIN32
00145     // Special XWindows method
00146     static XImage *ximage_from_pixmap(Pixmap src, Fl_Rect &rect);
00147 #endif
00148 
00149     static inline int calc_pitch(int bytespp, int width) {
00150         if(!bytespp || !width) return 0;
00151         int pitch = width * bytespp;
00152         return (pitch + 3) & ~3;    /* word aligning */
00153     }
00154 
00155     // Init renderer
00156     static void system_init();
00157     static bool system_inited();
00158 
00159     // Converts to system format.
00160     // If 'hw_surface' is set to true, then system colormap is used if needed.
00161     // NOTE: needed only when drawing to system pixmap!
00162     static uint8 *system_convert(Fl_PixelFormat *src_fmt, Fl_Size *src_size, uint8 *src, bool hw_surface=false);
00163     static Fl_PixelFormat *system_format();
00164 
00165     // Image byte order
00166     static bool big_endian();
00167     static bool lil_endian();
00168 };
00169 
00170 typedef struct
00171 {
00172     uint8 *s_pixels;
00173     int s_width;
00174     int s_height;
00175     int s_skip;
00176 
00177     uint8 *d_pixels;
00178     int d_width;
00179     int d_height;
00180     int d_skip;
00181 
00182     Fl_PixelFormat *src;
00183     uint8 *table;
00184     Fl_PixelFormat *dst;
00185 
00186     bool hw_surface;
00187 } BlitInfo;
00188 
00189 typedef void (*Blit_Function)(BlitInfo *info);
00190 
00191 // Fast pixel modifier color functions:
00192 extern bool fl_format_equal(Fl_PixelFormat *A, Fl_PixelFormat *B);
00193 
00194 /* Load pixel of the specified format from a buffer and get its R-G-B values */
00195 extern void fl_rgb_from_pixel(uint32 pixel, Fl_PixelFormat *fmt, uint8 &r, uint8 &g, uint8 &b);
00196 extern void fl_rgb_from_rgb565(uint16 pixel, uint8 &r, uint8 &g, uint8 &b);
00197 extern void fl_rgb_from_rgb555(uint16 pixel, uint8 &r, uint8 &g, uint8 &b);
00198 extern void fl_rgb_from_rgb888(uint32 pixel, uint8 &r, uint8 &g, uint8 &b);
00199 
00200 extern void fl_rgba_from_pixel(uint32 pixel, Fl_PixelFormat *fmt, uint8 &r, uint8 &g, uint8 &b, uint8 &a);
00201 extern void fl_rgba_from_8888(uint32 pixel, Fl_PixelFormat *fmt, uint8 &r, uint8 &g, uint8 &b, uint8 &a);
00202 extern void fl_rgba_from_rgba8888(uint32 pixel, uint8 &r, uint8 &g, uint8 &b, uint8 &a);
00203 extern void fl_rgba_from_argb8888(uint32 pixel, uint8 &r, uint8 &g, uint8 &b, uint8 &a);
00204 extern void fl_rgba_from_abgr8888(uint32 pixel, uint8 &r, uint8 &g, uint8 &b, uint8 &a);
00205 
00206 /* Assemble R-G-B values into a specified pixel format and store them */
00207 extern void fl_pixel_from_rgb(uint32 &pixel, Fl_PixelFormat *fmt, uint8 r, uint8 g, uint8 b);
00208 extern void fl_rgb888_from_rgb(uint32 &pixel, uint8 r, uint8 g, uint8 b);
00209 extern void fl_rgb555_from_rgb(uint16 &pixel, uint8 r, uint8 g, uint8 b);
00210 extern void fl_rgb565_from_rgb(uint16 &pixel, uint8 r, uint8 g, uint8 b);
00211 
00212 extern void fl_assemble_rgb(uint8 *buf, int bpp, Fl_PixelFormat *fmt, uint8 r, uint8 g, uint8 b);
00213 extern void fl_assemble_rgb_amask(uint8 *buf, int bpp, Fl_PixelFormat *fmt, uint8 r, uint8 g, uint8 b, uint8 Amask);
00214 extern void fl_assemble_rgba(uint8 *buf, int bpp, Fl_PixelFormat *fmt, uint8 r, uint8 g, uint8 b, uint8 a);
00215 
00216 extern void fl_retrieve_rgb_pixel(uint8 *buf, int bpp, uint32 &pixel);
00217 extern void fl_disemble_rgb(uint8 *buf, int bpp, Fl_PixelFormat *fmt, uint32 &pixel, uint8 &R, uint8 &G, uint8 &B);
00218 extern void fl_disemble_rgba(uint8 *buf, int bpp, Fl_PixelFormat *fmt, uint32 &pixel, uint8 &r, uint8 &g, uint8 &b, uint8 &a);
00219 extern void fl_pixel_from_rgba(uint32 &pixel, Fl_PixelFormat *fmt, uint8 r, uint8 g, uint8 b, uint8 a);
00220 
00221 /* Blend the RGB values of two pixels based on a source alpha value */
00222 extern void fl_alpha_blend(uint8 sR, uint8 sG, uint8 sB, uint8 A, uint8 &dR, uint8 &dG, uint8 &dB);
00223 
00224 // Byte swapping functions for EFltk:
00225 extern uint16 fl_swap_16(uint16 d);
00226 extern uint32 fl_swap_32(uint32 d);
00227 
00228 // Endian independ, swaps bytes, if needed. (e.g. big endian machine will swap bytes in 'fl_swap_le16')
00229 extern uint16 fl_swap_le16(uint16 d);
00230 extern uint32 fl_swap_le32(uint32 d);
00231 extern uint16 fl_swap_be16(uint16 d);
00232 extern uint32 fl_swap_be32(uint32 d);
00233 
00234 #endif

Generated on Thu Jul 31 15:33:45 2003 for eFLTK by doxygen1.2.15