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 54 of file SDL_shape_internals.h.

Enumeration Type Documentation

◆ SDL_ShapeKind

Enumerator
QuadShape 
TransparentShape 
OpaqueShape 

Definition at line 47 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 67 of file SDL_shape.c.

References SDL_PixelFormat::Amask, SDL_Color::b, SDL_WindowShapeParams::binarizationCutoff, SDL_PixelFormat::BytesPerPixel, SDL_WindowShapeParams::colorKey, SDL_Surface::format, SDL_Color::g, SDL_Surface::h, SDL_WindowShapeMode::mode, NULL, SDL_WindowShapeMode::parameters, SDL_Surface::pitch, SDL_Surface::pixels, SDL_Color::r, SDL_GetRGBA, SDL_LockSurface, SDL_MUSTLOCK, SDL_UnlockSurface, ShapeModeBinarizeAlpha, ShapeModeColorKey, ShapeModeDefault, ShapeModeReverseBinarizeAlpha, and SDL_Surface::w.

68 {
69  int x = 0;
70  int y = 0;
71  Uint8 r = 0,g = 0,b = 0,alpha = 0;
72  Uint8* pixel = NULL;
73  Uint32 bitmap_pixel,pixel_value = 0,mask_value = 0;
74  SDL_Color key;
75  if(SDL_MUSTLOCK(shape))
76  SDL_LockSurface(shape);
77  for(y = 0;y<shape->h;y++) {
78  for(x=0;x<shape->w;x++) {
79  alpha = 0;
80  pixel_value = 0;
81  pixel = (Uint8 *)(shape->pixels) + (y*shape->pitch) + (x*shape->format->BytesPerPixel);
82  switch(shape->format->BytesPerPixel) {
83  case(1):
84  pixel_value = *(Uint8*)pixel;
85  break;
86  case(2):
87  pixel_value = *(Uint16*)pixel;
88  break;
89  case(3):
90  pixel_value = *(Uint32*)pixel & (~shape->format->Amask);
91  break;
92  case(4):
93  pixel_value = *(Uint32*)pixel;
94  break;
95  }
96  SDL_GetRGBA(pixel_value,shape->format,&r,&g,&b,&alpha);
97  bitmap_pixel = y*shape->w + x;
98  switch(mode.mode) {
99  case(ShapeModeDefault):
100  mask_value = (alpha >= 1 ? 1 : 0);
101  break;
103  mask_value = (alpha >= mode.parameters.binarizationCutoff ? 1 : 0);
104  break;
106  mask_value = (alpha <= mode.parameters.binarizationCutoff ? 1 : 0);
107  break;
108  case(ShapeModeColorKey):
109  key = mode.parameters.colorKey;
110  mask_value = ((key.r != r || key.g != g || key.b != b) ? 1 : 0);
111  break;
112  }
113  bitmap[bitmap_pixel / ppb] |= mask_value << (7 - ((ppb - 1) - (bitmap_pixel % ppb)));
114  }
115  }
116  if(SDL_MUSTLOCK(shape))
117  SDL_UnlockSurface(shape);
118 }
GLsizei GLfixed GLfixed GLfixed GLfixed const GLubyte * bitmap
#define SDL_UnlockSurface
GLdouble GLdouble GLdouble r
Definition: SDL_opengl.h:2072
Uint8 g
Definition: SDL_pixels.h:296
GLint GLint GLint GLint GLint x
Definition: SDL_opengl.h:1567
Uint8 BytesPerPixel
Definition: SDL_pixels.h:318
A color key is applied.
Definition: SDL_shape.h:87
Uint8 b
Definition: SDL_pixels.h:297
uint32_t Uint32
An unsigned 32-bit integer type.
Definition: SDL_stdinc.h:161
GLfloat GLfloat GLfloat alpha
GLboolean GLboolean g
Uint8 r
Definition: SDL_pixels.h:295
GLint GLint GLint GLint GLint GLint y
Definition: SDL_opengl.h:1567
void * pixels
Definition: SDL_surface.h:75
uint8_t Uint8
An unsigned 8-bit integer type.
Definition: SDL_stdinc.h:143
The default mode, a binarized alpha cutoff of 1.
Definition: SDL_shape.h:81
SDL_WindowShapeParams parameters
Window-shape parameters.
Definition: SDL_shape.h:104
#define SDL_GetRGBA
#define NULL
Definition: begin_code.h:143
A binarized alpha cutoff with a given integer value.
Definition: SDL_shape.h:83
SDL_PixelFormat * format
Definition: SDL_surface.h:72
#define SDL_LockSurface
#define SDL_MUSTLOCK(S)
Definition: SDL_surface.h:61
SDL_Color colorKey
Definition: SDL_shape.h:96
A binarized alpha cutoff with a given integer value, but with the opposite comparison.
Definition: SDL_shape.h:85
uint16_t Uint16
An unsigned 16-bit integer type.
Definition: SDL_stdinc.h:151
Uint8 binarizationCutoff
a cutoff alpha value for binarization of the window shape&#39;s alpha channel.
Definition: SDL_shape.h:95
WindowShapeMode mode
The mode of these window-shape parameters.
Definition: SDL_shape.h:102
GLboolean GLboolean GLboolean b

