이 프로젝트는 비트맵 이미지를 처리하는 애플리케이션의 첫 번째 단계입니다. 비트맵의 기본 구조와 파일 형식에 대해 이해하고, 간단한 이미지 처리 기능을 구현합니다.
비트맵 파일은 다음과 같은 구조로 이루어져 있습니다:
typedef struct {
unsigned short type; // Magic identifier: 0x4d42
unsigned int size; // File size in bytes
unsigned short reserved1; // Reserved
unsigned short reserved2; // Reserved
unsigned int offset; // Offset to image data in bytes
} BMPFileHeader;
typedef struct {
unsigned int size; // Header size in bytes
int width, height; // Width and height of image
unsigned short planes; // Number of color planes
unsigned short bits; // Bits per pixel
unsigned int compression; // Compression type
unsigned int imagesize; // Image size in bytes
int xresolution, yresolution; // Pixels per meter
unsigned int ncolors; // Number of colors
unsigned int importantcolors; // Important colors
} BMPInfoHeader;
각 픽셀의 R, G, B 값에 가중치를 적용하여 그레이스케일로 변환합니다:
// RGB to Grayscale conversion
unsigned char toGrayscale(unsigned char r, unsigned char g, unsigned char b) {
return (unsigned char)(0.299 * r + 0.587 * g + 0.114 * b);
}
픽셀 값을 255에서 뺄셈하여 반전시킵니다:
// Invert color
unsigned char invertPixel(unsigned char pixel) {
return 255 - pixel;
}
Phase2에서는 다음과 같은 기능을 추가할 예정입니다: