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

  1. #include <vd2/system/halffloat.h>
  2. #include <vd2/system/math.h>
  3. #include "uberblit_v210.h"
  4.  
  5. ///////////////////////////////////////////////////////////////////////////////
  6.  
  7. void VDPixmapGen_32F_To_V210::Compute(void *dst0, sint32 y) {
  8.     uint32 *dst = (uint32 *)dst0;
  9.     const float *srcR = (const float *)mpSrcR->GetRow(y, mSrcIndexR);
  10.     const float *srcG = (const float *)mpSrcG->GetRow(y, mSrcIndexG);
  11.     const float *srcB = (const float *)mpSrcB->GetRow(y, mSrcIndexB);
  12.  
  13.     VDCPUCleanupExtensions();
  14.  
  15.     int w6 = mWidth / 6;
  16.     for(sint32 i=0; i<w6; ++i) {
  17.         float r0 = srcR[0];
  18.         float r1 = srcR[1];
  19.         float r2 = srcR[2];
  20.         srcR += 3;
  21.  
  22.         float b0 = srcB[0];
  23.         float b1 = srcB[1];
  24.         float b2 = srcB[2];
  25.         srcB += 3;
  26.  
  27.         float g0 = srcG[0];
  28.         float g1 = srcG[1];
  29.         float g2 = srcG[2];
  30.         float g3 = srcG[3];
  31.         float g4 = srcG[4];
  32.         float g5 = srcG[5];
  33.         srcG += 6;
  34.  
  35.         if (r0 < 0.0f) r0 = 0.0f; else if (r0 > 1.0f) r0 = 1.0f;
  36.         if (r1 < 0.0f) r1 = 0.0f; else if (r1 > 1.0f) r1 = 1.0f;
  37.         if (r2 < 0.0f) r2 = 0.0f; else if (r2 > 1.0f) r2 = 1.0f;
  38.         if (g0 < 0.0f) g0 = 0.0f; else if (g0 > 1.0f) g0 = 1.0f;
  39.         if (g1 < 0.0f) g1 = 0.0f; else if (g1 > 1.0f) g1 = 1.0f;
  40.         if (g2 < 0.0f) g2 = 0.0f; else if (g2 > 1.0f) g2 = 1.0f;
  41.         if (g3 < 0.0f) g3 = 0.0f; else if (g3 > 1.0f) g3 = 1.0f;
  42.         if (g4 < 0.0f) g4 = 0.0f; else if (g4 > 1.0f) g4 = 1.0f;
  43.         if (g5 < 0.0f) g5 = 0.0f; else if (g5 > 1.0f) g5 = 1.0f;
  44.         if (b0 < 0.0f) b0 = 0.0f; else if (b0 > 1.0f) b0 = 1.0f;
  45.         if (b1 < 0.0f) b1 = 0.0f; else if (b1 > 1.0f) b1 = 1.0f;
  46.         if (b2 < 0.0f) b2 = 0.0f; else if (b2 > 1.0f) b2 = 1.0f;
  47.  
  48.         uint32 ir0 = (uint32)VDRoundToIntFast(r0 * 1024.0f);
  49.         uint32 ir1 = (uint32)VDRoundToIntFast(r1 * 1024.0f);
  50.         uint32 ir2 = (uint32)VDRoundToIntFast(r2 * 1024.0f);
  51.         uint32 ib0 = (uint32)VDRoundToIntFast(b0 * 1024.0f);
  52.         uint32 ib1 = (uint32)VDRoundToIntFast(b1 * 1024.0f);
  53.         uint32 ib2 = (uint32)VDRoundToIntFast(b2 * 1024.0f);
  54.         uint32 ig0 = (uint32)VDRoundToIntFast(g0 * 1024.0f);
  55.         uint32 ig1 = (uint32)VDRoundToIntFast(g1 * 1024.0f);
  56.         uint32 ig2 = (uint32)VDRoundToIntFast(g2 * 1024.0f);
  57.         uint32 ig3 = (uint32)VDRoundToIntFast(g3 * 1024.0f);
  58.         uint32 ig4 = (uint32)VDRoundToIntFast(g4 * 1024.0f);
  59.         uint32 ig5 = (uint32)VDRoundToIntFast(g5 * 1024.0f);
  60.  
  61.         // dword 0: XX Cr0 Y0 Cb0
  62.         // dword 1: XX Y2 Cb1 Y1
  63.         // dword 2: XX Cb2 Y3 Cr1
  64.         // dword 3: XX Y5 Cr2 Y4
  65.         dst[0] = (ir0 << 20) + (ig0 << 10) + ib0;
  66.         dst[1] = (ig2 << 20) + (ib1 << 10) + ig1;
  67.         dst[2] = (ib2 << 20) + (ig3 << 10) + ir1;
  68.         dst[3] = (ig5 << 20) + (ir2 << 10) + ig4;
  69.  
  70.         dst += 4;
  71.     }
  72.  
  73.     int leftovers = mWidth - w6*6;
  74.     if (leftovers) {
  75.         float g0 = 0;
  76.         float g1 = 0;
  77.         float g2 = 0;
  78.         float g3 = 0;
  79.         float g4 = 0;
  80.         float r0 = 0;
  81.         float r1 = 0;
  82.         float r2 = 0;
  83.         float b0 = 0;
  84.         float b1 = 0;
  85.         float b2 = 0;
  86.  
  87.         switch(leftovers) {
  88.             case 5:    r2 = srcR[2];
  89.                     b2 = srcB[2];
  90.                     g4 = srcG[4];
  91.             case 4:    g3 = srcG[3];
  92.             case 3:    r1 = srcR[1];
  93.                     b1 = srcB[1];
  94.                     g2 = srcG[2];
  95.             case 2:    g1 = srcG[1];
  96.             case 1:    r0 = srcR[0];
  97.                     b0 = srcB[0];
  98.                     g0 = srcG[0];
  99.         }
  100.  
  101.         if (r0 < 0.0f) r0 = 0.0f; else if (r0 > 1.0f) r0 = 1.0f;
  102.         if (r1 < 0.0f) r1 = 0.0f; else if (r1 > 1.0f) r1 = 1.0f;
  103.         if (r2 < 0.0f) r2 = 0.0f; else if (r2 > 1.0f) r2 = 1.0f;
  104.         if (g0 < 0.0f) g0 = 0.0f; else if (g0 > 1.0f) g0 = 1.0f;
  105.         if (g1 < 0.0f) g1 = 0.0f; else if (g1 > 1.0f) g1 = 1.0f;
  106.         if (g2 < 0.0f) g2 = 0.0f; else if (g2 > 1.0f) g2 = 1.0f;
  107.         if (g3 < 0.0f) g3 = 0.0f; else if (g3 > 1.0f) g3 = 1.0f;
  108.         if (g4 < 0.0f) g4 = 0.0f; else if (g4 > 1.0f) g4 = 1.0f;
  109.         if (b0 < 0.0f) b0 = 0.0f; else if (b0 > 1.0f) b0 = 1.0f;
  110.         if (b1 < 0.0f) b1 = 0.0f; else if (b1 > 1.0f) b1 = 1.0f;
  111.         if (b2 < 0.0f) b2 = 0.0f; else if (b2 > 1.0f) b2 = 1.0f;
  112.  
  113.         uint32 ir0 = (uint32)VDRoundToIntFast(r0 * 1024.0f);
  114.         uint32 ir1 = (uint32)VDRoundToIntFast(r1 * 1024.0f);
  115.         uint32 ir2 = (uint32)VDRoundToIntFast(r2 * 1024.0f);
  116.         uint32 ib0 = (uint32)VDRoundToIntFast(b0 * 1024.0f);
  117.         uint32 ib1 = (uint32)VDRoundToIntFast(b1 * 1024.0f);
  118.         uint32 ib2 = (uint32)VDRoundToIntFast(b2 * 1024.0f);
  119.         uint32 ig0 = (uint32)VDRoundToIntFast(g0 * 1024.0f);
  120.         uint32 ig1 = (uint32)VDRoundToIntFast(g1 * 1024.0f);
  121.         uint32 ig2 = (uint32)VDRoundToIntFast(g2 * 1024.0f);
  122.         uint32 ig3 = (uint32)VDRoundToIntFast(g3 * 1024.0f);
  123.         uint32 ig4 = (uint32)VDRoundToIntFast(g4 * 1024.0f);
  124.  
  125.         // dword 0: XX Cr0 Y0 Cb0
  126.         // dword 1: XX Y2 Cb1 Y1
  127.         // dword 2: XX Cb2 Y3 Cr1
  128.         // dword 3: XX Y5 Cr2 Y4
  129.         dst[0] = (ir0 << 20) + (ig0 << 10) + ib0;
  130.         dst[1] = (ig2 << 20) + (ib1 << 10) + ig1;
  131.         dst[2] = (ib2 << 20) + (ig3 << 10) + ir1;
  132.         dst[3] =               (ir2 << 10) + ig4;
  133.         dst += 4;
  134.     }
  135.  
  136.     // QuickTime defines the v210 format and requires zero padding in all unused samples.
  137.     int w48up = (mWidth + 23) / 24;
  138.     int w6up = (mWidth + 5) / 6;
  139.     int zeropad = w48up * 16 - w6up * 4;
  140.     memset(dst, 0, zeropad * 4);
  141. }
  142.  
  143. ///////////////////////////////////////////////////////////////////////////////
  144.  
  145. void VDPixmapGen_V210_To_32F::Start() {
  146.     StartWindow(((mWidth + 5) / 6) * 6 * sizeof(float), 3);
  147. }
  148.  
  149. const void *VDPixmapGen_V210_To_32F::GetRow(sint32 y, uint32 index) {
  150.     return (const uint8 *)VDPixmapGenWindowBasedOneSource::GetRow(y, index) + mWindowPitch * index;
  151. }
  152.  
  153. sint32 VDPixmapGen_V210_To_32F::GetWidth(int index) const {
  154.     return index == 1 ? mWidth : (mWidth + 1) >> 1;
  155. }
  156.  
  157. uint32 VDPixmapGen_V210_To_32F::GetType(uint32 output) const {
  158.     return (mpSrc->GetType(mSrcIndex) & ~kVDPixType_Mask) | kVDPixType_32F_LE;
  159. }
  160.  
  161. void VDPixmapGen_V210_To_32F::Compute(void *dst0, sint32 y) {
  162.     float *dstR = (float *)dst0;
  163.     float *dstG = (float *)((char *)dstR + mWindowPitch);
  164.     float *dstB = (float *)((char *)dstG + mWindowPitch);
  165.     const uint32 *src = (const uint32 *)mpSrc->GetRow(y, mSrcIndex);
  166.     uint32 w = (mWidth + 5) / 6;
  167.  
  168.     VDCPUCleanupExtensions();
  169.  
  170.     // dword 0: XX Cr0 Y0 Cb0
  171.     // dword 1: XX Y2 Cb1 Y1
  172.     // dword 2: XX Cb2 Y3 Cr1
  173.     // dword 3: XX Y5 Cr2 Y4
  174.  
  175.     for(uint32 i=0; i<w; ++i) {
  176.         const uint32 w0 = src[0];
  177.         const uint32 w1 = src[1];
  178.         const uint32 w2 = src[2];
  179.         const uint32 w3 = src[3];
  180.         src += 4;
  181.  
  182.         dstB[0] = (float)( w0        & 0x3ff) / 1023.0f;
  183.         dstG[0] = (float)((w0 >> 10) & 0x3ff) / 1023.0f;
  184.         dstR[0] = (float)((w0 >> 20) & 0x3ff) / 1023.0f;
  185.         dstG[1] = (float)( w1        & 0x3ff) / 1023.0f;
  186.         dstB[1] = (float)((w1 >> 10) & 0x3ff) / 1023.0f;
  187.         dstG[2] = (float)((w1 >> 20) & 0x3ff) / 1023.0f;
  188.         dstR[1] = (float)( w2        & 0x3ff) / 1023.0f;
  189.         dstG[3] = (float)((w2 >> 10) & 0x3ff) / 1023.0f;
  190.         dstB[2] = (float)((w2 >> 20) & 0x3ff) / 1023.0f;
  191.         dstG[4] = (float)( w3        & 0x3ff) / 1023.0f;
  192.         dstR[2] = (float)((w3 >> 10) & 0x3ff) / 1023.0f;
  193.         dstG[5] = (float)((w3 >> 20) & 0x3ff) / 1023.0f;
  194.  
  195.         dstR += 3;
  196.         dstG += 6;
  197.         dstB += 3;
  198.     }
  199. }
  200.