diff options
| author | Tim Keller <tjkeller.xyz> | 2025-05-06 21:17:38 -0500 |
|---|---|---|
| committer | Tim Keller <tjkeller.xyz> | 2025-05-06 21:17:38 -0500 |
| commit | b487f62ba7cd7dbbcadb2b5704ec1c99f6578390 (patch) | |
| tree | d4b9152f942dfca9a4cbc3e4b1b618e199c7cd4a /transition.py | |
| download | immich-frame-b487f62ba7cd7dbbcadb2b5704ec1c99f6578390.tar.xz immich-frame-b487f62ba7cd7dbbcadb2b5704ec1c99f6578390.zip | |
initial commit
Diffstat (limited to 'transition.py')
| -rw-r--r-- | transition.py | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/transition.py b/transition.py new file mode 100644 index 0000000..cf2acb4 --- /dev/null +++ b/transition.py @@ -0,0 +1,67 @@ +from OpenGL.GL import * +from OpenGL.GLUT import * +from OpenGL.GLU import * + +class Transition: + def draw(self, texture_prev, texture_next, window_width, window_height, delta_time, transition_time, transition_duration): + # Update alpha value for fade effect + alpha = transition_time / transition_duration + if alpha > 1.0: + alpha = 1.0 + + # Draw the first image + self._draw_image(texture_prev, 3840, 2160, window_width, window_height, 1 - alpha) # TODO instead of decreasing alpha, draw transparent letterboxes + # Draw the second image (with transparency) + self._draw_image(texture_next, 3840, 2160, window_width, window_height, alpha) + + return alpha >= 1.0 # Complete + + + + # Draw the image with blending enabled (to allow fade effect) + def _draw_image(self, texture_id, img_width, img_height, window_width, window_height, alpha): + if (not alpha): return + + glEnable(GL_BLEND) + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) + glBindTexture(GL_TEXTURE_2D, texture_id) + glColor4f(1.0, 1.0, 1.0, alpha) # Set alpha to control transparency + + # Calculate aspect ratio + img_aspect = img_width / float(img_height) + win_aspect = window_width / float(window_height) + + scaled_width = window_width + scaled_height = window_height + + # Scale the image to fit inside the window while maintaining aspect ratio + if img_aspect > win_aspect: + # Image is wider than window, letterbox vertically + scaled_height = window_width / img_aspect + else: + # Image is taller than window, letterbox horizontally + scaled_width = window_height * img_aspect + + # Position the image so it is centered + offset_x = (window_width - scaled_width) / 2 + offset_y = (window_height - scaled_height) / 2 + + # Normalize coordinates to range from -1 to 1 + x1 = (offset_x / window_width ) * 2 - 1 + y1 = (offset_y / window_height) * 2 - 1 + x2 = ((offset_x + scaled_width ) / window_width ) * 2 - 1 + y2 = ((offset_y + scaled_height) / window_height) * 2 - 1 + + # Draw the image in the center with scaling + glBegin(GL_QUADS) + glTexCoord2f(0, 0) + glVertex2f(x1, y1) + glTexCoord2f(1, 0) + glVertex2f(x2, y1) + glTexCoord2f(1, 1) + glVertex2f(x2, y2) + glTexCoord2f(0, 1) + glVertex2f(x1, y2) + glEnd() + + glDisable(GL_BLEND) |
