|
|
@ -494,16 +494,94 @@ uint32_t convert_to_pixelformat(std::string s) {
|
|
|
|
* copy part of an raw image
|
|
|
|
* copy part of an raw image
|
|
|
|
* destination must be pointer in case we need to align the size of the destination image.
|
|
|
|
* destination must be pointer in case we need to align the size of the destination image.
|
|
|
|
* this function will also realloc needed memory if needed. (only if: givin size < needed size)
|
|
|
|
* this function will also realloc needed memory if needed. (only if: givin size < needed size)
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* crop image to event set of dimensions
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
int PixCopy(unsigned char *srcdata, uint32_t srcpixfmt, int srcw, int srch,
|
|
|
|
int PixCopy(unsigned char *srcdata, uint32_t srcpixfmt, int srcw, int srch,
|
|
|
|
unsigned char **dstdataptr, int *dstsize, int *dstw, int *dsth,
|
|
|
|
unsigned char **dstdataptr, int *dstsize, int *dstw, int *dsth,
|
|
|
|
int regionx, int regiony, int regionw, int regionh) {
|
|
|
|
int regionx, int regiony, int regionw, int regionh) {
|
|
|
|
|
|
|
|
|
|
|
|
if (srcpixfmt == 0 || srcpixfmt == V4L2_PIX_FMT_MJPEG) return 0;
|
|
|
|
if (srcpixfmt == 0 || srcpixfmt == V4L2_PIX_FMT_MJPEG) return 0;
|
|
|
|
if (srcdata == NULL) return 0;
|
|
|
|
if (srcdata == NULL || dstdataptr == NULL) return 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// crop size to an even number
|
|
|
|
|
|
|
|
(*dsth) = regionw & ~1;
|
|
|
|
|
|
|
|
(*dstw) = regionh & ~1;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int bytesperpixel = 3;
|
|
|
|
|
|
|
|
int dsize = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
switch (srcpixfmt) {
|
|
|
|
|
|
|
|
case (V4L2_PIX_FMT_SGRBG8):
|
|
|
|
|
|
|
|
bytesperpixel = 2;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case (V4L2_PIX_FMT_BGR32):
|
|
|
|
|
|
|
|
case (V4L2_PIX_FMT_RGB32):
|
|
|
|
|
|
|
|
case (V4L2_PIX_FMT_SGRBG16):
|
|
|
|
|
|
|
|
bytesperpixel = 4;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case (V4L2_PIX_FMT_BGR24):
|
|
|
|
|
|
|
|
case (V4L2_PIX_FMT_RGB24):
|
|
|
|
|
|
|
|
bytesperpixel = 3;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
debug_drawraw(srcdata, srcpixfmt, srcw, srch);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// calculate image size and allocate memory if needed
|
|
|
|
|
|
|
|
dsize = (*dsth) * (*dstw) * bytesperpixel;
|
|
|
|
|
|
|
|
if ((*dstsize) < dsize || (*dstdataptr) == NULL) {
|
|
|
|
|
|
|
|
*dstdataptr = (unsigned char*) realloc (*dstdataptr, dsize);
|
|
|
|
|
|
|
|
*dstsize = dsize;
|
|
|
|
|
|
|
|
printf ("%s:%d reallocate memory for destination raw image\n", __FILE__, __LINE__);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
unsigned char *dptr, *sptr;
|
|
|
|
|
|
|
|
int y, dy, x, dx, i, d;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (y = regiony & (~1), dy = 0; dy < *dsth && y < srch; y++, dy++) {
|
|
|
|
|
|
|
|
for (x = regionx & (~1), dx = 0; dx < *dstw && x < srcw; x++, dx++) {
|
|
|
|
|
|
|
|
dptr = (*dstdataptr) + bytesperpixel * ( dy * *dstw + dx);
|
|
|
|
|
|
|
|
sptr = (srcdata) + bytesperpixel * ( y * srcw + x);
|
|
|
|
|
|
|
|
for (d = 0, i = 0; i < bytesperpixel; i++) {
|
|
|
|
|
|
|
|
dptr[i] = sptr[i];
|
|
|
|
|
|
|
|
d += sptr[i];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// printf (" %-3d",d);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// printf ("\n");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// printf ("%s:%d\n", __FILE__, __LINE__);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* int dy, y = regiony & (~1);
|
|
|
|
|
|
|
|
int dx, x;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (dptr = *dstdataptr, dy = 0; dy < *dsth; dy++, y++) {
|
|
|
|
|
|
|
|
x = regionx & (~1);
|
|
|
|
|
|
|
|
sptr = (srcdata + bytesperpixel * (y * srcw + x));
|
|
|
|
|
|
|
|
// printf ("\n");
|
|
|
|
|
|
|
|
for (dx = 0; dx < (*dstw * bytesperpixel); dx++, dptr++, sptr++) {
|
|
|
|
|
|
|
|
*dptr = *sptr;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// printf ("%x[%x] ", *dptr, *sptr);
|
|
|
|
|
|
|
|
int x1, x2, y1, y2;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
y1 = (sptr - srcdata) / (bytesperpixel * srcw);
|
|
|
|
|
|
|
|
x1 = ((sptr - srcdata) % (bytesperpixel * srcw)) / bytesperpixel;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
y2 = (dptr - *dstdataptr) / (bytesperpixel * (*dstw));
|
|
|
|
|
|
|
|
x2 = ((dptr - *dstdataptr) % (bytesperpixel * (*dstw))) / bytesperpixel;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
printf ("copy [%d , %d] ---> [ %d , %d] (%d , %d) Value: %d -> %d\n", x1,y1, x2, y2, dx, dy, *sptr, *dptr);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|