home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 July / CMCD0704.ISO / Software / Freeware / Utilitare / VisualBoyAdvance-1.7.2 / src / pixel.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2004-05-15  |  4.0 KB  |  151 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 Pixelate(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.   
  29.   nextLine = dstPtr + dstPitch;
  30.   
  31.   do {
  32.     u32 *bP = (u32 *) srcPtr;
  33.     u32 *xP = (u32 *) deltaPtr;
  34.     u32 *dP = (u32 *) dstPtr;
  35.     u32 *nL = (u32 *) nextLine;
  36.     u32 currentPixel;
  37.     u32 nextPixel;
  38.     u32 currentDelta;
  39.     u32 nextDelta;
  40.     
  41.     finish = (u8 *) bP + ((width+2) << 1);
  42.     nextPixel = *bP++;
  43.     nextDelta = *xP++;
  44.     
  45.     do {
  46.       currentPixel = nextPixel;
  47.       currentDelta = nextDelta;
  48.       nextPixel = *bP++;
  49.       nextDelta = *xP++;
  50.       
  51.       if ((nextPixel != nextDelta) || (currentPixel != currentDelta)) {
  52.         u32 colorA, colorB, product;
  53.         
  54.         *(xP - 2) = currentPixel;
  55. #ifdef WORDS_BIGENDIAN
  56.         colorA = currentPixel >> 16;
  57.         colorB = currentPixel & 0xffff;
  58. #else
  59.         colorA = currentPixel & 0xffff;
  60.         colorB = currentPixel >> 16;
  61. #endif
  62.         product = (((colorA & colorMask) >> 1) & colorMask) >> 1;
  63.         
  64. #ifdef WORDS_BIGENDIAN
  65.         *(nL) = (product << 16) | (product);
  66.         *(dP) = (colorA << 16) | product;
  67. #else
  68.         *(nL) = product | (product << 16);
  69.         *(dP) = colorA | (product << 16);
  70. #endif
  71.         
  72. #ifdef WORDS_BIGENDIAN
  73.         colorA = nextPixel >> 16;
  74. #else
  75.         colorA = nextPixel & 0xffff;
  76. #endif
  77.         product = (((colorB & colorMask) >> 1) & colorMask) >> 1;
  78. #ifdef WORDS_BIGENDIAN
  79.         *(nL + 1) = (product << 16) | (product);
  80.         *(dP + 1) = (colorB << 16) | (product);
  81. #else
  82.         *(nL + 1) = (product) | (product << 16);
  83.         *(dP + 1) = (colorB) | (product << 16);
  84. #endif
  85.       }
  86.       
  87.       dP += 2;
  88.       nL += 2;
  89.     } while ((u8 *) bP < finish);
  90.     
  91.     deltaPtr += srcPitch;
  92.     srcPtr += srcPitch;
  93.     dstPtr += dstPitch << 1;
  94.     nextLine += dstPitch << 1;
  95.   }
  96.   while (--height);
  97. }
  98.  
  99. void Pixelate32(u8 *srcPtr, u32 srcPitch, u8 * /* deltaPtr */,
  100.                 u8 *dstPtr, u32 dstPitch, int width, int height)
  101. {
  102.   u8 *nextLine, *finish;
  103.   u32 colorMask = ~RGB_LOW_BITS_MASK;
  104.   
  105.   nextLine = dstPtr + dstPitch;
  106.   
  107.   do {
  108.     u32 *bP = (u32 *) srcPtr;
  109.     //    u32 *xP = (u32 *) deltaPtr;
  110.     u32 *dP = (u32 *) dstPtr;
  111.     u32 *nL = (u32 *) nextLine;
  112.     u32 currentPixel;
  113.     u32 nextPixel;
  114.     
  115.     finish = (u8 *) bP + ((width+1) << 2);
  116.     nextPixel = *bP++;
  117.     
  118.     do {
  119.       currentPixel = nextPixel;
  120.       nextPixel = *bP++;
  121.       
  122.       u32 colorA, colorB, product;
  123.         
  124.       colorA = currentPixel;
  125.       colorB = nextPixel;
  126.  
  127.       product = (((colorA & colorMask) >> 1) & colorMask) >> 1;
  128.       *(nL) = product;
  129.       *(nL+1) = product;
  130.       *(dP) = colorA;
  131.       *(dP+1) = product;
  132.  
  133.       nextPixel = *bP++;
  134.       colorA = nextPixel;
  135.       product = (((colorB & colorMask) >> 1) & colorMask) >> 1;
  136.       *(nL + 2) = product;
  137.       *(nL + 3) = product;
  138.       *(dP + 2) = colorB;
  139.       *(dP + 3) = product;
  140.       
  141.       dP += 4;
  142.       nL += 4;
  143.     } while ((u8 *) bP < finish);
  144.     
  145.     srcPtr += srcPitch;
  146.     dstPtr += dstPitch << 1;
  147.     nextLine += dstPitch << 1;
  148.   }
  149.   while (--height);
  150. }
  151.