|
|
|
@ -40,8 +40,16 @@ int VideoFrameRaw::CopyFrom(int spixfmt, int sw, int sh, int ssize, unsigned cha
|
|
|
|
|
w = sw;
|
|
|
|
|
h = sh;
|
|
|
|
|
pixfmt = spixfmt;
|
|
|
|
|
memcpy (data, sdata, size);
|
|
|
|
|
memcpy (data, sdata, ssize);
|
|
|
|
|
|
|
|
|
|
/* int i, x, y, d;
|
|
|
|
|
for (y = 0; y < w; y++) for (x = 0; x < w; x++) {
|
|
|
|
|
for (i = 0, d = 0; i < 4; i++) {
|
|
|
|
|
d += data[4* (y*w+x)];
|
|
|
|
|
}
|
|
|
|
|
if (d > 1000) printf ("%d,%d -> %d\n", x, y, d);
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -83,9 +91,45 @@ int VideoFrameRaw::ReAlloc(int newsize) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int VideoFrameRaw::RectCopyFrom(VideoFrameRaw *src, int rectx, int recty, int rectw, int recth) {
|
|
|
|
|
return PixCopy (src->data, src->pixfmt, src->w, src->h,
|
|
|
|
|
int res = 0;
|
|
|
|
|
pixfmt = src->pixfmt;
|
|
|
|
|
|
|
|
|
|
res = PixCopy (src->data, src->pixfmt, src->w, src->h,
|
|
|
|
|
&data, &size, &w, &h,
|
|
|
|
|
rectx, recty, rectw, recth);
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
for (int i = 0; i < size; i++) if (data[i] > 0) {
|
|
|
|
|
printf ("%s:%d found data in destination.\n", __FILE__, __LINE__);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < src->size; i++) if (src->data[i] > 0) {
|
|
|
|
|
printf ("%s:%d found data in source.\n", __FILE__, __LINE__);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int bytesperpixel = 3;
|
|
|
|
|
int dsize = 0;
|
|
|
|
|
|
|
|
|
|
switch (src->pixfmt) {
|
|
|
|
|
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 res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -190,25 +234,32 @@ void VideoFrame::CopyTo(FloatImage *dest) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void VideoFrame::ToPixbuf(GdkPixbuf* dest) {
|
|
|
|
|
int destw, desth;
|
|
|
|
|
void VideoFrame::ToPixbuf(GdkPixbuf** dest) {
|
|
|
|
|
int destw, desth, bytelen;
|
|
|
|
|
unsigned char *destpixel;
|
|
|
|
|
|
|
|
|
|
if (dest == NULL) return;
|
|
|
|
|
|
|
|
|
|
desth = gdk_pixbuf_get_height(dest);
|
|
|
|
|
destw = gdk_pixbuf_get_width(dest);
|
|
|
|
|
destpixel = gdk_pixbuf_get_pixels(dest);
|
|
|
|
|
desth = gdk_pixbuf_get_height(*dest);
|
|
|
|
|
destw = gdk_pixbuf_get_width(*dest);
|
|
|
|
|
|
|
|
|
|
// check if the memory allocation way ok.
|
|
|
|
|
if (destw != w || desth != h) {
|
|
|
|
|
g_object_unref (*dest);
|
|
|
|
|
*dest = gdk_pixbuf_new (GDK_COLORSPACE_RGB, false, 8, w, h);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (destw * desth < h * w) {
|
|
|
|
|
destw = w;
|
|
|
|
|
desth = h;
|
|
|
|
|
// copy data
|
|
|
|
|
destpixel = gdk_pixbuf_get_pixels(*dest);
|
|
|
|
|
bytelen = gdk_pixbuf_get_byte_length(*dest);
|
|
|
|
|
if (bytelen < h * w * 3) {
|
|
|
|
|
printf ("******* Error: %s:%d bytelen (set to:%d) is not %d\n", __FILE__, __LINE__, bytelen, (h * w * 3));
|
|
|
|
|
printf ("******* please inform the maintainer of this project.\n");
|
|
|
|
|
printf ("******* this should not have happened at all.\n");
|
|
|
|
|
exit (-1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
memcpy (destpixel, data, 3*destw*desth);
|
|
|
|
|
memcpy (destpixel, data, 3*w*h);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|