Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | RSS feed

  1. /*!
  2.   \file Draw_HLine.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(p, color, x1-x0+1);
  26.  
  27. #elif SDL_DRAW_BPP == 2
  28. #define SDL_DRAW_PUTPIXEL \
  29.   i = x1-x0+1;                           \
  30.   switch( i % 4 ) {                      \
  31.     do{                                  \
  32.       case 0: *(Uint16*)p = color; p+=2; \
  33.       case 3: *(Uint16*)p = color; p+=2; \
  34.       case 2: *(Uint16*)p = color; p+=2; \
  35.       case 1: *(Uint16*)p = color; p+=2; \
  36.     }while( (i-=4) > 0 );                \
  37.   }
  38.  
  39. #elif SDL_DRAW_BPP == 3
  40. #define SDL_DRAW_PUTPIXEL_BPP_3_AUX \
  41.     if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { \
  42.       p[0] = colorbyte2;                   \
  43.       p[1] = colorbyte1;                   \
  44.       p[2] = colorbyte0;                   \
  45.     } else {                               \
  46.       p[0] = colorbyte0;                   \
  47.       p[1] = colorbyte1;                   \
  48.       p[2] = colorbyte2;                   \
  49.     }
  50.  
  51. #define SDL_DRAW_PUTPIXEL \
  52.   i = x1-x0+1;                                   \
  53.   switch( i % 4 ) {                              \
  54.     do{                                          \
  55.       case 0: SDL_DRAW_PUTPIXEL_BPP_3_AUX  p+=3; \
  56.       case 3: SDL_DRAW_PUTPIXEL_BPP_3_AUX  p+=3; \
  57.       case 2: SDL_DRAW_PUTPIXEL_BPP_3_AUX  p+=3; \
  58.       case 1: SDL_DRAW_PUTPIXEL_BPP_3_AUX  p+=3; \
  59.     }while( (i-=4) > 0 );                        \
  60.   }
  61.  
  62. #elif SDL_DRAW_BPP == 4
  63.  
  64. #ifdef __linux__
  65. #define SDL_DRAW_WMEMSET_START \
  66. if (sizeof(wchar_t) == sizeof(Uint32)) { \
  67.   wmemset((wchar_t*)p, color, x1-x0+1);  \
  68. } else {
  69. #define SDL_DRAW_WMEMSET_END }
  70. #else
  71. #define SDL_DRAW_WMEMSET_START
  72. #define SDL_DRAW_WMEMSET_END
  73. #endif
  74.  
  75. #define SDL_DRAW_PUTPIXEL \
  76. SDL_DRAW_WMEMSET_START                   \
  77.   i = x1-x0+1;                           \
  78.   switch( i % 4 ) {                      \
  79.     do{                                  \
  80.       case 0: *(Uint32*)p = color; p+=4; \
  81.       case 3: *(Uint32*)p = color; p+=4; \
  82.       case 2: *(Uint32*)p = color; p+=4; \
  83.       case 1: *(Uint32*)p = color; p+=4; \
  84.     }while( (i-=4) > 0 );                \
  85.   }                                      \
  86. SDL_DRAW_WMEMSET_END
  87.  
  88. #endif /*SDL_DRAW_BPP*/
  89.  
  90.  
  91. void SDL_DRAWFUNCTION(SDL_Surface *super,
  92.                       Sint16 x0,Sint16 y0, Sint16 x1,
  93.                       Uint32 color)
  94. {
  95. #if SDL_DRAW_BPP == 3
  96.   Uint8 colorbyte0 = (Uint8) (color & 0xff);
  97.   Uint8 colorbyte1 = (Uint8) ((color >> 8) & 0xff);
  98.   Uint8 colorbyte2 = (Uint8) ((color >> 16) & 0xff);
  99. #endif
  100.  
  101.   register Uint8 *p;
  102.   register Sint16 i;
  103.  
  104.   if (x0 > x1)  { i=x1; x1=x0; x0=i; }
  105.   p = (Uint8*)super->pixels + y0 * super->pitch + x0 * SDL_DRAW_BPP;
  106.  
  107.   SDL_DRAW_PUTPIXEL
  108.  
  109. }/*Draw_HLine*/
  110.  
  111.  
  112. #undef SDL_DRAW_PUTPIXEL
  113. #undef SDL_DRAW_PUTPIXEL_BPP_3_AUX
  114.  
  115. #undef SDL_DRAW_WMEMSET_START
  116. #undef SDL_DRAW_WMEMSET_END
  117.  
  118.