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.
didn't test but will look at monday. Thanks for report.
"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 ?
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.
Ok will look at it.
I made a patch for this: https://git.reviewboard.kde.org/r/106745
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