PAL color palette emulation

Discuss emulation of the Nintendo Entertainment System and Famicom.

Moderator: Moderators

Post Reply
User avatar
feos
Posts: 108
Joined: Tue Apr 19, 2011 11:26 am
Location: RU

PAL color palette emulation

Post by feos »

NTSC emulation is doing very well for a long time, but why not PAL emulation?

Basing on research from HardWareMan, I implemented some kind of PAL subcarrier (moire) emulation in FCEUX, basing on his idea about its phases.
https://sourceforge.net/p/fceultra/code/3112/

Some pics for reference (console+tuner capture vs. fceux):

Kinopio pallette:
http://hwm.us.to/famimusic/Capture/6538 ... SVideo.PNG
http://savepic.su/5582426.png

Bucky O'Hare:
http://hwm.us.to/famimusic/Capture/6538 ... Svideo.png
http://savepic.su/5588570.png

Monochrome SMB:
http://savepic.su/440214.gif
http://savepic.su/5590618.png

There are 2 questions now:

1. How to make colors match?
While it might look that it's all about palette loaded, there's actually a Delphi version of that tool (by HWM himself) that outputs slightly different colors, and even makes them brighter! The funniest thing about it is that I used the same calculations on C, and it looks different! FCEUX default palette was used for all of them.
http://savepic.su/5579357.png
http://savepic.su/5586525.png
http://savepic.su/5580381.png

2. How to emulate some sort of rejector filter?
NES/Famicom has no Svideo output, but only plugging it that way one can see really sharp subcarrier mask. Primary output, Composite, gets filtered by reducing Luma (IIRC) to make moire less noticeable.
http://hwm.us.to/famimusic/Capture/6538 ... posite.PNG
http://hwm.us.to/famimusic/Capture/6538 ... posite.png
Attachments
fceux-PAL.7z
(1.05 MiB) Downloaded 611 times
Last edited by feos on Sat Dec 22, 2018 2:18 pm, edited 1 time in total.
User avatar
feos
Posts: 108
Joined: Tue Apr 19, 2011 11:26 am
Location: RU

Re: PAL color palette emulation

Post by feos »

I added some cheap notch filter simulation, it reduces the effect of moire mask up to totally killing it.

Code: Select all

if (notch)
	for (int j=0; j<16; j++) {
		if (moire[j] > 1) {
			step = (moire[j] - 1)/100;
			moire[j] -= step*notch;
		} else if (moire[j] < 1) {
			step = (1 - moire[j])/100;
			moire[j] += step*notch;
		}

	}
But there's another problem now. Since everything is calculated per palette tweak, I can't discard notch filter when it's a color border. Otherwise I'd need another 256*16 array of all the moired color values. Any ideas?

EDIT: attached the proper file with notch slider.
Attachments
fceux-pal-notch.7z
(1.05 MiB) Downloaded 552 times
Last edited by feos on Sun May 10, 2015 5:05 pm, edited 1 time in total.
User avatar
Dwedit
Posts: 4924
Joined: Fri Nov 19, 2004 7:35 pm
Contact:

Re: PAL color palette emulation

Post by Dwedit »

I see the FCEUX binary, but how do I actually see the PAL artifacts? I can't seem to find the setting in any obvious place.
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!
User avatar
feos
Posts: 108
Joined: Tue Apr 19, 2011 11:26 am
Location: RU

Re: PAL color palette emulation

Post by feos »

Dwedit wrote:I see the FCEUX binary, but how do I actually see the PAL artifacts? I can't seem to find the setting in any obvious place.
PAL filter is in Video config dialog, tweaks for it are in Palette config dialog. Enable hardware acceleration for more similarity.
lidnariq
Posts: 11432
Joined: Sun Apr 13, 2008 11:12 am

Re: PAL color palette emulation

Post by lidnariq »

I assume you read the thread about vertical chroma subsampling on PAL receivers? It looks like the PAL NES and Dendy produce sufficiently non-compliant timing that the exact resulting colors will vary too much from television to television. We don't even know the exact phase of the colorburst yet.

Of course, decoding anything without doing vertical chroma subsampling is still fine...

Actually on topic: The canonical way NTSC receivers do the chroma killer is to remodulate the decoded UV components and subtract that from the original. I assume you can do the same for PAL...
User avatar
feos
Posts: 108
Joined: Tue Apr 19, 2011 11:26 am
Location: RU

Re: PAL color palette emulation

Post by feos »

lidnariq wrote:The canonical way NTSC receivers do the chroma killer is to remodulate the decoded UV components and subtract that from the original. I assume you can do the same for PAL...
Can you elaborate or send me elsewhere for further reading?
tepples
Posts: 22708
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: PAL color palette emulation

Post by tepples »

PAL chroma merging? was the previous topic. It had these:
  • Page 1: "palblend" test ROM by lidnariq, whose output combines colors on alternating scanlines in a way that looks like the cover of the album 90125 by Yes
  • Pages 3-4: Confirmation that both PAL NES PPU (2C07) and Dendy PPU swap the function of red and green tint bits ($2001 D6/D5) compared to the NTSC PPU (2C02)
  • Page 5-6: "palphase" test ROM by tepples, which combines all 12 colors $11-$1C with similarly luminant gray $00 or color $11-$1C
