Created
March 12, 2018 02:13
-
-
Save gregkepler/e98744b5ac03369e1a036be9b710d0f6 to your computer and use it in GitHub Desktop.
Rotate Channels or Surfaces in Cinder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void SurfaceChannelRotateApp::rotateChannel( const ci::Channel &channel, ci::Channel &destChannel ) | |
{ | |
const int32_t height = channel.getHeight(); | |
const int32_t width = channel.getWidth(); | |
// 90 deg | |
/* | |
for( int32_t y = 0; y < height; ++y ) { | |
auto ogPtr = channel.getData( ivec2( 0, y ) ); | |
auto newPtr = destChannel.getData( ivec2( height - y - 1, 0 ) ); | |
for( int32_t x = 0; x < width; ++x ) { | |
int rotRow = height * x; | |
auto v = ogPtr[x]; | |
newPtr[rotRow] = v; | |
} | |
}*/ | |
// -90 deg | |
for( int32_t y = 0; y < height; ++y ) { | |
auto ogPtr = channel.getData( ivec2( 0, y ) ); | |
auto newPtr = destChannel.getData( ivec2( y, 0 ) ); | |
for( int32_t x = 0; x < width; ++x ) { | |
int rotRow = height*x; | |
auto v = ogPtr[width - x - 1]; | |
newPtr[rotRow] = v; | |
} | |
} | |
} | |
void SurfaceChannelRotateApp::rotateSurface( const ci::Surface8u &surface, ci::Surface8u &destSurface ) | |
{ | |
const int32_t height = surface.getHeight(); | |
const int32_t width = surface.getWidth(); | |
const size_t inc = surface.getPixelInc(); | |
for( int32_t y = 0; y < height; ++y ) { | |
auto ogPtr = surface.getData( ivec2( 0, y ) ); | |
auto newPtr = destSurface.getData( ivec2( height - y - 1, 0 ) ); | |
for( int32_t x = 0; x < width; ++x ) { | |
for( int c = 0; c < inc; ++c ) { | |
int rotRow = height*(x*inc)+c; | |
auto v = ogPtr[x*inc + c]; | |
newPtr[rotRow] = v; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment