Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion include/Warp.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,24 @@ class Warp : public std::enable_shared_from_this<Warp> {
mEdges.z = glm::clamp( edges.z * 0.5f, 0.0f, 1.0f );
mEdges.w = glm::clamp( edges.w * 0.5f, 0.0f, 1.0f );
}
//! returns the edge blending shift value for the left, top, right and bottom (values between -1 and 1)
virtual const ci::vec4 getShift() const { return mShift; }
//! set the edge blending shift value for the left, top, right and bottom (values between -1 and 1)
virtual void setShift(float left, float top, float right, float bottom)
{
mShift.x = left;
mShift.y = top;
mShift.z = right;
mShift.w = bottom;
}
//! set the edge blending shift value for the left, top, right and bottom (values between -1 and 1)
virtual void setShift(const ci::vec4 &shift)
{
mShift.x = shift.x;
mShift.y = shift.y;
mShift.z = shift.z;
mShift.w = shift.w;
}

//! reset control points to undistorted image
virtual void reset() = 0;
Expand Down Expand Up @@ -267,7 +285,7 @@ class Warp : public std::enable_shared_from_this<Warp> {
ci::vec3 mGamma;
ci::vec4 mEdges;
float mExponent;

ci::vec4 mShift;
//! time of last control point selection
double mSelectedTime;
//! keep track of mouse position
Expand Down
20 changes: 19 additions & 1 deletion src/Warp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ Warp::Warp( WarpType type )
, mGamma( 1.0f )
, mEdges( 0.0f )
, mExponent( 2.0f )
, mShift( 0.0f )
, mSelectedTime( 0 )
{
mWindowSize = vec2( float( mWidth ), float( mHeight ) );
Expand Down Expand Up @@ -177,6 +178,14 @@ XmlTree Warp::toXml() const
luminance.setAttribute( "green", mLuminance.y );
luminance.setAttribute( "blue", mLuminance.z );
blend.push_back( luminance );

XmlTree shift;
shift.setTag("shift");
shift.setAttribute("left", mShift.x);
shift.setAttribute("top", mShift.y);
shift.setAttribute("right", mShift.z);
shift.setAttribute("bottom", mShift.w);
blend.push_back(shift);
}
xml.push_back( blend );

Expand Down Expand Up @@ -223,6 +232,14 @@ void Warp::fromXml( const XmlTree &xml )
mLuminance.y = luminance->getAttributeValue<float>( "green", mLuminance.y );
mLuminance.z = luminance->getAttributeValue<float>( "blue", mLuminance.z );
}

auto shift = blend->find("shift");
if (shift != blend->end()) {
mShift.x = shift->getAttributeValue<float>("left", mShift.x);
mShift.y = shift->getAttributeValue<float>("top", mShift.y);
mShift.z = shift->getAttributeValue<float>("right", mShift.z);
mShift.w = shift->getAttributeValue<float>("bottom", mShift.w);
}
}

// reconstruct warp
Expand Down Expand Up @@ -274,7 +291,7 @@ void Warp::deselectControlPoint()

