typedef unsigned char BYTE : windows
typedef unsigned char uint8_t : Linux
typedef unsigned char uchar : opencv
class RGB
{
unsigned char R;
unsigned char G;
unsigned char B;
}
int w = 640;
int h = 480;
// stack 영역에 로컬 변수 형태로 할당
unsigned char** p;
// h개 변수 만큼의 포인터 생성, p가 위치 가리킴
p = new unsigned char*[h];
for (int i = 0; i < h; i++) {
// w개 변수 만큼의 포인터 생성, p[i]가 위치 가리킴
p[i] = new unsigned char[w] {};
}
동적 2차원 배열의 원소에 접근
동적 2차원 배열 메모리 해제
for (int y = 0; y < h; y++)
delete[] p[i];
delete[] p;
int w = 10, h = 10;
unsigned char* data = new unsigned char[w * h] {};
...
delete[] data;
// 값을 받아서 변경 가능하도록 참조자로 값 받음
unsigned char& p1 = *(data + y*w + x);
class MyImage
{
public:
// 기본 생성자
MyImage(): w(0), h(0), data(0) {}
// w, h를 받아올 경우 생성자
MyImage(int _w, int _h): w(_w), h(_h) {
data = new unsigned char[w * h] {};
}
// 소멸자
~MyImage() {
if (data) delete[] data;
}
unsigned char& at(int x, int y) {
return *(data + y * w + x);
}
public:
int w, h;
unsigned char* data;
}
BMP
JPG
GIF
PNG (TIF 도 유사)
비트맵
비트맵의 종류
비트맵 종류 (출처: 비트맵 구조(비트맵 분석 #4))
Ex) FHD 동영상을 BMP 형식으로 1분 재생하려면? 메모리 할당량은 다음과 같음:
1920 x 1080 x 3 = 약 2000 x 1000 x 3 = 6 MB
1초 당 30 fps라 가정 한다면, 6 MB x 30 = 180 MB
1분의 경우: 180 MB x 60 = 10800 MB = 약 10 GB
압축의 경우 픽셀 값이 크게 안바뀌면(low frequency) 더 많이 압축되고, 고주파 성분(high frequency)이 더 강하면 덜 압축되는 경향을 보임