Proof of concept: using ExifTool in C++

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Proof of concept: using ExifTool in C++

Bugzilla from thorsten.schnebeck@gmx.net
Hi list, hi Phil,

as you know I'm still on my way in promoting ExifTool and this weekend I had a
little bit time to program.

As a proof of concept I programmed a new kfile_rawimage- and
rawimage_thumbnail service using ExifTool in KDE.
For security reasons I did not use ExifTool as a script but feeding libperl
with a Perl program in C++ using the Image::ExifTool Perl library.

Speed impact is not as bad as I thought at the beginning but this has also
something to do, that the original kcamerarawplugin from kdegraphics uses
temp files I do not need with ExifTool. For single file handling its really
ok and thumbnails are cached anyway.

When I compare my kfile_rawimage with kfile_jpeg I see, that using ExifTool is
nearly the same straight forward than using the old and not more up-to-date
libexif.

Here is a code extract:

extern "C" {
  #include <INTERN.h>
  #include <perl.h>
  static PerlInterpreter *MyPerl;
}

bool rawimagePlugin::readInfo( KFileMetaInfo& info, uint what) {
  KFileMetaInfoGroup group = appendGroup(info, "RAWInfo");
  const QString path(info.path());
  if ( path.isEmpty() ) return false; // remote file

  // setup Perl program
  STRLEN n_a;
  char *embedding[] = {"", "-e", "0"};
  QString exiftool = "my $file=\"" + QFile::encodeName(path) + \
      "\";use Image::ExifTool; my $exiftool = new Image::ExifTool;" + \
      "$exiftool->Options(PrintConv => 1);" + \
      "$info = $exiftool->ImageInfo($file);";

  // run Perl program
  MyPerl = perl_alloc();
  perl_construct( MyPerl );
  perl_parse(MyPerl, NULL, 3, embedding, (char **)NULL);
  PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
  perl_run(MyPerl);
  perl_eval_pv((char*) exiftool.latin1(), TRUE);
  perl_eval_pv((char*) "$return=$$info{'Make'};", TRUE);
  QString make=SvPV(perl_get_sv("return", FALSE), n_a);

  perl_eval_pv((char*) "$return=$$info{'Model'};", TRUE);
  QString model=SvPV(perl_get_sv("return", FALSE), n_a);

  perl_eval_pv((char*) "$return=$$info{'FocalLength'};", TRUE);
  QString focal=SvPV(perl_get_sv("return", FALSE), n_a);

  perl_eval_pv((char*) "$return=$$info{'Aperture'};", TRUE);
  QString aperture=SvPV(perl_get_sv("return", FALSE), n_a);

  perl_destruct(MyPerl);
  perl_free(MyPerl);
  PERL_SYS_TERM();

Watching this service in action please look the screenshot at
http://forum.ebv4linux.de/download.php?id=215
As you can see the new code supports the rotation flag and thumbnail
generating of RAW files.
If I know how to handle mimetype magic and deinstallation of the old mimetype
handler I can publish the code as a kdevelop project.

Bye

  Thorsten

_______________________________________________
Digikam-devel mailing list
[hidden email]
https://mail.kde.org/mailman/listinfo/digikam-devel
Loading...