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 / h / uberblit_rgb.h < prev    next >
Encoding:
C/C++ Source or Header  |  2009-09-14  |  14.0 KB  |  553 lines

  1. #ifndef f_VD2_KASUMI_UBERBLIT_RGB_H
  2. #define f_VD2_KASUMI_UBERBLIT_RGB_H
  3.  
  4. #include <vd2/system/cpuaccel.h>
  5. #include "uberblit_base.h"
  6.  
  7. ///////////////////////////////////////////////////////////////////////////////////////////////////
  8. //
  9. //    16-bit crossconverters
  10. //
  11. ///////////////////////////////////////////////////////////////////////////////////////////////////
  12.  
  13. class VDPixmapGen_X1R5G5B5_To_R5G6B5 : public VDPixmapGenWindowBasedOneSourceSimple {
  14. public:
  15.     void Start() {
  16.         StartWindow(mWidth * 2);
  17.     }
  18.  
  19.     uint32 GetType(uint32 output) const {
  20.         return (mpSrc->GetType(mSrcIndex) & ~kVDPixType_Mask) | kVDPixType_565_LE;
  21.     }
  22.  
  23. protected:
  24.     virtual void Compute(void *dst0, sint32 y) {
  25.         uint16 *dst = (uint16 *)dst0;
  26.         const uint16 *src = (const uint16 *)mpSrc->GetRow(y, mSrcIndex);
  27.         sint32 w = mWidth;
  28.  
  29.         for(sint32 i=0; i<w; ++i) {
  30.             uint32 px = src[i];
  31.  
  32.             px += (px & 0x7fe0);
  33.             px += (px & 0x400) >> 5;
  34.  
  35.             dst[i] = (uint16)px;
  36.         }
  37.     }
  38. };
  39.  
  40. class VDPixmapGen_R5G6B5_To_X1R5G5B5 : public VDPixmapGenWindowBasedOneSourceSimple {
  41. public:
  42.     void Start() {
  43.         StartWindow(mWidth * 2);
  44.     }
  45.  
  46.     uint32 GetType(uint32 output) const {
  47.         return (mpSrc->GetType(mSrcIndex) & ~kVDPixType_Mask) | kVDPixType_8888;
  48.     }
  49.  
  50. protected:
  51.     void Compute(void *dst0, sint32 y) {
  52.         uint16 *dst = (uint16 *)dst0;
  53.         const uint16 *src = (const uint16 *)mpSrc->GetRow(y, mSrcIndex);
  54.         sint32 w = mWidth;
  55.  
  56.         for(sint32 i=0; i<w; ++i) {
  57.             uint32 px = src[i];
  58.  
  59.             px &= 0xffdf;
  60.             px -= (px & 0xffc0) >> 1;
  61.  
  62.             dst[i] = (uint16)px;
  63.         }
  64.     }
  65. };
  66.  
  67. ///////////////////////////////////////////////////////////////////////////////////////////////////
  68. //
  69. //    32-bit upconverters
  70. //
  71. ///////////////////////////////////////////////////////////////////////////////////////////////////
  72.  
  73. class VDPixmapGen_X1R5G5B5_To_X8R8G8B8 : public VDPixmapGenWindowBasedOneSourceSimple {
  74. public:
  75.     void Start() {
  76.         StartWindow(mWidth * 4);
  77.     }
  78.  
  79.     uint32 GetType(uint32 output) const {
  80.         return (mpSrc->GetType(mSrcIndex) & ~kVDPixType_Mask) | kVDPixType_8888;
  81.     }
  82.  
  83. protected:
  84.     virtual void Compute(void *dst0, sint32 y) {
  85.         uint32 *dst = (uint32 *)dst0;
  86.         const uint16 *src = (const uint16 *)mpSrc->GetRow(y, mSrcIndex);
  87.         sint32 w = mWidth;
  88.  
  89.         for(sint32 i=0; i<w; ++i) {
  90.             uint32 px = src[i];
  91.             uint32 px5 = ((px & 0x7c00) << 9) + ((px & 0x03e0) << 6) + ((px & 0x001f) << 3);
  92.  
  93.             dst[i] = px5 + ((px5 >> 5) & 0x070707);
  94.         }
  95.     }
  96. };
  97.  
  98. class VDPixmapGen_R5G6B5_To_X8R8G8B8 : public VDPixmapGenWindowBasedOneSourceSimple {
  99. public:
  100.     void Start() {
  101.         StartWindow(mWidth * 4);
  102.     }
  103.  
  104.     uint32 GetType(uint32 output) const {
  105.         return (mpSrc->GetType(mSrcIndex) & ~kVDPixType_Mask) | kVDPixType_8888;
  106.     }
  107.  
  108. protected:
  109.     void Compute(void *dst0, sint32 y) {
  110.         uint32 *dst = (uint32 *)dst0;
  111.         const uint16 *src = (const uint16 *)mpSrc->GetRow(y, mSrcIndex);
  112.         sint32 w = mWidth;
  113.  
  114.         for(sint32 i=0; i<w; ++i) {
  115.             uint32 px = src[i];
  116.             uint32 px_rb5 = ((px & 0xf800) << 8) + ((px & 0x001f) << 3);
  117.             uint32 px_g6 = ((px & 0x07e0) << 5);
  118.  
  119.             dst[i] = px_rb5 + px_g6 + (((px_rb5 >> 5) + (px_g6 >> 6)) & 0x070307);
  120.         }
  121.     }
  122. };
  123.  
  124. class VDPixmapGen_R8G8B8_To_A8R8G8B8 : public VDPixmapGenWindowBasedOneSourceSimple {
  125. public:
  126.     void Start() {
  127.         StartWindow(mWidth * 4);
  128.     }
  129.  
  130.     uint32 GetType(uint32 output) const {
  131.         return (mpSrc->GetType(mSrcIndex) & ~kVDPixType_Mask) | kVDPixType_8888;
  132.     }
  133.  
  134. protected:
  135.     void Compute(void *dst0, sint32 y) {
  136.         uint8 *dst = (uint8 *)dst0;
  137.         const uint8 *src = (const uint8 *)mpSrc->GetRow(y, mSrcIndex);
  138.         sint32 w = mWidth;
  139.  
  140.         for(sint32 i=0; i<w; ++i) {
  141.             dst[0] = src[0];
  142.             dst[1] = src[1];
  143.             dst[2] = src[2];
  144.             dst[3] = 255;
  145.             dst += 4;
  146.             src += 3;
  147.         }
  148.     }
  149. };
  150.  
  151. ///////////////////////////////////////////////////////////////////////////////////////////////////
  152. //
  153. //    32-bit downconverters
  154. //
  155. ///////////////////////////////////////////////////////////////////////////////////////////////////
  156.  
  157. class VDPixmapGen_X8R8G8B8_To_X1R5G5B5 : public VDPixmapGenWindowBasedOneSourceSimple {
  158. public:
  159.     void Start() {
  160.         StartWindow(mWidth * 2);
  161.     }
  162.  
  163.     uint32 GetType(uint32 output) const {
  164.         return (mpSrc->GetType(mSrcIndex) & ~kVDPixType_Mask) | kVDPixType_1555_LE;
  165.     }
  166.  
  167. protected:
  168.     void Compute(void *dst0, sint32 y) {
  169.         uint16 *dst = (uint16 *)dst0;
  170.         const uint32 *src = (const uint32 *)mpSrc->GetRow(y, mSrcIndex);
  171.         sint32 w = mWidth;
  172.  
  173.         for(sint32 i=0; i<w; ++i) {
  174.             uint32 px = src[i];
  175.  
  176.             dst[i] = ((px >> 9) & 0x7c00) + ((px >> 6) & 0x03e0) + ((px >> 3) & 0x001f);
  177.         }
  178.     }
  179. };
  180.  
  181. class VDPixmapGen_X8R8G8B8_To_R5G6B5 : public VDPixmapGenWindowBasedOneSourceSimple {
  182. public:
  183.     void Start() {
  184.         StartWindow(mWidth * 2);
  185.     }
  186.  
  187.     uint32 GetType(uint32 output) const {
  188.         return (mpSrc->GetType(mSrcIndex) & ~kVDPixType_Mask) | kVDPixType_565_LE;
  189.     }
  190.  
  191. protected:
  192.     void Compute(void *dst0, sint32 y) {
  193.         uint16 *dst = (uint16 *)dst0;
  194.         const uint32 *src = (const uint32 *)mpSrc->GetRow(y, mSrcIndex);
  195.         sint32 w = mWidth;
  196.  
  197.         for(sint32 i=0; i<w; ++i) {
  198.             uint32 px = src[i];
  199.  
  200.             dst[i] = ((px >> 8) & 0xf800) + ((px >> 5) & 0x07e0) + ((px >> 3) & 0x001f);
  201.         }
  202.     }
  203. };
  204.  
  205. class VDPixmapGen_X8R8G8B8_To_R8G8B8 : public VDPixmapGenWindowBasedOneSourceSimple {
  206. public:
  207.     void Start() {
  208.         StartWindow(mWidth * 3);
  209.     }
  210.  
  211.     uint32 GetType(uint32 output) const {
  212.         return (mpSrc->GetType(mSrcIndex) & ~kVDPixType_Mask) | kVDPixType_888;
  213.     }
  214.  
  215. protected:
  216.     void Compute(void *dst0, sint32 y) {
  217.         uint8 *dst = (uint8 *)dst0;
  218.         const uint8 *src = (const uint8 *)mpSrc->GetRow(y, mSrcIndex);
  219.         sint32 w = mWidth;
  220.  
  221.         for(sint32 i=0; i<w; ++i) {
  222.             dst[0] = src[0];
  223.             dst[1] = src[1];
  224.             dst[2] = src[2];
  225.  
  226.             dst += 3;
  227.             src += 4;
  228.         }
  229.     }
  230. };
  231.  
  232. ///////////////////////////////////////////////////////////////////////////////////////////////////
  233. //
  234. //    32-bit downconverters
  235. //
  236. ///////////////////////////////////////////////////////////////////////////////////////////////////
  237.  
  238. class VDPixmapGen_X8R8G8B8_To_X1R5G5B5_Dithered : public VDPixmapGenWindowBasedOneSourceSimple {
  239. public:
  240.     void Start() {
  241.         StartWindow(mWidth * 2);
  242.     }
  243.  
  244.     uint32 GetType(uint32 output) const {
  245.         return (mpSrc->GetType(mSrcIndex) & ~kVDPixType_Mask) | kVDPixType_1555_LE;
  246.     }
  247.  
  248. protected:
  249.     void Compute(void *dst0, sint32 y) {
  250.         uint16 *dst = (uint16 *)dst0;
  251.         const uint32 *src = (const uint32 *)mpSrc->GetRow(y, mSrcIndex);
  252.         sint32 w = mWidth;
  253.  
  254.         static const uint32 kDitherMatrix[4][4][2]={
  255.             { 0x00000000, 0x00000000, 0x04000400, 0x00040000, 0x01000100, 0x00010000, 0x05000500, 0x00050000 },
  256.             { 0x06000600, 0x00060000, 0x02000200, 0x00020000, 0x07000700, 0x00070000, 0x03000300, 0x00030000 },
  257.             { 0x01800180, 0x00018000, 0x05800580, 0x00058000, 0x00800080, 0x00008000, 0x04800480, 0x00048000 },
  258.             { 0x07800780, 0x00078000, 0x03800380, 0x00038000, 0x06800680, 0x00068000, 0x02800280, 0x00028000 },
  259.         };
  260.  
  261.         const uint32 (*drow)[2] = kDitherMatrix[y & 3];
  262.  
  263.         for(sint32 i=0; i<w; ++i) {
  264.             uint32 px = src[i];
  265.             uint32 drg = drow[i & 3][0];
  266.             uint32 db = drow[i & 3][1];
  267.             uint32 rb = (px & 0xff00ff) * 249 + drg;
  268.             uint32 g = (px & 0xff00) * 249 + db;
  269.  
  270.             dst[i] = ((rb >> 17) & 0x7c00) + ((g >> 14) & 0x03e0) + ((rb >> 11) & 0x001f);
  271.         }
  272.     }
  273. };
  274.  
  275. class VDPixmapGen_X8R8G8B8_To_R5G6B5_Dithered : public VDPixmapGenWindowBasedOneSourceSimple {
  276. public:
  277.     void Start() {
  278.         StartWindow(mWidth * 2);
  279.     }
  280.  
  281.     uint32 GetType(uint32 output) const {
  282.         return (mpSrc->GetType(mSrcIndex) & ~kVDPixType_Mask) | kVDPixType_565_LE;
  283.     }
  284.  
  285. protected:
  286.     void Compute(void *dst0, sint32 y) {
  287.         uint16 *dst = (uint16 *)dst0;
  288.         const uint32 *src = (const uint32 *)mpSrc->GetRow(y, mSrcIndex);
  289.         sint32 w = mWidth;
  290.  
  291.         static const uint32 kDitherMatrix[4][4][2]={
  292.             { 0x00000000, 0x00000000, 0x04000400, 0x00020000, 0x01000100, 0x00008000, 0x05000500, 0x00028000 },
  293.             { 0x06000600, 0x00030000, 0x02000200, 0x00010000, 0x07000700, 0x00038000, 0x03000300, 0x00018000 },
  294.             { 0x01800180, 0x0000c000, 0x05800580, 0x0002c000, 0x00800080, 0x00004000, 0x04800480, 0x00024000 },
  295.             { 0x07800780, 0x0003c000, 0x03800380, 0x0001c000, 0x06800680, 0x00034000, 0x02800280, 0x00014000 },
  296.         };
  297.  
  298.         const uint32 (*drow)[2] = kDitherMatrix[y & 3];
  299.  
  300.         for(sint32 i=0; i<w; ++i) {
  301.             uint32 px = src[i];
  302.             uint32 drg = drow[i & 3][0];
  303.             uint32 db = drow[i & 3][1];
  304.             uint32 rb = (px & 0xff00ff) * 249 + drg;
  305.             uint32 g = (px & 0xff00) * 253 + db;
  306.  
  307.             dst[i] = ((rb >> 16) & 0xf800) + ((g >> 13) & 0x07e0) + ((rb >> 11) & 0x001f);
  308.         }
  309.     }
  310. };
  311.  
  312. ///////////////////////////////////////////////////////////////////////////////////////////////////
  313. //
  314. //    32F upconverters
  315. //
  316. ///////////////////////////////////////////////////////////////////////////////////////////////////
  317.  
  318. class VDPixmapGen_8_To_32F : public VDPixmapGenWindowBasedOneSourceSimple {
  319. public:
  320.     void Start() {
  321.         StartWindow(mWidth * 4);
  322.     }
  323.  
  324.     uint32 GetType(uint32 output) const {
  325.         return (mpSrc->GetType(mSrcIndex) & ~kVDPixType_Mask) | kVDPixType_32F_LE;
  326.     }
  327.  
  328. protected:
  329.     void Compute(void *dst0, sint32 y) {
  330.         float *dst = (float *)dst0;
  331.         const uint8 *src = (const uint8 *)mpSrc->GetRow(y, mSrcIndex);
  332.         sint32 w = mWidth;
  333.  
  334.         VDCPUCleanupExtensions();
  335.  
  336.         for(sint32 i=0; i<w; ++i)
  337.             *dst++ = (float)*src++ * (1.0f / 255.0f);
  338.     }
  339. };
  340.  
  341. class VDPixmapGen_X8R8G8B8_To_X32B32G32R32F : public VDPixmapGenWindowBasedOneSourceSimple {
  342. public:
  343.     void Start() {
  344.         StartWindow(mWidth * 16);
  345.     }
  346.  
  347.     uint32 GetType(uint32 output) const {
  348.         return (mpSrc->GetType(mSrcIndex) & ~kVDPixType_Mask) | kVDPixType_32Fx4_LE;
  349.     }
  350.  
  351. protected:
  352.     void Compute(void *dst0, sint32 y) {
  353.         float *dst = (float *)dst0;
  354.         const uint8 *src = (const uint8 *)mpSrc->GetRow(y, mSrcIndex);
  355.         sint32 w = mWidth;
  356.  
  357.         VDCPUCleanupExtensions();
  358.  
  359.         for(sint32 i=0; i<w; ++i) {
  360.             dst[0] = (float)src[2] * (1.0f / 255.0f);
  361.             dst[1] = (float)src[1] * (1.0f / 255.0f);
  362.             dst[2] = (float)src[0] * (1.0f / 255.0f);
  363.             dst[3] = 1.0f;
  364.             dst += 4;
  365.             src += 4;
  366.         }
  367.     }
  368. };
  369.  
  370. ///////////////////////////////////////////////////////////////////////////////////////////////////
  371. //
  372. //    32F downconverters
  373. //
  374. ///////////////////////////////////////////////////////////////////////////////////////////////////
  375.  
  376. class VDPixmapGen_32F_To_8 : public VDPixmapGenWindowBasedOneSourceSimple {
  377. public:
  378.     void Start() {
  379.         StartWindow(mWidth);
  380.     }
  381.  
  382.     uint32 GetType(uint32 output) const {
  383.         return (mpSrc->GetType(mSrcIndex) & ~kVDPixType_Mask) | kVDPixType_8;
  384.     }
  385.  
  386. protected:
  387.     void Compute(void *dst0, sint32 y) {
  388.         uint8 *dst = (uint8 *)dst0;
  389.         const float *src = (const float *)mpSrc->GetRow(y, mSrcIndex);
  390.         sint32 w = mWidth;
  391.  
  392.         VDCPUCleanupExtensions();
  393.  
  394.         for(sint32 i=0; i<w; ++i) {
  395.             float b = *src++;
  396.  
  397.             uint32 ib = VDClampedRoundFixedToUint8Fast(b);
  398.  
  399.             dst[i] = (uint8)ib;
  400.         }
  401.     }
  402. };
  403.  
  404. class VDPixmapGen_32F_To_8_Dithered : public VDPixmapGenWindowBasedOneSourceSimple {
  405. public:
  406.     void Start() {
  407.         StartWindow(mWidth);
  408.     }
  409.  
  410.     uint32 GetType(uint32 output) const {
  411.         return (mpSrc->GetType(mSrcIndex) & ~kVDPixType_Mask) | kVDPixType_8;
  412.     }
  413.  
  414. protected:
  415.     void Compute(void *dst0, sint32 y) {
  416.         uint8 *dst = (uint8 *)dst0;
  417.         const float *src = (const float *)mpSrc->GetRow(y, mSrcIndex);
  418.         VDCPUCleanupExtensions();
  419.  
  420.         sint32 w = mWidth;
  421.  
  422. #define X(v) ((v) - 0x49400000)
  423.  
  424.         static const sint32 kDitherMatrix[4][4]={
  425.             { X( 0), X( 8), X( 2), X(10), },
  426.             { X(12), X( 4), X(14), X( 6), },
  427.             { X( 3), X(11), X( 1), X( 9), },
  428.             { X(15), X( 7), X(13), X( 5), },
  429.         };
  430.  
  431. #undef X
  432.  
  433.         const sint32 *pDitherRow = kDitherMatrix[y & 3];
  434.  
  435.         for(sint32 i=0; i<w; ++i) {
  436.             float b = *src++;
  437.  
  438.             sint32 addend = pDitherRow[i & 3];
  439.             union {
  440.                 float f;
  441.                 sint32 i;
  442.             }    cb = {b * 255.0f + 786432.0f};
  443.  
  444.             sint32 vb = ((sint32)cb.i + addend) >> 4;
  445.  
  446.             if ((uint32)vb >= 0x100)
  447.                 vb = (uint8)(~vb >> 31);
  448.  
  449.             dst[i] = (uint8)vb;
  450.         }
  451.     }
  452. };
  453.  
  454. class VDPixmapGen_X32B32G32R32F_To_X8R8G8B8 : public VDPixmapGenWindowBasedOneSourceSimple {
  455. public:
  456.     void Start() {
  457.         StartWindow(mWidth * 4);
  458.     }
  459.  
  460.     uint32 GetType(uint32 output) const {
  461.         return (mpSrc->GetType(mSrcIndex) & ~kVDPixType_Mask) | kVDPixType_8888;
  462.     }
  463.  
  464. protected:
  465.     void Compute(void *dst0, sint32 y) {
  466.         uint32 *dst = (uint32 *)dst0;
  467.         const float *src = (const float *)mpSrc->GetRow(y, mSrcIndex);
  468.  
  469.         VDCPUCleanupExtensions();
  470.  
  471.         sint32 w = mWidth;
  472.  
  473.         for(sint32 i=0; i<w; ++i) {
  474.             float r = src[0];
  475.             float g = src[1];
  476.             float b = src[2];
  477.             src += 4;
  478.  
  479.             uint32 ir = VDClampedRoundFixedToUint8Fast(r) << 16;
  480.             uint32 ig = VDClampedRoundFixedToUint8Fast(g) << 8;
  481.             uint32 ib = VDClampedRoundFixedToUint8Fast(b);
  482.  
  483.             dst[i] = ir + ig + ib;
  484.         }
  485.     }
  486. };
  487.  
  488. class VDPixmapGen_X32B32G32R32F_To_X8R8G8B8_Dithered : public VDPixmapGenWindowBasedOneSourceSimple {
  489. public:
  490.     void Start() {
  491.         StartWindow(mWidth * 4);
  492.     }
  493.  
  494.     uint32 GetType(uint32 output) const {
  495.         return (mpSrc->GetType(mSrcIndex) & ~kVDPixType_Mask) | kVDPixType_8888;
  496.     }
  497.  
  498. protected:
  499.     void Compute(void *dst0, sint32 y) {
  500.         uint32 *dst = (uint32 *)dst0;
  501.         const float *src = (const float *)mpSrc->GetRow(y, mSrcIndex);
  502.  
  503.         VDCPUCleanupExtensions();
  504.  
  505.         sint32 w = mWidth;
  506.  
  507. #define X(v) ((v) - 0x49400000)
  508.  
  509.         static const sint32 kDitherMatrix[4][4]={
  510.             { X( 0), X( 8), X( 2), X(10), },
  511.             { X(12), X( 4), X(14), X( 6), },
  512.             { X( 3), X(11), X( 1), X( 9), },
  513.             { X(15), X( 7), X(13), X( 5), },
  514.         };
  515.  
  516. #undef X
  517.  
  518.         const sint32 *pDitherRow = kDitherMatrix[y & 3];
  519.  
  520.         for(sint32 i=0; i<w; ++i) {
  521.             float r = src[0];
  522.             float g = src[1];
  523.             float b = src[2];
  524.             src += 4;
  525.  
  526.             sint32 addend = pDitherRow[i & 3];
  527.             union {
  528.                 float f;
  529.                 sint32 i;
  530.             }    cr = {r * 255.0f + 786432.0f},
  531.                 cg = {g * 255.0f + 786432.0f},
  532.                 cb = {b * 255.0f + 786432.0f};
  533.  
  534.             sint32 vr = ((sint32)cr.i + addend) >> 4;
  535.             sint32 vg = ((sint32)cg.i + addend) >> 4;
  536.             sint32 vb = ((sint32)cb.i + addend) >> 4;
  537.  
  538.             if ((uint32)vr >= 0x100)
  539.                 vr = (uint8)(~vr >> 31);
  540.  
  541.             if ((uint32)vg >= 0x100)
  542.                 vg = (uint8)(~vg >> 31);
  543.  
  544.             if ((uint32)vb >= 0x100)
  545.                 vb = (uint8)(~vb >> 31);
  546.  
  547.             dst[i] = (vr << 16) + (vg << 8) + vb;
  548.         }
  549.     }
  550. };
  551.  
  552. #endif
  553.