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

  1. //    VirtualDub - Video processing and capture application
  2. //    Graphics support library
  3. //    Copyright (C) 1998-2008 Avery Lee
  4. //
  5. //    This program is free software; you can redistribute it and/or modify
  6. //    it under the terms of the GNU General Public License as published by
  7. //    the Free Software Foundation; either version 2 of the License, or
  8. //    (at your option) any later version.
  9. //
  10. //    This program is distributed in the hope that it will be useful,
  11. //    but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. //    GNU General Public License for more details.
  14. //
  15. //    You should have received a copy of the GNU General Public License
  16. //    along with this program; if not, write to the Free Software
  17. //    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  
  19. #ifndef f_VD2_KASUMI_UBERBLIT_SWIZZLE_H
  20. #define f_VD2_KASUMI_UBERBLIT_SWIZZLE_H
  21.  
  22. #include <vd2/system/cpuaccel.h>
  23. #include "uberblit_base.h"
  24.  
  25. ///////////////////////////////////////////////////////////////////////////////////////////////////
  26. //
  27. //    generic converters
  28. //
  29. ///////////////////////////////////////////////////////////////////////////////////////////////////
  30.  
  31. class VDPixmapGen_Swap8In16 : public VDPixmapGenWindowBasedOneSource {
  32. public:
  33.     void Init(IVDPixmapGen *gen, int srcIndex, uint32 w, uint32 h, uint32 bpr);
  34.     void Start();
  35.  
  36.     uint32 GetType(uint32 index) const;
  37.  
  38. protected:
  39.     void Compute(void *dst0, sint32 y);
  40.  
  41.     uint32 mRowLength;
  42. };
  43.  
  44. ///////////////////////////////////////////////////////////////////////////////////////////////////
  45. //
  46. //    32-bit deinterleavers
  47. //
  48. ///////////////////////////////////////////////////////////////////////////////////////////////////
  49.  
  50. class VDPixmapGen_8In16 : public VDPixmapGenWindowBasedOneSource {
  51. public:
  52.     void Init(IVDPixmapGen *gen, int srcIndex, int offset, uint32 w, uint32 h) {
  53.         InitSource(gen, srcIndex);
  54.         mOffset = offset;
  55.         SetOutputSize(w, h);
  56.         gen->AddWindowRequest(0, 0);
  57.     }
  58.  
  59.     void Start() {
  60.         StartWindow(mWidth);
  61.     }
  62.  
  63.     uint32 GetType(uint32 index) const {
  64.         return (mpSrc->GetType(mSrcIndex) & ~kVDPixType_Mask) | kVDPixType_8;
  65.     }
  66.  
  67. protected:
  68.     void Compute(void *dst0, sint32 y) {
  69.         const uint8 *srcp = (const uint8 *)mpSrc->GetRow(y, mSrcIndex) + mOffset;
  70.         uint8 *dst = (uint8 *)dst0;
  71.         sint32 w = mWidth;
  72.         for(sint32 x=0; x<w; ++x) {
  73.             *dst++ = *srcp;
  74.             srcp += 2;
  75.         }
  76.     }
  77.  
  78.     int mOffset;
  79. };
  80.  
  81. class VDPixmapGen_8In32 : public VDPixmapGenWindowBasedOneSource {
  82. public:
  83.     void Init(IVDPixmapGen *gen, int srcIndex, int offset, uint32 w, uint32 h) {
  84.         InitSource(gen, srcIndex);
  85.         mOffset = offset;
  86.         SetOutputSize(w, h);
  87.         gen->AddWindowRequest(0, 0);
  88.     }
  89.  
  90.     void Start() {
  91.         StartWindow(mWidth);
  92.     }
  93.  
  94.     uint32 GetType(uint32 index) const {
  95.         return (mpSrc->GetType(mSrcIndex) & ~kVDPixType_Mask) | kVDPixType_8;
  96.     }
  97.  
  98. protected:
  99.     void Compute(void *dst0, sint32 y) {
  100.         const uint8 *srcp = (const uint8 *)mpSrc->GetRow(y, mSrcIndex) + mOffset;
  101.         uint8 *dst = (uint8 *)dst0;
  102.         sint32 w = mWidth;
  103.         for(sint32 x=0; x<w; ++x) {
  104.             *dst++ = *srcp;
  105.             srcp += 4;
  106.         }
  107.     }
  108.  
  109.     int mOffset;
  110. };
  111.  
  112. ///////////////////////////////////////////////////////////////////////////////////////////////////
  113. //
  114. //    16-bit interleavers
  115. //
  116. ///////////////////////////////////////////////////////////////////////////////////////////////////
  117.  
  118. class VDPixmapGen_B8x2_To_B8R8 : public VDPixmapGenWindowBased {
  119. public:
  120.     void Init(IVDPixmapGen *srcCb, uint32 srcindexCb, IVDPixmapGen *srcCr, uint32 srcindexCr);
  121.     void Start();
  122.     uint32 GetType(uint32 output) const;
  123.  
  124. protected:
  125.     void Compute(void *dst0, sint32 y);
  126.  
  127.     IVDPixmapGen *mpSrcCb;
  128.     uint32 mSrcIndexCb;
  129.     IVDPixmapGen *mpSrcCr;
  130.     uint32 mSrcIndexCr;
  131. };
  132.  
  133. ///////////////////////////////////////////////////////////////////////////////////////////////////
  134. //
  135. //    32-bit interleavers
  136. //
  137. ///////////////////////////////////////////////////////////////////////////////////////////////////
  138.  
  139. class VDPixmapGen_B8x3_To_G8B8_G8R8 : public VDPixmapGenWindowBased {
  140. public:
  141.     void Init(IVDPixmapGen *srcCr, uint32 srcindexCr, IVDPixmapGen *srcY, uint32 srcindexY, IVDPixmapGen *srcCb, uint32 srcindexCb) {
  142.         mpSrcY = srcY;
  143.         mSrcIndexY = srcindexY;
  144.         mpSrcCb = srcCb;
  145.         mSrcIndexCb = srcindexCb;
  146.         mpSrcCr = srcCr;
  147.         mSrcIndexCr = srcindexCr;
  148.         mWidth = srcY->GetWidth(srcindexY);
  149.         mHeight = srcY->GetHeight(srcindexY);
  150.  
  151.         srcY->AddWindowRequest(0, 0);
  152.         srcCb->AddWindowRequest(0, 0);
  153.         srcCr->AddWindowRequest(0, 0);
  154.     }
  155.  
  156.     void Start() {
  157.         mpSrcY->Start();
  158.         mpSrcCb->Start();
  159.         mpSrcCr->Start();
  160.  
  161.         StartWindow(((mWidth + 1) & ~1) * 2);
  162.     }
  163.  
  164.     uint32 GetType(uint32 output) const {
  165.         return (mpSrcY->GetType(mSrcIndexY) & ~kVDPixType_Mask) | kVDPixType_B8G8_R8G8;
  166.     }
  167.  
  168. protected:
  169.     void Compute(void *dst0, sint32 y) {
  170.         uint8 *VDRESTRICT dst = (uint8 *)dst0;
  171.         const uint8 *VDRESTRICT srcY = (const uint8 *)mpSrcY->GetRow(y, mSrcIndexY);
  172.         const uint8 *VDRESTRICT srcCb = (const uint8 *)mpSrcCb->GetRow(y, mSrcIndexCb);
  173.         const uint8 *VDRESTRICT srcCr = (const uint8 *)mpSrcCr->GetRow(y, mSrcIndexCr);
  174.  
  175.         sint32 w = mWidth >> 1;
  176.         for(sint32 x=0; x<w; ++x) {
  177.             uint8 y1 = srcY[0];
  178.             uint8 cb = srcCb[0];
  179.             uint8 y2 = srcY[1];
  180.             uint8 cr = srcCr[0];
  181.  
  182.             dst[0] = y1;
  183.             dst[1] = cb;
  184.             dst[2] = y2;
  185.             dst[3] = cr;
  186.  
  187.             srcY += 2;
  188.             ++srcCb;
  189.             ++srcCr;
  190.             dst += 4;
  191.         }
  192.  
  193.         if (mWidth & 1) {
  194.             uint8 y1 = srcY[0];
  195.             uint8 cb = srcCb[0];
  196.             uint8 cr = srcCr[0];
  197.  
  198.             dst[0] = y1;
  199.             dst[1] = cb;
  200.             dst[2] = y1;
  201.             dst[3] = cr;
  202.         }
  203.     }
  204.  
  205.     IVDPixmapGen *mpSrcY;
  206.     uint32 mSrcIndexY;
  207.     IVDPixmapGen *mpSrcCb;
  208.     uint32 mSrcIndexCb;
  209.     IVDPixmapGen *mpSrcCr;
  210.     uint32 mSrcIndexCr;
  211. };
  212.  
  213. class VDPixmapGen_B8x3_To_B8G8_R8G8 : public VDPixmapGenWindowBased {
  214. public:
  215.     void Init(IVDPixmapGen *srcCr, uint32 srcindexCr, IVDPixmapGen *srcY, uint32 srcindexY, IVDPixmapGen *srcCb, uint32 srcindexCb) {
  216.         mpSrcY = srcY;
  217.         mSrcIndexY = srcindexY;
  218.         mpSrcCb = srcCb;
  219.         mSrcIndexCb = srcindexCb;
  220.         mpSrcCr = srcCr;
  221.         mSrcIndexCr = srcindexCr;
  222.         mWidth = srcY->GetWidth(srcindexY);
  223.         mHeight = srcY->GetHeight(srcindexY);
  224.  
  225.         srcY->AddWindowRequest(0, 0);
  226.         srcCb->AddWindowRequest(0, 0);
  227.         srcCr->AddWindowRequest(0, 0);
  228.     }
  229.  
  230.     void Start() {
  231.         mpSrcY->Start();
  232.         mpSrcCb->Start();
  233.         mpSrcCr->Start();
  234.  
  235.         StartWindow(((mWidth + 1) & ~1) * 2);
  236.     }
  237.  
  238.     uint32 GetType(uint32 output) const {
  239.         return (mpSrcY->GetType(mSrcIndexY) & ~kVDPixType_Mask) | kVDPixType_G8B8_G8R8;
  240.     }
  241.  
  242. protected:
  243.     void Compute(void *dst0, sint32 y) {
  244.         uint8 * VDRESTRICT dst = (uint8 *)dst0;
  245.         const uint8 *VDRESTRICT srcY = (const uint8 *)mpSrcY->GetRow(y, mSrcIndexY);
  246.         const uint8 *VDRESTRICT srcCb = (const uint8 *)mpSrcCb->GetRow(y, mSrcIndexCb);
  247.         const uint8 *VDRESTRICT srcCr = (const uint8 *)mpSrcCr->GetRow(y, mSrcIndexCr);
  248.  
  249.         sint32 w2 = mWidth >> 1;
  250.         for(sint32 x=0; x<w2; ++x) {
  251.             uint8 cb = srcCb[0];
  252.             uint8 y1 = srcY[0];
  253.             uint8 cr = srcCr[0];
  254.             uint8 y2 = srcY[1];
  255.  
  256.             dst[0] = cb;
  257.             dst[1] = y1;
  258.             dst[2] = cr;
  259.             dst[3] = y2;
  260.             dst += 4;
  261.             srcY += 2;
  262.             ++srcCb;
  263.             ++srcCr;
  264.         }
  265.  
  266.         if (mWidth & 1) {
  267.             uint8 cb = srcCb[0];
  268.             uint8 y1 = srcY[0];
  269.             uint8 cr = srcCr[0];
  270.  
  271.             dst[0] = cb;
  272.             dst[1] = y1;
  273.             dst[2] = cr;
  274.             dst[3] = y1;
  275.         }
  276.     }
  277.  
  278.     IVDPixmapGen *mpSrcY;
  279.     uint32 mSrcIndexY;
  280.     IVDPixmapGen *mpSrcCb;
  281.     uint32 mSrcIndexCb;
  282.     IVDPixmapGen *mpSrcCr;
  283.     uint32 mSrcIndexCr;
  284. };
  285.  
  286. class VDPixmapGen_B8x3_To_X8R8G8B8 : public VDPixmapGenWindowBased {
  287. public:
  288.     void Init(IVDPixmapGen *srcCr, uint32 srcindexCr, IVDPixmapGen *srcY, uint32 srcindexY, IVDPixmapGen *srcCb, uint32 srcindexCb) {
  289.         mpSrcY = srcY;
  290.         mSrcIndexY = srcindexY;
  291.         mpSrcCb = srcCb;
  292.         mSrcIndexCb = srcindexCb;
  293.         mpSrcCr = srcCr;
  294.         mSrcIndexCr = srcindexCr;
  295.         mWidth = srcY->GetWidth(srcindexY);
  296.         mHeight = srcY->GetHeight(srcindexY);
  297.  
  298.         srcY->AddWindowRequest(0, 0);
  299.         srcCb->AddWindowRequest(0, 0);
  300.         srcCr->AddWindowRequest(0, 0);
  301.     }
  302.  
  303.     void Start() {
  304.         mpSrcY->Start();
  305.         mpSrcCb->Start();
  306.         mpSrcCr->Start();
  307.  
  308.         StartWindow(mWidth * 4);
  309.     }
  310.  
  311.     uint32 GetType(uint32 output) const {
  312.         return (mpSrcY->GetType(mSrcIndexY) & ~kVDPixType_Mask) | kVDPixType_8888;
  313.     }
  314.  
  315. protected:
  316.     void Compute(void *dst0, sint32 y) {
  317.         uint8 *dst = (uint8 *)dst0;
  318.         const uint8 *srcY = (const uint8 *)mpSrcY->GetRow(y, mSrcIndexY);
  319.         const uint8 *srcCb = (const uint8 *)mpSrcCb->GetRow(y, mSrcIndexCb);
  320.         const uint8 *srcCr = (const uint8 *)mpSrcCr->GetRow(y, mSrcIndexCr);
  321.  
  322.         for(sint32 x=0; x<mWidth; ++x) {
  323.             uint8 y = *srcY++;
  324.             uint8 cb = *srcCb++;
  325.             uint8 cr = *srcCr++;
  326.  
  327.             dst[0] = cb;
  328.             dst[1] = y;
  329.             dst[2] = cr;
  330.             dst[3] = 255;
  331.             dst += 4;
  332.         }
  333.     }
  334.  
  335.     IVDPixmapGen *mpSrcY;
  336.     uint32 mSrcIndexY;
  337.     IVDPixmapGen *mpSrcCb;
  338.     uint32 mSrcIndexCb;
  339.     IVDPixmapGen *mpSrcCr;
  340.     uint32 mSrcIndexCr;
  341. };
  342.  
  343. #endif
  344.