Commit 68d2b552 authored by Sam Lantinga's avatar Sam Lantinga

Split out the SDL_rect and SDL_surface functions into their own headers.

Removed unused count from the dirty rect list.

--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%402639
parent fa9233ea
...@@ -37,6 +37,10 @@ extern "C" { ...@@ -37,6 +37,10 @@ extern "C" {
/* *INDENT-ON* */ /* *INDENT-ON* */
#endif #endif
/* Transparency definitions: These define alpha as the opacity of a surface */
#define SDL_ALPHA_OPAQUE 255
#define SDL_ALPHA_TRANSPARENT 0
enum enum
{ /* Pixel type */ { /* Pixel type */
SDL_PIXELTYPE_UNKNOWN, SDL_PIXELTYPE_UNKNOWN,
...@@ -330,6 +334,54 @@ extern DECLSPEC int SDLCALL SDL_SetPaletteColors(SDL_Palette * palette, ...@@ -330,6 +334,54 @@ extern DECLSPEC int SDLCALL SDL_SetPaletteColors(SDL_Palette * palette,
*/ */
extern DECLSPEC void SDLCALL SDL_FreePalette(SDL_Palette * palette); extern DECLSPEC void SDLCALL SDL_FreePalette(SDL_Palette * palette);
/**
* \fn Uint32 SDL_MapRGB(const SDL_PixelFormat *format,
* Uint8 r, Uint8 g, Uint8 b)
*
* \brief Maps an RGB triple to an opaque pixel value for a given pixel format
*
* \sa SDL_MapRGBA
*/
extern DECLSPEC Uint32 SDLCALL SDL_MapRGB(const SDL_PixelFormat * format,
Uint8 r, Uint8 g, Uint8 b);
/**
* \fn Uint32 SDL_MapRGBA(const SDL_PixelFormat *fmt,
* Uint8 r, Uint8 g, Uint8 b, Uint8 a)
*
* \brief Maps an RGBA quadruple to a pixel value for a given pixel format
*
* \sa SDL_MapRGB
*/
extern DECLSPEC Uint32 SDLCALL SDL_MapRGBA(const SDL_PixelFormat * format,
Uint8 r, Uint8 g, Uint8 b,
Uint8 a);
/**
* \fn void SDL_GetRGB(Uint32 pixel, const SDL_PixelFormat * format,
* Uint8 * r, Uint8 * g, Uint8 * b)
*
* \brief Maps a pixel value into the RGB components for a given pixel format
*
* \sa SDL_GetRGBA
*/
extern DECLSPEC void SDLCALL SDL_GetRGB(Uint32 pixel,
const SDL_PixelFormat * format,
Uint8 * r, Uint8 * g, Uint8 * b);
/**
* \fn void SDL_GetRGBA(Uint32 pixel, const SDL_PixelFormat * format,
* Uint8 * r, Uint8 * g, Uint8 * b, Uint8 * a)
*
* \brief Maps a pixel value into the RGBA components for a given pixel format
*
* \sa SDL_GetRGB
*/
extern DECLSPEC void SDLCALL SDL_GetRGBA(Uint32 pixel,
const SDL_PixelFormat * format,
Uint8 * r, Uint8 * g, Uint8 * b,
Uint8 * a);
/* Ends C function definitions when using C++ */ /* Ends C function definitions when using C++ */
#ifdef __cplusplus #ifdef __cplusplus
/* *INDENT-OFF* */ /* *INDENT-OFF* */
......
/*
SDL - Simple DirectMedia Layer
Copyright (C) 1997-2006 Sam Lantinga
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Sam Lantinga
slouken@libsdl.org
*/
/**
* \file SDL_rect.h
*
* Header file for SDL_rect definition and management functions
*/
#ifndef _SDL_rect_h
#define _SDL_rect_h
#include "SDL_stdinc.h"
#include "SDL_error.h"
#include "SDL_pixels.h"
#include "SDL_rwops.h"
#include "begin_code.h"
/* Set up for C function definitions, even when using C++ */
#ifdef __cplusplus
/* *INDENT-OFF* */
extern "C" {
/* *INDENT-ON* */
#endif
/**
* \struct SDL_Rect
*
* \brief A rectangle, with the origin at the upper left.
*
* \sa SDL_RectEmpty
* \sa SDL_RectEquals
* \sa SDL_HasIntersection
* \sa SDL_IntersectRect
* \sa SDL_UnionRect
*/
typedef struct SDL_Rect
{
int x, y;
int w, h;
} SDL_Rect;
/**
* \def SDL_RectEmpty()
*
* \brief Returns true if the rectangle has no area.
*/
#define SDL_RectEmpty(X) (((X)->w <= 0) || ((X)->h <= 0))
/**
* \def SDL_RectEquals()
*
* \brief Returns true if the two rectangles are equal.
*/
#define SDL_RectEquals(A, B) (((A)->x == (B)->x) && ((A)->y == (B)->y) && \
((A)->w == (B)->w) && ((A)->h == (B)->h))
/**
* \fn SDL_bool SDL_HasIntersection(const SDL_Rect * A, const SDL_Rect * B);
*
* \brief Determine whether two rectangles intersect.
*
* \return SDL_TRUE if there is an intersection, SDL_FALSE otherwise.
*/
extern DECLSPEC SDL_bool SDLCALL SDL_HasIntersection(const SDL_Rect * A,
const SDL_Rect * B);
/**
* \fn SDL_bool SDL_IntersectRect(const SDL_Rect * A, const SDL_Rect * B, SDL_Rect * result)
*
* \brief Calculate the intersection of two rectangles.
*
* \return SDL_TRUE if there is an intersection, SDL_FALSE otherwise.
*/
extern DECLSPEC SDL_bool SDLCALL SDL_IntersectRect(const SDL_Rect * A,
const SDL_Rect * B,
SDL_Rect * result);
/**
* \fn void SDL_UnionRect(const SDL_Rect * A, const SDL_Rect * B, SDL_Rect * result)
*
* \brief Calculate the union of two rectangles
*/
extern DECLSPEC void SDLCALL SDL_UnionRect(const SDL_Rect * A,
const SDL_Rect * B,
SDL_Rect * result);
/* Ends C function definitions when using C++ */
#ifdef __cplusplus
/* *INDENT-OFF* */
}
/* *INDENT-ON* */
#endif
#include "close_code.h"
#endif /* _SDL_rect_h */
/* vi: set ts=4 sw=4 expandtab: */
This diff is collapsed.
This diff is collapsed.
...@@ -536,8 +536,7 @@ SDL_FindColor(SDL_Palette * pal, Uint8 r, Uint8 g, Uint8 b) ...@@ -536,8 +536,7 @@ SDL_FindColor(SDL_Palette * pal, Uint8 r, Uint8 g, Uint8 b)
/* Find the opaque pixel value corresponding to an RGB triple */ /* Find the opaque pixel value corresponding to an RGB triple */
Uint32 Uint32
SDL_MapRGB(const SDL_PixelFormat * const format, const Uint8 r, const Uint8 g, SDL_MapRGB(const SDL_PixelFormat * format, Uint8 r, Uint8 g, Uint8 b)
const Uint8 b)
{ {
if (format->palette == NULL) { if (format->palette == NULL) {
return (r >> format->Rloss) << format->Rshift return (r >> format->Rloss) << format->Rshift
...@@ -550,8 +549,8 @@ SDL_MapRGB(const SDL_PixelFormat * const format, const Uint8 r, const Uint8 g, ...@@ -550,8 +549,8 @@ SDL_MapRGB(const SDL_PixelFormat * const format, const Uint8 r, const Uint8 g,
/* Find the pixel value corresponding to an RGBA quadruple */ /* Find the pixel value corresponding to an RGBA quadruple */
Uint32 Uint32
SDL_MapRGBA(const SDL_PixelFormat * const format, const Uint8 r, SDL_MapRGBA(const SDL_PixelFormat * format, Uint8 r, Uint8 g, Uint8 b,
const Uint8 g, const Uint8 b, const Uint8 a) Uint8 a)
{ {
if (format->palette == NULL) { if (format->palette == NULL) {
return (r >> format->Rloss) << format->Rshift return (r >> format->Rloss) << format->Rshift
...@@ -564,57 +563,64 @@ SDL_MapRGBA(const SDL_PixelFormat * const format, const Uint8 r, ...@@ -564,57 +563,64 @@ SDL_MapRGBA(const SDL_PixelFormat * const format, const Uint8 r,
} }
void void
SDL_GetRGBA(Uint32 pixel, SDL_PixelFormat * fmt, SDL_GetRGB(Uint32 pixel, const SDL_PixelFormat * format, Uint8 * r, Uint8 * g,
Uint8 * r, Uint8 * g, Uint8 * b, Uint8 * a) Uint8 * b)
{ {
if (fmt->palette == NULL) { if (format->palette == NULL) {
/* /*
* This makes sure that the result is mapped to the * This makes sure that the result is mapped to the
* interval [0..255], and the maximum value for each * interval [0..255], and the maximum value for each
* component is 255. This is important to make sure * component is 255. This is important to make sure
* that white is indeed reported as (255, 255, 255), * that white is indeed reported as (255, 255, 255).
* and that opaque alpha is 255.
* This only works for RGB bit fields at least 4 bit * This only works for RGB bit fields at least 4 bit
* wide, which is almost always the case. * wide, which is almost always the case.
*/ */
unsigned v; unsigned v;
v = (pixel & fmt->Rmask) >> fmt->Rshift; v = (pixel & format->Rmask) >> format->Rshift;
*r = (v << fmt->Rloss) + (v >> (8 - (fmt->Rloss << 1))); *r = (v << format->Rloss) + (v >> (8 - (format->Rloss << 1)));
v = (pixel & fmt->Gmask) >> fmt->Gshift; v = (pixel & format->Gmask) >> format->Gshift;
*g = (v << fmt->Gloss) + (v >> (8 - (fmt->Gloss << 1))); *g = (v << format->Gloss) + (v >> (8 - (format->Gloss << 1)));
v = (pixel & fmt->Bmask) >> fmt->Bshift; v = (pixel & format->Bmask) >> format->Bshift;
*b = (v << fmt->Bloss) + (v >> (8 - (fmt->Bloss << 1))); *b = (v << format->Bloss) + (v >> (8 - (format->Bloss << 1)));
if (fmt->Amask) {
v = (pixel & fmt->Amask) >> fmt->Ashift;
*a = (v << fmt->Aloss) + (v >> (8 - (fmt->Aloss << 1)));
} else {
*a = SDL_ALPHA_OPAQUE;
}
} else { } else {
*r = fmt->palette->colors[pixel].r; *r = format->palette->colors[pixel].r;
*g = fmt->palette->colors[pixel].g; *g = format->palette->colors[pixel].g;
*b = fmt->palette->colors[pixel].b; *b = format->palette->colors[pixel].b;
*a = SDL_ALPHA_OPAQUE;
} }
} }
void void
SDL_GetRGB(Uint32 pixel, SDL_PixelFormat * fmt, Uint8 * r, Uint8 * g, SDL_GetRGBA(Uint32 pixel, const SDL_PixelFormat * format,
Uint8 * b) Uint8 * r, Uint8 * g, Uint8 * b, Uint8 * a)
{ {
if (fmt->palette == NULL) { if (format->palette == NULL) {
/* the note for SDL_GetRGBA above applies here too */ /*
* This makes sure that the result is mapped to the
* interval [0..255], and the maximum value for each
* component is 255. This is important to make sure
* that white is indeed reported as (255, 255, 255),
* and that opaque alpha is 255.
* This only works for RGB bit fields at least 4 bit
* wide, which is almost always the case.
*/
unsigned v; unsigned v;
v = (pixel & fmt->Rmask) >> fmt->Rshift; v = (pixel & format->Rmask) >> format->Rshift;
*r = (v << fmt->Rloss) + (v >> (8 - (fmt->Rloss << 1))); *r = (v << format->Rloss) + (v >> (8 - (format->Rloss << 1)));
v = (pixel & fmt->Gmask) >> fmt->Gshift; v = (pixel & format->Gmask) >> format->Gshift;
*g = (v << fmt->Gloss) + (v >> (8 - (fmt->Gloss << 1))); *g = (v << format->Gloss) + (v >> (8 - (format->Gloss << 1)));
v = (pixel & fmt->Bmask) >> fmt->Bshift; v = (pixel & format->Bmask) >> format->Bshift;
*b = (v << fmt->Bloss) + (v >> (8 - (fmt->Bloss << 1))); *b = (v << format->Bloss) + (v >> (8 - (format->Bloss << 1)));
if (format->Amask) {
v = (pixel & format->Amask) >> format->Ashift;
*a = (v << format->Aloss) + (v >> (8 - (format->Aloss << 1)));
} else {
*a = SDL_ALPHA_OPAQUE;
}
} else { } else {
*r = fmt->palette->colors[pixel].r; *r = format->palette->colors[pixel].r;
*g = fmt->palette->colors[pixel].g; *g = format->palette->colors[pixel].g;
*b = fmt->palette->colors[pixel].b; *b = format->palette->colors[pixel].b;
*a = SDL_ALPHA_OPAQUE;
} }
} }
......
...@@ -143,7 +143,6 @@ SDL_AddDirtyRect(SDL_DirtyRectList * list, const SDL_Rect * rect) ...@@ -143,7 +143,6 @@ SDL_AddDirtyRect(SDL_DirtyRectList * list, const SDL_Rect * rect)
dirty->rect = *rect; dirty->rect = *rect;
dirty->next = list->list; dirty->next = list->list;
list->list = dirty; list->list = dirty;
++list->count;
} }
void void
...@@ -164,7 +163,6 @@ SDL_ClearDirtyRects(SDL_DirtyRectList * list) ...@@ -164,7 +163,6 @@ SDL_ClearDirtyRects(SDL_DirtyRectList * list)
list->free = list->list; list->free = list->list;
} }
list->list = NULL; list->list = NULL;
list->count = 0;
} }
void void
......
...@@ -29,7 +29,6 @@ typedef struct SDL_DirtyRect ...@@ -29,7 +29,6 @@ typedef struct SDL_DirtyRect
typedef struct SDL_DirtyRectList typedef struct SDL_DirtyRectList
{ {
int count;
SDL_DirtyRect *list; SDL_DirtyRect *list;
SDL_DirtyRect *free; SDL_DirtyRect *free;
} SDL_DirtyRectList; } SDL_DirtyRectList;
......
...@@ -806,7 +806,7 @@ GL_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, ...@@ -806,7 +806,7 @@ GL_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
int minx, miny, maxx, maxy; int minx, miny, maxx, maxy;
GLfloat minu, maxu, minv, maxv; GLfloat minu, maxu, minv, maxv;
if (texturedata->dirty.count > 0) { if (texturedata->dirty.list) {
SDL_DirtyRect *dirty; SDL_DirtyRect *dirty;
void *pixels; void *pixels;
int bpp = SDL_BYTESPERPIXEL(texture->format); int bpp = SDL_BYTESPERPIXEL(texture->format);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment