It is currently Thu Dec 14, 2017 6:25 am

All times are UTC - 7 hours





Post new topic Reply to topic  [ 37 posts ]  Go to page Previous  1, 2, 3  Next
Author Message
PostPosted: Thu Oct 23, 2014 11:25 am 
Offline
User avatar

Joined: Sun Sep 19, 2004 9:28 pm
Posts: 3192
Location: Mountain View, CA, USA
Quoting the documentation (nes_ntsc.txt) that comes with blargg's nes_ntsc code:

Code:
Image Size
----------
For proper aspect ratio, the image generated by the library must be
doubled vertically.

Use the NES_NTSC_OUT_WIDTH() and NES_NTSC_IN_WIDTH() macros to convert
between input and output widths that the blitter uses. For example, if
you are blitting an image 256 pixels wide, use NES_NTSC_OUT_WIDTH( 256 )
to find out how many output pixels are written per row. Another example,
use NES_NTSC_IN_WIDTH( 640 ) to find how many input pixels will fit
within 640 output pixels. The blitter rounds the input width down in
some cases, so the requested width might not be possible. Use
NES_NTSC_IN_WIDTH( NES_NTSC_OUT_WIDTH( in_width ) ) to find what a given
in_width would be rounded down to.

And from nes_ntsc.h -- it looks like these are macros, so someone would need to write the code to dynamically change this on the fly (through a command-line argument or some other means). Comments are worth noting:

Code:
/* Number of output pixels written by blitter for given input width. Width might
be rounded down slightly; use NES_NTSC_IN_WIDTH() on result to find rounded
value. Guaranteed not to round 256 down at all. */
#define NES_NTSC_OUT_WIDTH( in_width ) \
   ((((in_width) - 1) / nes_ntsc_in_chunk + 1) * nes_ntsc_out_chunk)

/* Number of input pixels that will fit within given output width. Might be
rounded down slightly; use NES_NTSC_OUT_WIDTH() on result to find rounded
value. */
#define NES_NTSC_IN_WIDTH( out_width ) \
   (((out_width) / nes_ntsc_out_chunk - 1) * nes_ntsc_in_chunk + 1)


Top
 Profile  
 
PostPosted: Thu Oct 23, 2014 11:26 am 
Offline

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 19342
Location: NE Indiana, USA (NTSC)
Bregalad wrote:
Mmh, sorry, yes I know your editor is impressive and all, but honnestly running it like that is so much less user friendly than a PC program that allows the mouse to be used.

I could make a version that uses a mouse. I've already made two programs that support a Super NES mouse through a Super NES controller to NES adapter: Thwaite and my sound effects editor. But right now, the only NES emulator I can think of that supports a mouse is Nintendulator, and Quietust refuses to add filters. So first you'd have to either A. solder together such an adapter to run on an actual NES, B. request support for an NTSC filter in an NES emulator that supports the Super NES Mouse, or C. request support for the Super NES Mouse in an NES emulator that supports an NTSC filter. I've requested support for the Super NES Mouse in FCEUX.


Top
 Profile  
 
PostPosted: Thu Oct 23, 2014 11:30 am 
Offline
User avatar

Joined: Sun Jan 22, 2012 12:03 pm
Posts: 5896
Location: Canada
DragonDePlatino wrote:
That's impossible to cleanly resize back down to 256x224 unless I want to stretch the pixels in the process.


What is wrong with 301 x 224? Even changing the aspect ratio with interpolation back to 256 x 224 would still should the NTSC filter's effect pretty well.

What you did was resize it to 256 x 224, but preserving the new aspect ratio with black bars, and apparently without interpolation, leaving us with an image that is very distorted vertically (especially look at all those stripe artifacts across the image). All I'm saying is that because of the resizing process you applied, the example you made didn't really show us what the NTSC filter does very well at all.

Three examples of how it could have been done alternatively:

Attachment:
File comment: Interpolated to 301 x 224. (Aspect preserved.)
just_interpolated.png
just_interpolated.png [ 140.37 KiB | Viewed 2158 times ]

Interpolated to 301 x 224. I think this is best; an interpolation of precisely 50% on both axes leaves a clean result, and preserves the aspect ratio.

Attachment:
File comment: Interpolated to 256 x 191. (Aspect preserved, vertical information loss.)
letterboxed.png
letterboxed.png [ 118.52 KiB | Viewed 2158 times ]

