Bug 138949

Summary: save/overwrite fails: wrong dialog
Product: [Applications] digikam Reporter: Daniel Bauer <linux>
Component: ImageEditor-SaveAssignee: Digikam Developers <digikam-bugs-null>
Status: RESOLVED FIXED    
Severity: normal    
Priority: NOR    
Version: unspecified   
Target Milestone: ---   
Platform: openSUSE   
OS: Linux   
Latest Commit: Version Fixed In: 0.9.1
Sentry Crash Report:

Description Daniel Bauer 2006-12-18 09:06:29 UTC
Version:           0.9 svn (using KDE KDE 3.5.5)
Installed from:    SuSE RPMs
OS:                Linux

When re-opening a freshly saved file that was made from a CR2 raw file in 8-bit mode and then trying to save (overwrite) this file again, the dialog "New Image File Name" appears and the file cannot be overwritten.

To reproduce:

1) open a CR2-raw file in 8-bit mode
2) save as jpg (or png or tiff, havn't tried others)
3) close editor window
4) open the new jpg and change something to make it "modified"
5) close editor window, click "save" in "The image has been modified"-warning
6) dialog "New Image File Name" appears (instead of saving/overwriting the file silently). The file cannot be overwritten.

The error occurs only in 8-bit mode, when starting with a CR2-raw file (I havn't other raw files to test). It does not happen when starting with any other kind of image file.

It happens only, when re-opening the new file (from Step 2) before opening any other file.

If any other file is opened between Step 3 and 4 or if digiKam is closed and started again, the error doesn't appear. It also doesn't appear if "16-bit" is checked in digiKam settings.
Comment 1 Marcel Wiesweg 2006-12-23 18:06:21 UTC
SVN commit 616109 by mwiesweg:

When an image is saved in another format and put in the cache for the new path,
the read-only property is unchanged.

Only put in cache under for the new path if the file format did not change
- make file format from DImgInterface accessible from Canvas
- store original format in SavingContext as well as saved-to format
- check when putting in cache in ImageWindow

BUG: 138949


 M  +5 -0      canvas/canvas.cpp  
 M  +1 -0      canvas/canvas.h  
 M  +16 -9     canvas/dimginterface.cpp  
 M  +1 -0      canvas/dimginterface.h  
 M  +3 -0      editor/editorwindow.cpp  
 M  +5 -1      editor/imagewindow.cpp  
 M  +2 -1      editor/savingcontextcontainer.h  


--- trunk/extragear/graphics/digikam/utilities/imageeditor/canvas/canvas.cpp #616108:616109
@@ -516,6 +516,11 @@
     return DImg(*d->im->getImg());
 }
 
+QString Canvas::currentImageFileFormat()
+{
+    return d->im->getImageFormat();
+}
+
 int Canvas::imageWidth()
 {
     return d->im->origWidth();  
--- trunk/extragear/graphics/digikam/utilities/imageeditor/canvas/canvas.h #616108:616109
@@ -71,6 +71,7 @@
     void  setUndoHistoryOrigin();
     void  updateUndoState();
     DImg  currentImage();
+    QString currentImageFileFormat();
 
     bool  maxZoom();
     bool  minZoom();
--- trunk/extragear/graphics/digikam/utilities/imageeditor/canvas/dimginterface.cpp #616108:616109
@@ -527,15 +527,7 @@
 
     // This is possibly empty
     if (mimeType.isEmpty())
-    {
-        mimeType = d->image.attribute("format").toString();
-        // It is a bug if format attribute is not given
-        if (mimeType.isEmpty())
-        {
-            DWarning() << "DImg object does not contain attribute \"format\"" << endl;
-            mimeType = QImageIO::imageFormat(d->filename);
-        }
-    }
+        mimeType = getImageFormat();
 
     DDebug() << "Saving to :" << QFile::encodeName(fileName).data() << " (" 
               << mimeType << ")" << endl;
@@ -1142,6 +1134,21 @@
     return d->filename.section( '/', -1 );
 }
 
+QString DImgInterface::getImageFormat()
+{
+    if (d->image.isNull())
+        return QString();
+
+    QString mimeType = d->image.attribute("format").toString();
+    // It is a bug in the loader if format attribute is not given
+    if (mimeType.isEmpty())
+    {
+        DWarning() << "DImg object does not contain attribute \"format\"" << endl;
+        mimeType = QImageIO::imageFormat(d->filename);
+    }
+    return mimeType;
+}
+
 ICCSettingsContainer* DImgInterface::getICCSettings()
 {
     return d->cmSettings;
--- trunk/extragear/graphics/digikam/utilities/imageeditor/canvas/dimginterface.h #616108:616109
@@ -143,6 +143,7 @@
     ICCSettingsContainer *getICCSettings();
 
     QString               getImageFileName();
+    QString               getImageFormat();
 
 protected slots:
 
--- trunk/extragear/graphics/digikam/utilities/imageeditor/editor/editorwindow.cpp #616108:616109
@@ -1319,6 +1319,8 @@
     m_savingContext->srcURL             = url;
     m_savingContext->destinationURL     = m_savingContext->srcURL;
     m_savingContext->destinationExisted = true;
+    m_savingContext->originalFormat     = m_canvas->currentImageFileFormat();
+    m_savingContext->format             = m_savingContext->originalFormat;
     m_savingContext->abortingSaving     = false;
     m_savingContext->savingState        = SavingContextContainer::SavingStateSave;
     // use magic file extension which tells the digikamalbums ioslave to ignore the file
@@ -1456,6 +1458,7 @@
     // use magic file extension which tells the digikamalbums ioslave to ignore the file
     m_savingContext->saveTempFile   = new KTempFile(newURL.directory(false), ".digikamtempfile.tmp");
     m_savingContext->destinationURL = newURL;
+    m_savingContext->originalFormat = m_canvas->currentImageFileFormat();
     m_savingContext->savingState    = SavingContextContainer::SavingStateSaveAs;
     m_savingContext->saveTempFile->setAutoDelete(true);
     m_savingContext->abortingSaving = false;
--- trunk/extragear/graphics/digikam/utilities/imageeditor/editor/imagewindow.cpp #616108:616109
@@ -825,7 +825,11 @@
         d->urlCurrent = m_savingContext->destinationURL;
         m_canvas->switchToLastSaved(m_savingContext->destinationURL.path());
         slotUpdateItemInfo();
-        LoadingCacheInterface::putImage(m_savingContext->destinationURL.path(), m_canvas->currentImage());
+        // If the DImg is put in the cache under the new name, this means the new file will not be reloaded.
+        // This may irritate users who want to check for quality loss in lossy formats.
+        // In any case, only do that if the format did not change - too many assumptions otherwise (see bug #138949).
+        if (m_savingContext->originalFormat == m_savingContext->format)
+            LoadingCacheInterface::putImage(m_savingContext->destinationURL.path(), m_canvas->currentImage());
 
         // notify main app that file changed or a file is added
         if(m_savingContext->destinationExisted)
--- trunk/extragear/graphics/digikam/utilities/imageeditor/editor/savingcontextcontainer.h #616108:616109
@@ -67,7 +67,8 @@
     bool                     synchronousSavingResult;
     bool                     destinationExisted;
     bool                     abortingSaving;
-    
+
+    QString                  originalFormat;
     QString                  format;
 
     KURL                     srcURL;