Fix #926: Use system background color in window mode
[geeqie.git] / src / image.c
index ad474d6..1326ff1 100644 (file)
@@ -589,7 +589,14 @@ void image_alter_orientation(ImageWindow *imd, FileData *fd_n, AlterType type)
        else
                if (options->metadata.write_orientation)
                        {
-                       orientation = metadata_read_int(fd_n, ORIENTATION_KEY, EXIF_ORIENTATION_TOP_LEFT);
+                       if (g_strcmp0(imd->image_fd->format_name, "heif") == 0)
+                               {
+                               orientation = EXIF_ORIENTATION_TOP_LEFT;
+                               }
+                       else
+                               {
+                               orientation = metadata_read_int(fd_n, ORIENTATION_KEY, EXIF_ORIENTATION_TOP_LEFT);
+                               }
                        }
        }
 
@@ -620,13 +627,21 @@ void image_alter_orientation(ImageWindow *imd, FileData *fd_n, AlterType type)
 
        if (orientation != (fd_n->exif_orientation ? fd_n->exif_orientation : 1))
                {
-               if (!options->metadata.write_orientation)
+               if (g_strcmp0(fd_n->format_name, "heif") != 0)
+                       {
+                       if (!options->metadata.write_orientation)
+                               {
+                               /* user_orientation does not work together with options->metadata.write_orientation,
+                                  use either one or the other.
+                                  we must however handle switching metadata.write_orientation on and off, therefore
+                                  we just disable referencing new fd's, not unreferencing the old ones
+                               */
+                               if (fd_n->user_orientation == 0) file_data_ref(fd_n);
+                               fd_n->user_orientation = orientation;
+                               }
+                       }
+               else
                        {
-                       /* user_orientation does not work together with options->metadata.write_orientation,
-                          use either one or the other.
-                          we must however handle switching metadata.write_orientation on and off, therefore
-                          we just disable referencing new fd's, not unreferencing the old ones
-                       */
                        if (fd_n->user_orientation == 0) file_data_ref(fd_n);
                        fd_n->user_orientation = orientation;
                        }
@@ -637,15 +652,18 @@ void image_alter_orientation(ImageWindow *imd, FileData *fd_n, AlterType type)
                fd_n->user_orientation = 0;
                }
 
-       if (options->metadata.write_orientation)
+       if (g_strcmp0(fd_n->format_name, "heif") != 0)
                {
-               if (type == ALTER_NONE)
-                       {
-                       metadata_write_revert(fd_n, ORIENTATION_KEY);
-                       }
-               else
+               if (options->metadata.write_orientation)
                        {
-                       metadata_write_int(fd_n, ORIENTATION_KEY, orientation);
+                       if (type == ALTER_NONE)
+                               {
+                               metadata_write_revert(fd_n, ORIENTATION_KEY);
+                               }
+                       else
+                               {
+                               metadata_write_int(fd_n, ORIENTATION_KEY, orientation);
+                               }
                        }
                }
 
@@ -686,6 +704,11 @@ gboolean image_get_overunderexposed(ImageWindow *imd)
        return imd->overunderexposed;
 }
 
+void image_set_ignore_alpha(ImageWindow *imd, gboolean ignore_alpha)
+{
+   pixbuf_renderer_set_ignore_alpha((PixbufRenderer *)imd->pr, ignore_alpha);
+}
+
 /*
  *-------------------------------------------------------------------
  * read ahead (prebuffer)
@@ -872,12 +895,16 @@ static void image_load_done_cb(ImageLoader *il, gpointer data)
                                break;
                        case FORMAT_CLASS_VIDEO:
                                pixbuf = pixbuf_inline(PIXBUF_INLINE_VIDEO);
+                               break;
                        case FORMAT_CLASS_COLLECTION:
                                pixbuf = pixbuf_inline(PIXBUF_INLINE_COLLECTION);
                                break;
                        case FORMAT_CLASS_DOCUMENT:
                                pixbuf = pixbuf_inline(PIXBUF_INLINE_ICON_PDF);
                                break;
+                       case FORMAT_CLASS_ARCHIVE:
+                               pixbuf = pixbuf_inline(PIXBUF_INLINE_ARCHIVE);
+                               break;
                        default:
                                pixbuf = pixbuf_inline(PIXBUF_INLINE_BROKEN);
                        }
@@ -1089,6 +1116,15 @@ static void image_change_complete(ImageWindow *imd, gdouble zoom)
                        pr = PIXBUF_RENDERER(imd->pr);
                        pr->zoom = zoom;        /* store the zoom, needed by the loader */
 
