Tham khảo tài liệu 'nén ảnh part 2', công nghệ thông tin, đồ họa - thiết kế - flash phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | void main int i j N M loc k ind xt yt unsigned char v L gray table_length unsigned long int code table_code ctemp2 unsigned long int aux1 aux2 Lmask act_len flength unsigned char mask Len int ch unsigned char ctemp Ltemp float temp sum pt p big unsigned long int histo double nsq char file_name1 14 file_name2 14 FILE fptr fptro clrscr printf Enter file name of image -- scanf s file_name1 fptr fopen file_name1 rb if fptr NULL printf s does not exist. file_name1 exit 1 printf nEnter file name for compressed image -- scanf s file_name2 k stricmp file_name1 file_name2 if k 0 printf nInput and output files cannot share the same name. fcloseall exit 1 ind access file_name2 0 while ind k stricmp file_name1 file_name2 if k 0 321 gotoxy 1 8 printf Input and output files cannot share the same name. exit 1 gotoxy 1 4 printf File exists. Wish to overwrite y or n -- while ch getch y ch n putch ch switch ch case y ind 1 break case n gotoxy 1 4 printf gotoxy 1 3 printf gotoxy 1 3 printf Enter file name -- scanf s file_name2 ind access file_name2 0 fptro fopen file_name2 wb xt wherex yt wherey gotoxy 70 25 textattr RED LIGHTGRAY 4 BLINK cputs WAIT Generate histogram. histo unsigned long int malloc 256 sizeof long int for i 0 i 256 i histo i 0 while ch getc fptr EOF histo ch p float malloc 256 sizeof float gray unsigned char malloc 256 sizeof char 322 k 0 for i 0 i 256 i if histo i 0 p k float histo j gray k i k free histo N k Normalize. sum for i 0 i N i sum p i for i 0 i N i p i sum Rearranging the probability values in ascending order. for i 0 i N-1 i big p i loc i for j i 1 j N j if p j big big p i loc j if loc i continue else temp p i ctemp gray j p i p loc gray i gray loc p loc temp gray loc ctemp .