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;
616 id_us_plus((ID *)ma);
617 test_object_materials(ob->data);
620 int find_material_index(Object *ob, Material *ma)
625 if(ma==NULL) return 0;
627 totcolp= give_totcolp(ob);
628 matarar= give_matarar(ob);
630 if(totcolp==NULL || matarar==NULL) return 0;
632 for(a=0; a<*totcolp; a++)
633 if((*matarar)[a]==ma)
640 void object_add_material_slot(Object *ob)
645 if(ob->totcol>=MAXMAT) return;
647 ma= give_current_material(ob, ob->actcol);
649 ma= add_material("Material");
651 ma= copy_material(ma);
653 ma->id.us= 0; /* eeh... */
655 assign_material(ob, ma, ob->totcol+1);
656 ob->actcol= ob->totcol;
659 static void do_init_render_material(Material *ma, int r_mode, float *amb)
662 int a, needuv=0, needtang=0;
664 if(ma->flarec==0) ma->flarec= 1;
666 /* add all texcoflags from mtex, texco and mapto were cleared in advance */
667 for(a=0; a<MAX_MTEX; a++) {
669 /* separate tex switching */
670 if(ma->septex & (1<<a)) continue;
673 if(mtex && mtex->tex && (mtex->tex->type | (mtex->tex->use_nodes && mtex->tex->nodetree) )) {
675 ma->texco |= mtex->texco;
676 ma->mapto |= mtex->mapto;
678 if ELEM3(mtex->tex->type, TEX_IMAGE, TEX_PLUGIN, TEX_ENVMAP) ma->texco |= TEXCO_OSA;
681 if(ma->texco & (TEXCO_ORCO|TEXCO_REFL|TEXCO_NORM|TEXCO_STRAND|TEXCO_STRESS)) needuv= 1;
682 else if(ma->texco & (TEXCO_GLOB|TEXCO_UV|TEXCO_OBJECT|TEXCO_SPEED)) needuv= 1;
683 else if(ma->texco & (TEXCO_LAVECTOR|TEXCO_VIEW|TEXCO_STICKY)) needuv= 1;
685 if((ma->mapto & MAP_NORM) && (mtex->normapspace == MTEX_NSPACE_TANGENT))
690 if(needtang) ma->mode |= MA_NORMAP_TANG;
691 else ma->mode &= ~MA_NORMAP_TANG;
694 if(ma->mode & MA_RADIO) needuv= 1;
696 if(ma->mode & (MA_VERTEXCOL|MA_VERTEXCOLP|MA_FACETEXTURE)) {
698 if(r_mode & R_OSA) ma->texco |= TEXCO_OSA; /* for texfaces */
700 if(needuv) ma->texco |= NEED_UV;
702 /* since the raytracer doesnt recalc O structs for each ray, we have to preset them all */
703 if(r_mode & R_RAYTRACE) {
704 if(ma->mode & (MA_RAYMIRROR|MA_RAYTRANSP|MA_SHADOW_TRA)) {
705 ma->texco |= NEED_UV|TEXCO_ORCO|TEXCO_REFL|TEXCO_NORM;
706 if(r_mode & R_OSA) ma->texco |= TEXCO_OSA;
711 ma->ambr= ma->amb*amb[0];
712 ma->ambg= ma->amb*amb[1];
713 ma->ambb= ma->amb*amb[2];
715 /* will become or-ed result of all node modes */
716 ma->mode_l= ma->mode;
717 ma->mode_l &= ~MA_SHLESS;
719 if(ma->strand_surfnor > 0.0f)
720 ma->mode_l |= MA_STR_SURFDIFF;
723 static void init_render_nodetree(bNodeTree *ntree, Material *basemat, int r_mode, float *amb)
727 for(node=ntree->nodes.first; node; node= node->next) {
729 if(GS(node->id->name)==ID_MA) {
730 Material *ma= (Material *)node->id;
732 do_init_render_material(ma, r_mode, amb);
733 basemat->texco |= ma->texco;
734 basemat->mode_l |= ma->mode_l;
737 else if(node->type==NODE_GROUP)
738 init_render_nodetree((bNodeTree *)node->id, basemat, r_mode, amb);
741 /* parses the geom+tex nodes */
742 ntreeShaderGetTexcoMode(ntree, r_mode, &basemat->texco, &basemat->mode_l);
745 void init_render_material(Material *mat, int r_mode, float *amb)
748 do_init_render_material(mat, r_mode, amb);
750 if(mat->nodetree && mat->use_nodes) {
751 init_render_nodetree(mat->nodetree, mat, r_mode, amb);
753 ntreeBeginExecTree(mat->nodetree); /* has internal flag to detect it only does it once */
757 void init_render_materials(int r_mode, float *amb)
761 /* clear these flags before going over materials, to make sure they
762 * are cleared only once, otherwise node materials contained in other
763 * node materials can go wrong */
764 for(ma= G.main->mat.first; ma; ma= ma->id.next) {
771 /* two steps, first initialize, then or the flags for layers */
772 for(ma= G.main->mat.first; ma; ma= ma->id.next) {
773 /* is_used flag comes back in convertblender.c */
774 ma->flag &= ~MA_IS_USED;
776 init_render_material(ma, r_mode, amb);
779 do_init_render_material(&defmaterial, r_mode, amb);
782 /* only needed for nodes now */
783 void end_render_material(Material *mat)
785 if(mat && mat->nodetree && mat->use_nodes)
786 ntreeEndExecTree(mat->nodetree); /* has internal flag to detect it only does it once */
789 void end_render_materials(void)
792 for(ma= G.main->mat.first; ma; ma= ma->id.next)
794 end_render_material(ma);
797 static int material_in_nodetree(bNodeTree *ntree, Material *mat)
801 for(node=ntree->nodes.first; node; node= node->next) {
802 if(node->id && GS(node->id->name)==ID_MA) {
803 if(node->id==(ID*)mat)
806 else if(node->type==NODE_GROUP)
807 if(material_in_nodetree((bNodeTree*)node->id, mat))
814 int material_in_material(Material *parmat, Material *mat)
818 else if(parmat->nodetree && parmat->use_nodes)
819 return material_in_nodetree(parmat->nodetree, mat);
824 /* ****************** */
826 char colname_array[125][20]= {
827 "Black","DarkRed","HalfRed","Red","Red",
828 "DarkGreen","DarkOlive","Brown","Chocolate","OrangeRed",
829 "HalfGreen","GreenOlive","DryOlive","Goldenrod","DarkOrange",
830 "LightGreen","Chartreuse","YellowGreen","Yellow","Gold",
831 "Green","LawnGreen","GreenYellow","LightOlive","Yellow",
832 "DarkBlue","DarkPurple","HotPink","VioletPink","RedPink",
833 "SlateGray","DarkGrey","PalePurple","IndianRed","Tomato",
834 "SeaGreen","PaleGreen","GreenKhaki","LightBrown","LightSalmon",
835 "SpringGreen","PaleGreen","MediumOlive","YellowBrown","LightGold",
836 "LightGreen","LightGreen","LightGreen","GreenYellow","PaleYellow",
837 "HalfBlue","DarkSky","HalfMagenta","VioletRed","DeepPink",
838 "SteelBlue","SkyBlue","Orchid","LightHotPink","HotPink",
839 "SeaGreen","SlateGray","MediumGrey","Burlywood","LightPink",
840 "SpringGreen","Aquamarine","PaleGreen","Khaki","PaleOrange",
841 "SpringGreen","SeaGreen","PaleGreen","PaleWhite","YellowWhite",
842 "LightBlue","Purple","MediumOrchid","Magenta","Magenta",
843 "RoyalBlue","SlateBlue","MediumOrchid","Orchid","Magenta",
844 "DeepSkyBlue","LightSteelBlue","LightSkyBlue","Violet","LightPink",
845 "Cyan","DarkTurquoise","SkyBlue","Grey","Snow",
846 "Mint","Mint","Aquamarine","MintCream","Ivory",
847 "Blue","Blue","DarkMagenta","DarkOrchid","Magenta",
848 "SkyBlue","RoyalBlue","LightSlateBlue","MediumOrchid","Magenta",
849 "DodgerBlue","SteelBlue","MediumPurple","PalePurple","Plum",
850 "DeepSkyBlue","PaleBlue","LightSkyBlue","PalePurple","Thistle",
851 "Cyan","ColdBlue","PaleTurquoise","GhostWhite","White"
854 void automatname(Material *ma)
860 if(ma->mode & MA_SHLESS) ref= 1.0;
863 r= (int)(4.99*(ref*ma->r));
864 g= (int)(4.99*(ref*ma->g));
865 b= (int)(4.99*(ref*ma->b));
868 new_id(&G.main->mat, (ID *)ma, colname_array[nr]);
873 void object_remove_material_slot(Object *ob)
875 Material *mao, ***matarar;
882 if(ob==NULL || ob->totcol==0) return;
884 /* take a mesh/curve/mball as starting point, remove 1 index,
885 * AND with all objects that share the ob->data
887 * after that check indices in mesh/curve/mball!!!
890 totcolp= give_totcolp(ob);
891 matarar= give_matarar(ob);
893 /* we delete the actcol */
895 mao= (*matarar)[ob->actcol-1];
896 if(mao) mao->id.us--;
899 for(a=ob->actcol; a<ob->totcol; a++)
900 (*matarar)[a-1]= (*matarar)[a];
909 obt= G.main->object.first;
912 if(obt->data==ob->data) {
914 /* WATCH IT: do not use actcol from ob or from obt (can become zero) */
915 mao= obt->mat[actcol-1];
916 if(mao) mao->id.us--;
918 for(a=actcol; a<obt->totcol; a++) {
919 obt->mat[a-1]= obt->mat[a];
920 obt->matbits[a-1]= obt->matbits[a];
923 if(obt->actcol > obt->totcol) obt->actcol= obt->totcol;
927 MEM_freeN(obt->matbits);
935 /* check indices from mesh */
937 if(ob->type==OB_MESH) {
938 Mesh *me= get_mesh(ob);
939 mesh_delete_material_index(me, actcol-1);
940 freedisplist(&ob->disp);
942 else if ELEM(ob->type, OB_CURVE, OB_SURF) {
947 if(nu->mat_nr && nu->mat_nr>=actcol-1) {
949 if (ob->type == OB_CURVE) nu->charidx--;
953 freedisplist(&ob->disp);
958 /* r g b = current value, col = new value, fac==0 is no change */
959 /* if g==NULL, it only does r channel */
960 void ramp_blend(int type, float *r, float *g, float *b, float fac, float *col)
962 float tmp, facm= 1.0-fac;
966 *r = facm*(*r) + fac*col[0];
968 *g = facm*(*g) + fac*col[1];
969 *b = facm*(*b) + fac*col[2];
980 *r *= (facm + fac*col[0]);
982 *g *= (facm + fac*col[1]);
983 *b *= (facm + fac*col[2]);
987 *r = 1.0 - (facm + fac*(1.0 - col[0])) * (1.0 - *r);
989 *g = 1.0 - (facm + fac*(1.0 - col[1])) * (1.0 - *g);
990 *b = 1.0 - (facm + fac*(1.0 - col[2])) * (1.0 - *b);
993 case MA_RAMP_OVERLAY:
995 *r *= (facm + 2.0f*fac*col[0]);
997 *r = 1.0 - (facm + 2.0f*fac*(1.0 - col[0])) * (1.0 - *r);
1000 *g *= (facm + 2.0f*fac*col[1]);
1002 *g = 1.0 - (facm + 2.0f*fac*(1.0 - col[1])) * (1.0 - *g);
1004 *b *= (facm + 2.0f*fac*col[2]);
1006 *b = 1.0 - (facm + 2.0f*fac*(1.0 - col[2])) * (1.0 - *b);
1018 *r = facm*(*r) + fac*(*r)/col[0];
1021 *g = facm*(*g) + fac*(*g)/col[1];
1023 *b = facm*(*b) + fac*(*b)/col[2];
1027 *r = facm*(*r) + fac*fabs(*r-col[0]);
1029 *g = facm*(*g) + fac*fabs(*g-col[1]);
1030 *b = facm*(*b) + fac*fabs(*b-col[2]);
1035 if(tmp < *r) *r= tmp;
1038 if(tmp < *g) *g= tmp;
1040 if(tmp < *b) *b= tmp;
1045 if(tmp > *r) *r= tmp;
1048 if(tmp > *g) *g= tmp;
1050 if(tmp > *b) *b= tmp;
1057 tmp = 1.0 - fac*col[0];
1060 else if ((tmp = (*r) / tmp)> 1.0)
1067 tmp = 1.0 - fac*col[1];
1070 else if ((tmp = (*g) / tmp) > 1.0 )
1076 tmp = 1.0 - fac*col[2];
1079 else if ((tmp = (*b) / tmp) > 1.0 )
1089 tmp = facm + fac*col[0];
1093 else if (( tmp = (1.0 - (1.0 - (*r)) / tmp )) < 0.0)
1101 tmp = facm + fac*col[1];
1104 else if (( tmp = (1.0 - (1.0 - (*g)) / tmp )) < 0.0 )
1111 tmp = facm + fac*col[2];
1114 else if (( tmp = (1.0 - (1.0 - (*b)) / tmp )) < 0.0 )
1125 float colH,colS,colV;
1126 float tmpr,tmpg,tmpb;
1127 rgb_to_hsv(col[0],col[1],col[2],&colH,&colS,&colV);
1129 rgb_to_hsv(*r,*g,*b,&rH,&rS,&rV);
1130 hsv_to_rgb( colH , rS, rV, &tmpr, &tmpg, &tmpb);
1131 *r = facm*(*r) + fac*tmpr;
1132 *g = facm*(*g) + fac*tmpg;
1133 *b = facm*(*b) + fac*tmpb;
1140 float colH,colS,colV;
1141 rgb_to_hsv(*r,*g,*b,&rH,&rS,&rV);
1143 rgb_to_hsv(col[0],col[1],col[2],&colH,&colS,&colV);
1144 hsv_to_rgb( rH, (facm*rS +fac*colS), rV, r, g, b);
1151 float colH,colS,colV;
1152 rgb_to_hsv(*r,*g,*b,&rH,&rS,&rV);
1153 rgb_to_hsv(col[0],col[1],col[2],&colH,&colS,&colV);
1154 hsv_to_rgb( rH, rS, (facm*rV +fac*colV), r, g, b);
1160 float colH,colS,colV;
1161 float tmpr,tmpg,tmpb;
1162 rgb_to_hsv(col[0],col[1],col[2],&colH,&colS,&colV);
1164 rgb_to_hsv(*r,*g,*b,&rH,&rS,&rV);
1165 hsv_to_rgb( colH, colS, rV, &tmpr, &tmpg, &tmpb);
1166 *r = facm*(*r) + fac*tmpr;
1167 *g = facm*(*g) + fac*tmpg;
1168 *b = facm*(*b) + fac*tmpb;