+                       /* Disable 2-pass for GIFs. Animated GIFs can flicker when enabled
+                        * Reduce quality to worst but fastest to avoid dropped frames */
+                       if (g_ascii_strcasecmp(imd->image_fd->extension, ".GIF") == 0)
+                               {
+                               g_object_set(G_OBJECT(imd->pr), "zoom_2pass", FALSE, NULL);
+                               g_object_set(G_OBJECT(imd->pr), "zoom_quality", GDK_INTERP_NEAREST, NULL);
+                               }
+
+
                        if (image_load_begin(imd, imd->image_fd))
                                {
                                imd->unknown = FALSE;
@@ -1152,12 +1188,47 @@ static gboolean image_focus_in_cb(GtkWidget *widget, GdkEventFocus *event, gpoin
 static gboolean image_scroll_cb(GtkWidget *widget, GdkEventScroll *event, gpointer data)
 {
        ImageWindow *imd = data;
+       gboolean in_lw = FALSE;
+       gint i = 0;
+       LayoutWindow *lw = NULL;
 
-       if (imd->func_scroll &&
-           event && event->type == GDK_SCROLL)
+       if (imd->func_scroll && event && event->type == GDK_SCROLL)
                {
-               imd->func_scroll(imd, event, imd->data_scroll);
-               return TRUE;
+               layout_valid(&lw);
+               /* check if the image is in a layout window */
+               for (i = 0; i < MAX_SPLIT_IMAGES; i++)
+                       {
+                       if (imd == lw->split_images[i])
+                               {
+                               in_lw = TRUE;
+                               break;
+                               }
+                       }
+
+               if (in_lw)
+                       {
+                       if (lw->options.split_pane_sync)
+                               {
+                               for (i = 0; i < MAX_SPLIT_IMAGES; i++)
+                                       {
+                                       if (lw->split_images[i])
+                                               {
+                                               layout_image_activate(lw, i, FALSE);
+                                               imd->func_scroll(lw->split_images[i], event, lw->split_images[i]->data_scroll);
+                                               }
+                                       }
+                               }
+                       else
+                               {
+                               imd->func_scroll(imd, event, imd->data_scroll);
+                               }
+                       return TRUE;
+                       }
+               else
+                       {
+                       imd->func_scroll(imd, event, imd->data_scroll);
+                       return TRUE;
+                       }
                }
 
        return FALSE;
@@ -1183,7 +1254,7 @@ void image_attach_window(ImageWindow *imd, GtkWidget *window,
 
        lw = layout_find_by_image(imd);
 
-       if (!(options->image.fit_window_to_image && lw && lw->options.tools_float)) window = NULL;
+       if (!(options->image.fit_window_to_image && lw && (lw->options.tools_float || lw->options.tools_hidden))) window = NULL;
 
        pixbuf_renderer_set_parent((PixbufRenderer *)imd->pr, (GtkWindow *)window);
 
@@ -1311,6 +1382,7 @@ GdkPixbuf *image_get_pixbuf(ImageWindow *imd)
 
 void image_change_pixbuf(ImageWindow *imd, GdkPixbuf *pixbuf, gdouble zoom, gboolean lazy)
 {
+       LayoutWindow *lw;
        StereoPixbufData stereo_data = STEREO_PIXBUF_DEFAULT;
        /* read_exif and similar functions can actually notice that the file has changed and trigger
           a notification that removes the pixbuf from cache and unrefs it. Therefore we must ref it
@@ -1326,8 +1398,16 @@ void image_change_pixbuf(ImageWindow *imd, GdkPixbuf *pixbuf, gdouble zoom, gboo
                        }
                else if (options->image.exif_rotate_enable)
                        {
-                       imd->orientation = metadata_read_int(imd->image_fd, ORIENTATION_KEY, EXIF_ORIENTATION_TOP_LEFT);
-                       imd->image_fd->exif_orientation = imd->orientation;
+                       if (g_strcmp0(imd->image_fd->format_name, "heif") == 0)
+                               {
+                               imd->orientation = EXIF_ORIENTATION_TOP_LEFT;
+                               imd->image_fd->exif_orientation = imd->orientation;
+                               }
+                       else
+                               {
+                               imd->orientation = metadata_read_int(imd->image_fd, ORIENTATION_KEY, EXIF_ORIENTATION_TOP_LEFT);
+                               imd->image_fd->exif_orientation = imd->orientation;
+                               }
                        }
                }
 
@@ -1360,9 +1440,11 @@ void image_change_pixbuf(ImageWindow *imd, GdkPixbuf *pixbuf, gdouble zoom, gboo
 
        if (pixbuf) g_object_unref(pixbuf);
 
-       if (imd->color_profile_enable)
+       /* Color correction takes too much time for an animated gif */
+       lw = layout_find_by_image(imd);
+       if (imd->color_profile_enable && lw && !lw->animation)
                {
-               image_post_process_color(imd, 0, FALSE); /* TODO: error handling */
+               image_post_process_color(imd, 0, FALSE); /** @todo error handling */
                }
 
        if (imd->cm || imd->desaturate || imd->overunderexposed)
@@ -1772,7 +1854,7 @@ static void image_notify_cb(FileData *fd, NotifyType type, gpointer data)
        if ((type & NOTIFY_REREAD) && fd == imd->image_fd)
                {
                /* there is no need to reload on NOTIFY_CHANGE,
-                  modified files should be detacted anyway and NOTIFY_REREAD should be recieved
+                  modified files should be detacted anyway and NOTIFY_REREAD should be received
                   or they are removed from the filelist completely on "move" and "delete"
                */
                DEBUG_1("Notify image: %s %04x", fd->path, type);
@@ -1806,6 +1888,12 @@ void image_background_set_color(ImageWindow *imd, GdkColor *color)
 void image_background_set_color_from_options(ImageWindow *imd, gboolean fullscreen)
 {
        GdkColor *color = NULL;
+#if GTK_CHECK_VERSION(3,0,0)
+       GdkColor theme_color;
+       GdkRGBA bg_color;
+       GtkStyleContext *style_context;
+       LayoutWindow *lw = NULL;
+#endif
 
        if ((options->image.use_custom_border_color && !fullscreen) ||
            (options->image.use_custom_border_color_in_fullscreen && fullscreen))
@@ -1813,6 +1901,22 @@ void image_background_set_color_from_options(ImageWindow *imd, gboolean fullscre
                color = &options->image.border_color;
                }
 
+#if GTK_CHECK_VERSION(3,0,0)
+       else
+               {
+               if (!layout_valid(&lw)) return;
+
+               style_context = gtk_widget_get_style_context(lw->window);
+               gtk_style_context_get_background_color(style_context, GTK_STATE_FLAG_NORMAL, &bg_color);
+
+               theme_color.red = bg_color.red * 65535;
+               theme_color.green = bg_color.green * 65535;
+               theme_color.blue = bg_color.blue * 65535;
+
+               color = &theme_color;
+               }
+#endif
+
        image_background_set_color(imd, color);
 }