Hello,
I have modified the ofImage class to add mirror (horizontal & vertical) and rotate functionality.
Here is new code to add!
ofImage.h
after:
void resize(int newWidth, int newHeight);
add:
void mirror(bool horizontal, bool vertical);
void rotate(float angle);
after:
void resizePixels(ofPixels &pix, int newWidth, int newHeight);
add:
void flipPixels(ofPixels &pix, bool horizontal, bool vertical);
void rotatePixels(ofPixels &pix, float angle);
ofImage.cpp
after:
//------------------------------------
void ofImage::resize(int newWidth, int newHeight){
resizePixels(myPixels, newWidth, newHeight);
tex.clear();
if (bUseTexture == true){
tex.allocate(myPixels.width, myPixels.height, myPixels.glDataType);
}
update();
}
add:
//------------------------------------
void ofImage::mirror(bool horizontal, bool vertical){
flipPixels(myPixels, horizontal, vertical);
update();
}
//------------------------------------
void ofImage::rotate(float angle){
rotatePixels(myPixels, angle);
tex.clear();
if (bUseTexture == true){
tex.allocate(myPixels.width, myPixels.height, myPixels.glDataType);
}
update();
}
after:
//----------------------------------------------------
void ofImage::resizePixels(ofPixels &pix, int newWidth, int newHeight){
FIBITMAP * bmp = getBmpFromPixels(pix);
FIBITMAP * convertedBmp = NULL;
convertedBmp = FreeImage_Rescale(bmp, newWidth, newHeight, FILTER_BICUBIC);
putBmpIntoPixels(convertedBmp, pix);
#ifdef TARGET_LITTLE_ENDIAN
// if (pix.bytesPerPixel != 1) swapRgb(pix); /** disabled to fix channel-marring bug (as per: [http://forum.openframeworks.cc/t/ofimage-resize-bug-in-00573-xcode-fat-ycam/1242/0](http://forum.openframeworks.cc/t/ofimage-resize-bug-in-00573-xcode-fat-ycam/1242/0)
add:
//----------------------------------------------------
void ofImage::flipPixels(ofPixels &pix, bool horizontal, bool vertical){
if(!horizontal && !vertical)
return;
FIBITMAP * bmp = getBmpFromPixels(pix);
bool horSuccess = false, vertSuccess = false;
if(horizontal)
horSuccess = FreeImage_FlipHorizontal(bmp);
if(vertical)
vertSuccess = FreeImage_FlipVertical(bmp);
if(horSuccess || vertSuccess)
putBmpIntoPixels(bmp, pix);
if (bmp != NULL) FreeImage_Unload(bmp);
}
//----------------------------------------------------
void ofImage::rotatePixels(ofPixels &pix, float angle){
if(angle == 0.0)
return;
FIBITMAP * bmp = getBmpFromPixels(pix);
FIBITMAP * convertedBmp = NULL;
convertedBmp = FreeImage_RotateClassic(bmp, angle);
putBmpIntoPixels(convertedBmp, pix);
if (bmp != NULL) FreeImage_Unload(bmp);
if (convertedBmp != NULL) FreeImage_Unload(convertedBmp);
}
Hope this is helpful to someone out there!
Also, if anyone has any tips to make it better, I’d love to hear it!
Cheers!