32
Drawing Pixel, Bitmap, Image

Drawing Pixel, Bitmap, Image. Bitmap Bitmap: Pixel 당 1 bit (0/1) 의 array Bitmap 색상 : bitmap 1 에 대응하는 frame buffer 의 색상은 현재 raster color 로 설정된다

Embed Size (px)

DESCRIPTION

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

Citation preview

Page 1: Drawing Pixel, Bitmap, Image. Bitmap Bitmap: Pixel 당 1 bit (0/1) 의 array Bitmap 색상 : bitmap 1 에 대응하는 frame buffer 의 색상은 현재 raster color 로 설정된다

Drawing Pixel, Bitmap, Image

Page 2: Drawing Pixel, Bitmap, Image. Bitmap Bitmap: Pixel 당 1 bit (0/1) 의 array Bitmap 색상 : bitmap 1 에 대응하는 frame buffer 의 색상은 현재 raster color 로 설정된다

Bitmap• Bitmap: Pixel 당 1 bit (0/1) 의 array• Bitmap 색상 : bitmap 1 에 대응하는 frame bu

ffer 의 색상은 현재 raster color 로 설정된다 .• bitmap display 위치 : 현재 raster 위치에

상대적으로 결정 . • 현재 raster 위치 설정 : glRasterPos*() 함수 • Bitmap 의 draw: glBitmap() 함수

Page 3: Drawing Pixel, Bitmap, Image. Bitmap Bitmap: Pixel 당 1 bit (0/1) 의 array Bitmap 색상 : bitmap 1 에 대응하는 frame buffer 의 색상은 현재 raster color 로 설정된다

Bitmap Data

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

Page 4: Drawing Pixel, Bitmap, Image. Bitmap Bitmap: Pixel 당 1 bit (0/1) 의 array Bitmap 색상 : bitmap 1 에 대응하는 frame buffer 의 색상은 현재 raster color 로 설정된다

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 부터 위로 정의한다 .

Page 5: Drawing Pixel, Bitmap, Image. Bitmap Bitmap: Pixel 당 1 bit (0/1) 의 array Bitmap 색상 : bitmap 1 에 대응하는 frame buffer 의 색상은 현재 raster color 로 설정된다

Raster 위치 설정

• glRasterPos{234}{sifd}(x, y, z, w);• glRasterPosfv {234}{sifd}(coords);• 명 기 한 좌 표 값 은 vertex 좌 표 와

동일하게 변환된다 .• raster position data 구성 = three windo

w coordinates (x, y, z) + clip coordinate w value + an eye coordinate distance + a valid bit + associated color data + texture coordinates

Page 6: Drawing Pixel, Bitmap, Image. Bitmap Bitmap: Pixel 당 1 bit (0/1) 의 array Bitmap 색상 : bitmap 1 에 대응하는 frame buffer 의 색상은 현재 raster color 로 설정된다

bitmap 의 draw • glBitmap(Glsizei width, Glsizei height, GLfloat xorig,

GLfloat yorig, GLfloat xmove, GLfloat ymove, const GLubyte * bitmap)

• xorg, yorg: Bitmapxorg, yorg: Bitmap 의 원점의 원점 . . 현재의 현재의 raster positionraster position 과 과 bitmapbitmap 의 의 (xorg, yorg) (xorg, yorg) 위치를 일치 시킨다위치를 일치 시킨다 ..

• xmove, ymove: bitmapxmove, ymove: bitmap 이 이 drawdraw 된후 된후 raster positionraster position이 이동되는 이 이동되는 offset offset

• 좌표의 모든 단위는 좌표의 모든 단위는 pixelpixel 임 임

Page 7: Drawing Pixel, Bitmap, Image. Bitmap Bitmap: Pixel 당 1 bit (0/1) 의 array Bitmap 색상 : bitmap 1 에 대응하는 frame buffer 의 색상은 현재 raster color 로 설정된다

bitmap 의 draw

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

위치하게 된다 .

Page 8: Drawing Pixel, Bitmap, Image. Bitmap Bitmap: Pixel 당 1 bit (0/1) 의 array Bitmap 색상 : bitmap 1 에 대응하는 frame buffer 의 색상은 현재 raster color 로 설정된다

bitmap 의 색지정• glColor3f(1.0, 1.0, 1.0); /* white */ glR

asterPos3fv(position); glColor3f(1.0, 0.0, 0.0); /* red */ glBit

map(....);• 위의 code 에서 bitmap 은 white color

로 그려진다 . • GL_CURRENT_RASTER_COLOR is set wh

en glRasterPos() is called

Page 9: Drawing Pixel, Bitmap, Image. Bitmap Bitmap: Pixel 당 1 bit (0/1) 의 array Bitmap 색상 : bitmap 1 에 대응하는 frame buffer 의 색상은 현재 raster color 로 설정된다

Image• Image(Pixmap): more information (colors) f

