SDL  2.0
SDL_shape_internals.h File Reference
#include "../SDL_internal.h"
#include "SDL_rect.h"
#include "SDL_shape.h"
#include "SDL_surface.h"
#include "begin_code.h"
#include "close_code.h"
+ Include dependency graph for SDL_shape_internals.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  SDL_QuadTreeChildren
 
union  SDL_ShapeUnion
 
struct  SDL_ShapeTree
 

Typedefs

typedef void(* SDL_TraversalFunction) (SDL_ShapeTree *, void *)
 

Enumerations

enum  SDL_ShapeKind {
  QuadShape ,
  TransparentShape ,
  OpaqueShape
}
 

Functions

void SDL_CalculateShapeBitmap (SDL_WindowShapeMode mode, SDL_Surface *shape, Uint8 *bitmap, Uint8 ppb)
 
SDL_ShapeTreeSDL_CalculateShapeTree (SDL_WindowShapeMode mode, SDL_Surface *shape)
 
void SDL_TraverseShapeTree (SDL_ShapeTree *tree, SDL_TraversalFunction function, void *closure)
 
void SDL_FreeShapeTree (SDL_ShapeTree **shape_tree)
 

Typedef Documentation

◆ SDL_TraversalFunction

typedef void(* SDL_TraversalFunction) (SDL_ShapeTree *, void *)

Definition at line 56 of file SDL_shape_internals.h.

Enumeration Type Documentation

◆ SDL_ShapeKind

Enumerator
QuadShape 
TransparentShape 
OpaqueShape 

Definition at line 49 of file SDL_shape_internals.h.

Function Documentation

◆ SDL_CalculateShapeBitmap()

void SDL_CalculateShapeBitmap ( SDL_WindowShapeMode  mode,
SDL_Surface shape,
Uint8 bitmap,
Uint8  ppb 
)

Definition at line 70 of file SDL_shape.c.

71 {
72  int x = 0;
73  int y = 0;
74  Uint8 r = 0,g = 0,b = 0,alpha = 0;
75  Uint8* pixel = NULL;
76  Uint32 pixel_value = 0,mask_value = 0;
77  int bytes_per_scanline = (shape->w + (ppb - 1)) / ppb;
78  Uint8 *bitmap_scanline;
79  SDL_Color key;
80  if(SDL_MUSTLOCK(shape))
81  SDL_LockSurface(shape);
82  for(y = 0;y<shape->h;y++) {
83  bitmap_scanline = bitmap + y * bytes_per_scanline;
84  for(x=0;x<shape->w;x++) {
85  alpha = 0;
86  pixel_value = 0;
87  pixel = (Uint8 *)(shape->pixels) + (y*shape->pitch) + (x*shape->format->BytesPerPixel);
88  switch(shape->format->BytesPerPixel) {
89  case(1):
90  pixel_value = *pixel;
91  break;
92  case(2):
93  pixel_value = *(Uint16*)pixel;
94  break;
95  case(3):
96  pixel_value = *(Uint32*)pixel & (~shape->format->Amask);
97  break;
98  case(4):
99  pixel_value = *(Uint32*)pixel;
100  break;
101  }
102  SDL_GetRGBA(pixel_value,shape->format,&r,&g,&b,&alpha);
103  switch(mode.mode) {
104  case(ShapeModeDefault):
105  mask_value = (alpha >= 1 ? 1 : 0);
106  break;
108  mask_value = (alpha >= mode.parameters.binarizationCutoff ? 1 : 0);
109  break;
111  mask_value = (alpha <= mode.parameters.binarizationCutoff ? 1 : 0);
112  break;
113  case(ShapeModeColorKey):
114  key = mode.parameters.colorKey;
115  mask_value = ((key.r != r || key.g != g || key.b != b) ? 1 : 0);
116  break;
117  }
118  bitmap_scanline[x / ppb] |= mask_value << (x % ppb);
119  }
120  }
121  if(SDL_MUSTLOCK(shape))
122  SDL_UnlockSurface(shape);
123 }
#define SDL_UnlockSurface
#define SDL_LockSurface
#define SDL_GetRGBA
GLint GLint GLint GLint GLint GLint y
Definition: SDL_opengl.h:1574
GLdouble GLdouble GLdouble r
Definition: SDL_opengl.h:2079
GLint GLint GLint GLint GLint x
Definition: SDL_opengl.h:1574
GLboolean GLboolean GLboolean b
GLenum mode
GLsizei GLfixed GLfixed GLfixed GLfixed const GLubyte * bitmap
GLboolean GLboolean g
GLfloat GLfloat GLfloat alpha
@ ShapeModeBinarizeAlpha
A binarized alpha cutoff with a given integer value.
Definition: SDL_shape.h:84
@ ShapeModeColorKey
A color key is applied.
Definition: SDL_shape.h:88
@ ShapeModeDefault
The default mode, a binarized alpha cutoff of 1.
Definition: SDL_shape.h:82
@ ShapeModeReverseBinarizeAlpha
A binarized alpha cutoff with a given integer value, but with the opposite comparison.
Definition: SDL_shape.h:86
uint16_t Uint16
Definition: SDL_stdinc.h:197
uint8_t Uint8
Definition: SDL_stdinc.h:185
uint32_t Uint32
Definition: SDL_stdinc.h:209
#define SDL_MUSTLOCK(S)
Definition: SDL_surface.h:62
#define NULL
Definition: begin_code.h:163
GLuint64 key
Definition: gl2ext.h:2192
Uint8 BytesPerPixel
Definition: SDL_pixels.h:329
SDL_PixelFormat * format
Definition: SDL_surface.h:73
void * pixels
Definition: SDL_surface.h:76

