It is currently Fri Dec 15, 2017 4:52 pm

All times are UTC - 7 hours





Post new topic Reply to topic  [ 41 posts ]  Go to page 1, 2, 3  Next
Author Message
 Post subject: Emulating NTSC video
PostPosted: Sat Oct 22, 2016 4:35 pm 
Offline
User avatar

Joined: Mon Dec 29, 2014 1:46 pm
Posts: 750
Location: New York, NY
For the C++ on the Wiki, what is that 9-bit pixel color? Is there a way to convert the 6-bit PPU palette index into that?


Top
 Profile  
 
 Post subject: Re: Emulating NTSC video
PostPosted: Sat Oct 22, 2016 4:55 pm 
Online

Joined: Sun Apr 13, 2008 11:12 am
Posts: 6533
Location: Seattle
It's the 6-bit raw color number (i.e. the output of the palette) appended to the preemphasis bits.


Top
 Profile  
 
 Post subject: Re: Emulating NTSC video
PostPosted: Sun Oct 23, 2016 12:23 pm 
Offline
User avatar

Joined: Mon Dec 29, 2014 1:46 pm
Posts: 750
Location: New York, NY
Thanks. I plugged in that code without any optimizations to see what it looks like. He's a screenshot (3x magnification):

Image

That looks pretty horrible to me. And, I'm pretty sure that effect can be simulated by applying a filter that emphasizes R, then G, then B cyclically over every 3 pixels.

Anyway, the NTSC filters in other emulators don't look that bad. What is missing here?


Top
 Profile  
 
 Post subject: Re: Emulating NTSC video
PostPosted: Sun Oct 23, 2016 12:32 pm 
Offline
User avatar

Joined: Sun Jan 22, 2012 12:03 pm
Posts: 5898
Location: Canada
zeroone wrote:
Anyway, the NTSC filters in other emulators don't look that bad. What is missing here?

I think that looks more or less correct, but you've rendered to low resolution and then upscaled.

If you want better looking quality, you should render the NTSC output directly to a higher resolution output. Vertical can just double or triple lines (darkening some if you like "scanline" simulation), but horizontal should be accounting for the NTSC signal across the whole line (possibly while stretching to a different aspect ratio).

e.g. Blargg's NTSC filter demo upscales 256 x 240 to 602 x 480.


Top
 Profile  
 
 Post subject: Re: Emulating NTSC video
PostPosted: Sun Oct 23, 2016 12:42 pm 
Offline
User avatar

Joined: Sun Jan 22, 2012 12:03 pm
Posts: 5898
Location: Canada
For a quick comparison, Blargg's filter demo output compared to decimating it to half the resolution:
Attachment:
smb3_blargg.png
smb3_blargg.png [ 91.55 KiB | Viewed 1398 times ]
Attachment:
smb3_blargg_decimated.png
smb3_blargg_decimated.png [ 45.36 KiB | Viewed 1398 times ]

Note the better quality in the first image because it is able to subsample the analog NTSC signal during horizontal upscaling.


Top
 Profile  
 
 Post subject: Re: Emulating NTSC video
PostPosted: Sun Oct 23, 2016 12:53 pm 
Offline
User avatar

Joined: Mon Dec 29, 2014 1:46 pm
Posts: 750
Location: New York, NY
It looks like every other line is slightly darker. I'll try to figure out how that code works.


Top
 Profile  
 
 Post subject: Re: Emulating NTSC video
PostPosted: Sun Oct 23, 2016 1:23 pm 
Offline

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 19348
Location: NE Indiana, USA (NTSC)
You're seeing a combination of three differences:

  • As rainwarrior mentioned, TVs and emulators run the NTSC decoder at full output resolution, as opposed to one sample per NES pixel.
  • The PPU alternates the color subcarrier's phase by one-third of a cycle between one frame and the next. When played at 60 fps, frames with different phases blend together in a way that a single-field still screenshot doesn't capture.
  • The last thing you noticed is "scanlines", an interpolation technique that makes every other line darker to simulate the beam shape on a CRT that's focused for 480i but displaying 240p. But this is independent of the NTSC encoding and decoding; PlayChoice-style emulation with scanlines but without an NTSC filter is still valid.


Top
 Profile  
 
 Post subject: Re: Emulating NTSC video
