diff options
| author | Tim Keller <tjkeller.xyz> | 2025-05-09 21:58:54 -0500 |
|---|---|---|
| committer | Tim Keller <tjkeller.xyz> | 2025-05-09 21:58:54 -0500 |
| commit | 145de3311cb9f32ac0bc9842b0600fcad84fed16 (patch) | |
| tree | 2822a41929eac3758d0ffe7a7d1b8cf49158a09e /pix.py | |
| parent | b487f62ba7cd7dbbcadb2b5704ec1c99f6578390 (diff) | |
| download | immich-frame-145de3311cb9f32ac0bc9842b0600fcad84fed16.tar.xz immich-frame-145de3311cb9f32ac0bc9842b0600fcad84fed16.zip | |
add support for downloading new images from immich api on a separate thread
Diffstat (limited to 'pix.py')
| -rw-r--r-- | pix.py | 97 |
1 files changed, 14 insertions, 83 deletions
@@ -1,89 +1,20 @@ import sys -from OpenGL.GL import * -from OpenGL.GLUT import * -from OpenGL.GLU import * -from PIL import Image -from time import time +from threading import Thread -from transition import Transition - -display_time = 2.0 -transition_duration = 0.5 - -# Load image as a texture using PIL -def load_texture(image_path): - img = Image.open(image_path) - img = img.convert("RGBA") # Ensure the image is in RGBA mode (4 channels: R, G, B, A) - img_data = img.tobytes("raw", "RGBA", 0, -1) # Convert image data to bytes - - texture_id = glGenTextures(1) - glBindTexture(GL_TEXTURE_2D, texture_id) - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, img.width, img.height, 0, GL_RGBA, GL_UNSIGNED_BYTE, img_data) - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR) - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR) - return texture_id - -# Main display function -transition = Transition() -def display(): - global start_time, image_time, last_time, alpha, texture_id1, texture_id2 - - current_time = time() - alive_time = current_time - start_time - delta_time = current_time - last_time - last_time = current_time - image_time += delta_time - - if (image_time < display_time): - return - - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) - glLoadIdentity() - - # Get window size - window_width, window_height = glutGet(GLUT_WINDOW_WIDTH), glutGet(GLUT_WINDOW_HEIGHT) - - # DRAW - transition_time = image_time - display_time - complete = transition.draw(texture_id1, texture_id2, window_width, window_height, delta_time, transition_time, transition_duration) - - glClearColor(0.0, 0.0, 0.0, 1.0) # Set the background color to black - - glutSwapBuffers() - - if (complete): - image_time = 0 - texture_id1, texture_id2 = texture_id2, texture_id1 - -# Initialization and main loop -def main(): - global texture_id1, texture_id2, alpha, last_time, start_time, image_time - - # Initialize the window - glutInit(sys.argv) - glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB) - glutCreateWindow("Image Viewer with Fade Transition") - glEnable(GL_TEXTURE_2D) +from window import PixDisplay +from immich import ImmichConnector +def load_textures(pd): # Load two images for transition - texture_id1 = load_texture("image1.jpg") - texture_id2 = load_texture("image2.jpg") - - alpha = 0.0 # Start with fully transparent - image_time = 0 - start_time = time() - last_time = time() - - # Set up the OpenGL viewport and projection - glMatrixMode(GL_PROJECTION) - glLoadIdentity() - glOrtho(-1, 1, -1, 1, -1, 1) - glMatrixMode(GL_MODELVIEW) - - glutDisplayFunc(display) - glutIdleFunc(display) - glutMainLoop() + tex = ImageTexture("image1.jpg") + pd.textures.append(tex) + tex = ImageTexture("image2.jpg") + pd.textures.append(tex) if __name__ == "__main__": - main() - + immichConnector = ImmichConnector("http://192.168.1.13", "m5nqOoBc4uhAba21gZdCP3z8D3JT4GPxDXL2psd52EA") + pd = PixDisplay() + #t1 = Thread(target=load_textures, daemon=True, args=(pd,)) + t1 = Thread(target=immichConnector.idle, daemon=True, args=(pd,)) + t1.start() + pd.main() |
