indent pixels.c pixels.h

Note - no change to pixels.h
This commit is contained in:
Bill Kendrick 2017-10-15 11:02:51 -07:00
parent 0d8502bdaf
commit 41893a9cda

View file

@ -37,21 +37,19 @@ static void putpixel8(SDL_Surface * surface, int x, int y, Uint32 pixel)
Uint8 *p; Uint8 *p;
/* Assuming the X/Y values are within the bounds of this surface... */ /* Assuming the X/Y values are within the bounds of this surface... */
if (likely if (likely(likely((unsigned)x < (unsigned)surface->w) && likely((unsigned)y < (unsigned)surface->h)))
(likely((unsigned) x < (unsigned) surface->w) {
&& likely((unsigned) y < (unsigned) surface->h))) // Set a pointer to the exact location in memory of the pixel
{ p = (Uint8 *) (((Uint8 *) surface->pixels) + /* Start: beginning of RAM */
// Set a pointer to the exact location in memory of the pixel (y * surface->pitch) + /* Go down Y lines */
p = (Uint8 *) (((Uint8 *) surface->pixels) + /* Start: beginning of RAM */ x); /* Go in X pixels */
(y * surface->pitch) + /* Go down Y lines */
x); /* Go in X pixels */
/* Set the (correctly-sized) piece of data in the surface's RAM /* Set the (correctly-sized) piece of data in the surface's RAM
* to the pixel value sent in: */ * to the pixel value sent in: */
*p = pixel; *p = pixel;
} }
} }
/* Draw a single pixel into the surface: */ /* Draw a single pixel into the surface: */
@ -60,21 +58,19 @@ static void putpixel16(SDL_Surface * surface, int x, int y, Uint32 pixel)
Uint8 *p; Uint8 *p;
/* Assuming the X/Y values are within the bounds of this surface... */ /* Assuming the X/Y values are within the bounds of this surface... */
if (likely if (likely(likely((unsigned)x < (unsigned)surface->w) && likely((unsigned)y < (unsigned)surface->h)))
(likely((unsigned) x < (unsigned) surface->w) {
&& likely((unsigned) y < (unsigned) surface->h))) // Set a pointer to the exact location in memory of the pixel
{ p = (Uint8 *) (((Uint8 *) surface->pixels) + /* Start: beginning of RAM */
// Set a pointer to the exact location in memory of the pixel (y * surface->pitch) + /* Go down Y lines */
p = (Uint8 *) (((Uint8 *) surface->pixels) + /* Start: beginning of RAM */ (x * 2)); /* Go in X pixels */
(y * surface->pitch) + /* Go down Y lines */
(x * 2)); /* Go in X pixels */
/* Set the (correctly-sized) piece of data in the surface's RAM /* Set the (correctly-sized) piece of data in the surface's RAM
* to the pixel value sent in: */ * to the pixel value sent in: */
*(Uint16 *) p = pixel; *(Uint16 *) p = pixel;
} }
} }
/* Draw a single pixel into the surface: */ /* Draw a single pixel into the surface: */
@ -83,33 +79,31 @@ static void putpixel24(SDL_Surface * surface, int x, int y, Uint32 pixel)
Uint8 *p; Uint8 *p;
/* Assuming the X/Y values are within the bounds of this surface... */ /* Assuming the X/Y values are within the bounds of this surface... */
if (likely if (likely(likely((unsigned)x < (unsigned)surface->w) && likely((unsigned)y < (unsigned)surface->h)))
(likely((unsigned) x < (unsigned) surface->w)
&& likely((unsigned) y < (unsigned) surface->h)))
{
// Set a pointer to the exact location in memory of the pixel
p = (Uint8 *) (((Uint8 *) surface->pixels) + /* Start: beginning of RAM */
(y * surface->pitch) + /* Go down Y lines */
(x * 3)); /* Go in X pixels */
/* Set the (correctly-sized) piece of data in the surface's RAM
* to the pixel value sent in: */
if (SDL_BYTEORDER == SDL_BIG_ENDIAN)
{ {
p[0] = (pixel >> 16) & 0xff; // Set a pointer to the exact location in memory of the pixel
p[1] = (pixel >> 8) & 0xff; p = (Uint8 *) (((Uint8 *) surface->pixels) + /* Start: beginning of RAM */
p[2] = pixel & 0xff; (y * surface->pitch) + /* Go down Y lines */
} (x * 3)); /* Go in X pixels */
else
{
p[0] = pixel & 0xff;
p[1] = (pixel >> 8) & 0xff;
p[2] = (pixel >> 16) & 0xff;
}
}
/* Set the (correctly-sized) piece of data in the surface's RAM
* to the pixel value sent in: */
if (SDL_BYTEORDER == SDL_BIG_ENDIAN)
{
p[0] = (pixel >> 16) & 0xff;
p[1] = (pixel >> 8) & 0xff;
p[2] = pixel & 0xff;
}
else
{
p[0] = pixel & 0xff;
p[1] = (pixel >> 8) & 0xff;
p[2] = (pixel >> 16) & 0xff;
}
}
} }
/* Draw a single pixel into the surface: */ /* Draw a single pixel into the surface: */
@ -118,21 +112,19 @@ static void putpixel32(SDL_Surface * surface, int x, int y, Uint32 pixel)
Uint8 *p; Uint8 *p;
/* Assuming the X/Y values are within the bounds of this surface... */ /* Assuming the X/Y values are within the bounds of this surface... */
if (likely if (likely(likely((unsigned)x < (unsigned)surface->w) && likely((unsigned)y < (unsigned)surface->h)))
(likely((unsigned) x < (unsigned) surface->w) {
&& likely((unsigned) y < (unsigned) surface->h))) // Set a pointer to the exact location in memory of the pixel
{ p = (Uint8 *) (((Uint8 *) surface->pixels) + /* Start: beginning of RAM */
// Set a pointer to the exact location in memory of the pixel (y * surface->pitch) + /* Go down Y lines */
p = (Uint8 *) (((Uint8 *) surface->pixels) + /* Start: beginning of RAM */ (x * 4)); /* Go in X pixels */
(y * surface->pitch) + /* Go down Y lines */
(x * 4)); /* Go in X pixels */
/* Set the (correctly-sized) piece of data in the surface's RAM /* Set the (correctly-sized) piece of data in the surface's RAM
* to the pixel value sent in: */ * to the pixel value sent in: */
*(Uint32 *) p = pixel; // 32-bit display *(Uint32 *) p = pixel; // 32-bit display
} }
} }
/* Get a pixel: */ /* Get a pixel: */
@ -141,17 +133,17 @@ static Uint32 getpixel8(SDL_Surface * surface, int x, int y)
Uint8 *p; Uint8 *p;
/* get the X/Y values within the bounds of this surface */ /* get the X/Y values within the bounds of this surface */
if (unlikely((unsigned) x > (unsigned) surface->w - 1u)) if (unlikely((unsigned)x > (unsigned)surface->w - 1u))
x = (x < 0) ? 0 : surface->w - 1; x = (x < 0) ? 0 : surface->w - 1;
if (unlikely((unsigned) y > (unsigned) surface->h - 1u)) if (unlikely((unsigned)y > (unsigned)surface->h - 1u))
y = (y < 0) ? 0 : surface->h - 1; y = (y < 0) ? 0 : surface->h - 1;
/* Set a pointer to the exact location in memory of the pixel /* Set a pointer to the exact location in memory of the pixel
in question: */ in question: */
p = (Uint8 *) (((Uint8 *) surface->pixels) + /* Start at top of RAM */ p = (Uint8 *) (((Uint8 *) surface->pixels) + /* Start at top of RAM */
(y * surface->pitch) + /* Go down Y lines */ (y * surface->pitch) + /* Go down Y lines */
x); /* Go in X pixels */ x); /* Go in X pixels */
/* Return the correctly-sized piece of data containing the /* Return the correctly-sized piece of data containing the
@ -167,17 +159,17 @@ static Uint32 getpixel16(SDL_Surface * surface, int x, int y)
Uint8 *p; Uint8 *p;
/* get the X/Y values within the bounds of this surface */ /* get the X/Y values within the bounds of this surface */
if (unlikely((unsigned) x > (unsigned) surface->w - 1u)) if (unlikely((unsigned)x > (unsigned)surface->w - 1u))
x = (x < 0) ? 0 : surface->w - 1; x = (x < 0) ? 0 : surface->w - 1;
if (unlikely((unsigned) y > (unsigned) surface->h - 1u)) if (unlikely((unsigned)y > (unsigned)surface->h - 1u))
y = (y < 0) ? 0 : surface->h - 1; y = (y < 0) ? 0 : surface->h - 1;
/* Set a pointer to the exact location in memory of the pixel /* Set a pointer to the exact location in memory of the pixel
in question: */ in question: */
p = (Uint8 *) (((Uint8 *) surface->pixels) + /* Start at top of RAM */ p = (Uint8 *) (((Uint8 *) surface->pixels) + /* Start at top of RAM */
(y * surface->pitch) + /* Go down Y lines */ (y * surface->pitch) + /* Go down Y lines */
(x * 2)); /* Go in X pixels */ (x * 2)); /* Go in X pixels */
/* Return the correctly-sized piece of data containing the /* Return the correctly-sized piece of data containing the
@ -194,17 +186,17 @@ static Uint32 getpixel24(SDL_Surface * surface, int x, int y)
Uint32 pixel; Uint32 pixel;
/* get the X/Y values within the bounds of this surface */ /* get the X/Y values within the bounds of this surface */
if (unlikely((unsigned) x > (unsigned) surface->w - 1u)) if (unlikely((unsigned)x > (unsigned)surface->w - 1u))
x = (x < 0) ? 0 : surface->w - 1; x = (x < 0) ? 0 : surface->w - 1;
if (unlikely((unsigned) y > (unsigned) surface->h - 1u)) if (unlikely((unsigned)y > (unsigned)surface->h - 1u))
y = (y < 0) ? 0 : surface->h - 1; y = (y < 0) ? 0 : surface->h - 1;
/* Set a pointer to the exact location in memory of the pixel /* Set a pointer to the exact location in memory of the pixel
in question: */ in question: */
p = (Uint8 *) (((Uint8 *) surface->pixels) + /* Start at top of RAM */ p = (Uint8 *) (((Uint8 *) surface->pixels) + /* Start at top of RAM */
(y * surface->pitch) + /* Go down Y lines */ (y * surface->pitch) + /* Go down Y lines */
(x * 3)); /* Go in X pixels */ (x * 3)); /* Go in X pixels */
/* Return the correctly-sized piece of data containing the /* Return the correctly-sized piece of data containing the
@ -227,24 +219,24 @@ static Uint32 getpixel32(SDL_Surface * surface, int x, int y)
Uint8 *p; Uint8 *p;
/* get the X/Y values within the bounds of this surface */ /* get the X/Y values within the bounds of this surface */
if (unlikely((unsigned) x > (unsigned) surface->w - 1u)) if (unlikely((unsigned)x > (unsigned)surface->w - 1u))
x = (x < 0) ? 0 : surface->w - 1; x = (x < 0) ? 0 : surface->w - 1;
if (unlikely((unsigned) y > (unsigned) surface->h - 1u)) if (unlikely((unsigned)y > (unsigned)surface->h - 1u))
y = (y < 0) ? 0 : surface->h - 1; y = (y < 0) ? 0 : surface->h - 1;
/* Set a pointer to the exact location in memory of the pixel /* Set a pointer to the exact location in memory of the pixel
in question: */ in question: */
p = (Uint8 *) (((Uint8 *) surface->pixels) + /* Start at top of RAM */ p = (Uint8 *) (((Uint8 *) surface->pixels) + /* Start at top of RAM */
(y * surface->pitch) + /* Go down Y lines */ (y * surface->pitch) + /* Go down Y lines */
(x * 4)); /* Go in X pixels */ (x * 4)); /* Go in X pixels */
/* Return the correctly-sized piece of data containing the /* Return the correctly-sized piece of data containing the
* pixel's value (an 8-bit palette value, or a 16-, 24- or 32-bit * pixel's value (an 8-bit palette value, or a 16-, 24- or 32-bit
* RGB value) */ * RGB value) */
return *(Uint32 *) p; // 32-bit display return *(Uint32 *) p; // 32-bit display
} }
void (*putpixels[]) (SDL_Surface *, int, int, Uint32) = void (*putpixels[]) (SDL_Surface *, int, int, Uint32) =