]> git.sesse.net Git - mlt/commitdiff
Add geometry opacity interpretation to affine.
authorDan Dennedy <dan@dennedy.org>
Tue, 11 Jan 2011 05:57:56 +0000 (21:57 -0800)
committerDan Dennedy <dan@dennedy.org>
Tue, 11 Jan 2011 05:57:56 +0000 (21:57 -0800)
Also, fixes interpolation method selection and removes a redundant
bounds test.

src/modules/plus/interp.h
src/modules/plus/transition_affine.c

index f5ad8b2727f3624a4a46f60717a56d898e26a84b..39e626dffd34c6b0aaf7c1242fd31fca86f36f2d 100644 (file)
 #include <inttypes.h>
 
 
-#define TEST_XY_LIMITS
+//#define TEST_XY_LIMITS
 
 //--------------------------------------------------------
 //pointer to an interpolating function
-typedef int (*interpp)(unsigned char*, int, int, float, float, unsigned char*);
+typedef int (*interpp)(unsigned char*, int, int, float, float, float, unsigned char*);
 
 //************************************
 //REMAP AN IMAGE
@@ -70,7 +70,7 @@ void remap(int wi, int hi, int wo, int ho, unsigned char *vhs, unsigned char *iz
                x=map[2*(wo*i+j)];
                y=map[2*(wo*i+j)+1];
                if (x>0)
-                       interp(vhs,wi,hi,x,y,&izs[wo*i+j]);
+                       interp(vhs,wi,hi,x,y,1.0,&izs[wo*i+j]);
                else
                        izs[wo*i+j]=bgc;        //background fill
        }
