티스토리 뷰
// normal read
FILE *f = fopen("file.bmp", "rb");
unsigned char info[54];
fread(info, sizeof(unsigned char), 54, f);
int width = *(int*)&info[18];
int height = *(int*)&info[22];
int size = 3*width*height; // for RGB
unsigned char *data = new unsigned char[size];
fread(data, sizeof(unsigned char), size, f);
fclose(f);
// bmp를 저장할 때 RGB가 아닌 BGR순으로 저장하기 때문
for(int i=0; i<size; i+=3){
unsigned char temp = data[i];
data[i] = data[i+2];
data[i+2] = temp;
}
일부 bmp파일은 색 정보를 저장할 때 줄 바꿈 정보를 포함하고 있으므로 다음과 같이 읽는다.
// row padded read
FILE *f = fopen("file.bmp", "rb");
unsigned char info[54];
fread(info, sizeof(usnigned char), 54, f);
int width = *(int*)&info[18];
int height = *(int*)&info[22];
int rowPadded = (3*width + 3) & (~3);
unsigned char *data = new unsigned char[rowPadded];
unsigned char temp;
for(int i=0; i<height; i++){
fread(data, sizeof(unsigned char), rowPadded, f);
for(int j=0; j<width; j++){
temp = data[j];
data[j] = data[j+2];
data[j+2] = temp;
}
}
'Programming > Algorithm' 카테고리의 다른 글
Lerp 연산 (Linear Interpolation) (0) | 2020.07.17 |
---|---|
3 match game 알고리즘 : CrossCheck (0) | 2017.01.08 |
3 match game 알고리즘 : match3 (0) | 2017.01.05 |
3 match game 알고리즘 : Swap (3) | 2017.01.03 |
유도탄 만들기(Guided Missile) (2) | 2015.08.22 |
- Total
- Today
- Yesterday
- SOCKET
- JSP
- scala
- 드라마
- OS
- 국내여행
- SHADER
- ue4
- game
- Cocos2d-x
- 알고리즘
- ios
- SwiftUI
- Spring
- 자료구조
- winsock
- rxswift
- swift
- 운영체제
- machine learing
- 수학
- C/C++
- 데이터베이스
- Git
- C++
- mongoDB
- DesignPattern
- C
- Java
- database
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 | 31 |