erkexzcx / valetudopng

A Valetudo map renderer (ex Hypfer/ICantBelieveItsNotValetudo) for Home Assistant.
https://valetudo.cloud/
Apache License 2.0
42 stars 6 forks source link

Use scale as float #8

Closed tylla closed 9 months ago

tylla commented 10 months ago

Scale should be treated as a float during all calculations.

erkexzcx commented 9 months ago

What does this PR fix? I mean it looks nicer, but does it fix anything?

tylla commented 9 months ago

Yep, it does! :) Being able to scale the image to some fractional value. Currently for example if I specify a scale = 4.2 it doesn't take into account as it gets converted into integer before the real math takes place.

erkexzcx commented 9 months ago

if I specify a scale = 4.2 it doesn't take into account as it gets converted into integer before the real math takes place.

Actually I can't implement such fractional scaling due to the way map is being scaled up.

Let's say your original (scale of 1x) map looks like this (2x2, 4 pixels):

A B
C D

If you use scale of 2 - it would be upscaled like this (4x4, 16 pixels):

A A B B
A A B B
C C D D
C C D D

First, I draw a map with a scale of 1, then I upscale it by above logic. Everything is multi-threaded, for performance reasons and the problem is that I don't know how I would do it with fractional scaling. And I am pretty sure it would look fairly bad if fractional scaling is used - performance loss as well as blurry picture. So I simply cannot do fractional scaling due to the way map is being upscaled.

I still think that this PR would not do anything. Or am I still wrong? :sweat_smile:

tylla commented 9 months ago

Sorry for the late reply I was quite busy.

I wasn't aware that the code does such simple upscale, I thought it does some proper scaling. Yes, that could possibly bring some blurryness, but this should be tolerated. Btw. maybe the scaling should be left to the browser, by quickly generating the simpler (or bigger) image and simply specifying the width/height of the image it should be presented. The browsers have some quite optimized image scale codes. This would have the added benefit, that devices with higher pixel density could present a sharper, more detailed map. Maybe I should extract this idea as a new feature request?! :)

So in the end, yes, given the current code, this PR wouldn't do anything noticeable. :)