panel bitmap bug

Posted By: Hummel

panel bitmap bug - 01/05/11 20:22

Hi,

when scaling and/or mirroring a panel with bitmap several small 'offset-bugs' seem to occur in the bitmap:



In the case of mirroring only (scale_x/y=-1) a single pixel offset appears (in mirroring direction).

Using scale_x/y=-2 gives nearly the same effect but itīs now just a half-pixel offset.

scale_x/y=(-)16 gives the same result but the panel without mirroring displays its bitmap now shifted too.

I used engine version 8.10.1

Grüße

PS: test code
Click to reveal..
Code:
#include <acknex.h>
#include <default.c>

BMAP *_bQuad="Quad.tga";

PANEL *_pQuad1=
{
	bmap=_bQuad;
	flags=SHOW;
}

PANEL *_pQuad2=
{
	bmap=_bQuad;
	flags=SHOW;
}

PANEL *_pQuad3=
{
	bmap=_bQuad;
	flags=SHOW;
}

PANEL *_pQuad4=
{
	bmap=_bQuad;
	flags=SHOW;
}

void main()
{
	fps_max=50;

	video_mode=9;
	
	vec_set(screen_color,vector(255,255,255));
	
	var _vScale=16;
	
	_pQuad1->scale_x=_vScale;
	_pQuad1->scale_y=_vScale;
	
	_pQuad1->pos_x=1*_vScale;
	_pQuad1->pos_y=1*_vScale;
	
	_pQuad2->scale_x=-_vScale;
	_pQuad2->scale_y=_vScale;
	
	_pQuad2->pos_x=18*_vScale;
	_pQuad2->pos_y=1*_vScale;
	
	_pQuad3->scale_x=_vScale;
	_pQuad3->scale_y=-_vScale;
	
	_pQuad3->pos_x=1*_vScale;
	_pQuad3->pos_y=18*_vScale;
	
	_pQuad4->scale_x=-_vScale;
	_pQuad4->scale_y=-_vScale;
	
	_pQuad4->pos_x=18*_vScale;
	_pQuad4->pos_y=18*_vScale;
}



Posted By: jcl

Re: panel bitmap bug - 01/06/11 17:19

I'm afraid my best advice here is compensating the problem by painting an extra black row in your image. As you can imagine, the extra pixels that you see are drawn intentionally.

The rasterization process of graphics hardware requires pixels to be hit in the center. Otherwise, the 2D image becomes utterly distorted and you'll complain.

But when you think about the consequences of rendering from the center of the first to the center of the last pixel of a 16 pixel image, you will notice that the render length is 15 and not 16 pixels. Your image is too small and you'll complain again.

Thus, 3D engines usually render an extra pixel, getting the right image size without distortion. This is the best compromise. Our reward is that no one has complained so far. At least until now.

Hope this explains the problem.
Posted By: Hummel

Re: panel bitmap bug - 01/06/11 17:27

Is there no way to implement a compensation pixel shift at least for mirroring only? (I dont really care about the scaled up versions)
Posted By: jcl

Re: panel bitmap bug - 01/06/11 17:31

It's not a problem of mirroring. It also happens in unmirrored images. It's only noticeable in very small images that are scaled up.

What we could theoretically do is adding a panel flag for not rendering the last pixel. You'll then get panels that are 1 pixel too small. But I do not like this solution - it's better to compensate this in the image. Or write a small function that reduces the panel size_x and size_y by 1 pixel.
Posted By: Hummel

Re: panel bitmap bug - 01/06/11 17:51

Itīs also noticable in not (or just in one direction) scaled up images which are quite small like the ones you use when building a GUI and thatīs actually the situation when I noticed it.
When I want to display a window border bar using f.i. a streched 2x16 bitmap I dont care about a possible pixel shift along the stretch. But as soon as I want to use the same bitmap for the opposite border bar by using scale_x=-1; I get the pixel offset.
And since itīs the nature of this kind of bitmaps to contain important color information in just a handfull of pixels, specially in the border pixels, the visual effect can be a completely other one than the one of the opposite border.

Creating multible versions of each bitmaps seems to be the only solution...

...and that makes me sad frown
Posted By: Rei_Ayanami

Re: panel bitmap bug - 01/06/11 17:58

You could also make a function which creates a mirrored version of the bmap...

[as a workaround, sounds better than creating many images]
Posted By: Hummel

Re: panel bitmap bug - 01/06/11 18:04

That is my plan but still, using a single value seems to be the smarter solution to me. Memory is not really the problem as long as I just need multible versions for the GUI but it looks like memo waste when developing a 2D game with many different tiles where you have to generate multible versions for half of the pics...

EDIT: what about a shift_x/y panel member where the user could define pixel shifts for the bitmaps of a panel on his own?
Is there a performance or technical prob implementing this?
Posted By: Hummel

Re: panel bitmap bug - 01/08/11 11:12

Just bumped for the case that you didnt read my 'EDIT-question'.
If you think Iīm a nagger delete this post. tongue
© 2024 lite-C Forums