Main Page | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

SDLMain.cpp File Reference

#include "SDLMain.h"
#include "SDL_rotozoom.h"
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>

Go to the source code of this file.

Defines

#define CLIP_LEFT_EDGE   0x1
#define CLIP_RIGHT_EDGE   0x2
#define CLIP_BOTTOM_EDGE   0x4
#define CLIP_TOP_EDGE   0x8
#define CLIP_INSIDE(a)   (!a)
#define CLIP_REJECT(a, b)   (a&b)
#define CLIP_ACCEPT(a, b)   (!(a|b))
#define clip_xmin(surface)   surface->clip_rect.x
#define clip_xmax(surface)   surface->clip_rect.x+surface->clip_rect.w-1
#define clip_ymin(surface)   surface->clip_rect.y
#define clip_ymax(surface)   surface->clip_rect.y+surface->clip_rect.h-1
#define R(color)   (((color)&0xff0000)>>16)
#define G(color)   (((color)&0x00ff00)>>8)
#define B(color)   (((color)&0x0000ff))

Functions

int clipEncode (Sint16 x, Sint16 y, Sint16 left, Sint16 top, Sint16 right, Sint16 bottom)
int clipLine (SDL_Surface *dst, Sint16 *x1, Sint16 *y1, Sint16 *x2, Sint16 *y2)
int _putPixelAlpha (SDL_Surface *surface, Sint16 x, Sint16 y, Uint32 color, Uint8 alpha)
int pixelColorNolock (SDL_Surface *dst, Sint16 x, Sint16 y, Uint32 color)


Define Documentation

#define CLIP_LEFT_EDGE   0x1
 

Definition at line 625 of file SDLMain.cpp.

Referenced by clipEncode(), and clipLine().

#define CLIP_RIGHT_EDGE   0x2
 

Definition at line 626 of file SDLMain.cpp.

Referenced by clipEncode(), and clipLine().

#define CLIP_BOTTOM_EDGE   0x4
 

Definition at line 627 of file SDLMain.cpp.

Referenced by clipEncode(), and clipLine().

#define CLIP_TOP_EDGE   0x8
 

Definition at line 628 of file SDLMain.cpp.

Referenced by clipEncode(), and clipLine().

#define CLIP_INSIDE  )     (!a)
 

Definition at line 629 of file SDLMain.cpp.

Referenced by clipLine().

#define CLIP_REJECT a,
 )     (a&b)
 

Definition at line 630 of file SDLMain.cpp.

Referenced by clipLine().

#define CLIP_ACCEPT a,
 )     (!(a|b))
 

Definition at line 631 of file SDLMain.cpp.

Referenced by clipLine().

#define clip_xmin surface   )     surface->clip_rect.x
 

Definition at line 722 of file SDLMain.cpp.

Referenced by _putPixelAlpha().

#define clip_xmax surface   )     surface->clip_rect.x+surface->clip_rect.w-1
 

Definition at line 723 of file SDLMain.cpp.

Referenced by _putPixelAlpha().

#define clip_ymin surface   )     surface->clip_rect.y
 

Definition at line 724 of file SDLMain.cpp.

Referenced by _putPixelAlpha().

#define clip_ymax surface   )     surface->clip_rect.y+surface->clip_rect.h-1
 

Definition at line 725 of file SDLMain.cpp.

Referenced by _putPixelAlpha().

#define R color   )     (((color)&0xff0000)>>16)
 

Definition at line 1319 of file SDLMain.cpp.

Referenced by _putPixelAlpha(), SDLMain::horizgradient(), and SDLMain::vertgradient().

#define G color   )     (((color)&0x00ff00)>>8)
 

Definition at line 1320 of file SDLMain.cpp.

Referenced by _putPixelAlpha(), SDLMain::horizgradient(), and SDLMain::vertgradient().

#define B color   )     (((color)&0x0000ff))
 

