Weird image behaviour using virtual resolution

BlitzMax Forums/BlitzMax Programming/Weird image behaviour using virtual resolution

Adam Novagen(Posted 2015) [#1]
So the current project is something retro-styled, running at a 400x224 virtual resolution. To keep the "purity" of the pixel aesthetic, the program can run in windowed mode at a x1, x2, x3 or x4 scale, i.e. 400x224, 800x448, 1200x672 or 1600x896. I'd begun this program while working on tile-based maps, which gave me no trouble for a long time. However, today I loaded in a larger image - a 400x224 image for the title screen - and I noticed something strange.

At x1 and x3 scale, the image rendered perfectly. However, at x2 and x4 scale, there were odd rows of pixels that were slighly offset, almost like scanlines. Here's a sample image showing this behaviour:



There's nothing wrong with the embedded image, this is a screenshot taken from the program window while at x4 scale.

A close-up of the most affected area:



This same image, at x3 scale (or x1), shows no signs of this odd "jittering:"



Oddly enough, using SetScale 1.0001,1.0001 appears to have fixed problem completely, which leads me to believe this is some kind of floating-point error with virtual resolutions. Still, it's got me scratching my head a bit; can anyone shed some light on this nonsense?


Matty(Posted 2015) [#2]
Maybe my eyes are bad.....but I can't see any difference in the two pictures at all?


Adam Novagen(Posted 2015) [#3]
It is a bit subtle, I probably should've highlighted it. Here, have a magnified peek:

x3 scale, nothing amiss:



x4 scale, suddenly scanline-ish distortion:



As mentioned before, using SetScale 1.0001,1.0001 fixes it, so it's not really a problem; I'm just curious as to what's causing it.


Pingus(Posted 2015) [#4]
None of the images above are 'perfect' pixel imo. I see antialiasing on all.
If you want perfect pixel scales, you should set up your game to the desktop resolution, and scale your pictures depending on the available space and add borders around the game window. Any kind of virtual resolution, or full screen mode different from the desktop resolution will add blur, antialiasin, jittering...


H&K(Posted 2015) [#5]
Hes talking about the crenellations (castle like in/outs)
Which as solved look like some boundary rounding


TomToad(Posted 2015) [#6]
Try using LoadImage("imagename.png",MASKEDIMAGE) and see if that solves the problem. BlitzMax will try and 'smooth' an image when it is resized. Possibly with the smoothing and anti-aliasing together, it is creating the problems you are seeing.


Floyd(Posted 2015) [#7]
It's probably some numerical oddity of the way image pixels get mapped to screen pixels.

Such moiré patterns can be very surprising. Here's an example program if you have a couple of minutes to kill. It creates a black and white checkerboard image, which is displayed at increasing scales and rotations. If you haven't tried something like this you would never guess how it looks.

Graphics 700, 700

chex:TImage = CreateImage(512,512,1,DYNAMICIMAGE)
SetImageHandle chex, 256, 256

For y = 0 To 510 Step 2
	For x = 0 To 510 Step 2
		Plot x, y
		Plot x+1, y+1
	Next
Next
GrabImage chex, 0, 0

For n# = 0.4 To 1.0 Step 0.001
	Cls
	SetScale n, n
	DrawImage chex, 350, 350
	Flip
Next	

For n = 0 To 25 Step 0.005
	Cls
	DrawImage chex, 350, 350
	SetRotation n
	Flip
Next