www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/09/05/11:19:54

From: "Mr A. Appleyard" <MCLSSAA2 AT fs2 DOT mt DOT umist DOT ac DOT uk>
Organization: Materials Science Centre
To: DJGPP AT delorie DOT com
Date: Fri, 5 Sep 1997 16:15:31 GMT-1
Subject: Graphics: fading from one image to another
Message-ID: <C7AB5D50A4@fs2.mt.umist.ac.uk>

  If:-
  you program graphics,
    you use only the usual 16 colours (palette numbers 0 to 15)
      you are using a byte-per-pixel screen mode such as 0x13 or VESA 0x101,
  I have just written and tested a compact algorithm to fade smoothly from one
screen image to another.
  Please email to me in person re any enquiries.

#define pk __attribute__((packed))
typedef struct{byte red pk,green pk,blue pk;} palette;
The bytes in the screen images are palette numbers.
The graphical screen address is conventional 0xa0000.
palette C[256],P[16];
The (i*16+j)th palette will contain the current stage in changing a pixel's
  colour from old colour j to new colour i.
New is the required new screen image that you want to fade to.
Create two arrays of bytes Old, W, each big enough to hold a screen image.
Read the current graphical screen to array Old.
for(i=0;i<(screen_size);i++) W[i]=((New[i]&15)<<4)|(Old[i]&15);
Get current palettes 0 to 15 to array P, using int10 with AX=0x1017.
for(i=0;i<=32;i++) { /* loop, gradually changing the colours */
    while(Time()-ct<i*(1./64)); /* alter here to set how long the fade takes */
    for(j=0;j<256;j++) {
        C[j].red  =(P[j>>4].red  *i+P[j&15].red  *(n-i))/32;
        C[j].green=(P[j>>4].green*i+P[j&15].green*(n-i))/32;
        C[j].blue =(P[j>>4].blue *i+P[j&15].blue *(n-i))/32;}
    Set palettes 0 to 255 from array C
    if(!i) copy array W to the screen;}
Next we must change the screen image to look like array New without flashing
  due to an image being momentarily on screen with the wrong set of palettes:-
for(i=0;i<640*480;i++) W[i]=(W[i]&0xf0)+(W[i]>>4);
Copy array W to the screen;
for(i=0;i<256;i++) C[i]=P[i&15]; /* 16 repeats of the standard palette */
Set palettes 0 to 255 from array C, using int10 with AX=0x1012;
Copy array New to the screen.

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019