[멀티미디어공학]Bitmap Parser
日新又日新 | 2008. 10. 11. 05:51

#define Read_2B(fp)    (fgetc(fp) + 0x100*fgetc(fp))
#define Read_4B(fp)    (fgetc(fp) + 0x100*fgetc(fp) + 0x10000*fgetc(fp) + 0x1000000*fgetc(fp))

struct bmp_header {
    short    magic_no;
    int    size;
    short    reserved1;
    short    reserved2;
    int    offset;
};

struct bmp_info {
    int    size_header;
    int    width;
    int    height;
    short    no_color_planes;
    short    bit_per_pixel;
    int    compression;
    int    img_size;
    int    h_resolution;
    int    v_resolution;
    int    no_colors_used;
    int    no_imp_colors;

    long int h_resolution_dpi;
    long int v_resolution_dpi;
};

//비트맵 헤더 관련 코드

my_header.magic_no = Read_2B(fpi);//첫 2바이트 : 비트맵 파일의 매직넘버, 파일의 종류를 나타낸다.

// insert codes to fetch bmp_header information

my_header.size = Read_4B(fpi);//다음 4바이트 : 파일의 사이즈

for (int x = 2 ; x > 0 ; x--) {//다음 2바이트 2개 : reserved 영역, 0이 아니면 문제가 있는 것이다.

//printf("%d : %x\n", x, Read_2B(fpi));

if (Read_2B(fpi) != 0x00)

printf("Bitmap File is incorrect!!\n");

}

my_header.offset = Read_4B(fpi);//다음 4바이트 : 오프셋, 실질 데이터 시작 주소가 얼마나 떨어져 있는지 나타낸다.

 

//...비트맵 헤더 정보 출력...

 

// insert codes to fetch bmp_information

if ((my_info.size_header = Read_4B(fpi)) != BMP_INFO) {//헤더 크기, 40byte가 아니면 winV3 포맷이 아니다.

printf("This file is not Windows V3 format!!!\n");

fclose(fpi);

fclose(fpo);

return 0;

}

my_info.width = Read_4B(fpi);//이미지 폭

my_info.height = Read_4B(fpi);//이미지 높이

my_info.no_color_planes = Read_2B(fpi);//색평면 개수(Color Plane), 반드시 1이어야 한다.

my_info.bit_per_pixel = Read_2B(fpi);//픽셀당 비트수

my_info.compression = Read_4B(fpi);//압축 방식

my_info.img_size = Read_4B(fpi);//이미지 크기, 파일 사이즈가 아닌 이미지의 로우데이터 크기이다.

my_info.h_resolution = Read_4B(fpi);//Horizontal 해상도, 미터당 픽셀수로 나타난다.

my_info.h_resolution_dpi = my_info.h_resolution*10000/393700;//Horizontal 해상도, dpi로 나타낸다.

my_info.v_resolution = Read_4B(fpi);//Vertical 해상도, 미터당 픽셀수로 나타난다.

my_info.v_resolution_dpi = my_info.v_resolution*10000/393700;//Vertical 해상도, dpi로 나타낸다.

my_info.no_colors_used = Read_4B(fpi);//사용된 색상 수

my_info.no_imp_colors = Read_4B(fpi);//중요하게 사용된 색상수, 모든 색상이 중요하면 0이다.

 

//...비트맵 정보 출력...





 
 
 
트랙백 | 댓글



위치로그 : 태그 : 방명록 : 관리자
이우성's Blog is powered by Daum / Designed by SSen
관리자  |  글쓰기
BLOG main image
전, 이우성입니다. ( I am Woosung, Lee. ) ""
 Category
 Media
 TAGS
 Recent Entries
 Recent Comments
 Calendar
 Archive
 Link Site
 Visitor Statistics
+ Total :
+ Today :
+ Yesterday :
카피
rss