cogl: improves header and coding style consistency

We've had complaints that our Cogl code/headers are a bit "special" so
this is a first pass at tidying things up by giving them some
consistency. These changes are all consistent with how new code in Cogl
is being written, but the style isn't consistently applied across all
code yet.

There are two parts to this patch; but since each one required a large
amount of effort to maintain tidy indenting it made sense to combine the
changes to reduce the time spent re indenting the same lines.

The first change is to use a consistent style for declaring function
prototypes in headers. Cogl headers now consistently use this style for
prototypes:

 return_type
 cogl_function_name (CoglType arg0,
                     CoglType arg1);

Not everyone likes this style, but it seems that most of the currently
active Cogl developers agree on it.

The second change is to constrain the use of redundant glib data types
in Cogl. Uses of gint, guint, gfloat, glong, gulong and gchar have all
been replaced with int, unsigned int, float, long, unsigned long and char
respectively. When talking about pixel data; use of guchar has been
replaced with guint8, otherwise unsigned char can be used.

The glib types that we continue to use for portability are gboolean,
gint{8,16,32,64}, guint{8,16,32,64} and gsize.

The general intention is that Cogl should look palatable to the widest
range of C programmers including those outside the Gnome community so
- especially for the public API - we want to minimize the number of
foreign looking typedefs.
This commit is contained in:
Robert Bragg
2010-02-10 01:57:32 +00:00
parent 10fa7c7ce9
commit 0f5f4e8645
64 changed files with 1491 additions and 1184 deletions

View File

@ -34,7 +34,7 @@
/* TO rgba */
inline static void
_cogl_g_to_rgba (const guchar *src, guchar *dst)
_cogl_g_to_rgba (const guint8 *src, guint8 *dst)
{
dst[0] = src[0];
dst[1] = src[0];
@ -43,7 +43,7 @@ _cogl_g_to_rgba (const guchar *src, guchar *dst)
}
inline static void
_cogl_rgb_to_rgba (const guchar *src, guchar *dst)
_cogl_rgb_to_rgba (const guint8 *src, guint8 *dst)
{
dst[0] = src[0];
dst[1] = src[1];
@ -52,7 +52,7 @@ _cogl_rgb_to_rgba (const guchar *src, guchar *dst)
}
inline static void
_cogl_bgr_to_rgba (const guchar *src, guchar *dst)
_cogl_bgr_to_rgba (const guint8 *src, guint8 *dst)
{
dst[0] = src[2];
dst[1] = src[1];
@ -61,7 +61,7 @@ _cogl_bgr_to_rgba (const guchar *src, guchar *dst)
}
inline static void
_cogl_bgra_to_rgba (const guchar *src, guchar *dst)
_cogl_bgra_to_rgba (const guint8 *src, guint8 *dst)
{
dst[0] = src[2];
dst[1] = src[1];
@ -70,7 +70,7 @@ _cogl_bgra_to_rgba (const guchar *src, guchar *dst)
}
inline static void
_cogl_argb_to_rgba (const guchar *src, guchar *dst)
_cogl_argb_to_rgba (const guint8 *src, guint8 *dst)
{
dst[0] = src[1];
dst[1] = src[2];
@ -79,7 +79,7 @@ _cogl_argb_to_rgba (const guchar *src, guchar *dst)
}
inline static void
_cogl_abgr_to_rgba (const guchar *src, guchar *dst)
_cogl_abgr_to_rgba (const guint8 *src, guint8 *dst)
{
dst[0] = src[3];
dst[1] = src[2];
@ -88,7 +88,7 @@ _cogl_abgr_to_rgba (const guchar *src, guchar *dst)
}
inline static void
_cogl_rgba_to_rgba (const guchar *src, guchar *dst)
_cogl_rgba_to_rgba (const guint8 *src, guint8 *dst)
{
dst[0] = src[0];
dst[1] = src[1];
@ -99,13 +99,13 @@ _cogl_rgba_to_rgba (const guchar *src, guchar *dst)
/* FROM rgba */
inline static void
_cogl_rgba_to_g (const guchar *src, guchar *dst)
_cogl_rgba_to_g (const guint8 *src, guint8 *dst)
{
dst[0] = (src[0] + src[1] + src[2]) / 3;
}
inline static void
_cogl_rgba_to_rgb (const guchar *src, guchar *dst)
_cogl_rgba_to_rgb (const guint8 *src, guint8 *dst)
{
dst[0] = src[0];
dst[1] = src[1];
@ -113,7 +113,7 @@ _cogl_rgba_to_rgb (const guchar *src, guchar *dst)
}
inline static void
_cogl_rgba_to_bgr (const guchar *src, guchar *dst)
_cogl_rgba_to_bgr (const guint8 *src, guint8 *dst)
{
dst[0] = src[2];
dst[1] = src[1];
@ -121,7 +121,7 @@ _cogl_rgba_to_bgr (const guchar *src, guchar *dst)
}
inline static void
_cogl_rgba_to_bgra (const guchar *src, guchar *dst)
_cogl_rgba_to_bgra (const guint8 *src, guint8 *dst)
{
dst[0] = src[2];
dst[1] = src[1];
@ -130,7 +130,7 @@ _cogl_rgba_to_bgra (const guchar *src, guchar *dst)
}
inline static void
_cogl_rgba_to_argb (const guchar *src, guchar *dst)
_cogl_rgba_to_argb (const guint8 *src, guint8 *dst)
{
dst[0] = src[3];
dst[1] = src[0];
@ -139,7 +139,7 @@ _cogl_rgba_to_argb (const guchar *src, guchar *dst)
}
inline static void
_cogl_rgba_to_abgr (const guchar *src, guchar *dst)
_cogl_rgba_to_abgr (const guint8 *src, guint8 *dst)
{
dst[0] = src[3];
dst[1] = src[2];
@ -150,7 +150,7 @@ _cogl_rgba_to_abgr (const guchar *src, guchar *dst)
/* (Un)Premultiplication */
inline static void
_cogl_unpremult_alpha_0 (guchar *dst)
_cogl_unpremult_alpha_0 (guint8 *dst)
{
dst[0] = 0;
dst[1] = 0;
@ -159,9 +159,9 @@ _cogl_unpremult_alpha_0 (guchar *dst)
}
inline static void
_cogl_unpremult_alpha_last (guchar *dst)
_cogl_unpremult_alpha_last (guint8 *dst)
{
guchar alpha = dst[3];
guint8 alpha = dst[3];
dst[0] = (dst[0] * 255) / alpha;
dst[1] = (dst[1] * 255) / alpha;
@ -169,9 +169,9 @@ _cogl_unpremult_alpha_last (guchar *dst)
}
inline static void
_cogl_unpremult_alpha_first (guchar *dst)
_cogl_unpremult_alpha_first (guint8 *dst)
{
guchar alpha = dst[0];
guint8 alpha = dst[0];
dst[1] = (dst[1] * 255) / alpha;
dst[2] = (dst[2] * 255) / alpha;
@ -189,24 +189,24 @@ _cogl_unpremult_alpha_first (guchar *dst)
} G_STMT_END
inline static void
_cogl_premult_alpha_last (guchar *dst)
_cogl_premult_alpha_last (guint8 *dst)
{
guchar alpha = dst[3];
guint8 alpha = dst[3];
/* Using a separate temporary per component has given slightly better
* code generation with GCC in the past; it shouldn't do any worse in
* any case.
*/
guint t1, t2, t3;
unsigned int t1, t2, t3;
MULT(dst[0], alpha, t1);
MULT(dst[1], alpha, t2);
MULT(dst[2], alpha, t3);
}
inline static void
_cogl_premult_alpha_first (guchar *dst)
_cogl_premult_alpha_first (guint8 *dst)
{
guchar alpha = dst[0];
guint t1, t2, t3;
guint8 alpha = dst[0];
unsigned int t1, t2, t3;
MULT(dst[1], alpha, t1);
MULT(dst[2], alpha, t2);
@ -342,12 +342,12 @@ _cogl_bitmap_fallback_convert (const CoglBitmap *bmp,
CoglBitmap *dst_bmp,
CoglPixelFormat dst_format)
{
guchar *src;
guchar *dst;
gint src_bpp;
gint dst_bpp;
gint x,y;
guchar temp_rgba[4] = {0,0,0,0};
guint8 *src;
guint8 *dst;
int src_bpp;
int dst_bpp;
int x,y;
guint8 temp_rgba[4] = {0,0,0,0};
/* Make sure conversion supported */
if (!_cogl_bitmap_fallback_can_convert (bmp->format, dst_format))
@ -358,20 +358,20 @@ _cogl_bitmap_fallback_convert (const CoglBitmap *bmp,
/* Initialize destination bitmap */
*dst_bmp = *bmp;
dst_bmp->rowstride = sizeof(guchar) * dst_bpp * dst_bmp->width;
dst_bmp->rowstride = sizeof(guint8) * dst_bpp * dst_bmp->width;
dst_bmp->format = ((bmp->format & COGL_PREMULT_BIT) |
(dst_format & COGL_UNPREMULT_MASK));
/* Allocate a new buffer to hold converted data */
dst_bmp->data = g_malloc (sizeof(guchar)
dst_bmp->data = g_malloc (sizeof(guint8)
* dst_bmp->height
* dst_bmp->rowstride);
/* FIXME: Optimize */
for (y = 0; y < bmp->height; y++)
{
src = (guchar*)bmp->data + y * bmp->rowstride;
dst = (guchar*)dst_bmp->data + y * dst_bmp->rowstride;
src = (guint8*)bmp->data + y * bmp->rowstride;
dst = (guint8*)dst_bmp->data + y * dst_bmp->rowstride;
for (x = 0; x < bmp->width; x++)
{
@ -429,8 +429,8 @@ _cogl_bitmap_fallback_convert (const CoglBitmap *bmp,
gboolean
_cogl_bitmap_fallback_unpremult (CoglBitmap *bmp)
{
guchar *p;
gint x,y;
guint8 *p;
int x,y;
/* Make sure format supported for un-premultiplication */
if (!_cogl_bitmap_fallback_can_unpremult (bmp->format))
@ -438,7 +438,7 @@ _cogl_bitmap_fallback_unpremult (CoglBitmap *bmp)
for (y = 0; y < bmp->height; y++)
{
p = (guchar*) bmp->data + y * bmp->rowstride;
p = (guint8*) bmp->data + y * bmp->rowstride;
if (bmp->format & COGL_AFIRST_BIT)
{
@ -472,8 +472,8 @@ _cogl_bitmap_fallback_unpremult (CoglBitmap *bmp)
gboolean
_cogl_bitmap_fallback_premult (CoglBitmap *bmp)
{
guchar *p;
gint x,y;
guint8 *p;
int x,y;
/* Make sure format supported for un-premultiplication */
if (!_cogl_bitmap_fallback_can_premult (bmp->format))
@ -481,7 +481,7 @@ _cogl_bitmap_fallback_premult (CoglBitmap *bmp)
for (y = 0; y < bmp->height; y++)
{
p = (guchar*) bmp->data + y * bmp->rowstride;
p = (guint8*) bmp->data + y * bmp->rowstride;
if (bmp->format & COGL_AFIRST_BIT)
{
@ -525,7 +525,7 @@ _cogl_bitmap_fallback_premult (CoglBitmap *bmp)
gboolean
_cogl_bitmap_fallback_from_file (CoglBitmap *bmp,
const gchar *filename)
const char *filename)
{
/* FIXME: use jpeglib, libpng, etc. manually maybe */
return FALSE;