求 帮助 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);
}