멀티미디어공학 에 해당하는 글3 개
2008.10.11   [멀티미디어공학]Bitmap Parser
2008.10.11   [멀티미디어공학]Ordered Dithering
2008.10.11   [멀티미디어공학]Simple Dithering


[멀티미디어공학]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이다.

 

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





 
 
 
트랙백 | 댓글



[멀티미디어공학]Ordered Dithering
日新又日新 | 2008. 10. 11. 05:46
#2. Ordered Dithering

 1://------------------[simple dither algorithm start]--------------------
 2:// input : in_img,        output : out_img
 3:int pixel_x, pixel_y;
 4:int i, j;
 5:int level;
 6:int ordermatrix[4][4] = {{0, 8, 2, 10}, {12, 4, 14, 6}, {3, 11, 1, 9}, {15, 7,  13, 5} };
 7:for ( pixel_x = 0 ; pixel_x < XSIZE ; pixel_x++ ) {
 8:    for ( pixel_y = 0 ; pixel_y < YSIZE ; pixel_y++ ) {
 9:        level = in_img[pixel_x][pixel_y] / 16;
10:        i = pixel_x % 4;
11:        j = pixel_y % 4;
12:
13:        if ( level > ordermatrix[i][j] ) {
14:            out_img[pixel_x][pixel_y] = 255;
15:        } else {
16:            out_img[pixel_x][pixel_y] = 0;
17:        }
18:    }
19:}
20://------------------[simple dither algorithm end]--------------------


Simple Dithreing에 비해서 레벨 0일 때의 처리가 없음.
10~11 : Dither Matrix에서 비교할 대상 설정
13~17 : 현재 나눠진 레벨값을 Dither Matrix에서 비교대상과 비교하여 흑/백 결정
         -> 결과 파일에서의 픽셀크기가 변경되지 않음


 
 
 
트랙백 | 댓글



[멀티미디어공학]Simple Dithering
日新又日新 | 2008. 10. 11. 05:44
#1. Simple Dithering

 1: //------------------[simple dither algorithm start]--------------------
 2:// input : in_img,        output : out_img
 3:int pixel_x, pixel_y;
 4:int level;
 5:int simplematrix[4][1] = { {0}, {3}, {2}, {1} };
 6:int i, j;
 7:for ( pixel_x = 0 ; pixel_x < XSIZE ; pixel_x++ ) {
 8:    for ( pixel_y = 0 ; pixel_y < YSIZE ; pixel_y++ ) {
 9:        level = in_img[pixel_x][pixel_y] / 52;
10:        for ( i = 0 ; i < 2 ; i++) {
11:            for ( j = 0 ; j < 2 ; j++) {
12:                if ( level == 0 ) {
13:                    out_img[pixel_x * 2 + i][pixel_y * 2 + j] = 0;
14:                } else {
15:                    if ( level <= simplematrix[i][j] ) {
16:                        out_img[pixel_x * 2 + i][pixel_y * 2 + j] = 0;
17:                    } else {
18:                        out_img[pixel_x * 2 + i][pixel_y * 2 + j] = 255;
19:                    }
20:                }
21:            }
22:        }
23:    }
24:}
25:    //------------------[simple dither algorithm end]--------------------


5: Dither Matrix 설정
7~8 : 각 픽셀에 대해서
9 : 레벨값(255)을 5단계로 나눔
10~11 : 한 픽셀을 4픽셀로 표현
13 : 나눠진 레벨값이 0이면 0
14~19: 나눠진 레벨값이 0이 아니면 Dither Matrix와 비교해서 작은 곳은 백색, 큰 곳은 흑색


 
 
 
트랙백 | 댓글



위치로그 : 태그 : 방명록 : 관리자
이우성'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