Blender  V2.59
BLI_math_color.h
Go to the documentation of this file.
00001 /*
00002  * $Id: BLI_math_color.h 37783 2011-06-24 03:49:56Z campbellbarton $
00003  *
00004  * ***** BEGIN GPL LICENSE BLOCK *****
00005  *
00006  * This program is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU General Public License
00008  * as published by the Free Software Foundation; either version 2
00009  * of the License, or (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software Foundation,
00018  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00019  *
00020  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
00021  * All rights reserved.
00022  *
00023  * The Original Code is: some of this file.
00024  *
00025  * ***** END GPL LICENSE BLOCK *****
00026  * */
00027 
00028 #ifndef BLI_MATH_COLOR_H
00029 #define BLI_MATH_COLOR_H
00030 
00035 #ifdef __cplusplus
00036 extern "C" {
00037 #endif
00038 
00039 /* primaries */
00040 #define BLI_XYZ_SMPTE   0
00041 #define BLI_XYZ_REC709_SRGB     1
00042 #define BLI_XYZ_CIE             2
00043 
00044 /* built-in profiles */
00045 #define BLI_PR_NONE             0
00046 #define BLI_PR_SRGB             1
00047 #define BLI_PR_REC709   2
00048 
00049 /* YCbCr */
00050 #define BLI_YCC_ITU_BT601       0
00051 #define BLI_YCC_ITU_BT709       1
00052 #define BLI_YCC_JFIF_0_255      2
00053         
00054 /******************* Conversion to RGB ********************/
00055 
00056 void hsv_to_rgb(float h, float s, float v, float *r, float *g, float *b);
00057 void hex_to_rgb(char *hexcol, float *r, float *g, float *b);
00058 void yuv_to_rgb(float y, float u, float v, float *lr, float *lg, float *lb);
00059 void ycc_to_rgb(float y, float cb, float cr, float *lr, float *lg, float *lb, int colorspace);
00060 void xyz_to_rgb(float x, float y, float z, float *r, float *g, float *b, int colorspace);
00061 void cpack_to_rgb(unsigned int col, float *r, float *g, float *b);
00062 
00063 /***************** Conversion from RGB ********************/
00064 
00065 void rgb_to_yuv(float r, float g, float b, float *ly, float *lu, float *lv);
00066 void rgb_to_ycc(float r, float g, float b, float *ly, float *lcb, float *lcr, int colorspace);
00067 void rgb_to_hsv(float r, float g, float b, float *lh, float *ls, float *lv);
00068 void rgb_to_hsv_compat(float r, float g, float b, float *lh, float *ls, float *lv);
00069 unsigned int rgb_to_cpack(float r, float g, float b);
00070 unsigned int hsv_to_cpack(float h, float s, float v);
00071 
00072 float rgb_to_grayscale(float rgb[3]);
00073 unsigned char rgb_to_grayscale_byte(unsigned char rgb[3]);
00074 
00075 /***************** Profile Transformations ********************/
00076 
00077 void gamma_correct(float *c, float gamma);
00078 float rec709_to_linearrgb(float c);
00079 float linearrgb_to_rec709(float c);
00080 float srgb_to_linearrgb(float c);
00081 float linearrgb_to_srgb(float c);
00082 void srgb_to_linearrgb_v3_v3(float *col_to, float *col_from);
00083 void linearrgb_to_srgb_v3_v3(float *col_to, float *col_from);
00084 
00085 /* rgba buffer convenience functions */
00086 void srgb_to_linearrgb_rgba_buf(float *col, int tot);
00087 void linearrgb_to_srgb_rgba_buf(float *col, int tot);
00088 void srgb_to_linearrgb_rgba_rgba_buf(float *col_to, float *col_from, int tot);
00089 void linearrgb_to_srgb_rgba_rgba_buf(float *col_to, float *col_from, int tot);
00090         
00091 /************************** Other *************************/
00092 
00093 int constrain_rgb(float *r, float *g, float *b);
00094 void minmax_rgb(short c[3]);
00095 
00096 void rgb_float_set_hue_float_offset(float * rgb, float hue_offset);
00097 void rgb_byte_set_hue_float_offset(unsigned char * rgb, float hue_offset);
00098 
00099 /***************** lift/gamma/gain / ASC-CDL conversion *****************/
00100 
00101 void lift_gamma_gain_to_asc_cdl(float *lift, float *gamma, float *gain, float *offset, float *slope, float *power);
00102 
00103 void rgb_byte_to_float(const unsigned char *in, float *out);
00104 void rgb_float_to_byte(const float *in, unsigned char *out);
00105 
00106 #ifdef __cplusplus
00107 }
00108 #endif
00109 
00110 #endif /* BLI_MATH_COLOR_H */
00111