Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | RSS feed

  1. /*!
  2.   \file Draw_FillCircle.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, 2*x+1); \
  26.   memset(p1, color, 2*x+1); \
  27.   p0 = ((Uint8*)super->pixels+ (y0+x)*super->pitch+ (x0-y)); \
  28.   p1 = ((Uint8*)super->pixels+ (y0-x)*super->pitch+ (x0-y)); \
  29.   memset(p0, color, 2*y+1); \
  30.   memset(p1, color, 2*y+1);
  31.  
  32. #elif SDL_DRAW_BPP == 2
  33. #define SDL_DRAW_PUTPIXEL \
  34.   i = 2*x+1;                                              \
  35.   switch( i % 4 ) {                                       \
  36.     do{                                                   \
  37.       case 0: *(Uint16*)p0 = color; *(Uint16*)p1 = color; \
  38.               p0+=2; p1+=2;                               \
  39.       case 3: *(Uint16*)p0 = color; *(Uint16*)p1 = color; \
  40.               p0+=2; p1+=2;                               \
  41.       case 2: *(Uint16*)p0 = color; *(Uint16*)p1 = color; \
  42.               p0+=2; p1+=2;                               \
  43.       case 1: *(Uint16*)p0 = color; *(Uint16*)p1 = color; \
  44.               p0+=2; p1+=2;                               \
  45.     }while( (i-=4) > 0 );                                 \
  46.   }                                                       \
  47.   p0 = ((Uint8*)super->pixels+ (y0+x)*super->pitch+ (x0-y)*2); \
  48.   p1 = ((Uint8*)super->pixels+ (y0-x)*super->pitch+ (x0-y)*2); \
  49.   i = 2*y+1;                                              \
  50.   switch( i % 4 ) {                                       \
  51.     do{                                                   \
  52.       case 0: *(Uint16*)p0 = color; *(Uint16*)p1 = color; \
  53.               p0+=2; p1+=2;                               \
  54.       case 3: *(Uint16*)p0 = color; *(Uint16*)p1 = color; \
  55.               p0+=2; p1+=2;                               \
  56.       case 2: *(Uint16*)p0 = color; *(Uint16*)p1 = color; \
  57.               p0+=2; p1+=2;                               \
  58.       case 1: *(Uint16*)p0 = color; *(Uint16*)p1 = color; \
  59.               p0+=2; p1+=2;                               \
  60.     }while( (i-=4) > 0 );                                 \
  61.   }
  62.  
  63.  
  64. #elif SDL_DRAW_BPP == 3
  65. #define SDL_DRAW_PUTPIXEL_BPP_3_AUX \
  66.     if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { \
  67.       p0[0] = colorbyte2;                   \
  68.       p0[1] = colorbyte1;                   \
  69.       p0[2] = colorbyte0;                   \
  70.       p1[0] = colorbyte2;                   \
  71.       p1[1] = colorbyte1;                   \
  72.       p1[2] = colorbyte0;                   \
  73.     } else {                                \
  74.       p0[0] = colorbyte0;                   \
  75.       p0[1] = colorbyte1;                   \
  76.       p0[2] = colorbyte2;                   \
  77.       p1[0] = colorbyte0;                   \
  78.       p1[1] = colorbyte1;                   \
  79.       p1[2] = colorbyte2;                   \
  80.     }
  81.  
  82. #define SDL_DRAW_PUTPIXEL \
  83.   i = 2*x+1;                              \
  84.   switch( i % 4 ) {                       \
  85.     do{                                   \
  86.       case 0: SDL_DRAW_PUTPIXEL_BPP_3_AUX \
  87.               p0+=3; p1+=3;               \
  88.       case 3: SDL_DRAW_PUTPIXEL_BPP_3_AUX \
  89.               p0+=3; p1+=3;               \
  90.       case 2: SDL_DRAW_PUTPIXEL_BPP_3_AUX \
  91.               p0+=3; p1+=3;               \
  92.       case 1: SDL_DRAW_PUTPIXEL_BPP_3_AUX \
  93.               p0+=3; p1+=3;               \
  94.     }while( (i-=4) > 0 );                 \
  95.   }                                       \
  96.   p0 = ((Uint8*)super->pixels+ (y0+x)*super->pitch+ (x0-y)*3); \
  97.   p1 = ((Uint8*)super->pixels+ (y0-x)*super->pitch+ (x0-y)*3); \
  98.   i = 2*y+1;                              \
  99.   switch( i % 4 ) {                       \
  100.     do{                                   \
  101.       case 0: SDL_DRAW_PUTPIXEL_BPP_3_AUX \
  102.               p0+=3; p1+=3;               \
  103.       case 3: SDL_DRAW_PUTPIXEL_BPP_3_AUX \
  104.               p0+=3; p1+=3;               \
  105.       case 2: SDL_DRAW_PUTPIXEL_BPP_3_AUX \
  106.               p0+=3; p1+=3;               \
  107.       case 1: SDL_DRAW_PUTPIXEL_BPP_3_AUX \
  108.               p0+=3; p1+=3;               \
  109.     }while( (i-=4) > 0 );                 \
  110.   }
  111.  
  112.  
  113. #elif SDL_DRAW_BPP == 4
  114.  
  115. #ifdef __linux__
  116. #define SDL_DRAW_WMEMSET_START \
  117. if (sizeof(wchar_t) == sizeof(Uint32)) { \
  118.   wmemset((wchar_t*)p0, color, 2*x+1); \
  119.   wmemset((wchar_t*)p1, color, 2*x+1); \
  120.   p0 = ((Uint8*)super->pixels+ (y0+x)*super->pitch+ (x0-y)*4); \
  121.   p1 = ((Uint8*)super->pixels+ (y0-x)*super->pitch+ (x0-y)*4); \
  122.   wmemset((wchar_t*)p0, color, 2*y+1); \
  123.   wmemset((wchar_t*)p1, color, 2*y+1); \
  124. } else {
  125. #define SDL_DRAW_WMEMSET_END }
  126. #else
  127. #define SDL_DRAW_WMEMSET_START
  128. #define SDL_DRAW_WMEMSET_END
  129. #endif
  130.  
  131. #define SDL_DRAW_PUTPIXEL \
  132. SDL_DRAW_WMEMSET_START                                    \
  133.   i = 2*x+1;                                              \
  134.   switch( i % 4 ) {                                       \
  135.     do{                                                   \
  136.       case 0: *(Uint32*)p0 = color; *(Uint32*)p1 = color; \
  137.               p0+=4; p1+=4;                               \
  138.       case 3: *(Uint32*)p0 = color; *(Uint32*)p1 = color; \
  139.               p0+=4; p1+=4;                               \
  140.       case 2: *(Uint32*)p0 = color; *(Uint32*)p1 = color; \
  141.               p0+=4; p1+=4;                               \
  142.       case 1: *(Uint32*)p0 = color; *(Uint32*)p1 = color; \
  143.               p0+=4; p1+=4;                               \
  144.     }while( (i-=4) > 0 );                                 \
  145.   }                                                       \
  146.   p0 = ((Uint8*)super->pixels+ (y0+x)*super->pitch+ (x0-y)*4); \
  147.   p1 = ((Uint8*)super->pixels+ (y0-x)*super->pitch+ (x0-y)*4); \
  148.   i = 2*y+1;                                              \
  149.   switch( i % 4 ) {                                       \
  150.     do{                                                   \
  151.       case 0: *(Uint32*)p0 = color; *(Uint32*)p1 = color; \
  152.               p0+=4; p1+=4;                               \
  153.       case 3: *(Uint32*)p0 = color; *(Uint32*)p1 = color; \
  154.               p0+=4; p1+=4;                               \
  155.       case 2: *(Uint32*)p0 = color; *(Uint32*)p1 = color; \
  156.               p0+=4; p1+=4;                               \
  157.       case 1: *(Uint32*)p0 = color; *(Uint32*)p1 = color; \
  158.               p0+=4; p1+=4;                               \
  159.     }while( (i-=4) > 0 );                                 \
  160.   }                                                       \
  161. SDL_DRAW_WMEMSET_END
  162.  
  163. #endif /*SDL_DRAW_BPP*/
  164.  
  165.  
  166.  
  167. void SDL_DRAWFUNCTION(SDL_Surface *super,
  168.                       Sint16 x0, Sint16 y0, Uint16 r,
  169.                       Uint32 color)
  170. {
  171. #if SDL_DRAW_BPP == 3
  172.   Uint8 colorbyte0 = (Uint8) (color & 0xff);
  173.   Uint8 colorbyte1 = (Uint8) ((color >> 8) & 0xff);
  174.   Uint8 colorbyte2 = (Uint8) ((color >> 16) & 0xff);
  175. #endif
  176.  
  177.   register Uint8 *p0;
  178.   register Uint8 *p1;
  179. #if SDL_DRAW_BPP != 1
  180.   register Sint16 i;
  181. #endif
  182.  
  183.   Sint16 x = 0;
  184.   Sint16 y = r-1;     /*radius zero == draw nothing*/
  185.   Sint16 d = 3 - 2*r;
  186.   Sint16 diagonalInc = 10 - 4*r;
  187.   Sint16 rightInc = 6;
  188.  
  189.   while (x <= y) {
  190.  
  191.     p0 = ((Uint8*)super->pixels+ (y0+y)*super->pitch+ (x0-x)*SDL_DRAW_BPP);
  192.     p1 = ((Uint8*)super->pixels+ (y0-y)*super->pitch+ (x0-x)*SDL_DRAW_BPP);
  193.  
  194.     SDL_DRAW_PUTPIXEL
  195.  
  196.     if (d >=  0) {
  197.       d += diagonalInc;
  198.       diagonalInc += 8;
  199.       y -= 1;
  200.     } else {
  201.       d += rightInc;
  202.       diagonalInc += 4;
  203.     }
  204.     rightInc += 4;
  205.     x += 1;
  206.   }
  207.  
  208. }/*Draw_FillCircle*/
  209.  
  210.  
  211. #undef SDL_DRAW_PUTPIXEL
  212. #undef SDL_DRAW_PUTPIXEL_BPP_3_AUX
  213.  
  214. #undef SDL_DRAW_WMEMSET_START
  215. #undef SDL_DRAW_WMEMSET_END
  216.  
  217.