reference

This documentation is automatically generated from the openFrameworks source code using doxygen and refers to the most recent release, version 0.12.0.

ofPixels.h File Reference
#include "ofUtils.h"
#include "ofLog.h"
#include "ofMath.h"
#include "ofConstants.h"
#include <limits>

Go to the source code of this file.

Classes

class  ofPixels_< PixelType >
 A class representing a collection of pixels. More...
 

Namespaces

namespace  std
 

Macros

#define OF_PIXELS_MONO   OF_PIXELS_GRAY
 
#define OF_PIXELS_R   OF_PIXELS_GRAY
 
#define OF_PIXELS_RG   OF_PIXELS_GRAY_ALPHA
 

Typedefs

typedef ofColor_< unsigned char > ofColor
 
typedef ofColor_< float > ofFloatColor
 
typedef ofColor_< unsigned short > ofShortColor
 
typedef ofPixels_< unsigned char > ofPixels
 
typedef ofPixels_< float > ofFloatPixels
 
typedef ofPixels_< unsigned short > ofShortPixels
 
typedef ofPixelsofPixelsRef
 
typedef ofFloatPixelsofFloatPixelsRef
 
typedef ofShortPixelsofShortPixelsRef
 

Enumerations

enum  ofInterpolationMethod { OF_INTERPOLATE_NEAREST_NEIGHBOR =1 , OF_INTERPOLATE_BILINEAR =2 , OF_INTERPOLATE_BICUBIC =3 }
 
enum  ofPixelFormat : short {
  OF_PIXELS_GRAY = 0 , OF_PIXELS_GRAY_ALPHA = 1 , OF_PIXELS_RGB =2 , OF_PIXELS_BGR =3 ,
  OF_PIXELS_RGBA =4 , OF_PIXELS_BGRA =5 , OF_PIXELS_RGB565 =6 , OF_PIXELS_NV12 =7 ,
  OF_PIXELS_NV21 =8 , OF_PIXELS_YV12 =9 , OF_PIXELS_I420 =10 , OF_PIXELS_YUY2 =11 ,
  OF_PIXELS_UYVY =12 , OF_PIXELS_Y , OF_PIXELS_U , OF_PIXELS_V ,
  OF_PIXELS_UV , OF_PIXELS_VU , OF_PIXELS_NUM_FORMATS , OF_PIXELS_UNKNOWN =-1 ,
  OF_PIXELS_NATIVE =-2
}
 Used to represent the available pixel formats. More...
 

Functions

template<typename T >
std::string ofToString (const T &v)
 Convert a value to a string.
 
template<>
std::string ofToString (const ofPixelFormat &pixelType)
 

Detailed Description

ofPixels is an object for working with blocks of pixels, those pixels can be copied from an image that you've loaded, something that you've drawn using ofGraphics, or a ofVideoGrabber instance.

You can create an image from pixels, using on ofPixels object like so:

ofLoadImage(p, "pathToImage.jpg");
bool ofLoadImage(ofPixels &pix, const of::filesystem::path &path, const ofImageLoadSettings &settings)
Definition ofImage.cpp:302

ofPixels represents pixels data on the CPU as opposed to an ofTexture which represents pixel data on the GPU. They can easily be made inter- operational though:

// do some stuff with tex
tex.readToPixels(pix); // now all the pixels from tex are in pix
A wrapper class for an OpenGL texture.
Definition ofTexture.h:253
void readToPixels(ofPixels &pixels) const
Read current texture data from the GPU into pixels.
Definition ofTexture.cpp:1219

You can access the pixels in an ofPixels object with the [] operator.

// put some stuff in the pixels
size_t i = 0;
while( i < pix.size()) {
char c = pix[i];
i++;
}
size_t size() const
Get the number of values that the ofPixels object contains, so an RGB data 400x400 would be 480,...
Definition ofPixels.cpp:997
#define c

You can think of the ofPixels as the CPU side representation of pixel data that can be sent to the GPU as an ofTexture object. To draw pixels, you need to put them into an ofTexture and to manipulate an ofTextures pixel data you need an ofPixels object.

Macro Definition Documentation

◆ OF_PIXELS_MONO

#define OF_PIXELS_MONO   OF_PIXELS_GRAY

◆ OF_PIXELS_R

#define OF_PIXELS_R   OF_PIXELS_GRAY

◆ OF_PIXELS_RG

#define OF_PIXELS_RG   OF_PIXELS_GRAY_ALPHA

Typedef Documentation

◆ ofColor

typedef ofColor_<unsigned char> ofColor

◆ ofFloatColor

typedef ofColor_<float> ofFloatColor

◆ ofFloatPixels

typedef ofPixels_<float> ofFloatPixels

◆ ofFloatPixelsRef

◆ ofPixels