Interpolated to 256 x 191. Unlike the example you made, the interpolation method used here preserves some of the detail. There is still significant information loss vertically, so this is not entirely clean, but at least you have less artifacts.

Attachment:
File comment: Interpolated to 256 x 224. (Horizontal squish.)
horizontally_interpolated.png
horizontally_interpolated.png [ 135.8 KiB | Viewed 2158 times ]

Interpolated to 256 x 224. This shows fairly well what the NTSC filter does, but ignores the aspect ratio change. There is some loss of detail about what the NTSC filter does horizontally, but it is not as prone to aliasing problems as the vertical loss of detail is, since the NTSC signal is organized in scanlines.

Specifically Lanczos interpolation was used, but other interpolation methods may give similar results. The main thing here is not to use nearest neighbour resampling (no interpolation) when scaling down.


Top
 Profile  
 
PostPosted: Thu Oct 23, 2014 1:47 pm 
Offline
User avatar

Joined: Mon Oct 20, 2014 1:50 pm
Posts: 94
Oh! I almost forgot! Yeah, I was using-nearest neighbor when scaling down...I tend to have that set as my default scaling since I draw with programs like ASEprite. Anyways, I think that last image will work just fine for the thread!

_________________


Top
 Profile  
 
PostPosted: Thu Oct 23, 2014 2:07 pm 
Offline

Joined: Sun Apr 13, 2008 11:12 am
Posts: 6520
Location: Seattle
Fair warning: the reason that nes_ntsc produces an image that's stretched horizontally is because the actual hardware does that. Undoing the aspect ratio change is somewhat misleading ... either you have the NTSC artifacts, and the pixel aspect ratio is 8:7, or you use square pixels and there's no NTSC artifacts.


Top
 Profile  
 
PostPosted: Thu Oct 23, 2014 2:17 pm 
Offline
User avatar

Joined: Sun Sep 19, 2004 9:28 pm
Posts: 3192
Location: Mountain View, CA, USA
Not to mention: I don't know what all of this is being used for -- the thread so far implies it's being used for map generation -- but when it comes to screenshots, it's my experience that people really don't like seeing blurry crap and would rather see sharp pixels.

I can't tell you how many times I've used GameFAQs maps and so on, only to find people applied stupid filters + weird resizing + other crap and the end result actually hurts my eyes. I actually go find other maps/walkthroughs/etc. in that scenario. So IMO you're better off not bothering and instead just doing a linear ("nearest neighbour") scale of 2x and so on.

If you're doing it for some other reason, i.e. you wanna see if the graphics improvements/changes you're doing would look semi-good with actual NTSC artefacting, then that's a bit more understandable.


Top
 Profile  
 
PostPosted: Thu Oct 23, 2014 2:18 pm 
Offline
User avatar

Joined: Fri Nov 12, 2004 2:49 pm
Posts: 7314
Location: Chexbres, VD, Switzerland
Quite a few emus, such as VirtuaNES, has an option for a 8:7 ratio (a ckeckbox called "TV aspect"), and that since long before Blargg made the NTSC filter.

Quote:
linear ("nearest neighbour")

Linear and nearest neighbour are 2 completely different things ! From the context it sounds like it's nearest neighbour interpolation you're talking about, NOT linear, since linear interpolation WILL blur the pixels together.


Top
 Profile  
 
PostPosted: Thu Oct 23, 2014 2:50 pm 
Offline
User avatar

Joined: Mon Oct 20, 2014 1:50 pm
Posts: 94
Well, the reason I was originally interested in this is because I needed to test my sprites for clarity. In the past, I've had a lot of people complain that my sprites don't have enough contrast or they're too detailed even if I think they're fine. So as a good benchmark, I like to view them with an NTSC filter to see if I can still recognize them. If I can't, I usually go back and change body proportions, remove details, etc.

Anyways, regardless of the aspect ratio, this NTSC filter works great for my purposes! Thanks again for compiling this for the less programming-adept such as I.

_________________


Top
 Profile  
 
PostPosted: Thu Oct 23, 2014 4:34 pm 
Offline

