JPEG compressor
Dependencies: SDL_lib SX1276Lib mbed
encoder.cpp@1:f0c646dfe574, 2016-09-22 (annotated)
- Committer:
- miruga27
- Date:
- Thu Sep 22 00:01:55 2016 +0000
- Revision:
- 1:f0c646dfe574
- Parent:
- 0:1076a8b67c6c
- Child:
- 2:f256eebcade8
H261_encoder
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
miruga27 | 1:f0c646dfe574 | 1 | |
miruga27 | 0:1076a8b67c6c | 2 | //Author: Miguel Ruiz García |
miruga27 | 0:1076a8b67c6c | 3 | //Company: University of Cantabria. 2016 |
miruga27 | 0:1076a8b67c6c | 4 | //mail: mrg47@alumnos.unican.es |
miruga27 | 0:1076a8b67c6c | 5 | |
miruga27 | 0:1076a8b67c6c | 6 | #include "mbed.h" |
miruga27 | 0:1076a8b67c6c | 7 | #include "stdio.h" |
miruga27 | 0:1076a8b67c6c | 8 | #include <math.h> |
miruga27 | 0:1076a8b67c6c | 9 | #include "SDL_lib/SDL.h" |
miruga27 | 0:1076a8b67c6c | 10 | #include "functions.h" |
miruga27 | 1:f0c646dfe574 | 11 | //#include "lora2.h" |
miruga27 | 1:f0c646dfe574 | 12 | #include "lora_tansc.h" |
miruga27 | 0:1076a8b67c6c | 13 | |
miruga27 | 1:f0c646dfe574 | 14 | DigitalOut myled(LED1); |
miruga27 | 0:1076a8b67c6c | 15 | DigitalIn button(PC_13); |
miruga27 | 1:f0c646dfe574 | 16 | |
miruga27 | 0:1076a8b67c6c | 17 | Serial uart(PA_2, PA_3); |
miruga27 | 1:f0c646dfe574 | 18 | |
miruga27 | 0:1076a8b67c6c | 19 | #define BPS 128000 |
miruga27 | 0:1076a8b67c6c | 20 | #define BITS 8 |
miruga27 | 0:1076a8b67c6c | 21 | #define STOP_BITS 1 |
miruga27 | 0:1076a8b67c6c | 22 | |
miruga27 | 0:1076a8b67c6c | 23 | |
miruga27 | 0:1076a8b67c6c | 24 | |
miruga27 | 1:f0c646dfe574 | 25 | int main(int argc, char *argv[]){ |
miruga27 | 1:f0c646dfe574 | 26 | Serial pc(USBTX, USBRX); |
miruga27 | 0:1076a8b67c6c | 27 | pc.baud(BPS); |
miruga27 | 0:1076a8b67c6c | 28 | pc.format (BITS,SerialBase::None, STOP_BITS) ; |
miruga27 | 0:1076a8b67c6c | 29 | |
miruga27 | 0:1076a8b67c6c | 30 | myled=1; |
miruga27 | 0:1076a8b67c6c | 31 | wait (5); |
miruga27 | 0:1076a8b67c6c | 32 | myled=0; |
miruga27 | 1:f0c646dfe574 | 33 | short int m[HEIGHT][WIDTH][3]; |
miruga27 | 0:1076a8b67c6c | 34 | int i,j,veces=0; |
miruga27 | 1:f0c646dfe574 | 35 | |
miruga27 | 1:f0c646dfe574 | 36 | for(veces=0;veces<120;veces++){ |
miruga27 | 1:f0c646dfe574 | 37 | |
miruga27 | 1:f0c646dfe574 | 38 | myled=0; |
miruga27 | 1:f0c646dfe574 | 39 | for(i=0;i<8;i++){ |
miruga27 | 1:f0c646dfe574 | 40 | for(j=0;j<320;j++){ |
miruga27 | 0:1076a8b67c6c | 41 | |
miruga27 | 0:1076a8b67c6c | 42 | while(!pc.readable()); |
miruga27 | 1:f0c646dfe574 | 43 | m[i][j][0]=(char)pc.getc(); |
miruga27 | 0:1076a8b67c6c | 44 | |
miruga27 | 0:1076a8b67c6c | 45 | while(!pc.readable()); |
miruga27 | 1:f0c646dfe574 | 46 | m[i][j][1]=(char)pc.getc(); |
miruga27 | 0:1076a8b67c6c | 47 | while(!pc.readable()); |
miruga27 | 1:f0c646dfe574 | 48 | m[i][j][2]=(char)pc.getc(); |
miruga27 | 0:1076a8b67c6c | 49 | |
miruga27 | 0:1076a8b67c6c | 50 | } |
miruga27 | 0:1076a8b67c6c | 51 | } |
miruga27 | 0:1076a8b67c6c | 52 | |
miruga27 | 0:1076a8b67c6c | 53 | |
miruga27 | 1:f0c646dfe574 | 54 | myled=1; |
miruga27 | 0:1076a8b67c6c | 55 | |
miruga27 | 0:1076a8b67c6c | 56 | |
miruga27 | 0:1076a8b67c6c | 57 | rgb_to_yuv(m); |
miruga27 | 0:1076a8b67c6c | 58 | |
miruga27 | 0:1076a8b67c6c | 59 | |
miruga27 | 1:f0c646dfe574 | 60 | |
miruga27 | 1:f0c646dfe574 | 61 | int mat[8][8][3]; |
miruga27 | 1:f0c646dfe574 | 62 | for(i=0;i<HEIGHT;i+=8){ |
miruga27 | 1:f0c646dfe574 | 63 | for(j=0;j<WIDTH;j+=8){ |
miruga27 | 0:1076a8b67c6c | 64 | |
miruga27 | 0:1076a8b67c6c | 65 | int k=0,l=0; |
miruga27 | 0:1076a8b67c6c | 66 | |
miruga27 | 0:1076a8b67c6c | 67 | for(k=i;k<i+8;k++){ |
miruga27 | 0:1076a8b67c6c | 68 | |
miruga27 | 0:1076a8b67c6c | 69 | for(l=j;l<j+8;l++){ |
miruga27 | 0:1076a8b67c6c | 70 | |
miruga27 | 0:1076a8b67c6c | 71 | |
miruga27 | 1:f0c646dfe574 | 72 | mat[k-i][l-j][0]=m[k][l][0]; |
miruga27 | 1:f0c646dfe574 | 73 | mat[k-i][l-j][1]=m[k][l][1]; |
miruga27 | 1:f0c646dfe574 | 74 | mat[k-i][l-j][2]=m[k][l][2]; |
miruga27 | 0:1076a8b67c6c | 75 | |
miruga27 | 0:1076a8b67c6c | 76 | } |
miruga27 | 0:1076a8b67c6c | 77 | |
miruga27 | 0:1076a8b67c6c | 78 | |
miruga27 | 0:1076a8b67c6c | 79 | } |
miruga27 | 1:f0c646dfe574 | 80 | |
miruga27 | 1:f0c646dfe574 | 81 | DCT(mat,m,i,j);// 'i' 'j' índices de los pixeles en x e y del macrobloque |
miruga27 | 0:1076a8b67c6c | 82 | |
miruga27 | 0:1076a8b67c6c | 83 | } |
miruga27 | 0:1076a8b67c6c | 84 | |
miruga27 | 0:1076a8b67c6c | 85 | } |
miruga27 | 0:1076a8b67c6c | 86 | |
miruga27 | 1:f0c646dfe574 | 87 | |
miruga27 | 0:1076a8b67c6c | 88 | cuantizador(m); |
miruga27 | 0:1076a8b67c6c | 89 | |
miruga27 | 1:f0c646dfe574 | 90 | |
miruga27 | 0:1076a8b67c6c | 91 | short int *matriz =(short int *) malloc(sizeof(short int)*HEIGHT*WIDTH*3); |
miruga27 | 0:1076a8b67c6c | 92 | |
miruga27 | 1:f0c646dfe574 | 93 | zig_zag(m,matriz);//OJO!!!!! |
miruga27 | 1:f0c646dfe574 | 94 | |
miruga27 | 1:f0c646dfe574 | 95 | short int acumulador[3]={0,0,0}; |
miruga27 | 1:f0c646dfe574 | 96 | RLC(matriz,acumulador); |
miruga27 | 0:1076a8b67c6c | 97 | |
miruga27 | 1:f0c646dfe574 | 98 | |
miruga27 | 1:f0c646dfe574 | 99 | short int * temp1= (short int *) malloc(sizeof(short int)*acumulador[0]);//reserva de memoria exacta para cada una de las componenetes y u v |
miruga27 | 1:f0c646dfe574 | 100 | short int * temp2= (short int *) malloc(sizeof(short int)*acumulador[1]); |
miruga27 | 1:f0c646dfe574 | 101 | short int * temp3= (short int *) malloc(sizeof(short int)*acumulador[2]); |
miruga27 | 1:f0c646dfe574 | 102 | RLC2(matriz,temp1,temp2,temp3); |
miruga27 | 1:f0c646dfe574 | 103 | free(matriz); |
miruga27 | 1:f0c646dfe574 | 104 | |
miruga27 | 1:f0c646dfe574 | 105 | lora(temp1,acumulador[0],temp2,acumulador[1],temp3,acumulador[2]); |
miruga27 | 1:f0c646dfe574 | 106 | |
miruga27 | 1:f0c646dfe574 | 107 | |
miruga27 | 1:f0c646dfe574 | 108 | free(temp1); |
miruga27 | 1:f0c646dfe574 | 109 | free(temp2); |
miruga27 | 1:f0c646dfe574 | 110 | free(temp3); |
miruga27 | 1:f0c646dfe574 | 111 | while(!pc.writeable()); |
miruga27 | 1:f0c646dfe574 | 112 | pc.printf("1");//OJO con ponerlo aqui arriba |
miruga27 | 0:1076a8b67c6c | 113 | |
miruga27 | 0:1076a8b67c6c | 114 | |
miruga27 | 1:f0c646dfe574 | 115 | } |
miruga27 | 0:1076a8b67c6c | 116 | |
miruga27 | 0:1076a8b67c6c | 117 | |
miruga27 | 0:1076a8b67c6c | 118 | //http://www.martin-gardner.co.uk/how-to-connect-your-old-sd-card-to-an-arduino/ |
miruga27 | 0:1076a8b67c6c | 119 | while(1){ |
miruga27 | 0:1076a8b67c6c | 120 | |
miruga27 | 0:1076a8b67c6c | 121 | myled=1; |
miruga27 | 0:1076a8b67c6c | 122 | wait(0.2); |
miruga27 | 0:1076a8b67c6c | 123 | myled=0; |
miruga27 | 0:1076a8b67c6c | 124 | wait(0.2); |
miruga27 | 0:1076a8b67c6c | 125 | } |
miruga27 | 0:1076a8b67c6c | 126 | |
miruga27 | 0:1076a8b67c6c | 127 | |
miruga27 | 0:1076a8b67c6c | 128 | } |
miruga27 | 0:1076a8b67c6c | 129 |