or each pixel. For example, RGBA pixel• Image Source - 사진을 scanning - frame buffer - 프로그램으로 memory 에 생성

Page 10: Drawing Pixel, Bitmap, Image. Bitmap Bitmap: Pixel 당 1 bit (0/1) 의 array Bitmap 색상 : bitmap 1 에 대응하는 frame buffer 의 색상은 현재 raster color 로 설정된다

Pixel Data 의 Read/Draw/Copy

• glReadPixels(): framebuffer 에서 읽어 processor memory 에 data 저장

• glDrawPixels(): processor memory 의 pixel data 를 framebuffer로

• glCopyPixels(): Framebufferdml pixel 을 frame buffer 로 복사 .• glDrawPixels()/glCopyPixels() 함수에서 raster 위치는 glRasterP

os*() 로 지정된다 .

Page 11: Drawing Pixel, Bitmap, Image. Bitmap Bitmap: Pixel 당 1 bit (0/1) 의 array Bitmap 색상 : bitmap 1 에 대응하는 frame buffer 의 색상은 현재 raster color 로 설정된다

• glDrawPixels(width, height, format, type, GLvoid *pixels);

- From : 프로세서 memory 의 array pixels - To : framebuffer 에 현재의 raster position 에서 widt

h 와 height 의 사각형 크기로 - format : memory 에 있는 pixel 의 formats - type : memory 에 있는 pixel component 의 data typ

e - raster position 의 설정은 glRasterPos*() 함수를

사용 - 쓰여질 framebuffer 는 glDrawBuffer(GL_BACK)

함수 를 사용 . 이 함수에 인수로는 GL_BACK, GL_FRO

NT, GL_LEFT, GL_RIGHT, GL_FRONT_LEFT 등을 사용

Page 12: Drawing Pixel, Bitmap, Image. Bitmap Bitmap: Pixel 당 1 bit (0/1) 의 array Bitmap 색상 : bitmap 1 에 대응하는 frame buffer 의 색상은 현재 raster color 로 설정된다

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();

예제 Code

Page 13: Drawing Pixel, Bitmap, Image. Bitmap Bitmap: Pixel 당 1 bit (0/1) 의 array Bitmap 색상 : bitmap 1 에 대응하는 frame buffer 의 색상은 현재 raster color 로 설정된다

Pixel Reading 함수 : Frame buffer 에서 pixel data 를 읽어 memory 로 저장

glReadPixels(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) 함수를 사용하여 지정한다 .

Page 14: Drawing Pixel, Bitmap, Image. Bitmap Bitmap: Pixel 당 1 bit (0/1) 의 array Bitmap 색상 : bitmap 1 에 대응하는 frame buffer 의 색상은 현재 raster color 로 설정된다

Pixel Copying: glCopyPixels 함수 ()

• glCopyPixels(x, y, width, height, buffer);• - From : framebuffer rectange whose lower-left corner i

s at (x,y) and dimensions are width and height -To : framebuffer with its lower-left corner at the cur

rent raster position• - buffer : GL_DEPTH, GL_STENCIL or GL_COLOR • -data 가 memory 에 저장되지 않으므로 format 과• type 은 필요 없다 .• - source buffer 는 glReadBuffer() 함수로• destination buffer 는 glWriteBuffer() 함수로 지정

Page 15: Drawing Pixel, Bitmap, Image. Bitmap Bitmap: Pixel 당 1 bit (0/1) 의 array Bitmap 색상 : bitmap 1 에 대응하는 frame buffer 의 색상은 현재 raster color 로 설정된다

Image 처리 Pipeline

Page 16: Drawing Pixel, Bitmap, Image. Bitmap Bitmap: Pixel 당 1 bit (0/1) 의 array Bitmap 색상 : bitmap 1 에 대응하는 frame buffer 의 색상은 현재 raster color 로 설정된다

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

Page 17: Drawing Pixel, Bitmap, Image. Bitmap Bitmap: Pixel 당 1 bit (0/1) 의 array Bitmap 색상 : bitmap 1 에 대응하는 frame buffer 의 색상은 현재 raster color 로 설정된다

glCopyPixels() pipeline

Page 18: Drawing Pixel, Bitmap, Image. Bitmap Bitmap: Pixel 당 1 bit (0/1) 의 array Bitmap 색상 : bitmap 1 에 대응하는 frame buffer 의 색상은 현재 raster color 로 설정된다

glBitmap pipeline

Page 19: Drawing Pixel, Bitmap, Image. Bitmap Bitmap: Pixel 당 1 bit (0/1) 의 array Bitmap 색상 : bitmap 1 에 대응하는 frame buffer 의 색상은 현재 raster color 로 설정된다

glTexImage*(), glTexSubImage*(), glGetTexImage()

