Pixel aspect ratio and ddraw
Moderator: Moderators
Dwedit is right that the problem comes from using nearest neighbor resampling, which just doubles rows or columns of pixels. You want to use some sort of interpolation.
I will warn you that bilinear interpolation will blur the image. If you're resizing to 2x or bigger, I recommend upscaling your 256x240 pixel picture to another 512x480 pixel offscreen surface in nearest neighbor mode so that pixels still have well-defined edges, and then using bilinear interpolation from that to the final window.
I will warn you that bilinear interpolation will blur the image. If you're resizing to 2x or bigger, I recommend upscaling your 256x240 pixel picture to another 512x480 pixel offscreen surface in nearest neighbor mode so that pixels still have well-defined edges, and then using bilinear interpolation from that to the final window.
mmm.. i googled for "image interpolation" and is a big topic. I found a PDF that threat that topic, but is out of my scope, in the sense i can't understand it. It's full of math examples and all things like that.Dwedit wrote:Don't resize to 292x240, enlarge it to something much bigger, but when you pick a new size for the image, keep it at the same ratio as 294x240. So you resize from 256x240 to something bigger, and make the image slightly wider at the same time.
So if you enlarge it to 1920x1080 for example, you get a size of 1317x1080.
If you will be keeping the image small, it's best not to correct the aspect ratio. But it works well for enlargements.
Also, when you resize, you want a resizing algorithm that interpolates the image.
I also searched for a library or code to do interpolation but there is no one!!. Maybe i should try with a game dev book, something simpler.
ANes
Note: These images come from an emulator that trims off the top and bottom 8 scanlines as overscan before doing any other processing, and please don't nitpick the palette either.

SMB1 title screen, dot for dot

SMB1 title screen, resized to 292x224 with point sampling (nearest neighbor)
Notice how uneven the ground is because some NES pixels become 1 screen pixel wide and others become 2.

SMB1 title screen, resized to 292x224 with linear interpolation
Nice and smooth.

SMB1 title screen, resized to 584x448 with point sampling
Notice that the ground's still uneven, but less so than at 292x224, because some NES pixels become 2 screen pixels wide and others become 3.

SMB1 title screen, resized to 584x448 with linear interpolation
It's smooth, almost too smooth, because linear interpolation applies a blur over everything.

SMB1 title screen, resized to 512x448 with point sampling and then to 584x448 with linear interpolation
The first step of doubling ensures that pixel edges remain well defined; the linear step keeps them smooth. This is what your emulator's output should look like if you're not planning to emulate NTSC video artifacts.

SMB1 title screen, resized to 512x448 with Scale2x and then to 584x448 with linear interpolation
Scale2x doesn't do much for 45 degree lines, but look at what it does to the text, bushes, and floor.
DirectX itself can perform point sampling and linear interpolation. External libraries are available to apply the Scale2x effect, and it's even been done in a pixel shader.

SMB1 title screen, dot for dot

SMB1 title screen, resized to 292x224 with point sampling (nearest neighbor)
Notice how uneven the ground is because some NES pixels become 1 screen pixel wide and others become 2.

SMB1 title screen, resized to 292x224 with linear interpolation
Nice and smooth.

SMB1 title screen, resized to 584x448 with point sampling
Notice that the ground's still uneven, but less so than at 292x224, because some NES pixels become 2 screen pixels wide and others become 3.

SMB1 title screen, resized to 584x448 with linear interpolation
It's smooth, almost too smooth, because linear interpolation applies a blur over everything.

SMB1 title screen, resized to 512x448 with point sampling and then to 584x448 with linear interpolation
The first step of doubling ensures that pixel edges remain well defined; the linear step keeps them smooth. This is what your emulator's output should look like if you're not planning to emulate NTSC video artifacts.

SMB1 title screen, resized to 512x448 with Scale2x and then to 584x448 with linear interpolation
Scale2x doesn't do much for 45 degree lines, but look at what it does to the text, bushes, and floor.
DirectX itself can perform point sampling and linear interpolation. External libraries are available to apply the Scale2x effect, and it's even been done in a pixel shader.
Nvidia cards only do point sampling on Vista+. I switched to Direct3D because of this.Disch wrote:Is surface blitting even still supported by modern hardware?
I'm using the method described here for resizing. It results in a smooth image, but edge detail is better preserved than with straight bilinear filtering.
OT: Don't use JPG for NES screenshots (or any other image with few colors and flat-colored areas), it severily degrades the image and results in bigger files than GIF or PNG, which are lossless. Your image is 35KB, and it's all blurry and ruined by JPG artifacts. Compare it to tepples' image:Anes wrote:

This is a perfect representation of the original image, with no degradation of any kind, and is under 2KB in size (it's over 17 times smaller, and looks much better!). JPG is for photographs and real-world stuff, for pixel art always use GIF or PNG.
Also, don't forget that scaling is different on DDraw than D3D (regardless of OS). There are those of us who do not like the blurry filter crap output when using an emulator, even when using an even number (e.g. display size of 512x448). I prefer my graphics to look pixellated rather than blurry as shit, but that's also why I use an even multiple (*2) for my display resolution. Oh, and full screen vs. windowed seems to matter too. You can look all the many emulators out there which all let you toggle this kind of feature (GPU scaling vs. software); each calls it something different, which amuses me.
(Let the record state that that book is Introduction to 3D Game Programming with DirectX 10 by Frank D. Luna.)
The biggest problem that I can see with DirectX 10 is that it's new in Windows Vista, which means 45 percent of people still can't run it according to this table:
The biggest problem that I can see with DirectX 10 is that it's new in Windows Vista, which means 45 percent of people still can't run it according to this table:
I already don't have any XP boxes in my home anymore since I replaced the last one with a new PC running Windows 7 nearly a year ago, but my aunt and her kids still have four. It'll take a couple more years (April 2014) for Windows XP to leave extended support.Net Market Share wrote:Windows XP: 44.85%
The author also wrote DirectX 9 versions of the book: with shaders and without.
IMO, if you're starting now, go for DX10/11, or at the very least, take the shader approach. Or, if you're really worried about broad platform compatibility, look at OpenGL instead.
IMO, if you're starting now, go for DX10/11, or at the very least, take the shader approach. Or, if you're really worried about broad platform compatibility, look at OpenGL instead.