| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 404 人关注过本帖
标题:求 帮助 C语言 读取 错误
只看楼主 加入收藏
xiaoyufeifei
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2011-9-25
结帖率:66.67%
收藏
 问题点数:0 回复次数:1 
求 帮助 C语言 读取 错误
#include <stdio.h>
#include <malloc.h>
#include <string.h>
#include <stdlib.h>


#define MB_SIZE        16
#define BLOCK_SIZE    8
#define PI (4.*atan(1.))
#define lines   176
#define clines  88

// image resolution
int  pels;   // number of pixel in a line (Y)
int  Lines;  // number of lines in a picture (Y)
int  im_size; // number of pixel in a picture (Y)

int num_hor_blocks;  // number of the blocks in the horizontal direction;
int num_ver_blocks;  // number of the blocks in the vertical direction;

int  cpels;   // number of pixel in a line (Cb or Cr)
int  cim_size; // number of pixel in a picture (Cb or Cr)

int *p_quant;

// initialize picture parameters
void Initialize (char inf[100], char outf[100], char *argv[], int *p_quant);
void ReadImage (char inf[100], unsigned char *lum[lines], unsigned char *cb[clines], unsigned char *cr[clines]);
void WriteImage (char outf[100], unsigned char *lum[lines], unsigned char *cb[clines], unsigned char *cr[clines]);

void main (int argc, char *argv[])
{
    unsigned char *lum1[lines], *cb1[clines], *cr1[clines];
    unsigned char *lum2[lines], *cb2[clines], *cr2[clines];
    char inputfile_original[100];
    char inputfile_distorted[100];
    int i, j;
    double sum;


    Initialize (inputfile_original, inputfile_distorted, argv, p_quant);


    for (i = 0; i < lines; i++)
    {
        *(lum1+i) = (unsigned char *)malloc(pels*sizeof(unsigned char));
        *(lum2+i) = (unsigned char *)malloc(pels*sizeof(unsigned char));
    }
    for (i = 0; i < clines; i++)
    {
        *(cb1+i) = (unsigned char *)malloc(cpels*sizeof(unsigned char));
        *(cb2+i) = (unsigned char *)malloc(cpels*sizeof(unsigned char));
        *(cr1+i) = (unsigned char *)malloc(cpels*sizeof(unsigned char));
        *(cr2+i) = (unsigned char *)malloc(cpels*sizeof(unsigned char));

    }

    ReadImage (inputfile_original, lum1, cb1, cr1);
        

    sum = 0.;
    WriteImage (inputfile_distorted, lum1, cb1, cr1);

   
    free (lum1[pels]);
    free (cb1[cpels]);
    free (cr1[cpels]);
    free (lum2[pels]);
    free (cb2[cpels]);
    free (cr2[cpels]);

    return;
}

void Initialize (char inf[100], char outf[100], char *argv[], int *p_quant)
{
   
    pels = 176;
    Lines = 144;

    cpels = pels/2;
//    clines = Lines/2;

    num_hor_blocks = pels/BLOCK_SIZE;
    num_ver_blocks = lines/BLOCK_SIZE;

    im_size = pels*lines;
    cim_size = cpels*clines;
  
    strcpy (inf, argv[1]);
    strcpy (outf, argv[2]);
    //*p_quant = atoi(argv[3]);

   
    return ;
}

void ReadImage (char inf[100], unsigned char *lum[lines], unsigned char *cb[clines], unsigned char *cr[clines])
{
    FILE *fin = NULL;
    int i;

    fin = fopen (inf, "rb");
    if (fin == NULL)
    {
        fprintf(stderr,"\n%s file open failure !!!\n", inf);
        exit (0);
    }
    for (i = 0; i < lines; i ++)
        fread (*(lum + i), sizeof(unsigned char), pels, fin);
    for (i = 0; i < clines; i ++)
    {
        fread (*(cb + i),  sizeof(unsigned char), cpels, fin);
        fread (*(cr + i),  sizeof(unsigned char), cpels, fin);
    }
   

    fclose (fin);
}


void WriteImage (char outf[100], unsigned char *lum[lines], unsigned char *cb[clines], unsigned char *cr[clines])
{
    FILE *fout = NULL;
    int i;

    fout = fopen (outf, "wb");
    if (fout == NULL)
    {
        fprintf(stderr,"\n%s file open failure !!!\n", outf);
        exit (0);
    }
    for (i = 0; i < lines; i ++)
        fwrite (*(lum + i), sizeof(unsigned char), pels, fout);
    for (i = 0; i < clines; i ++)
    {
        fwrite (*(cb + i),  sizeof(unsigned char), clines, fout);
        fwrite (*(cr + i),  sizeof(unsigned char), clines, fout);
    }


    fclose (fout);
}
搜索更多相关主题的帖子: horizontal direction vertical include number 
2012-06-19 13:31
xiaoyufeifei
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2011-9-25
收藏
得分:0 
在线等 非常感谢 ~~~~~
2012-06-19 13:32
快速回复:求 帮助 C语言 读取 错误
数据加载中...
 
   



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

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