14 #ifndef _CAM_V4L2_HELPERS_H_
15 #define _CAM_V4L2_HELPERS_H_
19 #include <base/samples/Frame.hpp>
30 for(
int v=0; v<256; ++v) {
31 lookup_v2r[v] = ( (v-128) * 37221 ) >> 15;
34 for(
int u=0; u<256; ++u) {
35 for(
int v=0; v<256; ++v) {
36 lookup_uv2g[u][v] = ( ((u-128) * 12975) + ((v-128) * 18949) ) >> 15;
40 for(
int u=0; u<256; ++u) {
41 lookup_u2b[u] = ((u-128) * 66883) >> 15;
53 if(frame.getFrameMode() == base::samples::frame::MODE_JPEG) {
54 std::vector<uint8_t>::iterator it = frame.image.begin();
55 std::vector<uint8_t>::iterator it_n = frame.image.begin() + 1;
56 for(; it_n != frame.image.end(); it++, it_n++) {
57 if(*it == 0xFF && *it_n == 0xFE) {
58 size_t old_length = *(it+2)<<8 | *(it_n+2);
61 frame.image.erase(it, it + (2 + old_length));
66 if(*it == 0xFF && *it_n == 0XDA) {
73 static bool storeImageToFile(std::vector<uint8_t>
const& buffer, std::string
const& file_name) {
74 LOG_DEBUG(
"storeImageToFile, buffer contains %d bytes, stores to %s",
75 buffer.size(), file_name.c_str());
78 LOG_WARN(
"Empty buffer passed, nothing will be stored");
83 file = fopen(file_name.c_str(),
"w");
85 LOG_ERROR(
"File %s could not be opened, no image will be stored", file_name.c_str());
88 unsigned int written = fwrite (&buffer[0], 1 , buffer.size(), file);
89 if(written != buffer.size()) {
90 LOG_ERROR(
"Only %d of %d bytes could be written", written, buffer.size());
107 uint8_t& r, uint8_t& g, uint8_t& b) {
111 int r2 = y2 + lookup_v2r[(int)v];
112 int g2 = y2 - lookup_uv2g[(int)u][(
int)v];
113 int b2 = y2 + lookup_u2b[(int)u];
130 size_t yuyv_data_length,
131 std::vector<uint8_t>& rgb_buffer) {
133 assert(yuyv_data_length%4 == 0);
135 int rgb_size = (yuyv_data_length / 2) * 3;
136 rgb_buffer.resize(rgb_size);
137 std::vector<uint8_t>::iterator it = rgb_buffer.begin();
140 uint8_t* y = yuyv_data;
146 for(
unsigned int i=0; i < yuyv_data_length/4 && it != rgb_buffer.end(); ++i, y+=4, u+=4, y2+=4, v+=4) {
169 int lookup_uv2g[256][256];
void convertYUYV2RGB(uint8_t *yuyv_data, size_t yuyv_data_length, std::vector< uint8_t > &rgb_buffer)
Definition: helpers.h:129
void convertYUYVPixel(uint8_t y, uint8_t u, uint8_t v, uint8_t &r, uint8_t &g, uint8_t &b)
Definition: helpers.h:106
static void removeJpegCommentBlock(base::samples::frame::Frame &frame)
Definition: helpers.h:51
static bool storeImageToFile(std::vector< uint8_t > const &buffer, std::string const &file_name)
Definition: helpers.h:73
Helpers()
Definition: helpers.h:29
uint8_t clip(int value)
Definition: helpers.h:98