Joined: Thu Aug 12, 2010 3:43 am
Posts: 1589
I'd say that the 602×448 image probably shouldn't have been downscaled at all in the first place... I mean, artifacts vary at the subpixel level, so the higher resolution is actually needed for an accurate representation. Not to mention that let's face it, it's not a large image for today's resolutions (heck, for the current higher resolutions 256×224 is actually too small).


Top
 Profile  
 
PostPosted: Thu Oct 23, 2014 5:50 pm 
Offline
User avatar

Joined: Sun Sep 19, 2004 9:28 pm
Posts: 3192
Location: Mountain View, CA, USA
Bregalad wrote:
Quote:
linear ("nearest neighbour")

Linear and nearest neighbour are 2 completely different things ! From the context it sounds like it's nearest neighbour interpolation you're talking about, NOT linear, since linear interpolation WILL blur the pixels together.

I guess I'm using the wrong terms then, sorry. I know bilinear and trilinear interpolation will result in horrific blur, but was under the impression the term "linear interpolation" (no bi- or tri- prefixes) meant the same thing as nearest-neighbour. Good to know I was wrong + learned something.


Top
 Profile  
 
PostPosted: Thu Oct 23, 2014 8:01 pm 
Offline
User avatar

Joined: Sun Jan 22, 2012 12:03 pm
Posts: 5896
Location: Canada
koitsu wrote:
I guess I'm using the wrong terms then, sorry. I know bilinear and trilinear interpolation will result in horrific blur, but was under the impression the term "linear interpolation" (no bi- or tri- prefixes) meant the same thing as nearest-neighbour. Good to know I was wrong + learned something.

Bilinear and trilinear are both linear interpolation, just in 2 and 3 dimensions, respectively. For example:

- Linear interpolation is done on audio.
- Bilinear interpolation is done on images.
- Trilinear interpolation is done on a volume, often a stack of images like in mip-mapping.

The prefix may be omitted if the number of dimensions is implictly known, or otherwise unimportant.

Unfortunately this scheme of prefixes does not hold up consistently in other cases. For instance the terms "biquadratic filter" and "binormal" don't refer to 2-dimensional analogs of a "quadratic filter" or "normal".


Top
 Profile  
 
PostPosted: Fri Oct 24, 2014 3:01 am 
Offline

Joined: Thu Aug 12, 2010 3:43 am
Posts: 1589
koitsu wrote:
I guess I'm using the wrong terms then, sorry. I know bilinear and trilinear interpolation will result in horrific blur, but was under the impression the term "linear interpolation" (no bi- or tri- prefixes) meant the same thing as nearest-neighbour. Good to know I was wrong + learned something.

Bilinear refers to linear interpolation in both the X and Y axes. Trilinear means doing that and also linear interpolation between mipmaps (a third "axis"), although I suppose it also applies to the Z axis when it comes to 3D textures.

Simple linear interpolation would be interpolating in one axis and not the others =P I'm not even sure if that's supported by the hardware (OpenGL doesn't support it).


Top
 Profile  
 
PostPosted: Fri Oct 24, 2014 5:23 am 
Offline

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 19342
Location: NE Indiana, USA (NTSC)
If you do bilinear interpolation between two images of the same height, you get linear interpolation in the horizontal direction and nothing in the vertical. Complications may arise if an API is unclear about whether a coordinate of 0 applies to a texel center or a texel corner.


Top
 Profile  
 
PostPosted: Fri Oct 24, 2014 6:26 am 
Offline
User avatar

Joined: Sun Jan 22, 2012 12:03 pm
Posts: 5896
Location: Canada
That's not unclear at all:

In OpenGL, 0 is a pixel corner.
In Direct3D <= 9, 0 is a pixel centre (i.e. the wrong way to do it).
In Direct3D >= 10, 0 is configurable as either but defaults to the pixel corner.


Top
 Profile  
 
PostPosted: Fri Dec 19, 2014 10:24 am 
Offline
User avatar

Joined: Mon Jan 03, 2005 10:36 am
Posts: 2982
Location: Tampere, Finland
Could you post the compiled ntsc_nes demo as well? I believe it has some benefits over the more generic ntsc_snes library when used on NES images.

_________________
Download STREEMERZ for NES from fauxgame.com! — Some other stuff I've done: kkfos.aspekt.fi


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

All times are UTC - 7 hours


Who is online

Users browsing this forum: Yahoo [Bot] and 3 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