PostPosted: Sun Oct 23, 2016 4:39 pm 
Offline
User avatar

Joined: Sun Jan 22, 2012 12:03 pm
Posts: 5898
Location: Canada
zeroone wrote:
It looks like every other line is slightly darker. I'll try to figure out how that code works.

That part isn't important, simulating scanlines is merely a stylistic choice / personal preference. It's a vague approximation of the gaps between lines in 240p on a CRT.

The vertical stretching of the image is simply done by doubling every line (no interpolation or oversampling, etc.). The scanline effect is literally just darkening every second line. I would have removed it for clarity if the filter demo had an option to do so, since I was only trying to demonstrate how the horizontal scaling is different.


Top
 Profile  
 
 Post subject: Re: Emulating NTSC video
PostPosted: Sun Oct 23, 2016 4:56 pm 
Offline
User avatar

Joined: Sun Jan 22, 2012 12:03 pm
Posts: 5898
Location: Canada
For a better comparison, here's the Blarrg filter example with the scanlines removed. (Compare this against the second "decimated" example above.)
Attachment:
smb3_blargg_scanlines_removed.png
smb3_blargg_scanlines_removed.png [ 51.53 KiB | Viewed 1356 times ]

Comparing the two you can see the decimated version has the same problem as your example, though maybe slightly milder (the problem is a little bit obscured by the aspect ratio change). The point is that quality improves with better sampling. You should see that the decimated version has more spurious colour fringes, etc. than the normal version, similar to your example.


Top
 Profile  
 
 Post subject: Re: Emulating NTSC video
PostPosted: Sun Oct 23, 2016 5:52 pm 
Online

Joined: Sun Apr 13, 2008 11:12 am
Posts: 6533
Location: Seattle
Does following along with my manual demodulation explain things at all?


Top
 Profile  
 
 Post subject: Re: Emulating NTSC video
PostPosted: Sun Oct 23, 2016 6:00 pm 
Offline
User avatar

Joined: Mon Dec 29, 2014 1:46 pm
Posts: 750
Location: New York, NY
One of the functions on the wiki takes a Width parameter. Here's the result with a Width of 512:

Image

@rainwarrior It's a lot closer to the last Blarrg image that you posted, but Blarrg's still doesn't not contain that much color fringing.

lidnariq wrote:
Does following along with my manual demodulation explain things at all?


That looks like a really interesting post. I'll study it. I'm clueless about how NTSC does it's thing. I just copied-and-pasted wiki code :)


Top
 Profile  
 
 Post subject: Re: Emulating NTSC video
PostPosted: Sun Oct 23, 2016 6:17 pm 
Offline
User avatar

Joined: Mon Dec 29, 2014 1:46 pm
Posts: 750
Location: New York, NY
Below is another with Width set to 768. It also smoothly stretches it to the TV pixel aspect ratio.

Image

I don't recall any CRT looking quite like these images.


Top
 Profile  
 
 Post subject: Re: Emulating NTSC video
PostPosted: Sun Oct 23, 2016 6:21 pm 
Offline
User avatar

Joined: Sat Feb 12, 2005 9:43 pm
Posts: 10164
Location: Rio de Janeiro - Brazil
The red-green-blue artifacts are way too pronounced, but the image looks fairly accurate otherwise, IMO.


Top
 Profile  
 
 Post subject: Re: Emulating NTSC video
PostPosted: Sun Oct 23, 2016 6:24 pm 
Offline
User avatar

Joined: Mon Dec 29, 2014 1:46 pm
Posts: 750
Location: New York, NY
tokumaru wrote:
The red-green-blue artifacts are way too pronounced, but the image looks fairly accurate otherwise, IMO.


I agree. But, this was generated with the code straight off the wiki. Any tuning suggestions?


Top
 Profile  
 
 Post subject: Re: Emulating NTSC video
PostPosted: Sun Oct 23, 2016 6:36 pm 
Online

Joined: Sun Apr 13, 2008 11:12 am
Posts: 6533
Location: Seattle
The C++ on the wiki "should" generate a 2048x240 image.

Oh, I see, the "width" parameter imposes a simple decimation of the output image. At a width of 768, it ought to be ... moderately representative to the actual bandwidth of the system, I'd think...?


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 41 posts ]  Go to page 1, 2, 3  Next

All times are UTC - 7 hours


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group