H261 decoder

Dependencies:   SDL_lib2 SX1276Lib mbed

Revision:
1:1ed97958d0f3
Parent:
0:5bd441b8ab2d
--- a/functions_dec.h	Thu Sep 22 00:04:30 2016 +0000
+++ b/functions_dec.h	Wed Jan 11 20:18:38 2017 +0000
@@ -25,6 +25,16 @@
 #define RAIZ2 1.414214
 #define PI16 0.19635
 
+const float coeff[8][8]={
+        {1.000, 0.980658, 0.923381, 0.830384, 0.705265, 0.552863, 0.379075, 0.190623},
+        {1.000000, 0.830384, 0.379075, -0.200829, -0.712605, -0.982642, -0.919336, -0.544161},
+        {1.000000, 0.552863, -0.388685, -0.982642, -0.697848, 0.211013, 0.931171, 0.818607},
+        {1.000000, 0.190623, -0.927326, -0.544161, 0.719867, 0.818607, -0.407777, -0.974070},
+        {1.000000, -0.200829, -0.919336, 0.570086, 0.690356, -0.847373, -0.350003, 0.987954},
+        {1.000000, -0.561505, -0.369424, 0.976372, -0.727052, -0.159885, 0.906605, -0.858241},
+        {1.000000, -0.836138, 0.398253, 0.170150, -0.682790, 0.971663, -0.942098, 0.603785},
+        {1.000000, -0.982642, 0.931171, -0.847373, 0.734158, -0.595456, 0.436082, -0.261569} };
+
 void IDCT(int matrix[8][8][3],short int f[HEIGHT][WIDTH][3],int p_fil,int p_col){
     int i=0,j=0,u,v;
     float cu=1,cv=1;
@@ -45,7 +55,8 @@
             float dato=0.0;
             float dato2=0.0;
             float dato3=0.0;
-
+            
+            float acum0=0.0,acum1=0.0,acum2=0.0;
 
             for(u=0;u<8;u++){
 
@@ -59,26 +70,28 @@
 
                     }
                     else cv=1.0;
-                    dato=(float)(cos((float)((((+j-p_col)<<1)+1)*v*PI16)));
-                    dato2=(float)(cos((float)((((i-p_fil)<<1)+1)*u*PI16)));
+                    /*dato=(float)(cos((float)((((j-p_col)*2)+1)*v*PI16)));
+                    dato2=(float)(cos((float)((((i-p_fil)*2)+1)*u*PI16)));*/
+                    dato=coeff[j-p_col][v];//(float)(cos((float)((((j-p_col)*2)+1)*v*PI16)));
+                    dato2=coeff[i-p_fil][u];//(float)(cos((float)((((i-p_fil)*2)+1)*u*PI16)));
                     dato3=(float)((cu*cv)/4);
 
-                    f[i][j][0]+=(short int)(dato*dato2*(matrix[u][v][0]))*dato3;//crominancia
-                    f[i][j][1]+=(short int)(dato*dato2*(matrix[u][v][1]))*dato3;//crominancia
-                    f[i][j][2]+=(short int)(dato*dato2*(matrix[u][v][2]))*dato3;//luminancia
+                    acum0+=(float)(dato*dato2*(matrix[u][v][0]))*dato3;//crominancia
+                    acum1+=(float)(dato*dato2*(matrix[u][v][1]))*dato3;//crominancia
+                    acum2+=(float)(dato*dato2*(matrix[u][v][2]))*dato3;//luminancia
 
                 }
             }
-
-
-
+            
+            f[i][j][0]=(short int)acum0;
+            f[i][j][1]=(short int)acum1;
+            f[i][j][2]=(short int)acum2;
 
         }
 
 
     }
 
-
 }
 
 void yuv_to_rgb(short int f[HEIGHT][WIDTH][3]){
@@ -87,7 +100,7 @@
     int i=0,j=0;
 
     float r=0.0,g=0.0,b=0.0;
-    char cad[180];
+   
 
     int cont;
   
@@ -96,16 +109,16 @@
 
 
 
-            b=(f[i][j][2]-16)*1.164+(f[i][j][1]-128)*2.017;
-            g=(f[i][j][2]-16)*1.164-(f[i][j][0]-128)*0.813-(f[i][j][1]-128)*0.392;
-            r=((f[i][j][2])-16)*1.164+((f[i][j][0])-128)*1.596;
+            b=(f[i][j][0])+(f[i][j][1]-128)*1.765;
+            g=(f[i][j][0])-(f[i][j][2]-128)*0.711-(f[i][j][1]-128)*0.343;
+            r=((f[i][j][0]))+((f[i][j][2])-128)*1.400;
 
         /*  r=(*(pixel+2)-16)*1.164+(*(pixel)-128)*1.793;
             g=(*(pixel+2)-16)*1.164-(*(pixel+1)-128)*0.213-(*(pixel)-128)*0.533;
             b=(*(pixel+2)-16)*1.164+((*(pixel+1))-128)*2.112;*/
-            if(r>255) r=255;
+            if(b>255) r=255;
             if(g>255) g=255;
-            if(b>255) b=255;
+            if(r>255) b=255;
 
             if(r<0) r=0;
             if(g<0) g=0;
@@ -189,9 +202,9 @@
         for(j=0;j<WIDTH;j+=8)
         for(x_block=i; x_block<i+8 ;x_block++){
             for(y_block=j; y_block<j+8 ;y_block++){
-                mat[x_block][y_block][2]*=luma[x_block-i][y_block-j];
+                mat[x_block][y_block][0]*=luma[x_block-i][y_block-j];
                 mat[x_block][y_block][1]*=croma[x_block-i][y_block-j];
-                mat[x_block][y_block][0]*=croma[x_block-i][y_block-j];
+                mat[x_block][y_block][2]*=croma[x_block-i][y_block-j];
             }
         }
     }