Skip to content

Instantly share code, notes, and snippets.

@gregkepler
Created March 12, 2018 02:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gregkepler/e98744b5ac03369e1a036be9b710d0f6 to your computer and use it in GitHub Desktop.
Save gregkepler/e98744b5ac03369e1a036be9b710d0f6 to your computer and use it in GitHub Desktop.
Rotate Channels or Surfaces in Cinder
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