sequencer float conversion was only using rgb -> float conversion inconsistantly...
authorCampbell Barton <ideasman42@gmail.com>
Mon, 12 Jul 2010 14:57:24 +0000 (14:57 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Mon, 12 Jul 2010 14:57:24 +0000 (14:57 +0000)
Added IMB_float_from_rect_simple() for the sequencer to use.

source/blender/blenkernel/intern/displist.c
source/blender/blenkernel/intern/seqeffects.c
source/blender/blenkernel/intern/sequencer.c
source/blender/imbuf/IMB_imbuf.h
source/blender/imbuf/intern/divers.c

index 716d311..bb020c9 100644 (file)
@@ -575,9 +575,9 @@ static void mesh_create_shadedColors(Render *re, Object *ob, int onlyForMesh, un
                        char *col1= (char*)&col1base[j*4];
                        char *col2= (char*)(col2base?&col2base[j*4]:NULL);
                        float *vn = (mf->flag & ME_SMOOTH)?&vnors[3*vidx[j]]:n1;
-                       
-                       VECCOPY(vec, mv->co);
-                       mul_m4_v3(mat, vec);
+
+                       mul_v3_m4v3(vec, mat, mv->co);
+
                        vec[0]+= 0.001*vn[0];
                        vec[1]+= 0.001*vn[1];
                        vec[2]+= 0.001*vn[2];
@@ -688,8 +688,7 @@ void shadeDispList(Scene *scene, Base *base)
                                                
                                                a= dl->nr;              
                                                while(a--) {
-                                                       VECCOPY(vec, fp);
-                                                       mul_m4_v3(mat, vec);
+                                                       mul_v3_m4v3(vec, mat, fp);
                                                        
                                                        fastshade(vec, n1, fp, ma, (char *)col1, NULL);
                                                        
@@ -704,8 +703,7 @@ void shadeDispList(Scene *scene, Base *base)
                                                nor= dl->nors;
                                                
                                                while(a--) {
-                                                       VECCOPY(vec, fp);
-                                                       mul_m4_v3(mat, vec);
+                                                       mul_v3_m4v3(vec, mat, fp);
                                                        
                                                        n1[0]= imat[0][0]*nor[0]+imat[0][1]*nor[1]+imat[0][2]*nor[2];
                                                        n1[1]= imat[1][0]*nor[0]+imat[1][1]*nor[1]+imat[1][2]*nor[2];
@@ -742,8 +740,7 @@ void shadeDispList(Scene *scene, Base *base)
                                                
                                                a= dl->nr;              
                                                while(a--) {
-                                                       VECCOPY(vec, fp);
-                                                       mul_m4_v3(mat, vec);
+                                                       mul_v3_m4v3(vec, mat, fp);
                                                        
                                                        /* transpose ! */
                                                        n1[0]= imat[0][0]*nor[0]+imat[0][1]*nor[1]+imat[0][2]*nor[2];
index 56a8edc..73c1977 100644 (file)
@@ -312,7 +312,7 @@ static void do_plugin_effect(Scene *scene, Sequence *seq, int cfra,
                        IMB_convert_rgba_to_abgr(out);
                }
                if (seq->plugin->version<=3 && float_rendering) {
-                       IMB_float_from_rect(out);
+                       IMB_float_from_rect_simple(out);
                }
 
                if (use_temp_bufs) {
@@ -2783,7 +2783,7 @@ static void do_multicam(Scene *scene, Sequence *seq, int cfra,
                IMB_rect_from_float(i);
                memcpy(out->rect, i->rect, out->x * out->y * 4);
        } else if (out->rect_float && i->rect) {
-               IMB_float_from_rect(i);
+               IMB_float_from_rect_simple(i);
                memcpy(out->rect_float, i->rect_float, out->x * out->y *4*sizeof(float));
        }
 }
index 6e48a71..fd3e56a 100644 (file)
@@ -1022,13 +1022,13 @@ static void do_effect(Scene *scene, int cfra, Sequence *seq, TStripElem * se,
        y= se2->ibuf->y;
 
        if (!se1->ibuf->rect_float && se->ibuf->rect_float) {
-               IMB_float_from_rect(se1->ibuf);
+               IMB_float_from_rect_simple(se1->ibuf);
        }
        if (!se2->ibuf->rect_float && se->ibuf->rect_float) {
-               IMB_float_from_rect(se2->ibuf);
+               IMB_float_from_rect_simple(se2->ibuf);
        }
        if (!se3->ibuf->rect_float && se->ibuf->rect_float) {
-               IMB_float_from_rect(se3->ibuf);
+               IMB_float_from_rect_simple(se3->ibuf);
        }
        
        if (!se1->ibuf->rect && !se->ibuf->rect_float) {
@@ -1784,17 +1784,9 @@ static void input_preprocess(Scene *scene, Sequence *seq, TStripElem *se, int cf
        }
 
        if(seq->flag & SEQ_MAKE_FLOAT) {
-               if (!se->ibuf->rect_float) {
-                       int profile = IB_PROFILE_NONE;
-                       
-                       /* no color management:
-                        * don't disturb the existing profiles */
-                       SWAP(int, se->ibuf->profile, profile);
+               if (!se->ibuf->rect_float)
+                       IMB_float_from_rect_simple(se->ibuf);
 
-                       IMB_float_from_rect(se->ibuf);
-                       
-                       SWAP(int, se->ibuf->profile, profile);
-               }
                if (se->ibuf->rect) {
                        imb_freerectImBuf(se->ibuf);
                }
@@ -2085,14 +2077,14 @@ static void do_build_seq_ibuf(Scene *scene, Sequence * seq, TStripElem *se, int
                        }
                        copy_from_ibuf_still(seq, se);
 
-                       if (!se->ibuf) {
-                               se->ibuf= IMB_loadiffname(
-                                       name, IB_rect);
+                       if (se->ibuf==NULL && (se->ibuf= IMB_loadiffname(name, IB_rect))) {
                                /* we don't need both (speed reasons)! */
-                               if (se->ibuf &&
-                                       se->ibuf->rect_float && se->ibuf->rect) {
+                               if (se->ibuf->rect_float && se->ibuf->rect)
                                        imb_freerectImBuf(se->ibuf);
-                               }
+
+                               /* all sequencer color is done in SRGB space, linear gives odd crossfades */
+                               if(se->ibuf->profile == IB_PROFILE_LINEAR_RGB)
+                                       IMB_convert_profile(se->ibuf, IB_PROFILE_NONE);
 
                                copy_to_ibuf_still(seq, se);
                        }
@@ -2707,11 +2699,11 @@ static TStripElem* do_build_seq_array_recursively(
 
                        if (!se1->ibuf_comp->rect_float && 
                                se2->ibuf_comp->rect_float) {
-                               IMB_float_from_rect(se1->ibuf_comp);
+                               IMB_float_from_rect_simple(se1->ibuf_comp);
                        }
                        if (!se2->ibuf->rect_float && 
                                se2->ibuf_comp->rect_float) {
-                               IMB_float_from_rect(se2->ibuf);
+                               IMB_float_from_rect_simple(se2->ibuf);
                        }
 
                        if (!se1->ibuf_comp->rect && 
index 37399c9..07b99dd 100644 (file)
@@ -319,6 +319,9 @@ void IMB_de_interlace(struct ImBuf *ibuf);
 void IMB_interlace(struct ImBuf *ibuf);
 void IMB_rect_from_float(struct ImBuf *ibuf);
 void IMB_float_from_rect(struct ImBuf *ibuf);
+void IMB_float_from_rect_simple(struct ImBuf *ibuf); /* no profile conversion */
+/* note, check that the conversion exists, only some are supported */
+void IMB_convert_profile(struct ImBuf *ibuf, int profile);
 
 /**
  * Change the ordering of the color bytes pointed to by rect from
index 0cc4346..7b3a07f 100644 (file)
@@ -222,3 +222,74 @@ void IMB_float_from_rect(struct ImBuf *ibuf)
        }
 }
 
+/* no profile conversion */
+void IMB_float_from_rect_simple(struct ImBuf *ibuf)
+{
+       int profile = IB_PROFILE_NONE;
+
+       /* no color management:
+        * don't disturb the existing profiles */
+       SWAP(int, ibuf->profile, profile);
+
+       IMB_float_from_rect(ibuf);
+
+       SWAP(int, ibuf->profile, profile);
+}
+
+void IMB_convert_profile(struct ImBuf *ibuf, int profile)
+{
+       int ok= FALSE;
+       int i;
+
+       unsigned char *rct= (unsigned char *)ibuf->rect;
+       float *rctf= ibuf->rect_float;
+
+       if(ibuf->profile == profile)
+               return;
+
+       if(ELEM(ibuf->profile, IB_PROFILE_NONE, IB_PROFILE_SRGB)) { /* from */
+               if(profile == IB_PROFILE_LINEAR_RGB) { /* to */
+                       if(ibuf->rect_float) {
+                               for (i = ibuf->x * ibuf->y; i > 0; i--, rctf+=4) {
+                                       rctf[0]= srgb_to_linearrgb(rctf[0]);
+                                       rctf[1]= srgb_to_linearrgb(rctf[1]);
+                                       rctf[2]= srgb_to_linearrgb(rctf[2]);
+                               }
+                       }
+                       if(ibuf->rect) {
+                               for (i = ibuf->x * ibuf->y; i > 0; i--, rct+=4) {
+                                       rctf[0]= (unsigned char)((srgb_to_linearrgb((float)rctf[0]/255.0f) * 255.0f) + 0.5f);
+                                       rctf[1]= (unsigned char)((srgb_to_linearrgb((float)rctf[1]/255.0f) * 255.0f) + 0.5f);
+                                       rctf[2]= (unsigned char)((srgb_to_linearrgb((float)rctf[2]/255.0f) * 255.0f) + 0.5f);
+                               }
+                       }
+                       ok= TRUE;
+               }
+       }
+       else if (ibuf->profile == IB_PROFILE_LINEAR_RGB) { /* from */
+               if(ELEM(profile, IB_PROFILE_NONE, IB_PROFILE_SRGB)) { /* to */
+                       if(ibuf->rect_float) {
+                               for (i = ibuf->x * ibuf->y; i > 0; i--, rctf+=4) {
+                                       rctf[0]= linearrgb_to_srgb(rctf[0]);
+                                       rctf[1]= linearrgb_to_srgb(rctf[1]);
+                                       rctf[2]= linearrgb_to_srgb(rctf[2]);
+                               }
+                       }
+                       if(ibuf->rect) {
+                               for (i = ibuf->x * ibuf->y; i > 0; i--, rct+=4) {
+                                       rctf[0]= (unsigned char)((linearrgb_to_srgb((float)rctf[0]/255.0f) * 255.0f) + 0.5f);
+                                       rctf[1]= (unsigned char)((linearrgb_to_srgb((float)rctf[1]/255.0f) * 255.0f) + 0.5f);
+                                       rctf[2]= (unsigned char)((linearrgb_to_srgb((float)rctf[2]/255.0f) * 255.0f) + 0.5f);
+                               }
+                       }
+                       ok= TRUE;
+               }
+       }
+
+       if(ok==FALSE){
+               printf("IMB_convert_profile: failed profile conversion %d -> %d\n", ibuf->profile, profile);
+               return;
+       }
+
+       ibuf->profile= profile;
+}