Change scaling algorithm for performance

This commit is contained in:
2020-06-08 19:44:34 +02:00
parent 8272352d64
commit 4b4e1968b3
3 changed files with 10 additions and 10 deletions

View File

@@ -1,7 +1,6 @@
import strformat
# Package # Package
version = slurp("src/version") version = "0.2.0"
author = "luxick" author = "luxick"
description = "Play an image slide show from different sources" description = "Play an image slide show from different sources"
license = "GPL-2.0" license = "GPL-2.0"

View File

@@ -1,4 +1,4 @@
import os, sets, random, httpClient, json, strformat, options, deques import os, sets, random, httpClient, json, strutils, strformat, options, deques, times
import gintro/[gdkpixbuf, gobject] import gintro/[gdkpixbuf, gobject]
import common import common
@@ -53,8 +53,9 @@ proc newFileOpResult(file: string): FileOpResult =
# Utilities # Utilities
######################## ########################
proc log(ip: ImageProvider, msg: string) = proc log(ip: ImageProvider, things: varargs[string, `$`]) =
if ip.verbose: echo msg if ip.verbose:
echo things.join()
######################## ########################
# Image Provider procs # Image Provider procs
@@ -147,7 +148,10 @@ proc next*(ip: var ImageProvider, width, height: int): FileOpResult =
else: else:
w = width w = width
h = ((rawPixbuf.height * w) / rawPixbuf.width).toInt h = ((rawPixbuf.height * w) / rawPixbuf.width).toInt
var pixbuf = rawPixbuf.scaleSimple(w, h, InterpType.bilinear) let then = now()
var pixbuf = rawPixbuf.scaleSimple(w, h, InterpType.nearest)
let now = now()
ip.log "Image scaled. Time: ", (now - then).inMilliseconds, "ms"
# The pixbuf is written to disk and loaded again once because # The pixbuf is written to disk and loaded again once because
# directly setting the image from a pixbuf will leak memory # directly setting the image from a pixbuf will leak memory
let saved = pixbuf.savev(tmpFile, "png", @[]) let saved = pixbuf.savev(tmpFile, "png", @[])

View File

@@ -48,10 +48,7 @@ router randopixRouter:
proc runServer*[ServerArgs](arg: ServerArgs) {.thread, nimcall.} = proc runServer*[ServerArgs](arg: ServerArgs) {.thread, nimcall.} =
verbose = arg.verbose verbose = arg.verbose
if verbose:
logging.setLogFilter(lvlInfo) logging.setLogFilter(lvlInfo)
else:
logging.setLogFilter(lvlNotice)
let port = Port(arg.port) let port = Port(arg.port)
let settings = newSettings(port=port) let settings = newSettings(port=port)
var server = initJester(randopixRouter, settings=settings) var server = initJester(randopixRouter, settings=settings)