본문 바로가기

프로그래밍/미분류

[번역] 팩 디바이스-인디펜던트 비트맵

반응형
Windows Graphics Programming Win32 GDI and DirectDraw


Chapter 10 Bitmap Basics

10.1 Device-Independent Bitmap Formats

Packed Device-Independent Bitmap

The BMP file format is the format in which a DIB is stored in an independent disk file. We mentioned that a BMP file contains a file header, a bitmap information block, and a pixel array. The file header serves an information purpose during loading of a DIB into memory. But once in memory, the file header is no longer needed. The file header can be reconstructed from the bitmap information header.

A DIB without a file header is called a packed DIB. The word packed here does not mean the way in which pixels are packed in a scan line. It conveys that the remaining pieces of a DIB are next to each other in a continuous memory.

A packed DIB starts with a bitmap information header, followed by a mask array, color table, and pixel array. Win32 API commonly use a pointer to BITMAPINFO structure to denote a packed DIB pointer. Although the structure has no reference to the mask array and pixel array, at least it tells you there is a color table.

Quite a few Win32 API return and accept packed DIBs. When DIBs are included in executable files as resources, FindResource, LoadResource, and LockResource can be used to return a pointer to a packed DIB. CreateDIBPatternBrushPt uses a packed DIB to create a pattern brush. The Window clipboard also uses packed DIBs.

Within an in-memory packed DIB, the color table could be a table of indexes to a logical palette. For example, if the iUsage parameter to CreateDIBPatternBrushPt is DIB_PAL_COLORS, the color table is an array of indexes. But such a DIB should not be passed to other applications or written to disk, unless you're only dealing with willing partners. There is no flag in the DIB file format to tell that the color table is relative to an unknown palette.

팩 디바이스 인디펜던트 비트맵(Packed Device-Independent Bitmap)

BMP 파일 포맷은 DIB를 독립적인 디스크상의 파일로 저장할 때 필요한 포맷이다. 이제 우린 BMP 파일은 파일 헤더와 비트맵 인포메이션 블럭, 픽셀 배열로 이루어졌다는 걸 알고 있다. 이 가운데 파일 헤더는 DIB를 메모리로 로드할 때만 사용되는 정보로, 메모리에 올라간 후에는 필요가 없다. 파일 헤더는 또한 비트맵 인포메이션 헤더로부터 재구성할 수 있다.

파일 헤더를 뺀 나머지 DIB를 팩 DIB 라고 한다. 여기서 팩(packed)이란 픽셀이 한 스캔라인에 패킹되어 있다는 뜻이 아니고, 파일 헤더를 뺀 나머지 부분이 메모리에 연속적으로 있다는 뜻이다.

팩 DIB는 비트맵 인포메이션 헤더로 시작해서, 마스크 어레이, 컬러 테이블, 픽셀 어레이까지 이어진다. Win32 API는 이 팩 DIB를 가리키기 위해서 보통 BITMAPINFO 구조체 포인터를 사용한다. 비록 이 구조체에 마스크 어레이와 픽셀 어레이는 없지만, 최소한 컬러 테이블은 들어 있다.

많은 Win32 API가 이와같은 팩 DIB를 반환하거나 인자로 받는다. DIB가 실행파일에 리소스로 포함되었을 경우 사용하는 FindResource, LoadResource, LockResource 는 팩 DIB의 포인터를 반환한다. CreateDIBPatternBrushPt 도 팩 DIB를 사용해 패턴 브러시를 만든다. Windows 클립보드 또한 팩 DIB를 사용한다.

메모리 내부의 팩 DIB의 컬러 테이블은 논리 팔레트의 테이블 인덱스값을 가질 수 있다. 예를 들어, CreateDIBPatternBrushPt 의 iUsage 패러미터가 DIB_PAL_COLORS라면, 컬러 테이블은 인덱스의 배열이다. 그러나 이런 DIB는 다른 응용 프로그램에게 전달하거나, 디스크에 저장해서는 안 된다. DIB 파일 포맷 자체에는 컬러 테이블이 어떤 팔레트의 인덱스라는 걸 알려주는 플래그가 없기 때문이다.
728x90