[ create a new paste ] login | about

Link: http://codepad.org/oNUxByE7    [ raw code | output | fork ]

C, pasted on Nov 21:
//画像処理のプログラム
//カラー画像を読み込みRGBの3枚のグレースケールから
//HSVの3枚のグレースケールを出力するプログラムを作成してほしいです。
//下記のプログラムは途中が間違っていますが改良をお願いします。

#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
  FILE *fp;
int i,j;
unsigned char buf[2];
unsigned short *data;
int w,h;

 w = atoi (argv[1]);
 h = atoi (argv[2]);

data=(unsigned short*)malloc(sizeof(unsigned short)*w*h);
fp=fopen(argv[3],"rb");
fseek(fp,512,SEEK_SET);
for(j=0; j<h; j++){
  for(i=0; i<w; i++){
    fread((char*)buf,2,1,fp);
    data[i+j*h]=(unsigned short)(buf[0]<<8)|buf[1];
  }
 }
 fclose(fp);

for(i=0; i<w*h; i++){
  data[i]/=4;
 }


 fp=fopen(argv[4],"wb");
 fprintf(fp,"P5 %d %d 255\n",w,h);
for(j=0;j<h;j++){
  for(i=0;i<w;i++){
    buf[0]=(unsigned char) data[i+j*w];
    fwrite((char*)buf,1,1,fp);
  }
 }

fclose(fp);

//for(i=0; i<w*h; i++){
// data[i]/=4;
// }
//free(data);

 return 0;
}

 h = atoi (argv[2]);
//R
dataR=(unsigned short*)malloc(sizeof(unsigned short)*w*h);
fp=fopen(argv[3],"rb");
fseek(fp,512,SEEK_SET);
for(j=0; j<h; j++){
  for(i=0; i<w; i++){
    fread((char*)buf,2,1,fp);
    data[i+j*w]=(unsigned short)(buf[0]<<8)|buf[1];
  }
 }
//G
dataG=(unsigned short*)malloc(sizeof(unsigned short)*w*h);
fp=fopen(argv[4],"rb");
fseek(fp,512,SEEK_SET);
for(j=0; j<h; j++){
  for(i=0; i<w; i++){
    fread((char*)buf,2,1,fp);
    data[i+j*w]=(unsigned short)(buf[0]<<8)|buf[1];
  }
 }
//B
dataB=(unsigned short*)malloc(sizeof(unsigned short)*w*h);
fp=fopen(argv[5],"rb");
fseek(fp,512,SEEK_SET);
for(j=0; j<h; j++){
  for(i=0; i<w; i++){
    fread((char*)buf,2,1,fp);
    data[i+j*w]=(unsigned short)(buf[0]<<8)|buf[1];
  }
 }
 fclose(fp);

for(i=0; i<w*h; i++){
  data[i]/=4;
 }
//siki
max = 0, color = 0;
if(max < data1[i])}
  max = data1[i];
}
if(max < data2[i])}
  max = data2[i];
}
if(max < data3[i])}
  max = data3[i];
}

min = 255;
if(min > data1[i])}
  min = data1[i];
}
min = 255;
if(min > data2[i])}
  min = data2[i];
}

min = 255;
if(min > data3[i])}
  min = data3[i];
}
 data6[i] = max

 data5[i] = 255 * (max-min)/max;
if(c==1)}

data4[i] = 60 * ((B-G)/(max-min));



//syuturyoku

 fp=fopen(argv[4],"wb");
 fprintf(fp,"P5 %d %d 255\n",w,h);
for(j=0;j<h;j++){
  for(i=0;i<w;i++){
    buf[0]=(unsigned char) data[i+j*w];
    fwrite((char*)buf,1,1,fp);
  }
 }

fclose(fp);

//for(i=0; i<w*h; i++){
// data[i]/=4;
// }
//free(data);

 return 0;
}


Output:
Line 54: warning: data definition has no type or storage class
Line 54: error: 'argv' undeclared here (not in a function)
Line 54: error: initializer element is not constant
Line 56: warning: data definition has no type or storage class
Line 56: error: 'w' undeclared here (not in a function)
Line 56: warning: initialization makes integer from pointer without a cast
Line 56: error: initializer element is not constant
Line 57: warning: data definition has no type or storage class
Line 57: warning: initialization makes integer from pointer without a cast
Line 57: error: initializer element is not constant
Line 58: error: expected ')' before numeric constant
Line 59: error: expected identifier or '(' before 'for'
Line 59: error: expected '=', ',', ';', 'asm' or '__attribute__' before '<' token
Line 59: error: expected '=', ',', ';', 'asm' or '__attribute__' before '++' token
Line 66: warning: data definition has no type or storage class
Line 66: warning: initialization makes integer from pointer without a cast
Line 66: error: initializer element is not constant
Line 67: warning: data definition has no type or storage class
Line 67: error: redefinition of 'fp'
Line 57: error: previous definition of 'fp' was here
Line 67: warning: initialization makes integer from pointer without a cast
Line 67: error: initializer element is not constant
Line 68: error: expected ')' before numeric constant
Line 69: error: expected identifier or '(' before 'for'
Line 69: error: expected '=', ',', ';', 'asm' or '__attribute__' before '<' token
Line 69: error: expected '=', ',', ';', 'asm' or '__attribute__' before '++' token
Line 76: warning: data definition has no type or storage class
Line 76: warning: initialization makes integer from pointer without a cast
Line 76: error: initializer element is not constant
Line 77: warning: data definition has no type or storage class
Line 77: error: redefinition of 'fp'
Line 57: error: previous definition of 'fp' was here
Line 77: warning: initialization makes integer from pointer without a cast
Line 77: error: initializer element is not constant
Line 78: error: expected ')' before numeric constant
Line 79: error: expected identifier or '(' before 'for'
Line 79: error: expected '=', ',', ';', 'asm' or '__attribute__' before '<' token
Line 79: error: expected '=', ',', ';', 'asm' or '__attribute__' before '++' token
Line 85: warning: data definition has no type or storage class
Line 85: warning: parameter names (without types) in function declaration
Line 87: error: expected identifier or '(' before 'for'
Line 87: error: expected '=', ',', ';', 'asm' or '__attribute__' before '<' token
Line 87: error: expected '=', ',', ';', 'asm' or '__attribute__' before '++' token
Line 91: warning: data definition has no type or storage class
Line 92: error: expected identifier or '(' before 'if'
Line 93: warning: data definition has no type or storage class
Line 93: error: redefinition of 'max'
Line 91: error: previous definition of 'max' was here
Line 93: error: 'data1' undeclared here (not in a function)
Line 93: error: 'i' undeclared here (not in a function)
Line 94: error: expected identifier or '(' before '}' token
Line 95: error: expected identifier or '(' before 'if'
Line 96: warning: data definition has no type or storage class
Line 96: error: redefinition of 'max'
Line 91: error: previous definition of 'max' was here
Line 96: error: 'data2' undeclared here (not in a function)
Line 97: error: expected identifier or '(' before '}' token
Line 98: error: expected identifier or '(' before 'if'
Line 99: warning: data definition has no type or storage class
Line 99: error: redefinition of 'max'
Line 91: error: previous definition of 'max' was here
Line 99: error: 'data3' undeclared here (not in a function)
Line 100: error: expected identifier or '(' before '}' token
Line 102: warning: data definition has no type or storage class
Line 103: error: expected identifier or '(' before 'if'
Line 104: warning: data definition has no type or storage class
Line 104: error: redefinition of 'min'
Line 102: error: previous definition of 'min' was here
Line 105: error: expected identifier or '(' before '}' token
Line 106: warning: data definition has no type or storage class
Line 106: error: redefinition of 'min'
Line 102: error: previous definition of 'min' was here
Line 107: error: expected identifier or '(' before 'if'
Line 108: warning: data definition has no type or storage class
Line 108: error: redefinition of 'min'
Line 102: error: previous definition of 'min' was here
Line 109: error: expected identifier or '(' before '}' token
Line 111: warning: data definition has no type or storage class
Line 111: error: redefinition of 'min'
Line 102: error: previous definition of 'min' was here
Line 112: error: expected identifier or '(' before 'if'
Line 113: warning: data definition has no type or storage class
Line 113: error: redefinition of 'min'
Line 102: error: previous definition of 'min' was here
Line 114: error: expected identifier or '(' before '}' token
Line 115: warning: data definition has no type or storage class
Line 117: error: expected ',' or ';' before 'data5'
Line 118: error: expected identifier or '(' before 'if'
Line 120: warning: data definition has no type or storage class
Line 120: error: 'B' undeclared here (not in a function)
Line 120: error: 'G' undeclared here (not in a function)
Line 126: warning: data definition has no type or storage class
Line 126: error: redefinition of 'fp'
Line 57: error: previous definition of 'fp' was here
Line 126: warning: initialization makes integer from pointer without a cast
Line 126: error: initializer element is not constant
Line 127: error: expected ')' before string constant
Line 128: error: expected identifier or '(' before 'for'
Line 128: error: expected '=', ',', ';', 'asm' or '__attribute__' before '<' token
Line 128: error: expected '=', ',', ';', 'asm' or '__attribute__' before '++' token
Line 135: warning: data definition has no type or storage class
Line 135: warning: parameter names (without types) in function declaration
Line 142: error: expected identifier or '(' before 'return'
Line 143: error: expected identifier or '(' before '}' token


Create a new paste based on this one


Comments: