# CrossFadeCels

Crossfades between two cels.

### Synopsis

`CCB * CrossFadeCels (Item screen, int32 step, CCB *oldCel, CCB *newCel)`

### Description

Calculates and optionally draws a 16-level crossfade between two cels. The crossfade is accomplished in sixteen equal steps by sixteen calls to this function with the step parameter varying between 0 and 15 on each subsequent call. Step 0 draws oldCel at 15/16 intensity and newCel at 1/16 intensity, step 1 draws 14/16 oldCel and 2/16 newCel, and so on up to step 15 which is 0/16 oldCel and 16/16 newCel (that is, oldCel is not drawn and newCel is drawn as opaque).

The screen parameter can be either a Screen or Bitmap item, in which case the cels are drawn on each call. It can also be zero, in which case the calculations are done but the cels are not drawn. In the latter case, the return value is a pointer to the cels you must draw; the oldCel and newCel CCBs will be linked together in the right order for drawing. As the crossfade progresses the order in which the cels are drawn changes, so if you pass zero for the screen item you must draw the cels based on this function's return value.

This function make certain assumptions about the cels. If the cels don't match the assumptions your mileage may vary, visually. Both cels should be single cels, not lists of cels and not anti-aliased cels. Both cels should project to the same screen area. If the cels contain transparency in differing locations and there are non-black pixels under the transparency area in the bitmap, the results may not be what you expect in that area. Coded-8 cels won't work because their AMV-based scaling can't be mixed with the PIXC-based scaling set up by this function. The ccb_NextPtr, PIXC word, and CCB_LAST flag values in both cels are modified on each call. After the last call (step=15) both cel's PIXC words are reset to 0x1F001F00, both cel's CCB_LAST flags are set, and both cels' ccb_NextPtr links are NULL. If this doesn't work for your needs, save and restore these values yourself, or clone the CCBs and pass the clones to this function.

Other than the limitations and assumptions mentioned above, any type of cels should work just fine (E.G., coded/uncoded, packed/not-packed, any flags settings, any PLUT values, any size/perspective mapping, etc.). The two cels can be different types.

Each cel is drawn just once; no intermediate prescale-the-bitmap drawing is done.

This function is coded so that you can start at any fade level, and skip intermediate levels if you want. The last step should not be skipped, because it's the one that restores the PIXC words. You can call anystep multiple times.

### Arguments

screen
  Screen or Bitmap item to which the cels are drawn, or zero to bypass the internal drawing step.

step
  Value between 0 and 15 inclusive.

oldCel
  Pointer to the old (outgoing) cel.

newCel
  Pointer to the new (incoming) cel.

### Return Value

Pointer to the cels to be drawn, useful only if the screen parameter was zero to bypass internal drawing.

### Implementation

Library call implemented in lib3do.lib.

### Associated Files

lib3do.lib, celutils.h

### See Also

`CrossFadeCels8`