JPEG compressor

Dependencies:   SDL_lib SX1276Lib mbed

Revision:
2:f256eebcade8
Parent:
1:f0c646dfe574
--- a/encoder.cpp	Thu Sep 22 00:01:55 2016 +0000
+++ b/encoder.cpp	Wed Jan 11 20:20:00 2017 +0000
@@ -8,34 +8,36 @@
 #include <math.h>
 #include "SDL_lib/SDL.h"
 #include "functions.h"
-//#include "lora2.h"
+#include "lora2.h"
+//#include "sx1276-hal.h"
+//#include "debug.h"
 #include "lora_tansc.h"
 
-DigitalOut myled(LED1);
+//DigitalOut led(LED1);
 DigitalIn button(PC_13);
 
-Serial uart(PA_2, PA_3);
+//Serial uart(PA_2, PA_3);
 
 #define BPS 128000
 #define BITS 8
 #define STOP_BITS 1
  
 
-
 int main(int argc, char *argv[]){
     Serial pc(USBTX, USBRX);
     pc.baud(BPS);
     pc.format (BITS,SerialBase::None, STOP_BITS) ;
+
+    /*led=1;
     
-    myled=1;
-    wait (5);
-    myled=0;
+    wait (2);
+    led=!led;*/
     short int m[HEIGHT][WIDTH][3];
     int i,j,veces=0;
+    //debug( "start of transmission...\r\n" );
+for(veces=0;veces<30;veces++){
     
-for(veces=0;veces<120;veces++){
-    
-    myled=0;
+    //myled=0;
     for(i=0;i<8;i++){
        for(j=0;j<320;j++){
                 
@@ -49,15 +51,15 @@
         
         }
     }
-        
+    
         
-    myled=1;
+    //myled=1;
 
 
     rgb_to_yuv(m);
     
 
- 
+     //debug( "DCT...\r\n" );
     int mat[8][8][3];
     for(i=0;i<HEIGHT;i+=8){
         for(j=0;j<WIDTH;j+=8){
@@ -79,51 +81,89 @@
             }
             
             DCT(mat,m,i,j);// 'i' 'j' índices de los pixeles en x e y del macrobloque
-
+ 
         }
     
     }
 
-   
+    //debug( "CUANTIZAR...\r\n" );   
     cuantizador(m);
 
    
     short int *matriz =(short int *) malloc(sizeof(short int)*HEIGHT*WIDTH*3);
-
+    //debug( "zig-zag...\r\n" );
     zig_zag(m,matriz);//OJO!!!!!
-
-    short int acumulador[3]={0,0,0};
+    //debug( "rlc...\r\n" );
+    short int acumulador[3]={0x0000,0x0000,0x0000};
     RLC(matriz,acumulador);
     
     
     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]);
+    short int * temp2= (short int *) malloc(sizeof(short int)*acumulador[1]);//U
+    short int * temp3= (short int *) malloc(sizeof(short int)*acumulador[2]);//V
+
     RLC2(matriz,temp1,temp2,temp3);
     free(matriz);
 
+    /*acumulador[0]=20;
+    acumulador[1]=20;
+    acumulador[2]=20;*/
     lora(temp1,acumulador[0],temp2,acumulador[1],temp3,acumulador[2]);
-    
+    //debug( "end of transmission...\r\n" );
+
+
     
     free(temp1);
     free(temp2);
     free(temp3);
+    
     while(!pc.writeable());
-    pc.printf("1");//OJO con ponerlo aqui arriba
+    pc.printf("1");//OJO con ponerlo aqui arriba*/
+    
+    char h;
+    h=acumulador[0]&0xff;
+    
+    while(!pc.writeable());
+    pc.printf("%c",h);
+    
+    h=(acumulador[0]>>8) & 0xff;
+    
+    while(!pc.writeable());
+    pc.printf("%c",h);
+
 
 
+    h=acumulador[1]&0xff;
+    
+    while(!pc.writeable());
+    pc.printf("%c",h);
+    
+    h=(acumulador[1]>>8)&0xff;
+    
+    while(!pc.writeable());
+    pc.printf("%c",h);
+    
+    
+    h=acumulador[2]&0xff;
+    
+    while(!pc.writeable());
+    pc.printf("%c",h);
+    
+    h=(acumulador[2]>>8)&0xff;
+    
+    while(!pc.writeable());
+    pc.printf("%c",h);//OJO con ponerlo aqui arriba
 }
-
+fuera:
 
  //http://www.martin-gardner.co.uk/how-to-connect-your-old-sd-card-to-an-arduino/
+    DigitalOut led(LED1);
     while(1){
         
-        myled=1;
-        wait(0.2);
-        myled=0;
-        wait(0.2);
+        led=1;
+        wait(0.5);
+        led=0;
+        wait(0.5);
     }
     
-    
 }
-