unsigned Warp::findControlPoint( const vec2 &pos, float *distance ) const
{
unsigned index;
unsigned index = 0;

// store mouse position for later use in e.g. WarpBilinear::keyDown().
mMouse = pos;
Expand Down Expand Up @@ -352,6 +369,7 @@ WarpList Warp::readSettings( const DataSourceRef &source )

// iterate maps
for( XmlTree::ConstIter child = profileXml.begin( "map" ); child != profileXml.end(); ++child ) {

XmlTree warpXml = child->getChild( "warp" );

// create warp of the correct type
Expand Down
11 changes: 7 additions & 4 deletions src/WarpBilinear.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ void WarpBilinear::draw( bool controls )
mShader->uniform( "uEdges", mEdges );
mShader->uniform( "uExponent", mExponent );
mShader->uniform( "uEditMode", (bool)isEditModeEnabled() );
mShader->uniform( "uShift", mShift + vec4(-mX1, -mY1, 1.f - mX2, 1.f - mY2) );


mBatch->draw();

Expand Down Expand Up @@ -689,6 +691,7 @@ void WarpBilinear::createShader()
"uniform vec4 uEdges;\n"
"uniform float uExponent;\n"
"uniform bool uEditMode;\n"
"uniform vec4 uShift;\n"
""
"in vec2 vertTexCoord0;\n"
"in vec4 vertColor;\n"
Expand All @@ -706,10 +709,10 @@ void WarpBilinear::createShader()
" vec4 texColor = texture( uTex0, vertTexCoord0 );\n"
""
" float a = 1.0;\n"
" if( uEdges.x > 0.0 ) a *= clamp( vertTexCoord0.x / uEdges.x, 0.0, 1.0 );\n"
" if( uEdges.y > 0.0 ) a *= clamp( vertTexCoord0.y / uEdges.y, 0.0, 1.0 );\n"
" if( uEdges.z > 0.0 ) a *= clamp( ( 1.0 - vertTexCoord0.x ) / uEdges.z, 0.0, 1.0 );\n"
" if( uEdges.w > 0.0 ) a *= clamp( ( 1.0 - vertTexCoord0.y ) / uEdges.w, 0.0, 1.0 );\n"
" if( uEdges.x > 0.0 ) a *= clamp( ( uShift.x + vertTexCoord0.x ) / uEdges.x, 0.0, 1.0 );\n"
" if( uEdges.y > 0.0 ) a *= clamp( ( uShift.y + vertTexCoord0.y ) / uEdges.y, 0.0, 1.0 );\n"
" if( uEdges.z > 0.0 ) a *= clamp( ( 1.0 - uShift.z - vertTexCoord0.x ) / uEdges.z, 0.0, 1.0 );\n"
" if( uEdges.w > 0.0 ) a *= clamp( ( 1.0 - uShift.w - vertTexCoord0.y ) / uEdges.w, 0.0, 1.0 );\n"
""
" const vec3 one = vec3( 1.0 );\n"
" vec3 blend = ( a < 0.5 ) ? ( uLuminance * pow( 2.0 * a, uExponent ) ) : one - ( one - uLuminance ) * pow( 2.0 * ( 1.0 - a ), uExponent );\n"
Expand Down
11 changes: 6 additions & 5 deletions src/WarpPerspective.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ void WarpPerspective::draw( const gl::Texture2dRef &texture, const Area &srcArea
mShader->uniform( "uGamma", mGamma );
mShader->uniform( "uEdges", mEdges );
mShader->uniform( "uExponent", mExponent );

mShader->uniform("uShift", mShift);
auto coords = texture->getAreaTexCoords( srcArea );
gl::drawSolidRect( rect, coords.getUpperLeft(), coords.getLowerRight() );

Expand Down Expand Up @@ -333,6 +333,7 @@ void WarpPerspective::createShader()
"uniform vec3 uGamma;\n"
"uniform vec4 uEdges;\n"
"uniform float uExponent;\n"
"uniform vec4 uShift;\n"
""
"in vec2 vertTexCoord0;\n"
"in vec4 vertColor;\n"
Expand All @@ -343,10 +344,10 @@ void WarpPerspective::createShader()
" vec4 texColor = texture( uTex0, vertTexCoord0 );\n"
""
" float a = 1.0;\n"
" if( uEdges.x > 0.0 ) a *= clamp( vertTexCoord0.x / uEdges.x, 0.0, 1.0 );\n"
" if( uEdges.y > 0.0 ) a *= clamp( vertTexCoord0.y / uEdges.y, 0.0, 1.0 );\n"
" if( uEdges.z > 0.0 ) a *= clamp( ( 1.0 - vertTexCoord0.x ) / uEdges.z, 0.0, 1.0 );\n"
" if( uEdges.w > 0.0 ) a *= clamp( ( 1.0 - vertTexCoord0.y ) / uEdges.w, 0.0, 1.0 );\n"
" if( uEdges.x > 0.0 ) a *= clamp( ( uShift.x + vertTexCoord0.x ) / uEdges.x, 0.0, 1.0 );\n"
" if( uEdges.y > 0.0 ) a *= clamp( ( uShift.y + vertTexCoord0.y ) / uEdges.y, 0.0, 1.0 );\n"
" if( uEdges.z > 0.0 ) a *= clamp( ( 1.0 - uShift.z - vertTexCoord0.x ) / uEdges.z, 0.0, 1.0 );\n"
" if( uEdges.w > 0.0 ) a *= clamp( ( 1.0 - uShift.w - vertTexCoord0.y ) / uEdges.w, 0.0, 1.0 );\n"
""
" const vec3 one = vec3( 1.0 );\n"
" vec3 blend = ( a < 0.5 ) ? ( uLuminance * pow( 2.0 * a, uExponent ) ) : one - ( one - uLuminance ) * pow( 2.0 * ( 1.0 - a ), uExponent );\n"
Expand Down