대문 / 프로그래밍 / 그래픽 좌표계

그래픽 좌표계

좌표계의 종류

Upload new Attachment "coords_system.png" 위 그림은 아래 설명을 위해서 작성한 하나의 가상 화면입니다.

  • 하나의 점은 16K color 수를 표현할수 있다고 가정합니다.
  • 붉은색 사각형 하나는 실제 화면에 표시되는 점으로 가정합니다.
  • 회색사각형은 실제 화면에 보이지 않는 비가시영역으로 가정합니다. ( 이 영역은 Paging unit의 효율을 위해서 하나의 Row당 Padding되는 영역으로 설명될수 있습니다. )

  • Pixel 좌표계

    실제 화면에 표시되는 점을 하나의 단위로 보는 좌표계입니다.

    위에서 화면전체는 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;
    


    Bound(Screen) 좌표계

    하나의 점 마저도 크게 확대해보면 사각형 또는 어느 범위안의 구역이라는 시점으로 바라본 좌표계로써 보이는 점들의 외곽영역을 기준으로 하는 좌표계
    typedef struct hwport_bound_ts {
        int left, top, right, bottom;
    }__hwport_bound_t;
    #define hwport_bound_t __hwport_bound_t
    
    typedef struct hwport_screen_ts {
        int bits_per_pixel;
        size_t bytes_per_line;
        hwport_bound_t bound;
    }__hwport_screen_t;
    #define hwport_screen_t __hwport_screen_t
    
    static hwport_screen_t my_screen = {
        16,                  /* bits_per_pixel */
        (32 + 4) * (16 / 8), /* bytes_per_line */
        { 0, 0, 32, 32 }     /* bound */
    };
    


    위의 그림에서 붉은색 사각형은 다음과 같이 표현될수 있습니다.
    hwport_bound_t my_bound = {
        2, 2, 11, 11
    };
    


    Pixel 좌표계와 Bound 좌표계의 분석

    hwport_bound_t를 hwport_rectangle_t 로 변환하려면 다음과 같은 공식이 성립합니다. hwport_region_t를 hwport_rectangle_t 로 변환할때는 1을 더해주어야 했다는 점이 주목해야 될 부분입니다.
    my_rectangle.x = my_bound.left;
    my_rectangle.y = my_bound.top;
    my_rectangle.width = (unsigned int)(my_bound.right - my_bound.left);
    my_rectangle.height = (unsigned int)(my_bound.bottom - my_bound.top);
    

    /*
    End of page
    (RemoteIP=38.107.179.242:43209)
    Copyright © HWPORT.COM
    All Rights Reserved.
    */