- english
- /
- japanese
methods
- allocate()
- clear()
- crop()
- cropTo()
- getBitsPerChannel()
- getBitsPerPixel()
- getBytesPerChannel()
- getBytesPerPixel()
- getChannel()
- getColor()
- getHeight()
- getImageType()
- getNumChannels()
- getPixelIndex()
- getPixels()
- getWidth()
- isAllocated()
- mirror()
- mirrorTo()
- operator=()
- operator[]()
- pasteInto()
- resize()
- resizeTo()
- rotate90()
- rotate90To()
- set()
- setChannel()
- setColor()
- setFromAlignedPixels()
- setFromExternalPixels()
- setFromPixels()
- setImageType()
- setNumChannels()
- size()
- swap()
- swapRgb()
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:
ofPixels p;
ofLoadImage(p, "pathToImage.jpg");
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:
ofTexture tex;
// do some stuff with t
ofPixels pix;
tex.readToPixels(pix); // now all the pixels from tex are in pix
You can access the pixels in an ofPixels object with the [] operator.
ofPixels pix;
// put some stuff in the pixels
int i = 0;
while( i < pix.size()) {
char c = pix[i];
i++;
}
clear()
void ofPixels_::clear()
This clears all the data from the ofPixels objects. After calling this you'll need to allocate the ofPixels object again to use it.
crop(...)
void ofPixels_::crop(int x, int y, int width, int height)
This crops the pixels to a new width and height. As a word of caution this reallocates memory and can be a bit expensive if done a lot.
cropTo(...)
void ofPixels_::cropTo(ofPixels_< PixelType > &toPix, int x, int y, int _width, int _height)
This crops the pixels into the ofPixels reference passed in by toPix. at the x and y and with the new width and height. As a word of caution this reallocates memory and can be a bit expensive if done a lot.
getBitsPerChannel()
int ofPixels_::getBitsPerChannel()
This is how large each channel of a pixels is, ofPixels objects that store pixel data as unsigned char are smaller than ofPixels objects that store pixel data as floats.
This returns bit, not bytes, so you'll probably see ofPixels
getBitsPerPixel()
int ofPixels_::getBitsPerPixel()
If you have RGB pixel data, this will return 3, if you have RGBA, you'll have 4, if you have grayscale, this will return 1.
getBytesPerChannel()
int ofPixels_::getBytesPerChannel()
This is how large each channel of a pixels is, ofPixels objects that store pixel data as unsigned char are smaller than ofPixels objects that store pixel data as floats.
This returns bytes, not bits, so you'll probably see ofPixels
getChannel(...)
ofPixels_ ofPixels_::getChannel(int channel)
This returns a single channel, for instance, the Red pixel values, from the ofPixels object, this gives you a grayscale representation of that one channel.
ofPixels rpix = pix.getChannel(0);
ofPixels gpix = pix.getChannel(1);
ofPixels bpix = pix.getChannel(2);
getColor(...)
ofColor_ ofPixels_::getColor(int x, int y)
This method returns the ofColor that the pixels contains at an x, y pair:
ofColor c = pix.getColor(mouseX, mouseY);
getImageType()
ofImageType ofPixels_::getImageType()
Returns what image type the ofPixels object is.
getNumChannels()
int ofPixels_::getNumChannels()
This returns the number of channels that the ofPixels object contains. RGB is 3 channels, RGBA is 4, and grayscale is 1.
getPixelIndex(...)
int ofPixels_::getPixelIndex(int x, int y)
This method tells you want pixel index an x, y pair would be at in the index, for instance:
ofColor yellow = ofColor::yellow;
int ind = pix.getPixelIndex(mouseX, mouseY);
pix.setPixel(ind, yellow);
getPixels()
const PixelType * ofPixels_::getPixels()
This returns a raw pointer to the pixel data. Changing this will change the value of the pixels in the ofPixels object. One way to inspect the values returns in this pointer would be:
unsigned char* pixPtr = pix.getPixels();
while(pixPtr) {
// for RGB pixels there will be 3 values for each pixel
// for RGBA pixels there will be 4
++pixPtr;
}
isAllocated()
bool ofPixels_::isAllocated()
Returns whether memory has been allocated for an ofPixels object or not. Many operations like copying pixels, etc, automatically allocate the memory needed, but it's sometimes good to check.
mirror(...)
void ofPixels_::mirror(bool vertically, bool horizontal)
This reflects the pixels across the vertical and/or horizontal axis.
mirrorTo(...)
void ofPixels_::mirrorTo(ofPixels_< PixelType > &dst, bool vertically, bool horizontal)
operator[](...)
PixelType & ofPixels_::operator
Provides access to each channel of each pixel. If you have RGB pixel data, then you'll have 3 values for each pixel, if you have RGBA, you'll have 4.
pasteInto(...)
bool ofPixels_::pasteInto(ofPixels_< PixelType > &dst, int x, int y)
This pastes the ofPixels object into another ofPixels object at the specified index, copying data from the ofPixels that the method is being called on to the ofPixels object at &dst. If the data being copied doesn't fit into the dst then the image is cropped.
ofLoadImage(footballPixels, "two.jpg");
ofLoadImage(fujiPixels, "one.jpg");
fujiTex.loadData(footballPixels);
footballTex.loadData(fujiPixels);
footballPixels.pasteInto(fujiPixels, 150, 100); // now fujiPixels is altered
mixtureTex.loadData(fujiPixels);
Drawing the three textures here you can see the ball cropped into the mountain:
![]()
resize(...)
bool ofPixels_::resize(int dstWidth, int dstHeight, ofInterpolationMethod interpMethod=OF_INTERPOLATE_NEAREST_NEIGHBOR)
This resizes the ofPixels instance to the dstHeight and dstWidth. The options for the interpolation methods are as follows: OF_INTERPOLATE_NEAREST_NEIGHBOR =1 OF_INTERPOLATE_BILINEAR =2 OF_INTERPOLATE_BICUBIC =3
resizeTo(...)
bool ofPixels_::resizeTo(ofPixels_< PixelType > &dst, ofInterpolationMethod interpMethod=OF_INTERPOLATE_NEAREST_NEIGHBOR)
This resizes the ofPixels instance to the size of the ofPixels object passed in dst. The options for the interpolation methods are as follows: OF_INTERPOLATE_NEAREST_NEIGHBOR =1 OF_INTERPOLATE_BILINEAR =2 OF_INTERPOLATE_BICUBIC =3
rotate90(...)
void ofPixels_::rotate90(int nClockwiseRotations)
crop to a new width and height, this reallocates memory.
setChannel(...)
void ofPixels_::setChannel(int channel, const ofPixels_< PixelType > channelPixels)
This sets all the pixel data for a single channel, for instance, the Red pixel values, from an ofPixels object assumed to be a grayscale representation of the data that should go into that one channel.
setColor(...)
void ofPixels_::setColor(int x, int y, ofColor_< PixelType > color)
Sets the color of the pixel at the x,y location.
setFromAlignedPixels(...)
void ofPixels_::setFromAlignedPixels(const PixelType *newPixels, int width, int height, int channels, int stride)
setFromExternalPixels(...)
void ofPixels_::setFromExternalPixels(PixelType *newPixels, int w, int h, int channels)
setFromPixels(...)
void ofPixels_::setFromPixels(const PixelType *newPixels, int w, int h, int channels)
setFromPixels(...)
void ofPixels_::setFromPixels(const PixelType *newPixels, int w, int h, ofImageType type)
size()
int ofPixels_::size()
This gives you the number of values that the ofPixels object contains, so an RGB data 400x400 would be 480,000, whereas RGBA data of the same dimensions would be 640,000.
Last updated
Thursday, 16 May 2013 14:01:03 UTC
-
cbf0910627a25e6153f2452833c5313fe6067059

