def _draw_image(self, at_bottom, scroll): def pixb_process(pixbuf): """ Small helper for common stuff to few pixbufs. """ if prefs['horizontal flip']: pixbuf = pixbuf.flip(horizontal=True) if prefs['vertical flip']: pixbuf = pixbuf.flip(horizontal=False) pixbuf = self.enhancer.enhance(pixbuf) return pixbuf self._waiting_for_redraw = False self._display_active_widgets() if not self.file_handler.file_loaded: return False area_width, area_height = self.get_visible_area_size() if self.zoom_mode == preferences.ZOOM_MODE_HEIGHT: scaled_width = -1 else: scaled_width = area_width if self.zoom_mode == preferences.ZOOM_MODE_WIDTH: scaled_height = -1 else: scaled_height = area_height scale_up = prefs['stretch'] self.is_virtual_double_page = \ self.file_handler.get_virtual_double_page() # TODO: If and when it becomes possible to resize (and do other things) # to PixbufAnimation objects, change these hacks to make them work # correctly. All the conditionals about animated are part of this if self.displayed_double(): left_pixbuf, right_pixbuf = self.file_handler.get_pixbufs() if self.is_manga_mode: right_pixbuf, left_pixbuf = left_pixbuf, right_pixbuf #instead of modifying returns, just do two extra calls here left_animated = isinstance(left_pixbuf, gtk.gdk.PixbufAnimation) right_animated = isinstance(right_pixbuf, gtk.gdk.PixbufAnimation) left_unscaled_x = left_pixbuf.get_width() left_unscaled_y = left_pixbuf.get_height() right_unscaled_x = right_pixbuf.get_width() right_unscaled_y = right_pixbuf.get_height() left_rotation = prefs['rotation'] right_rotation = prefs['rotation'] if prefs['auto rotate from exif']: if not left_animated: left_rotation += image.get_implied_rotation(left_pixbuf) left_rotation = left_rotation % 360 if not right_animated: right_rotation += image.get_implied_rotation(right_pixbuf) right_rotation = right_rotation % 360 if self.zoom_mode == preferences.ZOOM_MODE_MANUAL: if not left_animated and left_rotation in (90, 270): total_width = left_unscaled_y total_height = left_unscaled_x else: total_width = left_unscaled_x total_height = left_unscaled_y if not right_animated and right_rotation in (90, 270): total_width += right_unscaled_y total_height += right_unscaled_x else: total_width += right_unscaled_x total_height += right_unscaled_y total_width += 2 # For the 2 px gap between images. scaled_width = int(self._manual_zoom * total_width / 100) scaled_height = int(self._manual_zoom * total_height / 100) scale_up = True left_pixbuf, right_pixbuf = image.fit_2_in_rectangle( left_pixbuf, right_pixbuf, scaled_width, scaled_height, scale_up=scale_up, rotation1=left_rotation, rotation2=right_rotation, animated1=left_animated, animated2=right_animated) if not left_animated: pixb_process(left_pixbuf) self.left_image.set_from_pixbuf(left_pixbuf) else: self.left_image.set_from_animation(left_pixbuf) if not right_animated: pixb_process(right_pixbuf) self.right_image.set_from_pixbuf(right_pixbuf) else: self.right_image.set_from_animation(right_pixbuf) x_padding = (area_width - left_pixbuf.get_width() - right_pixbuf.get_width()) / 2 y_padding = (area_height - max(left_pixbuf.get_height(), right_pixbuf.get_height())) / 2 if not left_animated and left_rotation in (90, 270): left_scale_percent = (100.0 * left_pixbuf.get_width() / left_unscaled_y) else: left_scale_percent = (100.0 * left_pixbuf.get_width() / left_unscaled_x) if not right_animated and right_rotation in (90, 270): right_scale_percent = (100.0 * right_pixbuf.get_width() / right_unscaled_y) else: right_scale_percent = (100.0 * right_pixbuf.get_width() / right_unscaled_x) self.statusbar.set_page_number( self.file_handler.get_current_page(), self.file_handler.get_number_of_pages(), double_page=True) self.statusbar.set_resolution( (left_unscaled_x, left_unscaled_y, left_scale_percent), (right_unscaled_x, right_unscaled_y, right_scale_percent)) if prefs['smart bg']: bg_colour = image.get_most_common_edge_colour(left_pixbuf) self.set_bg_colour(bg_colour) left_filename, right_filename = \ self.file_handler.get_page_filename(double=True) if self.is_manga_mode: left_filename, right_filename = right_filename, left_filename self.statusbar.set_filename(left_filename + ', ' + right_filename) else: pixbuf = self.file_handler.get_pixbufs(single=True) #instead of modifying returns, just do an extra single call here animated = isinstance(pixbuf, gtk.gdk.PixbufAnimation) unscaled_x = pixbuf.get_width() unscaled_y = pixbuf.get_height() rotation = prefs['rotation'] if not animated and prefs['auto rotate from exif']: rotation += image.get_implied_rotation(pixbuf) rotation = rotation % 360 if self.zoom_mode == preferences.ZOOM_MODE_MANUAL: if not animated: scaled_width = int(self._manual_zoom * unscaled_x / 100) scaled_height = int(self._manual_zoom * unscaled_y / 100) if rotation in (90, 270): scaled_width, scaled_height = scaled_height, scaled_width scale_up = True pixbuf = image.fit_in_rectangle(pixbuf, scaled_width, scaled_height, scale_up=scale_up, rotation=rotation, animated=animated) if not animated: pixbuf = pixb_process(pixbuf) self.left_image.set_from_pixbuf(pixbuf) else: self.left_image.set_from_animation(pixbuf) self.right_image.clear() x_padding = (area_width - pixbuf.get_width()) / 2 y_padding = (area_height - pixbuf.get_height()) / 2 if not animated and rotation in (90, 270): scale_percent = 100.0 * pixbuf.get_width() / unscaled_y else: scale_percent = 100.0 * pixbuf.get_width() / unscaled_x self.statusbar.set_page_number( self.file_handler.get_current_page(), self.file_handler.get_number_of_pages()) self.statusbar.set_resolution( (unscaled_x, unscaled_y, scale_percent)) self.statusbar.set_filename(self.file_handler.get_page_filename()) if prefs['smart bg']: bg_colour = image.get_most_common_edge_colour(pixbuf) self.set_bg_colour(bg_colour) self._image_box.window.freeze_updates() self._main_layout.move(self._image_box, max(0, x_padding), max(0, y_padding)) self.left_image.show() if self.displayed_double(): self.right_image.show() else: self.right_image.hide() self._main_layout.set_size(*self._image_box.size_request()) if scroll: if at_bottom: self.scroll_to_fixed(horiz='endsecond', vert='bottom') else: self.scroll_to_fixed(horiz='startfirst', vert='top') self._image_box.window.thaw_updates() self.statusbar.set_root(self.file_handler.get_base_filename()) self.statusbar.update() self.update_title() while gtk.events_pending(): gtk.main_iteration(False) enhance.draw_histogram(self.left_image) self.file_handler.do_cacheing() self.thumbnailsidebar.load_thumbnails() return False
def _draw_image(self, at_bottom, scroll): def pixb_process(pixbuf): """ Small helper for common stuff to few pixbufs. """ if prefs['horizontal flip']: pixbuf = pixbuf.flip(horizontal=True) if prefs['vertical flip']: pixbuf = pixbuf.flip(horizontal=False) pixbuf = self.enhancer.enhance(pixbuf) return pixbuf self._waiting_for_redraw = False self._display_active_widgets() if not self.file_handler.file_loaded: return False area_width, area_height = self.get_visible_area_size() if self.zoom_mode == preferences.ZOOM_MODE_HEIGHT: scaled_width = -1 else: scaled_width = area_width if self.zoom_mode == preferences.ZOOM_MODE_WIDTH: scaled_height = -1 else: scaled_height = area_height scale_up = prefs['stretch'] self.is_virtual_double_page = \ self.file_handler.get_virtual_double_page() # TODO: If and when it becomes possible to resize (and do other things) # to PixbufAnimation objects, change these hacks to make them work # correctly. All the conditionals about animated are part of this if self.displayed_double(): left_pixbuf, right_pixbuf = self.file_handler.get_pixbufs() if self.is_manga_mode: right_pixbuf, left_pixbuf = left_pixbuf, right_pixbuf #instead of modifying returns, just do two extra calls here left_animated = isinstance(left_pixbuf, gtk.gdk.PixbufAnimation) right_animated = isinstance(right_pixbuf, gtk.gdk.PixbufAnimation) left_unscaled_x = left_pixbuf.get_width() left_unscaled_y = left_pixbuf.get_height() right_unscaled_x = right_pixbuf.get_width() right_unscaled_y = right_pixbuf.get_height() left_rotation = prefs['rotation'] right_rotation = prefs['rotation'] if prefs['auto rotate from exif']: if not left_animated: left_rotation += image.get_implied_rotation(left_pixbuf) left_rotation = left_rotation % 360 if not right_animated: right_rotation += image.get_implied_rotation(right_pixbuf) right_rotation = right_rotation % 360 if self.zoom_mode == preferences.ZOOM_MODE_MANUAL: if not left_animated and left_rotation in (90, 270): total_width = left_unscaled_y total_height = left_unscaled_x else: total_width = left_unscaled_x total_height = left_unscaled_y if not right_animated and right_rotation in (90, 270): total_width += right_unscaled_y total_height += right_unscaled_x else: total_width += right_unscaled_x total_height += right_unscaled_y total_width += 2 # For the 2 px gap between images. scaled_width = int(self._manual_zoom * total_width / 100) scaled_height = int(self._manual_zoom * total_height / 100) scale_up = True left_pixbuf, right_pixbuf = image.fit_2_in_rectangle( left_pixbuf, right_pixbuf, scaled_width, scaled_height, scale_up=scale_up, rotation1=left_rotation, rotation2=right_rotation, animated1=left_animated, animated2=right_animated) if not left_animated: pixb_process(left_pixbuf) self.left_image.set_from_pixbuf(left_pixbuf) else: self.left_image.set_from_animation(left_pixbuf) if not right_animated: pixb_process(right_pixbuf) self.right_image.set_from_pixbuf(right_pixbuf) else: self.right_image.set_from_animation(right_pixbuf) x_padding = (area_width - left_pixbuf.get_width() - right_pixbuf.get_width()) / 2 y_padding = (area_height - max(left_pixbuf.get_height(), right_pixbuf.get_height())) / 2 if not left_animated and left_rotation in (90, 270): left_scale_percent = (100.0 * left_pixbuf.get_width() / left_unscaled_y) else: left_scale_percent = (100.0 * left_pixbuf.get_width() / left_unscaled_x) if not right_animated and right_rotation in (90, 270): right_scale_percent = (100.0 * right_pixbuf.get_width() / right_unscaled_y) else: right_scale_percent = (100.0 * right_pixbuf.get_width() / right_unscaled_x) self.statusbar.set_page_number( self.file_handler.get_current_page(), self.file_handler.get_number_of_pages(), double_page=True) self.statusbar.set_resolution( (left_unscaled_x, left_unscaled_y, left_scale_percent), (right_unscaled_x, right_unscaled_y, right_scale_percent)) if prefs['smart bg']: bg_colour = image.get_most_common_edge_colour(left_pixbuf) self.set_bg_colour(bg_colour) left_filename, right_filename = \ self.file_handler.get_page_filename(double=True) if self.is_manga_mode: left_filename, right_filename = right_filename, left_filename self.statusbar.set_filename(left_filename + ', ' + right_filename) else: pixbuf = self.file_handler.get_pixbufs(single=True) #instead of modifying returns, just do an extra single call here animated = isinstance(pixbuf, gtk.gdk.PixbufAnimation) unscaled_x = pixbuf.get_width() unscaled_y = pixbuf.get_height() rotation = prefs['rotation'] if not animated and prefs['auto rotate from exif']: rotation += image.get_implied_rotation(pixbuf) rotation = rotation % 360 if self.zoom_mode == preferences.ZOOM_MODE_MANUAL: if not animated: scaled_width = int(self._manual_zoom * unscaled_x / 100) scaled_height = int(self._manual_zoom * unscaled_y / 100) if rotation in (90, 270): scaled_width, scaled_height = scaled_height, scaled_width scale_up = True pixbuf = image.fit_in_rectangle(pixbuf, scaled_width, scaled_height, scale_up=scale_up, rotation=rotation, animated=animated) if not animated: pixbuf = pixb_process(pixbuf) self.left_image.set_from_pixbuf(pixbuf) else: self.left_image.set_from_animation(pixbuf) self.right_image.clear() x_padding = (area_width - pixbuf.get_width()) / 2 y_padding = (area_height - pixbuf.get_height()) / 2 if not animated and rotation in (90, 270): scale_percent = 100.0 * pixbuf.get_width() / unscaled_y else: scale_percent = 100.0 * pixbuf.get_width() / unscaled_x self.statusbar.set_page_number( self.file_handler.get_current_page(), self.file_handler.get_number_of_pages()) self.statusbar.set_resolution((unscaled_x, unscaled_y, scale_percent)) self.statusbar.set_filename(self.file_handler.get_page_filename()) if prefs['smart bg']: bg_colour = image.get_most_common_edge_colour(pixbuf) self.set_bg_colour(bg_colour) self._image_box.window.freeze_updates() self._main_layout.move(self._image_box, max(0, x_padding), max(0, y_padding)) self.left_image.show() if self.displayed_double(): self.right_image.show() else: self.right_image.hide() self._main_layout.set_size(*self._image_box.size_request()) if scroll: if at_bottom: self.scroll_to_fixed(horiz='endsecond', vert='bottom') else: self.scroll_to_fixed(horiz='startfirst', vert='top') self._image_box.window.thaw_updates() self.statusbar.set_root(self.file_handler.get_base_filename()) self.statusbar.update() self.update_title() while gtk.events_pending(): gtk.main_iteration(False) enhance.draw_histogram(self.left_image) self.file_handler.do_cacheing() self.thumbnailsidebar.load_thumbnails() return False
def _add_subpixbuf(self, canvas, x, y, image_size, source_pixbuf, other_image_width=0, left=True): """Copy a subpixbuf from <source_pixbuf> to <canvas> as it should be in the lens if the coordinates <x>, <y> are the mouse pointer position on the main window layout area. The displayed image (scaled from the <source_pixbuf>) must have size <image_size>. If <other_image_width> is given, it is the width of the "other" image in double page mode. The image we are getting the coordinates for is the left one unless <left> is False. """ area_x, area_y = self._window.get_visible_area_size() if left: padding_x = max(0, (area_x - other_image_width - image_size[0]) // 2) else: padding_x = \ (max(0, (area_x - other_image_width - image_size[0]) // 2) + other_image_width + 2) padding_y = max(0, (area_y - image_size[1]) // 2) x -= padding_x y -= padding_y rotation = prefs['rotation'] if prefs['auto rotate from exif']: rotation += image.get_implied_rotation(source_pixbuf) rotation = rotation % 360 if rotation in [90, 270]: scale = float(source_pixbuf.get_height()) / image_size[0] else: scale = float(source_pixbuf.get_width()) / image_size[0] x *= scale y *= scale source_mag = prefs['lens magnification'] / scale width = prefs['lens size'] / source_mag height = width paste_left = x > width / 2 paste_top = y > height / 2 dest_x = max(0, int(math.ceil((width / 2 - x) * source_mag))) dest_y = max(0, int(math.ceil((height / 2 - y) * source_mag))) if rotation == 90: x, y = y, source_pixbuf.get_height() - x elif rotation == 180: x = source_pixbuf.get_width() - x y = source_pixbuf.get_height() - y elif rotation == 270: x, y = source_pixbuf.get_width() - y, x if prefs['horizontal flip']: if rotation in (90, 270): y = source_pixbuf.get_height() - y else: x = source_pixbuf.get_width() - x if prefs['vertical flip']: if rotation in (90, 270): x = source_pixbuf.get_width() - x else: y = source_pixbuf.get_height() - y src_x = x - width / 2 src_y = y - height / 2 if src_x < 0: width += src_x src_x = 0 if src_y < 0: height += src_y src_y = 0 width = max(0, min(source_pixbuf.get_width() - src_x, width)) height = max(0, min(source_pixbuf.get_height() - src_y, height)) if width < 1 or height < 1: return subpixbuf = source_pixbuf.subpixbuf(int(src_x), int(src_y), int(width), int(height)) subpixbuf = subpixbuf.scale_simple( int(math.ceil(source_mag * subpixbuf.get_width())), int(math.ceil(source_mag * subpixbuf.get_height())), gtk.gdk.INTERP_TILES) if rotation == 90: subpixbuf = subpixbuf.rotate_simple( gtk.gdk.PIXBUF_ROTATE_CLOCKWISE) elif rotation == 180: subpixbuf = subpixbuf.rotate_simple( gtk.gdk.PIXBUF_ROTATE_UPSIDEDOWN) elif rotation == 270: subpixbuf = subpixbuf.rotate_simple( gtk.gdk.PIXBUF_ROTATE_COUNTERCLOCKWISE) if prefs['horizontal flip']: subpixbuf = subpixbuf.flip(horizontal=True) if prefs['vertical flip']: subpixbuf = subpixbuf.flip(horizontal=False) if paste_left: dest_x = 0 else: dest_x = min(canvas.get_width() - subpixbuf.get_width(), dest_x) if paste_top: dest_y = 0 else: dest_y = min(canvas.get_height() - subpixbuf.get_height(), dest_y) subpixbuf.copy_area(0, 0, subpixbuf.get_width(), subpixbuf.get_height(), canvas, dest_x, dest_y)
def _draw_image(self, at_bottom, scroll): self._waiting_for_redraw = False self._display_active_widgets() if not self.file_handler.file_loaded: return False area_width, area_height = self.get_visible_area_size() if self.zoom_mode == preferences.ZOOM_MODE_HEIGHT: scaled_width = -1 else: scaled_width = area_width if self.zoom_mode == preferences.ZOOM_MODE_WIDTH: scaled_height = -1 else: scaled_height = area_height scale_up = prefs["stretch"] self.is_virtual_double_page = self.file_handler.get_virtual_double_page() if self.displayed_double(): left_pixbuf, right_pixbuf = self.file_handler.get_pixbufs() if self.is_manga_mode: right_pixbuf, left_pixbuf = left_pixbuf, right_pixbuf left_unscaled_x = left_pixbuf.get_width() left_unscaled_y = left_pixbuf.get_height() right_unscaled_x = right_pixbuf.get_width() right_unscaled_y = right_pixbuf.get_height() left_rotation = prefs["rotation"] right_rotation = prefs["rotation"] if prefs["auto rotate from exif"]: left_rotation += image.get_implied_rotation(left_pixbuf) left_rotation = left_rotation % 360 right_rotation += image.get_implied_rotation(right_pixbuf) right_rotation = right_rotation % 360 if self.zoom_mode == preferences.ZOOM_MODE_MANUAL: if left_rotation in (90, 270): total_width = left_unscaled_y total_height = left_unscaled_x else: total_width = left_unscaled_x total_height = left_unscaled_y if right_rotation in (90, 270): total_width += right_unscaled_y total_height += right_unscaled_x else: total_width += right_unscaled_x total_height += right_unscaled_y total_width += 2 # For the 2 px gap between images. scaled_width = int(self._manual_zoom * total_width / 100) scaled_height = int(self._manual_zoom * total_height / 100) scale_up = True left_pixbuf, right_pixbuf = image.fit_2_in_rectangle( left_pixbuf, right_pixbuf, scaled_width, scaled_height, scale_up=scale_up, rotation1=left_rotation, rotation2=right_rotation, ) if prefs["horizontal flip"]: left_pixbuf = left_pixbuf.flip(horizontal=True) right_pixbuf = right_pixbuf.flip(horizontal=True) if prefs["vertical flip"]: left_pixbuf = left_pixbuf.flip(horizontal=False) right_pixbuf = right_pixbuf.flip(horizontal=False) left_pixbuf = self.enhancer.enhance(left_pixbuf) right_pixbuf = self.enhancer.enhance(right_pixbuf) self.left_image.set_from_pixbuf(left_pixbuf) self.right_image.set_from_pixbuf(right_pixbuf) x_padding = (area_width - left_pixbuf.get_width() - right_pixbuf.get_width()) / 2 y_padding = (area_height - max(left_pixbuf.get_height(), right_pixbuf.get_height())) / 2 if left_rotation in (90, 270): left_scale_percent = 100.0 * left_pixbuf.get_width() / left_unscaled_y else: left_scale_percent = 100.0 * left_pixbuf.get_width() / left_unscaled_x if right_rotation in (90, 270): right_scale_percent = 100.0 * right_pixbuf.get_width() / right_unscaled_y else: right_scale_percent = 100.0 * right_pixbuf.get_width() / right_unscaled_x self.statusbar.set_page_number( self.file_handler.get_current_page(), self.file_handler.get_number_of_pages(), double_page=True ) self.statusbar.set_resolution( (left_unscaled_x, left_unscaled_y, left_scale_percent), (right_unscaled_x, right_unscaled_y, right_scale_percent), ) left_filename, right_filename = self.file_handler.get_page_filename(double=True) if self.is_manga_mode: left_filename, right_filename = right_filename, left_filename self.statusbar.set_filename(left_filename + ", " + right_filename) else: pixbuf = self.file_handler.get_pixbufs(single=True) unscaled_x = pixbuf.get_width() unscaled_y = pixbuf.get_height() rotation = prefs["rotation"] if prefs["auto rotate from exif"]: rotation += image.get_implied_rotation(pixbuf) rotation = rotation % 360 if self.zoom_mode == preferences.ZOOM_MODE_MANUAL: scaled_width = int(self._manual_zoom * unscaled_x / 100) scaled_height = int(self._manual_zoom * unscaled_y / 100) if rotation in (90, 270): scaled_width, scaled_height = scaled_height, scaled_width scale_up = True pixbuf = image.fit_in_rectangle(pixbuf, scaled_width, scaled_height, scale_up=scale_up, rotation=rotation) if prefs["horizontal flip"]: pixbuf = pixbuf.flip(horizontal=True) if prefs["vertical flip"]: pixbuf = pixbuf.flip(horizontal=False) pixbuf = self.enhancer.enhance(pixbuf) self.left_image.set_from_pixbuf(pixbuf) self.right_image.clear() x_padding = (area_width - pixbuf.get_width()) / 2 y_padding = (area_height - pixbuf.get_height()) / 2 if rotation in (90, 270): scale_percent = 100.0 * pixbuf.get_width() / unscaled_y else: scale_percent = 100.0 * pixbuf.get_width() / unscaled_x self.statusbar.set_page_number( self.file_handler.get_current_page(), self.file_handler.get_number_of_pages() ) self.statusbar.set_resolution((unscaled_x, unscaled_y, scale_percent)) self.statusbar.set_filename(self.file_handler.get_page_filename()) if prefs["smart bg"]: bg_colour = image.get_most_common_edge_colour(self.left_image.get_pixbuf()) self.set_bg_colour(bg_colour) self._image_box.get_window().freeze_updates() self._main_layout.move(self._image_box, max(0, x_padding), max(0, y_padding)) self.left_image.show() if self.displayed_double(): self.right_image.show() else: self.right_image.hide() self._main_layout.set_size(self._image_box.size_request().width, self._image_box.size_request().height) if scroll: if at_bottom: self.scroll_to_fixed(horiz="endsecond", vert="bottom") else: self.scroll_to_fixed(horiz="startfirst", vert="top") self._image_box.get_window().thaw_updates() self.statusbar.set_root(self.file_handler.get_base_filename()) self.statusbar.update() self.update_title() while Gtk.events_pending(): Gtk.main_iteration_do(False) enhance.draw_histogram(self.left_image) self.file_handler.do_cacheing() self.thumbnailsidebar.load_thumbnails() return False
def _draw_image(self, at_bottom, scroll): self._waiting_for_redraw = False self._display_active_widgets() if not self.file_handler.file_loaded: return False area_width, area_height = self.get_visible_area_size() if self.zoom_mode == preferences.ZOOM_MODE_HEIGHT: scaled_width = -1 else: scaled_width = area_width if self.zoom_mode == preferences.ZOOM_MODE_WIDTH: scaled_height = -1 else: scaled_height = area_height scale_up = prefs['stretch'] self.is_virtual_double_page = \ self.file_handler.get_virtual_double_page() if self.displayed_double(): left_pixbuf, right_pixbuf = self.file_handler.get_pixbufs() if self.is_manga_mode: right_pixbuf, left_pixbuf = left_pixbuf, right_pixbuf left_unscaled_x = left_pixbuf.get_width() left_unscaled_y = left_pixbuf.get_height() right_unscaled_x = right_pixbuf.get_width() right_unscaled_y = right_pixbuf.get_height() left_rotation = prefs['rotation'] right_rotation = prefs['rotation'] if prefs['auto rotate from exif']: left_rotation += image.get_implied_rotation(left_pixbuf) left_rotation = left_rotation % 360 right_rotation += image.get_implied_rotation(right_pixbuf) right_rotation = right_rotation % 360 if self.zoom_mode == preferences.ZOOM_MODE_MANUAL: if left_rotation in (90, 270): total_width = left_unscaled_y total_height = left_unscaled_x else: total_width = left_unscaled_x total_height = left_unscaled_y if right_rotation in (90, 270): total_width += right_unscaled_y total_height += right_unscaled_x else: total_width += right_unscaled_x total_height += right_unscaled_y total_width += 2 # For the 2 px gap between images. scaled_width = int(self._manual_zoom * total_width / 100) scaled_height = int(self._manual_zoom * total_height / 100) scale_up = True left_pixbuf, right_pixbuf = image.fit_2_in_rectangle( left_pixbuf, right_pixbuf, scaled_width, scaled_height, scale_up=scale_up, rotation1=left_rotation, rotation2=right_rotation) if prefs['horizontal flip']: left_pixbuf = left_pixbuf.flip(horizontal=True) right_pixbuf = right_pixbuf.flip(horizontal=True) if prefs['vertical flip']: left_pixbuf = left_pixbuf.flip(horizontal=False) right_pixbuf = right_pixbuf.flip(horizontal=False) left_pixbuf = self.enhancer.enhance(left_pixbuf) right_pixbuf = self.enhancer.enhance(right_pixbuf) self.left_image.set_from_pixbuf(left_pixbuf) self.right_image.set_from_pixbuf(right_pixbuf) x_padding = (area_width - left_pixbuf.get_width() - right_pixbuf.get_width()) / 2 y_padding = (area_height - max(left_pixbuf.get_height(), right_pixbuf.get_height())) / 2 if left_rotation in (90, 270): left_scale_percent = (100.0 * left_pixbuf.get_width() / left_unscaled_y) else: left_scale_percent = (100.0 * left_pixbuf.get_width() / left_unscaled_x) if right_rotation in (90, 270): right_scale_percent = (100.0 * right_pixbuf.get_width() / right_unscaled_y) else: right_scale_percent = (100.0 * right_pixbuf.get_width() / right_unscaled_x) self.statusbar.set_page_number( self.file_handler.get_current_page(), self.file_handler.get_number_of_pages(), double_page=True) self.statusbar.set_resolution( (left_unscaled_x, left_unscaled_y, left_scale_percent), (right_unscaled_x, right_unscaled_y, right_scale_percent)) left_filename, right_filename = \ self.file_handler.get_page_filename(double=True) if self.is_manga_mode: left_filename, right_filename = right_filename, left_filename self.statusbar.set_filename(left_filename + ', ' + right_filename) else: pixbuf = self.file_handler.get_pixbufs(single=True) unscaled_x = pixbuf.get_width() unscaled_y = pixbuf.get_height() rotation = prefs['rotation'] if prefs['auto rotate from exif']: rotation += image.get_implied_rotation(pixbuf) rotation = rotation % 360 if self.zoom_mode == preferences.ZOOM_MODE_MANUAL: scaled_width = int(self._manual_zoom * unscaled_x / 100) scaled_height = int(self._manual_zoom * unscaled_y / 100) if rotation in (90, 270): scaled_width, scaled_height = scaled_height, scaled_width scale_up = True pixbuf = image.fit_in_rectangle(pixbuf, scaled_width, scaled_height, scale_up=scale_up, rotation=rotation) if prefs['horizontal flip']: pixbuf = pixbuf.flip(horizontal=True) if prefs['vertical flip']: pixbuf = pixbuf.flip(horizontal=False) pixbuf = self.enhancer.enhance(pixbuf) self.left_image.set_from_pixbuf(pixbuf) self.right_image.clear() x_padding = (area_width - pixbuf.get_width()) / 2 y_padding = (area_height - pixbuf.get_height()) / 2 if rotation in (90, 270): scale_percent = 100.0 * pixbuf.get_width() / unscaled_y else: scale_percent = 100.0 * pixbuf.get_width() / unscaled_x self.statusbar.set_page_number( self.file_handler.get_current_page(), self.file_handler.get_number_of_pages()) self.statusbar.set_resolution((unscaled_x, unscaled_y, scale_percent)) self.statusbar.set_filename(self.file_handler.get_page_filename()) if prefs['smart bg']: bg_colour = image.get_most_common_edge_colour( self.left_image.get_pixbuf()) self.set_bg_colour(bg_colour) self._image_box.window.freeze_updates() self._main_layout.move(self._image_box, max(0, x_padding), max(0, y_padding)) self.left_image.show() if self.displayed_double(): self.right_image.show() else: self.right_image.hide() self._main_layout.set_size(*self._image_box.size_request()) if scroll: if at_bottom: self.scroll_to_fixed(horiz='endsecond', vert='bottom') else: self.scroll_to_fixed(horiz='startfirst', vert='top') self._image_box.window.thaw_updates() self.statusbar.set_root(self.file_handler.get_base_filename()) self.statusbar.update() self.update_title() while gtk.events_pending(): gtk.main_iteration(False) enhance.draw_histogram(self.left_image) self.file_handler.do_cacheing() self.thumbnailsidebar.load_thumbnails() return False