JPEG compressor

Dependencies:   SDL_lib SX1276Lib mbed

Revision:
1:f0c646dfe574
Parent:
0:1076a8b67c6c
Child:
2:f256eebcade8
--- a/encoder.cpp	Wed Sep 07 18:47:02 2016 +0000
+++ b/encoder.cpp	Thu Sep 22 00:01:55 2016 +0000
@@ -1,3 +1,4 @@
+
 //Author: Miguel Ruiz García
 //Company: University of Cantabria. 2016
 //mail: mrg47@alumnos.unican.es
@@ -7,69 +8,59 @@
 #include <math.h>
 #include "SDL_lib/SDL.h"
 #include "functions.h"
+//#include "lora2.h"
+#include "lora_tansc.h"
 
-//#include "MODSERIAL.h"
-//DigitalOut myled(LED1);
+DigitalOut myled(LED1);
 DigitalIn button(PC_13);
-Serial pc(USBTX, USBRX);
+
 Serial uart(PA_2, PA_3);
+
 #define BPS 128000
 #define BITS 8
 #define STOP_BITS 1
  
 
 
-
-int main2(int argc, char *argv[]) {
-    
+int main(int argc, char *argv[]){
+    Serial pc(USBTX, USBRX);
     pc.baud(BPS);
     pc.format (BITS,SerialBase::None, STOP_BITS) ;
     
     myled=1;
     wait (5);
     myled=0;
-  //  short int m[8][320][3];
+    short int m[HEIGHT][WIDTH][3];
     int i,j,veces=0;
-    int ci,cj;
-/*for(veces=0;veces<120;veces++){
-    //char *m=(char *)malloc(sizeof(char)*HEIGHT*WIDTH*3);
-    for(ci=0;ci<8;ci++){
-       for(cj=0;cj<320;cj++){
+    
+for(veces=0;veces<120;veces++){
+    
+    myled=0;
+    for(i=0;i<8;i++){
+       for(j=0;j<320;j++){
                 
                 while(!pc.readable());
-                //*(m+i*WIDTH+j*3+0)=pc.getc();
-                    m[ci][cj][0]=(unsigned char)pc.getc();
-                    
-                    
-                    myled=0;
+                    m[i][j][0]=(char)pc.getc();
                     
-                
                 while(!pc.readable());   
-                    //*(m+i*WIDTH+j*3+1)=pc.getc();
-                    m[ci][cj][1]=(unsigned char)pc.getc();
+                    m[i][j][1]=(char)pc.getc();
                 while(!pc.readable());
-                    //*(m+i*WIDTH+j*3+2)=pc.getc();
-                    m[ci][cj][2]=(unsigned char)pc.getc();
+                    m[i][j][2]=(char)pc.getc();
         
         }
     }
         
         
-        myled=1;
+    myled=1;
 
-      //free(m);
-        
 
-    
-  
     rgb_to_yuv(m);
     
-    //pc.printf("Imagen trasladada a yuv \n");
 
-    int cont=1;
-    int matrix[8][8][3];
-    for(i=0;i<8;i+=8){
-        for(j=0;j<320;j+=8){
+ 
+    int mat[8][8][3];
+    for(i=0;i<HEIGHT;i+=8){
+        for(j=0;j<WIDTH;j+=8){
 
             int k=0,l=0;
 
@@ -78,82 +69,51 @@
                 for(l=j;l<j+8;l++){
                     
 
-                    matrix[k-i][l-j][0]=m[k][l][0];
-                    matrix[k-i][l-j][1]=m[k][l][1];
-                    matrix[k-i][l-j][2]=m[k][l][2];
+                    mat[k-i][l-j][0]=m[k][l][0];
+                    mat[k-i][l-j][1]=m[k][l][1];
+                    mat[k-i][l-j][2]=m[k][l][2];
                    
                 }
                
 
             }
-            //pc.printf("llamo a DCT %d \n",cont);
-            DCT(matrix,m,i,j);// i j índices de los pixeles en x e y del macrobloque
-            cont++;
-
-
+            
+            DCT(mat,m,i,j);// 'i' 'j' índices de los pixeles en x e y del macrobloque
 
         }
     
     }
-    //pc.printf("DCT \n");
 
-    
+   
     cuantizador(m);
 
-    //pc.printf("Cuantizada \n");
-    
+   
     short int *matriz =(short int *) malloc(sizeof(short int)*HEIGHT*WIDTH*3);
 
+    zig_zag(m,matriz);//OJO!!!!!
+
+    short int acumulador[3]={0,0,0};
+    RLC(matriz,acumulador);
     
-    zig_zag(m,matriz);
+    
+    short int * temp1= (short int *) malloc(sizeof(short int)*acumulador[0]);//reserva de memoria exacta para cada una de las componenetes y u v
+    short int * temp2= (short int *) malloc(sizeof(short int)*acumulador[1]);
+    short int * temp3= (short int *) malloc(sizeof(short int)*acumulador[2]);
+    RLC2(matriz,temp1,temp2,temp3);
+    free(matriz);
+
+    lora(temp1,acumulador[0],temp2,acumulador[1],temp3,acumulador[2]);
+    
+    
+    free(temp1);
+    free(temp2);
+    free(temp3);
+    while(!pc.writeable());
+    pc.printf("1");//OJO con ponerlo aqui arriba
 
 
-       
-    RLC(matriz);
-    unsigned char a=64;
-    pc.printf("%c",a);
-   
-}    
-        
-
-     /*   for(i=0;i<8;i++){
-            for(j=0;j<320;j++){//132 WORKS
-                while(!pc.writeable());
-                    //pc.printf("%c",*(m+i*WIDTH+j*3+0));
-                    pc.printf("%c",(char)m[i][j][0]);
-                    
+}
 
-                
-                while(!pc.writeable());
-                    //pc.printf("%c",*(m+i*WIDTH+j*3+1));
-                    pc.printf("%c",(char)m[i][j][1]);
-                    
-                while(!pc.writeable());
-                    //pc.printf("%c",*(m+i*WIDTH+j*3+2));
-                    pc.printf("%c",(char)m[i][j][2]);
-                   
-                    
-            } 
-        }*/
-    
-short int *mw =(short int *) malloc(sizeof(short int)*HEIGHT*WIDTH*3);
-int cont_y=4,cont_u=4,cont_v=4;
-int y=0,u=0,v=0;
-*(mw+y*3+0)=13;
-y++;
-*(mw+y*3+0)=13;
-y++;
-
-*(mw+u*3+1)=13;
-u++;
-*(mw+u*3+1)=13;
-u++;
-
-*(mw+v*3+2)=13;
-v++;
-*(mw+v*3+2)=13;
-v++;
-//lora(mw,&cont_y,&cont_u,&cont_v);
 
  //http://www.martin-gardner.co.uk/how-to-connect-your-old-sd-card-to-an-arduino/
     while(1){