1 / 32

Drawing Pixel, Bitmap, Image

Drawing Pixel, Bitmap, Image. Bitmap. Bitmap: Pixel 당 1 bit (0/1) 의 array Bitmap 색상 : bitmap 1 에 대응하는 frame buffer 의 색상은 현재 raster color 로 설정된다 . bitmap display 위치 : 현재 raster 위치에 상대적으로 결정 . 현재 raster 위치 설정 : glRasterPos*() 함수 Bitmap 의 draw: glBitmap() 함수. Bitmap Data.

cyrus-rosa
Download Presentation

Drawing Pixel, Bitmap, Image

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Drawing Pixel, Bitmap, Image

  2. Bitmap • Bitmap: Pixel당 1 bit (0/1)의 array • Bitmap 색상: bitmap 1에 대응하는 frame buffer의 색상은 현재 raster color로 설정된다. • bitmap display 위치: 현재 raster 위치에 상대적으로 결정. • 현재 raster 위치 설정: glRasterPos*() 함수 • Bitmap의 draw: glBitmap() 함수

  3. Bitmap Data Bitmap data는 아래에서 위 방향으로 MSB first로 정의된다.

  4. Bitmap Data • GLubyte rasters[24] = { 0xc0, 0x00, 0xc0, 0x00, 0xc0, 0x00, 0xc0, 0x00, 0xc0, 0x00, 0xff, 0x00, 0xff, 0x00, 0xc0, 0x00, 0xc0, 0x00, 0xc0, 0x00, 0xff, 0xc0, 0xff, 0xc0}; • Bitmap의 size는 16x12이므로 2개의 unsigned byte가 하나의 row를 구성 • Data는 아래의 row 부터 위로 정의한다.

  5. Raster 위치 설정 • glRasterPos{234}{sifd}(x, y, z, w); • glRasterPosfv {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

  6. bitmap의 draw • glBitmap(Glsizeiwidth, Glsizeiheight, GLfloatxorig, GLfloat yorig, GLfloatxmove, GLfloatymove, const GLubyte* bitmap) • xorg, yorg: Bitmap의 원점. 현재의 raster position과 bitmap의 (xorg, yorg) 위치를 일치 시킨다. • xmove, ymove: bitmap이 draw된후 raster position이 이동되는 offset • 좌표의 모든 단위는 pixel임

  7. bitmap의 draw • 원점이 (0,0)이므로 글자의 baseline은 0의 위치 • xOffset이 11이므로 다음의 F letter는 11 위치 offset 되어 draw 된다. • Xoffset이 11.5로 지정되면 F 글자 사이의 간격은 1 또는 2 pixel 사이에 위치하게 된다.

  8. bitmap의 색지정 • glColor3f(1.0, 1.0, 1.0); /* white */ glRasterPos3fv(position); glColor3f(1.0, 0.0, 0.0); /* red */ glBitmap(....); • 위의 code에서 bitmap은 white color로 그려진다. • GL_CURRENT_RASTER_COLOR is set when glRasterPos() is called

  9. Image • Image(Pixmap): more information (colors) for each pixel. For example, RGBA pixel • Image Source - 사진을 scanning - frame buffer - 프로그램으로 memory에 생성

  10. Pixel Data의 Read/Draw/Copy • glReadPixels(): framebuffer에서 읽어 processor memory에 data 저장 • glDrawPixels(): processor memory의 pixel data를 framebuffer로 • glCopyPixels(): Framebufferdml pixel을 frame buffer로 복사. • glDrawPixels()/glCopyPixels() 함수에서 raster 위치는 glRasterPos*()로 지정된다.

  11. glDrawPixels(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의 설정은 glRasterPos*() 함수를 사용 - 쓰여질 framebuffer는 glDrawBuffer(GL_BACK) 함수 를 사용. 이 함수에 인수로는 GL_BACK, GL_FRONT, GL_LEFT, GL_RIGHT, GL_FRONT_LEFT 등을 사용

  12. 예제 Code GLubyte checkImage[ImageHeight][ImageWidth][3] glClear(GL_COLOR_BUFFER_BIT); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glRasterPos2i(0, 0); glDrawPixels(ImageWidth, ImageHeight, GL_RGB, GL_UNSIGNED_BYTE, checkImage); glFlush();

  13. Pixel Reading 함수: Frame buffer에서 pixel data를 읽어 memory로 저장 uglReadPixels(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는 glReadBuffer(GL_BACK) 함수를 사용하여 지정한다.

  14. Pixel Copying: glCopyPixels 함수() • glCopyPixels(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는 glReadBuffer() 함수로 • destination buffer는 glWriteBuffer() 함수로 지정

  15. Image 처리 Pipeline

  16. glDrawPixels()/glReadPixels()의 pipeline • glDrawPixels: Processor Memory -> Pixel Stroage Mode -> Pixel-Transfer Operation -> Raterization ( including Pixel Zoom) -> Per-Fragment Operation -> framebuffer • glReadPixels: framebuffer -> Pixel-Transfer Operation -> processor memory

  17. glCopyPixels() pipeline

  18. glBitmap pipeline

  19. glTexImage*(), glTexSubImage*(), glGetTexImage()

  20. glCopyTexImage*()/glCopyTexSubImage*()

  21. Pixel Storage Mode의 control • glPixelStore{if}() 함수를 사용 • Byte Swapping • LSB ordering • Row or pixel skipping 작업

  22. void glPixelStore{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의 순서를 바꾸지는 않는다.

  23. GL_UNPACK_LSB_FIRST: param=GL_TRUE일때, 한 byte 안에서 bit 의 순서를 바꾼다 • GL_UNPACK_ROW_LENGTH: 한 row에 있는 actual pixel의 수를 정의. 0일 때는 glDrawPixels() 등의 함수에서 지정한 width 값으로 설정됨. • GL_UNPACK_SKIP_ROWS: skip될 row의 수를 설정 • GL_UNPACK_SKIP_PIXELS: skip될 pixels의 수를 설정

  24. 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에 저장

  25. Pname Type Initial Value Valid Range GL_PACK_SWAP_BYTES Boolean false true or false 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

  26. Pixel Transfer Operation - Color biasing, scaling, mapping ….등을 수행: Color, color index, depth, stencil pixel에 대하여 적용됨. -glDrawPixels, glReadPixels, glCopyPixels, glTexImage1D, and glTexImage2D함수에 영향을 줌. - void glPixelTransfer{if}(GLenum pname, TYPE param);

  27. void glPixelTransfer{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에 더해지는 값

  28. 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_PixelMap에 의하여 설정된 color-to-color map에 의하여 값이 보정된다.

  29. Pixel Mapping - void glPixelMap{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

  30. GL_float lut[256]; for (I=0; I < 256; ++I) lut[I]=pow(i/255.0, 1.0/1.7); glPixelTransferi(GL_MAP_COLOR, GL_TRUE); glPixelMap(GL_PIXEL_MAP_R_TO_R, 256, lut); glPixelMap(GL_PIXEL_MAP_G_TO_G, 256, lut); glPixelMap(GL_PIXEL_MAP_B_TO_B, 256, lut);

  31. Pixel Zooming uPixel을 확대, 축소, Flipping 등을 할 수 있다. glDrawPixels, glCopyPixels 등에 적용됨. uvoid glPixelZoom(GLfloat zoomx, GLfloat zoomy); uglPixelZoom(-1.0, 1.0) // image는 수평으로 flip

More Related