Exemple #1
0
lfCamera::~lfCamera ()
{
    lf_free (Maker);
    lf_free (Model);
    lf_free (Variant);
    lf_free (Mount);
}
Exemple #2
0
static void ht_cst_exit_accuracy(void)
{
    osux_yaml_free(yw_acc);
    lf_free(SLOW_LF);
    lf_free(SPC_FREQ_LF);
    lf_free(SPC_INFLU_LF);
    lf_free(HIT_WINDOW_LF);
    lf_free(ACCURACY_SCALE_LF);
}
lfLens::~lfLens ()
{
    lf_free (Maker);
    lf_free (Model);
    _lf_list_free ((void **)Mounts);
    _lf_list_free ((void **)CalibDistortion);
    _lf_list_free ((void **)CalibTCA);
    _lf_list_free ((void **)CalibVignetting);
}
Exemple #4
0
lfMount &lfMount::operator = (const lfMount &other)
{
    lf_free (Name);
    Name = lf_mlstr_dup (other.Name);
    lf_free (Compat); Compat = NULL;
    if (other.Compat)
        for (int i = 0; other.Compat [i]; i++)
                AddCompat (other.Compat [i]);

    return *this;
}
lfLens::~lfLens ()
{
    lf_free (Maker);
    lf_free (Model);
    _lf_list_free ((void **)Mounts);
    _lf_list_free ((void **)CalibDistortion);
    _lf_list_free ((void **)CalibTCA);
    _lf_list_free ((void **)CalibVignetting);
    if (!--_lf_lens_regex_refs)
        _lf_free_lens_regex ();
}
Exemple #6
0
lfCamera &lfCamera::operator = (const lfCamera &other)
{
    lf_free (Maker);
    Maker = lf_mlstr_dup (other.Maker);
    lf_free (Model);
    Model = lf_mlstr_dup (other.Model);
    lf_free (Variant);
    Variant = lf_mlstr_dup (other.Variant);
    _lf_setstr (&Mount, other.Mount);
    CropFactor = other.CropFactor;
    return *this;
}
static int check_exif(_Data *data)
{
  const lfLens **lenses;
  const lfLens *lens;
  lime_exif *exif = data->common->exif->data;
  
  if (data->common->exif_loaded == 1)
    return 0;
  else if (data->common->exif_loaded == -1)
    return -1;
  
  data->common->lens_model = lime_exif_handle_find_str_by_tagname(exif, "LensType");
  if (!data->common->lens_model)
    data->common->lens_model = lime_exif_handle_find_str_by_tagname(exif, "LensModel");
  if (!data->common->lens_model) {
    data->common->exif_loaded = -1;
    return -1;
  }
  data->common->lens_model = strdup(data->common->lens_model);
  data->common->f = lime_exif_handle_find_float_by_tagname(exif, "FocalLength");
  data->common->f_dist = lime_exif_handle_find_float_by_tagname(exif, "FocusDistance");
  if (data->common->f_dist == -1.0)
    data->common->f_dist = 1000;
  data->common->f_num = lime_exif_handle_find_float_by_tagname(exif, "FNumber");
  
  
  //FIXME check for errors...
  if (!data->common->db) {
    data->common->db = lf_db_new();
    lf_db_load(data->common->db);
  }
  
  lenses = lf_db_find_lenses_hd(data->common->db, NULL, NULL, data->common->lens_model, 0);
  
  if (!lenses) {
    printf("lensfun could not find lens model %s!\n", data->common->lens_model);
    data->common->exif_loaded = -1;
    return -1;
  }
  
  lens = lenses[0];
  data->common->lens = lens;
  lf_free(lenses);
  
  data->common->exif_loaded = 1;
  
  return 0;
}
lfLens &lfLens::operator = (const lfLens &other)
{
    lf_free (Maker);
    Maker = lf_mlstr_dup (other.Maker);
    lf_free (Model);
    Model = lf_mlstr_dup (other.Model);
    MinFocal = other.MinFocal;
    MaxFocal = other.MaxFocal;
    MinAperture = other.MinAperture;
    MaxAperture = other.MaxAperture;

    lf_free (Mounts); Mounts = NULL;
    if (other.Mounts)
        for (int i = 0; other.Mounts [i]; i++)
            AddMount (other.Mounts [i]);

    CenterX = other.CenterX;
    CenterY = other.CenterY;
    CropFactor = other.CropFactor;
    AspectRatio = other.AspectRatio;
    Type = other.Type;

    lf_free (CalibDistortion); CalibDistortion = NULL;
    if (other.CalibDistortion)
        for (int i = 0; other.CalibDistortion [i]; i++)
            AddCalibDistortion (other.CalibDistortion [i]);
    lf_free (CalibTCA); CalibTCA = NULL;
    if (other.CalibTCA)
        for (int i = 0; other.CalibTCA [i]; i++)
            AddCalibTCA (other.CalibTCA [i]);
    lf_free (CalibVignetting); CalibVignetting = NULL;
    if (other.CalibVignetting)
        for (int i = 0; other.CalibVignetting [i]; i++)
            AddCalibVignetting (other.CalibVignetting [i]);
    lf_free (CalibCrop); CalibCrop = NULL;
    if (other.CalibCrop)
        for (int i = 0; other.CalibCrop [i]; i++)
            AddCalibCrop (other.CalibCrop [i]);
    lf_free (CalibFov); CalibFov = NULL;
    if (other.CalibFov)
        for (int i = 0; other.CalibFov [i]; i++)
            AddCalibFov (other.CalibFov [i]);

    return *this;
}
lfLens &lfLens::operator = (const lfLens &other)
{
    lf_free (Maker);
    Maker = lf_mlstr_dup (other.Maker);
    lf_free (Model);
    Model = lf_mlstr_dup (other.Model);
    MinFocal = other.MinFocal;
    MaxFocal = other.MaxFocal;
    MinAperture = other.MinAperture;
    MaxAperture = other.MaxAperture;

    lf_free (Mounts);
    Mounts = NULL;
    if (other.Mounts)
        for (int i = 0; other.Mounts [i]; i++)
            AddMount (other.Mounts [i]);

    CenterX = other.CenterX;
    CenterY = other.CenterY;
    RedCCI = other.RedCCI;
    GreenCCI = other.GreenCCI;
    BlueCCI = other.BlueCCI;
    CropFactor = other.CropFactor;
    Type = other.Type;

    lf_free (CalibDistortion);
    CalibDistortion = NULL;
    if (other.CalibDistortion)
        for (int i = 0; other.CalibDistortion [i]; i++)
            AddCalibDistortion (other.CalibDistortion [i]);
    lf_free (CalibTCA);
    CalibTCA = NULL;
    if (other.CalibTCA)
        for (int i = 0; other.CalibTCA [i]; i++)
            AddCalibTCA (other.CalibTCA [i]);
    lf_free (CalibVignetting);
    CalibVignetting = NULL;
    if (other.CalibVignetting)
        for (int i = 0; other.CalibVignetting [i]; i++)
            AddCalibVignetting (other.CalibVignetting [i]);

    return *this;
}
Exemple #10
0
lfMount::~lfMount ()
{
    lf_free (Name);
    _lf_list_free ((void **)Compat);
}
Exemple #11
0
static void _xml_text (GMarkupParseContext *context,
                       const gchar         *text,
                       gsize                text_len,
                       gpointer             user_data,
                       GError             **error)
{
    lfParserData *pd = (lfParserData *)user_data;
    const gchar *ctx = g_markup_parse_context_get_element (context);

    while (*text && strchr (" \t\n\r", *text))
        text++;
    if (!*text)
        goto leave;

    if (!strcmp (ctx, "name"))
    {
        if (pd->mount)
            pd->mount->SetName (text, pd->lang);
        else
        {
        bad_ctx:
            g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT,
                         "Wrong context for element <%.*s>\n",
                         int (text_len), text);
            goto leave;
        }
    }
    else if (!strcmp (ctx, "maker"))
    {
        if (pd->camera)
            pd->camera->SetMaker (text, pd->lang);
        else if (pd->lens)
            pd->lens->SetMaker (text, pd->lang);
        else
            goto bad_ctx;
    }
    else if (!strcmp (ctx, "model"))
    {
        if (pd->camera)
            pd->camera->SetModel (text, pd->lang);
        else if (pd->lens)
            pd->lens->SetModel (text, pd->lang);
        else
            goto bad_ctx;
    }
    else if (!strcmp (ctx, "variant"))
    {
        if (pd->camera)
            pd->camera->SetVariant (text, pd->lang);
        else
            goto bad_ctx;
    }
    else if (!strcmp (ctx, "mount"))
    {
        if (pd->camera)
            pd->camera->SetMount (text);
        else if (pd->lens)
            pd->lens->AddMount (text);
        else
            goto bad_ctx;
    }
    else if (!strcmp (ctx, "compat"))
    {
        if (pd->mount)
            pd->mount->AddCompat (text);
        else
            goto bad_ctx;
    }
    else if (!strcmp (ctx, "cropfactor"))
    {
        if (pd->camera)
            pd->camera->CropFactor = atof (text);
        else if (pd->lens)
            pd->lens->CropFactor = atof (text);
        else
            goto bad_ctx;
    }
    else if (!strcmp (ctx, "type"))
    {
        if (pd->lens)
        {
            if (!_lf_strcmp (text, "rectilinear"))
                pd->lens->Type = LF_RECTILINEAR;
            else if (!_lf_strcmp (text, "fisheye"))
                pd->lens->Type = LF_FISHEYE;
            else if (!_lf_strcmp (text, "panoramic"))
                pd->lens->Type = LF_PANORAMIC;
            else if (!_lf_strcmp (text, "equirectangular"))
                pd->lens->Type = LF_EQUIRECTANGULAR;
            else
            {
                g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT,
                             "Invalid lens type `%s' (%s/%s)\n", text,
                             pd->camera ? pd->camera->Maker : "???",
                             pd->camera ? pd->camera->Model : "???");
                return;
            }
        }
        else
            goto bad_ctx;
    }

leave:
    lf_free (pd->lang);
    pd->lang = NULL;
}
Exemple #12
0
int main (int argc, char **argv)
{
    setlocale (LC_ALL, "");

    if (!ParseParameters(argc, argv))
        return -1;

    // load database
    lfDatabase *ldb = new lfDatabase ();

    if (ldb->Load () != LF_NO_ERROR) {
        ldb->Destroy();
        g_print ("\rERROR: Database could not be loaded\n");
        return -1;
    }

    // try to find camera in the database
    const lfCamera *cam = NULL;
    if (opts.Camera) {
        const lfCamera ** cameras = ldb->FindCamerasExt(NULL, opts.Camera);
        if (cameras)
            cam = cameras[0];
        else
            g_print ("Cannot find a camera matching `%s' in database\n", opts.Camera);
        lf_free (cameras);
     }

    // try to find a matching lens in the database
    const lfLens *lens = NULL;
    if (opts.Lens) {
        const lfLens **lenses = ldb->FindLenses (cam, NULL, opts.Lens);
        if (lenses)
            lens = lenses [0];
        else
            g_print ("Cannot find a lens matching `%s' in database\n", opts.Lens);
        lf_free (lenses);
    }

    // print camera and lens information if in verbose mode or if no input file is specified
    if (opts.Verbose || !opts.Input) {
        if (cam && lens) {
            g_print("Matching lens and camera combination found in the database:\n");
            PrintCamera(cam, ldb);
            PrintLens(lens, ldb);
        } else if (!cam && lens) {
            g_print("Matching lens found in the database:\n");
            PrintLens(lens, ldb);
        } else if (!lens && cam) {
            g_print("Matching camera found in the database:\n");
            PrintCamera(cam, ldb);
        }
    } else {
        if (cam && lens) {
            g_print("= Selecting %s / %s\n", cam->Model, lens->Model);
        } else if (!cam && lens) {
            g_print("= Selecting %s\n", lens->Model);
        }
    }

    // nothing to process, so lets quit here
    if (!opts.Input) {
        ldb->Destroy();
        return 0;
    }

    // assume standard values if parameters are not specified
    if (cam)
        opts.Crop = cam->CropFactor;
    else if (!opts.Crop)
        opts.Crop = lens->CropFactor;    
    if (!opts.Focal)
        opts.Focal = lens->MinFocal;
    if (!opts.Aperture)
        opts.Aperture = lens->MinAperture;

    if (opts.Verbose) {
        g_print("\nProcessing parameters:\n"
                "    |- Image crop factor: %g\n"
                "    |- Focal length: %gmm\n"
                "    |- Aperture: f/%g\n"
                "    |- Distance: %gm\n\n",
                opts.Crop, opts.Focal, opts.Aperture, opts.Distance);
    } else {
        g_print("= Processing parameters: Crop %g, Focal %gmm, Aperture f/%g, Distance: %gm\n",
                opts.Crop, opts.Focal, opts.Aperture, opts.Distance);
    }

    Image *img = new Image ();
    g_print ("~ Loading `%s' ... ", opts.Input);
    if (!img->Open (opts.Input)) {
        g_print ("\rERROR: failed to open file `%s'\n", opts.Input);
        delete img;
        ldb->Destroy();
        return -1;
    }
    if (!img->LoadPNG ()) {
        g_print ("\rERROR: failed to parse PNG data from file `%s'\n", opts.Input);
        delete img;
        ldb->Destroy();
        return -1;
    }
    g_print ("done.\n~ Image size [%ux%u].\n", img->width, img->height);

    lfModifier *mod = lfModifier::Create (lens, opts.Crop, img->width, img->height);
    if (!mod) {
        g_print ("\rWarning: failed to create modifier\n");
        delete img;
        ldb->Destroy();
        return -1;
    }
    int modflags = mod->Initialize (
        lens, LF_PF_U8, opts.Focal,
        opts.Aperture, opts.Distance, opts.Scale, opts.TargetGeom,
        opts.ModifyFlags, opts.Inverse);

    g_print("~ Selected modifications: ");
    if (modflags & LF_MODIFY_TCA)
        g_print ("[tca]");
    if (modflags & LF_MODIFY_VIGNETTING)
        g_print ("[vign]");
    if (modflags & LF_MODIFY_DISTORTION)
        g_print ("[dist]");
    if (modflags & LF_MODIFY_GEOMETRY)
        g_print ("[geom]");
    if (opts.Scale != 1.0)
        g_print ("[scale]");
    if (modflags==0)
        g_print ("[NOTHING]");
    g_print ("\n");

    g_print("~ Run processing chain... ");

    clock_t st;
    clock_t xt = clock ();
    while (xt == (st = clock ()))
        ;

    img = ApplyModifier (modflags, opts.Inverse, img, mod);

    clock_t et = clock ();
    g_print ("done (%.3g secs)\n", double (et - st) / CLOCKS_PER_SEC);

    mod->Destroy ();

    g_print ("~ Save output as `%s'...", opts.Output);
    bool ok = img->SavePNG (opts.Output);

    delete img;
    ldb->Destroy ();

    if (ok) {
        g_print (" done\n");
        return 0;
    } else {
        g_print (" FAILED\n");
        return -1;
    }

}