home *** CD-ROM | disk | FTP | other *** search
/ Computer Shopper 275 / DPCS0111DVD.ISO / Toolkit / Audio-Visual / VirtualDub / Source / VirtualDub-1.9.10-src.7z / src / Kasumi / source / alphablt.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2009-09-14  |  2.2 KB  |  77 lines

  1. #include <vd2/system/math.h>
  2. #include <vd2/system/cpuaccel.h>
  3. #include <vd2/Kasumi/pixmap.h>
  4. #include <vd2/Kasumi/pixmaputils.h>
  5. #include <vd2/Kasumi/pixmapops.h>
  6.  
  7. void VDPixmapBltAlphaConst8(uint8 *dst, ptrdiff_t dstpitch, const uint8 *src, ptrdiff_t srcpitch, uint32 w, uint32 h, uint32 ialpha);
  8.  
  9. bool VDPixmapBltAlphaConst(const VDPixmap& dst, const VDPixmap& src, float alpha) {
  10.     if (!(alpha >= 0.0f))
  11.         alpha = 0.0f;
  12.     else if (!(alpha <= 1.0f))
  13.         alpha = 1.0f;
  14.  
  15.     uint32 ialpha = VDRoundToInt32(alpha * 256.0f);
  16.  
  17.     // format check
  18.     if (dst.format != src.format || !src.format)
  19.         return false;
  20.  
  21.     // degenerate case check
  22.     if (!dst.w || !dst.h)
  23.         return false;
  24.  
  25.     // size check
  26.     if (src.w != dst.w || src.h != dst.h)
  27.         return false;
  28.  
  29.     // check for formats that are not 8bpp
  30.     switch(src.format) {
  31.         case nsVDPixmap::kPixFormat_Pal1:
  32.         case nsVDPixmap::kPixFormat_Pal2:
  33.         case nsVDPixmap::kPixFormat_Pal4:
  34.         case nsVDPixmap::kPixFormat_Pal8:
  35.         case nsVDPixmap::kPixFormat_RGB565:
  36.         case nsVDPixmap::kPixFormat_XRGB1555:
  37.             return false;
  38.     }
  39.  
  40.     const VDPixmapFormatInfo& formatInfo = VDPixmapGetInfo(src.format);
  41.  
  42.     const int qw = -(-dst.w >> formatInfo.qwbits);
  43.     const int qh = -(-dst.h >> formatInfo.qhbits);
  44.     const int auxw = -(-dst.w >> formatInfo.auxwbits);
  45.     const int auxh = -(-dst.h >> formatInfo.auxhbits);
  46.  
  47.     switch(formatInfo.auxbufs) {
  48.     case 2:
  49.         VDPixmapBltAlphaConst8((uint8 *)dst.data3, dst.pitch3, (const uint8 *)src.data3, src.pitch3, auxw, auxh, ialpha);
  50.     case 1:
  51.         VDPixmapBltAlphaConst8((uint8 *)dst.data2, dst.pitch2, (const uint8 *)src.data2, src.pitch2, auxw, auxh, ialpha);
  52.     case 0:
  53.         VDPixmapBltAlphaConst8((uint8 *)dst.data, dst.pitch, (const uint8 *)src.data, src.pitch, formatInfo.qsize * qw, qh, ialpha);
  54.     }
  55.  
  56.     return true;
  57. }
  58.  
  59. void VDPixmapBltAlphaConst8(uint8 *dst, ptrdiff_t dstpitch, const uint8 *src, ptrdiff_t srcpitch, uint32 w, uint32 h, uint32 ialpha) {
  60.     dstpitch -= w;
  61.     srcpitch -= w;
  62.     do {
  63.         uint32 w2 = w;
  64.         do {
  65.             sint32 sc = *src;
  66.             sint32 dc = *dst;
  67.  
  68.             *dst = dc + (((sc-dc)*ialpha + 128) >> 8);
  69.             ++src;
  70.             ++dst;
  71.         } while(--w2);
  72.  
  73.         src += srcpitch;
  74.         dst += dstpitch;
  75.     } while(--h);
  76. }
  77.