@@ -96,7 +96,7 @@ void remap32(int wi, int hi, int wo, int ho, unsigned char *vhs, unsigned char *
                x=map[2*(wo*i+j)];
                y=map[2*(wo*i+j)+1];
                if (x>0)
-                       interp(vhs,wi,hi,x,y,&izs[4*(wo*i+j)]);
+                       interp(vhs,wi,hi,x,y,1.0,&izs[4*(wo*i+j)]);
                else    //background fill
                {
                        izs[4*(wo*i+j)]=bgc;
@@ -117,8 +117,9 @@ void remap32(int wi, int hi, int wo, int ho, unsigned char *vhs, unsigned char *
 //     *sl vhodni array (slika)
 //     w,h dimenzija slike je wxh
 //     x,y tocka, za katero izracuna interpolirano vrednost
+//  o opacity
 //     *v interpolirana vrednost
-int interpNNpr_b(unsigned char *sl, int w, int h, float x, float y, unsigned char *v)
+int interpNNpr_b(unsigned char *sl, int w, int h, float x, float y, float o, unsigned char *v)
 {
        //printf("u=%5.2f v=%5.2f   ",x,y);
        printf("u=%5.3f v=%5.3f     ",x/(w-1),y/(h-1));
@@ -138,8 +139,9 @@ int interpNNpr_b(unsigned char *sl, int w, int h, float x, float y, unsigned cha
 //     *sl vhodni array (slika)
 //     w,h dimenzija slike je wxh
 //     x,y tocka, za katero izracuna interpolirano vrednost
+//  o opacity
 //     *v interpolirana vrednost
-int interpNN_b(unsigned char *sl, int w, int h, float x, float y, unsigned char *v)
+int interpNN_b(unsigned char *sl, int w, int h, float x, float y, float o, unsigned char *v)
 {
 #ifdef TEST_XY_LIMITS
        if ((x<0)||(x>=(w-1))||(y<0)||(y>=(h-1))) return -1;
@@ -156,14 +158,15 @@ int interpNN_b(unsigned char *sl, int w, int h, float x, float y, unsigned char
 //     *sl vhodni array (slika)
 //     w,h dimenzija slike je wxh
 //     x,y tocka, za katero izracuna interpolirano vrednost
+//  o opacity
 //     *v interpolirana vrednost
-int interpNN_b32(unsigned char *sl, int w, int h, float x, float y, unsigned char *v)
+int interpNN_b32(unsigned char *sl, int w, int h, float x, float y, float o, unsigned char *v)
 {
 #ifdef TEST_XY_LIMITS
        if ((x<0)||(x>=(w-1))||(y<0)||(y>=(h-1))) return -1;
 #endif
        v[3]= sl[(int)rintf(x)*4+(int)rintf(y)*4*w+3];
-       float alpha = (float) v[3] / 255.0;
+       float alpha = (float) v[3] / 255.0 * o;
        v[0]= v[0] * (1.0 - alpha) + sl[(int)rintf(x)*4+(int)rintf(y)*4*w] * alpha;
        v[1]= v[1] * (1.0 - alpha) + sl[(int)rintf(x)*4+(int)rintf(y)*4*w+1] * alpha;
        v[2]= v[2] * (1.0 - alpha) + sl[(int)rintf(x)*4+(int)rintf(y)*4*w+2] * alpha;
@@ -177,8 +180,9 @@ int interpNN_b32(unsigned char *sl, int w, int h, float x, float y, unsigned cha
 //     *sl vhodni array (slika)
 //     w,h dimenzija slike je wxh
 //     x,y tocka, za katero izracuna interpolirano vrednost
+//  o opacity
 //     *v interpolirana vrednost
-int interpBL_b(unsigned char *sl, int w, int h, float x, float y, unsigned char *v)
+int interpBL_b(unsigned char *sl, int w, int h, float x, float y, float o, unsigned char *v)
 {
        int m,n,k,l;
        float a,b;
@@ -198,7 +202,7 @@ int interpBL_b(unsigned char *sl, int w, int h, float x, float y, unsigned char
 //------------------------------------------------------
 //bilinearna interpolacija
 //za byte (char) vrednosti  v packed color 32 bitnem formatu
-int interpBL_b32(unsigned char *sl, int w, int h, float x, float y, unsigned char *v)
+int interpBL_b32(unsigned char *sl, int w, int h, float x, float y, float o, unsigned char *v)
 {
        int m,n,k,l,n1,l1,k1;
        float a,b;
@@ -215,7 +219,7 @@ int interpBL_b32(unsigned char *sl, int w, int h, float x, float y, unsigned cha
        a=sl[k+3]+(sl[k1+3]-sl[k+3])*(x-(float)m);
        b=sl[l+3]+(sl[l1+3]-sl[n1+3])*(x-(float)m);
        v[3]=a+(b-a)*(y-(float)n);
-       float alpha = (float) v[3] / 255.0;
+       float alpha = (float) v[3] / 255.0 * o;
 
        a=sl[k]+(sl[k1]-sl[k])*(x-(float)m);
        b=sl[l]+(sl[l1]-sl[n1])*(x-(float)m);
@@ -239,8 +243,9 @@ int interpBL_b32(unsigned char *sl, int w, int h, float x, float y, unsigned cha
 //     *sl vhodni array (slika)
 //     w,h dimenzija slike je wxh
 //     x,y tocka, za katero izracuna interpolirano vrednost
+//  o opacity
 //     *v interpolirana vrednost
-int interpBC_b(unsigned char *sl, int w, int h, float x, float y, unsigned char *v)
+int interpBC_b(unsigned char *sl, int w, int h, float x, float y, float o, unsigned char *v)
 {
        int i,j,l,m,n;
        float k;
@@ -289,7 +294,7 @@ int interpBC_b(unsigned char *sl, int w, int h, float x, float y, unsigned char
 //------------------------------------------------------
 //bikubicna interpolacija  "smooth"
 //za byte (char) vrednosti  v packed color 32 bitnem formatu
-int interpBC_b32(unsigned char *sl, int w, int h, float x, float y, unsigned char *v)
+int interpBC_b32(unsigned char *sl, int w, int h, float x, float y, float o, unsigned char *v)
 {
        int i,j,b,l,m,n;
        float k;
@@ -335,7 +340,7 @@ int interpBC_b32(unsigned char *sl, int w, int h, float x, float y, unsigned cha
                if (p[3]>256.0) p[3]=255.0;
 
                v[b]= v[b] * (1.0 - alpha) + p[3] * alpha;
-               if (b == 3) alpha = v[b] / 255.0;
+               if (b == 3) alpha = v[b] / 255.0 * o;
        }
 
        return 0;
@@ -348,10 +353,11 @@ int interpBC_b32(unsigned char *sl, int w, int h, float x, float y, unsigned cha
 //     *sl vhodni array (slika)
 //     w,h dimenzija slike je wxh
 //     x,y tocka, za katero izracuna interpolirano vrednost
+//  o opacity
 //     *v interpolirana vrednost
 //!!! ODKOD SUM???  (ze po eni rotaciji v interp_test !!)
 //!!! v defish tega suma ni???
-int interpBC2_b(unsigned char *sl, int w, int h, float x, float y, unsigned char *v)
+int interpBC2_b(unsigned char *sl, int w, int h, float x, float y, float o, unsigned char *v)
 {
        int i,k,l,m,n;
        float pp,p[4],wx[4],wy[4],xx;
@@ -403,7 +409,7 @@ int interpBC2_b(unsigned char *sl, int w, int h, float x, float y, unsigned char
 //za byte (char) vrednosti  v packed color 32 bitnem formatu
 //!!! ODKOD SUM???  (ze po eni rotaciji v interp_test !!)
 //!!! v defish tega suma ni???
-int interpBC2_b32(unsigned char *sl, int w, int h, float x, float y, unsigned char *v)
+int interpBC2_b32(unsigned char *sl, int w, int h, float x, float y, float o, unsigned char *v)
 {
        int b,i,k,l,m,n,u;
        float pp,p[4],wx[4],wy[4],xx;
@@ -461,8 +467,9 @@ int interpBC2_b32(unsigned char *sl, int w, int h, float x, float y, unsigned ch
 //     *sl vhodni array (slika)
 //     w,h dimenzija slike je wxh
 //     x,y tocka, za katero izracuna interpolirano vrednost
+//  o opacity
 //     *v interpolirana vrednost
-int interpSP4_b(unsigned char *sl, int w, int h, float x, float y, unsigned char *v)
+int interpSP4_b(unsigned char *sl, int w, int h, float x, float y, float o, unsigned char *v)
 {
        int i,j,m,n;
        float pp,p[4],wx[4],wy[4],xx;
@@ -508,7 +515,7 @@ int interpSP4_b(unsigned char *sl, int w, int h, float x, float y, unsigned char
 //------------------------------------------------------
 //spline 4x4 interpolacija
 //za byte (char) vrednosti  v packed color 32 bitnem formatu
-int interpSP4_b32(unsigned char *sl, int w, int h, float x, float y, unsigned char *v)
+int interpSP4_b32(unsigned char *sl, int w, int h, float x, float y, float o, unsigned char *v)
 {
        int i,j,m,n,b;
        float pp,p[4],wx[4],wy[4],xx;
@@ -562,10 +569,11 @@ int interpSP4_b32(unsigned char *sl, int w, int h, float x, float y, unsigned ch
 //     *sl vhodni array (slika)
 //     w,h dimenzija slike je wxh
 //     x,y tocka, za katero izracuna interpolirano vrednost
+//  o opacity
 //     *v interpolirana vrednost
 //!!! PAZI, TOLE NE DELA CISTO PRAV ???   belina se siri
 //!!! zaenkrat sem dodal fudge factor...
-int interpSP6_b(unsigned char *sl, int w, int h, float x, float y, unsigned char *v)
+int interpSP6_b(unsigned char *sl, int w, int h, float x, float y, float o, unsigned char *v)
 {
        int i,j,m,n;
        float pp,p[6],wx[6],wy[6],xx;
@@ -631,7 +639,7 @@ int interpSP6_b(unsigned char *sl, int w, int h, float x, float y, unsigned char
 //za byte (char) vrednosti  v packed color 32 bitnem formatu
 //!!! PAZI, TOLE NE DELA CISTO PRAV ???   belina se siri
 //!!! zaenkrat sem dodal fudge factor...
-int interpSP6_b32(unsigned char *sl, int w, int h, float x, float y, unsigned char *v)
+int interpSP6_b32(unsigned char *sl, int w, int h, float x, float y, float o, unsigned char *v)
 {
        int i,b,j,m,n;
        float pp,p[6],wx[6],wy[6],xx;
@@ -702,8 +710,9 @@ int interpSP6_b32(unsigned char *sl, int w, int h, float x, float y, unsigned ch
 //     *sl vhodni array (slika)
 //     w,h dimenzija slike je wxh
 //     x,y tocka, za katero izracuna interpolirano vrednost
+//  o opacity
 //     *v interpolirana vrednost
-int interpSC16_b(unsigned char *sl, int w, int h, float x, float y, unsigned char *v)
+int interpSC16_b(unsigned char *sl, int w, int h, float x, float y, float o, unsigned char *v)
 {
        int i,j,m,n;
        float pp,p[16],wx[16],wy[16],xx,xxx,x1;
@@ -762,7 +771,7 @@ int interpSC16_b(unsigned char *sl, int w, int h, float x, float y, unsigned cha
 //------------------------------------------------------
 //truncated sinc "lanczos" 16x16 interpolacija
 //za byte (char) vrednosti  v packed color 32 bitnem formatu
-int interpSC16_b32(unsigned char *sl, int w, int h, float x, float y, unsigned char *v)
+int interpSC16_b32(unsigned char *sl, int w, int h, float x, float y, float o, unsigned char *v)
 {
        int i,j,m,b,n;
        float pp,p[16],wx[16],wy[16],xx,xxx,x1;
index 63288322353aa407a95e6b16d634a807e78d02d9..43d5c1ae70104b2c064fd3c361a530111bdb0da4 100644 (file)
@@ -395,7 +395,6 @@ static int transition_get_image( mlt_frame a_frame, uint8_t **image, mlt_image_f
        int normalised_height = mlt_properties_get_int( a_props, "normalised_height" );
 
        double consumer_ar = mlt_properties_get_double( a_props, "consumer_aspect_ratio" );
-       const char *interps = mlt_properties_get( b_props, "rescale.interp" );
 
        // Structures for geometry
        struct mlt_geometry_item_s result;
@@ -423,6 +422,7 @@ static int transition_get_image( mlt_frame a_frame, uint8_t **image, mlt_image_f
        mlt_properties_set_int( b_props, "rescale_height", b_height );
 
        // Suppress padding and aspect normalization.
+       const char *interps = strdup( mlt_properties_get( b_props, "rescale.interp" ) );
        mlt_properties_set( b_props, "rescale.interp", "none" );
        if ( mlt_properties_get_double( b_props, "aspect_ratio" ) == 0.0 )
                mlt_properties_set_double( b_props, "aspect_ratio", consumer_ar );
@@ -463,7 +463,10 @@ static int transition_get_image( mlt_frame a_frame, uint8_t **image, mlt_image_f
                get_affine( &affine, this, ( float )position );
                dz = MapZ( affine.matrix, 0, 0 );
                if ( ( int )abs( dz * 1000 ) < 25 )
+               {
+                       free( interps );
                        return 0;
+               }
 
                // Factor scaling into the transformation based on output resolution.
                if ( mlt_properties_get_int( properties, "distort" ) )
@@ -521,11 +524,12 @@ static int transition_get_image( mlt_frame a_frame, uint8_t **image, mlt_image_f
                                dx = MapX( affine.matrix, x, y ) / dz + x_offset;
                                dy = MapY( affine.matrix, x, y ) / dz + y_offset;
                                if ( dx >= 0 && dx < b_width && dy >=0 && dy < b_height )
-                                       interp( b_image, b_width, b_height, dx, dy, p );
+                                       interp( b_image, b_width, b_height, dx, dy, result.mix/100.0, p );
                                p += 4;
                        }
                }
        }
+       free( interps );
 
        return 0;
 }