Marisol Mánica
/
fotoprueba
Comprimir imagen
main.cpp@0:337a7c42ab62, 2015-11-09 (annotated)
- Committer:
- SolManB
- Date:
- Mon Nov 09 20:12:58 2015 +0000
- Revision:
- 0:337a7c42ab62
Para comprimir imagen
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
SolManB | 0:337a7c42ab62 | 1 | #include "mbed.h" |
SolManB | 0:337a7c42ab62 | 2 | #include<stdio.h> |
SolManB | 0:337a7c42ab62 | 3 | #include<string.h> |
SolManB | 0:337a7c42ab62 | 4 | #include<iostream> |
SolManB | 0:337a7c42ab62 | 5 | #include<fstream> |
SolManB | 0:337a7c42ab62 | 6 | #include<errno.h> |
SolManB | 0:337a7c42ab62 | 7 | |
SolManB | 0:337a7c42ab62 | 8 | DigitalOut myled(LED1); |
SolManB | 0:337a7c42ab62 | 9 | LocalFileSystem local("local"); |
SolManB | 0:337a7c42ab62 | 10 | |
SolManB | 0:337a7c42ab62 | 11 | using namespace std; |
SolManB | 0:337a7c42ab62 | 12 | int m=0; |
SolManB | 0:337a7c42ab62 | 13 | |
SolManB | 0:337a7c42ab62 | 14 | void send_image(){ |
SolManB | 0:337a7c42ab62 | 15 | |
SolManB | 0:337a7c42ab62 | 16 | FILE *picture; |
SolManB | 0:337a7c42ab62 | 17 | FILE *respaldo=NULL; |
SolManB | 0:337a7c42ab62 | 18 | int size, read_size, stat, packet_index; |
SolManB | 0:337a7c42ab62 | 19 | char send_buffer[10240], read_buffer[256]; |
SolManB | 0:337a7c42ab62 | 20 | packet_index = 1; |
SolManB | 0:337a7c42ab62 | 21 | |
SolManB | 0:337a7c42ab62 | 22 | picture = fopen("/local/PICT003.JPG", "r"); |
SolManB | 0:337a7c42ab62 | 23 | printf("Getting Picture Size\n"); |
SolManB | 0:337a7c42ab62 | 24 | |
SolManB | 0:337a7c42ab62 | 25 | //PAra el respaldoç |
SolManB | 0:337a7c42ab62 | 26 | respaldo = fopen("/local/respaldo.txt", "w"); |
SolManB | 0:337a7c42ab62 | 27 | if(picture == NULL) { |
SolManB | 0:337a7c42ab62 | 28 | printf("Error Opening Image File"); } |
SolManB | 0:337a7c42ab62 | 29 | |
SolManB | 0:337a7c42ab62 | 30 | fseek(picture, 0, SEEK_END); |
SolManB | 0:337a7c42ab62 | 31 | size = ftell(picture); |
SolManB | 0:337a7c42ab62 | 32 | fseek(picture, 0, SEEK_SET); |
SolManB | 0:337a7c42ab62 | 33 | printf("Total Picture size: %i\n",size); |
SolManB | 0:337a7c42ab62 | 34 | |
SolManB | 0:337a7c42ab62 | 35 | //Send Picture Size |
SolManB | 0:337a7c42ab62 | 36 | printf("Sending Picture Size\n"); |
SolManB | 0:337a7c42ab62 | 37 | fprintf(respaldo, "1. %d,\n\r",size); |
SolManB | 0:337a7c42ab62 | 38 | |
SolManB | 0:337a7c42ab62 | 39 | //Send Picture as Byte Array |
SolManB | 0:337a7c42ab62 | 40 | printf("Sending Picture as Byte Array\n"); |
SolManB | 0:337a7c42ab62 | 41 | |
SolManB | 0:337a7c42ab62 | 42 | int t=2; |
SolManB | 0:337a7c42ab62 | 43 | while(!feof(picture)) { |
SolManB | 0:337a7c42ab62 | 44 | //while(packet_index = 1){ |
SolManB | 0:337a7c42ab62 | 45 | //Read from the file into our send buffer |
SolManB | 0:337a7c42ab62 | 46 | read_size = fread(send_buffer, 1, sizeof(send_buffer)-1, picture); |
SolManB | 0:337a7c42ab62 | 47 | |
SolManB | 0:337a7c42ab62 | 48 | //Send data through our socket |
SolManB | 0:337a7c42ab62 | 49 | |
SolManB | 0:337a7c42ab62 | 50 | fprintf(respaldo,"%d. ",t); //checar |
SolManB | 0:337a7c42ab62 | 51 | while(m<read_size) |
SolManB | 0:337a7c42ab62 | 52 | { |
SolManB | 0:337a7c42ab62 | 53 | fprintf(respaldo,"%02hhx ",send_buffer[m]); |
SolManB | 0:337a7c42ab62 | 54 | m++; |
SolManB | 0:337a7c42ab62 | 55 | } |
SolManB | 0:337a7c42ab62 | 56 | fprintf(respaldo,",%d,\n",read_size); |
SolManB | 0:337a7c42ab62 | 57 | m=0; |
SolManB | 0:337a7c42ab62 | 58 | |
SolManB | 0:337a7c42ab62 | 59 | printf("Packet Number: %i\n",packet_index); |
SolManB | 0:337a7c42ab62 | 60 | printf("Packet Size Sent: %i\n",read_size); |
SolManB | 0:337a7c42ab62 | 61 | printf(" \n"); |
SolManB | 0:337a7c42ab62 | 62 | printf(" \n"); |
SolManB | 0:337a7c42ab62 | 63 | |
SolManB | 0:337a7c42ab62 | 64 | |
SolManB | 0:337a7c42ab62 | 65 | packet_index++; |
SolManB | 0:337a7c42ab62 | 66 | t++; |
SolManB | 0:337a7c42ab62 | 67 | //Zero out our send buffer |
SolManB | 0:337a7c42ab62 | 68 | |
SolManB | 0:337a7c42ab62 | 69 | } |
SolManB | 0:337a7c42ab62 | 70 | fclose(respaldo); |
SolManB | 0:337a7c42ab62 | 71 | fclose(picture); |
SolManB | 0:337a7c42ab62 | 72 | } |
SolManB | 0:337a7c42ab62 | 73 | |
SolManB | 0:337a7c42ab62 | 74 | int main() |
SolManB | 0:337a7c42ab62 | 75 | { |
SolManB | 0:337a7c42ab62 | 76 | send_image(); |
SolManB | 0:337a7c42ab62 | 77 | } |