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

  1. #include <vd2/Kasumi/pixmap.h>
  2. #include <vd2/Kasumi/pixmapops.h>
  3. #include <vd2/Kasumi/pixmaputils.h>
  4. #include <vd2/system/memory.h>
  5. #include <tchar.h>
  6. #include "test.h"
  7.  
  8. DEFINE_TEST(Pixmap) {
  9.     using namespace nsVDPixmap;
  10.  
  11.     // test pal1
  12.     for(int format=kPixFormat_Pal1; format<=kPixFormat_Pal8; ++format) {
  13.  
  14.         _tprintf(_T("    Testing format %hs\n"), VDPixmapGetInfo(format).name);
  15.  
  16.         int testw = 2048 >> (format - kPixFormat_Pal1);
  17.         int teststep = 8 >> (format - kPixFormat_Pal1);
  18.  
  19.         VDPixmapBuffer srcbuf(testw, 2, format);
  20.  
  21.         int palcount = 1 << (1 << (format - kPixFormat_Pal1));
  22.         for(int k=0; k<palcount; ++k) {
  23.             uint32 v = 0;
  24.  
  25.             if (k & 1)
  26.                 v |= 0x000000ff;
  27.             if (k & 2)
  28.                 v |= 0x0000ff00;
  29.             if (k & 4)
  30.                 v |= 0x00ff0000;
  31.             if (k & 8)
  32.                 v |= 0xff000000;
  33.  
  34.             ((uint32 *)srcbuf.palette)[k] = v;
  35.         }
  36.  
  37.         for(int q=0; q<256; ++q)
  38.             ((uint8 *)srcbuf.data)[q] = ((uint8 *)srcbuf.data)[srcbuf.pitch + q] = (uint8)q;
  39.  
  40.         VDInvertMemory(vdptroffset(srcbuf.data, srcbuf.pitch), 256);
  41.  
  42.         VDPixmapBuffer intbuf[4];
  43.         
  44.         intbuf[0].init(testw, 2, kPixFormat_XRGB1555);
  45.         intbuf[1].init(testw, 2, kPixFormat_RGB565);
  46.         intbuf[2].init(testw, 2, kPixFormat_RGB888);
  47.         intbuf[3].init(testw, 2, kPixFormat_XRGB8888);
  48.  
  49.         VDPixmapBuffer dstbuf(testw, 2, kPixFormat_RGB888);
  50.  
  51.         for(int x1=0; x1<testw; x1+=teststep) {
  52.             int xlimit = std::min<int>(testw, x1+64);
  53.             for(int x2=x1+8; x2<xlimit; x2+=teststep) {
  54.                 for(int i=0; i<4; ++i) {
  55.                     VDMemset8Rect(intbuf[i].data, intbuf[i].pitch, 0, intbuf[i].w * VDPixmapGetInfo(intbuf[i].format).qsize, intbuf[i].h);
  56.                     VDVERIFY(VDPixmapBlt(intbuf[i], x1, 0, srcbuf, x1, 0, x2-x1, 2));
  57.                 }
  58.  
  59.                 for(int j=0; j<3; ++j) {
  60.                     VDMemset8Rect(dstbuf.data, dstbuf.pitch, 0, 3*dstbuf.w, dstbuf.h);
  61.                     VDVERIFY(VDPixmapBlt(dstbuf, intbuf[j]));
  62.  
  63.                     VDVERIFY(!VDCompareRect(intbuf[2].data, intbuf[2].pitch, dstbuf.data, dstbuf.pitch, 3*dstbuf.w, dstbuf.h));
  64.                 }
  65.             }
  66.         }
  67.  
  68.     }
  69.  
  70.     // test primary color conversion
  71.     for(int size=7; size<=9; ++size) {
  72.         VDPixmapBuffer src(9, 9, kPixFormat_XRGB8888);
  73.         VDPixmapBuffer output(9, 9, kPixFormat_XRGB8888);
  74.  
  75.         for(int srcformat = nsVDPixmap::kPixFormat_XRGB1555; srcformat < nsVDPixmap::kPixFormat_Max_Standard; ++srcformat) {
  76.             if (srcformat == kPixFormat_YUV444_XVYU)
  77.                 continue;
  78.  
  79.             for(int dstformat = nsVDPixmap::kPixFormat_XRGB1555; dstformat < nsVDPixmap::kPixFormat_Max_Standard; ++dstformat) {
  80.                 if (dstformat == kPixFormat_YUV444_XVYU)
  81.                     continue;
  82.  
  83.                 VDPixmap srccrop(src);
  84.                 srccrop.w = size;
  85.                 srccrop.h = size;
  86.  
  87.                 VDPixmapBuffer in(size, size, srcformat);
  88.                 VDPixmapBuffer out(size, size, dstformat);
  89.  
  90.                 static const uint32 kColors[8]={
  91.                     0xff000000,
  92.                     0xffffffff,
  93.                     0xff0000ff,
  94.                     0xff00ff00,
  95.                     0xff00ffff,
  96.                     0xffff0000,
  97.                     0xffff00ff,
  98.                     0xffffff00,
  99.                 };
  100.  
  101.                 int maxtest = (srcformat == kPixFormat_Y8 || dstformat == kPixFormat_Y8) ? 2 : 8;
  102.  
  103.                 for(int v=0; v<maxtest; ++v) {
  104.                     VDMemset32Rect(src.data, src.pitch, kColors[v], size, size);
  105.  
  106.                     VDVERIFY(VDPixmapBlt(in, srccrop));
  107.                     VDVERIFY(VDPixmapBlt(out, in));
  108.                     VDVERIFY(VDPixmapBlt(output, out));
  109.  
  110.                     for(int y=0; y<size; ++y) {
  111.                         const uint32 *sp = (const uint32 *)vdptroffset(src.data, src.pitch*y);
  112.                         uint32 *dp = (uint32 *)vdptroffset(output.data, output.pitch*y);
  113.  
  114.                         for(int x=0; x<size; ++x) {
  115.                             const uint32 spx = sp[x];
  116.                             const uint32 dpx = dp[x];
  117.  
  118.                             const int re = (int)((spx>>16)&0xff) - (int)((dpx>>16)&0xff);
  119.                             const int ge = (int)((spx>> 8)&0xff) - (int)((dpx>> 8)&0xff);
  120.                             const int be = (int)((spx    )&0xff) - (int)((dpx    )&0xff);
  121.  
  122.                             if (abs(re) > 1 || abs(ge) > 1 || abs(be) > 1) {
  123.                                 printf("        Failed: %s -> %s\n", VDPixmapGetInfo(srcformat).name, VDPixmapGetInfo(dstformat).name);
  124.                                 printf("            (%d,%d) %08lx != %08lx\n", x, y, spx, dpx);
  125.                                 VDASSERT(false);
  126.                                 goto failed;
  127.                             }
  128.                         }
  129.                     }
  130.     failed:;
  131.                 }
  132.             }
  133.         }
  134.     }
  135.     return 0;
  136. }
  137.  
  138.