home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 July / CMCD0704.ISO / Software / Freeware / Utilitare / VisualBoyAdvance-1.7.2 / src / motionblur.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2004-05-15  |  5.1 KB  |  193 lines

  1. // VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator.
  2. // Copyright (C) 1999-2003 Forgotten
  3. // Copyright (C) 2004 Forgotten and the VBA development team
  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, or(at your option)
  8. // 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 Foundation,
  17. // Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  18.  
  19. #include "System.h"
  20.  
  21. extern int RGB_LOW_BITS_MASK;
  22.  
  23. void MotionBlur(u8 *srcPtr, u32 srcPitch, u8 *deltaPtr,
  24.                 u8 *dstPtr, u32 dstPitch, int width, int height)
  25. {
  26.   u8 *nextLine, *finish;
  27.   u32 colorMask = ~(RGB_LOW_BITS_MASK | (RGB_LOW_BITS_MASK << 16));
  28.   u32 lowPixelMask = RGB_LOW_BITS_MASK;
  29.   
  30.   nextLine = dstPtr + dstPitch;
  31.   
  32.   do {
  33.     u32 *bP = (u32 *) srcPtr;
  34.     u32 *xP = (u32 *) deltaPtr;
  35.     u32 *dP = (u32 *) dstPtr;
  36.     u32 *nL = (u32 *) nextLine;
  37.     u32 currentPixel;
  38.     u32 nextPixel;
  39.     u32 currentDelta;
  40.     u32 nextDelta;
  41.     
  42.     finish = (u8 *) bP + ((width+2) << 1);
  43.     nextPixel = *bP++;
  44.     nextDelta = *xP++;
  45.     
  46.     do {
  47.       currentPixel = nextPixel;
  48.       currentDelta = nextDelta;
  49.       nextPixel = *bP++;
  50.       nextDelta = *xP++;
  51.  
  52.       if(currentPixel != currentDelta) {
  53.         u32 colorA, product, colorB;
  54.         
  55.         *(xP - 2) = currentPixel;
  56. #ifdef WORDS_BIGENDIAN
  57.         colorA = currentPixel >> 16;
  58.         colorB = currentDelta >> 16;
  59. #else
  60.         colorA = currentPixel & 0xffff;
  61.         colorB = currentDelta & 0xffff;
  62. #endif
  63.  
  64.         product =   ((((colorA & colorMask) >> 1) +
  65.                           ((colorB & colorMask) >> 1) +
  66.                           (colorA & colorB & lowPixelMask)));
  67.         
  68.         *(dP) = product | product << 16;
  69.         *(nL) = product | product << 16;
  70.  
  71. #ifdef WORDS_BIGENDIAN
  72.         colorA = (currentPixel & 0xffff);
  73.         colorB = (currentDelta & 0xffff);
  74. #else
  75.         colorA = currentPixel >> 16;
  76.         colorB = currentDelta >> 16;
  77. #endif
  78.         product = ((((colorA & colorMask) >> 1) +
  79.                   ((colorB & colorMask) >> 1) +
  80.                     (colorA & colorB & lowPixelMask)));
  81.         
  82.         *(dP + 1) = product | product << 16;
  83.         *(nL + 1) = product | product << 16;
  84.       } else {
  85.         u32 colorA, product;
  86.         
  87.         *(xP - 2) = currentPixel;
  88. #ifdef WORDS_BIGENDIAN
  89.         colorA = currentPixel >> 16;
  90. #else
  91.         colorA = currentPixel & 0xffff;
  92. #endif
  93.         
  94.         product = colorA;
  95.         
  96.         *(dP) = product | product << 16;
  97.         *(nL) = product | product << 16;
  98. #ifdef WORDS_BIGENDIAN
  99.         colorA = (currentPixel & 0xffff);
  100. #else
  101.         colorA = currentPixel >> 16;
  102. #endif
  103.         product = colorA;
  104.         
  105.         *(dP + 1) = product | product << 16;
  106.         *(nL + 1) = product | product << 16;        
  107.       }
  108.       
  109.       dP += 2;
  110.       nL += 2;
  111.     } while ((u8 *) bP < finish);
  112.     
  113.     deltaPtr += srcPitch;
  114.     srcPtr += srcPitch;
  115.     dstPtr += dstPitch << 1;
  116.     nextLine += dstPitch << 1;
  117.   }
  118.   while (--height);
  119. }
  120.  
  121. void MotionBlur32(u8 *srcPtr, u32 srcPitch, u8 *deltaPtr,
  122.                   u8 *dstPtr, u32 dstPitch, int width, int height)
  123. {
  124.   u8 *nextLine, *finish;
  125.   u32 colorMask = ~RGB_LOW_BITS_MASK;
  126.   u32 lowPixelMask = RGB_LOW_BITS_MASK;
  127.   
  128.   nextLine = dstPtr + dstPitch;
  129.   
  130.   do {
  131.     u32 *bP = (u32 *) srcPtr;
  132.     u32 *xP = (u32 *) deltaPtr;
  133.     u32 *dP = (u32 *) dstPtr;
  134.     u32 *nL = (u32 *) nextLine;
  135.     u32 currentPixel;
  136.     u32 nextPixel;
  137.     u32 currentDelta;
  138.     u32 nextDelta;
  139.     
  140.     finish = (u8 *) bP + ((width+1) << 2);
  141.     nextPixel = *bP++;
  142.     nextDelta = *xP++;
  143.     
  144.     do {
  145.       currentPixel = nextPixel;
  146.       currentDelta = nextDelta;
  147.       nextPixel = *bP++;
  148.       nextDelta = *xP++;
  149.  
  150.       u32 colorA, product, colorB;
  151.  
  152.       *(xP - 2) = currentPixel;
  153.       colorA = currentPixel;
  154.       colorB = currentDelta;
  155.       
  156.       product =   ((((colorA & colorMask) >> 1) +
  157.                     ((colorB & colorMask) >> 1) +
  158.                     (colorA & colorB & lowPixelMask)));
  159.       
  160.       *(dP) = product;
  161.       *(dP+1) = product;
  162.       *(nL) = product;
  163.       *(nL+1) = product;
  164.  
  165.       *(xP - 1) = nextPixel;
  166.  
  167.       colorA = nextPixel;
  168.       colorB = nextDelta;
  169.       
  170.       product = ((((colorA & colorMask) >> 1) +
  171.                   ((colorB & colorMask) >> 1) +
  172.                   (colorA & colorB & lowPixelMask)));
  173.       
  174.       *(dP + 2) = product;
  175.       *(dP + 3) = product;
  176.       *(nL + 2) = product;
  177.       *(nL + 3) = product;
  178.  
  179.       nextPixel = *bP++;
  180.       nextDelta = *xP++;
  181.       
  182.       dP += 4;
  183.       nL += 4;
  184.     } while ((u8 *) bP < finish);
  185.     
  186.     deltaPtr += srcPitch;
  187.     srcPtr += srcPitch;
  188.     dstPtr += dstPitch << 1;
  189.     nextLine += dstPitch << 1;
  190.   }
  191.   while (--height);
  192. }
  193.