Beispiel #1
0
int lfModifier::EnableDistortionCorrection (const lfLensCalibDistortion& lcd)
{
    if (Reverse)
        switch (lcd.Model)
        {
            case LF_DIST_MODEL_POLY3:
                if (lcd.Terms [0] == 0)
                    return enabledMods;
                // See "Note about PT-based distortion models" at the top of
                // this file.
                {
                    lfLensCalibDistortion lcd_ = lcd;
                    lcd_.Terms [0] = pow (1 - lcd.Terms [0], 3) / lcd.Terms [0];
                    AddCoordDistCallback (lcd_, ModifyCoord_UnDist_Poly3, 250);
                }
                break;

            case LF_DIST_MODEL_POLY5:
                AddCoordDistCallback (lcd, ModifyCoord_UnDist_Poly5, 250);
                break;

            case LF_DIST_MODEL_PTLENS:
            {
                // See "Note about PT-based distortion models" at the top of
                // this file.
                lfLensCalibDistortion lcd_ = lcd;
                float d = 1 - lcd.Terms [0] - lcd.Terms [1] - lcd.Terms [2];
                lcd_.Terms [0] /= pow (d, 4);
                lcd_.Terms [1] /= pow (d, 3);
                lcd_.Terms [2] /= pow (d, 2);
#ifdef VECTORIZATION_SSE
                if (_lf_detect_cpu_features () & LF_CPU_FLAG_SSE)
                    AddCoordDistCallback (lcd_, ModifyCoord_UnDist_PTLens_SSE, 250);
                else
#endif
                AddCoordDistCallback (lcd_, ModifyCoord_UnDist_PTLens, 250);
                break;
            }
            case LF_DIST_MODEL_ACM:
                g_warning ("[lensfun] \"acm\" distortion model is not yet implemented "
                           "for reverse correction");
                return enabledMods;

            default:
                return enabledMods;
        }
    else
        switch (lcd.Model)
        {
            case LF_DIST_MODEL_POLY3:
                // See "Note about PT-based distortion models" at the top of
                // this file.
                {
                    lfLensCalibDistortion lcd_ = lcd;
                    lcd_.Terms [0] = lcd.Terms [0] / pow (1 - lcd.Terms [0], 3);
    #ifdef VECTORIZATION_SSE
                    if (_lf_detect_cpu_features () & LF_CPU_FLAG_SSE)
                        AddCoordDistCallback (lcd_, ModifyCoord_Dist_Poly3_SSE, 750);
                    else
    #endif
                    AddCoordDistCallback (lcd_, ModifyCoord_Dist_Poly3, 750);
                }
                break;

            case LF_DIST_MODEL_POLY5:
                AddCoordDistCallback (lcd, ModifyCoord_Dist_Poly5, 750);
                break;

            case LF_DIST_MODEL_PTLENS:
            {
                // See "Note about PT-based distortion models" at the top of
                // this file.
                {
                    lfLensCalibDistortion lcd_ = lcd;
                    float d = 1 - lcd.Terms [0] - lcd.Terms [1] - lcd.Terms [2];
                    lcd_.Terms [0] /= pow (d, 4);
                    lcd_.Terms [1] /= pow (d, 3);
                    lcd_.Terms [2] /= pow (d, 2);
    #ifdef VECTORIZATION_SSE
                    if (_lf_detect_cpu_features () & LF_CPU_FLAG_SSE)
                        AddCoordDistCallback (lcd_, ModifyCoord_Dist_PTLens_SSE, 750);
                    else
    #endif
                    AddCoordDistCallback (lcd_, ModifyCoord_Dist_PTLens, 750);
                }
                break;
            }
            case LF_DIST_MODEL_ACM:
                AddCoordDistCallback (lcd, ModifyCoord_Dist_ACM, 750);
                break;

            default:
                return enabledMods;
        }

    enabledMods |= LF_MODIFY_DISTORTION;
    return enabledMods;
}
bool lfModifier::AddCoordCallbackDistortion (lfLensCalibDistortion &model, bool reverse)
{
    float tmp [3];

    if (reverse)
        switch (model.Model)
        {
            case LF_DIST_MODEL_POLY3:
                if (!model.Terms [0])
                    return false;
                tmp [0] = 1.0 / model.Terms [0];
                AddCoordCallback (lfExtModifier::ModifyCoord_UnDist_Poly3, 250,
                                  tmp, sizeof (float));
                break;

            case LF_DIST_MODEL_POLY5:
                AddCoordCallback (lfExtModifier::ModifyCoord_UnDist_Poly5, 250,
                                  model.Terms, sizeof (float) * 2);
                break;

            case LF_DIST_MODEL_FOV1:
                if (!model.Terms [0])
                    return false;
                tmp [0] = 1.0 / model.Terms [0];
                tmp [1] = 2.0 * tan (model.Terms [0] / 2.0);
                AddCoordCallback (lfExtModifier::ModifyCoord_UnDist_FOV1, 250,
                                  tmp, sizeof (float) * 2);
                break;

            case LF_DIST_MODEL_PTLENS:
#ifdef VECTORIZATION_SSE
                if (_lf_detect_cpu_features () & LF_CPU_FLAG_SSE)
                    AddCoordCallback (lfExtModifier::ModifyCoord_UnDist_PTLens_SSE, 250,
                                      model.Terms, sizeof (float) * 3);
                else
#endif
                AddCoordCallback (lfExtModifier::ModifyCoord_UnDist_PTLens, 250,
                                  model.Terms, sizeof (float) * 3);
                break;

            default:
                return false;
        }
    else
        switch (model.Model)
        {
            case LF_DIST_MODEL_POLY3:
#ifdef VECTORIZATION_SSE
                if (_lf_detect_cpu_features () & LF_CPU_FLAG_SSE)
                    AddCoordCallback (lfExtModifier::ModifyCoord_Dist_Poly3_SSE, 750,
                                      model.Terms, sizeof (float));
                else
#endif
                AddCoordCallback (lfExtModifier::ModifyCoord_Dist_Poly3, 750,
                                  model.Terms, sizeof (float));
                break;

            case LF_DIST_MODEL_POLY5:
                AddCoordCallback (lfExtModifier::ModifyCoord_Dist_Poly5, 750,
                                  model.Terms, sizeof (float) * 2);
                break;

            case LF_DIST_MODEL_FOV1:
                if (!model.Terms [0])
                    return false;
                tmp [0] = model.Terms [0];
                tmp [1] = 0.5 / tan (model.Terms [0] / 2.0);
                AddCoordCallback (lfExtModifier::ModifyCoord_Dist_FOV1, 750, tmp, sizeof (float) * 2);
                break;

            case LF_DIST_MODEL_PTLENS:
#ifdef VECTORIZATION_SSE
                if (_lf_detect_cpu_features () & LF_CPU_FLAG_SSE)
                    AddCoordCallback (lfExtModifier::ModifyCoord_Dist_PTLens_SSE, 750,
                                      model.Terms, sizeof (float) * 3);
                else
#endif
                AddCoordCallback (lfExtModifier::ModifyCoord_Dist_PTLens, 750,
                                  model.Terms, sizeof (float) * 3);
                break;

            default:
                return false;
        }

    return true;
}