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

  1. #include <vd2/system/vdtypes.h>
  2. #include <vd2/Kasumi/pixmap.h>
  3. #include <vd2/Kasumi/pixmaputils.h>
  4.  
  5. #define DECLARE_RGB(x, y) void VDPixmapBlt_##x##_to_##y##_reference(void *dst0, ptrdiff_t dstpitch, const void *src0, ptrdiff_t srcpitch, vdpixsize w, vdpixsize h)
  6.  
  7. ///////////////////////////////////////////////////////////////////////////
  8. //
  9. //    RGB blitters: -> XRGB1555
  10. //
  11. ///////////////////////////////////////////////////////////////////////////
  12.  
  13. DECLARE_RGB(RGB565, XRGB1555) {
  14.     const uint16 *src = (const uint16 *)src0;
  15.     uint16 *dst = (uint16 *)dst0;
  16.  
  17.     srcpitch -= 2*w;
  18.     dstpitch -= 2*w;
  19.  
  20.     do {
  21.         int wt = w;
  22.  
  23.         do {
  24.             const uint32 px = *src++;
  25.             *dst++ = (px&0x001f) + ((px&0xffc0)>>1);
  26.         } while(--wt);
  27.  
  28.         vdptrstep(src, srcpitch);
  29.         vdptrstep(dst, dstpitch);
  30.     } while(--h);
  31. }
  32.  
  33. DECLARE_RGB(RGB888, XRGB1555) {
  34.     const uint8 *src = (const uint8 *)src0;
  35.     uint16 *dst = (uint16 *)dst0;
  36.  
  37.     srcpitch -= 3*w;
  38.     dstpitch -= 2*w;
  39.  
  40.     do {
  41.         int wt = w;
  42.  
  43.         do {
  44.             const uint32 r = ((uint32)src[2] & 0xf8) << 7;
  45.             const uint32 g = ((uint32)src[1] & 0xf8) << 2;
  46.             const uint32 b = (uint32)src[0] >> 3;
  47.             src += 3;
  48.  
  49.             *dst++ = (uint16)(r + g + b);
  50.         } while(--wt);
  51.  
  52.         vdptrstep(src, srcpitch);
  53.         vdptrstep(dst, dstpitch);
  54.     } while(--h);
  55. }
  56.  
  57. DECLARE_RGB(XRGB8888, XRGB1555) {
  58.     const uint8 *src = (const uint8 *)src0;
  59.     uint16 *dst = (uint16 *)dst0;
  60.  
  61.     srcpitch -= 4*w;
  62.     dstpitch -= 2*w;
  63.  
  64.     do {
  65.         int wt = w;
  66.  
  67.         do {
  68.             const uint32 r = ((uint32)src[2] & 0xf8) << 7;
  69.             const uint32 g = ((uint32)src[1] & 0xf8) << 2;
  70.             const uint32 b = (uint32)src[0] >> 3;
  71.             src += 4;
  72.  
  73.             *dst++ = (uint16)(r + g + b);
  74.         } while(--wt);
  75.  
  76.         vdptrstep(src, srcpitch);
  77.         vdptrstep(dst, dstpitch);
  78.     } while(--h);
  79. }
  80.  
  81. ///////////////////////////////////////////////////////////////////////////
  82. //
  83. //    RGB blitters: -> RGB565
  84. //
  85. ///////////////////////////////////////////////////////////////////////////
  86.  
  87. DECLARE_RGB(XRGB1555, RGB565) {
  88.     const uint16 *src = (const uint16 *)src0;
  89.     uint16 *dst = (uint16 *)dst0;
  90.  
  91.     srcpitch -= 2*w;
  92.     dstpitch -= 2*w;
  93.  
  94.     do {
  95.         int wt = w;
  96.  
  97.         do {
  98.             const uint32 px = *src++;
  99.             *dst++ = (uint16)(px + (px&0xffe0) + ((px&0x0200)>>4));
  100.         } while(--wt);
  101.  
  102.         vdptrstep(src, srcpitch);
  103.         vdptrstep(dst, dstpitch);
  104.     } while(--h);
  105. }
  106.  
  107. DECLARE_RGB(RGB888, RGB565) {
  108.     const uint8 *src = (const uint8 *)src0;
  109.     uint16 *dst = (uint16 *)dst0;
  110.  
  111.     srcpitch -= 3*w;
  112.     dstpitch -= 2*w;
  113.  
  114.     do {
  115.         int wt = w;
  116.  
  117.         do {
  118.             const uint32 r = ((uint32)src[2] & 0xf8) << 8;
  119.             const uint32 g = ((uint32)src[1] & 0xfc) << 3;
  120.             const uint32 b = (uint32)src[0] >> 3;
  121.             src += 3;
  122.  
  123.             *dst++ = (uint16)(r + g + b);
  124.         } while(--wt);
  125.  
  126.         vdptrstep(src, srcpitch);
  127.         vdptrstep(dst, dstpitch);
  128.     } while(--h);
  129. }
  130.  
  131. DECLARE_RGB(XRGB8888, RGB565) {
  132.     const uint8 *src = (const uint8 *)src0;
  133.     uint16 *dst = (uint16 *)dst0;
  134.  
  135.     srcpitch -= 4*w;
  136.     dstpitch -= 2*w;
  137.  
  138.     do {
  139.         int wt = w;
  140.  
  141.         do {
  142.             const uint32 r = ((uint32)src[2] & 0xf8) << 8;
  143.             const uint32 g = ((uint32)src[1] & 0xfc) << 3;
  144.             const uint32 b = (uint32)src[0] >> 3;
  145.             src += 4;
  146.  
  147.             *dst++ = (uint16)(r + g + b);
  148.         } while(--wt);
  149.  
  150.         vdptrstep(src, srcpitch);
  151.         vdptrstep(dst, dstpitch);
  152.     } while(--h);
  153. }
  154.  
  155. ///////////////////////////////////////////////////////////////////////////
  156. //
  157. //    RGB blitters: -> RGB888
  158. //
  159. ///////////////////////////////////////////////////////////////////////////
  160.  
  161. DECLARE_RGB(XRGB1555, RGB888) {
  162.     const uint16 *src = (const uint16 *)src0;
  163.     uint8 *dst = (uint8 *)dst0;
  164.  
  165.     srcpitch -= 2*w;
  166.     dstpitch -= 3*w;
  167.  
  168.     do {
  169.         int wt = w;
  170.  
  171.         do {
  172.             const uint32 px = *src++;
  173.             uint32 rb = px & 0x7c1f;
  174.             uint32 g = px & 0x03e0;
  175.  
  176.             rb += rb<<5;
  177.             g += g<<5;
  178.  
  179.             dst[0] = (uint8)(rb>>2);
  180.             dst[1] = (uint8)(g>>7);
  181.             dst[2] = (uint8)(rb>>12);
  182.             dst += 3;
  183.         } while(--wt);
  184.  
  185.         vdptrstep(src, srcpitch);
  186.         vdptrstep(dst, dstpitch);
  187.     } while(--h);
  188. }
  189.  
  190. DECLARE_RGB(RGB565, RGB888) {
  191.     const uint16 *src = (const uint16 *)src0;
  192.     uint8 *dst = (uint8 *)dst0;
  193.  
  194.     srcpitch -= 2*w;
  195.     dstpitch -= 3*w;
  196.  
  197.     do {
  198.         int wt = w;
  199.  
  200.         do {
  201.             const uint32 px = *src++;
  202.             uint32 rb = px & 0xf81f;
  203.             uint32 g = px & 0x07e0;
  204.  
  205.             rb += rb<<5;
  206.             g += g<<6;
  207.  
  208.             dst[0] = (uint8)(rb>>2);
  209.             dst[1] = (uint8)(g>>9);
  210.             dst[2] = (uint8)(rb>>13);
  211.             dst += 3;
  212.         } while(--wt);
  213.  
  214.         vdptrstep(src, srcpitch);
  215.         vdptrstep(dst, dstpitch);
  216.     } while(--h);
  217. }
  218.  
  219. DECLARE_RGB(XRGB8888, RGB888) {
  220.     const uint8 *src = (const uint8 *)src0;
  221.     uint8 *dst = (uint8 *)dst0;
  222.  
  223.     srcpitch -= 4*w;
  224.     dstpitch -= 3*w;
  225.  
  226.     do {
  227.         int wt = w;
  228.  
  229.         do {
  230.             dst[0] = src[0];
  231.             dst[1] = src[1];
  232.             dst[2] = src[2];
  233.             dst += 3;
  234.             src += 4;
  235.         } while(--wt);
  236.  
  237.         vdptrstep(src, srcpitch);
  238.         vdptrstep(dst, dstpitch);
  239.     } while(--h);
  240. }
  241.  
  242. ///////////////////////////////////////////////////////////////////////////
  243. //
  244. //    RGB blitters: -> XRGB8888
  245. //
  246. ///////////////////////////////////////////////////////////////////////////
  247.  
  248. DECLARE_RGB(XRGB1555, XRGB8888) {
  249.     const uint16 *src = (const uint16 *)src0;
  250.     uint32 *dst = (uint32 *)dst0;
  251.  
  252.     srcpitch -= 2*w;
  253.     dstpitch -= 4*w;
  254.  
  255.     do {
  256.         int wt = w;
  257.  
  258.         do {
  259.             const uint32 px = *src++;
  260.             const uint32 rgb = ((px & 0x7c00) << 9) + ((px & 0x03e0) << 6) + ((px & 0x001f) << 3);
  261.  
  262.             *dst++ = rgb + ((rgb & 0xe0e0e0)>>5);
  263.         } while(--wt);
  264.  
  265.         vdptrstep(src, srcpitch);
  266.         vdptrstep(dst, dstpitch);
  267.     } while(--h);
  268. }
  269.  
  270. DECLARE_RGB(RGB565, XRGB8888) {
  271.     const uint16 *src = (const uint16 *)src0;
  272.     uint32 *dst = (uint32 *)dst0;
  273.  
  274.     srcpitch -= 2*w;
  275.     dstpitch -= 4*w;
  276.  
  277.     do {
  278.         int wt = w;
  279.  
  280.         do {
  281.             const uint32 px = *src++;
  282.             const uint32 rb = ((px & 0xf800) << 8) + ((px & 0x001f) << 3);
  283.             const uint32 g = ((px & 0x07e0) << 5) + (px & 0x0300);
  284.  
  285.             *dst++ = rb + ((rb & 0xe000e0)>>5) + g;
  286.         } while(--wt);
  287.  
  288.         vdptrstep(src, srcpitch);
  289.         vdptrstep(dst, dstpitch);
  290.     } while(--h);
  291. }
  292.  
  293. DECLARE_RGB(RGB888, XRGB8888) {
  294.     const uint8 *src = (const uint8 *)src0;
  295.     uint32 *dst = (uint32 *)dst0;
  296.  
  297.     srcpitch -= 3*w;
  298.     dstpitch -= 4*w;
  299.  
  300.     do {
  301.         int wt = w;
  302.  
  303.         do {
  304.             *dst++ = (uint32)src[0] + ((uint32)src[1]<<8) + ((uint32)src[2]<<16);
  305.             src += 3;
  306.         } while(--wt);
  307.         vdptrstep(src, srcpitch);
  308.         vdptrstep(dst, dstpitch);
  309.     } while(--h);
  310. }
  311.