7 * ***** BEGIN GPL LICENSE BLOCK *****
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software Foundation,
21 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
24 * All rights reserved.
26 * The Original Code is: all of this file.
28 * Contributor(s): none yet.
30 * ***** END GPL LICENSE BLOCK *****
36 #include "MEM_guardedalloc.h"
38 #include "DNA_curve_types.h"
39 #include "DNA_material_types.h"
40 #include "DNA_mesh_types.h"
41 #include "DNA_meta_types.h"
42 #include "DNA_node_types.h"
43 #include "DNA_object_types.h"
44 #include "DNA_scene_types.h"
45 #include "DNA_texture_types.h"
46 #include "DNA_userdef_types.h"
48 #include "BLI_blenlib.h"
49 #include "BLI_arithb.h"
51 #include "BKE_animsys.h"
52 #include "BKE_blender.h"
53 #include "BKE_displist.h"
54 #include "BKE_global.h"
55 #include "BKE_icons.h"
56 #include "BKE_library.h"
58 #include "BKE_material.h"
61 #include "BKE_utildefines.h"
63 #ifndef DISABLE_PYTHON
64 #include "BPY_extern.h"
67 #include "GPU_material.h"
69 /* used in UI and render */
72 /* called on startup, creator.c */
73 void init_def_material(void)
75 init_material(&defmaterial);
78 /* not material itself */
79 void free_material(Material *ma)
84 #ifndef DISABLE_PYTHON
85 BPY_free_scriptlink(&ma->scriptlink);
88 for(a=0; a<MAX_MTEX; a++) {
90 if(mtex && mtex->tex) mtex->tex->id.us--;
91 if(mtex) MEM_freeN(mtex);
94 if(ma->ramp_col) MEM_freeN(ma->ramp_col);
95 if(ma->ramp_spec) MEM_freeN(ma->ramp_spec);
97 BKE_free_animdata((ID *)ma);
99 BKE_previewimg_free(&ma->preview);
100 BKE_icon_delete((struct ID*)ma);
103 /* is no lib link block, but material extension */
105 ntreeFreeTree(ma->nodetree);
106 MEM_freeN(ma->nodetree);
109 if(ma->gpumaterial.first)
110 GPU_material_free(ma);
113 void init_material(Material *ma)
115 ma->r= ma->g= ma->b= ma->ref= 0.8;
116 ma->specr= ma->specg= ma->specb= 1.0;
117 ma->mirr= ma->mirg= ma->mirb= 1.0;
121 ma->spec= ma->hasize= 0.5;
123 ma->starc= ma->ringc= 4;
126 ma->flaresize= ma->subsize= 1.0;
139 ma->strand_sta= ma->strand_end= 1.0f;
143 ma->ray_depth_tra= 2;
144 ma->fresnel_mir= 0.0;
145 ma->fresnel_tra= 0.0;
146 ma->fresnel_tra_i= 1.25;
147 ma->fresnel_mir_i= 1.25;
150 ma->shad_alpha= 1.0f;
152 ma->gloss_mir = ma->gloss_tra= 1.0;
153 ma->samp_gloss_mir = ma->samp_gloss_tra= 18;
154 ma->adapt_thresh_mir = ma->adapt_thresh_tra = 0.005;
156 ma->fadeto_mir = MA_RAYMIR_FADETOSKY;
158 ma->rampfac_col= 1.0;
159 ma->rampfac_spec= 1.0;
160 ma->pr_lamp= 3; /* two lamps, is bits */
161 ma->pr_type= MA_SPHERE;
163 ma->sss_radius[0]= 1.0f;
164 ma->sss_radius[1]= 1.0f;
165 ma->sss_radius[2]= 1.0f;
166 ma->sss_col[0]= 0.8f;
167 ma->sss_col[1]= 0.8f;
168 ma->sss_col[2]= 0.8f;
169 ma->sss_error= 0.05f;
172 ma->sss_colfac= 1.0f;
173 ma->sss_texfac= 0.0f;
177 ma->mode= MA_TRACEBLE|MA_SHADBUF|MA_SHADOW|MA_RADIO|MA_RAYBIAS|MA_TANGENT_STR;
182 Material *add_material(char *name)
186 ma= alloc_libblock(&G.main->mat, ID_MA, name);
193 Material *copy_material(Material *ma)
198 man= copy_libblock(ma);
200 #if 0 // XXX old animation system
201 id_us_plus((ID *)man->ipo);
202 #endif // XXX old animation system
203 id_us_plus((ID *)man->group);
206 for(a=0; a<MAX_MTEX; a++) {
208 man->mtex[a]= MEM_mallocN(sizeof(MTex), "copymaterial");
209 memcpy(man->mtex[a], ma->mtex[a], sizeof(MTex));
210 id_us_plus((ID *)man->mtex[a]->tex);
214 #ifndef DISABLE_PYTHON
215 BPY_copy_scriptlink(&ma->scriptlink);
218 if(ma->ramp_col) man->ramp_col= MEM_dupallocN(ma->ramp_col);
219 if(ma->ramp_spec) man->ramp_spec= MEM_dupallocN(ma->ramp_spec);
221 if (ma->preview) man->preview = BKE_previewimg_copy(ma->preview);
224 man->nodetree= ntreeCopyTree(ma->nodetree, 0); /* 0 == full new tree */
227 man->gpumaterial.first= man->gpumaterial.last= NULL;
232 void make_local_material(Material *ma)
239 int a, local=0, lib=0;
241 /* - only lib users: do nothing
242 * - only local users: set flag
246 if(ma->id.lib==0) return;
249 ma->id.flag= LIB_LOCAL;
250 new_id(0, (ID *)ma, 0);
251 for(a=0; a<MAX_MTEX; a++) {
252 if(ma->mtex[a]) id_lib_extern((ID *)ma->mtex[a]->tex);
259 ob= G.main->object.first;
262 for(a=0; a<ob->totcol; a++) {
264 if(ob->id.lib) lib= 1;
272 me= G.main->mesh.first;
275 for(a=0; a<me->totcol; a++) {
277 if(me->id.lib) lib= 1;
285 cu= G.main->curve.first;
288 for(a=0; a<cu->totcol; a++) {
290 if(cu->id.lib) lib= 1;
298 mb= G.main->mball.first;
301 for(a=0; a<mb->totcol; a++) {
303 if(mb->id.lib) lib= 1;
311 if(local && lib==0) {
313 ma->id.flag= LIB_LOCAL;
315 for(a=0; a<MAX_MTEX; a++) {
316 if(ma->mtex[a]) id_lib_extern((ID *)ma->mtex[a]->tex);
319 new_id(0, (ID *)ma, 0);
321 else if(local && lib) {
323 man= copy_material(ma);
327 ob= G.main->object.first;
330 for(a=0; a<ob->totcol; a++) {
343 me= G.main->mesh.first;
346 for(a=0; a<me->totcol; a++) {
359 cu= G.main->curve.first;
362 for(a=0; a<cu->totcol; a++) {
375 mb= G.main->mball.first;
378 for(a=0; a<mb->totcol; a++) {
393 Material ***give_matarar(Object *ob)
399 if(ob->type==OB_MESH) {
403 else if ELEM3(ob->type, OB_CURVE, OB_FONT, OB_SURF) {
407 else if(ob->type==OB_MBALL) {
414 short *give_totcolp(Object *ob)
420 if(ob->type==OB_MESH) {
422 return &(me->totcol);
424 else if ELEM3(ob->type, OB_CURVE, OB_FONT, OB_SURF) {
426 return &(cu->totcol);
428 else if(ob->type==OB_MBALL) {
430 return &(mb->totcol);
435 Material *give_current_material(Object *ob, int act)
437 Material ***matarar, *ma;
440 if(ob==NULL) return NULL;
442 /* if object cannot have material, totcolp==NULL */
443 totcolp= give_totcolp(ob);
444 if(totcolp==NULL || ob->totcol==0) return NULL;
446 if(act>ob->totcol) act= ob->totcol;
447 else if(act<=0) act= 1;
449 if(ob->matbits[act-1]) { /* in object */
454 /* check for inconsistancy */
455 if(*totcolp < ob->totcol)
456 ob->totcol= *totcolp;
457 if(act>ob->totcol) act= ob->totcol;
459 matarar= give_matarar(ob);
461 if(matarar && *matarar) ma= (*matarar)[act-1];
469 ID *material_from(Object *ob, int act)
474 if(ob->totcol==0) return ob->data;
477 if(ob->matbits[act-1]) return (ID *)ob;
478 else return ob->data;
481 /* GS reads the memory pointed at in a specific ordering. There are,
482 * however two definitions for it. I have jotted them down here, both,
483 * but I think the first one is actually used. The thing is that
484 * big-endian systems might read this the wrong way round. OTOH, we
485 * constructed the IDs that are read out with this macro explicitly as
486 * well. I expect we'll sort it out soon... */
489 #define GS(a) (*((short *)(a)))
491 /* from misc_util: flip the bytes from x */
492 /* #define GS(x) (((unsigned char *)(x))[0] << 8 | ((unsigned char *)(x))[1]) */
494 void test_object_materials(ID *id)
496 /* make the ob mat-array same size as 'ob->data' mat-array */
507 if( GS(id->name)==ID_ME ) {
511 else if( GS(id->name)==ID_CU ) {
515 else if( GS(id->name)==ID_MB ) {
521 ob= G.main->object.first;
529 MEM_freeN(ob->matbits);
534 else if(ob->totcol<totcol) {
535 newmatar= MEM_callocN(sizeof(void *)*totcol, "newmatar");
536 newmatbits= MEM_callocN(sizeof(char)*totcol, "newmatbits");
538 memcpy(newmatar, ob->mat, sizeof(void *)*ob->totcol);
539 memcpy(newmatbits, ob->matbits, sizeof(char)*ob->totcol);
541 MEM_freeN(ob->matbits);
544 ob->matbits= newmatbits;
547 if(ob->totcol && ob->actcol==0) ob->actcol= 1;
548 if(ob->actcol>ob->totcol) ob->actcol= ob->totcol;
555 void assign_material(Object *ob, Material *ma, int act)
557 Material *mao, **matar, ***matarar;
561 if(act>MAXMAT) return;
566 totcolp= give_totcolp(ob);
567 matarar= give_matarar(ob);
569 if(totcolp==0 || matarar==0) return;
572 matar= MEM_callocN(sizeof(void *)*act, "matarray1");
575 memcpy(matar, *matarar, sizeof(void *)*(*totcolp));
583 if(act > ob->totcol) {
584 matar= MEM_callocN(sizeof(void *)*act, "matarray2");
585 matbits= MEM_callocN(sizeof(char)*act, "matbits1");
587 memcpy(matar, ob->mat, sizeof(void *)*( ob->totcol ));
588 memcpy(matbits, ob->matbits, sizeof(char)*(*totcolp));
590 MEM_freeN(ob->matbits);
593 ob->matbits= matbits;
596 /* copy object/mesh linking, or assign based on userpref */
598 ob->matbits[act-1]= ob->matbits[ob->actcol-1];
600 ob->matbits[act-1]= (U.flag & USER_MAT_ON_OB)? 1: 0;
605 if(ob->matbits[act-1]) { /* in object */
607 if(mao) mao->id.us--;
611 mao= (*matarar)[act-1];
612 if(mao) mao->id.us--;
613 (*matarar)[act-1]= ma;
617 id_us_plus((ID *)ma);
618 test_object_materials(ob->data);
621 int find_material_index(Object *ob, Material *ma)
626 if(ma==NULL) return 0;
628 totcolp= give_totcolp(ob);
629 matarar= give_matarar(ob);
631 if(totcolp==NULL || matarar==NULL) return 0;
633 for(a=0; a<*totcolp; a++)
634 if((*matarar)[a]==ma)
641 void object_add_material_slot(Object *ob)
646 if(ob->totcol>=MAXMAT) return;
648 ma= give_current_material(ob, ob->actcol);
650 assign_material(ob, ma, ob->totcol+1);
651 ob->actcol= ob->totcol;
654 static void do_init_render_material(Material *ma, int r_mode, float *amb)
657 int a, needuv=0, needtang=0;
659 if(ma->flarec==0) ma->flarec= 1;
661 /* add all texcoflags from mtex, texco and mapto were cleared in advance */
662 for(a=0; a<MAX_MTEX; a++) {
664 /* separate tex switching */
665 if(ma->septex & (1<<a)) continue;
668 if(mtex && mtex->tex && (mtex->tex->type | (mtex->tex->use_nodes && mtex->tex->nodetree) )) {
670 ma->texco |= mtex->texco;
671 ma->mapto |= mtex->mapto;
673 if ELEM3(mtex->tex->type, TEX_IMAGE, TEX_PLUGIN, TEX_ENVMAP) ma->texco |= TEXCO_OSA;
676 if(ma->texco & (TEXCO_ORCO|TEXCO_REFL|TEXCO_NORM|TEXCO_STRAND|TEXCO_STRESS)) needuv= 1;
677 else if(ma->texco & (TEXCO_GLOB|TEXCO_UV|TEXCO_OBJECT|TEXCO_SPEED)) needuv= 1;
678 else if(ma->texco & (TEXCO_LAVECTOR|TEXCO_VIEW|TEXCO_STICKY)) needuv= 1;
680 if((ma->mapto & MAP_NORM) && (mtex->normapspace == MTEX_NSPACE_TANGENT))
685 if(needtang) ma->mode |= MA_NORMAP_TANG;
686 else ma->mode &= ~MA_NORMAP_TANG;
689 if(ma->mode & MA_RADIO) needuv= 1;
691 if(ma->mode & (MA_VERTEXCOL|MA_VERTEXCOLP|MA_FACETEXTURE)) {
693 if(r_mode & R_OSA) ma->texco |= TEXCO_OSA; /* for texfaces */
695 if(needuv) ma->texco |= NEED_UV;
697 /* since the raytracer doesnt recalc O structs for each ray, we have to preset them all */
698 if(r_mode & R_RAYTRACE) {
699 if(ma->mode & (MA_RAYMIRROR|MA_RAYTRANSP|MA_SHADOW_TRA)) {
700 ma->texco |= NEED_UV|TEXCO_ORCO|TEXCO_REFL|TEXCO_NORM;
701 if(r_mode & R_OSA) ma->texco |= TEXCO_OSA;
706 ma->ambr= ma->amb*amb[0];
707 ma->ambg= ma->amb*amb[1];
708 ma->ambb= ma->amb*amb[2];
710 /* will become or-ed result of all node modes */
711 ma->mode_l= ma->mode;
712 ma->mode_l &= ~MA_SHLESS;
714 if(ma->strand_surfnor > 0.0f)
715 ma->mode_l |= MA_STR_SURFDIFF;
718 static void init_render_nodetree(bNodeTree *ntree, Material *basemat, int r_mode, float *amb)
722 for(node=ntree->nodes.first; node; node= node->next) {
724 if(GS(node->id->name)==ID_MA) {
725 Material *ma= (Material *)node->id;
727 do_init_render_material(ma, r_mode, amb);
728 basemat->texco |= ma->texco;
729 basemat->mode_l |= ma->mode_l;
732 else if(node->type==NODE_GROUP)
733 init_render_nodetree((bNodeTree *)node->id, basemat, r_mode, amb);
736 /* parses the geom+tex nodes */
737 ntreeShaderGetTexcoMode(ntree, r_mode, &basemat->texco, &basemat->mode_l);
740 void init_render_material(Material *mat, int r_mode, float *amb)
743 do_init_render_material(mat, r_mode, amb);
745 if(mat->nodetree && mat->use_nodes) {
746 init_render_nodetree(mat->nodetree, mat, r_mode, amb);
748 ntreeBeginExecTree(mat->nodetree); /* has internal flag to detect it only does it once */
752 void init_render_materials(int r_mode, float *amb)
756 /* clear these flags before going over materials, to make sure they
757 * are cleared only once, otherwise node materials contained in other
758 * node materials can go wrong */
759 for(ma= G.main->mat.first; ma; ma= ma->id.next) {
766 /* two steps, first initialize, then or the flags for layers */
767 for(ma= G.main->mat.first; ma; ma= ma->id.next) {
768 /* is_used flag comes back in convertblender.c */
769 ma->flag &= ~MA_IS_USED;
771 init_render_material(ma, r_mode, amb);
774 do_init_render_material(&defmaterial, r_mode, amb);
777 /* only needed for nodes now */
778 void end_render_material(Material *mat)
780 if(mat && mat->nodetree && mat->use_nodes)
781 ntreeEndExecTree(mat->nodetree); /* has internal flag to detect it only does it once */
784 void end_render_materials(void)
787 for(ma= G.main->mat.first; ma; ma= ma->id.next)
789 end_render_material(ma);
792 static int material_in_nodetree(bNodeTree *ntree, Material *mat)
796 for(node=ntree->nodes.first; node; node= node->next) {
797 if(node->id && GS(node->id->name)==ID_MA) {
798 if(node->id==(ID*)mat)
801 else if(node->type==NODE_GROUP)
802 if(material_in_nodetree((bNodeTree*)node->id, mat))
809 int material_in_material(Material *parmat, Material *mat)
813 else if(parmat->nodetree && parmat->use_nodes)
814 return material_in_nodetree(parmat->nodetree, mat);
819 /* ****************** */
821 char colname_array[125][20]= {
822 "Black","DarkRed","HalfRed","Red","Red",
823 "DarkGreen","DarkOlive","Brown","Chocolate","OrangeRed",
824 "HalfGreen","GreenOlive","DryOlive","Goldenrod","DarkOrange",
825 "LightGreen","Chartreuse","YellowGreen","Yellow","Gold",
826 "Green","LawnGreen","GreenYellow","LightOlive","Yellow",
827 "DarkBlue","DarkPurple","HotPink","VioletPink","RedPink",
828 "SlateGray","DarkGrey","PalePurple","IndianRed","Tomato",
829 "SeaGreen","PaleGreen","GreenKhaki","LightBrown","LightSalmon",
830 "SpringGreen","PaleGreen","MediumOlive","YellowBrown","LightGold",
831 "LightGreen","LightGreen","LightGreen","GreenYellow","PaleYellow",
832 "HalfBlue","DarkSky","HalfMagenta","VioletRed","DeepPink",
833 "SteelBlue","SkyBlue","Orchid","LightHotPink","HotPink",
834 "SeaGreen","SlateGray","MediumGrey","Burlywood","LightPink",
835 "SpringGreen","Aquamarine","PaleGreen","Khaki","PaleOrange",
836 "SpringGreen","SeaGreen","PaleGreen","PaleWhite","YellowWhite",
837 "LightBlue","Purple","MediumOrchid","Magenta","Magenta",
838 "RoyalBlue","SlateBlue","MediumOrchid","Orchid","Magenta",
839 "DeepSkyBlue","LightSteelBlue","LightSkyBlue","Violet","LightPink",
840 "Cyan","DarkTurquoise","SkyBlue","Grey","Snow",
841 "Mint","Mint","Aquamarine","MintCream","Ivory",
842 "Blue","Blue","DarkMagenta","DarkOrchid","Magenta",
843 "SkyBlue","RoyalBlue","LightSlateBlue","MediumOrchid","Magenta",
844 "DodgerBlue","SteelBlue","MediumPurple","PalePurple","Plum",
845 "DeepSkyBlue","PaleBlue","LightSkyBlue","PalePurple","Thistle",
846 "Cyan","ColdBlue","PaleTurquoise","GhostWhite","White"
849 void automatname(Material *ma)
855 if(ma->mode & MA_SHLESS) ref= 1.0;
858 r= (int)(4.99*(ref*ma->r));
859 g= (int)(4.99*(ref*ma->g));
860 b= (int)(4.99*(ref*ma->b));
863 new_id(&G.main->mat, (ID *)ma, colname_array[nr]);
868 void object_remove_material_slot(Object *ob)
870 Material *mao, ***matarar;
877 if(ob==NULL || ob->totcol==0) return;
879 /* take a mesh/curve/mball as starting point, remove 1 index,
880 * AND with all objects that share the ob->data
882 * after that check indices in mesh/curve/mball!!!
885 totcolp= give_totcolp(ob);
886 matarar= give_matarar(ob);
888 /* we delete the actcol */
890 mao= (*matarar)[ob->actcol-1];
891 if(mao) mao->id.us--;
894 for(a=ob->actcol; a<ob->totcol; a++)
895 (*matarar)[a-1]= (*matarar)[a];
904 obt= G.main->object.first;
907 if(obt->data==ob->data) {
909 /* WATCH IT: do not use actcol from ob or from obt (can become zero) */
910 mao= obt->mat[actcol-1];
911 if(mao) mao->id.us--;
913 for(a=actcol; a<obt->totcol; a++) {
914 obt->mat[a-1]= obt->mat[a];
915 obt->matbits[a-1]= obt->matbits[a];
918 if(obt->actcol > obt->totcol) obt->actcol= obt->totcol;
922 MEM_freeN(obt->matbits);
930 /* check indices from mesh */
932 if(ob->type==OB_MESH) {
933 Mesh *me= get_mesh(ob);
934 mesh_delete_material_index(me, actcol-1);
935 freedisplist(&ob->disp);
937 else if ELEM(ob->type, OB_CURVE, OB_SURF) {
942 if(nu->mat_nr && nu->mat_nr>=actcol-1) {
944 if (ob->type == OB_CURVE) nu->charidx--;
948 freedisplist(&ob->disp);
953 /* r g b = current value, col = new value, fac==0 is no change */
954 /* if g==NULL, it only does r channel */
955 void ramp_blend(int type, float *r, float *g, float *b, float fac, float *col)
957 float tmp, facm= 1.0-fac;
961 *r = facm*(*r) + fac*col[0];
963 *g = facm*(*g) + fac*col[1];
964 *b = facm*(*b) + fac*col[2];
975 *r *= (facm + fac*col[0]);
977 *g *= (facm + fac*col[1]);
978 *b *= (facm + fac*col[2]);
982 *r = 1.0 - (facm + fac*(1.0 - col[0])) * (1.0 - *r);
984 *g = 1.0 - (facm + fac*(1.0 - col[1])) * (1.0 - *g);
985 *b = 1.0 - (facm + fac*(1.0 - col[2])) * (1.0 - *b);
988 case MA_RAMP_OVERLAY:
990 *r *= (facm + 2.0f*fac*col[0]);
992 *r = 1.0 - (facm + 2.0f*fac*(1.0 - col[0])) * (1.0 - *r);
995 *g *= (facm + 2.0f*fac*col[1]);
997 *g = 1.0 - (facm + 2.0f*fac*(1.0 - col[1])) * (1.0 - *g);
999 *b *= (facm + 2.0f*fac*col[2]);
1001 *b = 1.0 - (facm + 2.0f*fac*(1.0 - col[2])) * (1.0 - *b);
1013 *r = facm*(*r) + fac*(*r)/col[0];
1016 *g = facm*(*g) + fac*(*g)/col[1];
1018 *b = facm*(*b) + fac*(*b)/col[2];
1022 *r = facm*(*r) + fac*fabs(*r-col[0]);
1024 *g = facm*(*g) + fac*fabs(*g-col[1]);
1025 *b = facm*(*b) + fac*fabs(*b-col[2]);
1030 if(tmp < *r) *r= tmp;
1033 if(tmp < *g) *g= tmp;
1035 if(tmp < *b) *b= tmp;
1040 if(tmp > *r) *r= tmp;
1043 if(tmp > *g) *g= tmp;
1045 if(tmp > *b) *b= tmp;
1052 tmp = 1.0 - fac*col[0];
1055 else if ((tmp = (*r) / tmp)> 1.0)
1062 tmp = 1.0 - fac*col[1];
1065 else if ((tmp = (*g) / tmp) > 1.0 )
1071 tmp = 1.0 - fac*col[2];
1074 else if ((tmp = (*b) / tmp) > 1.0 )
1084 tmp = facm + fac*col[0];
1088 else if (( tmp = (1.0 - (1.0 - (*r)) / tmp )) < 0.0)
1096 tmp = facm + fac*col[1];
1099 else if (( tmp = (1.0 - (1.0 - (*g)) / tmp )) < 0.0 )
1106 tmp = facm + fac*col[2];
1109 else if (( tmp = (1.0 - (1.0 - (*b)) / tmp )) < 0.0 )
1120 float colH,colS,colV;
1121 float tmpr,tmpg,tmpb;
1122 rgb_to_hsv(col[0],col[1],col[2],&colH,&colS,&colV);
1124 rgb_to_hsv(*r,*g,*b,&rH,&rS,&rV);
1125 hsv_to_rgb( colH , rS, rV, &tmpr, &tmpg, &tmpb);
1126 *r = facm*(*r) + fac*tmpr;
1127 *g = facm*(*g) + fac*tmpg;
1128 *b = facm*(*b) + fac*tmpb;
1135 float colH,colS,colV;
1136 rgb_to_hsv(*r,*g,*b,&rH,&rS,&rV);
1138 rgb_to_hsv(col[0],col[1],col[2],&colH,&colS,&colV);
1139 hsv_to_rgb( rH, (facm*rS +fac*colS), rV, r, g, b);
1146 float colH,colS,colV;
1147 rgb_to_hsv(*r,*g,*b,&rH,&rS,&rV);
1148 rgb_to_hsv(col[0],col[1],col[2],&colH,&colS,&colV);
1149 hsv_to_rgb( rH, rS, (facm*rV +fac*colV), r, g, b);
1155 float colH,colS,colV;
1156 float tmpr,tmpg,tmpb;
1157 rgb_to_hsv(col[0],col[1],col[2],&colH,&colS,&colV);
1159 rgb_to_hsv(*r,*g,*b,&rH,&rS,&rV);
1160 hsv_to_rgb( colH, colS, rV, &tmpr, &tmpg, &tmpb);
1161 *r = facm*(*r) + fac*tmpr;
1162 *g = facm*(*g) + fac*tmpg;
1163 *b = facm*(*b) + fac*tmpb;