|
|
|
@ -22,8 +22,10 @@ std::string toBits(unsigned int i, int maxbits);
|
|
|
|
#define DNRI (*(src+src_w+1))
|
|
|
|
#define DNRI (*(src+src_w+1))
|
|
|
|
|
|
|
|
|
|
|
|
#define BITCONV(d) ((d>>8) & 0xff)
|
|
|
|
#define BITCONV(d) ((d>>8) & 0xff)
|
|
|
|
#define STORE *(dst++) = BITCONV(r); *(dst++) = BITCONV(g); *(dst++) = BITCONV(b); src++;
|
|
|
|
#define STORE if (dst) { *(dst++) = BITCONV(r); *(dst++) = BITCONV(g); *(dst++) = BITCONV(b); src++; }
|
|
|
|
#define STORE8 *(dst++) = (r & 0xff); *(dst++) = (g & 0xff); *(dst++) = (b & 0xff); 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); }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
@ -31,7 +33,7 @@ std::string toBits(unsigned int i, int maxbits);
|
|
|
|
RGB image by bilinear interpolation.
|
|
|
|
RGB image by bilinear interpolation.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
void debayer_grbg16 (uint16_t * src, int src_w, int src_h,
|
|
|
|
void debayer_grbg16 (uint16_t * src, int src_w, int src_h,
|
|
|
|
uint8_t * dst, int dst_w, int dst_h) {
|
|
|
|
uint8_t * dst, float * dstf, int dst_w, int dst_h) {
|
|
|
|
|
|
|
|
|
|
|
|
// GG RR GG RR
|
|
|
|
// GG RR GG RR
|
|
|
|
// BB GG BB GG
|
|
|
|
// BB GG BB GG
|
|
|
|
@ -45,6 +47,7 @@ void debayer_grbg16 (uint16_t * src, int src_w, int src_h,
|
|
|
|
g = CE;
|
|
|
|
g = CE;
|
|
|
|
b = DN;
|
|
|
|
b = DN;
|
|
|
|
STORE;
|
|
|
|
STORE;
|
|
|
|
|
|
|
|
STOREF16;
|
|
|
|
|
|
|
|
|
|
|
|
// upper first line, starts with RR GG RR ...
|
|
|
|
// upper first line, starts with RR GG RR ...
|
|
|
|
for (xs = 1; xs < src_w - 1; xs+=2) {
|
|
|
|
for (xs = 1; xs < src_w - 1; xs+=2) {
|
|
|
|
@ -53,11 +56,13 @@ void debayer_grbg16 (uint16_t * src, int src_w, int src_h,
|
|
|
|
g = (LE + RI + DN) / 3;
|
|
|
|
g = (LE + RI + DN) / 3;
|
|
|
|
b = (DNLE + DNRI) / 2;
|
|
|
|
b = (DNLE + DNRI) / 2;
|
|
|
|
STORE;
|
|
|
|
STORE;
|
|
|
|
|
|
|
|
STOREF16;
|
|
|
|
// green pixel
|
|
|
|
// green pixel
|
|
|
|
r = (LE + RI) / 2;
|
|
|
|
r = (LE + RI) / 2;
|
|
|
|
g = CE;
|
|
|
|
g = CE;
|
|
|
|
b = DN;
|
|
|
|
b = DN;
|
|
|
|
STORE;
|
|
|
|
STORE;
|
|
|
|
|
|
|
|
STOREF16;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// upper right pixel (red)
|
|
|
|
// upper right pixel (red)
|
|
|
|
@ -65,6 +70,7 @@ void debayer_grbg16 (uint16_t * src, int src_w, int src_h,
|
|
|
|
g = (DN + LE) / 2;
|
|
|
|
g = (DN + LE) / 2;
|
|
|
|
b = DNLE;
|
|
|
|
b = DNLE;
|
|
|
|
STORE;
|
|
|
|
STORE;
|
|
|
|
|
|
|
|
STOREF16;
|
|
|
|
|
|
|
|
|
|
|
|
// go through the "body" of the image
|
|
|
|
// go through the "body" of the image
|
|
|
|
for (ys = 1; ys < src_h - 1; ys+=2) {
|
|
|
|
for (ys = 1; ys < src_h - 1; ys+=2) {
|
|
|
|
@ -76,23 +82,27 @@ void debayer_grbg16 (uint16_t * src, int src_w, int src_h,
|
|
|
|
g = (UP + DN + RI) / 3;
|
|
|
|
g = (UP + DN + RI) / 3;
|
|
|
|
b = CE;
|
|
|
|
b = CE;
|
|
|
|
STORE;
|
|
|
|
STORE;
|
|
|
|
|
|
|
|
STOREF16;
|
|
|
|
for (xs = 1; xs < src_w - 1; xs+=2) {
|
|
|
|
for (xs = 1; xs < src_w - 1; xs+=2) {
|
|
|
|
// green pixel
|
|
|
|
// green pixel
|
|
|
|
r = (UP + DN) / 2;
|
|
|
|
r = (UP + DN) / 2;
|
|
|
|
g = CE;
|
|
|
|
g = CE;
|
|
|
|
b = (LE + RI) / 2;
|
|
|
|
b = (LE + RI) / 2;
|
|
|
|
STORE;
|
|
|
|
STORE;
|
|
|
|
|
|
|
|
STOREF16;
|
|
|
|
// blue pixel
|
|
|
|
// blue pixel
|
|
|
|
r = (UPLE + UPRI + DNLE + DNRI) / 4;
|
|
|
|
r = (UPLE + UPRI + DNLE + DNRI) / 4;
|
|
|
|
g = (LE + RI + UP + DN) / 4;
|
|
|
|
g = (LE + RI + UP + DN) / 4;
|
|
|
|
b = CE;
|
|
|
|
b = CE;
|
|
|
|
STORE;
|
|
|
|
STORE;
|
|
|
|
|
|
|
|
STOREF16;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// last pixel in line (green)
|
|
|
|
// last pixel in line (green)
|
|
|
|
r = (UP + DN) / 2;
|
|
|
|
r = (UP + DN) / 2;
|
|
|
|
g = CE;
|
|
|
|
g = CE;
|
|
|
|
b = LE;
|
|
|
|
b = LE;
|
|
|
|
STORE;
|
|
|
|
STORE;
|
|
|
|
|
|
|
|
STOREF16;
|
|
|
|
|
|
|
|
|
|
|
|
// every second line with GG RR GG RR ... (start at 3rd line)
|
|
|
|
// every second line with GG RR GG RR ... (start at 3rd line)
|
|
|
|
|
|
|
|
|
|
|
|
@ -101,23 +111,27 @@ void debayer_grbg16 (uint16_t * src, int src_w, int src_h,
|
|
|
|
g = CE;
|
|
|
|
g = CE;
|
|
|
|
b = (UP + DN) / 2;
|
|
|
|
b = (UP + DN) / 2;
|
|
|
|
STORE;
|
|
|
|
STORE;
|
|
|
|
|
|
|
|
STOREF16;
|
|
|
|
for (xs = 1; xs < src_w - 1; xs+=2) {
|
|
|
|
for (xs = 1; xs < src_w - 1; xs+=2) {
|
|
|
|
// red pixel
|
|
|
|
// red pixel
|
|
|
|
r = CE;
|
|
|
|
r = CE;
|
|
|
|
g = (LE + RI + UP + DN) / 4;
|
|
|
|
g = (LE + RI + UP + DN) / 4;
|
|
|
|
b = (UPLE + UPRI + DNLE + DNRI) / 4;
|
|
|
|
b = (UPLE + UPRI + DNLE + DNRI) / 4;
|
|
|
|
STORE;
|
|
|
|
STORE;
|
|
|
|
|
|
|
|
STOREF16;
|
|
|
|
// green pixel
|
|
|
|
// green pixel
|
|
|
|
r = (LE + RI) / 2;
|
|
|
|
r = (LE + RI) / 2;
|
|
|
|
g = CE;
|
|
|
|
g = CE;
|
|
|
|
b = (UP + DN) / 2;
|
|
|
|
b = (UP + DN) / 2;
|
|
|
|
STORE;
|
|
|
|
STORE;
|
|
|
|
|
|
|
|
STOREF16;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// last pixel in line (red)
|
|
|
|
// last pixel in line (red)
|
|
|
|
r = CE;
|
|
|
|
r = CE;
|
|
|
|
g = (UP + DN + LE) / 3;
|
|
|
|
g = (UP + DN + LE) / 3;
|
|
|
|
b = (UPLE + DNLE) / 2;
|
|
|
|
b = (UPLE + DNLE) / 2;
|
|
|
|
STORE;
|
|
|
|
STORE;
|
|
|
|
|
|
|
|
STOREF16;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// bottom left pixel
|
|
|
|
// bottom left pixel
|
|
|
|
@ -125,6 +139,7 @@ void debayer_grbg16 (uint16_t * src, int src_w, int src_h,
|
|
|
|
g = (UP + RI) / 2;
|
|
|
|
g = (UP + RI) / 2;
|
|
|
|
b = CE;
|
|
|
|
b = CE;
|
|
|
|
STORE;
|
|
|
|
STORE;
|
|
|
|
|
|
|
|
STOREF16;
|
|
|
|
|
|
|
|
|
|
|
|
// last line starting with GG BB GG ...
|
|
|
|
// last line starting with GG BB GG ...
|
|
|
|
for (xs = 1; xs < src_w - 1; xs+=2) {
|
|
|
|
for (xs = 1; xs < src_w - 1; xs+=2) {
|
|
|
|
@ -133,11 +148,13 @@ void debayer_grbg16 (uint16_t * src, int src_w, int src_h,
|
|
|
|
g = CE;
|
|
|
|
g = CE;
|
|
|
|
b = (LE + RI) / 2;
|
|
|
|
b = (LE + RI) / 2;
|
|
|
|
STORE;
|
|
|
|
STORE;
|
|
|
|
|
|
|
|
STOREF16;
|
|
|
|
// blue pixel
|
|
|
|
// blue pixel
|
|
|
|
r = (UPLE + UPRI) / 2;
|
|
|
|
r = (UPLE + UPRI) / 2;
|
|
|
|
g = (LE + UP + RI) / 2;
|
|
|
|
g = (LE + UP + RI) / 2;
|
|
|
|
b = CE;
|
|
|
|
b = CE;
|
|
|
|
STORE;
|
|
|
|
STORE;
|
|
|
|
|
|
|
|
STOREF16;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// bottom right pixel (green)
|
|
|
|
// bottom right pixel (green)
|
|
|
|
@ -145,21 +162,22 @@ void debayer_grbg16 (uint16_t * src, int src_w, int src_h,
|
|
|
|
g = CE;
|
|
|
|
g = CE;
|
|
|
|
b = LE;
|
|
|
|
b = LE;
|
|
|
|
STORE;
|
|
|
|
STORE;
|
|
|
|
|
|
|
|
STOREF16;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
The function converts a 8bit GRBG 2x2 CFA coded image into an 8bit
|
|
|
|
The function converts a 8bit GRBG 2x2 CFA coded image into an 8bit
|
|
|
|
RGB image by bilinear interpolation.
|
|
|
|
RGB image by bilinear interpolation.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
void debayer_gbrg8 (uint8_t * src, int src_w, int src_h, uint8_t * dst, int dst_w, int dst_h) {
|
|
|
|
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, dst_w, 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) {
|
|
|
|
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, dst_w, dst_h);
|
|
|
|
debayer_grbg8 (src, src_w, src_h, dst, dstf, dst_w, dst_h);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
void debayer_grbg8 (uint8_t * src, int src_w, int src_h, uint8_t * dst, int dst_w, int 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) {
|
|
|
|
|
|
|
|
|
|
|
|
// GG RR GG RR
|
|
|
|
// GG RR GG RR
|
|
|
|
// BB GG BB GG
|
|
|
|
// BB GG BB GG
|
|
|
|
@ -173,6 +191,7 @@ void debayer_grbg8 (uint8_t * src, int src_w, int src_h, uint8_t * dst, int dst_
|
|
|
|
g = CE;
|
|
|
|
g = CE;
|
|
|
|
b = DN;
|
|
|
|
b = DN;
|
|
|
|
STORE8;
|
|
|
|
STORE8;
|
|
|
|
|
|
|
|
STOREF8;
|
|
|
|
|
|
|
|
|
|
|
|
// upper first line, starts with RR GG RR ...
|
|
|
|
// upper first line, starts with RR GG RR ...
|
|
|
|
for (xs = 1; xs < src_w - 1; xs+=2) {
|
|
|
|
for (xs = 1; xs < src_w - 1; xs+=2) {
|
|
|
|
@ -181,11 +200,13 @@ void debayer_grbg8 (uint8_t * src, int src_w, int src_h, uint8_t * dst, int dst_
|
|
|
|
g = (LE + RI + DN) / 3;
|
|
|
|
g = (LE + RI + DN) / 3;
|
|
|
|
b = (DNLE + DNRI) / 2;
|
|
|
|
b = (DNLE + DNRI) / 2;
|
|
|
|
STORE8;
|
|
|
|
STORE8;
|
|
|
|
|
|
|
|
STOREF8;
|
|
|
|
// green pixel
|
|
|
|
// green pixel
|
|
|
|
r = (LE + RI) / 2;
|
|
|
|
r = (LE + RI) / 2;
|
|
|
|
g = CE;
|
|
|
|
g = CE;
|
|
|
|
b = DN;
|
|
|
|
b = DN;
|
|
|
|
STORE8;
|
|
|
|
STORE8;
|
|
|
|
|
|
|
|
STOREF8;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// upper right pixel (red)
|
|
|
|
// upper right pixel (red)
|
|
|
|
@ -193,6 +214,7 @@ void debayer_grbg8 (uint8_t * src, int src_w, int src_h, uint8_t * dst, int dst_
|
|
|
|
g = (DN + LE) / 2;
|
|
|
|
g = (DN + LE) / 2;
|
|
|
|
b = DNLE;
|
|
|
|
b = DNLE;
|
|
|
|
STORE8;
|
|
|
|
STORE8;
|
|
|
|
|
|
|
|
STOREF8;
|
|
|
|
|
|
|
|
|
|
|
|
// go through the "body" of the image
|
|
|
|
// go through the "body" of the image
|
|
|
|
for (ys = 1; ys < src_h - 1; ys+=2) {
|
|
|
|
for (ys = 1; ys < src_h - 1; ys+=2) {
|
|
|
|
@ -204,23 +226,27 @@ void debayer_grbg8 (uint8_t * src, int src_w, int src_h, uint8_t * dst, int dst_
|
|
|
|
g = (UP + DN + RI) / 3;
|
|
|
|
g = (UP + DN + RI) / 3;
|
|
|
|
b = CE;
|
|
|
|
b = CE;
|
|
|
|
STORE8;
|
|
|
|
STORE8;
|
|
|
|
|
|
|
|
STOREF8;
|
|
|
|
for (xs = 1; xs < src_w - 1; xs+=2) {
|
|
|
|
for (xs = 1; xs < src_w - 1; xs+=2) {
|
|
|
|
// green pixel
|
|
|
|
// green pixel
|
|
|
|
r = (UP + DN) / 2;
|
|
|
|
r = (UP + DN) / 2;
|
|
|
|
g = CE;
|
|
|
|
g = CE;
|
|
|
|
b = (LE + RI) / 2;
|
|
|
|
b = (LE + RI) / 2;
|
|
|
|
STORE8;
|
|
|
|
STORE8;
|
|
|
|
|
|
|
|
STOREF8;
|
|
|
|
// blue pixel
|
|
|
|
// blue pixel
|
|
|
|
r = (UPLE + UPRI + DNLE + DNRI) / 4;
|
|
|
|
r = (UPLE + UPRI + DNLE + DNRI) / 4;
|
|
|
|
g = (LE + RI + UP + DN) / 4;
|
|
|
|
g = (LE + RI + UP + DN) / 4;
|
|
|
|
b = CE;
|
|
|
|
b = CE;
|
|
|
|
STORE8;
|
|
|
|
STORE8;
|
|
|
|
|
|
|
|
STOREF8;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// last pixel in line (green)
|
|
|
|
// last pixel in line (green)
|
|
|
|
r = (UP + DN) / 2;
|
|
|
|
r = (UP + DN) / 2;
|
|
|
|
g = CE;
|
|
|
|
g = CE;
|
|
|
|
b = LE;
|
|
|
|
b = LE;
|
|
|
|
STORE8;
|
|
|
|
STORE8;
|
|
|
|
|
|
|
|
STOREF8;
|
|
|
|
|
|
|
|
|
|
|
|
// every second line with GG RR GG RR ... (start at 3rd line)
|
|
|
|
// every second line with GG RR GG RR ... (start at 3rd line)
|
|
|
|
|
|
|
|
|
|
|
|
@ -229,23 +255,27 @@ void debayer_grbg8 (uint8_t * src, int src_w, int src_h, uint8_t * dst, int dst_
|
|
|
|
g = CE;
|
|
|
|
g = CE;
|
|
|
|
b = (UP + DN) / 2;
|
|
|
|
b = (UP + DN) / 2;
|
|
|
|
STORE8;
|
|
|
|
STORE8;
|
|
|
|
|
|
|
|
STOREF8;
|
|
|
|
for (xs = 1; xs < src_w - 1; xs+=2) {
|
|
|
|
for (xs = 1; xs < src_w - 1; xs+=2) {
|
|
|
|
// red pixel
|
|
|
|
// red pixel
|
|
|
|
r = CE;
|
|
|
|
r = CE;
|
|
|
|
g = (LE + RI + UP + DN) / 4;
|
|
|
|
g = (LE + RI + UP + DN) / 4;
|
|
|
|
b = (UPLE + UPRI + DNLE + DNRI) / 4;
|
|
|
|
b = (UPLE + UPRI + DNLE + DNRI) / 4;
|
|
|
|
STORE8;
|
|
|
|
STORE8;
|
|
|
|
|
|
|
|
STOREF8;
|
|
|
|
// green pixel
|
|
|
|
// green pixel
|
|
|
|
r = (LE + RI) / 2;
|
|
|
|
r = (LE + RI) / 2;
|
|
|
|
g = CE;
|
|
|
|
g = CE;
|
|
|
|
b = (UP + DN) / 2;
|
|
|
|
b = (UP + DN) / 2;
|
|
|
|
STORE8;
|
|
|
|
STORE8;
|
|
|
|
|
|
|
|
STOREF8;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// last pixel in line (red)
|
|
|
|
// last pixel in line (red)
|
|
|
|
r = CE;
|
|
|
|
r = CE;
|
|
|
|
g = (UP + DN + LE) / 3;
|
|
|
|
g = (UP + DN + LE) / 3;
|
|
|
|
b = (UPLE + DNLE) / 2;
|
|
|
|
b = (UPLE + DNLE) / 2;
|
|
|
|
STORE8;
|
|
|
|
STORE8;
|
|
|
|
|
|
|
|
STOREF8;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// bottom left pixel
|
|
|
|
// bottom left pixel
|
|
|
|
@ -253,6 +283,7 @@ void debayer_grbg8 (uint8_t * src, int src_w, int src_h, uint8_t * dst, int dst_
|
|
|
|
g = (UP + RI) / 2;
|
|
|
|
g = (UP + RI) / 2;
|
|
|
|
b = CE;
|
|
|
|
b = CE;
|
|
|
|
STORE8;
|
|
|
|
STORE8;
|
|
|
|
|
|
|
|
STOREF8;
|
|
|
|
|
|
|
|
|
|
|
|
// last line starting with GG BB GG ...
|
|
|
|
// last line starting with GG BB GG ...
|
|
|
|
for (xs = 1; xs < src_w - 1; xs+=2) {
|
|
|
|
for (xs = 1; xs < src_w - 1; xs+=2) {
|
|
|
|
@ -261,11 +292,13 @@ void debayer_grbg8 (uint8_t * src, int src_w, int src_h, uint8_t * dst, int dst_
|
|
|
|
g = CE;
|
|
|
|
g = CE;
|
|
|
|
b = (LE + RI) / 2;
|
|
|
|
b = (LE + RI) / 2;
|
|
|
|
STORE8;
|
|
|
|
STORE8;
|
|
|
|
|
|
|
|
STOREF8;
|
|
|
|
// blue pixel
|
|
|
|
// blue pixel
|
|
|
|
r = (UPLE + UPRI) / 2;
|
|
|
|
r = (UPLE + UPRI) / 2;
|
|
|
|
g = (LE + UP + RI) / 2;
|
|
|
|
g = (LE + UP + RI) / 2;
|
|
|
|
b = CE;
|
|
|
|
b = CE;
|
|
|
|
STORE8;
|
|
|
|
STORE8;
|
|
|
|
|
|
|
|
STOREF8;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// bottom right pixel (green)
|
|
|
|
// bottom right pixel (green)
|
|
|
|
@ -273,9 +306,10 @@ void debayer_grbg8 (uint8_t * src, int src_w, int src_h, uint8_t * dst, int dst_
|
|
|
|
g = CE;
|
|
|
|
g = CE;
|
|
|
|
b = LE;
|
|
|
|
b = LE;
|
|
|
|
STORE8;
|
|
|
|
STORE8;
|
|
|
|
|
|
|
|
STOREF8;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int MAX(int a, int m) { if (a > m) return m; else return a; };
|
|
|
|
#define MAX(_a_,_m_) ( _a_ > _m_ ? _m_ : _a_)
|
|
|
|
#define PRGGB10P_U ((uint16_t)(*(psrc-src_w*2*10/8)))
|
|
|
|
#define PRGGB10P_U ((uint16_t)(*(psrc-src_w*2*10/8)))
|
|
|
|
#define PRGGB10P_D ((uint16_t)(*(psrc+src_w*2*10/8)))
|
|
|
|
#define PRGGB10P_D ((uint16_t)(*(psrc+src_w*2*10/8)))
|
|
|
|
#define PRGGB10P_L ((uint16_t)(*(psrc-2)*10/8))
|
|
|
|
#define PRGGB10P_L ((uint16_t)(*(psrc-2)*10/8))
|
|
|
|
@ -284,75 +318,11 @@ int MAX(int a, int m) { if (a > m) return m; else return a; };
|
|
|
|
#define PRGGB10P_UR ((uint16_t)(*(psrc+2-src_w*2*10/8)))
|
|
|
|
#define PRGGB10P_UR ((uint16_t)(*(psrc+2-src_w*2*10/8)))
|
|
|
|
#define PRGGB10P_DL ((uint16_t)(*(psrc-2-src_w*2*10/8)))
|
|
|
|
#define PRGGB10P_DL ((uint16_t)(*(psrc-2-src_w*2*10/8)))
|
|
|
|
#define PRGGB10P_DR ((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,
|
|
|
|
void debayer_rggb10packet (uint8_t *src, int src_w, int src_h,
|
|
|
|
uint8_t * dst, int dst_w, int dst_h) {
|
|
|
|
uint8_t *dst, float *dstf, int dst_w, int dst_h) {
|
|
|
|
int s, d;
|
|
|
|
|
|
|
|
int xs, ys, xd, yd;
|
|
|
|
|
|
|
|
unsigned char r, g, b;
|
|
|
|
|
|
|
|
int max = dst_w * dst_h * 3;
|
|
|
|
|
|
|
|
unsigned char *pdst;
|
|
|
|
|
|
|
|
unsigned char *psrc;
|
|
|
|
|
|
|
|
int shift;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
printf ("%s:%d src size:%dx%d dst size:%dx%d\n", __FILE__, __LINE__, src_w, src_h, dst_w, dst_h);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// RR GG RR GG HH RR
|
|
|
|
|
|
|
|
// GG BB GG BB HH GG
|
|
|
|
|
|
|
|
// RR GG RR GG HH RR
|
|
|
|
|
|
|
|
// GG BB GG BB HH GG
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
debug ("not yep implemented");
|
|
|
|
for (ys = 0, yd = 0, psrc = src, pdst = dst; ys < dst_h; ys++, yd++) {
|
|
|
|
debug ("src size:%dx%d dst size:%dx%d", src_w, src_h, dst_w, dst_h);
|
|
|
|
r = 0;
|
|
|
|
|
|
|
|
g = 0;
|
|
|
|
|
|
|
|
b = 0;
|
|
|
|
|
|
|
|
for (xs = 0, xd = 0; xd < dst_w; xs++, xd++) {
|
|
|
|
|
|
|
|
r = 0; b = 0; g = 0;
|
|
|
|
|
|
|
|
if (ys > 0 && ys < src_h-1 && xs > 0 && xs < src_w-1) {
|
|
|
|
|
|
|
|
if (ys&1) {
|
|
|
|
|
|
|
|
if (xs&1) {
|
|
|
|
|
|
|
|
b = *psrc;
|
|
|
|
|
|
|
|
g = (PRGGB10P_L + PRGGB10P_R + PRGGB10P_U + PRGGB10P_D)/4;
|
|
|
|
|
|
|
|
r = (PRGGB10P_UL + PRGGB10P_DL + PRGGB10P_UR + PRGGB10P_UL)/4;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
b = (PRGGB10P_L + PRGGB10P_R)/2;
|
|
|
|
|
|
|
|
g = *psrc;
|
|
|
|
|
|
|
|
r = (PRGGB10P_U + PRGGB10P_D)/2;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
if (xs&1) {
|
|
|
|
|
|
|
|
b = (PRGGB10P_U + PRGGB10P_D)/2;
|
|
|
|
|
|
|
|
g = *psrc;
|
|
|
|
|
|
|
|
r = (PRGGB10P_L + PRGGB10P_R)/2;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
g = (PRGGB10P_L + PRGGB10P_R + PRGGB10P_U + PRGGB10P_D)/4;
|
|
|
|
|
|
|
|
b = (PRGGB10P_UL + PRGGB10P_DL + PRGGB10P_UR + PRGGB10P_UL)/4;
|
|
|
|
|
|
|
|
r = *psrc;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pdst - dst > max) {
|
|
|
|
|
|
|
|
printf ("debayer error. dpst out of bounds size:%dx%d pos:%dx%d \n", dst_w, dst_h, xd, yd);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((ys == 10 || ys == 11) && xs < 10) printf ("%dx%d - %d, %d, %d\n", xs, ys, r, g, b);
|
|
|
|
|
|
|
|
pdst[0] = MAX(r, 0xff);
|
|
|
|
|
|
|
|
pdst[1] = MAX(g, 0xff);
|
|
|
|
|
|
|
|
pdst[2] = MAX(b, 0xff);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (yd < 100 && xd < 300) {
|
|
|
|
|
|
|
|
pdst[0] = 0; if (xd < 100) pdst[0] = 255;
|
|
|
|
|
|
|
|
pdst[1] = 0; if (xd > 100 && xd < 200) pdst[1] = 255;
|
|
|
|
|
|
|
|
pdst[2] = 0; if (xd > 200 && xd < 300) pdst[2] = 255;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pdst += 3;
|
|
|
|
|
|
|
|
psrc++;
|
|
|
|
|
|
|
|
if (xs && (xs % 4 == 0)) psrc++;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -385,7 +355,7 @@ inline int swap16(uint16_t i) {
|
|
|
|
#define PRGGB10_UR (unsigned int)(*(psrc+1-src_w))
|
|
|
|
#define PRGGB10_UR (unsigned int)(*(psrc+1-src_w))
|
|
|
|
#define PRGGB10_DL (unsigned int)(*(psrc-1+src_w))
|
|
|
|
#define PRGGB10_DL (unsigned int)(*(psrc-1+src_w))
|
|
|
|
#define PRGGB10_DR (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, int dst_w, int dst_h) {
|
|
|
|
void debayer_gbrg10 (uint8_t * src, int src_w, int src_h, uint8_t * dst, float * dstf, int dst_w, int dst_h) {
|
|
|
|
// GG BB GG BB
|
|
|
|
// GG BB GG BB
|
|
|
|
// RR GG RR GG
|
|
|
|
// RR GG RR GG
|
|
|
|
// GG BB GG BB
|
|
|
|
// GG BB GG BB
|
|
|
|
@ -393,13 +363,16 @@ void debayer_gbrg10 (uint8_t * src, int src_w, int src_h, uint8_t * dst, int ds
|
|
|
|
int xs, ys, xd, yd;
|
|
|
|
int xs, ys, xd, yd;
|
|
|
|
uint32_t r, g, b, data;
|
|
|
|
uint32_t r, g, b, data;
|
|
|
|
int max = dst_w * dst_h * 3;
|
|
|
|
int max = dst_w * dst_h * 3;
|
|
|
|
uint8_t *pdst;
|
|
|
|
uint8_t *pdst = NULL;
|
|
|
|
uint16_t *psrc;
|
|
|
|
float *pdstf = NULL;
|
|
|
|
|
|
|
|
uint16_t *psrc = NULL;
|
|
|
|
int max_r = 0;
|
|
|
|
int max_r = 0;
|
|
|
|
int max_g = 0;
|
|
|
|
int max_g = 0;
|
|
|
|
int max_b = 0;
|
|
|
|
int max_b = 0;
|
|
|
|
|
|
|
|
|
|
|
|
for (ys = 0, yd = 0, psrc = (uint16_t*)src, pdst = dst; ys < dst_h; ys++, yd++) {
|
|
|
|
pdst = dst;
|
|
|
|
|
|
|
|
pdstf = dstf;
|
|
|
|
|
|
|
|
for (ys = 0, yd = 0, psrc = (uint16_t*)src; ys < dst_h; ys++, yd++) {
|
|
|
|
r = 0;
|
|
|
|
r = 0;
|
|
|
|
g = 0;
|
|
|
|
g = 0;
|
|
|
|
b = 0;
|
|
|
|
b = 0;
|
|
|
|
@ -431,21 +404,28 @@ void debayer_gbrg10 (uint8_t * src, int src_w, int src_h, uint8_t * dst, int ds
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pdst[0] = (r >> 2);
|
|
|
|
|
|
|
|
pdst[1] = (g >> 2);
|
|
|
|
// copy pixel to destination 24RGB
|
|
|
|
pdst[2] = (b >> 2);
|
|
|
|
if (pdst) {
|
|
|
|
// if (yd < 100 && xd < 300) {
|
|
|
|
pdst[0] = (r >> 2);
|
|
|
|
// pdst[0] = 0; if (xd < 100) pdst[0] = 255;
|
|
|
|
pdst[1] = (g >> 2);
|
|
|
|
// pdst[1] = 0; if (xd > 100 && xd < 200) pdst[1] = 255;
|
|
|
|
pdst[2] = (b >> 2);
|
|
|
|
// pdst[2] = 0; if (xd > 200 && xd < 300) pdst[2] = 255;
|
|
|
|
pdst += 3;
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
psrc += 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
void debayer_rggb10 (uint8_t *src, int src_w, int src_h, uint8_t * dst, int dst_w, int dst_h) {
|
|
|
|
void debayer_rggb10 (uint8_t *src, int src_w, int src_h, uint8_t *dst, float *dstf, int dst_w, int dst_h) {
|
|
|
|
// RR GG RR GG
|
|
|
|
// RR GG RR GG
|
|
|
|
// GG BB GG BB
|
|
|
|
// GG BB GG BB
|
|
|
|
// RR GG RR GG
|
|
|
|
// RR GG RR GG
|
|
|
|
@ -453,13 +433,16 @@ void debayer_rggb10 (uint8_t *src, int src_w, int src_h, uint8_t * dst, int dst_
|
|
|
|
int xs, ys, xd, yd;
|
|
|
|
int xs, ys, xd, yd;
|
|
|
|
uint32_t r, g, b, data;
|
|
|
|
uint32_t r, g, b, data;
|
|
|
|
int max = dst_w * dst_h * 3;
|
|
|
|
int max = dst_w * dst_h * 3;
|
|
|
|
uint8_t *pdst;
|
|
|
|
uint8_t *pdst = NULL;
|
|
|
|
|
|
|
|
float *pdstf = NULL;
|
|
|
|
uint16_t *psrc;
|
|
|
|
uint16_t *psrc;
|
|
|
|
int max_r = 0;
|
|
|
|
int max_r = 0;
|
|
|
|
int max_g = 0;
|
|
|
|
int max_g = 0;
|
|
|
|
int max_b = 0;
|
|
|
|
int max_b = 0;
|
|
|
|
|
|
|
|
|
|
|
|
for (ys = 0, yd = 0, psrc = (uint16_t*)src, pdst = dst; ys < dst_h; ys++, yd++) {
|
|
|
|
pdst = dst;
|
|
|
|
|
|
|
|
pdstf = dstf;
|
|
|
|
|
|
|
|
for (ys = 0, yd = 0, psrc = (uint16_t*)src; ys < dst_h; ys++, yd++) {
|
|
|
|
r = 0;
|
|
|
|
r = 0;
|
|
|
|
g = 0;
|
|
|
|
g = 0;
|
|
|
|
b = 0;
|
|
|
|
b = 0;
|
|
|
|
@ -491,15 +474,21 @@ void debayer_rggb10 (uint8_t *src, int src_w, int src_h, uint8_t * dst, int dst_
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pdst[0] = (r >> 2);
|
|
|
|
// copy pixel to destination 24RGB
|
|
|
|
pdst[1] = (g >> 2);
|
|
|
|
if (pdst) {
|
|
|
|
pdst[2] = (b >> 2);
|
|
|
|
pdst[0] = (r >> 2);
|
|
|
|
// if (yd < 100 && xd < 300) {
|
|
|
|
pdst[1] = (g >> 2);
|
|
|
|
// pdst[0] = 0; if (xd < 100) pdst[0] = 255;
|
|
|
|
pdst[2] = (b >> 2);
|
|
|
|
// pdst[1] = 0; if (xd > 100 && xd < 200) pdst[1] = 255;
|
|
|
|
pdst += 3;
|
|
|
|
// pdst[2] = 0; if (xd > 200 && xd < 300) pdst[2] = 255;
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
|
|
|
|
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;
|
|
|
|
psrc += 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|