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 / blt_spanutils_x86.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2009-09-14  |  4.5 KB  |  171 lines

  1. //    VirtualDub - Video processing and capture application
  2. //    Graphics support library
  3. //    Copyright (C) 1998-2007 Avery Lee
  4. //
  5. //    This program is free software; you can redistribute it and/or modify
  6. //    it under the terms of the GNU General Public License as published by
  7. //    the Free Software Foundation; either version 2 of the License, or
  8. //    (at your option) any later version.
  9. //
  10. //    This program is distributed in the hope that it will be useful,
  11. //    but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. //    GNU General Public License for more details.
  14. //
  15. //    You should have received a copy of the GNU General Public License
  16. //    along with this program; if not, write to the Free Software
  17. //    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  
  19. #include "blt_spanutils_x86.h"
  20.  
  21. #ifdef _MSC_VER
  22.     #pragma warning(disable: 4799)        // warning C4799: function 'nsVDPixmapSpanUtils::vdasm_horiz_expand2x_coaligned_ISSE' has no EMMS instruction
  23. #endif
  24.  
  25. extern "C" void __cdecl vdasm_horiz_expand2x_coaligned_ISSE(void *dst, const void *src, uint32 count);
  26. extern "C" void __cdecl vdasm_horiz_expand4x_coaligned_MMX(void *dst, const void *src, uint32 count);
  27. extern "C" void __cdecl vdasm_vert_average_13_ISSE(void *dst, const void *src1, const void *src3, uint32 count);
  28. extern "C" void __cdecl vdasm_vert_average_17_ISSE(void *dst, const void *src1, const void *src3, uint32 count);
  29. extern "C" void __cdecl vdasm_vert_average_35_ISSE(void *dst, const void *src1, const void *src3, uint32 count);
  30.  
  31. namespace nsVDPixmapSpanUtils {
  32.  
  33.     void horiz_expand2x_coaligned_ISSE(uint8 *dst, const uint8 *src, sint32 w) {
  34.         if (w >= 17) {
  35.             uint32 fastcount = (w - 1) & ~15;
  36.  
  37.             vdasm_horiz_expand2x_coaligned_ISSE(dst, src, fastcount);
  38.             dst += fastcount;
  39.             src += fastcount >> 1;
  40.             w -= fastcount;
  41.         }
  42.  
  43.         w = -w;
  44.         if ((w+=2) < 0) {
  45.             do {
  46.                 dst[0] = src[0];
  47.                 dst[1] = (uint8)((src[0] + src[1] + 1)>>1);
  48.                 dst += 2;
  49.                 ++src;
  50.             } while((w+=2)<0);
  51.         }
  52.  
  53.         w -= 2;
  54.         while(w < 0) {
  55.             ++w;
  56.             *dst++ = src[0];
  57.         }
  58.     }
  59.  
  60.     void horiz_expand4x_coaligned_MMX(uint8 *dst, const uint8 *src, sint32 w) {
  61.         if (w >= 17) {
  62.             uint32 fastcount = (w - 1) >> 4;
  63.  
  64.             vdasm_horiz_expand4x_coaligned_MMX(dst, src, fastcount);
  65.             dst += fastcount << 4;
  66.             src += fastcount << 2;
  67.             w -= fastcount << 4;
  68.         }
  69.  
  70.         w = -w;
  71.         if ((w+=4) < 0) {
  72.             do {
  73.                 dst[0] = src[0];
  74.                 dst[1] = (uint8)((3*src[0] + src[1] + 2)>>2);
  75.                 dst[2] = (uint8)((src[0] + src[1] + 1)>>1);
  76.                 dst[3] = (uint8)((src[0] + 3*src[1] + 2)>>2);
  77.                 dst += 4;
  78.                 ++src;
  79.             } while((w+=4)<0);
  80.         }
  81.  
  82.         w -= 4;
  83.         while(w < 0) {
  84.             ++w;
  85.             *dst++ = src[0];
  86.         }
  87.     }
  88.  
  89.     void vert_expand2x_centered_ISSE(uint8 *dst, const uint8 *const *srcs, sint32 w, uint8 phase) {
  90.         const uint8 *src3 = srcs[0];
  91.         const uint8 *src1 = srcs[1];
  92.  
  93.         if (phase >= 128)
  94.             std::swap(src1, src3);
  95.  
  96.         uint32 fastcount = w & ~15;
  97.  
  98.         if (fastcount) {
  99.             vdasm_vert_average_13_ISSE(dst, src1, src3, fastcount);
  100.             dst += fastcount;
  101.             src1 += fastcount;
  102.             src3 += fastcount;
  103.             w -= fastcount;
  104.         }
  105.  
  106.         if (w) {
  107.             do {
  108.                 *dst++ = (uint8)((*src1++ + 3**src3++ + 2) >> 2);
  109.             } while(--w);
  110.         }
  111.     }
  112.  
  113.     void vert_average_1_7_ISSE(uint8 *dst, const uint8 *src7, const uint8 *src1, sint32 w) {
  114.         uint32 fastcount = w & ~7;
  115.  
  116.         if (fastcount) {
  117.             vdasm_vert_average_17_ISSE(dst, src1, src7, fastcount);
  118.             dst += fastcount;
  119.             src1 += fastcount;
  120.             src7 += fastcount;
  121.             w -= fastcount;
  122.         }
  123.  
  124.         if (w) {
  125.             do {
  126.                 *dst++ = (uint8)((*src1++ + 7**src7++ + 4) >> 3);
  127.             } while(--w);
  128.         }
  129.     }
  130.  
  131.     void vert_average_3_5_ISSE(uint8 *dst, const uint8 *src7, const uint8 *src1, sint32 w) {
  132.         uint32 fastcount = w & ~7;
  133.  
  134.         if (fastcount) {
  135.             vdasm_vert_average_35_ISSE(dst, src1, src7, fastcount);
  136.             dst += fastcount;
  137.             src1 += fastcount;
  138.             src7 += fastcount;
  139.             w -= fastcount;
  140.         }
  141.  
  142.         if (w) {
  143.             do {
  144.                 *dst++ = (uint8)((3**src1++ + 5**src7++ + 4) >> 3);
  145.             } while(--w);
  146.         }
  147.     }
  148.  
  149.     void vert_expand4x_centered_ISSE(uint8 *dst, const uint8 *const *srcs, sint32 w, uint8 phase) {
  150.         const uint8 *src1 = srcs[0];
  151.         const uint8 *src2 = srcs[1];
  152.  
  153.         switch(phase & 0xc0) {
  154.         case 0x00:
  155.             vert_average_1_7_ISSE(dst, src2, src1, w);
  156.             break;
  157.         case 0x40:
  158.             vert_average_3_5_ISSE(dst, src2, src1, w);
  159.             break;
  160.         case 0x80:
  161.             vert_average_3_5_ISSE(dst, src1, src2, w);
  162.             break;
  163.         case 0xc0:
  164.             vert_average_1_7_ISSE(dst, src1, src2, w);
  165.             break;
  166.         default:
  167.             VDNEVERHERE;
  168.         }
  169.     }
  170. }
  171.