Skip to content

Instantly share code, notes, and snippets.

@gregkepler
Created March 12, 2018 02:13
Show Gist options
  • Save gregkepler/e98744b5ac03369e1a036be9b710d0f6 to your computer and use it in GitHub Desktop.
Save gregkepler/e98744b5ac03369e1a036be9b710d0f6 to your computer and use it in GitHub Desktop.

Revisions

  1. gregkepler created this gist Mar 12, 2018.
    47 changes: 47 additions & 0 deletions SurfaceChannelRotate.cpp
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,47 @@
    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;
    }
    }
    }
    }