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

  1. #include <vd2/system/vdtypes.h>
  2. #include <vd2/system/memory.h>
  3. #include <vd2/system/vdstl.h>
  4. #include <vd2/Kasumi/pixmap.h>
  5. #include <vd2/Kasumi/pixmaputils.h>
  6.  
  7. #include "bitutils.h"
  8. #include "blt_spanutils.h"
  9.  
  10. #define DECLARE_YUV(x, y) void VDPixmapBlt_##x##_to_##y##_reference(void *dst0, ptrdiff_t dstpitch, const void *src0, ptrdiff_t srcpitch, vdpixsize w, vdpixsize h)
  11. #define DECLARE_YUV_PLANAR(x, y) void VDPixmapBlt_##x##_to_##y##_reference(const VDPixmap& dst, const VDPixmap& src, vdpixsize w, vdpixsize h)
  12.  
  13. using namespace nsVDPixmapBitUtils;
  14. using namespace nsVDPixmapSpanUtils;
  15.  
  16. DECLARE_YUV(XVYU, UYVY) {
  17.     uint32 *dst = (uint32 *)dst0;
  18.     const uint32 *src = (const uint32 *)src0;
  19.  
  20.     srcpitch -= (w&~1)*4;
  21.     dstpitch -= (w&~1)*2;
  22.  
  23.     do {
  24.         vdpixsize wt = w;
  25.  
  26.         wt = -wt;
  27.  
  28.         if (++wt) {
  29.             uint32 a, b, c;
  30.  
  31.             a = src[0];
  32.             b = src[1];
  33.             *dst++ = (avg_8888_121(a, a, b) & 0xff00ff) + (a & 0xff00) + ((b & 0xff00)<<16);
  34.             src += 2;
  35.  
  36.             if ((wt+=2) < 0) {
  37.                 do {
  38.                     a = src[-1];
  39.                     b = src[0];
  40.                     c = src[1];
  41.  
  42.                     *dst++ = (avg_8888_121(a, b, c) & 0xff00ff) + (b & 0xff00) + ((c & 0xff00)<<16);
  43.                     src += 2;
  44.                 } while((wt+=2) < 0);
  45.             }
  46.         }
  47.  
  48.         if (!(wt&1))
  49.             *dst = *src;
  50.  
  51.         vdptrstep(src, srcpitch);
  52.         vdptrstep(dst, dstpitch);
  53.     } while(--h);
  54. }
  55.  
  56. DECLARE_YUV(XVYU, YUYV) {
  57.     uint32 *dst = (uint32 *)dst0;
  58.     const uint32 *src = (const uint32 *)src0;
  59.  
  60.     srcpitch -= (w&~1)*4;
  61.     dstpitch -= (w&~1)*2;
  62.  
  63.     do {
  64.         vdpixsize wt = w;
  65.  
  66.         wt = -wt;
  67.  
  68.         if (++wt) {
  69.             uint32 a, b, c;
  70.  
  71.             a = src[0];
  72.             b = src[1];
  73.             *dst++ = ((avg_8888_121(a, a, b) & 0xff00ff)<<8) + ((a & 0xff00)>>8) + ((b & 0xff00)<<8);
  74.             src += 2;
  75.  
  76.             if ((wt+=2)<0) {
  77.                 do {
  78.                     a = src[-1];
  79.                     b = src[0];
  80.                     c = src[1];
  81.  
  82.                     *dst++ = ((avg_8888_121(a, b, c) & 0xff00ff)<<8) + ((b & 0xff00)>>8) + ((c & 0xff00)<<8);
  83.                     src += 2;
  84.                 } while((wt+=2) < 0);
  85.             }
  86.         }
  87.  
  88.         if (!(wt&1)) {
  89.             uint32 v = *src;
  90.             *dst = ((v&0xff00ff)<<8) + ((v&0xff00ff00)>>8);
  91.         }
  92.  
  93.         vdptrstep(src, srcpitch);
  94.         vdptrstep(dst, dstpitch);
  95.     } while(--h);
  96. }
  97.  
  98. DECLARE_YUV(UYVY, YUYV) {            // also YUYV->UYVY
  99.     uint32 *dst = (uint32 *)dst0;
  100.     const uint32 *src = (const uint32 *)src0;
  101.  
  102.     w = (w+1) >> 1;
  103.  
  104.     dstpitch -= 4*w;
  105.     srcpitch -= 4*w;
  106.  
  107.     do {
  108.         vdpixsize w2 = w;
  109.  
  110.         do {
  111.             const uint32 p = *src++;
  112.  
  113.             *dst++ = ((p & 0xff00ff00)>>8) + ((p & 0x00ff00ff)<<8);
  114.         } while(--w2);
  115.  
  116.         vdptrstep(src, srcpitch);
  117.         vdptrstep(dst, dstpitch);
  118.     } while(--h);
  119. }
  120.  
  121. DECLARE_YUV(UYVY, Y8) {
  122.     uint8 *dst = (uint8 *)dst0;
  123.     const uint8 *src = (const uint8 *)src0;
  124.  
  125.     dstpitch -= w;
  126.     srcpitch -= 2*w;
  127.  
  128.     do {
  129.         vdpixsize w2 = w;
  130.  
  131.         do {
  132.             *dst++ = src[1];
  133.             src += 2;
  134.         } while(--w2);
  135.  
  136.         vdptrstep(src, srcpitch);
  137.         vdptrstep(dst, dstpitch);
  138.     } while(--h);
  139. }
  140.  
  141. DECLARE_YUV(YUYV, Y8) {
  142.     uint8 *dst = (uint8 *)dst0;
  143.     const uint8 *src = (const uint8 *)src0;
  144.  
  145.     dstpitch -= w;
  146.     srcpitch -= 2*w;
  147.  
  148.     do {
  149.         vdpixsize w2 = w;
  150.  
  151.         do {
  152.             *dst++ = src[0];
  153.             src += 2;
  154.         } while(--w2);
  155.  
  156.         vdptrstep(src, srcpitch);
  157.         vdptrstep(dst, dstpitch);
  158.     } while(--h);
  159. }
  160.  
  161. DECLARE_YUV(Y8, UYVY) {
  162.     uint8 *dst = (uint8 *)dst0;
  163.     const uint8 *src = (const uint8 *)src0;
  164.  
  165.     dstpitch -= 2*w;
  166.     srcpitch -= w;
  167.  
  168.     do {
  169.         vdpixsize w2 = w;
  170.  
  171.         do {
  172.             dst[0] = 0x80;
  173.             dst[1] = *src++;
  174.             dst += 2;
  175.         } while(--w2);
  176.  
  177.         if (w & 1) {
  178.             dst[0] = 0x80;
  179.             dst[1] = dst[-1];
  180.         }
  181.  
  182.         vdptrstep(src, srcpitch);
  183.         vdptrstep(dst, dstpitch);
  184.     } while(--h);
  185. }
  186.  
  187. DECLARE_YUV(Y8, YUYV) {
  188.     uint8 *dst = (uint8 *)dst0;
  189.     const uint8 *src = (const uint8 *)src0;
  190.  
  191.     dstpitch -= 2*w;
  192.     srcpitch -= w;
  193.  
  194.     do {
  195.         vdpixsize w2 = w;
  196.  
  197.         do {
  198.             dst[0] = *src++;
  199.             dst[1] = 0x80;
  200.             dst += 2;
  201.         } while(--w2);
  202.  
  203.         if (w & 1) {
  204.             dst[0] = dst[-1];
  205.             dst[1] = 0x80;
  206.         }
  207.  
  208.         vdptrstep(src, srcpitch);
  209.         vdptrstep(dst, dstpitch);
  210.     } while(--h);
  211. }
  212.  
  213. DECLARE_YUV_PLANAR(YUV411, YV12) {
  214.     VDMemcpyRect(dst.data, dst.pitch, src.data, src.pitch, w, h);
  215.  
  216.     vdblock<uint8> tmprow(w);    
  217.     const uint8 *srcp = (const uint8 *)src.data2;
  218.     ptrdiff_t srcpitch = src.pitch2;
  219.     uint8 *dstp = (uint8 *)dst.data2;
  220.     ptrdiff_t dstpitch = dst.pitch2;
  221.     const uint8 *src1, *src2;
  222.  
  223.     vdpixsize h2;
  224.     for(h2 = h; h2 > 0; h2 -= 2) {
  225.         src1 = srcp;
  226.         vdptrstep(srcp, srcpitch);
  227.         if (h2 > 1)
  228.             src2 = srcp;
  229.         else
  230.             src2 = src1;
  231.         vdptrstep(srcp, srcpitch);
  232.  
  233.         const uint8 *sources[2] = {src1, src2};
  234.  
  235.         vert_compress2x_centered_fast(tmprow.data(), sources, w, 0);
  236.         horiz_expand2x_coaligned(dstp, tmprow.data(), w);
  237.  
  238.         vdptrstep(dstp, dstpitch);
  239.     }
  240.  
  241.     srcp = (const uint8 *)src.data3;
  242.     srcpitch = src.pitch3;
  243.     dstp = (uint8 *)dst.data3;
  244.     dstpitch = dst.pitch3;
  245.     for(h2 = h; h2 > 0; h2 -= 2) {
  246.         src1 = srcp;
  247.         vdptrstep(srcp, srcpitch);
  248.         if (h2 > 1)
  249.             src2 = srcp;
  250.         else
  251.             src2 = src1;
  252.         vdptrstep(srcp, srcpitch);
  253.  
  254.         const uint8 *sources[2] = {src1, src2};
  255.         vert_compress2x_centered_fast(tmprow.data(), sources, w, 0);
  256.         horiz_expand2x_coaligned(dstp, tmprow.data(), w);
  257.  
  258.         vdptrstep(dstp, dstpitch);
  259.     }
  260. }
  261.