JPEG compressor
Dependencies: SDL_lib SX1276Lib mbed
encoder.cpp
- Committer:
- miruga27
- Date:
- 2017-01-11
- Revision:
- 2:f256eebcade8
- Parent:
- 1:f0c646dfe574
File content as of revision 2:f256eebcade8:
//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 "lora2.h" //#include "sx1276-hal.h" //#include "debug.h" #include "lora_tansc.h" //DigitalOut led(LED1); DigitalIn button(PC_13); //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; 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++){ //myled=0; for(i=0;i<8;i++){ for(j=0;j<320;j++){ while(!pc.readable()); m[i][j][0]=(char)pc.getc(); while(!pc.readable()); m[i][j][1]=(char)pc.getc(); while(!pc.readable()); m[i][j][2]=(char)pc.getc(); } } //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){ int k=0,l=0; for(k=i;k<i+8;k++){ for(l=j;l<j+8;l++){ 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]; } } 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!!!!! //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]);//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*/ 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){ led=1; wait(0.5); led=0; wait(0.5); } }