GP32 Fade ins


TheMrCul

Still Fresh
Joined
Apr 18, 2003
Messages
52
I know how to fade to black and to white using Gamepark's standard GpLcdFade commands, but I was wondering if anyone knew how to fade from black or from white *into* a image, not just from an image to black or white?
Thanks guys and girls!
-Aal
 
my slow 16/8bits fadein:

(myscreen is the current screen pointer, (i.e: gpDraw.ptbuffer))

Code:
void Fade16bIn(u16 *image)
{
  u32 i;
  u16 pix,pixel,addP;
  u8  r,g,b,j;

for(j=0;j<32;j++)
{
  for(i=0;i<320*240;i++)  // optimised(?) :-/ 16/8Bits Fade
  {
    addP=0;
    pixel=image[i];  	// prend les pixels à comparer
    pix=myscreen[i];
    if((pix&0xF800)!=(pixel&0xF800)) addP+=0x800;
    if((pix&0x7C0 )!=(pixel&0x7C0 )) addP+=0x40;
    if((pix&0x3E  )!=(pixel&0x3E  )) addP+=0x2;
    myscreen[i]+=addP;  	// ajoute une unité aux composantes qui ne sont pas à la couleur de l'image
  }
}

maybe this can help you ...
 
Orion_ posted on Oct 23 2003 at 10:15 AM said:
my slow 16/8bits fadein:

(myscreen is the current screen pointer, (i.e: gpDraw.ptbuffer))

Code:
void Fade16bIn(u16 *image)
{
  u32 i;
  u16 pix,pixel,addP;
  u8  r,g,b,j;

for(j=0;j<32;j++)
{
  for(i=0;i<320*240;i++)  // optimised(?) :-/ 16/8Bits Fade
  {
    addP=0;
    pixel=image[i];  	// prend les pixels à comparer
    pix=myscreen[i];
    if((pix&0xF800)!=(pixel&0xF800)) addP+=0x800;
    if((pix&0x7C0 )!=(pixel&0x7C0 )) addP+=0x40;
    if((pix&0x3E  )!=(pixel&0x3E  )) addP+=0x2;
    myscreen[i]+=addP;  	// ajoute une unité aux composantes qui ne sont pas à la couleur de l'image
  }
}

maybe this can help you ...
you can drastically speed up your fade in routine by getting rid of those nasty 'if' statements and using a lookup table instead...

ok, this is all in my head and not tested, but it goes something like this...

Code:
void Fade16bIn( u16* image )
{
	u32 i, j;
	u16* src, dst;
	u32  r, g, b;

	u16 lut[64];
	u16* plut;
	for( i = 0; i < 32; ++i )
  lut[i] = 0;
	for(; i < 64; ++i )
  lut[i] = i - 32;

	for( i = 0; i < 33; ++i )
	{
  plut = &lut[i];
  src = image;
  dst = myscreen;
  for( j = 320 * 240; j; --j )
  {
  	r = *src >> 11;
  	r = plut[r] << 11;

  	g = (*src >> 6) & 0x1F;
  	g = plut[g] << 6;

  	b = (*src >> 1) & 0x1F;
  	b = plut[b] << 1;

  	*dst++ = (u16)(r|g|b);
  	src++;
  }
	}
}

there may be an ARM instruction that can be used instead of the LUT, but you'll have to ask a more 'l33t' coder about that ;)
 
Last edited by a moderator:
Thanks guys, but, when I try to compile with minigp32 it doesn't know what a u16 or u8 or u32 is! What do I do (I'm only an amateur programmer, I don't know what they are either!)
 
you should have a header file that defines what u8, u16 and u32 are, amongst other things...

Code:
typedef unsigned char  u8;
typedef unsigned short	u16;
typedef unsigned long	u32;
 
Back
Top