|
|
|
|
@ -24,8 +24,6 @@ std::string toBits(unsigned int i, int maxbits);
|
|
|
|
|
#define BITCONV(d) ((d>>8) & 0xff)
|
|
|
|
|
#define STORE if (dst) { *(dst++) = BITCONV(r); *(dst++) = BITCONV(g); *(dst++) = BITCONV(b); src++; }
|
|
|
|
|
#define STORE8 if (dst) { *(dst++) = (r & 0xff); *(dst++) = (g & 0xff); *(dst++) = (b & 0xff); src++; }
|
|
|
|
|
#define STOREF16 if (dstf) { *(dstf++) = ((float)r/65535.0); *(dstf++) = ((float)g/65535.0); *(dstf++) = ((float)b/65535.0); }
|
|
|
|
|
#define STOREF8 if (dstf) { *(dstf++) = ((float)r/255.0); *(dstf++) = ((float)g/255.0); *(dstf++) = ((float)b/255.0); }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
@ -33,7 +31,7 @@ std::string toBits(unsigned int i, int maxbits);
|
|
|
|
|
RGB image by bilinear interpolation.
|
|
|
|
|
*/
|
|
|
|
|
void debayer_grbg16 (uint16_t * src, int src_w, int src_h,
|
|
|
|
|
uint8_t * dst, float * dstf, int dst_w, int dst_h) {
|
|
|
|
|
uint8_t * dst, int dst_w, int dst_h) {
|
|
|
|
|
|
|
|
|
|
// GG RR GG RR
|
|
|
|
|
// BB GG BB GG
|
|
|
|
|
@ -47,7 +45,6 @@ void debayer_grbg16 (uint16_t * src, int src_w, int src_h,
|
|
|
|
|
g = CE;
|
|
|
|
|
b = DN;
|
|
|
|
|
STORE;
|
|
|
|
|
STOREF16;
|
|
|
|
|
|
|
|
|
|
// upper first line, starts with RR GG RR ...
|
|
|
|
|
for (xs = 1; xs < src_w - 1; xs+=2) {
|
|
|
|
|
@ -56,13 +53,11 @@ void debayer_grbg16 (uint16_t * src, int src_w, int src_h,
|
|
|
|
|
g = (LE + RI + DN) / 3;
|
|
|
|
|
b = (DNLE + DNRI) / 2;
|
|
|
|
|
STORE;
|
|
|
|
|
STOREF16;
|
|
|
|
|
// green pixel
|
|
|
|
|
r = (LE + RI) / 2;
|
|
|
|
|
g = CE;
|
|
|
|
|
b = DN;
|
|
|
|
|
STORE;
|
|
|
|
|
STOREF16;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// upper right pixel (red)
|
|
|
|
|
@ -70,7 +65,6 @@ void debayer_grbg16 (uint16_t * src, int src_w, int src_h,
|
|
|
|
|
g = (DN + LE) / 2;
|
|
|
|
|
b = DNLE;
|
|
|
|
|
STORE;
|
|
|
|
|
STOREF16;
|
|
|
|
|
|
|
|
|
|
// go through the "body" of the image
|
|
|
|
|
for (ys = 1; ys < src_h - 1; ys+=2) {
|
|
|
|
|
@ -82,27 +76,23 @@ void debayer_grbg16 (uint16_t * src, int src_w, int src_h,
|
|
|
|
|
g = (UP + DN + RI) / 3;
|
|
|
|
|
b = CE;
|
|
|
|
|
STORE;
|
|
|
|
|
STOREF16;
|
|
|
|
|
for (xs = 1; xs < src_w - 1; xs+=2) {
|
|
|
|
|
// green pixel
|
|
|
|
|
r = (UP + DN) / 2;
|
|
|
|
|
g = CE;
|
|
|
|
|
b = (LE + RI) / 2;
|
|
|
|
|
STORE;
|
|
|
|
|
STOREF16;
|
|
|
|
|
// blue pixel
|
|
|
|
|
r = (UPLE + UPRI + DNLE + DNRI) / 4;
|
|
|
|
|
g = (LE + RI + UP + DN) / 4;
|
|
|
|
|
b = CE;
|
|
|
|
|
STORE;
|
|
|
|
|
STOREF16;
|
|
|
|
|
}
|
|
|
|
|
// last pixel in line (green)
|
|
|
|
|
r = (UP + DN) / 2;
|
|
|
|
|
g = CE;
|
|
|
|
|
b = LE;
|
|
|
|
|
STORE;
|
|
|
|
|
STOREF16;
|
|
|
|
|
|
|
|
|
|
// every second line with GG RR GG RR ... (start at 3rd line)
|
|
|
|
|
|
|
|
|
|
@ -111,27 +101,23 @@ void debayer_grbg16 (uint16_t * src, int src_w, int src_h,
|
|
|
|
|
g = CE;
|
|
|
|
|
b = (UP + DN) / 2;
|
|
|
|
|
STORE;
|
|
|
|
|
STOREF16;
|
|
|
|
|
for (xs = 1; xs < src_w - 1; xs+=2) {
|
|
|
|
|
// red pixel
|
|
|
|
|
r = CE;
|
|
|
|
|
g = (LE + RI + UP + DN) / 4;
|
|
|
|
|
b = (UPLE + UPRI + DNLE + DNRI) / 4;
|
|
|
|
|
STORE;
|
|
|
|
|
STOREF16;
|
|
|
|
|
// green pixel
|
|
|
|
|
r = (LE + RI) / 2;
|
|
|
|
|
g = CE;
|
|
|
|
|
b = (UP + DN) / 2;
|
|
|
|
|
STORE;
|
|
|
|
|
STOREF16;
|
|
|
|
|
}
|
|
|
|
|
// last pixel in line (red)
|
|
|
|
|
r = CE;
|
|
|
|
|
g = (UP + DN + LE) / 3;
|
|
|
|
|
b = (UPLE + DNLE) / 2;
|
|
|
|
|
STORE;
|
|
|
|
|
STOREF16;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// bottom left pixel
|
|
|
|
|
@ -139,7 +125,6 @@ void debayer_grbg16 (uint16_t * src, int src_w, int src_h,
|
|
|
|
|
g = (UP + RI) / 2;
|
|
|
|
|
b = CE;
|
|
|
|
|
STORE;
|
|
|
|
|
STOREF16;
|
|
|
|
|
|
|
|
|
|
// last line starting with GG BB GG ...
|
|
|
|
|
for (xs = 1; xs < src_w - 1; xs+=2) {
|
|
|
|
|
@ -148,13 +133,11 @@ void debayer_grbg16 (uint16_t * src, int src_w, int src_h,
|
|
|
|
|
g = CE;
|
|
|
|
|
b = (LE + RI) / 2;
|
|
|
|
|
STORE;
|
|
|
|
|
STOREF16;
|
|
|
|
|
// blue pixel
|
|
|
|
|
r = (UPLE + UPRI) / 2;
|
|
|
|
|
g = (LE + UP + RI) / 2;
|
|
|
|
|
b = CE;
|
|
|
|
|
STORE;
|
|
|
|
|
STOREF16;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// bottom right pixel (green)
|
|
|
|
|
@ -162,22 +145,21 @@ void debayer_grbg16 (uint16_t * src, int src_w, int src_h,
|
|
|
|
|
g = CE;
|
|
|
|
|
b = LE;
|
|
|
|
|
STORE;
|
|
|
|
|
STOREF16;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
The function converts a 8bit GRBG 2x2 CFA coded image into an 8bit
|
|
|
|
|
RGB image by bilinear interpolation.
|
|
|
|
|
*/
|
|
|
|
|
void debayer_gbrg8 (uint8_t * src, int src_w, int src_h, uint8_t *dst, float *dstf, int dst_w, int dst_h) {
|
|
|
|
|
debayer_grbg8 (src, src_w, src_h, dst, dstf, dst_w, dst_h);
|
|
|
|
|
void debayer_gbrg8 (uint8_t * src, int src_w, int src_h, uint8_t *dst, int dst_w, int dst_h) {
|
|
|
|
|
debayer_grbg8 (src, src_w, src_h, dst, dst_w, dst_h);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
void debayer_rggb8 (uint8_t * src, int src_w, int src_h, uint8_t * dst, float *dstf, int dst_w, int dst_h) {
|
|
|
|
|
debayer_grbg8 (src, src_w, src_h, dst, dstf, dst_w, dst_h);
|
|
|
|
|
void debayer_rggb8 (uint8_t * src, int src_w, int src_h, uint8_t * dst, int dst_w, int dst_h) {
|
|
|
|
|
debayer_grbg8 (src, src_w, src_h, dst, dst_w, dst_h);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
void debayer_grbg8 (uint8_t * src, int src_w, int src_h, uint8_t * dst, float *dstf, int dst_w, int dst_h) {
|
|
|
|
|
void debayer_grbg8 (uint8_t * src, int src_w, int src_h, uint8_t * dst, int dst_w, int dst_h) {
|
|
|
|
|
|
|
|
|
|
// GG RR GG RR
|
|
|
|
|
// BB GG BB GG
|
|
|
|
|
@ -191,7 +173,6 @@ void debayer_grbg8 (uint8_t * src, int src_w, int src_h, uint8_t * dst, float *d
|
|
|
|
|
g = CE;
|
|
|
|
|
b = DN;
|
|
|
|
|
STORE8;
|
|
|
|
|
STOREF8;
|
|
|
|
|
|
|
|
|
|
// upper first line, starts with RR GG RR ...
|
|
|
|
|
for (xs = 1; xs < src_w - 1; xs+=2) {
|
|
|
|
|
@ -200,13 +181,11 @@ void debayer_grbg8 (uint8_t * src, int src_w, int src_h, uint8_t * dst, float *d
|
|
|
|
|
g = (LE + RI + DN) / 3;
|
|
|
|
|
b = (DNLE + DNRI) / 2;
|
|
|
|
|
STORE8;
|
|
|
|
|
STOREF8;
|
|
|
|
|
// green pixel
|
|
|
|
|
r = (LE + RI) / 2;
|
|
|
|
|
g = CE;
|
|
|
|
|
b = DN;
|
|
|
|
|
STORE8;
|
|
|
|
|
STOREF8;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// upper right pixel (red)
|
|
|
|
|
@ -214,7 +193,6 @@ void debayer_grbg8 (uint8_t * src, int src_w, int src_h, uint8_t * dst, float *d
|
|
|
|
|
g = (DN + LE) / 2;
|
|
|
|
|
b = DNLE;
|
|
|
|
|
STORE8;
|
|
|
|
|
STOREF8;
|
|
|
|
|
|
|
|
|
|
// go through the "body" of the image
|
|
|
|
|
for (ys = 1; ys < src_h - 1; ys+=2) {
|
|
|
|
|
@ -226,27 +204,23 @@ void debayer_grbg8 (uint8_t * src, int src_w, int src_h, uint8_t * dst, float *d
|
|
|
|
|
g = (UP + DN + RI) / 3;
|
|
|
|
|
b = CE;
|
|
|
|
|
STORE8;
|
|
|
|
|
STOREF8;
|
|
|
|
|
for (xs = 1; xs < src_w - 1; xs+=2) {
|
|
|
|
|
// green pixel
|
|
|
|
|
r = (UP + DN) / 2;
|
|
|
|
|
g = CE;
|
|
|
|
|
b = (LE + RI) / 2;
|
|
|
|
|
STORE8;
|
|
|
|
|
STOREF8;
|
|
|
|
|
// blue pixel
|
|
|
|
|
r = (UPLE + UPRI + DNLE + DNRI) / 4;
|
|
|
|
|
g = (LE + RI + UP + DN) / 4;
|
|
|
|
|
b = CE;
|
|
|
|
|
STORE8;
|
|
|
|
|
STOREF8;
|
|
|
|
|
}
|
|
|
|
|
// last pixel in line (green)
|
|
|
|
|
r = (UP + DN) / 2;
|
|
|
|
|
g = CE;
|
|
|
|
|
b = LE;
|
|
|
|
|
STORE8;
|
|
|
|
|
STOREF8;
|
|
|
|
|
|
|
|
|
|
// every second line with GG RR GG RR ... (start at 3rd line)
|
|
|
|
|
|
|
|
|
|
@ -255,27 +229,23 @@ void debayer_grbg8 (uint8_t * src, int src_w, int src_h, uint8_t * dst, float *d
|
|
|
|
|
g = CE;
|
|
|
|
|
b = (UP + DN) / 2;
|
|
|
|
|
STORE8;
|
|
|
|
|
STOREF8;
|
|
|
|
|
for (xs = 1; xs < src_w - 1; xs+=2) {
|
|
|
|
|
// red pixel
|
|
|
|
|
r = CE;
|
|
|
|
|
g = (LE + RI + UP + DN) / 4;
|
|
|
|
|
b = (UPLE + UPRI + DNLE + DNRI) / 4;
|
|
|
|
|
STORE8;
|
|
|
|
|
STOREF8;
|
|
|
|
|
// green pixel
|
|
|
|
|
r = (LE + RI) / 2;
|
|
|
|
|
g = CE;
|
|
|
|
|
b = (UP + DN) / 2;
|
|
|
|
|
STORE8;
|
|
|
|
|
STOREF8;
|
|
|
|
|
}
|
|
|
|
|
// last pixel in line (red)
|
|
|
|
|
r = CE;
|
|
|
|
|
g = (UP + DN + LE) / 3;
|
|
|
|
|
b = (UPLE + DNLE) / 2;
|
|
|
|
|
STORE8;
|
|
|
|
|
STOREF8;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// bottom left pixel
|
|
|
|
|
@ -283,7 +253,6 @@ void debayer_grbg8 (uint8_t * src, int src_w, int src_h, uint8_t * dst, float *d
|
|
|
|
|
g = (UP + RI) / 2;
|
|
|
|
|
b = CE;
|
|
|
|
|
STORE8;
|
|
|
|
|
STOREF8;
|
|
|
|
|
|
|
|
|
|
// last line starting with GG BB GG ...
|
|
|
|
|
for (xs = 1; xs < src_w - 1; xs+=2) {
|
|
|
|
|
@ -292,13 +261,11 @@ void debayer_grbg8 (uint8_t * src, int src_w, int src_h, uint8_t * dst, float *d
|
|
|
|
|
g = CE;
|
|
|
|
|
b = (LE + RI) / 2;
|
|
|
|
|
STORE8;
|
|
|
|
|
STOREF8;
|
|
|
|
|
// blue pixel
|
|
|
|
|
r = (UPLE + UPRI) / 2;
|
|
|
|
|
g = (LE + UP + RI) / 2;
|
|
|
|
|
b = CE;
|
|
|
|
|
STORE8;
|
|
|
|
|
STOREF8;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// bottom right pixel (green)
|
|
|
|
|
@ -306,7 +273,6 @@ void debayer_grbg8 (uint8_t * src, int src_w, int src_h, uint8_t * dst, float *d
|
|
|
|
|
g = CE;
|
|
|
|
|
b = LE;
|
|
|
|
|
STORE8;
|
|
|
|
|
STOREF8;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#define MAX(_a_,_m_) ( _a_ > _m_ ? _m_ : _a_)
|
|
|
|
|
@ -319,7 +285,7 @@ void debayer_grbg8 (uint8_t * src, int src_w, int src_h, uint8_t * dst, float *d
|
|
|
|
|
#define PRGGB10P_DL ((uint16_t)(*(psrc-2-src_w*2*10/8)))
|
|
|
|
|
#define PRGGB10P_DR ((uint16_t)(*(psrc+2+src_w*2*10/8)))
|
|
|
|
|
void debayer_rggb10packet (uint8_t *src, int src_w, int src_h,
|
|
|
|
|
uint8_t *dst, float *dstf, int dst_w, int dst_h) {
|
|
|
|
|
uint8_t *dst, int dst_w, int dst_h) {
|
|
|
|
|
|
|
|
|
|
debug ("not yep implemented");
|
|
|
|
|
debug ("src size:%dx%d dst size:%dx%d", src_w, src_h, dst_w, dst_h);
|
|
|
|
|
@ -355,7 +321,7 @@ inline int swap16(uint16_t i) {
|
|
|
|
|
#define PRGGB10_UR (unsigned int)(*(psrc+1-src_w))
|
|
|
|
|
#define PRGGB10_DL (unsigned int)(*(psrc-1+src_w))
|
|
|
|
|
#define PRGGB10_DR (unsigned int)(*(psrc+1+src_w))
|
|
|
|
|
void debayer_gbrg10 (uint8_t * src, int src_w, int src_h, uint8_t * dst, float * dstf, int dst_w, int dst_h) {
|
|
|
|
|
void debayer_gbrg10 (uint8_t * src, int src_w, int src_h, uint8_t * dst, int dst_w, int dst_h) {
|
|
|
|
|
// GG BB GG BB
|
|
|
|
|
// RR GG RR GG
|
|
|
|
|
// GG BB GG BB
|
|
|
|
|
@ -371,7 +337,6 @@ void debayer_gbrg10 (uint8_t * src, int src_w, int src_h, uint8_t * dst, float
|
|
|
|
|
int max_b = 0;
|
|
|
|
|
|
|
|
|
|
pdst = dst;
|
|
|
|
|
pdstf = dstf;
|
|
|
|
|
for (ys = 0, yd = 0, psrc = (uint16_t*)src; ys < dst_h; ys++, yd++) {
|
|
|
|
|
r = 0;
|
|
|
|
|
g = 0;
|
|
|
|
|
@ -413,19 +378,12 @@ void debayer_gbrg10 (uint8_t * src, int src_w, int src_h, uint8_t * dst, float
|
|
|
|
|
pdst += 3;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// copy pixel to destination float
|
|
|
|
|
if (pdstf) {
|
|
|
|
|
pdstf[0] = ((float)r / 1023.0);
|
|
|
|
|
pdstf[1] = ((float)g / 1023.0);
|
|
|
|
|
pdstf[2] = ((float)b / 1023.0);
|
|
|
|
|
pdstf += 3;
|
|
|
|
|
}
|
|
|
|
|
psrc += 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
void debayer_rggb10 (uint8_t *src, int src_w, int src_h, uint8_t *dst, float *dstf, int dst_w, int dst_h) {
|
|
|
|
|
void debayer_rggb10 (uint8_t *src, int src_w, int src_h, uint8_t *dst, int dst_w, int dst_h) {
|
|
|
|
|
// RR GG RR GG
|
|
|
|
|
// GG BB GG BB
|
|
|
|
|
// RR GG RR GG
|
|
|
|
|
@ -441,7 +399,6 @@ void debayer_rggb10 (uint8_t *src, int src_w, int src_h, uint8_t *dst, float *ds
|
|
|
|
|
int max_b = 0;
|
|
|
|
|
|
|
|
|
|
pdst = dst;
|
|
|
|
|
pdstf = dstf;
|
|
|
|
|
for (ys = 0, yd = 0, psrc = (uint16_t*)src; ys < dst_h; ys++, yd++) {
|
|
|
|
|
r = 0;
|
|
|
|
|
g = 0;
|
|
|
|
|
@ -482,13 +439,6 @@ void debayer_rggb10 (uint8_t *src, int src_w, int src_h, uint8_t *dst, float *ds
|
|
|
|
|
pdst += 3;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// copy pixel to destination float
|
|
|
|
|
if (pdstf) {
|
|
|
|
|
pdstf[0] = ((float)r / 1023.0);
|
|
|
|
|
pdstf[1] = ((float)g / 1023.0);
|
|
|
|
|
pdstf[2] = ((float)b / 1023.0);
|
|
|
|
|
pdstf += 3;
|
|
|
|
|
}
|
|
|
|
|
psrc += 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|