lidnariq
Posts: 11432
Joined: Sun Apr 13, 2008 11:12 am

Re: PAL color palette emulation

Post by lidnariq »

For NTSC, at least, it's:

* Capture phase of -U during colorburst
* Generate sine waves at U and V for the scanline (or I and Q if you're doing the specified differential bandwidth)
* Multiply received video by U and V sinusoids, causing demodulation
* Lowpass filter demodulated signals at ~1.5MHz (or 0.6MHz for Q)
* Multiply demodulated U and V signals by said sine waves
* subtract remodulated U and V components from received video
* lowpass filter this difference signal at 4.2MHz to recover Y

The numbers change a little for PAL, and of course there's the colorburst phase switch from scanline to scanline.
User avatar
feos
Posts: 108
Joined: Tue Apr 19, 2011 11:26 am
Location: RU

Re: PAL color palette emulation

Post by feos »

Now as I've read that thread, I have a question, and I wonder why no one tested it so far: scanlines of 2 alternate colors are blended, plain and simple. But what happens to each of them if there's also a third color scanline? Fourth?

Red becomes Purple
Blue becomes Purple
Red becomes Purple
Blue becomes Purple

Red becomes Yellow?
Green becomes White?
Blue becomes ?
Yellow becomes ?

I can imagine chroma merging is not identical to RGB merging, and it'd only complicate things, but what actually happens to end pixels? Simulating all those sines and cosines and deep hardware events is cool, but it promises to cost an emulator an unjustified amount of time. While simulating the end effect straight away is cheaper effort-wise and speed-wise.

To be clear, here's my actual filter code:
https://sourceforge.net/p/fceultra/code ... t.cpp#l627
lidnariq
Posts: 11432
Joined: Sun Apr 13, 2008 11:12 am

Re: PAL color palette emulation

Post by lidnariq »

My understanding of "normal" PAL chroma subsampling is that the chroma for the current scanline is averaged with the chroma from the previous scanline. So red blue red blue does become (unknown) purple purple purple on a "real" PAL signal, but the same colors generated by the NES or SNES may or may not. (e.g. Thefox's TV doesn't. Eugene's / HardWareMan's TVs apparently does)

A sequence of something else would be similar: red green blue yellow would become (unknown) yellow cyan grey... there's no effect beyond just the immediately previous scanline.
User avatar
Eugene.S
Posts: 317
Joined: Sat Apr 18, 2009 4:36 am
Location: UTC+3
Contact:

Re: PAL color palette emulation

Post by Eugene.S »

I set notch slider to "70". Hey, it looks VERY good on Drag's palette.

Image Image Image
Image Image Image
User avatar
feos
Posts: 108
Joined: Tue Apr 19, 2011 11:26 am
Location: RU

Re: PAL color palette emulation

Post by feos »

That palmerge thing is really weird.

First of all, there's not just chroma merging, there's total color bleeding in some cases, even through gray!
http://savepic.ru/5769224.png
While that video doesn't do it:
viewtopic.php?p=125781#p125781

Then, it seems too heavy when I simply blend each scanline with its predecessor 50/50. Stripes on Bucky title get washed out.

Here, access the option from Palette config.
Attachments
fceux-palmegre.7z
(1.05 MiB) Downloaded 535 times
lidnariq
Posts: 11432
Joined: Sun Apr 13, 2008 11:12 am

Re: PAL color palette emulation

Post by lidnariq »

feos wrote:First of all, there's not just chroma merging, there's total color bleeding in some cases, even through gray!
That's definitely as intended, see the C64 game Mayhem in Monsterland: it blends greys and various pure shades to work around the C64's somewhat anemic palette.
While that video doesn't do it:
viewtopic.php?p=125781#p125781
In that thread, we figured out that thefox's capture card doesn't do any vertical chroma subsampling.
User avatar
feos
Posts: 108
Joined: Tue Apr 19, 2011 11:26 am
Location: RU

Re: PAL color palette emulation

Post by feos »

lidnariq wrote:In that thread, we figured out that thefox's capture card doesn't do any vertical chroma subsampling.
LOL. So it's done on TVs and not on some capture cards?

Wait, it still should not blend with black or white?
download/file.php?id=1950&mode=view
http://savepic.ru/5783665.jpg
lidnariq
Posts: 11432
Joined: Sun Apr 13, 2008 11:12 am

Re: PAL color palette emulation

Post by lidnariq »

His capture card pretty clearly added PAL as an afterthought; it's just using the standard BT.601 sample rate (producing 720x576 instead of expected 768x576). I've read that some really early and/or really cheap TV sets didn't implement the vertical chroma subsampling either.

As far as I know, the chroma subsampling should always work. (See lft's Phasor: it abuses this chroma subsampling a LOT). I don't know what exactly will happen on out-of-gamut YUV values, as could happen when combining pure white or black with something colored. Then again, several NES palette entries are already out-of-gamut. (See all the toggles in drag's generator)
Post Reply