/* *************************************************************** */ int main(int argc, char * argv[]) { initCode(); int i=1; int isEncode = 1; PBLOC pbloc, pPrevLINK; PNOEUD pNoeud,pNext; srcFile = fopen(argv[1],"r"); if (srcFile==NULL) { printf("Il faut entrer le nom de fichier source ! \n"); exit(1); } srcFileNO = fileno(srcFile); rewind(srcFile); /* mettre le pointeur au debut du fichier */ strcpy(nomS,"CODE_SORTIE_DECOMP_"); strcat(nomS,argv[1]); if ((destFile = fopen(nomS,"w"))==NULL) { printf("Erreur : fopen destFile ! \n"); exit(1); } destFileNO = fileno(destFile); /* init arbre huffman - racine */ while(pow(2,(E+1))<=256) E++; R = 256 - (int)pow(2,E); racine.numNo = 2*256-1; racine.pPere = NULL; pNYT = &racine; decompression(); if(destFile) fclose(destFile); if(srcFile) fclose(srcFile); if(pNYT && pNYT != &racine) free(pNYT); pbloc = racine.pbloc; while(pbloc) { pNoeud = pbloc->pPrem; while(pNoeud) { pNext = pNoeud->pPrev; if(pNoeud != &racine) free(pNoeud); pNoeud = pNext; } pPrevLINK = pbloc->pPrev; free(pbloc); pbloc = pPrevLINK; } printf("\n\n%s est compresse dans le fichier '%s' par methode huffman diynamique\n",argv[1],nomS); return EXIT_SUCCESS; }
int main(int argc, char *argv[]) { int continuer = 1; Commande *commande = malloc(sizeof(commande)); initialiseCommande(commande); // signal(SIGINT, interrupt); Niveau *niveau = malloc(sizeof(niveau)); decompression(choixNiveau(argc, argv), commande, niveau); /*** */ struct sigaction act; memset (&act, '\0', sizeof(act)); /* Use the sa_sigaction field because the handles has two additional parameters */ act.sa_sigaction = &hdl; /* The SA_SIGINFO flag tells sigaction() to use the sa_sigaction field, not sa_handler. */ act.sa_flags = SA_SIGINFO; if (sigaction(SIGINT, &act, NULL) < 0) { perror ("sigaction"); return 1; } /**** */ int ch; int finCommande = 0; initscr(); idlok(stdscr, TRUE); scrollok(stdscr, TRUE); cbreak(); noecho(); keypad(stdscr, TRUE); intrflush(stdscr, FALSE); printw("nom : %s\n", niveau->nom); int x, y; int nbAppuiUp = 0; char *saisie; while(continuer){ finCommande = 0; saisie = malloc(TAILLE_MAX_COMMANDE*sizeof(char)); debutLigne(commande, niveau); while(finCommande == 0){ ch = wgetch(stdscr); if(ch != KEY_UP && ch !=KEY_DOWN) nbAppuiUp = 0; if (ch == KEY_BACKSPACE) { getyx(stdscr, y, x); if(x > strlen(commande->directory)+3){ move(y, x-1); delch(); strcpy(saisie, substr(saisie, 0, strlen(saisie)-1)); } } else if(ch == KEY_LEFT){ getyx(stdscr, y, x); move(y, x-1); } else if(ch == KEY_RIGHT){ getyx(stdscr, y, x); move(y, x+1); } else if (ch == KEY_UP) { nbAppuiUp++; String *temp = malloc(sizeof(String)); temp = niveau->history->premier; if (temp->suivant != NULL) { int i = 0; while(i < nbAppuiUp && temp->suivant != NULL){ temp = temp->suivant; i++; } free(saisie); saisie = malloc(sizeof(char)*TAILLE_MAX_COMMANDE); strcpy(saisie, temp->string); effaceCommande(commande); printw("%s", saisie); } } else if (ch == KEY_DOWN) { nbAppuiUp--; String *temp = malloc(sizeof(String)); temp = niveau->history->premier; if (temp->suivant != NULL) { int i = 0; while(i < nbAppuiUp && temp->suivant != NULL){ temp = temp->suivant; i++; } free(saisie); saisie = malloc(sizeof(char)*TAILLE_MAX_COMMANDE); strcpy(saisie, temp->string); effaceCommande(commande); printw("%s", saisie); } } else if(ch == KEY_DC){ delch(); strcpy(saisie, substr(saisie, 0, strlen(saisie)-1)); } else if(ch == '\t'){ effaceCommande(commande); char *essai = malloc(sizeof(char)*TAILLE_MAX_COMMANDE); if(strlen(autoComplete(saisie, niveau)) == 0) finCommande = 1; else{ strcpy(saisie, strcat(saisie, autoComplete(saisie, niveau))); printw("%s", saisie); } } else if(ch == '\n'){ finCommande = 1; printw("\n"); } else{ printw("%c", ch); sprintf(saisie, "%s%c", saisie, ch); } } strcpy(commande->commande, saisie); execution(commande, niveau); // free(saisie); } endwin(); return 0; }
void ImageMDCodec::decode(const MDStream* md_stream, AbstractStream* stream) const { if (!md_stream->is_empty()) { vector<pixel_container> took_stream; Uint8 flows_number = md_stream->get_flows_number(); Uint32 sequences_number = md_stream->get_sequences_number(); Uint16 image_width, image_height; Uint8 bpp = 0; bool null_pixel_present = false; for (Uint8 i=0; i<flows_number; i++) { Uint64 offset = 0; Uint16 payload_size = 0; for (Uint32 j=0; j<sequences_number; j++) { Descriptor* descriptor = new Descriptor(); if (md_stream->get_descriptor(i, j, descriptor) && (descriptor->get_codec_name()=="image")) { payload_size = descriptor->get_payload_size(); if (md_stream->is_valid(descriptor->get_flow_id(), descriptor->get_sequence_number())) { MemDataChunk* payload = decompression(descriptor->get_payload(), payload_size); payload_size = payload->get_lenght(); took_stream.resize(flows_number*sequences_number*(payload_size+1)); ImageCodecParameters* icp = dynamic_cast<ImageCodecParameters*>(descriptor->get_codec_parameter()); image_width = icp->get_width(); image_height = icp->get_height(); bpp = icp->get_bits_per_pixel(); if (bpp == 24) { Uint32 k; Uint32 pixels_in_payload = payload_size/3; DataChunkIterator it = payload->get_iterator(); for (k=0; k<pixels_in_payload; k++) { pixel_container curr_pixel; Uint8 r,g,b; it.get_Uint8(r); it.get_Uint8(g); it.get_Uint8(b); curr_pixel.set_r(r); curr_pixel.set_g(g); curr_pixel.set_b(b); Uint32 locate_position = offset+i+(k*flows_number); took_stream[locate_position] = curr_pixel; } offset += flows_number*k; } delete payload; } } else { Uint32 k; Uint32 pixels_in_payload = payload_size/3; for (k=0; k<pixels_in_payload; k++) { Uint32 locate_position = offset+i+(k*flows_number); took_stream[locate_position] = m_null_pixel; } offset += flows_number*k; null_pixel_present = true; } } } Uint32 pixel_number = image_width*image_height; MemDataChunk* final_pixels= new MemDataChunk(); final_pixels->resize(pixel_number*3); for (Uint32 i=0; i<pixel_number; i++) { MemDataChunk* pixel = &(took_stream[i].serialize()); final_pixels->set_data_chunk(i*3, pixel); delete pixel; } dynamic_cast<ImageStream*>(stream)->set_width(image_width); dynamic_cast<ImageStream*>(stream)->set_height(image_height); dynamic_cast<ImageStream*>(stream)->set_bits_per_pixel(bpp); dynamic_cast<ImageStream*>(stream)->set_null_pixel_presence(null_pixel_present); stream->set_data(*final_pixels); delete final_pixels; } }
int main(int argc, char *argv[]) { int len, ret, fd, mode; char *buf = NULL, *infile = NULL, *outfile = NULL; unsigned int file_len; struct timeval tv_start, tv_end; if (argc != 4 || argv[1][0] != '-' || (len = strlen(argv[1])) <= 1) return usage(argv[0]); mode = 0; ret = 1; // skip '-' while (ret < len) { switch (argv[1][ret++]) { case 'c': if (mode & MODE_DECOMPRESSION) return usage(argv[0]); mode |= MODE_COMPRESSION; break; case 'x': if (mode & MODE_COMPRESSION) return usage(argv[0]); mode |= MODE_DECOMPRESSION; break; case 'd': mode |= MODE_DELETE; break; case 't': mode |= MODE_TIME; break; default : return usage(argv[0]); break; } } infile = argv[2]; outfile = argv[3]; if ((mode & MODE_TIME) && gettimeofday(&tv_start, NULL)) { perror("fail to do gettimeofday"); return -1; } //init_log(); if (mode & MODE_COMPRESSION) { // Compression if ((fd = open(infile, O_RDONLY)) < 0 || (file_len = lseek(fd, 0, SEEK_END)) == 0 || (file_len & 0x80000000) || lseek(fd, 0, SEEK_SET) < 0) { perror("Fail to open SRC_FILE."); return 0; } if (!(buf= (char *)malloc(file_len * (sizeof(char))))) { perror("Fail to malloc for buf"); return 0; } len = 0; while (len < file_len) { if ((ret = read(fd, buf+len, file_len-len)) <= 0) { close(fd); perror("Fail to read SRC_FILE."); return 0; } len += ret; } close(fd); ret = compression(outfile, buf, file_len); free(buf); if (ret) { printf("Error to ArithmeticCoding\n"); return -1; } } else if (mode & MODE_DECOMPRESSION) { // Decompression if (decompression(infile, outfile)) { //log(LOG_USER | LOG_ERR , "%s : Fail to huffman_decompression", __func__); return -1; } } #ifdef Debug printf("Good !\n"); #else //unlink(LOG_FILE); #endif if (mode & MODE_DELETE) unlink(infile); if (mode & MODE_TIME) { if (gettimeofday(&tv_end, NULL)) { perror("\nArithmeticCoding done, But fail to get time."); } else { if (tv_end.tv_usec < tv_start.tv_usec) { tv_end.tv_usec = 1000000 + tv_end.tv_usec - tv_start.tv_usec; tv_end.tv_sec -= tv_start.tv_sec + 1; } else { tv_end.tv_usec -= tv_start.tv_usec; tv_end.tv_sec -= tv_start.tv_sec; } fprintf(stderr, "\nArithmeticCoding done time : %us %ums\n", tv_end.tv_sec, (tv_end.tv_usec)/1000); fflush(stderr); } } return 0; }