◆ SDL_CalculateShapeTree()

SDL_ShapeTree* SDL_CalculateShapeTree ( SDL_WindowShapeMode  mode,
SDL_Surface shape 
)

Definition at line 207 of file SDL_shape.c.

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

208 {
209  SDL_Rect dimensions = {0,0,shape->w,shape->h};
211  if(SDL_MUSTLOCK(shape))
212  SDL_LockSurface(shape);
213  result = RecursivelyCalculateShapeTree(mode,shape,dimensions);
214  if(SDL_MUSTLOCK(shape))
215  SDL_UnlockSurface(shape);
216  return result;
217 }
#define SDL_UnlockSurface
GLuint64EXT * result
#define NULL
Definition: begin_code.h:143
#define SDL_LockSurface
#define SDL_MUSTLOCK(S)
Definition: SDL_surface.h:61
static SDL_ShapeTree * RecursivelyCalculateShapeTree(SDL_WindowShapeMode mode, SDL_Surface *mask, SDL_Rect dimensions)
Definition: SDL_shape.c:121
A rectangle, with the origin at the upper left.
Definition: SDL_rect.h:64

◆ SDL_FreeShapeTree()

void SDL_FreeShapeTree ( SDL_ShapeTree **  shape_tree)

Definition at line 234 of file SDL_shape.c.

References NULL, QuadShape, SDL_free(), and SDL_FreeShapeTree().

Referenced by SDL_FreeShapeTree().

235 {
236  if((*shape_tree)->kind == QuadShape) {
237  SDL_FreeShapeTree((SDL_ShapeTree **)&(*shape_tree)->data.children.upleft);
238  SDL_FreeShapeTree((SDL_ShapeTree **)&(*shape_tree)->data.children.upright);
239  SDL_FreeShapeTree((SDL_ShapeTree **)&(*shape_tree)->data.children.downleft);
240  SDL_FreeShapeTree((SDL_ShapeTree **)&(*shape_tree)->data.children.downright);
241  }
242  SDL_free(*shape_tree);
243  *shape_tree = NULL;
244 }
void SDL_FreeShapeTree(SDL_ShapeTree **shape_tree)
Definition: SDL_shape.c:234
void SDL_free(void *mem)
#define NULL
Definition: begin_code.h:143

◆ SDL_TraverseShapeTree()

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

Definition at line 220 of file SDL_shape.c.

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

Referenced by SDL_TraverseShapeTree().

221 {
222  SDL_assert(tree != NULL);
223  if(tree->kind == QuadShape) {
224  SDL_TraverseShapeTree((SDL_ShapeTree *)tree->data.children.upleft,function,closure);
225  SDL_TraverseShapeTree((SDL_ShapeTree *)tree->data.children.upright,function,closure);
226  SDL_TraverseShapeTree((SDL_ShapeTree *)tree->data.children.downleft,function,closure);
227  SDL_TraverseShapeTree((SDL_ShapeTree *)tree->data.children.downright,function,closure);
228  }
229  else
230  function(tree,closure);
231 }
struct SDL_ShapeTree * upright
SDL_ShapeUnion data
#define SDL_assert(condition)
Definition: SDL_assert.h:167
#define NULL
Definition: begin_code.h:143
void SDL_TraverseShapeTree(SDL_ShapeTree *tree, SDL_TraversalFunction function, void *closure)
Definition: SDL_shape.c:220
struct SDL_ShapeTree * upleft
SDL_ShapeKind kind
struct SDL_ShapeTree * downright
SDL_QuadTreeChildren children
struct SDL_ShapeTree * downleft