summaryrefslogtreecommitdiff
path: root/transition.py
diff options
context:
space:
mode:
authorTim Keller <tjkeller.xyz>2025-05-10 11:52:02 -0500
committerTim Keller <tjkeller.xyz>2025-05-10 11:52:02 -0500
commit2bd4da7678b027843cac1a03a1b5f6cc70a7cc81 (patch)
treeea6a10a1a4a7c6ba355982697918d6bc6a0d94a3 /transition.py
parent568a87f44a674276e6e55f9302cc9e44a0929f71 (diff)
downloadimmich-frame-2bd4da7678b027843cac1a03a1b5f6cc70a7cc81.tar.xz
immich-frame-2bd4da7678b027843cac1a03a1b5f6cc70a7cc81.zip
requirements.txt added, significantly reduced cpu usage using timer func and vertex/fragment shader instead of drawing new quad etc every frame
Diffstat (limited to 'transition.py')
-rw-r--r--transition.py67
1 files changed, 0 insertions, 67 deletions
diff --git a/transition.py b/transition.py
deleted file mode 100644
index a076889..0000000
--- a/transition.py
+++ /dev/null
@@ -1,67 +0,0 @@
-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, 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, 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, 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 = texture.width / float(texture.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)