blender.h

Go to the documentation of this file.
00001 #ifndef BLENDER_H_HEADER_INCLUDED
00002 #define BLENDER_H_HEADER_INCLUDED
00003 
00004 
00005 #ifdef __cplusplus
00006 extern "C" {
00007 #endif
00008 
00009 /****h* libAfterImage/blender.h
00010  * NAME 
00011  * blender
00012  * DESCRIPTION
00013  * Defines implemented methods for ASScanline combining, that could
00014  * be passed to merge_layers() via ASImageLayer structure.
00015  * Also includes functions for colorspace conversion RGB<->HSV and
00016  * RGB<->HLS.
00017  * SEE ALSO
00018  * Functions :
00019  *    Colorspace conversion :
00020  *          rgb2value(), rgb2saturation(), rgb2hue(), rgb2luminance(),
00021  *          rgb2hsv(), rgb2hls(), hsv2rgb(), hls2rgb().
00022  *
00023  *    merge_scanline methods :
00024  *          alphablend_scanlines(), allanon_scanlines(),
00025  *          tint_scanlines(), add_scanlines(), sub_scanlines(),
00026  *          diff_scanlines(), darken_scanlines(), lighten_scanlines(),
00027  *          screen_scanlines(), overlay_scanlines(), hue_scanlines(),
00028  *          saturate_scanlines(), value_scanlines(),
00029  *          colorize_scanlines(), dissipate_scanlines().
00030  *
00031  *    usefull merging function name to function translator :
00032  *          blend_scanlines_name2func()
00033  *
00034  * Other libAfterImage modules :
00035  *          ascmap.h asfont.h asimage.h asvisual.h blender.h export.h
00036  *          import.h transform.h ximage.h
00037  * AUTHOR
00038  * Sasha Vasko <sasha at aftercode dot net>
00039  ******************/
00040 
00041 
00042 struct ASScanline;
00043 
00044 /* it produces  bottom = bottom <merge> top */
00045 typedef void (*merge_scanlines_func)( struct ASScanline *bottom, struct ASScanline *top, int offset);
00046 
00047 /****d* libAfterImage/colorspace
00048  * NAME
00049  * colorspace
00050  * DESCRIPTION
00051  * RGB colorspace: each color is represented as a combination of
00052  * red, green and blue values. Each value can be in 2 formats :
00053  * 8 bit and 24.8 bit. 24.8 bit makes for 32bit value with lower 8 bits
00054  * used as a fraction for better calculation precision.
00055  *
00056  * HSV colorspace: each color is represented as a combination of
00057  * hue, saturation and value. Hue is generally colorizing component where
00058  * value represents brightness.
00059  *
00060  * HLS colorspace: each color is represented as a combination of
00061  * hue, luminance and saturation. It is analogous to HSV with value
00062  * substituted by luminance, except that luminance could be both
00063  * negative and positive.
00064  *
00065  * alpha channel could be added to any of the above colorspaces. alpha
00066  * channel is generally used to define transparentness of the color.
00067  * libAfterImage is using ARGB colorspace as a base colorspace, and
00068  * represents most colors as ARGB32 values or ASScanline scanlines of
00069  * pixels.
00070  ****************/
00071 /****f* libAfterImage/rgb2value()
00072  * NAME
00073  * rgb2value()
00074  * NAME
00075  * rgb2saturation()
00076  * NAME
00077  * rgb2hue()
00078  * NAME
00079  * rgb2luminance()
00080  * SYNOPSIS
00081  * CARD32 rgb2value( CARD32 red, CARD32 green, CARD32 blue );
00082  * CARD32 rgb2saturation( CARD32 red, CARD32 green, CARD32 blue );
00083  * CARD32 rgb2hue( CARD32 red, CARD32 green, CARD32 blue );
00084  * CARD32 rgb2luminance (CARD32 red, CARD32 green, CARD32 blue );
00085  * INPUTS
00086  * red   - 32 bit value, 16 lower bits of which represent red channel
00087  * green - 32 bit value, 16 lower bits of which represent green channel
00088  * blue  - 32 bit value, 16 lower bits of which represent blue channel
00089  * RETURN VALUE
00090  * 32 bit value, 16 lower bits of which represent value, saturation, hue,
00091  * or luminance respectively.
00092  * DESCRIPTION
00093  * This functions translate RGB color into respective coordinates of
00094  * HSV and HLS colorspaces.
00095  * Returned hue values are in 16bit format. To translate it to and from
00096  * conventional 0-360 degree range, please use :
00097  * degrees2hue16() - converts conventional hue in 0-360 range into hue16
00098  * hue162degree()  - converts 16bit hue value into conventional degrees.
00099  ****************/
00100 #define HUE16_RANGE             (85<<7)
00101 #define MAX_HUE16                       0x0000FEFF
00102 #define MIN_HUE16                       0x00000001
00103 int normalize_degrees_val( int degrees );
00104 CARD32 degrees2hue16( int degrees );
00105 int    hue162degrees( CARD32 hue );
00106 #define percent2val16(p)        ((((CARD32)(p))*0x00FFFF)/100)
00107 #define val162percent(p)        ((((CARD32)(p))*100)/0x00FF00)
00108 
00109 
00110 CARD32 rgb2value( CARD32 red, CARD32 green, CARD32 blue );
00111 CARD32 rgb2saturation( CARD32 red, CARD32 green, CARD32 blue );
00112 CARD32 rgb2hue( CARD32 red, CARD32 green, CARD32 blue );
00113 CARD32 rgb2luminance (CARD32 red, CARD32 green, CARD32 blue );
00114 /****f* libAfterImage/rgb2hsv()
00115  * NAME
00116  * rgb2hsv()
00117  * NAME
00118  * rgb2hls()
00119  * SYNOPSIS
00120  * CARD32 rgb2hsv( CARD32 red, CARD32 green, CARD32 blue,
00121  *                 CARD32 *saturation, CARD32 *value );
00122  * CARD32 rgb2hls( CARD32 red, CARD32 green, CARD32 blue,
00123  *                 CARD32 *luminance, CARD32 *saturation );
00124  * INPUTS
00125  * red   - 32 bit value, 16 lower bits of which represent red channel
00126  * green - 32 bit value, 16 lower bits of which represent green channel
00127  * blue  - 32 bit value, 16 lower bits of which represent blue channel
00128  * RETURN VALUE
00129  * 32 bit value, 16 lower bits of which represent hue.
00130  * 32bit value pointed to by luminance, value and saturation will be set
00131  * respectively to color luminance, value and saturation.
00132  * DESCRIPTION
00133  * This functions translate RGB color into full set of HSV and HLS
00134  * coordinates at once. These functions work faster then separate
00135  * translation into each channel.
00136  ****************/
00137 CARD32 rgb2hsv( CARD32 red, CARD32 green, CARD32 blue, CARD32 *saturation, CARD32 *value );
00138 CARD32 rgb2hls (CARD32 red, CARD32 green, CARD32 blue, CARD32 *luminance, CARD32 *saturation );
00139 /****f* libAfterImage/hsv2rgb()
00140  * NAME
00141  * hsv2rgb()
00142  * NAME
00143  * hls2rgb()
00144  * SYNOPSIS
00145  * void hsv2rgb( CARD32 hue, CARD32 saturation, CARD32 value,
00146  *               CARD32 *red, CARD32 *green, CARD32 *blue);
00147  * void hls2rgb( CARD32 hue, CARD32 luminance, CARD32 saturation,
00148  *               CARD32 *red, CARD32 *green, CARD32 *blue);
00149  * INPUTS
00150  * hue        - 32 bit value, 16 lower bits of which represent hue.
00151  * saturation - 32 bit value, 16 lower bits of which represent saturation.
00152  * value      - 32 bit value, 16 lower bits of which represent value.
00153  * luminance  - 32 bit value, 16 lower bits of which represent luminance.
00154  * RETURN VALUE
00155  * 32bit value pointed to by red, green and blue will be set
00156  * respectively to RGB color channels.
00157  * DESCRIPTION
00158  * This functions performs reverse translation from HSV and HSL to
00159  * RGB color
00160  ****************/
00161 void hsv2rgb (CARD32 hue, CARD32 saturation, CARD32 value, CARD32 *red, CARD32 *green, CARD32 *blue);
00162 void hls2rgb (CARD32 hue, CARD32 luminance, CARD32 saturation, CARD32 *red, CARD32 *green, CARD32 *blue);
00163 
00164 /* scanline blending                                                                                                     */
00165 /****f* libAfterImage/merge_scanline
00166  * NAME
00167  * alphablend_scanlines() - combines top and bottom RGB components based
00168  *                        on alpha channel value:
00169  *                        bottom = bottom*(255-top_alpha)+top*top_alpha;
00170  * NAME
00171  * allanon_scanlines()  - averages each pixel between two scanlines.
00172  *                        This method has been first implemented by
00173  *                        Ethan Fisher aka allanon as mode 130:
00174  *                        bottom = (bottom+top)/2;
00175  * NAME
00176  * tint_scanlines()     - tints bottom scanline with top scanline( with
00177  *                        saturation to prevent overflow) :
00178  *                        bottom = (bottom*(top/2))/32768;
00179  * NAME
00180  * add_scanlines()      - adds top scanline to bottom scanline with
00181  *                        saturation to prevent overflow:
00182  *                        bottom = bottom+top;
00183  * NAME
00184  * sub_scanlines()      - substrates top scanline from bottom scanline
00185  *                        with saturation to prevent overflow:
00186  *                        bottom = bottom-top;
00187  * NAME
00188  * diff_scanlines()     - for each pixel calculates absolute difference
00189  *                        between bottom and top color value :
00190  *                        bottom = (bottom>top)?bottom-top:top-bottom;
00191  * NAME
00192  * darken_scanlines()   - substitutes each pixel with minimum color
00193  *                        value of top and bottom :
00194  *                        bottom = (bottom>top)?top:bottom;
00195  * NAME
00196  * lighten_scanlines()  - substitutes each pixel with maximum color
00197  *                        value of top and bottom :
00198  *                        bottom = (bottom>top)?bottom:top;
00199  * NAME
00200  * screen_scanlines()   - some wierd merging algorithm taken from GIMP;
00201  * NAME
00202  * overlay_scanlines()  - some wierd merging algorithm taken from GIMP;
00203  * NAME
00204  * hue_scanlines()      - substitute hue of bottom scanline with hue of
00205  *                        top scanline;
00206  * NAME
00207  * saturate_scanlines() - substitute saturation of bottom scanline with
00208  *                        the saturation of top scanline;
00209  * NAME
00210  * value_scanlines()    - substitute value of bottom scanline with
00211  *                        the value of top scanline;
00212  * NAME
00213  * colorize_scanlines() - combine luminance of bottom scanline with hue
00214  *                        and saturation of top scanline;
00215  * NAME
00216  * dissipate_scanlines()- randomly alpha-blend bottom and top scanlines,
00217  *                        using alpha value of top scanline as a
00218  *                        threshold for random values.
00219  * SYNOPSIS
00220  * void alphablend_scanlines( ASScanline *bottom, ASScanline *top, int );
00221  * void allanon_scanlines   ( ASScanline *bottom, ASScanline *top, int );
00222  * void tint_scanlines      ( ASScanline *bottom, ASScanline *top, int );
00223  * void add_scanlines       ( ASScanline *bottom, ASScanline *top, int );
00224  * void sub_scanlines       ( ASScanline *bottom, ASScanline *top, int );
00225  * void diff_scanlines      ( ASScanline *bottom, ASScanline *top, int );
00226  * void darken_scanlines    ( ASScanline *bottom, ASScanline *top, int );
00227  * void lighten_scanlines   ( ASScanline *bottom, ASScanline *top, int );
00228  * void screen_scanlines    ( ASScanline *bottom, ASScanline *top, int );
00229  * void overlay_scanlines   ( ASScanline *bottom, ASScanline *top, int );
00230  * void hue_scanlines       ( ASScanline *bottom, ASScanline *top, int );
00231  * void saturate_scanlines  ( ASScanline *bottom, ASScanline *top, int );
00232  * void value_scanlines     ( ASScanline *bottom, ASScanline *top, int );
00233  * void colorize_scanlines  ( ASScanline *bottom, ASScanline *top, int );
00234  * void dissipate_scanlines ( ASScanline *bottom, ASScanline *top, int );
00235  * INPUTS
00236  * bottom   - pointer to the ASScanline that will be overalayed
00237  * top      - pointer to ASScanline that will overlay bottom.
00238  * DESCRIPTION
00239  * This functions accept 2 scanlines as an arguments stored in
00240  * ASScanline structures with data in 24.8 format. Merging operation is
00241  * performed on these scanlines and result is stored in bottom
00242  * ASScanline.
00243  * The following are merging methods used in each function :
00244  *
00245  ****************/
00246 void alphablend_scanlines( struct ASScanline *bottom, struct ASScanline *top, int offset );
00247 void allanon_scanlines( struct ASScanline *bottom, struct ASScanline *top, int offset );
00248 void tint_scanlines( struct ASScanline *bottom, struct ASScanline *top, int offset );
00249 void add_scanlines( struct ASScanline *bottom, struct ASScanline *top, int offset );
00250 /* substruction with saturation : */
00251 void sub_scanlines( struct ASScanline *bottom, struct ASScanline *top, int offset );
00252 /* absolute pixel value difference : */
00253 void diff_scanlines( struct ASScanline *bottom, struct ASScanline *top, int offset );
00254 /* darkest of the two makes it in : */
00255 void darken_scanlines( struct ASScanline *bottom, struct ASScanline *top, int offset );
00256 /* lightest of the two makes it in : */
00257 void lighten_scanlines( struct ASScanline *bottom, struct ASScanline *top, int offset );
00258 /* guess what this one does - I could not :) */
00259 void screen_scanlines( struct ASScanline *bottom, struct ASScanline *top, int offset );
00260 /* somehow overlays bottom with top : */
00261 void overlay_scanlines( struct ASScanline *bottom, struct ASScanline *top, int offset );
00262 void hue_scanlines( struct ASScanline *bottom, struct ASScanline *top, int offset );
00263 void saturate_scanlines( struct ASScanline *bottom, struct ASScanline *top, int offset );
00264 void value_scanlines( struct ASScanline *bottom, struct ASScanline *top, int offset );
00265 void colorize_scanlines( struct ASScanline *bottom, struct ASScanline *top, int offset );
00266 void dissipate_scanlines( struct ASScanline *bottom, struct ASScanline *top, int offset );
00267 
00268 /****f* libAfterImage/blend_scanlines_name2func()
00269  * NAME
00270  * blend_scanlines_name2func()
00271  * NAME
00272  * list_scanline_merging()
00273  * SYNOPSIS
00274  * merge_scanlines_func blend_scanlines_name2func( const char *name );
00275  * void list_scanline_merging(FILE* stream, const char *format);
00276  * INPUTS
00277  * name - string, identifying scanline merging function.
00278  * RETURN VALUE
00279  * returns pointer to the scanline merging function on succes.
00280  * NULL on failure.
00281  * DESCRIPTION
00282  * blend_scanlines_name2func() will strip leading whitespaces off of
00283  * the supplied name, and then will attempt to match it against the list
00284  * of names of merging functions. It will then return pointer to the
00285  * function with matching name.
00286  * list_scanline_merging() simply prints out description of implemented
00287  * blending/merging methods onto the supplied stream, in supplied format.
00288  * Format must include 2 string specs, like so : "%s - %s" where first
00289  * one will be substituted to short method name, and second - description
00290  ****************/
00291 merge_scanlines_func blend_scanlines_name2func( const char *name );
00292 void list_scanline_merging(FILE* stream, const char *format);
00293 
00294 #ifdef __cplusplus
00295 }
00296 #endif
00297 
00298 #endif             /* BLENDER_H_HEADER_INCLUDED */
00299 

Generated on Tue Jul 5 14:13:27 2011 for ROOT_528-00b_version by  doxygen 1.5.1