Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TV Emulation doesn't have accurate colors #502

Open
1 task
Michaelangel007 opened this issue Oct 25, 2017 · 9 comments
Open
1 task

TV Emulation doesn't have accurate colors #502

Michaelangel007 opened this issue Oct 25, 2017 · 9 comments
Assignees

Comments

@Michaelangel007
Copy link
Contributor

Michaelangel007 commented Oct 25, 2017

Spun off from #357

Source

#254 Gives this program

10 HGR
20 FOR Y=0 TO 63:FOR X=0 TO 7
30 HCOLOR=INT(Y/8)
31 HPLOT X*32,Y*2 TO X*32+30,Y*2
32 HCOLOR=X
33 HPLOT X*32,Y*2+1 TO X*32+30,Y*2+1
40 NEXT:NEXT

1.25

1.25 Monitor mode:
1 25 hgr monitor 64colors

1.25 TV mode:

1 25 hgr tv 64colors

1.26

1.26 Monitor mode:

1 26 hgr monitor 64colors

1.26 TV mode

1 26 hgr tv 64colors

Real TV

On a real TV green + orange look yellow, matching 1.25 more:

real_tv

Notes:

@Michaelangel007
Copy link
Contributor Author

Michaelangel007 commented Oct 25, 2017

Source 2a

Let's explicitly render these 14 "fake" HGR colors sorted by hue:

1 GOTO 10
2 X=I*14:Y=J*16
3 FOR V=0 TO 7:T=Y+V*2
4 HCOLOR=A:HPLOT X,T TO X+13,T
5 IF S=1 THEN 9
6 HCOLOR=B:HPLOT X,T+1 TO X+13,T+1
7 HCOLOR=A:HPLOT X,T+40 TO X+11,T+40
8 HCOLOR=B:HPLOT X,T+72 TO X+11,T+72
9 NEXT:I=I+1:RETURN
10 HGR:S=1
20 A=5:B=0:I=2:J=0:GOSUB 2
30 A=1:I=5:GOSUB 2
40 A=6:I=8:GOSUB 2
50 A=2:I=11:GOSUB 2
60 A=3:B=3:I=13:GOSUB 2
70 I=0:J=1:S=0
80 A=2:B=5:GOSUB 2
90 A=5:B=7:GOSUB 2
100 A=5:B=5:GOSUB 2:REM ORANGE
110 A=5:B=1:GOSUB 2:REM yellow
120 A=1:B=3:GOSUB 2
130 A=1:B=1:GOSUB 2:REM GREEN
140 A=6:B=1:GOSUB 2
150 A=6:B=7:GOSUB 2
160 A=6:B=6:GOSUB 2:REM BLUE
170 A=6:B=2:GOSUB 2
180 A=2:B=7:GOSUB 2
190 A=2:B=2:GOSUB 2:REM MAGENTA
200 A=1:B=2:GOSUB 2:REM gray
210 A=3:B=3:GOSUB 2:REM WHITE
220 HCOLOR=3
230 FOR I=0 TO 13
240 HPLOT I*14+6,40 TO I*14+10,40
250 HPLOT I*14+6,42 TO I*14+10,42
260 HPLOT I*14+6,76 TO I*14+6,80
270 HPLOT I*14+4,78 TO I*14+8,78
280 NEXT

1.25 TV mode

1 25 hgr tv 14colors

1.26 TV mode

1 26 hgr tv 14colors

The vertical mixing of two adjacent scanlines looks worse in 1.26 then 1.25.

Now instead of having a full 256*256 lookup table, we should be able to get with a much smaller table.Why? If we treat the HGR screen as only producing the valid 16 GR / DHGR colors we only need to have a [16][16] mixing table.

We still need to work out how the bits need to be mixed. i.e. Do we take the top 4 bits of RGB ?

Solutions

We can either:

  • pre-process in YIQ space
  • process-in-place in 4-bit / 12-bit space
  • post-process this in RGB space

Which one is more accurate vs faster is TBD.

@Michaelangel007
Copy link
Contributor Author

Michaelangel007 commented Oct 25, 2017

Updated all images to be correct.

TL:DR;

  • 1.25 TV mode colors are TOO solid
  • 1.26 TV mode colors are TOO pixelated

For 1.27 we want to aim more in the middle.

Unanswered questions:

  • Can we just scan-double the output lines once we have the correct blended line?
  • Can we just do a linear (line1+line2)/2 and replicate to both lines?
  • Can we use a 3-way tap three times??

