問6
次の C プログラムの説明及びプログラムを読んで,設問に答えよ。
〔プログラムの説明〕
関数 CountColors は,横が 320 画素,縦が 240 画素の画像データの, 指定された長方形領域の中を走査して,実際に使用されている色を数えるプログラムである。 1 画素は,次の RGB 構造体に格納される。
画像データは,RGB 構造体の 2 次元配列に格納される。 画像データは,次のように定義する。 画像の座標系との関係を図に示す。
RGB Image[ 240 ][ 320 ] ;
図 画像データの座標系
画像データを,配列 Image に読み込んだ後,画像内の色を数えたい長方形領域を 示す引数を与えて関数 CountColors を呼び出すと,関数の戻り値として色数を返す。
関数 CountColors の原型(プロトタイプ)は
long int CountColors( int sx, int sy, int dx, int dy ) ;
であり,引数と点の座標の関係は,図のとおりである。
〔プログラム〕
typedef struct { unsigned char Red ; unsigned char Green ; unsigned char Blue ; } RGB ; #define Width 320 #define Height 240 #define TRUE 1 #define FALSE 0 RGB Image[ Height ][ Width ] ; long int CountColors( int sx, int sy, int dx, int dy ) { int w, h ; int px, py ; long int Colors ; int Counted[ Height ][ Width ] ; for( h = sy ; h <= dy ; h++ ) for( w = sx ; w <= dx ; w++ ) Counted[h][w] = FALSE ; Colors = 0 ; for( py = sy ; py <= dy ; py++ ) for( px = sx ; px <= dx ; px++ ) { if ( Counted[py][px] == FALSE ) { ; Counted[py][px] = TRUE ; for( h = py ; h <= dy ; h++ ) for( w = ( ) ; w <= dx ; w++ ) { if ( Counted[h][w] == FALSE ) { if (( Image[py][px].Red == Image[h][w].Red ) &&( Image[py][px].Green == Image[h][w].Green ) &&( Image[py][px].Blue == Image[h][w].Blue )) ; } } } } return Colors ; }
a に関する解答群
ア Colors = Counted[py][px] イ Colors = Counted[sy][sx]
ウ Colors++ エ Colors--
オ Counted[h][w] = FALSE カ Counted[h][w] = TRUE
b に関する解答群
ア h == py ? 0 : dx イ h == py ? px + 1 : sx
ウ h == py ? sx : px + 1 エ h == sy ? 0 : dx + 1
オ h == sy ? sx : px + 1
c に関する解答群
ア Counted[dy][dx] = FALSE イ Counted[dy][dx] = TRUE
ウ Counted[h][w] = FALSE エ Counted[h][w] = TRUE
オ Counted[py][px] = FALSE カ Counted[py][px] = TRUE
キ Counted[sy][sx] = FALSE ク Counted[sy][sx] = TRUE