References SDL_PixelFormat::Amask, SDL_PixelFormat::BytesPerPixel, SDL_Surface::format, SDL_Surface::h, NULL, SDL_Surface::pitch, SDL_Surface::pixels, SDL_GetRGBA, SDL_LockSurface, SDL_MUSTLOCK, SDL_UnlockSurface, ShapeModeBinarizeAlpha, ShapeModeColorKey, ShapeModeDefault, ShapeModeReverseBinarizeAlpha, and SDL_Surface::w.

◆ SDL_CalculateShapeTree()

SDL_ShapeTree* SDL_CalculateShapeTree ( SDL_WindowShapeMode  mode,
SDL_Surface shape 
)

Definition at line 212 of file SDL_shape.c.

213 {
214  SDL_Rect dimensions;
216 
217  dimensions.x = 0;
218  dimensions.y = 0;
219  dimensions.w = shape->w;
220  dimensions.h = shape->h;
221 
222  if(SDL_MUSTLOCK(shape))
223  SDL_LockSurface(shape);
224  result = RecursivelyCalculateShapeTree(mode,shape,dimensions);
225  if(SDL_MUSTLOCK(shape))
226  SDL_UnlockSurface(shape);
227  return result;
228 }
GLuint64EXT * result
static SDL_ShapeTree * RecursivelyCalculateShapeTree(SDL_WindowShapeMode mode, SDL_Surface *mask, SDL_Rect dimensions)
Definition: SDL_shape.c:126
A rectangle, with the origin at the upper left (integer).
Definition: SDL_rect.h:78
int h
Definition: SDL_rect.h:80
int w
Definition: SDL_rect.h:80
int y
Definition: SDL_rect.h:79
int x
Definition: SDL_rect.h:79

References SDL_Rect::h, SDL_Surface::h, NULL, RecursivelyCalculateShapeTree(), SDL_LockSurface, SDL_MUSTLOCK, SDL_UnlockSurface, SDL_Rect::w, SDL_Surface::w, SDL_Rect::x, and SDL_Rect::y.

◆ SDL_FreeShapeTree()

void SDL_FreeShapeTree ( SDL_ShapeTree **  shape_tree)

Definition at line 245 of file SDL_shape.c.

246 {
247  if((*shape_tree)->kind == QuadShape) {
248  SDL_FreeShapeTree((SDL_ShapeTree **)(char*)&(*shape_tree)->data.children.upleft);
249  SDL_FreeShapeTree((SDL_ShapeTree **)(char*)&(*shape_tree)->data.children.upright);
250  SDL_FreeShapeTree((SDL_ShapeTree **)(char*)&(*shape_tree)->data.children.downleft);
251  SDL_FreeShapeTree((SDL_ShapeTree **)(char*)&(*shape_tree)->data.children.downright);
252  }
253  SDL_free(*shape_tree);
254  *shape_tree = NULL;
255 }
#define SDL_free
void SDL_FreeShapeTree(SDL_ShapeTree **shape_tree)
Definition: SDL_shape.c:245

References NULL, QuadShape, and SDL_free.

◆ SDL_TraverseShapeTree()

void SDL_TraverseShapeTree ( SDL_ShapeTree tree,
SDL_TraversalFunction  function,
void closure 
)

Definition at line 231 of file SDL_shape.c.

232 {
233  SDL_assert(tree != NULL);
234  if(tree->kind == QuadShape) {
235  SDL_TraverseShapeTree((SDL_ShapeTree *)tree->data.children.upleft,function,closure);
236  SDL_TraverseShapeTree((SDL_ShapeTree *)tree->data.children.upright,function,closure);
237  SDL_TraverseShapeTree((SDL_ShapeTree *)tree->data.children.downleft,function,closure);
238  SDL_TraverseShapeTree((SDL_ShapeTree *)tree->data.children.downright,function,closure);
239  }
240  else
241  function(tree,closure);
242 }
#define SDL_assert(condition)
Definition: SDL_assert.h:171
void SDL_TraverseShapeTree(SDL_ShapeTree *tree, SDL_TraversalFunction function, void *closure)
Definition: SDL_shape.c:231
struct SDL_ShapeTree * downright
struct SDL_ShapeTree * upleft
struct SDL_ShapeTree * downleft
struct SDL_ShapeTree * upright
SDL_ShapeKind kind
SDL_ShapeUnion data
SDL_QuadTreeChildren children

References SDL_ShapeUnion::children, SDL_ShapeTree::data, SDL_QuadTreeChildren::downleft, SDL_QuadTreeChildren::downright, SDL_ShapeTree::kind, NULL, QuadShape, SDL_assert, SDL_QuadTreeChildren::upleft, and SDL_QuadTreeChildren::upright.