// blit an RGBA img, blending matte colour with src alpha onto the dest void BlitMatteRGBA8( Img const& srcimg, Box const& srcbox, Img& destimg, Box& destbox, PenColour const& matte ) { assert(srcimg.Fmt()==FMT_RGBA8); Box destclipped( destbox ); Box srcclipped( srcbox ); clip_blit( srcimg.Bounds(), srcclipped, destimg.Bounds(), destclipped ); const int w = destclipped.w; int y; for( y=0; y<destclipped.h; ++y ) { RGBA8 const* src = srcimg.PtrConst_RGBA8( srcclipped.x+0, srcclipped.y+y ); switch(destimg.Fmt()) { case FMT_I8: scan_matte_RGBA8_I8(src, destimg.Ptr_I8(destclipped.x+0,destclipped.y+y), w, matte.idx()); break; case FMT_RGBX8: scan_matte_RGBA8_RGBX8(src, destimg.Ptr_RGBX8(destclipped.x+0,destclipped.y+y), w, matte.rgb()); break; case FMT_RGBA8: scan_matte_RGBA8_RGBA8(src, destimg.Ptr_RGBA8(destclipped.x+0,destclipped.y+y), w, matte.rgb()); break; default: assert(false); break; } } destbox = destclipped; }
// blit an RGBA img, blending with src alpha onto the dest (must be RGBX8 or RGBA8) void BlitRGBA8( Img const& srcimg, Box const& srcbox, Img& destimg, Box& destbox ) { assert(srcimg.Fmt()==FMT_RGBA8); assert(destimg.Fmt()!=FMT_I8); Box destclipped( destbox ); Box srcclipped( srcbox ); clip_blit( srcimg.Bounds(), srcclipped, destimg.Bounds(), destclipped ); const int w = destclipped.w; int y; for( y=0; y<destclipped.h; ++y ) { RGBA8 const* src = srcimg.PtrConst_RGBA8( srcclipped.x+0, srcclipped.y+y ); switch(destimg.Fmt()) { case FMT_I8: assert(false); // not implemented break; case FMT_RGBX8: scan_RGBA8_RGBX8(src, destimg.Ptr_RGBX8(destclipped.x+0,destclipped.y+y), w); break; case FMT_RGBA8: scan_RGBA8_RGBA8(src, destimg.Ptr_RGBA8(destclipped.x+0,destclipped.y+y), w); break; default: assert(false); break; } } destbox = destclipped; }
// TODO: src,dest names meaningless. Should be a,b or something neutral void BlitSwap( Img& srcimg, Box const& srcbox, Img& destimg, Box& destbox) { assert( srcimg.Fmt() == destimg.Fmt()); Box destclipped( destbox ); Box srcclipped( srcbox ); clip_blit( srcimg.Bounds(), srcclipped, destimg.Bounds(), destclipped ); int y; for( y=0; y<destclipped.h; ++y ) { switch(srcimg.Fmt()) { case FMT_I8: { I8* src = srcimg.Ptr_I8( srcclipped.x+0, srcclipped.y+y ); I8* dest = destimg.Ptr_I8( destclipped.x+0, destclipped.y+y ); std::swap_ranges( src,src+destclipped.w, dest); } break; case FMT_RGBX8: { RGBX8* src = srcimg.Ptr_RGBX8( srcclipped.x+0, srcclipped.y+y ); RGBX8* dest = destimg.Ptr_RGBX8( destclipped.x+0, destclipped.y+y ); std::swap_ranges( src,src+destclipped.w, dest); } break; case FMT_RGBA8: { RGBA8* src = srcimg.Ptr_RGBA8( srcclipped.x+0, srcclipped.y+y ); RGBA8* dest = destimg.Ptr_RGBA8( destclipped.x+0, destclipped.y+y ); std::swap_ranges( src,src+destclipped.w, dest); } break; default: assert(false); break; } } destbox = destclipped; }
// blit from an I8 source to any target, with colourkey transparency void BlitI8Keyed( Img const& srcimg, Box const& srcbox, Palette const& srcpalette, Img& destimg, Box& destbox, int transparentIdx ) { assert(srcimg.Fmt()==FMT_I8); Box destclipped( destbox ); Box srcclipped( srcbox ); clip_blit( srcimg.Bounds(), srcclipped, destimg.Bounds(), destclipped ); const int w = destclipped.w; int y; for( y=0; y<destclipped.h; ++y ) { I8 const* src = srcimg.PtrConst_I8( srcclipped.x+0, srcclipped.y+y ); switch(destimg.Fmt()) { case FMT_I8: scan_I8_I8_keyed(src, destimg.Ptr_I8(destclipped.x+0,destclipped.y+y), w, transparentIdx); break; case FMT_RGBX8: scan_I8_RGBX8_keyed(src, srcpalette, destimg.Ptr_RGBX8(destclipped.x+0,destclipped.y+y), w, transparentIdx); break; case FMT_RGBA8: scan_I8_RGBA8_keyed(src, srcpalette, destimg.Ptr_RGBA8(destclipped.x+0,destclipped.y+y), w, transparentIdx); break; default: assert(false); break; } } destbox = destclipped; }