Video Data types

iimavlib provides several primitive types related to graphics processing, you can get them by including:

#include "iimavlib/video_types.h"

rgb_t

struct rgb_t {
    uint8_t r:8;
    uint8_t g:8;
    uint8_t b:8;
    rgb_t(uint8_t r=0, uint8_t g = 0, uint8_t b = 0);
};

Type representing a RGB pixel. It has overloaded operators for multiplication and division, so you can use things like this:

iimavlib::rgb_t red_pixel(255,10,10);
iimavlib::rgb_t light_red_pixel = red_pixel * 0.5;
// Now light_red_pixel is (127,5,5)

rectangle_t

struct rectangle_t {
    int x;
    int y;
    int width;
    int height;
    rectangle_t(int x, int y, int width = 0, int height = 0);
};

rectangle_t represents a rectangle with position and dimensions. There is a helper function intersection to calculate common area of two rectangles:

rectangle_t intersection(rectangle_t, const rectangle_t&);

video_buffer_t

A class representing simple video canvas.

It's data members look like this:

struct video_buffer_t {
    rectangle_t size;
    std::vector<rgb_t> data;
};

Basically it's a rectangle defining size and a vector of pixels. The complete signature is:

struct video_buffer_t {
    typedef std::vector<rgb_t> data_type;
    typedef data_type::iterator iterator;
    typedef data_type::const_iterator const_iterator;
    rectangle_t size;
    std::vector<rgb_t> data;
 
    video_buffer_t();
    video_buffer_t(rectangle_t size, rgb_t color = rgb_t());
    video_buffer_t(int width, int height, rgb_t color = rgb_t());
 
    void resize(int width, int height, rgb_t color= rgb_t());
 
    void resize(rectangle_t rect, rgb_t color = rgb_t());
 
    void clear(rgb_t color);
 
    rgb_t& operator()(int x, int y);
    rgb_t operator()(int x, int y) const;
 
    iterator begin();
    const_iterator begin() const;
    iterator end();
    const_iterator end() const;
};
Constructors

The class has 2 constructors, both defining size of the canvas and optionally a color (if not provided, it defaults to black).

resize

resize method has the same signatures as constructors. it resizes the canvas to specified size. The optional parameter color, is used to fill the newly allocated part of the buffer with a color, if the new size is larger than old one.

clear

clear fills the whole canvas with a single color.

operator()

video_buffer_t has an operator() for simplified access to underlying pixels. it takes x and y coordinates of the pixel:

// Creates a canvas 100x100 pixels, filled with default black color.
iimavlib::video_buffer_t canvas(100, 100);
 
// Sets a pixel on coordinates 20x50 to a red color.
canvas(20,50)=iimavlib::rgb_t(255,0,0);
 
// Draws a blue diagonal line
for (int i=0;i<100;++i) canvas(i,i) = iimavlib::rgb_t(0,0,255);
begin, end

The class also exposes begin/end methods of underlying vector, so it can be directly used as an input to STL algorithms. For example:

// Creates a canvas 100x100 pixels, filled with default black color.
iimavlib::video_buffer_t canvas(100, 100);
 
// Red color
iimavlib::rgb_t red_color(255,0,0)
 
// Fills the canvas with a red color
std::fill(canvas.begin(), canvas.end(), red_color);
// It's equivalent to calling canvas.clear(red_color);
 
// This also set every pixel to red color
for (auto& pixel: canvas) pixel = red_color;
 
// Increments green component of every pixel by 10.
std::for_each(canvas.begin(), canvas.end(),
    [](iimavlib::rgb_t& pixel){pixel.g += 10;});
 
support/iimavlib/video_types.txt · Last modified: 2014/03/12 23:17 by neneko
 
Except where otherwise noted, content on this wiki is licensed under the following license: GNU Free Documentation License 1.3
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki