typedef struct int xsize int ysize int level
- Slides: 24
データ構造~構造体定義~ 画像ファイルのフォーマット ヘッダ(画像サイズ,最大輝度) typedef struct { int xsize; int ysize; int level; PIXEL **p. Buffer; } IMAGE; typedef struct { unsigned char r; unsigned char g; unsigned char b; } PIXEL; 88 B 1 E 7 (136) (177) (231) 画像データ ヘッダ 画像データへの二重ポインタ 画像データ (1画素分) 5
データ構造~構造体定義~ 画像ファイルのフォーマット ヘッダ(画像サイズ,最大輝度) 88 B 1 E 7 (136) (177) (231) 画像データ typedef struct { int xsize; int ysize; int level; PPIXEL *p. Buffer; } IMAGE; typedef struct { unsigned char r; unsigned char g; unsigned char b; } PIXEL, *PPIXEL; (PIXEL*)型として PPIXELを新たに定義 6
ポインタの配列~画像バッファの確保~ void iio. Malloc. Image. Buffer(IMAGE *p. Image) p. Image xsize 256 ysize 192 level 255 p. Buffer xsize個のPIXEL の配列を確保 malloc(xsize * sizeof(PIXEL)); ysize個のPPIXEL の配列を確保 malloc(ysize * sizeof(PPIXEL)); 7
画像バッファの様子 → i p. Image xsize ysize level p. Buffer 256 192 255 ↓ j p. Image->p. Buffer[0][0] → i ↓ j ysize個 p. Image->p. Buffer[j][i] p. Image->p. Buffer[j] xsize個 8
ファイルを分割したときの関数のスコープ module. h #define MAX 1024 typedef unsigned char BYTE; void exported_func(int i); module. c #include <string. h> #include “module. h” 別のモジュール foo. c #include “module. h” exported_func(15); internal_func(30); internal_func(int a); #define INT_MACRO(a) (…) ○ × • ヘッダファイルにプロトタイプ宣言がない 関数は外部から参照できない • staticな関数は外部から参照できない void exported_func(int i) { //外部に公開する関数 } static internal_func(int a) { //モジュール内で //使用する関数 } 16
関数の設計 n ファイル入出力 (済) int iio. Load. File(IMAGE *p. Image, const char *fname); (未) int iio. Save. File(IMAGE *p. Image, const char *fname); メモリ確保/解放 (済) void iio. Malloc. Image. Buffer(IMAGE *p. Image); (未) void iio. Free. Image. Buffer(IMAGE *p. Image); n n 画像処理関連 (済) void ip. Rotate. Image(IMAGE *p. Image); 21
画像バッファの解放のヒント void iio. Free. Image. Buffer(IMAGE *p. Image) p. Image 開始 j =0; j < ysize? Y p. Buffer[ j ]を解放 ① j++; N xsize 256 ysize 192 level 255 p. Buffer[0] ① 一行ずつ解放 p. Buffer[1] p. Buffer[2] p. Bufferを解放 ② 終了 ②最後に各行へのポイ ンタの配列を解放 24
- Typedef struct tree int info struct *left
- Typedef struct tree int info
- Typedef struct node
- Typedef struct node int value
- Typedef struct tree int info
- Nodenext
- Struct node int data struct node* next
- Int sum(int a int n) int sum=0 i
- Typedef struct node
- Typedef struct en c
- Typedef struct in c linked list
- Typedef struct node
- Include stdio.h
- Typedef struct c
- Typedef struct
- Typedef struct tag
- Typedef union
- Typedef struct node
- Xsize
- Copy struct c
- Public void drawsquare(int x, int y, int len)
- Public int divide(int a int b)
- Int max(int x int y)
- Interface calculator public int add(int a int b) class test
- Typedef int element