Definition at line 1321 of file SDLMain.cpp.

Referenced by _putPixelAlpha(), SDLMain::horizgradient(), and SDLMain::vertgradient().


Function Documentation

int clipEncode Sint16  x,
Sint16  y,
Sint16  left,
Sint16  top,
Sint16  right,
Sint16  bottom
[static]
 

Definition at line 633 of file SDLMain.cpp.

References CLIP_BOTTOM_EDGE, CLIP_LEFT_EDGE, CLIP_RIGHT_EDGE, CLIP_TOP_EDGE, LOG_ENTER, and LOG_EXIT.

Referenced by clipLine().

00634 {
00635     char *CLASS = "None";
00636     static char *functionName="clipEncode";
00637     LOG_ENTER 
00638     int code = 0;
00639     if (x < left) {
00640     code |= CLIP_LEFT_EDGE;
00641     } else if (x > right) {
00642     code |= CLIP_RIGHT_EDGE;
00643     }
00644     if (y < top) {
00645     code |= CLIP_TOP_EDGE;
00646     } else if (y > bottom) {
00647     code |= CLIP_BOTTOM_EDGE;
00648     }
00649     LOG_EXIT
00650     return code;
00651 }

int clipLine SDL_Surface *  dst,
Sint16 *  x1,
Sint16 *  y1,
Sint16 *  x2,
Sint16 *  y2
[static]
 

Definition at line 653 of file SDLMain.cpp.

References CLIP_ACCEPT, CLIP_BOTTOM_EDGE, CLIP_INSIDE, CLIP_LEFT_EDGE, CLIP_REJECT, CLIP_RIGHT_EDGE, CLIP_TOP_EDGE, clipEncode(), LOG_ENTER, and LOG_EXIT.

Referenced by SDLMain::line().

00654 {
00655     char *CLASS = "None";
00656     static char *functionName="clipLine";
00657     LOG_ENTER 
00658     Sint16 left, right, top, bottom;
00659     int code1, code2;
00660     int draw = 0;
00661     Sint16 swaptmp;
00662     float m;
00663 
00664     /*
00665      * Get clipping boundary 
00666      */
00667     left = dst->clip_rect.x;
00668     right = dst->clip_rect.x + dst->clip_rect.w - 1;
00669     top = dst->clip_rect.y;
00670     bottom = dst->clip_rect.y + dst->clip_rect.h - 1;
00671 
00672     while (1) {
00673     code1 = clipEncode(*x1, *y1, left, top, right, bottom);
00674     code2 = clipEncode(*x2, *y2, left, top, right, bottom);
00675     if (CLIP_ACCEPT(code1, code2)) {
00676         draw = 1;
00677         break;
00678     } else if (CLIP_REJECT(code1, code2))
00679         break;
00680     else {
00681         if (CLIP_INSIDE(code1)) {
00682         swaptmp = *x2;
00683         *x2 = *x1;
00684         *x1 = swaptmp;
00685         swaptmp = *y2;
00686         *y2 = *y1;
00687         *y1 = swaptmp;
00688         swaptmp = code2;
00689         code2 = code1;
00690         code1 = swaptmp;
00691         }
00692         if (*x2 != *x1) {
00693         m = (*y2 - *y1) / (float) (*x2 - *x1);
00694         } else {
00695         m = 1.0f;
00696         }
00697         if (code1 & CLIP_LEFT_EDGE) {
00698         *y1 += (Sint16) ((left - *x1) * m);
00699         *x1 = left;
00700         } else if (code1 & CLIP_RIGHT_EDGE) {
00701         *y1 += (Sint16) ((right - *x1) * m);
00702         *x1 = right;
00703         } else if (code1 & CLIP_BOTTOM_EDGE) {
00704         if (*x2 != *x1) {
00705             *x1 += (Sint16) ((bottom - *y1) / m);
00706         }
00707         *y1 = bottom;
00708         } else if (code1 & CLIP_TOP_EDGE) {
00709         if (*x2 != *x1) {
00710             *x1 += (Sint16) ((top - *y1) / m);
00711         }
00712         *y1 = top;
00713         }
00714     }
00715     }
00716 
00717     LOG_EXIT
00718     return draw;
00719 }

