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

  1. #include "test.h"
  2. #include <vd2/system/vdalloc.h>
  3. #include <vd2/Kasumi/pixel.h>
  4. #include <vd2/Kasumi/pixmap.h>
  5. #include <vd2/Kasumi/pixmapops.h>
  6. #include <vd2/Kasumi/pixmaputils.h>
  7. #include "../../Kasumi/h/uberblit.h"
  8.  
  9. namespace {
  10.     bool CheckBlit(const VDPixmap& dst, const VDPixmap& src) {
  11.         uint32 w = std::min<uint32>(src.w, dst.w);
  12.         uint32 h = std::min<uint32>(src.h, dst.h);
  13.  
  14.         for(uint32 y=0; y<h; ++y) {
  15.             for(uint32 x=0; x<w; ++x) {
  16.                 uint32 p1 = VDPixmapSample(src, x, y);
  17.                 uint32 p2 = VDPixmapSample(dst, x, y);
  18.  
  19.                 int y1 = ((p1 & 0xff00ff)*0x130036 + (p1 & 0xff00)*0xb700) >> 16;
  20.                 int y2 = ((p2 & 0xff00ff)*0x130036 + (p2 & 0xff00)*0xb700) >> 16;
  21.  
  22.                 if (abs(y1 - y2) > 512) {
  23.                     printf("Bitmap comparison failed at (%d, %d) with formats %s and %s: #%06x != #%06x"
  24.                         , x
  25.                         , y
  26.                         , VDPixmapGetInfo(src.format).name
  27.                         , VDPixmapGetInfo(dst.format).name
  28.                         , p1 & 0xffffff
  29.                         , p2 & 0xffffff
  30.                         );
  31.  
  32.                     VDASSERT(false);
  33.                     return false;
  34.                 }
  35.             }
  36.         }
  37.  
  38.         return true;
  39.     }
  40. }
  41.  
  42. DEFINE_TEST(Uberblit) {
  43.     using namespace nsVDPixmap;
  44.  
  45.     // test primary color conversion
  46.     const int size = 8;
  47.  
  48.     static const uint32 kColors[8]={
  49.         0xff000000,
  50.         0xffffffff,
  51.         0xff0000ff,
  52.         0xff00ff00,
  53.         0xff00ffff,
  54.         0xffff0000,
  55.         0xffff00ff,
  56.         0xffffff00,
  57.     };
  58.  
  59.     const int kColorCount = sizeof(kColors)/sizeof(kColors[0]);
  60.  
  61.     VDPixmapBuffer src[kColorCount];
  62.     for(int i=0; i<kColorCount; ++i) {
  63.         src[i].init(size, size, kPixFormat_XRGB8888);
  64.         VDMemset32Rect(src[i].data, src[i].pitch, kColors[i], size, size);
  65.     }
  66.  
  67.     VDPixmapBuffer output(size, size, kPixFormat_XRGB8888);
  68.  
  69.     const VDPixmapFormatInfo& fiSrc = VDPixmapGetInfo(src[0].format);
  70.     const VDPixmapFormatInfo& fiOutput = VDPixmapGetInfo(output.format);
  71.  
  72.     for(int srcformat = nsVDPixmap::kPixFormat_XRGB1555; srcformat < nsVDPixmap::kPixFormat_Max_Standard; ++srcformat) {
  73.         VDPixmapFormat srcformat2 = (VDPixmapFormat)srcformat;
  74.  
  75.         if (srcformat == kPixFormat_YUV444_XVYU)
  76.             continue;
  77.  
  78.         VDPixmapBuffer in[kColorCount];
  79.         vdautoptr<IVDPixmapBlitter> blit1;
  80.                 const VDPixmapFormatInfo& fiIn = VDPixmapGetInfo(in[0].format);
  81.  
  82.         const int maxsrctest = srcformat == kPixFormat_Y8 ? 2 : 8;
  83.  
  84.         for(int v=0; v<maxsrctest; ++v) {
  85.             in[v].init(size, size, srcformat);
  86.  
  87.             if (!v)
  88.                 blit1 = VDPixmapCreateBlitter(in[0], src[0]);
  89.  
  90.             blit1->Blit(in[v], src[v]);
  91.             if (!CheckBlit(in[v], src[v])) goto failed2;
  92.             in[v].validate();
  93.         }
  94.  
  95.         for(int dstformat = nsVDPixmap::kPixFormat_XRGB1555; dstformat < nsVDPixmap::kPixFormat_Max_Standard; ++dstformat) {
  96.             VDPixmapFormat dstformat2 = (VDPixmapFormat)dstformat;
  97.  
  98.             if (dstformat == kPixFormat_YUV444_XVYU)
  99.                 continue;
  100.  
  101.             VDPixmapBuffer out(size, size, dstformat);
  102.  
  103.             int maxtest = (srcformat == kPixFormat_Y8 || dstformat == kPixFormat_Y8) ? 2 : 8;
  104.  
  105.             vdautoptr<IVDPixmapBlitter> blit2(VDPixmapCreateBlitter(out, in[0]));
  106.             vdautoptr<IVDPixmapBlitter> blit3(VDPixmapCreateBlitter(output, out));
  107.  
  108.             const VDPixmapFormatInfo& fiOut = VDPixmapGetInfo(out.format);
  109.  
  110.             for(int v=0; v<maxtest; ++v) {
  111.                 blit2->Blit(out, in[v]);
  112.                 if (!CheckBlit(out, in[v])) goto failed;
  113.                 out.validate();
  114.                 blit3->Blit(output, out);
  115.                 if (!CheckBlit(output, out)) goto failed;
  116.                 output.validate();
  117.  
  118.                 // white and black must be exact
  119.                 if (v < 2) {
  120.                     for(int y=0; y<size; ++y) {
  121.                         const uint32 *sp = (const uint32 *)vdptroffset(src[v].data, src[v].pitch*y);
  122.                         uint32 *dp = (uint32 *)vdptroffset(output.data, output.pitch*y);
  123.  
  124.                         for(int x=0; x<size; ++x) {
  125.                             const uint32 spx = sp[x];
  126.                             const uint32 dpx = dp[x];
  127.  
  128.                             if ((spx ^ dpx) & 0xffffff) {
  129.                                 printf("        Failed: %s -> %s\n", VDPixmapGetInfo(srcformat).name, VDPixmapGetInfo(dstformat).name);
  130.                                 printf("            (%d,%d) %08lx != %08lx\n", x, y, spx, dpx);
  131.                                 VDASSERT(false);
  132.                                 goto failed;
  133.                             }
  134.                         }
  135.                     }
  136.                 } else {
  137.                     for(int y=0; y<size; ++y) {
  138.                         const uint32 *sp = (const uint32 *)vdptroffset(src[v].data, src[v].pitch*y);
  139.                         uint32 *dp = (uint32 *)vdptroffset(output.data, output.pitch*y);
  140.  
  141.                         for(int x=0; x<size; ++x) {
  142.                             const uint32 spx = sp[x];
  143.                             const uint32 dpx = dp[x];
  144.  
  145.                             const int re = (int)((spx>>16)&0xff) - (int)((dpx>>16)&0xff);
  146.                             const int ge = (int)((spx>> 8)&0xff) - (int)((dpx>> 8)&0xff);
  147.                             const int be = (int)((spx    )&0xff) - (int)((dpx    )&0xff);
  148.  
  149.                             if (abs(re) > 1 || abs(ge) > 1 || abs(be) > 1) {
  150.                                 printf("        Failed: %s -> %s\n", VDPixmapGetInfo(srcformat).name, VDPixmapGetInfo(dstformat).name);
  151.                                 printf("            (%d,%d) %08lx != %08lx\n", x, y, spx, dpx);
  152.                                 VDASSERT(false);
  153.                                 goto failed;
  154.                             }
  155.                         }
  156.                     }
  157.                 }
  158. failed:;
  159.             }
  160.         }
  161. failed2:;
  162.     }
  163.     return 0;
  164. }
  165.