| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 592 人关注过本帖
标题:用行程编码压缩图片后,海明码检错、纠错(随机生成一位出错),再用行程编 ...
只看楼主 加入收藏
你是我的菜
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2010-6-6
收藏
 问题点数:0 回复次数:0 
用行程编码压缩图片后,海明码检错、纠错(随机生成一位出错),再用行程编码解压图片? 求海明码代码~
RT..
#include <stdio.h>   
#include <stdlib.h>   
int compress(int argc, char *argv[])   
{   
    FILE *imageFile,*outFile;   
   int i, data, nextData;   
   int n = 0;   
    if ((imageFile = fopen("123.bmp","rb")) == NULL) {   
        printf("can't open 123.bmp\n");   
        exit(1);   
    }   
   if ((outFile = fopen("123.cod","wb")) == NULL) {   
        printf("can't open 123.cod\n");   
       exit(1);   
    }  
    while (!feof(imageFile))   
    {  
        data = fgetc(imageFile);   
       n++;      
       if (n >= 1078) {   
            n = 1;   
            //first identifer---white pixel or black pixel   
           fputc(data, outFile);   
            while (!feof(imageFile)) {   
               nextData = fgetc(imageFile);   
                if (data != nextData) {   
                   //output two bytes   
                    //the first one is Low byte   
                    fputc(n % 256, outFile);   
                    //the second one is High byte   
                   n /= 256;   
                   fputc(n, outFile);   
                    n = 0;   
                   //exchange   
                    data = nextData;   
                }   
                n++;   
            }   
            goto closeFile;   
        }   
        fputc((char)data,outFile);   
    }   
closeFile:   
    if (fclose(imageFile)) exit(1);   
   if (fclose(outFile)) exit(1);   
  
    system("pause");   
    return 0;   
}

int haiming(int argc, char *argv[])
{      

 }

int decompress(int argc, char *argv[])   
{   
   FILE *imageZipFile,*outFile;   
   int i, data, nextData, identifer;   
    int m = 0;   
  
    if ((imageZipFile = fopen("123.cod", "rb")) == NULL) {   
        printf("can't open 123.cod\n");   
        exit(1);   
    }   
    if ((outFile = fopen("Recovery123.bmp", "wb")) == NULL) {   
        printf("can't open Recovery123.bmp\n");   
        exit(1);   
    }   
    while (!feof(imageZipFile))   
    {   
       data = fgetc(imageZipFile);   
       m++;      
        if (m >= 1078) {   
            identifer = data;   
           while (!feof(imageZipFile)) {   
               data = fgetc(imageZipFile);   
                nextData = fgetc(imageZipFile);   
              m = nextData * 256 + data;   
                for (i = 0; i < m; i++) {   
                   fputc(identifer, outFile);   
               }   
               identifer ^= 0x00ff;   
           }   
            goto closeFile;   
       }   
       fputc((char)data,outFile);   
    }   
closeFile:   
    if (fclose(imageZipFile)) exit(1);   
    if (fclose(outFile)) exit(1);   
  
    system("pause");   
    return 0;   
}  

int main(){
    int compress();
    int haiming();
    int decompress();
}

[ 本帖最后由 你是我的菜 于 2010-6-6 16:52 编辑 ]
搜索更多相关主题的帖子: 检错 明码 行程 随机 纠错 
2010-06-06 15:58
快速回复:用行程编码压缩图片后,海明码检错、纠错(随机生成一位出错),再用行 ...
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.019040 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved