Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | RSS feed

  1. /*!
  2.   \file Draw_Rect.c
  3.   \author Mario Palomo <mpalomo@ihman.com>
  4.   \author Jose M. de la Huerga Fernández
  5.   \author Pepe González Mora
  6.   \date 05-2002
  7.  
  8.   This library is free software; you can redistribute it and/or
  9.   modify it under the terms of the GNU Library General Public
  10.   License as published by the Free Software Foundation; either
  11.   version 2 of the License, or (at your option) any later version.
  12.  
  13.   This library is distributed in the hope that it will be useful,
  14.   but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16.   Library General Public License for more details.
  17.  
  18.   You should have received a copy of the GNU Library General Public
  19.   License along with this library; if not, write to the Free Foundation,
  20.   Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. */
  22.  
  23. #if SDL_DRAW_BPP == 1
  24. #define SDL_DRAW_PUTPIXEL \
  25.   memset(p0, color, w);                \
  26.   memset(p1, color, w);                \
  27.                                        \
  28.   if (h<3)  return;                    \
  29.   p0 = (Uint8*)super->pixels + (y+1)*super->pitch + x;       \
  30.   p1 = (Uint8*)super->pixels + (y+1)*super->pitch + (x+w-1); \
  31.   i = h-2;                             \
  32.   switch( i % 4 ) {                    \
  33.     do{                                \
  34.       case 0:                          \
  35.         *p0 = color; p0+=super->pitch; \
  36.         *p1 = color; p1+=super->pitch; \
  37.       case 3:                          \
  38.         *p0 = color; p0+=super->pitch; \
  39.         *p1 = color; p1+=super->pitch; \
  40.       case 2:                          \
  41.         *p0 = color; p0+=super->pitch; \
  42.         *p1 = color; p1+=super->pitch; \
  43.       case 1:                          \
  44.         *p0 = color; p0+=super->pitch; \
  45.         *p1 = color; p1+=super->pitch; \
  46.     }while( (i-=4) > 0 );              \
  47.   }
  48.  
  49.  
  50. #elif SDL_DRAW_BPP == 2
  51. #define SDL_DRAW_PUTPIXEL \
  52.   i = w;                                        \
  53.   switch( i % 4 ) {                             \
  54.     do{                                         \
  55.       case 0:                                   \
  56.         *(Uint16*)p0 = color; p0+=2;            \
  57.         *(Uint16*)p1 = color; p1+=2;            \
  58.       case 3:                                   \
  59.         *(Uint16*)p0 = color; p0+=2;            \
  60.         *(Uint16*)p1 = color; p1+=2;            \
  61.       case 2:                                   \
  62.         *(Uint16*)p0 = color; p0+=2;            \
  63.         *(Uint16*)p1 = color; p1+=2;            \
  64.       case 1:                                   \
  65.         *(Uint16*)p0 = color; p0+=2;            \
  66.         *(Uint16*)p1 = color; p1+=2;            \
  67.     }while( (i-=4) > 0 );                       \
  68.   }                                             \
  69.   if (h<3)  return;                             \
  70.   p0 = (Uint8*)super->pixels + (y+1)*super->pitch + x*2;       \
  71.   p1 = (Uint8*)super->pixels + (y+1)*super->pitch + (x+w-1)*2; \
  72.   i = h-2;                                      \
  73.   switch( i % 4 ) {                             \
  74.     do{                                         \
  75.       case 0:                                   \
  76.         *(Uint16*)p0 = color; p0+=super->pitch; \
  77.         *(Uint16*)p1 = color; p1+=super->pitch; \
  78.       case 3:                                   \
  79.         *(Uint16*)p0 = color; p0+=super->pitch; \
  80.         *(Uint16*)p1 = color; p1+=super->pitch; \
  81.       case 2:                                   \
  82.         *(Uint16*)p0 = color; p0+=super->pitch; \
  83.         *(Uint16*)p1 = color; p1+=super->pitch; \
  84.       case 1:                                   \
  85.         *(Uint16*)p0 = color; p0+=super->pitch; \
  86.         *(Uint16*)p1 = color; p1+=super->pitch; \
  87.     }while( (i-=4) > 0 );                       \
  88.   }
  89.  
  90.  
  91. #elif SDL_DRAW_BPP == 3
  92. #define SDL_DRAW_PUTPIXEL_BPP_3_AUX \
  93.     if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { \
  94.       p0[0] = colorbyte2;                  \
  95.       p0[1] = colorbyte1;                  \
  96.       p0[2] = colorbyte0;                  \
  97.       p1[0] = colorbyte2;                  \
  98.       p1[1] = colorbyte1;                  \
  99.       p1[2] = colorbyte0;                  \
  100.     } else {                               \
  101.       p0[0] = colorbyte0;                  \
  102.       p0[1] = colorbyte1;                  \
  103.       p0[2] = colorbyte2;                  \
  104.       p1[0] = colorbyte0;                  \
  105.       p1[1] = colorbyte1;                  \
  106.       p1[2] = colorbyte2;                  \
  107.     }
  108.  
  109. #define SDL_DRAW_PUTPIXEL \
  110.   i = w;                                    \
  111.   switch( i % 4 ) {                         \
  112.     do{                                     \
  113.       case 0:                               \
  114.         SDL_DRAW_PUTPIXEL_BPP_3_AUX         \
  115.         p0+=3; p1+=3;                       \
  116.       case 3:                               \
  117.         SDL_DRAW_PUTPIXEL_BPP_3_AUX         \
  118.         p0+=3; p1+=3;                       \
  119.       case 2:                               \
  120.         SDL_DRAW_PUTPIXEL_BPP_3_AUX         \
  121.         p0+=3; p1+=3;                       \
  122.       case 1:                               \
  123.         SDL_DRAW_PUTPIXEL_BPP_3_AUX         \
  124.         p0+=3; p1+=3;                       \
  125.     }while( (i-=4) > 0 );                   \
  126.   }                                         \
  127.   if (h<3)  return;                         \
  128.   p0 = (Uint8*)super->pixels + (y+1)*super->pitch + x*3;       \
  129.   p1 = (Uint8*)super->pixels + (y+1)*super->pitch + (x+w-1)*3; \
  130.   i = h-2;                                  \
  131.   switch( i % 4 ) {                         \
  132.     do{                                     \
  133.       case 0:                               \
  134.         SDL_DRAW_PUTPIXEL_BPP_3_AUX         \
  135.         p0+=super->pitch; p1+=super->pitch; \
  136.       case 3:                               \
  137.         SDL_DRAW_PUTPIXEL_BPP_3_AUX         \
  138.         p0+=super->pitch; p1+=super->pitch; \
  139.       case 2:                               \
  140.         SDL_DRAW_PUTPIXEL_BPP_3_AUX         \
  141.         p0+=super->pitch; p1+=super->pitch; \
  142.       case 1:                               \
  143.         SDL_DRAW_PUTPIXEL_BPP_3_AUX         \
  144.         p0+=super->pitch; p1+=super->pitch; \
  145.     }while( (i-=4) > 0 );                   \
  146.   }
  147.  
  148.  
  149. #elif SDL_DRAW_BPP == 4
  150.  
  151. #ifdef __linux__
  152. #define SDL_DRAW_WMEMSET_START \
  153. if (sizeof(wchar_t) == sizeof(Uint32)) { \
  154.   wmemset((wchar_t*)p0, color, w); \
  155.   wmemset((wchar_t*)p1, color, w); \
  156. } else {
  157. #define SDL_DRAW_WMEMSET_END }
  158. #else
  159. #define SDL_DRAW_WMEMSET_START
  160. #define SDL_DRAW_WMEMSET_END
  161. #endif
  162.  
  163. #define SDL_DRAW_PUTPIXEL \
  164. SDL_DRAW_WMEMSET_START                          \
  165.   i = w;                                        \
  166.   switch( i % 4 ) {                             \
  167.     do{                                         \
  168.       case 0:                                   \
  169.         *(Uint32*)p0 = color; p0+=4;            \
  170.         *(Uint32*)p1 = color; p1+=4;            \
  171.       case 3:                                   \
  172.         *(Uint32*)p0 = color; p0+=4;            \
  173.         *(Uint32*)p1 = color; p1+=4;            \
  174.       case 2:                                   \
  175.         *(Uint32*)p0 = color; p0+=4;            \
  176.         *(Uint32*)p1 = color; p1+=4;            \
  177.       case 1:                                   \
  178.         *(Uint32*)p0 = color; p0+=4;            \
  179.         *(Uint32*)p1 = color; p1+=4;            \
  180.     }while( (i-=4) > 0 );                       \
  181.   }                                             \
  182. SDL_DRAW_WMEMSET_END                            \
  183.   if (h<3)  return;                             \
  184.   p0 = (Uint8*)super->pixels + (y+1)*super->pitch + x*4;       \
  185.   p1 = (Uint8*)super->pixels + (y+1)*super->pitch + (x+w-1)*4; \
  186.   i = h-2;                                      \
  187.   switch( i % 4 ) {                             \
  188.     do{                                         \
  189.       case 0:                                   \
  190.         *(Uint32*)p0 = color; p0+=super->pitch; \
  191.         *(Uint32*)p1 = color; p1+=super->pitch; \
  192.       case 3:                                   \
  193.         *(Uint32*)p0 = color; p0+=super->pitch; \
  194.         *(Uint32*)p1 = color; p1+=super->pitch; \
  195.       case 2:                                   \
  196.         *(Uint32*)p0 = color; p0+=super->pitch; \
  197.         *(Uint32*)p1 = color; p1+=super->pitch; \
  198.       case 1:                                   \
  199.         *(Uint32*)p0 = color; p0+=super->pitch; \
  200.         *(Uint32*)p1 = color; p1+=super->pitch; \
  201.     }while( (i-=4) > 0 );                       \
  202.   }
  203.  
  204. #endif /*SDL_DRAW_BPP*/
  205.  
  206.  
  207. void SDL_DRAWFUNCTION(SDL_Surface *super,
  208.                   Sint16 x, Sint16 y, Uint16 w, Uint16 h,
  209.                   Uint32 color)
  210. {
  211. #if SDL_DRAW_BPP == 3
  212.   Uint8 colorbyte0 = (Uint8) (color & 0xff);
  213.   Uint8 colorbyte1 = (Uint8) ((color >> 8)  & 0xff);
  214.   Uint8 colorbyte2 = (Uint8) ((color >> 16) & 0xff);
  215. #endif
  216.  
  217.   register Uint8 *p0;
  218.   register Uint8 *p1;
  219.   register Sint16 i;
  220.  
  221.   if (w==0 || h==0)  return;
  222.  
  223.   p0 = (Uint8*)super->pixels +    y    * super->pitch + x * SDL_DRAW_BPP;
  224.   p1 = (Uint8*)super->pixels + (y+h-1) * super->pitch + x * SDL_DRAW_BPP;
  225.  
  226.   SDL_DRAW_PUTPIXEL
  227.  
  228. }/*Draw_Rect*/
  229.  
  230.  
  231. #undef SDL_DRAW_PUTPIXEL
  232. #undef SDL_DRAW_PUTPIXEL_BPP_3_AUX
  233.  
  234. #undef SDL_DRAW_WMEMSET_START
  235. #undef SDL_DRAW_WMEMSET_END
  236.  
  237.