This is default featured slide 1 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 2 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 3 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 4 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 5 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

*/
레이블이 BMP인 게시물을 표시합니다. 모든 게시물 표시
레이블이 BMP인 게시물을 표시합니다. 모든 게시물 표시

Image buffer를 Bitmap file format으로 저장하기(RGB)

Image처리를 하다보면 memory buffer에 있는 image raw데이터를 BMP포멧으로 저장할 필요가 있다.
RGB Buffer(24bit)를 widows bitmap format으로 저장하는 함수

// _fname : 저장할 파일 명( xxx.bmp )
// _buf : RGB 순서로 구성된 Image buff
// _w, _h : image width, height
void saveBMPfile(char *_fnameuchar* _bufint _wint _h)
{
    int filesize = 54 + _w * _h * 3;
    unsigned char bmpfileheader[14] = {'B','M'0,0,0,00,00,054,0,0,0};
    unsigned char bmpinfoheader[40] = {40,0,0,00,0,0,00,0,0,01,08,0};
    unsigned char bmppad[3] = {0,0,0};

    bmpfileheader2] = (unsigned char)(filesize    );
    bmpfileheader3] = (unsigned char)(filesize>> 8);
    bmpfileheader4] = (unsigned char)(filesize>>16);
    bmpfileheader5] = (unsigned char)(filesize>>24);

    bmpinfoheader4] = (unsigned char)( _w    );
    bmpinfoheader5] = (unsigned char)( _w>> 8);
    bmpinfoheader6] = (unsigned char)( _w>>16);
    bmpinfoheader7] = (unsigned char)( _w>>24);
    bmpinfoheader8] = (unsigned char)( _h    );
    bmpinfoheader9] = (unsigned char)( _h>> 8);
    bmpinfoheader[10] = (unsigned char)( _h>>16);
    bmpinfoheader[11] = (unsigned char)( _h>>24);

    FILE* fp;
    fp =fopen(_fname, "wb");
    if(fp!=NULL) {
        fwrite(bmpfileheader, 114, fp);
        fwrite(bmpinfoheader, 140, fp);
        fwrite(_buf, _w*_h, 3, fp);
        fclose(fp);
    }
}


* Gray Bufferer 저장하기 : 링크

관련문서

Image buffer를 Bitmap file format으로 저장하기(Gray image)

 Image처리를 하다보면 memory buffer에 있는 image raw데이터를 BMP포멧으로 저장할 필요가 있다.

Gray Buffer(8bit)를 widows bitmap fotmat으로 저장하는 함수

// _fname : 저장할 파일 명( xxx.bmp )
// _buf : RGB 순서로 구성된 Image buff
// _w, _h : image width, height
void saveBMPfile(char *_fnameuchar* _bufint _wint _h)
{
    int filesize = 54 + 256*4 + _w*_h;
    unsigned char bmppalete[256*4];
    unsigned char bmpfileheader[14] = {'B','M'0,0,0,00,00,054+256*4,0,0,0};
    unsigned char bmpinfoheader[40] = {40,0,0,00,0,0,00,0,0,01,08,0};
    unsigned char bmppad[3] = {0,0,0};

// BMP File header의 내용을 채워넣는다
// File의 크기
    bmpfileheader2] = (unsigned char)(filesize    );
    bmpfileheader3] = (unsigned char)(filesize>> 8);
    bmpfileheader4] = (unsigned char)(filesize>>16);
    bmpfileheader5] = (unsigned char)(filesize>>24);

// Image buffer의 Width
    bmpinfoheader4] = (unsigned char)( _w    );
    bmpinfoheader5] = (unsigned char)( _w>> 8);
    bmpinfoheader6] = (unsigned char)( _w>>16);
    bmpinfoheader7] = (unsigned char)( _w>>24);
// Image buffer의 Height
    bmpinfoheader8] = (unsigned char)( _h    );
    bmpinfoheader9] = (unsigned char)( _h>> 8);
    bmpinfoheader[10] = (unsigned char)( _h>>16);
    bmpinfoheader[11] = (unsigned char)( _h>>24);

// Pallet 정보 Windows Format의 구성 : RGBx 4Byte
// 8bit Image의 경우 Pallet의 크기 2^8 = 256
// Gray Image의 경우 RGB 동일값
    for(int i=0; i<256;i++) {
        bmppalete[i*4] = bmppalete[i*4+1] = bmppalete[i*4+2] = i;
        bmppalete[i*4+3] = 0;
    }
    FILE* fp;
    fp = fopen(_fname, "wb");
    if(fp!=NULL) {
        fwrite(bmpfileheader, 114, fp);
        fwrite(bmpinfoheader, 140, fp);
        fwrite(bmppalete, 1256*4, fp);
        fwrite(_buf, _w*_h, 1, fp);
        fclose(fp);
    }
}

* Color Buffer(RGB) 저장 : https://amosground.blogspot.com/2020/10/image-buffer-bitmap-file-format-rgb.html

관련문서