실제 화면에 표시되는 점을 하나의 단위로 보는 좌표계입니다.
위에서 화면전체는 Pixel좌표계로는 다음과 같이 표시될수 있습니다.
typedef struct hwport_rectangle_ts {
int x, y;
unsigned int width, height;
}__hwport_rectangle_t;
#define hwport_rectangle_t __hwport_rectangle_t
typedef struct hwport_screen_ts {
int bits_per_pixel;
size_t bytes_per_line;
hwport_rectangle_t rectangle;
}__hwport_screen_t;
#define hwport_screen_t __hwport_screen_t
static hwport_screen_t my_screen = {
16, /* bits_per_pixel = <위 그림에서 하나의 점은 16K 의 Color수를 표현한다고 가정하면 하나의 점을 표현하는데는 16bits가 필요합니다.> */
(size_t)((32u + 4u) * (16u / 8u)), /* bytes_per_line = 가시영역인 32개의 가로 Pixel수와 비가시영역 4개의 Pixel을 더하고 bits_per_pixel을 bytes_per_pixel로 곱한것입니다. */
{ 0, 0, 32u, 32u } /* rectangle = 비가시영역을 제외한 부분을 뜻합니다. 여기서 x, y는 항상 0이라고 할수는 없고 Over scan등이 고려될때는 0이 아닐수 있습니다. */
};
위의 그림에서 붉은색 사각형은 다음과 같이 표현될수 있습니다.
hwport_rectangle_t my_rectangle = {
2, 2, 9u, 9u
};
또 다른 표현으로는 다음과 같이도 표현합니다.
typedef struct hwport_region_ts {
int x1, y1, x2, y2;
}__hwport_region_t;
#define hwport_region_t __hwport_region_t
hwport_region_t my_region = {
2, 2, 10, 10
};
만약 hwport_region_t 를 hwport_rectangle_t 로 변환하려면 다음과 같은 공식이 성립합니다.
#define MIN(m_left,m_right) ((m_left < m_right) ? (m_left) : (m_right))
#define MAX(m_left,m_right) ((m_left > m_right) ? (m_left) : (m_right))
my_rectangle.x = MIN(my_region.x1, my_region.x2);
my_rectangle.y = MIN(my_region.y1, my_region.y2);
my_rectangle.width = (unsigned int)( MAX(my_region.x1, my_region.x2) - MIN(my_region.x1, my_region.x2) + 1 );
my_rectangle.height = (unsigned int)( MAX(my_region.y1, my_region.y2) - MIN(my_region.y1, my_region.y2) + 1 );
반대로 hwport_rectangle_t 를 hwport_region_t 로 변환하려면 다음과 같은 공식이 성립합니다.
if((my_rectangle.width <= 0u) || (my_rectangle.height <= 0u)) {
/* ERROR: invalid width or height */
}
my_region.x1 = my_rectangle.x;
my_region.y1 = my_rectangle.y;
my_region.x2 = ((int)my_rectangle.width) - my_rectangle.x - 1;
my_region.y2 = ((int)my_rectangle.height) - my_rectangle.y - 1;