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 71 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.

72 {
73  int x = 0;
74  int y = 0;
75  Uint8 r = 0,g = 0,b = 0,alpha = 0;
76  Uint8* pixel = NULL;
77  Uint32 pixel_value = 0,mask_value = 0;
78  int bytes_per_scanline = (shape->w + (ppb - 1)) / ppb;
79  Uint8 *bitmap_scanline;
80  SDL_Color key;
81  if(SDL_MUSTLOCK(shape))
82  SDL_LockSurface(shape);
83  for(y = 0;y<shape->h;y++) {
84  bitmap_scanline = bitmap + y * bytes_per_scanline;
85  for(x=0;x<shape->w;x++) {
86  alpha = 0;
87  pixel_value = 0;
88  pixel = (Uint8 *)(shape->pixels) + (y*shape->pitch) + (x*shape->format->BytesPerPixel);
89  switch(shape->format->BytesPerPixel) {
90  case(1):
91  pixel_value = *(Uint8*)pixel;
92  break;
93  case(2):
94  pixel_value = *(Uint16*)pixel;
95  break;
96  case(3):
97  pixel_value = *(Uint32*)pixel & (~shape->format->Amask);
98  break;
99  case(4):
100  pixel_value = *(Uint32*)pixel;
101  break;
102  }
103  SDL_GetRGBA(pixel_value,shape->format,&r,&g,&b,&alpha);
104  switch(mode.mode) {
105  case(ShapeModeDefault):
106  mask_value = (alpha >= 1 ? 1 : 0);
107  break;
109  mask_value = (alpha >= mode.parameters.binarizationCutoff ? 1 : 0);
110  break;
112  mask_value = (alpha <= mode.parameters.binarizationCutoff ? 1 : 0);
113  break;
114  case(ShapeModeColorKey):
115  key = mode.parameters.colorKey;
116  mask_value = ((key.r != r || key.g != g || key.b != b) ? 1 : 0);
117  break;
118  }
119  bitmap_scanline[x / ppb] |= mask_value << (x % ppb);
120  }
121  }
122  if(SDL_MUSTLOCK(shape))
123  SDL_UnlockSurface(shape);
124 }
GLsizei GLfixed GLfixed GLfixed GLfixed const GLubyte * bitmap
GLdouble GLdouble GLdouble r
Definition: SDL_opengl.h:2079
#define SDL_UnlockSurface
Uint8 g
Definition: SDL_pixels.h:298
GLint GLint GLint GLint GLint x
Definition: SDL_opengl.h:1574
Uint8 BytesPerPixel
Definition: SDL_pixels.h:320
A color key is applied.
Definition: SDL_shape.h:88
Uint8 b
Definition: SDL_pixels.h:299
uint32_t Uint32
Definition: SDL_stdinc.h:181
GLfloat GLfloat GLfloat alpha
GLuint64 key
Definition: gl2ext.h:2192
Uint8 r
Definition: SDL_pixels.h:297
void * pixels
Definition: SDL_surface.h:75
uint8_t Uint8
Definition: SDL_stdinc.h:157
The default mode, a binarized alpha cutoff of 1.
Definition: SDL_shape.h:82
SDL_WindowShapeParams parameters
Window-shape parameters.
Definition: SDL_shape.h:105
GLint GLint GLint GLint GLint GLint y
Definition: SDL_opengl.h:1574
#define SDL_GetRGBA
#define NULL
Definition: begin_code.h:164
A binarized alpha cutoff with a given integer value.
Definition: SDL_shape.h:84
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:97
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:169
Uint8 binarizationCutoff
A cutoff alpha value for binarization of the window shape&#39;s alpha channel.
Definition: SDL_shape.h:96
WindowShapeMode mode
The mode of these window-shape parameters.
Definition: SDL_shape.h:103
GLboolean GLboolean g
GLboolean GLboolean GLboolean b

◆ SDL_CalculateShapeTree()

SDL_ShapeTree* SDL_CalculateShapeTree ( SDL_WindowShapeMode  mode,
SDL_Surface shape 
)

Definition at line 213 of file SDL_shape.c.

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.

214 {
215  SDL_Rect dimensions;
217 
218  dimensions.x = 0;
219  dimensions.y = 0;
220  dimensions.w = shape->w;
221  dimensions.h = shape->h;
222 
223  if(SDL_MUSTLOCK(shape))
224  SDL_LockSurface(shape);
225  result = RecursivelyCalculateShapeTree(mode,shape,dimensions);
226  if(SDL_MUSTLOCK(shape))
227  SDL_UnlockSurface(shape);
228  return result;
229 }
#define SDL_UnlockSurface
GLuint64EXT * result
int x
Definition: SDL_rect.h:66
int w
Definition: SDL_rect.h:67
#define NULL
Definition: begin_code.h:164
#define SDL_LockSurface
#define SDL_MUSTLOCK(S)
Definition: SDL_surface.h:61
int h
Definition: SDL_rect.h:67
static SDL_ShapeTree * RecursivelyCalculateShapeTree(SDL_WindowShapeMode mode, SDL_Surface *mask, SDL_Rect dimensions)
Definition: SDL_shape.c:127
int y
Definition: SDL_rect.h:66
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 246 of file SDL_shape.c.

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

Referenced by SDL_FreeShapeTree().

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

◆ SDL_TraverseShapeTree()

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

Definition at line 232 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().

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