GadgetSeed  0.9.6
graphics_op.c
[詳解]
1 /** @file
2  @brief グラフィックス
3 
4  図形演算ライブラリ
5 
6  @date 2013.06.20
7  @date 2007.03.20
8 
9  @author Takashi SHUDO
10 */
11 
12 #include "graphics.h"
13 
14 //#define DEBUGTBITS 0x02
15 #include "dtprintf.h"
16 
17 /**
18  @brief 2つの矩形のアンドを求める
19 
20  @param[out] a 2つの矩形のアンド矩形
21  @param[in] s1 矩形1
22  @param[in] s2 矩形2
23 */
24 void and_rect(struct st_rect *a, struct st_rect *s1, struct st_rect *s2)
25 {
26  /* 範囲外? */
27  if((s1->top > s2->bottom)
28  || (s1->bottom < s2->top)
29  || (s1->left > s2->right)
30  || (s1->right < s2->left)) {
31  a->left = 0;
32  a->top = 0;
33  a->right = 0;
34  a->bottom = 0;
35  return;
36  }
37 
38  if(s1->left > s2->left) {
39  a->left = s1->left;
40  } else {
41  a->left = s2->left;
42  }
43 
44  if(s1->top > s2->top) {
45  a->top = s1->top;
46  } else {
47  a->top = s2->top;
48  }
49 
50  if(s1->right > s2->right) {
51  a->right = s2->right;
52  } else {
53  a->right = s1->right;
54  }
55 
56  if(s1->bottom > s2->bottom) {
57  a->bottom = s2->bottom;
58  } else {
59  a->bottom = s1->bottom;
60  }
61 }
62 
63 /**
64  @brief 矩形が0か調べる
65 
66  @param rect 矩形
67 
68  @return =1:矩形は0
69 */
70 short empty_rect(struct st_rect *rect)
71 {
72  if(rect->left == rect->right) {
73  return 1;
74  }
75 
76  if(rect->top == rect->bottom) {
77  return 1;
78  }
79 
80  return 0;
81 }
82 
83 /**
84  @brief 矩形を修正する
85 
86  @param[in,out] rect 矩形
87 */
88 void correct_rect(struct st_rect *rect)
89 {
90  short tmp;
91 
92  if(rect->left > rect->right) {
93  tmp = rect->left;
94  rect->left = rect->right;
95  rect->right = tmp;
96  }
97 
98  if(rect->top > rect->bottom) {
99  tmp = rect->top;
100  rect->top = rect->bottom;
101  rect->bottom = tmp;
102  }
103 }
104 
105 /**
106  @brief 座標が矩形の内部か調べる
107 
108  @param[in] x 座標X
109  @param[in] y 座標Y
110  @param[in] rect 矩形
111 
112  @return =1:座標は矩形の中
113 */
114 int is_point_in_rect(short x, short y, struct st_rect *rect)
115 {
116  if(x < rect->left) {
117  return 0;
118  }
119 
120  if(rect->right < x) {
121  return 0;
122  }
123 
124  if(y < rect->top) {
125  return 0;
126  }
127 
128  if(rect->bottom < y) {
129  return 0;
130  }
131 
132  return 1;
133 }
134 
135 /**
136  @brief 座標が四角の内部か調べる
137 
138  @param[in] x 座標X
139  @param[in] y 座標Y
140  @param[in] box 四角
141 
142  @return =1:座標は四角の中
143 */
144 int is_point_in_box(short x, short y, struct st_box *box)
145 {
146  struct st_rect rect;
147 
148  rect.left = box->pos.x;
149  rect.top = box->pos.y;
150  rect.right = box->pos.x + box->sur.width;
151  rect.bottom = box->pos.y + box->sur.height;
152 
153  return is_point_in_rect(x, y, &rect);
154 }
155 
156 /**
157  @brief box -> rect 変換
158 
159  @param[out] rect 矩形
160  @param[in] box 四角
161 */
162 void box2rect(struct st_rect *rect, struct st_box *box)
163 {
164  rect->left = box->pos.x;
165  rect->top = box->pos.y;
166  rect->right = box->pos.x + box->sur.width;
167  rect->bottom = box->pos.y + box->sur.height;
168 }
169 
170 /**
171  @brief イメージデータのサイズを変更する
172 
173  @param[out] dst_image リサイズ後イメージデータ
174  @param[in] dwidth リサイズ後イメージデータ幅
175  @param[in] dwidth リサイズ後イメージデータ高さ
176  @param[in] srctimage リサイズ前イメージデータ
177  @param[in] dwidth リサイズ前イメージデータ幅
178  @param[in] dwidth リサイズ前イメージデータ高さ
179 */
180 void resize_image(void *dst_image, short dwidth, short dheight,
181  void *src_image, short swidth, short sheight)
182 {
183  int i, j;
184 
185  PIXEL_DATA *dst = (PIXEL_DATA *)dst_image;
186  PIXEL_DATA *src = (PIXEL_DATA *)src_image;
187 
188  // 縮小時
189  if((dwidth <= swidth) && (dheight <= sheight)) {
190  for(j=0; j<dheight; j++) {
191  int sy = (sheight * j)/dheight;
192  for(i=0; i<dwidth; i++) {
193  int sx = (swidth * i)/dwidth;
194  DTPRINTF(0x02, "(%d, %d) < (%d, %d)\n", i, j, sx, sy);
195  dst[(dwidth * j) + i] = src[(swidth * sy) + sx];
196  }
197  }
198  }
199 
200  // 拡大時(未実装)
201 }
short y
Y座標
Definition: graphics.h:73
void correct_rect(struct st_rect *rect)
矩形を修正する
Definition: graphics_op.c:88
struct st_surface sur
面の大きさ
Definition: graphics.h:83
void resize_image(void *dst_image, short dwidth, short dheight, void *src_image, short swidth, short sheight)
イメージデータのサイズを変更する
Definition: graphics_op.c:180
アプリケーション(タスク)デバッグ用マクロ
struct st_position pos
左上頂点の位置
Definition: graphics.h:82
矩形
Definition: graphics.h:64
short height
高さ
Definition: graphics.h:78
short empty_rect(struct st_rect *rect)
矩形が0か調べる
Definition: graphics_op.c:70
short top
左上頂点のY座標
Definition: graphics.h:66
short bottom
右下頂点のY座標
Definition: graphics.h:68
short left
左上頂点のX座標
Definition: graphics.h:65
int is_point_in_box(short x, short y, struct st_box *box)
座標が四角の内部か調べる
Definition: graphics_op.c:144
長(正)方形
Definition: graphics.h:81
short width
Definition: graphics.h:77
short right
右下頂点のX座標
Definition: graphics.h:67
int is_point_in_rect(short x, short y, struct st_rect *rect)
座標が矩形の内部か調べる
Definition: graphics_op.c:114
void box2rect(struct st_rect *rect, struct st_box *box)
box -> rect 変換
Definition: graphics_op.c:162
void and_rect(struct st_rect *a, struct st_rect *s1, struct st_rect *s2)
2つの矩形のアンドを求める
Definition: graphics_op.c:24
グラフィックライブラリ
unsigned short PIXEL_DATA
$gsc グラフィックデバイスは24ビットカラー
Definition: graphics.h:17
short x
X座標
Definition: graphics.h:72