On 16 Aug 98 19:46:55 +0000, "2ReAL" wrote about Fade routine:
> Hi, i'm desperately in need of a good fade routine (OS friendly please)! Can anyone
> help me??
- Read the colours in an array.
- Repeat
- Multiply the values in the array by a factor smaller than 1
- Change the colours of the screen via LoadRGB4() or LoadRGB32()
- until the screen is dark
- Set the screen to all black
--
---
Menno Tjoelker
Eindhoven - the Netherlands
>- Read the colours in an array.
>- Repeat
> - Multiply the values in the array by a factor smaller than 1
Hmm exactly what value should this be? I tried several, none worked well..
> - Change the colours of the screen via LoadRGB4() or LoadRGB32()
>- until the screen is dark
>- Set the screen to all black
This is more or less the way i was doing it:
- load the screen palette into an array, then:
- compare each element with the destination color or palette (also on an array)
- if lower increase, if higher decrease: add or subtract $0111 (since it's
RGB values)
- change screen colours with LoadRGB4()
- repeat until colours = destination
It works, but the result isn't perfect..
--
!2ReAL! wHEn rEALITy sTARTs tO hURt tHAT's wHEn iT gETs 2 rEAl 4 yOu!
*2ReAL* <mur...@a-team.com> said into
"comp.sys.amiga.programmer" (16-Ago-98 20:46:55)
about "Fade routine":
> Hi, i'm desperately in need of a good fade routine
> (OS friendly please)!
I wrote one (C language)
for the MadeInJapan slideshow...
a productions with good graphics (manga) but mediocre coding.
I would sent to you
via private email... but your email address seems faked.
NOTE: The remarks are wrote in english/spanish language
/* ----------------------------------------------------------------------- */
/* Rutina de fundido para LoadRGB32 © 1995/96 - Dámaso Domínguez Estévez */
/* Versión 2.0 */
/* > AGA fade routine < */
/*
Prototipe/prototipo:
void Fundido (struct Screen *,ULONG *,ULONG *,int,BOOL)
Parameters/parámetros
struct Screen *pant pointer to fading screen
ULONG *palini pointer to initial/start palette
ULONG *palfin pointer to final palette
int numpas steps (number) for transition
BOOL fundido switch (on/off transition)
Return/devuelve:
void
*/
void Fundido(struct Screen *pant, ULONG *palini,ULONG *palfin,int numpas,BOOL fundido)
{
/* Temporal palette (significative 16 low bits) */
/* Paleta temporal de 16 bits inferiores significativos */
float palsum [98];
/* To add for 'palsum' (for each fade step) */
/* Incr. de 'palsum' en cada paso del fundido */
float palpas [98];
/* Palette 'palsum' but with LoadRGB32() format */
/* Paleta 'palsum' pero en formato LoadRGB32() */
ULONG palrgb [98];
register int b,c;
if(fundido) {
/* Inicializamos 'palsum' igualándolo a 'palini' y calculamos */
/* los incrementos que asignamos a 'palpas'. */
for(b=1;b<=96;b++) {
/* Init palsum */
/* Inicializamos palsum */
palsum[b]=(FLOAT)((palini[b]>>16)&65535L);
/* To calc the steps */
/* Calculamos incrementos */
palpas[b]=(FLOAT)((((palfin[b]>>16)&65535L)-palsum[b])/numpas);
}
/* The fade with 'numpas' steps */
/* Iniciamos el fundido a realizar en 'numpas' pasos */
for(b=0;b<=(numpas-1);b++) {
/* Change for each cicle on (over?) the three components */
/* El cambio se hace en cada ciclo sobre las tres componentes */
for(c=1;c<=96;c=c+3) {
/* Red component - componente R (rojo) */
palsum[c]=palsum[c]+palpas[c];
/* Conversion to LoadRGB() format */
/* La convierto a formato LoadRGB32() */
palrgb[c]=(((ULONG)(palsum[c])<<16)|65536);
/* Green component - componente G (verde) */
palsum[c+1]=palsum[c+1]+palpas[c+1];
/* Conversion to LoadRGB() format */
/* La convierto a formato LoadRGB32() */
palrgb[c+1]=(((ULONG)(palsum[c+1])<<16)|65536);
/* Blue component - componente B (azul) */
palsum[c+2]=palsum[c+2]+palpas[c+2];
/* Conversion to LoadRGB() format */
/* Convierto componente B a formato LoadRGB32() */
palrgb[c+2]=(((ULONG)(palsum[c+2])<<16)|65536);
}
/* First and last list element (LoadRGB()) */
/* Primer elemento y último de lista para LoadRGB32() */
palrgb[0] =32L<<16+0;
palrgb[97]=0;
/* The ideal delay */
/* El retraso ideal: no es posible un retraso menor y */
/* un valor mayor realiza un fundido demasiado lento. La */
/* utilización de esta función de retardo hace que du- */
/* rante el fundido, la CPU no se vea especialmente ago- */
/* biada de trabajo. */
Delay(1);
/* Changing the palette's screen */
/* Cambiando la paleta en la pantalla indicada */
LoadRGB32(&pant->ViewPort,palrgb);
}
}
/* Not fade: zero steps - With fade: rounding */
/* Si no hay fundido ... el fundido es de CERO pasos ;) */
/* Si lo hay... ¡evita pérdidas por redondeos! */
LoadRGB32(&pant->ViewPort,palfin);
}
/* ----------------------------------------------------------------------- */
/* Rutina de generación paleta monocolor aletoria en formato LoadRGB32 () */
/* v. 2.0 © 1995 - Dámaso Domínguez Estévez */
/* > To generate a random monocolor palette < */
/*
Prototipe/prototipo:
void GenerarPalMono (ULONG *,unsigned int,BOOL)
Parameters/parámetros:
ULONG *palmono pointer to palette
(filled by the routine),
unsigned int numcol colours number
BOOL colornegro switch (on=black palette, off=random)
Return/devuelve:
void
Note/notas:
La función genera o una paleta en negro o una paleta aleatoria;
en este último caso los colores rondarán el 10%-40% por componente
de manera que nunca serán demasiado intensos ni demasiado oscuros.
This function generate or a black palette or a random palette;
at this last case, the colours will be some dark
(10%-40% for each component).
*/
void GenerarPalMono(ULONG *palmono,unsigned int numcol,BOOL negro)
{
register int b;
/* Initializing palette */
/* Inicializa la paleta a 0 (me ahorra trabajo si 'negro' es TRUE) */
memset(palmono,0L,(numcol*3+2)*4);
if(!negro) {
/* Random colour */
/* Genera al azar un color para registro 1 (componentes R, G y B) */
for(b=1;b<=3;b++) {
palmono[b]=(((ULONG)(RangeRand(19660)+6553)<<16)|65536);
}
/* Copying components */
/* Copia dicho color (sus componentes) en los demás */
/* por lo que todos los colores serán ¡iguales!. */
for(b=4;b<=96;b=b+3) {
palmono [b]=palmono[1];
palmono[b+1]=palmono[2];
palmono[b+2]=palmono[3];
}
}
/* First element (LoadRGB32() format) */
/* Primer elemento de la lista 'palmono' en formato LoadRGB32() */
/* (último ya inicializado a cero gracias a 'memset'). */
palmono[0] =((ULONG)numcol)<<16+0;
}
See you later | Nos leemos...
AmiSpaTra (Fidonet 2:348/613.44)
--
... #Nombre de usu@rio cifrado con ROT-1/User n@me encrypted with ROT-1#
>>- Read the colours in an array.
>>- Repeat
>> - Multiply the values in the array by a factor smaller than 1
> Hmm exactly what value should this be? I tried several, none worked well..
>> - Change the colours of the screen via LoadRGB4() or LoadRGB32()
>>- until the screen is dark
>>- Set the screen to all black
> This is more or less the way i was doing it:
> - load the screen palette into an array, then:
> - compare each element with the destination color or palette (also on an ar
> - if lower increase, if higher decrease: add or subtract $0111 (since it's
> RGB values)
The problem is, if your source color is for example $f85 and your
destination color $8f5, you can't just add or substract $111. You should
substract 1 to the red value, add 1 to the green value and leave blue
unchanged. In fact you should treat each r,g,b component separately.
--
Antoine 'MORB' Chavasse / CdBS Software
Explore CdBS homepage : http://www.CdBSSoftware.net
/*
** time goes from 0 to 256
*/
void fade(unsigned char *palette, int time)
{
for (i = 0; i < 256; i++)
{
int r = *palette++;
int g = *palette++;
int b = *palette++;
r *= time;
g *= time;
b *= time;
r >>= 8;
g >>= 8;
b >>= 8;
palette_set_colour(r, g, b, i);
}
}
Or if you want to fade between two palettes (which seems to be what
he wanted ?)
void fade(unsigned char *p1, unsigned char *p2, int time)
{
for (i = 0; i < 256; i++)
{
int r = *p1++;
int g = *p1++;
int b = *p1++;
r *= (256-time);
g *= (256-time);
b *= (256-time);
r += (*p2++)*time;
g += (*p2++)*time;
b += (*p2++)*time;
r >>= 8;
g >>= 8;
b >>= 8;
palette_set_colour(r, g, b, i);
}
}
--
<--/---\------76-cols-----------------^-----Your-Name-Here----Something---->
/ Small*<-Perth Make Your Very 4 rows em...@address.here witty some
/ Ascii \ Own Signature File! | Profession Here dead guy
\ Picture / Follow The Instructions v Other Personal Info said here