Drawing Pixel Bitmap Image Bitmap Bitmap Pixel 1
Drawing Pixel, Bitmap, Image
Bitmap • Bitmap: Pixel당 1 bit (0/1)의 array • Bitmap 색상: bitmap 1에 대응하는 frame buffer의 색상은 현재 raster color로 설정된 다. • bitmap display 위치: 현재 raster 위치에 상대적으로 결정. • 현재 raster 위치 설정: gl. Raster. Pos*() 함수 • Bitmap의 draw: gl. Bitmap() 함수
Bitmap Data Bitmap data는 아래에서 위 방향으로 MSB first로 정 의된다.
Bitmap Data • GLubyte rasters[24] = { 0 xc 0, 0 x 00, 0 xc 0, 0 x 00, 0 xff, 0 x 00, 0 xc 0, 0 x 00, 0 xff, 0 xc 0}; • Bitmap의 size는 16 x 12이므로 2개의 unsigned byte가 하나의 row를 구성 • Data는 아래의 row 부터 위로 정의한다.
Raster 위치 설정 • gl. Raster. Pos{234}{sifd}(x, y, z, w); • gl. Raster. Posfv {234}{sifd}(coords); • 명기한 좌표값은 vertex 좌표와 동일하 게 변환된다. • raster position data 구성 = three window coordinates (x, y, z) + clip coordinate w value + an eye coordinate distance + a valid bit + associated color data + texture coordinates
bitmap의 draw • gl. Bitmap(Glsizei width, Glsizei height, GLfloat xorig, GLfloat yorig, GLfloat xmove, GLfloat ymove, const GLubyte * bitmap) • xorg, yorg: Bitmap의 원점. 현재의 raster position과 bitmap의 (xorg, yorg) 위치를 일치 시킨다. • xmove, ymove: bitmap이 draw된후 raster position 이 이동되는 offset • 좌표의 모든 단위는 pixel임
bitmap의 색지정 • gl. Color 3 f(1. 0, 1. 0); /* white */ gl. Raster. Pos 3 fv(position); gl. Color 3 f(1. 0, 0. 0); /* red */ gl. Bitmap(. . ); • 위의 code에서 bitmap은 white color로 그려진다. • GL_CURRENT_RASTER_COLOR is set when gl. Raster. Pos() is called
Image • Image(Pixmap): more information (colors) for each pixel. For example, RGBA pixel • Image Source - 사진을 scanning - frame buffer - 프로그램으로 memory에 생성
Pixel Data의 Read/Draw/Copy • gl. Read. Pixels(): framebuffer에서 읽어 processor memory에 data 저장 • gl. Draw. Pixels(): processor memory의 pixel data를 framebuffer로 • gl. Copy. Pixels(): Framebufferdml pixel을 frame buffer로 복사. • gl. Draw. Pixels()/gl. Copy. Pixels() 함 수 에 서 raster 위 치 는 gl. Raster. Pos*()로 지정된다.
• gl. Draw. Pixels(width, height, format, type, GLvoid *pixels); - From : 프로세서 memory의 array pixels - To : framebuffer에 현재의 raster position에서 width 와 height의 사각형 크기로 - format : memory에 있는 pixel의 formats - type : memory에 있는 pixel component의 data type - raster position의 설정은 gl. Raster. Pos*() 함수를 사용 - 쓰여질 framebuffer는 gl. Draw. Buffer(GL_BACK) 함수 를 사용. 이 함수에 인수로는 GL_BACK, GL_FRONT, GL_LEFT, GL_RIGHT, GL_FRONT_LEFT 등을 사용
예제 Code GLubyte check. Image[Image. Height][Image. Width][3] gl. Clear(GL_COLOR_BUFFER_BIT); gl. Pixel. Storei(GL_UNPACK_ALIGNMENT, 1); gl. Raster. Pos 2 i(0, 0); gl. Draw. Pixels(Image. Width, Image. Height, GL_RGB, GL_UNSIGNED_BYTE, check. Image); gl. Flush();
Pixel Reading 함수: Frame buffer에서 pixel data를 읽어 memory로 저장 u gl. Read. Pixels(x, y, width, height, format, type, GLvoid *pixels); - From : framebuffer whose lower-left corner (x, y) and dimensions are width and height (pixel 단위) - To : pixels로 지정한 memory로 framebuffer의 pixel을 저장 - Format : frame buffer에 있는 읽혀질 pixel data의 formats. GL_RGB, GL_RGBA, GL_RED, etc - type: 저장되는 pixel의 data type. GL_INT (4 byte), GL_UNSIGNED_BYTE, GL_UNSIGNED_SHORT - 일혀질 framebuffer는 gl. Read. Buffer(GL_BACK) 함수를 사용하여 지정한다.
Pixel Copying: gl. Copy. Pixels 함수() • gl. Copy. Pixels(x, y, width, height, buffer); • - From : framebuffer rectange whose lower-left corner is at (x, y) and dimensions are width and height -To : framebuffer with its lower-left corner at the current raster position • - buffer : GL_DEPTH, GL_STENCIL or GL_COLOR • -data가 memory에 저장되지 않으므로 format과 • type은 필요 없다. • - source buffer는 gl. Read. Buffer() 함수로 • destination buffer는 gl. Write. Buffer() 함수로 지정
Image 처리 Pipeline
gl. Draw. Pixels()/gl. Read. Pixels()의 pipeline • gl. Draw. Pixels: Processor Memory -> Pixel Stroage Mode -> Pixel-Transfer Operation -> Raterization ( including Pixel Zoom) -> Per-Fragment Operation -> framebuffer • gl. Read. Pixels: framebuffer -> Pixel. Transfer Operation -> processor memory
gl. Copy. Pixels() pipeline
gl. Bitmap pipeline
gl. Tex. Image*(), gl. Tex. Sub. Image*(), gl. Get. Tex. Image()
gl. Copy. Tex. Image*()/gl. Copy. Tex. Sub. Image*()
Pixel Storage Mode의 control • • gl. Pixel. Store{if}() 함수를 사용 Byte Swapping LSB ordering Row or pixel skipping 작업
void gl. Pixel. Store{if}(GLenum pname, TYPE param); • pname: unpack 일때 GL_UNPACK_xxx로 ㅔ pack일때 GL_PACK_XXX로 적용될 작업 지 정 • GL_UNPACK_SWAP_BYTES: multibyte color component (각각의 R, G, B 네에서) depth component, color index, stencil index안에 서 byte 순서를 바꾼다. RGBA의 순서를 바꾸지는 않는다.
• GL_UNPACK_LSB_FIRST: param=GL_TRUE 일때, 한 byte 안에서 bit 의 순서를 바꾼다 • GL_UNPACK_ROW_LENGTH: 한 row에 있는 actual pixel의 수 를 정 의. 0일 때 는 gl. Draw. Pixels() 등의 함수에서 지정한 width 값으로 설정됨. • GL_UNPACK_SKIP_ROWS: skip될 row의 수 를 설정 • GL_UNPACK_SKIP_PIXELS: skip될 pixels의 수를 설정
• GL_UNPACK_ALIGNMENT: 각각 pixel row의 시작을 나타내는 alignment requirement를 나타냄 (1, 2, 4, 8 중 하나 사용) • 5 pixel wide의 RGB (3 bytes) data row 당: 5*3 =15 byte 소요됨 빠른 access를 위하여 alignment를 4로 설정 하고 각 row를 16 byte memory에 저장
Pname Type Initial Value Valid Range GL_PACK_SWAP_BYTES Boolean false true or false GL_PACK_ROW_LENGTH integer 0 [0, ) GL_PACK_SKIP_ROWS integer 0 [0, ] GL_PACK_SKIP_PIXELS integer 0 [0, ] GL_PACK_ALIGNMENT integer 4 1, 2, 4, or 8 GL_UNPACK_SWAP_BYTES Boolean false true or false GL_UNPACK_LSB_FIRST Boolean false true or false GL_UNPACK_ROW_LENGTH integer 0 [0, ] GL_UNPACK_SKIP_ROWS integer 0 [0, ] GL_UNPACK_SKIP_PIXELS integer 0 [0, ] GL_UNPACK_ALIGNMENT integer 4 1, 2, 4, or 8
Pixel Transfer Operation - Color biasing, scaling, mapping …. 등을 수 행: Color, color index, depth, stencil pixel 에 대하여 적용됨. -gl. Draw. Pixels, gl. Read. Pixels, gl. Copy. Pixels, gl. Tex. Image 1 D, and gl. Tex. Image 2 D 함수에 영향을 줌. - void gl. Pixel. Transfer{if}(GLenum pname, TYPE param);
void gl. Pixel. Transfer{if}(GLenum pname, TYPE param); 함수 • GL_MAP_COLOR, GL_MAP_STENCIL: TRUE/FALSE MAPPING의 적용여부 • GL_RED_SCALE, GL_ALPHA_SCALE, GL_DEPTH_SCALE: 색의 component에 곱하여지는 factor • GL_RED_BIAS, etc: 색의 component에 더해지는 값
Color Pixel에 적용 - 각각의 color component는 SCALE factor로 곱해진 후 BIAS factor가 더해진다. 즉 red component는 GL_RED_SCALE로 곱해진 후 GL_RED_BIAS값이 더해진다. 그후 [0, 1] 범 위로 clamp된다. - GL_MAP_COLOR가 GL_TRUE로 설정됬을 때, GL_Pixel. Map에 의하여 설정된 color-tocolor map에 의하여 값이 보정된다.
Pixel Mapping - void gl. Pixel. Map{ui us f}(GLenum map, Lint mapsize, const TYPE *values); - Map: 적용될 map의 종류, GL_PIXEL_MAP_R_TO_R, GL_PIXEL_MAP_S_TO_S GL_PIXEL_MAP_I_TO_I , GL_PIXEL_MAP_I_TO_R GL_PIXEL_MAP_A_TO_A 등을 지정 - Mapsize: map의 row 크기 - Values: mapping table
GL_float lut[256]; for (I=0; I < 256; ++I) lut[I]=pow(i/255. 0, 1. 0/1. 7); gl. Pixel. Transferi(GL_MAP_COLOR, GL_TRUE); gl. Pixel. Map(GL_PIXEL_MAP_R_TO_R, 256, lut); gl. Pixel. Map(GL_PIXEL_MAP_G_TO_G, 256, lut); gl. Pixel. Map(GL_PIXEL_MAP_B_TO_B, 256, lut);
Pixel Zooming u Pixel을 확대, 축소, Flipping 등을 할 수 있 다. gl. Draw. Pixels, gl. Copy. Pixels 등에 적용됨. u void gl. Pixel. Zoom(GLfloat zoomx, GLfloat zoomy); u gl. Pixel. Zoom(-1. 0, 1. 0) // image는 수 평으로 flip
- Slides: 32