Page 20: Drawing Pixel, Bitmap, Image. Bitmap Bitmap: Pixel 당 1 bit (0/1) 의 array Bitmap 색상 : bitmap 1 에 대응하는 frame buffer 의 색상은 현재 raster color 로 설정된다

glCopyTexImage*()/glCopyTexSubImage*()

Page 21: Drawing Pixel, Bitmap, Image. Bitmap Bitmap: Pixel 당 1 bit (0/1) 의 array Bitmap 색상 : bitmap 1 에 대응하는 frame buffer 의 색상은 현재 raster color 로 설정된다

Pixel Storage Mode 의 control

• glPixelStore{if}() 함수를 사용• Byte Swapping• LSB ordering• Row or pixel skipping 작업

Page 22: Drawing Pixel, Bitmap, Image. Bitmap Bitmap: Pixel 당 1 bit (0/1) 의 array Bitmap 색상 : bitmap 1 에 대응하는 frame buffer 의 색상은 현재 raster color 로 설정된다

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

Page 23: Drawing Pixel, Bitmap, Image. Bitmap Bitmap: Pixel 당 1 bit (0/1) 의 array Bitmap 색상 : bitmap 1 에 대응하는 frame buffer 의 색상은 현재 raster color 로 설정된다

• 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 의 수를 설정

Page 24: Drawing Pixel, Bitmap, Image. Bitmap Bitmap: Pixel 당 1 bit (0/1) 의 array Bitmap 색상 : bitmap 1 에 대응하는 frame buffer 의 색상은 현재 raster color 로 설정된다
Page 25: Drawing Pixel, Bitmap, Image. Bitmap Bitmap: Pixel 당 1 bit (0/1) 의 array Bitmap 색상 : bitmap 1 에 대응하는 frame buffer 의 색상은 현재 raster color 로 설정된다

• 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 에 저장

Page 26: Drawing Pixel, Bitmap, Image. Bitmap Bitmap: Pixel 당 1 bit (0/1) 의 array Bitmap 색상 : bitmap 1 에 대응하는 frame buffer 의 색상은 현재 raster color 로 설정된다

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

Page 27: Drawing Pixel, Bitmap, Image. Bitmap Bitmap: Pixel 당 1 bit (0/1) 의 array Bitmap 색상 : bitmap 1 에 대응하는 frame buffer 의 색상은 현재 raster color 로 설정된다

Pixel Transfer Operation- Color biasing, scaling, mapping …. 등을 수행 :

Color, color index, depth, stencil pixel 에 대하여 적용됨 .

-glDrawPixels, glReadPixels, glCopyPixels, glTexImage1D, and glTexImage2D 함 수 에

영향을 줌 .- void glPixelTransfer{if}(GLenum pname, TY

PE param);

Page 28: Drawing Pixel, Bitmap, Image. Bitmap Bitmap: Pixel 당 1 bit (0/1) 의 array Bitmap 색상 : bitmap 1 에 대응하는 frame buffer 의 색상은 현재 raster color 로 설정된다

void glPixelTransfer{if}(GLenum pname, TYPE param);

함수

• GL_MAP_COLOR, GL_MAP_STENCIL: TRUE/FALSE MAPPING 의 적용여부• GL_RED_SCALE, GL_ALPHA_SCALE, GL_DEPTH_SCAL

E: 색의 component 에 곱하여지는 factor • GL_RED_BIAS, etc: 색의 component 에 더해지는 값

Page 29: Drawing Pixel, Bitmap, Image. Bitmap Bitmap: Pixel 당 1 bit (0/1) 의 array Bitmap 색상 : bitmap 1 에 대응하는 frame buffer 의 색상은 현재 raster color 로 설정된다

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 에 의하여 값이 보정된다 .

Page 30: Drawing Pixel, Bitmap, Image. Bitmap Bitmap: Pixel 당 1 bit (0/1) 의 array Bitmap 색상 : bitmap 1 에 대응하는 frame buffer 의 색상은 현재 raster color 로 설정된다

Pixel Mapping- void glPixelMap{ui us f}(GLenum map, Lint mapsize, const TY

PE *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

Page 31: Drawing Pixel, Bitmap, Image. Bitmap Bitmap: Pixel 당 1 bit (0/1) 의 array Bitmap 색상 : bitmap 1 에 대응하는 frame buffer 의 색상은 현재 raster color 로 설정된다

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);

Page 32: Drawing Pixel, Bitmap, Image. Bitmap Bitmap: Pixel 당 1 bit (0/1) 의 array Bitmap 색상 : bitmap 1 에 대응하는 frame buffer 의 색상은 현재 raster color 로 설정된다

Pixel Zooming

Pixel 을 확대 , 축소 , Flipping 등을 할 수 있 다 . glDrawPixels, glCopyPixels 등에 적용됨 .

void glPixelZoom(GLfloat zoomx, GLfloat zoomy);

glPixelZoom(-1.0, 1.0) // image 는 수평으로 flip