JPEG compressor

Dependencies:   SDL_lib SX1276Lib mbed

Revision:
0:1076a8b67c6c
Child:
1:f0c646dfe574
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/encoder.cpp	Wed Sep 07 18:47:02 2016 +0000
@@ -0,0 +1,169 @@
+//Author: Miguel Ruiz García
+//Company: University of Cantabria. 2016
+//mail: mrg47@alumnos.unican.es
+
+#include "mbed.h"
+#include "stdio.h"
+#include <math.h>
+#include "SDL_lib/SDL.h"
+#include "functions.h"
+
+//#include "MODSERIAL.h"
+//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[]) {
+    
+    pc.baud(BPS);
+    pc.format (BITS,SerialBase::None, STOP_BITS) ;
+    
+    myled=1;
+    wait (5);
+    myled=0;
+  //  short int m[8][320][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++){
+                
+                while(!pc.readable());
+                //*(m+i*WIDTH+j*3+0)=pc.getc();
+                    m[ci][cj][0]=(unsigned char)pc.getc();
+                    
+                    
+                    myled=0;
+                    
+                
+                while(!pc.readable());   
+                    //*(m+i*WIDTH+j*3+1)=pc.getc();
+                    m[ci][cj][1]=(unsigned char)pc.getc();
+                while(!pc.readable());
+                    //*(m+i*WIDTH+j*3+2)=pc.getc();
+                    m[ci][cj][2]=(unsigned char)pc.getc();
+        
+        }
+    }
+        
+        
+        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 k=0,l=0;
+
+            for(k=i;k<i+8;k++){
+                
+                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];
+                   
+                }
+               
+
+            }
+            //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++;
+
+
+
+        }
+    
+    }
+    //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);
+
+
+       
+    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){
+        
+        myled=1;
+        wait(0.2);
+        myled=0;
+        wait(0.2);
+    }
+    
+    
+}
+