typedef ofPixels_<unsigned char> ofPixels

◆ ofPixelsRef

◆ ofShortColor

typedef ofColor_<unsigned short> ofShortColor

◆ ofShortPixels

typedef ofPixels_<unsigned short> ofShortPixels

◆ ofShortPixelsRef

Enumeration Type Documentation

◆ ofInterpolationMethod

Enumerator
OF_INTERPOLATE_NEAREST_NEIGHBOR 
OF_INTERPOLATE_BILINEAR 
OF_INTERPOLATE_BICUBIC 

◆ ofPixelFormat

enum ofPixelFormat : short

Used to represent the available pixel formats.

See also
ofPixels
Enumerator
OF_PIXELS_GRAY 

A single-channel pixel, typically used for greyscale images.

This has 1 channel and a type-dependent number of bits per-pixel. 
OF_PIXELS_GRAY_ALPHA 

A single-channel pixel with an alpha channel.

This has 2 channels and a type-dependent number of bits per-pixel. 
OF_PIXELS_RGB 

An RGB pixel with no alpha channel.

This has 3 channels and a type-dependent number of bits per-pixel.

\sa http://www.fourcc.org/rgb.php#BI_RGB 
OF_PIXELS_BGR 

A pixel used for color data with a blue/green/red channel order.

This has 3 channels and a type-dependent number of bits per-pixel. 
OF_PIXELS_RGBA 

An RGBA pixel. This is typically used for color with transparency.

This has 4 channels and a type-dependent number of bits per-pixel.

\sa http://www.fourcc.org/rgb.php#RGBA 
OF_PIXELS_BGRA 

A pixel used for color/transparency with a blue/green/red/alpha channel order.

This has 4 channels and a type-dependent number of bits per-pixel. 
OF_PIXELS_RGB565 
OF_PIXELS_NV12 

A 12-bit YUV 4:2:0 pixel with an interleaved U/V plane.

YUV 4:2:0 image with a plane of 8-bit Y samples followed by an
interleaved U/V plane containing 8-bit 2x2 subsampled color difference
samples.

\sa http://www.fourcc.org/yuv.php#NV12 
OF_PIXELS_NV21 

A 12-bit YUV 4:2:0 pixel with an interleaved V/U plane.

YUV 4:2:0 image with a plane of 8-bit Y samples followed by an
interleaved V/U plane containing 8-bit 2x2 subsampled chroma samples.
The same as NV12 except the interleave order of U and V is reversed.

\sa http://www.fourcc.org/yuv.php#NV21 
OF_PIXELS_YV12 

A 12-bit YUV NxM Y plane followed by (N/2)x(M/2) V and U planes.

\sa http://www.fourcc.org/yuv.php#YV12 
OF_PIXELS_I420 

A 12-bit YUV format similar to OF_PIXELS_YV12, but with U & V reversed.

Note that IYUV and I420 appear to be identical.

\sa http://www.fourcc.org/yuv.php#IYUV 
OF_PIXELS_YUY2 

A 16-bit YUV 4:2:2 format.

\sa http://www.fourcc.org/yuv.php#YUY2 
OF_PIXELS_UYVY 

A 16-bit YUV 4:2:2 format.

\sa http://www.fourcc.org/yuv.php#UYVY 
OF_PIXELS_Y 

A single channel pixel, typically used for the luma component of YUV.

OF_PIXELS_U 

A single channel pixel, typically used (with V) for the chroma component of YUV.

OF_PIXELS_V 

A single channel pixel, typically used (with U) for the chroma component of YUV.

OF_PIXELS_UV 

A two channel pixel, with U first, representing both chroma components of YUV.

OF_PIXELS_VU 

A two channel pixel, with V first, representing both chroma components of YUV.

OF_PIXELS_NUM_FORMATS 

This is a placeholder to indicate the last valid enum.

OF_PIXELS_UNKNOWN 

This indicates an unknown pixel type.

OF_PIXELS_NATIVE 

This indicates an unknown, native pixel type.

Function Documentation

◆ ofToString() [1/2]

template<>
std::string ofToString ( const ofPixelFormat pixelType)

◆ ofToString() [2/2]

template<typename T >
std::string ofToString ( const T &  value)

Convert a value to a string.

Manipulation

ofToString does its best to convert any value to a string. If the data type implements a stream << operator, then it will be converted.

Example:

std::string str = "framerate is ";
str += ofToString(ofGetFrameRate()) + " fps";
// The string now contains something like "framerate is 60 fps".
float ofGetFrameRate()
Definition ofEvents.cpp:20
std::string ofToString(const T &)
Convert a value to a string.
Definition ofUtils.h:657
Template Parameters
TThe data type of the value to convert to a string.
Parameters
valueThe value to convert to a string.
Returns
A string representing the value or an empty string on failure.