#include<stdio.h>
#include"./Graphics.h"
#include"./Image.h"
#define IE 480
#define JE 640
void DisplayColorImage( int ** R,int ** G,int ** B, int ** Y)
{
int i,j,x;
double a,b,c;
a = 0.6 ;
b = 0.2 ;
c = 0.2 ;
for ( i= 0 ; i < IE ; i++ ) {
for ( j = 0 ; j < JE ; j++ ) {
Y[ i] [ j] = a* R[ i] [ j] + b* G[ i] [ j] + c* B[ i] [ j] ;
/* 画像の表示 */
GSetColor( Y[ i] [ j] ,Y[ i] [ j] ,Y[ i] [ j] ) ;
GPSet( j,i) ;
}
}
}
void Ptile( int ** Y)
{
int i,j;
for ( i= 0 ; i < IE; i++ ) {
for ( j= 0 ; j < JE; j++ ) {
if ( Y[ i] [ j] > 120 ) {
Y[ i] [ j] = 1 ;
} else {
Y[ i] [ j] = 0 ;
}
GSetColor( Y[ i] [ j] * 255 ,Y[ i] [ j] * 255 ,Y[ i] [ j] * 255 ) ;
GPSet( j,i) ;
}
}
}
void Shuushuku( int ** F, int ** F2) {
int i,j,s,IE,JE;
for ( i = 0 ; i < IE; i++ ) {
for ( j = 0 ; j < JE; j++ ) {
if ( F[ i] [ j] == 0 ) {
F[ i] [ j] = 0 ;
F2[ i] [ j] = 0 ;
} else {
F[ i] [ j] = 1 ;
F2[ i] [ j] = 1 ;
}
}
}
for ( i = 1 ; i < IE; i++ ) {
for ( j = 1 ; j < JE; j++ ) {
if ( F[ i- 1 ] [ j] == 1 && F2[ i] [ j- 1 ] == 1 &&
F[ i] [ j+ 1 ] == 1 && F2[ i- 1 ] [ j] == 1 ) {
F[ i] [ j] = 1 ;
} else {
F2[ i] [ j] = 0 ;
}
}
}
for ( i = 0 ; i < IE; i++ ) {
for ( j = 0 ; j < JE; j++ ) {
F2[ i] [ j] = F[ i] [ j] ;
}
}
for ( i = 1 ; i < IE; i++ ) {
for ( j = 1 ; j < JE; j++ ) {
if ( F2[ i] [ j] == 1 ) {
F[ i- 1 ] [ j] = 1 ;
F[ i] [ j- 1 ] = 1 ;
F[ i] [ j+ 1 ] = 1 ;
F[ i+ 1 ] [ j] = 1 ;
}
}
}
for ( i = 0 ; i < IE; i++ ) {
for ( j = 0 ; j < JE; j++ ) {
if ( F[ i] [ j] == 1 ) {
s= 255 ;
} else {
s= 0 ;
}
GSetColor( s, s, s) ;
GPSet( j,i) ;
}
}
}
void DisplayColorHairetu( int ** R,int ** G,int ** B, int ** Y)
{
int i,j,k,n;
double a,b,c;
a = 0.6 ;
b = 0.2 ;
c = 0.2 ;
int hairetu[ 256 ] ;
for ( n = 0 ; n < 256 ; n++ ) {
hairetu[ n] = 0 ;
}
for ( i= 0 ; i < IE ; i++ ) {
for ( j = 0 ; j < JE ; j++ ) {
Y[ i] [ j] = a* R[ i] [ j] + b* G[ i] [ j] + c* B[ i] [ j] ;
hairetu[ Y[ i] [ j] ] = hairetu[ Y[ i] [ j] ] + 1 ;
}
}
for ( k= 0 ; k < 256 ; k++ ) {
printf ( "%d %d\n " , k,hairetu[ k] ) ;
}
}
main( ) {
int i,j;
int ** R, ** G, ** B, ** Y, ** F, ** F2;
R = IAllocImage( 640 ,480 ) ;
G = IAllocImage( 640 ,480 ) ;
B = IAllocImage( 640 ,480 ) ;
Y = IAllocImage( 640 ,480 ) ;
F = IAllocImage( 640 ,480 ) ;
F2 = IAllocImage( 640 ,480 ) ;
GInit( 640 ,480 ) ;
ILoadPpmImage( "kadai1.ppm" ,R,G,B) ;
DisplayColorImage( R,G,B,Y) ;
DisplayColorHairetu( R,G,B,Y) ;
GWaitLoop( ) ;
Ptile( Y) ;
GWaitLoop( ) ;
Shuushuku( F,F2) ;
GWaitLoop( ) ;
}
I2luY2x1ZGU8c3RkaW8uaD4KI2luY2x1ZGUiLi9HcmFwaGljcy5oIgojaW5jbHVkZSIuL0ltYWdlLmgiCiNkZWZpbmUgSUUgNDgwCiNkZWZpbmUgSkUgNjQwCgp2b2lkIERpc3BsYXlDb2xvckltYWdlKGludCAqKlIsaW50ICoqRyxpbnQgKipCLCBpbnQqKlkpCnsKICAgICAgICBpbnQgaSxqLHg7CiAgICAgICAgZG91YmxlIGEsYixjOwogICAgICAgIGEgPSAwLjY7CiAgICAgICAgYiA9IDAuMjsKICAgICAgICBjID0gMC4yOwoKCiAgICAgICAgZm9yKGk9MCA7IGkgPCBJRSA7IGkrKyl7CiAgICAgICAgICAgZm9yKGogPSAwIDsgaiA8IEpFIDsgaisrKXsKICAgICAgICAgICAgICAgIFlbaV1bal09YSpSW2ldW2pdK2IqR1tpXVtqXStjKkJbaV1bal07CgoKICAgICAgICAgICAgIC8qIOeUu+WDj+OBruihqOekuiAqLwogICAgICAgICAgICAgICAgR1NldENvbG9yKFlbaV1bal0sWVtpXVtqXSxZW2ldW2pdKTsKICAgICAgICAgICAgICAgIEdQU2V0KGosaSk7CiAgICAgICAgICAgfQogICAgICAgIH0KfQoKCnZvaWQgUHRpbGUoaW50ICoqWSkKewogICAgICAgIGludCBpLGo7CiAgICAgICAgZm9yKGk9MDsgaSA8IElFOyBpKyspewogICAgICAgICAgICAgICAgZm9yKGo9MDsgaiA8IEpFOyBqKyspewogICAgICAgICAgICAgICAgICAgICAgICBpZihZW2ldW2pdPjEyMCl7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgWVtpXVtqXSA9IDE7CiAgICAgICAgICAgICAgICAgICAgICAgIH1lbHNlewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIFlbaV1bal0gPSAwOwogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBHU2V0Q29sb3IoWVtpXVtqXSoyNTUsWVtpXVtqXSoyNTUsWVtpXVtqXSoyNTUpOwogICAgICAgICAgICAgICAgR1BTZXQoaixpKTsKICAgICAgICAgICAgICAgIH0KICAgICAgICB9Cn0KCgp2b2lkIFNodXVzaHVrdShpbnQgKipGLCBpbnQgKipGMil7CiAgICAgICAgIGludCBpLGoscyxJRSxKRTsKICAgICAgICAgZm9yKGkgPSAwOyBpIDwgSUU7IGkrKyl7CiAgICAgICAgICAgICAgICAgZm9yKGogPTA7IGogPCBKRTsgaisrKXsKICAgICAgICAgICAgICAgICAgICAgICAgIGlmKEZbaV1bal0gPT0gMCl7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIEZbaV1bal0gPSAwOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBGMltpXVtqXSA9IDA7CiAgICAgICAgICAgICAgICAgICAgICAgICB9ZWxzZXsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgRltpXVtqXSA9IDE7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIEYyW2ldW2pdID0gMTsKICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICB9CiAgICAgICAgIH0KICAgICAgICAgZm9yKGkgPSAxOyBpIDwgSUU7IGkrKyl7CiAgICAgICAgICAgICAgICAgZm9yKGogPSAxOyBqIDwgSkU7IGorKyl7CiAgICAgICAgICAgICAgICAgICAgICAgICBpZihGW2ktMV1bal0gPT0gMSAmJiBGMltpXVtqLTFdID09IDEgJiYKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgRltpXVtqKzFdID09IDEgJiYgRjJbaS0xXVtqXSA9PSAxKXsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgRltpXVtqXSA9IDE7CiAgICAgICAgICAgICAgICAgICAgICAgICB9ZWxzZXsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgRjJbaV1bal0gPSAwOwogICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgIH0KICAgICAgICAgfQogICAgICAgICBmb3IoaSA9IDA7IGkgPCBJRTsgaSsrKXsKICAgICAgICAgICAgICAgICBmb3IoaiA9IDA7IGogPCBKRTsgaisrKXsKICAgICAgICAgICAgICAgICAgICAgICAgIEYyW2ldW2pdPUZbaV1bal07CiAgICAgICAgICAgICAgICAgfQogICAgICAgICB9CiAgICAgICAgIGZvcihpID0gMTsgaSA8IElFOyBpKyspewogICAgICAgICAgICAgICAgIGZvcihqID0gMTsgaiA8IEpFOyBqKyspewogICAgICAgICAgICAgICAgICAgICAgICAgaWYoRjJbaV1bal09PTEpewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBGW2ktMV1bal0gPSAxOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBGW2ldW2otMV0gPSAxOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBGW2ldW2orMV0gPSAxOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBGW2krMV1bal0gPSAxOwogICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgIH0KICAgICAgICAgfQogICAgICAgICBmb3IoaSA9IDA7IGkgPCBJRTsgaSsrKXsKICAgICAgICAgICAgICAgICBmb3IoaiA9IDA7IGogPCBKRTsgaisrKXsKICAgICAgICAgICAgICAgICAgICAgICAgIGlmKEZbaV1bal0gPT0gMSl7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHM9MjU1OwogICAgICAgICAgICAgICAgICAgICAgICAgfWVsc2V7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHM9MDsKICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgIEdTZXRDb2xvcihzLCBzLCBzKTsKICAgICAgICAgICAgICAgICAgICAgICAgIEdQU2V0KGosaSk7CiAgICAgICAgICAgICAgICAgfQogICAgICAgICB9Cn0KCgp2b2lkIERpc3BsYXlDb2xvckhhaXJldHUoaW50ICoqUixpbnQgKipHLGludCAqKkIsIGludCoqWSkKewogICAgICAgIGludCBpLGosayxuOwoKICAgICAgICBkb3VibGUgYSxiLGM7CiAgICAgICAgYSA9IDAuNjsKICAgICAgICBiID0gMC4yOwogICAgICAgIGMgPSAwLjI7CgogICAgICAgIGludCBoYWlyZXR1WzI1Nl07CgogICAgICAgIGZvcihuID0gMDsgbiA8IDI1NjsgbisrKXsKCiAgICAgICAgICAgICAgICBoYWlyZXR1W25dID0gMDsKICAgICAgICB9CgogICAgICAgIGZvcihpPTAgOyBpIDwgSUUgOyBpKyspewogICAgICAgICAgIGZvcihqID0gMCA7IGogPCBKRSA7IGorKyl7CgogICAgICAgICAgICAgICAgWVtpXVtqXT1hKlJbaV1bal0rYipHW2ldW2pdK2MqQltpXVtqXTsKICAgICAgICAgICAgICAgIGhhaXJldHVbWVtpXVtqXV09aGFpcmV0dVtZW2ldW2pdXSArIDEgOwogICAgICAgICAgIH0KICAgICAgICB9CgogICAgICAgIGZvcihrPTAgOyBrIDwgMjU2ICA7IGsrKyl7CiAgICAgICAgICAgICAgICBwcmludGYoIiVkICVkXG4iLCBrLGhhaXJldHVba10pOwogICAgICAgIH0KCn0KCm1haW4oKXsKICAgICAgICBpbnQgaSxqOwogICAgICAgIGludCAqKlIsICoqRywgKipCLCAqKlksICoqRiwgKipGMjsKCiAgICAgICAgUiA9IElBbGxvY0ltYWdlKDY0MCw0ODApOwogICAgICAgIEcgPSBJQWxsb2NJbWFnZSg2NDAsNDgwKTsKICAgICAgICBCID0gSUFsbG9jSW1hZ2UoNjQwLDQ4MCk7CiAgICAgICAgWSA9IElBbGxvY0ltYWdlKDY0MCw0ODApOwogICAgICAgIEYgPSBJQWxsb2NJbWFnZSg2NDAsNDgwKTsKICAgICAgICBGMiA9IElBbGxvY0ltYWdlKDY0MCw0ODApOwoKICAgICAgICBHSW5pdCg2NDAsNDgwKTsKICAgICAgICBJTG9hZFBwbUltYWdlKCJrYWRhaTEucHBtIiAsUixHLEIpOwogICAgICAgIERpc3BsYXlDb2xvckltYWdlKFIsRyxCLFkpOwogICAgICAgIERpc3BsYXlDb2xvckhhaXJldHUoUixHLEIsWSk7CiAgICAgICAgR1dhaXRMb29wKCk7CiAgICAgICAgUHRpbGUoWSk7CiAgICAgICAgR1dhaXRMb29wKCk7CiAgICAgICAgU2h1dXNodWt1KEYsRjIpOwogICAgICAgIEdXYWl0TG9vcCgpOwp9Cg==