Bug 307570 - Don't always recompress contact photos when saving
Summary: Don't always recompress contact photos when saving
Status: RESOLVED FIXED
Alias: None
Product: kdepimlibs
Classification: Applications
Component: kabc (show other bugs)
Version: 4.9
Platform: openSUSE Linux
: NOR normal
Target Milestone: ---
Assignee: kdepim bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-09-29 11:37 UTC by asamk
Modified: 2012-10-23 21:41 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In: 4.9.3


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description asamk 2012-09-29 11:37:27 UTC
When editing a contact in kaddressbook the contact photo is always recompressed when clicking Ok. So everytime I edit a contact the quality of the photo decreases.

I've had a look at the source code. When a contact is loaded into a KABC::Addressee object, the base64 photo data is stored into a KABC::Picture object as a QImage. When the contact is saved, the photo is compressed as jpeg again (with the default quality 75%).

A solution would be to also save the raw base64 data in KABC::Picture and to only recompress the photo when it was really changed.
Comment 1 Laurent Montel 2012-09-29 19:16:27 UTC
didn't test but will look at monday.
Thanks for report.
Comment 2 Laurent Montel 2012-09-30 08:53:09 UTC
"jpeg again (with the default quality 75%)." .?
QString Picture::toString() const
{
  QString str;

  str += QLatin1String( "Picture {\n" );
  str += QString::fromLatin1( "  Type: %1\n" ).arg( d->mType );
  str += QString::fromLatin1( "  IsIntern: %1\n" ).
         arg( d->mIntern ? QLatin1String( "true" ) : QLatin1String( "false" ) );
  if ( d->mIntern ) {
    QByteArray data;
    QBuffer buffer( &data );
    buffer.open( QIODevice::WriteOnly );
    d->mData.save( &buffer, "PNG" );
    str += QString::fromLatin1( "  Data: %1\n" ).arg( QString::fromLatin1( data.toBase64() ) );
  } else {
    str += QString::fromLatin1( "  Url: %1\n" ).arg( d->mUrl );
  }
  str += QLatin1String( "}\n" );

  return str;
}
it's store as png no ?
Comment 3 asamk 2012-09-30 09:00:26 UTC
no, that function is not used to store it in the vcf. It only seems useful for debugging.

the picture is loaded and stored in the file vcardtool.cpp:
VCardLine VCardTool::createPicture( const QString &identifier, const Picture &pic ) const
{
  VCardLine line( identifier );

  if ( pic.isIntern() ) {
    if ( !pic.data().isNull() ) {
      QByteArray input;
      QBuffer buffer( &input );
      buffer.open( QIODevice::WriteOnly );

      if ( !pic.data().hasAlphaChannel() ) {
        pic.data().save( &buffer, "JPEG" );

        line.setValue( input );
        line.addParameter( QLatin1String( "encoding" ), QLatin1String( "b" ) );
        line.addParameter( QLatin1String( "type" ), QLatin1String( "image/jpeg" ) );
      } else {
        pic.data().save( &buffer, "PNG" );

        line.setValue( input );
        line.addParameter( QLatin1String( "encoding" ), QLatin1String( "b" ) );
        line.addParameter( QLatin1String( "type" ), QLatin1String( "image/png" ) );
      }
    }
  } else if ( !pic.url().isEmpty() ) {
    line.setValue( pic.url() );
    line.addParameter( QLatin1String( "value" ), QLatin1String( "URI" ) );
  }

  return line;
}

The 75% quality I found from looking in the Qt source code, what QImage::save() does, if no quality is specified.
Comment 4 Laurent Montel 2012-09-30 09:10:11 UTC
Ok will look at it.
Comment 5 asamk 2012-10-06 16:18:00 UTC
I made a patch for this:
https://git.reviewboard.kde.org/r/106745
Comment 6 Allen Winter 2012-10-23 21:41:12 UTC
Git commit c0a50e2b6e7a8513d0a768afb35bc7aa3d1748f1 by Allen Winter.
Committed on 23/10/2012 at 23:40.
Pushed by winterz into branch 'master'.

Don't always recompress contact photos when saving
The patch from RB did not apply cleanly so I had to hand-patch
in a few files.  I hope I didn't screwup.

Thanks for the patch Sebastian!

REVIEW: 106745
FIXED-IN: 4.9.3

M  +11   -13   akonadi/contact/editor/imagewidget.cpp
M  +3    -1    akonadi/contact/editor/imagewidget.h
M  +66   -11   kabc/picture.cpp
M  +38   -5    kabc/picture.h
M  +138  -23   kabc/tests/picturetest.cpp
M  +10   -3    kabc/tests/picturetest.h
M  +17   -31   kabc/vcardtool.cpp

http://commits.kde.org/kdepimlibs/c0a50e2b6e7a8513d0a768afb35bc7aa3d1748f1