Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Little Jim

macrumors newbie
Original poster
Nov 13, 2020
12
4
Hi guys,
Although use Mac/Pc for quite a while, until now I still doesn't get this fact. Let say I have a 4k monitor and a video that is in 5k. To make my querry simple, let just narrow the perspective in to the horizontal size, or even more narrower, let look at the pixels line at the buttom, ok?
So 4k will have 3840 pixels at the button, and 5k video will have 5120 pixels.
My query is how could the monitor can allocating those 3840 pixels to present 5120 pixels?
Let consider 3840 pixels is like 38 color lamp bulbs. 5120 pixels is like the command to switch 51 bulbs to present 51 different colors.
How the hell 38 lamp bulbs always successfully in satisfying that 51 commands?
Would some one explain it for me?
Thank you guys.
 
Last edited:
The simplest method is to take 38 of the 51 light bulbs evenly spread out. The algorithm doesn't require floating point calculations or even the division operator - it can be done using integers with just the addition and subtraction operators, similar to the algorithm that uses only integer arithmetic to draw a line.
see https://en.wikipedia.org/wiki/Bresenham's_line_algorithm
and https://en.wikipedia.org/wiki/Digital_differential_analyzer_(graphics_algorithm)
This method just throws away some of the pixels which might not look very good.

Let's say x is the destination light bulb 0 to 37.
y is the source light bulb 0 to 50.
You want to make a line from 0,0 to 37,50.
The slope of the line is greater than 1 and less than 2 which means for each X, Y will go up by either 1 or 2.
The reciprocal of the slope is 0.745. This is slightly less than 3/4 (2.98/4) which means that y will usually increase by 4 when X increases by 3 but sometimes Y increases by 3 when X increases by 2.

You can run this code in Terminal.app:
Code:
maxx=38
maxy=51
((fraction=(maxy>>1)))
y=0
for ((x = 0; x < maxx; x++)); do
    echo "$x -> $y"
    while ((fraction < maxy)); do
        ((y++))
        ((fraction += maxx))
    done
    ((fraction -= maxy))
done

The result is like this (I added an extra line where Y increased by 2):
Code:
0 -> 0
1 -> 1

2 -> 3
3 -> 4
4 -> 5

5 -> 7
6 -> 8
7 -> 9

8 -> 11
9 -> 12
10 -> 13

11 -> 15
12 -> 16
13 -> 17

14 -> 19
15 -> 20
16 -> 21

17 -> 23
18 -> 24
19 -> 25

20 -> 27
21 -> 28
22 -> 29

23 -> 31
24 -> 32
25 -> 33

26 -> 35
27 -> 36
28 -> 37

29 -> 39
30 -> 40
31 -> 41

32 -> 43
33 -> 44
34 -> 45

35 -> 47
36 -> 48
37 -> 49


Then there are more complicated methods that produce a higher quality, more accurate image (each destination pixel may depend on multiple source pixels): https://en.wikipedia.org/wiki/Image_scaling
 
Last edited:
  • Like
Reactions: Little Jim
Thank a lot Joevt for your very precisely technical explain. Now I totally understand the mechanism of all the pixels. So instead of perceive the command as "switch 51 bulbs to present 51 different colors", we should perceived as "calculating to decide which colors for 38 lamp bulbs".
Thank you a lot Joevt.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.