Let's suppose we want to generate TV mode for lines N, and N+1

N-1| line 0 | A 
N+0| line 1 | B  \ TV mode mixing
N+1| line 2 | C  / TV mode mixing
N+2| line 3 | D

Does it blend? There are multiple ways we can blend:

Blend 1

line 1 = (A + B) / 2
line 2 = (C + D) / 2

Blend 2

line 1 = (B+C)/2
line 2 = (B+C)/2

Blend 3

line1 = A/4 + B/2 + C/4
line2 = B/4 + C/2 + D/4

@sicklittlemonkey
Copy link
Contributor

sicklittlemonkey commented Oct 25, 2017 via email

@Michaelangel007
Copy link
Contributor Author

Michaelangel007 commented Oct 25, 2017

If we use a naive bicubic down-sample Program 2 TV mode:

.. 50%:

1_downsampe_tv_50

... 25%:

2_downsample_tv_25

And then bicubic re-up-sample back up to 560px, we get these solid colors:

5_upsample_tv_100

We get similar results if we bilinear downsample / upsample monitor mode:

6_upsample_bilinear_monitor

Conclusion

A naive re-sampling matches the hues of the actual TV pretty good.

@Michaelangel007
Copy link
Contributor Author

Let's convert program 2 from HGR to GR:

Source 2b

1 GOTO 10
2 X=I*2:Y=J*4
3 FOR V=0 TO 3:T=Y+V
4 COLOR=A:PLOT X,T:PLOT X+1,T
5 IF S=1 THEN 9
6 REM ---
7 COLOR=B:PLOT X,T+10:PLOT X+1,T+10
8 COLOR=C:PLOT X,T+18:PLOT X+1,T+18
9 NEXT:I=I+1:RETURN
10 GR:S=1:J=0
20 A= 9:I= 2:GOSUB 2:REM ORANGE
30 A=12:I= 5:GOSUB 2:REM GREEN
40 A= 6:I= 8:GOSUB 2:REM BLUE
50 A= 3:I=11:GOSUB 2:REM MAGENTA
60 A=15:I=13:GOSUB 2:REM WHITE
70 I=0:J=1:S=0
80  A=11:B= 3:C= 9:GOSUB 2
90  A= 0:B= 9:C=15:GOSUB 2
100 A= 9:B= 9:C= 9:GOSUB 2:REM ORANGE
110 A=13:B= 9:C=12:GOSUB 2:REM yellow
120 A=14:B=12:C=15:GOSUB 2
130 A=12:B=12:C=12:GOSUB 2:REM GREEN
140 A= 0:B= 6:C=12:GOSUB 2
150 A= 0:B= 6:C=15:GOSUB 2
160 A= 6:B= 6:C= 6:GOSUB 2:REM BLUE
170 A= 7:B= 6:C= 3:GOSUB 2
180 A= 0:B= 3:C=15:GOSUB 2
190 A= 3:B= 3:C= 3:GOSUB 2:REM MAGENTA=3
200 A= 5:B=12:C= 3:GOSUB 2:REM gray
210 A=15:B=15:C=15:GOSUB 2:REM WHITE
300 FOR I=0 TO 15:COLOR=I:PLOT I*2,28:NEXT

Output

I've set the GR colors that don't match the fake HGR colors as black:

Monitor Mode

1 26 gr monitor 14colors

TV Mode

1 26 gr tv 14colors

@Michaelangel007
Copy link
Contributor Author

Michaelangel007 commented Oct 25, 2017

@sicklittlemonkey Thanks Nick - - images should be correct now. Can you verify please? Thanks

@Michaelangel007
Copy link
Contributor Author

Disk image (ProDOS /HGR.TV) with source programs:

hgr.tv.dsk.zip

@6502-workshop
Copy link

Thanks for posting this Michael! I am using colors affected by this issue extensively in Nox Archaist.

@Michaelangel007
Copy link
Contributor Author

No prob Mark.

Updated comment 1 with extra information -- yellow, and and Composite-to-VGA adapter/convertors

@tomcw tomcw modified the milestones: 1.27, 1.28 Dec 17, 2017
@tomcw tomcw removed this from the 1.28 milestone May 27, 2018
@tomcw tomcw added this to To Do in Michael's issues May 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

No branches or pull requests

3 participants