unsigned char* macvdCamera::getFrame() { OSErr err; int isUpdated = 0; if (!vdgIsGrabbing(pVdg)) return NULL; if (err = vdgIdle( pVdg, &isUpdated)) { printf("could not grab frame\n"); return NULL; } if (isUpdated) { unsigned char *src = (unsigned char*)pDstData; unsigned char *dest = buffer; switch (colour) { case true: { uyvy2rgb(width,height,src,dest); break; } case false: { uyvy2gray(width,height,src,dest); break; } } return buffer; } return NULL; }
unsigned char* V4LinuxCamera::getFrame() { if (cameraID==-1) return NULL; int frame = 0; v4l_mmap.frame = frame; ioctl(cameraID, VIDIOCSYNC, &frame); if(ioctl(cameraID, VIDIOCMCAPTURE, &v4l_mmap)<0) { stopCamera(); closeCamera(); return NULL; } camBuffer = camBuffer + v4l_buf.offsets[frame]; if (camBuffer==NULL) return NULL; switch (colour) { case false: if (v4l_mmap.format==VIDEO_PALETTE_YUYV) yuyv2gray(this->width, this->height, camBuffer, buffer); else if (v4l_mmap.format==VIDEO_PALETTE_UYVY) uyvy2gray(this->width, this->height, camBuffer, buffer); else if (v4l_mmap.format==VIDEO_PALETTE_YUV420P) return camBuffer; return buffer; break; case true: //ccvt_420p_bgr24(width, height, camBuffer, buffer); break; } return buffer; }
unsigned char* V4Linux2Camera::getFrame() { if (dev_handle<0) return NULL; if (ioctl(dev_handle, VIDIOC_DQBUF, &v4l2_buf)<0) { running = false; return NULL; } unsigned char *raw_buffer = (unsigned char*)buffers[v4l2_buf.index].start; if (raw_buffer==NULL) return NULL; if(cfg->color) { if (cfg->frame) { if (pixelformat==V4L2_PIX_FMT_YUYV) crop_yuyv2rgb(cfg->cam_width,raw_buffer,frm_buffer); else if (pixelformat==V4L2_PIX_FMT_UYVY) crop_uyvy2rgb(cfg->cam_width,raw_buffer,frm_buffer); else if (pixelformat==V4L2_PIX_FMT_YUV420) { //TODO } else if (pixelformat==V4L2_PIX_FMT_YUV410) { //TODO } else if (pixelformat==V4L2_PIX_FMT_GREY) crop_gray2rgb(cfg->cam_width,raw_buffer, frm_buffer); else if ((pixelformat == V4L2_PIX_FMT_MJPEG) || (pixelformat == V4L2_PIX_FMT_JPEG)) { int jpegSubsamp; tjDecompressHeader2(_jpegDecompressor, raw_buffer, v4l2_buf.bytesused, &cfg->cam_width, &cfg->cam_height, &jpegSubsamp); tjDecompress2(_jpegDecompressor, raw_buffer, v4l2_buf.bytesused, cam_buffer, cfg->cam_width, 0, cfg->cam_height, TJPF_RGB, TJFLAG_FASTDCT); crop(cfg->cam_width, cfg->cam_height,cam_buffer,frm_buffer,3); } } else { if (pixelformat==V4L2_PIX_FMT_YUYV) yuyv2rgb(cfg->cam_width,cfg->cam_height,raw_buffer,cam_buffer); else if (pixelformat==V4L2_PIX_FMT_UYVY) uyvy2rgb(cfg->cam_width,cfg->cam_height,raw_buffer,cam_buffer); else if (pixelformat==V4L2_PIX_FMT_YUV420) { //TODO } else if (pixelformat==V4L2_PIX_FMT_YUV410) { //TODO } else if (pixelformat==V4L2_PIX_FMT_GREY) gray2rgb(cfg->cam_width,cfg->cam_height,raw_buffer,cam_buffer); else if ((pixelformat == V4L2_PIX_FMT_MJPEG) || (pixelformat == V4L2_PIX_FMT_JPEG)) { int jpegSubsamp; tjDecompressHeader2(_jpegDecompressor, raw_buffer, v4l2_buf.bytesused, &cfg->cam_width, &cfg->cam_height, &jpegSubsamp); tjDecompress2(_jpegDecompressor, raw_buffer, v4l2_buf.bytesused, cam_buffer, cfg->cam_width, 0, cfg->cam_height, TJPF_RGB, TJFLAG_FASTDCT); } } } else { if (cfg->frame) { if (pixelformat==V4L2_PIX_FMT_YUYV) crop_yuyv2gray(cfg->cam_width,raw_buffer,frm_buffer); else if (pixelformat==V4L2_PIX_FMT_UYVY) crop_uyvy2gray(cfg->cam_width,raw_buffer,frm_buffer); else if (pixelformat==V4L2_PIX_FMT_YUV420) crop(cfg->cam_width, cfg->cam_height,raw_buffer,frm_buffer,1); else if (pixelformat==V4L2_PIX_FMT_YUV410) crop(cfg->cam_width, cfg->cam_height,raw_buffer,frm_buffer,1); else if (pixelformat==V4L2_PIX_FMT_GREY) crop(cfg->cam_width, cfg->cam_height,raw_buffer,frm_buffer,1); else if ((pixelformat == V4L2_PIX_FMT_MJPEG) || (pixelformat == V4L2_PIX_FMT_JPEG)) { int jpegSubsamp; tjDecompressHeader2(_jpegDecompressor, raw_buffer, v4l2_buf.bytesused, &cfg->cam_width, &cfg->cam_height, &jpegSubsamp); tjDecompress2(_jpegDecompressor, raw_buffer, v4l2_buf.bytesused, cam_buffer, cfg->cam_width, 0, cfg->cam_height, TJPF_GRAY, TJFLAG_FASTDCT); crop(cfg->cam_width, cfg->cam_height,cam_buffer,frm_buffer,1); } } else { if (pixelformat==V4L2_PIX_FMT_YUYV) yuyv2gray(cfg->cam_width, cfg->cam_height, raw_buffer, cam_buffer); else if (pixelformat==V4L2_PIX_FMT_UYVY) uyvy2gray(cfg->cam_width, cfg->cam_height, raw_buffer, cam_buffer); else if (pixelformat==V4L2_PIX_FMT_YUV420) memcpy(cam_buffer,raw_buffer,cfg->cam_width*cfg->cam_height); else if (pixelformat==V4L2_PIX_FMT_YUV410) memcpy(cam_buffer,raw_buffer,cfg->cam_width*cfg->cam_height); //else if (pixelformat==V4L2_PIX_FMT_GREY) memcpy(cam_buffer,raw_buffer,cam_width*cam_height); else if ((pixelformat == V4L2_PIX_FMT_MJPEG) || (pixelformat == V4L2_PIX_FMT_JPEG)) { int jpegSubsamp; tjDecompressHeader2(_jpegDecompressor, raw_buffer, v4l2_buf.bytesused, &cfg->cam_width, &cfg->cam_height, &jpegSubsamp); tjDecompress2(_jpegDecompressor, raw_buffer, v4l2_buf.bytesused, cam_buffer, cfg->cam_width, 0, cfg->cam_height, TJPF_GRAY, TJFLAG_FASTDCT); } } } if (-1 == ioctl (dev_handle, VIDIOC_QBUF, &v4l2_buf)) { printf("cannot unqueue buffer: %s\n", strerror(errno)); return NULL; } if (cfg->frame) return frm_buffer; else if ((!cfg->color) && (pixelformat==V4L2_PIX_FMT_GREY)) return raw_buffer; else return cam_buffer; }