Here is the call graph for this function:

int _putPixelAlpha SDL_Surface *  surface,
Sint16  x,
Sint16  y,
Uint32  color,
Uint8  alpha
 

Definition at line 727 of file SDLMain.cpp.

References B, clip_xmax, clip_xmin, clip_ymax, clip_ymin, G, LOG_ENTER, LOG_EXIT, and R.

Referenced by pixelColorNolock().

00728 {
00729     char *CLASS = "None";
00730     static char *functionName="_putPixelAlpha";
00731     LOG_ENTER 
00732 
00733     Uint32 Rmask = surface->format->Rmask, Gmask =
00734     surface->format->Gmask, Bmask = surface->format->Bmask, Amask = surface->format->Amask;
00735     Uint32 R, G, B, A = 0;
00736 
00737     if (x >= clip_xmin(surface) && x <= clip_xmax(surface)
00738     && y >= clip_ymin(surface) && y <= clip_ymax(surface)) {
00739 
00740     switch (surface->format->BytesPerPixel) {
00741     case 1:{        /* Assuming 8-bpp */
00742         if (alpha == 255) {
00743             *((Uint8 *) surface->pixels + y * surface->pitch + x) = color;
00744         } else {
00745             Uint8 *pixel = (Uint8 *) surface->pixels + y * surface->pitch + x;
00746 
00747             Uint8 dR = surface->format->palette->colors[*pixel].r;
00748             Uint8 dG = surface->format->palette->colors[*pixel].g;
00749             Uint8 dB = surface->format->palette->colors[*pixel].b;
00750             Uint8 sR = surface->format->palette->colors[color].r;
00751             Uint8 sG = surface->format->palette->colors[color].g;
00752             Uint8 sB = surface->format->palette->colors[color].b;
00753 
00754             dR = dR + ((sR - dR) * alpha >> 8);
00755             dG = dG + ((sG - dG) * alpha >> 8);
00756             dB = dB + ((sB - dB) * alpha >> 8);
00757 
00758             *pixel = SDL_MapRGB(surface->format, dR, dG, dB);
00759         }
00760         }
00761         break;
00762 
00763     case 2:{        /* Probably 15-bpp or 16-bpp */
00764         if (alpha == 255) {
00765             *((Uint16 *) surface->pixels + y * surface->pitch / 2 + x) = color;
00766         } else {
00767             Uint16 *pixel = (Uint16 *) surface->pixels + y * surface->pitch / 2 + x;
00768             Uint32 dc = *pixel;
00769 
00770             R = ((dc & Rmask) + (((color & Rmask) - (dc & Rmask)) * alpha >> 8)) & Rmask;
00771             G = ((dc & Gmask) + (((color & Gmask) - (dc & Gmask)) * alpha >> 8)) & Gmask;
00772             B = ((dc & Bmask) + (((color & Bmask) - (dc & Bmask)) * alpha >> 8)) & Bmask;
00773             if (Amask)
00774             A = ((dc & Amask) + (((color & Amask) - (dc & Amask)) * alpha >> 8)) & Amask;
00775 
00776             *pixel = R | G | B | A;
00777         }
00778         }
00779         break;
00780 
00781     case 3:{        /* Slow 24-bpp mode, usually not used */
00782         Uint8 *pix = (Uint8 *) surface->pixels + y * surface->pitch + x * 3;
00783         Uint8 rshift8 = surface->format->Rshift / 8;
00784         Uint8 gshift8 = surface->format->Gshift / 8;
00785         Uint8 bshift8 = surface->format->Bshift / 8;
00786         Uint8 ashift8 = surface->format->Ashift / 8;
00787 
00788 
00789         if (alpha == 255) {
00790             *(pix + rshift8) = color >> surface->format->Rshift;
00791             *(pix + gshift8) = color >> surface->format->Gshift;
00792             *(pix + bshift8) = color >> surface->format->Bshift;
00793             *(pix + ashift8) = color >> surface->format->Ashift;
00794         } else {
00795             Uint8 dR, dG, dB, dA = 0;
00796             Uint8 sR, sG, sB, sA = 0;
00797 
00798             pix = (Uint8 *) surface->pixels + y * surface->pitch + x * 3;
00799 
00800             dR = *((pix) + rshift8);
00801             dG = *((pix) + gshift8);
00802             dB = *((pix) + bshift8);
00803             dA = *((pix) + ashift8);
00804 
00805             sR = (color >> surface->format->Rshift) & 0xff;
00806             sG = (color >> surface->format->Gshift) & 0xff;
00807             sB = (color >> surface->format->Bshift) & 0xff;
00808             sA = (color >> surface->format->Ashift) & 0xff;
00809 
00810             dR = dR + ((sR - dR) * alpha >> 8);
00811             dG = dG + ((sG - dG) * alpha >> 8);
00812             dB = dB + ((sB - dB) * alpha >> 8);
00813             dA = dA + ((sA - dA) * alpha >> 8);
00814 
00815             *((pix) + rshift8) = dR;
00816             *((pix) + gshift8) = dG;
00817             *((pix) + bshift8) = dB;
00818             *((pix) + ashift8) = dA;
00819         }
00820         }
00821         break;
00822 
00823     case 4:{        /* Probably 32-bpp */
00824         if (alpha == 255) {
00825             *((Uint32 *) surface->pixels + y * surface->pitch / 4 + x) = color;
00826         } else {
00827             Uint32 *pixel = (Uint32 *) surface->pixels + y * surface->pitch / 4 + x;
00828             Uint32 dc = *pixel;
00829 
00830             R = ((dc & Rmask) + (((color & Rmask) - (dc & Rmask)) * alpha >> 8)) & Rmask;
00831             G = ((dc & Gmask) + (((color & Gmask) - (dc & Gmask)) * alpha >> 8)) & Gmask;
00832             B = ((dc & Bmask) + (((color & Bmask) - (dc & Bmask)) * alpha >> 8)) & Bmask;
00833             if (Amask)
00834             A = ((dc & Amask) + (((color & Amask) - (dc & Amask)) * alpha >> 8)) & Amask;
00835 
00836             *pixel = R | G | B | A;
00837         }
00838         }
00839         break;
00840     }
00841     }
00842 
00843     LOG_EXIT
00844     return (0);
00845 }

int pixelColorNolock SDL_Surface *  dst,
Sint16  x,
Sint16  y,
Uint32  color
 

Definition at line 848 of file SDLMain.cpp.

References _putPixelAlpha(), LOG_ENTER, and LOG_EXIT.

Referenced by SDLMain::line().

00849 {
00850     char *CLASS = "None";
00851     static char *functionName="pixelColorNolock";
00852     LOG_ENTER 
00853     Uint8 alpha;
00854     Uint32 mcolor;
00855     int result = 0;
00856 
00857     /*
00858      * Setup color 
00859      */
00860     alpha = color & 0x000000ff;
00861     mcolor =
00862     SDL_MapRGBA(dst->format, (color & 0xff000000) >> 24,
00863             (color & 0x00ff0000) >> 16, (color & 0x0000ff00) >> 8, alpha);
00864 
00865     /*
00866      * Draw 
00867      */
00868     result = _putPixelAlpha(dst, x, y, mcolor, alpha);
00869 
00870     LOG_EXIT
00871     return (result);
00872 }

Here is the call graph for this function:


Generated on Wed Jul 14 00:43:44 2004 for CSLib by doxygen 1.3.6