diff --git a/cogl/cogl-atlas.c b/cogl/cogl-atlas.c index 3b5ddab35..b6749b502 100644 --- a/cogl/cogl-atlas.c +++ b/cogl/cogl-atlas.c @@ -39,6 +39,7 @@ #include "cogl-debug.h" #include "cogl-framebuffer-private.h" #include "cogl-blit.h" +#include "cogl-private.h" #include @@ -187,7 +188,7 @@ _cogl_atlas_get_initial_size (CoglPixelFormat format, initial minimum size. If the format is only 1 byte per pixel we can use 1024x1024, otherwise we'll assume it will take 4 bytes per pixel and use 512x512. */ - if (_cogl_get_format_bpp (format) == 1) + if (_cogl_pixel_format_get_bytes_per_pixel (format) == 1) size = 1024; else size = 512; @@ -276,7 +277,7 @@ _cogl_atlas_create_texture (CoglAtlas *atlas, { guint8 *clear_data; CoglBitmap *clear_bmp; - int bpp = _cogl_get_format_bpp (atlas->texture_format); + int bpp = _cogl_pixel_format_get_bytes_per_pixel (atlas->texture_format); /* Create a buffer of zeroes to initially clear the texture */ clear_data = g_malloc0 (width * height * bpp); diff --git a/cogl/cogl-bitmap-fallback.c b/cogl/cogl-bitmap-fallback.c index 4478c4326..1b5b8ca1d 100644 --- a/cogl/cogl-bitmap-fallback.c +++ b/cogl/cogl-bitmap-fallback.c @@ -26,7 +26,7 @@ #endif #include "cogl.h" -#include "cogl-internal.h" +#include "cogl-private.h" #include "cogl-bitmap-private.h" #include @@ -367,8 +367,8 @@ _cogl_bitmap_fallback_convert (CoglBitmap *src_bmp, if (src_data == NULL) return NULL; - src_bpp = _cogl_get_format_bpp (src_format); - dst_bpp = _cogl_get_format_bpp (dst_format); + src_bpp = _cogl_pixel_format_get_bytes_per_pixel (src_format); + dst_bpp = _cogl_pixel_format_get_bytes_per_pixel (dst_format); /* Initialize destination bitmap */ dst_rowstride = sizeof(guint8) * dst_bpp * width; diff --git a/cogl/cogl-bitmap.c b/cogl/cogl-bitmap.c index a109d03b9..84fd7ac71 100644 --- a/cogl/cogl-bitmap.c +++ b/cogl/cogl-bitmap.c @@ -28,7 +28,7 @@ #include "cogl.h" #include "cogl-util.h" #include "cogl-debug.h" -#include "cogl-internal.h" +#include "cogl-private.h" #include "cogl-bitmap-private.h" #include "cogl-buffer-private.h" @@ -80,24 +80,6 @@ _cogl_bitmap_free (CoglBitmap *bmp) g_slice_free (CoglBitmap, bmp); } -int -_cogl_get_format_bpp (CoglPixelFormat format) -{ - int bpp_lut[] = { - 0, /* invalid */ - 1, /* A_8 */ - 3, /* 888 */ - 4, /* 8888 */ - 2, /* 565 */ - 2, /* 4444 */ - 2, /* 5551 */ - 2, /* YUV */ - 1 /* G_8 */ - }; - - return bpp_lut [format & COGL_UNORDERED_MASK]; -} - gboolean _cogl_bitmap_convert_premult_status (CoglBitmap *bmp, CoglPixelFormat dst_format) @@ -187,7 +169,7 @@ _cogl_bitmap_copy (CoglBitmap *src_bmp) { CoglBitmap *dst_bmp; CoglPixelFormat src_format = _cogl_bitmap_get_format (src_bmp); - int bpp = _cogl_get_format_bpp (src_format); + int bpp = _cogl_pixel_format_get_bytes_per_pixel (src_format); int width = _cogl_bitmap_get_width (src_bmp); int height = _cogl_bitmap_get_height (src_bmp); int dst_rowstride = width * bpp; @@ -228,7 +210,7 @@ _cogl_bitmap_copy_subregion (CoglBitmap *src, /* Intended only for fast copies when format is equal! */ g_assert (src->format == dst->format); - bpp = _cogl_get_format_bpp (src->format); + bpp = _cogl_pixel_format_get_bytes_per_pixel (src->format); if ((srcdata = _cogl_bitmap_map (src, COGL_BUFFER_ACCESS_READ, 0))) { diff --git a/cogl/cogl-blit.c b/cogl/cogl-blit.c index 8f695bf33..d3a6b9c95 100644 --- a/cogl/cogl-blit.c +++ b/cogl/cogl-blit.c @@ -268,7 +268,7 @@ static gboolean _cogl_blit_get_tex_data_begin (CoglBlitData *data) { data->format = cogl_texture_get_format (data->src_tex); - data->bpp = _cogl_get_format_bpp (data->format); + data->bpp = _cogl_pixel_format_get_bytes_per_pixel (data->format); data->image_data = g_malloc (data->bpp * data->src_width * data->src_height); diff --git a/cogl/cogl-internal.h b/cogl/cogl-internal.h index 6d0013756..417ec709c 100644 --- a/cogl/cogl-internal.h +++ b/cogl/cogl-internal.h @@ -70,9 +70,6 @@ cogl_gl_error_to_string (GLenum error_code); #define COGL_ENABLE_VERTEX_ARRAY (1<<2) #define COGL_ENABLE_COLOR_ARRAY (1<<3) -int -_cogl_get_format_bpp (CoglPixelFormat format); - void _cogl_enable (unsigned long flags); diff --git a/cogl/cogl-pixel-buffer.c b/cogl/cogl-pixel-buffer.c index 84f948f26..bb8abad38 100644 --- a/cogl/cogl-pixel-buffer.c +++ b/cogl/cogl-pixel-buffer.c @@ -39,7 +39,7 @@ #include #include "cogl.h" -#include "cogl-internal.h" +#include "cogl-private.h" #include "cogl-util.h" #include "cogl-context-private.h" #include "cogl-object.h" @@ -109,7 +109,7 @@ cogl_pixel_buffer_new_with_size (CoglContext *context, /* for now we fallback to cogl_pixel_buffer_new, later, we could ask * libdrm a tiled buffer for instance */ - stride = width * _cogl_get_format_bpp (format); + stride = width * _cogl_pixel_format_get_bytes_per_pixel (format); if (rowstride) *rowstride = stride; diff --git a/cogl/cogl-private.h b/cogl/cogl-private.h index 911356d5d..b4ff42056 100644 --- a/cogl/cogl-private.h +++ b/cogl/cogl-private.h @@ -63,6 +63,18 @@ _cogl_push_source (CoglPipeline *pipeline, gboolean enable_legacy); gboolean _cogl_get_enable_legacy_state (void); +/* + * _cogl_pixel_format_get_bytes_per_pixel: + * @format: a #CoglPixelFormat + * + * Queries how many bytes a pixel of the given @format takes. + * + * Return value: The number of bytes taken for a pixel of the given + * @format. + */ +int +_cogl_pixel_format_get_bytes_per_pixel (CoglPixelFormat format); + G_END_DECLS #endif /* __COGL_PRIVATE_H__ */ diff --git a/cogl/cogl-texture-2d-sliced.c b/cogl/cogl-texture-2d-sliced.c index 7220bf24c..2e6eaf0fe 100644 --- a/cogl/cogl-texture-2d-sliced.c +++ b/cogl/cogl-texture-2d-sliced.c @@ -32,7 +32,7 @@ #include "cogl.h" #include "cogl-debug.h" -#include "cogl-internal.h" +#include "cogl-private.h" #include "cogl-util.h" #include "cogl-bitmap.h" #include "cogl-bitmap-private.h" @@ -146,7 +146,7 @@ _cogl_texture_2d_sliced_allocate_waste_buffer (CoglTexture2DSliced *tex_2ds, tex_2ds->slice_y_spans->len - 1); if (last_x_span->waste > 0 || last_y_span->waste > 0) { - int bpp = _cogl_get_format_bpp (format); + int bpp = _cogl_pixel_format_get_bytes_per_pixel (format); CoglSpan *first_x_span = &g_array_index (tex_2ds->slice_x_spans, CoglSpan, 0); CoglSpan *first_y_span @@ -190,7 +190,7 @@ _cogl_texture_2d_sliced_set_waste (CoglTexture2DSliced *tex_2ds, { int bmp_rowstride = _cogl_bitmap_get_rowstride (source_bmp); CoglPixelFormat source_format = _cogl_bitmap_get_format (source_bmp); - int bpp = _cogl_get_format_bpp (source_format); + int bpp = _cogl_pixel_format_get_bytes_per_pixel (source_format); guint8 *bmp_data; const guint8 *src; guint8 *dst; diff --git a/cogl/cogl-texture-2d.c b/cogl/cogl-texture-2d.c index 89bf63dad..fef456b97 100644 --- a/cogl/cogl-texture-2d.c +++ b/cogl/cogl-texture-2d.c @@ -29,7 +29,7 @@ #endif #include "cogl.h" -#include "cogl-internal.h" +#include "cogl-private.h" #include "cogl-util.h" #include "cogl-texture-private.h" #include "cogl-texture-2d-private.h" @@ -268,10 +268,11 @@ _cogl_texture_2d_new_from_bitmap (CoglBitmap *bmp, (data = _cogl_bitmap_map (dst_bmp, COGL_BUFFER_ACCESS_READ, 0))) { + CoglPixelFormat format = _cogl_bitmap_get_format (dst_bmp); tex_2d->first_pixel.gl_format = gl_format; tex_2d->first_pixel.gl_type = gl_type; memcpy (tex_2d->first_pixel.data, data, - _cogl_get_format_bpp (_cogl_bitmap_get_format (dst_bmp))); + _cogl_pixel_format_get_bytes_per_pixel (format)); _cogl_bitmap_unmap (dst_bmp); } @@ -310,7 +311,7 @@ cogl_texture_2d_new_from_data (CoglContext *ctx, /* Rowstride from width if not given */ if (rowstride == 0) - rowstride = width * _cogl_get_format_bpp (format); + rowstride = width * _cogl_pixel_format_get_bytes_per_pixel (format); /* Wrap the data into a bitmap */ bmp = _cogl_bitmap_new_from_data ((guint8 *)data, @@ -770,7 +771,7 @@ _cogl_texture_2d_set_region (CoglTexture *tex, (data = _cogl_bitmap_map (bmp, COGL_BUFFER_ACCESS_READ, 0))) { CoglPixelFormat bpp = - _cogl_get_format_bpp (_cogl_bitmap_get_format (bmp)); + _cogl_pixel_format_get_bytes_per_pixel (_cogl_bitmap_get_format (bmp)); tex_2d->first_pixel.gl_format = gl_format; tex_2d->first_pixel.gl_type = gl_type; memcpy (tex_2d->first_pixel.data, @@ -811,7 +812,7 @@ _cogl_texture_2d_get_data (CoglTexture *tex, _COGL_GET_CONTEXT (ctx, FALSE); - bpp = _cogl_get_format_bpp (format); + bpp = _cogl_pixel_format_get_bytes_per_pixel (format); ctx->texture_driver->pixel_format_to_gl (format, NULL, /* internal format */ diff --git a/cogl/cogl-texture-3d.c b/cogl/cogl-texture-3d.c index f332b68f3..05ea35ced 100644 --- a/cogl/cogl-texture-3d.c +++ b/cogl/cogl-texture-3d.c @@ -27,7 +27,7 @@ #endif #include "cogl.h" -#include "cogl-internal.h" +#include "cogl-private.h" #include "cogl-util.h" #include "cogl-texture-private.h" #include "cogl-texture-3d-private.h" @@ -287,10 +287,11 @@ _cogl_texture_3d_new_from_bitmap (CoglBitmap *bmp, (data = _cogl_bitmap_map (dst_bmp, COGL_BUFFER_ACCESS_READ, 0))) { + CoglPixelFormat format = _cogl_bitmap_get_format (dst_bmp); tex_3d->first_pixel.gl_format = gl_format; tex_3d->first_pixel.gl_type = gl_type; memcpy (tex_3d->first_pixel.data, data, - _cogl_get_format_bpp (_cogl_bitmap_get_format (dst_bmp))); + _cogl_pixel_format_get_bytes_per_pixel (format)); _cogl_bitmap_unmap (dst_bmp); } @@ -340,7 +341,7 @@ cogl_texture_3d_new_from_data (unsigned int width, /* Rowstride from width if not given */ if (rowstride == 0) - rowstride = width * _cogl_get_format_bpp (format); + rowstride = width * _cogl_pixel_format_get_bytes_per_pixel (format); /* Image stride from height and rowstride if not given */ if (image_stride == 0) image_stride = height * rowstride; @@ -355,7 +356,8 @@ cogl_texture_3d_new_from_data (unsigned int width, if (image_stride % rowstride != 0) { int z, y; - int bmp_rowstride = _cogl_get_format_bpp (format) * width; + int bmp_rowstride = + _cogl_pixel_format_get_bytes_per_pixel (format) * width; guint8 *bmp_data = g_malloc (bmp_rowstride * height * depth); bitmap = _cogl_bitmap_new_from_data (bmp_data, diff --git a/cogl/cogl-texture-rectangle.c b/cogl/cogl-texture-rectangle.c index 556b718ef..88bc9f121 100644 --- a/cogl/cogl-texture-rectangle.c +++ b/cogl/cogl-texture-rectangle.c @@ -29,7 +29,7 @@ #endif #include "cogl.h" -#include "cogl-internal.h" +#include "cogl-private.h" #include "cogl-util.h" #include "cogl-texture-private.h" #include "cogl-texture-rectangle-private.h" @@ -531,7 +531,7 @@ _cogl_texture_rectangle_get_data (CoglTexture *tex, _COGL_GET_CONTEXT (ctx, FALSE); - bpp = _cogl_get_format_bpp (format); + bpp = _cogl_pixel_format_get_bytes_per_pixel (format); ctx->texture_driver->pixel_format_to_gl (format, NULL, /* internal format */ diff --git a/cogl/cogl-texture.c b/cogl/cogl-texture.c index bb3567761..1ff8a0f95 100644 --- a/cogl/cogl-texture.c +++ b/cogl/cogl-texture.c @@ -343,7 +343,7 @@ cogl_texture_new_from_data (unsigned int width, /* Rowstride from width if not given */ if (rowstride == 0) - rowstride = width * _cogl_get_format_bpp (format); + rowstride = width * _cogl_pixel_format_get_bytes_per_pixel (format); /* Wrap the data into a bitmap */ bmp = _cogl_bitmap_new_from_data ((guint8 *) data, @@ -530,7 +530,7 @@ cogl_texture_new_from_buffer_EXP (CoglPixelBuffer *buffer, if (rowstride == 0) rowstride = pixel_buffer->stride; if (rowstride == 0) - rowstride = width * _cogl_get_format_bpp (format); + rowstride = width * _cogl_pixel_format_get_bytes_per_pixel (format); /* use the CoglBuffer height and width as last resort */ if (width == 0) @@ -580,12 +580,13 @@ cogl_texture_get_format (CoglTexture *texture) unsigned int cogl_texture_get_rowstride (CoglTexture *texture) { + CoglPixelFormat format = cogl_texture_get_format (texture); /* FIXME: This function should go away. It previously just returned the rowstride that was used to upload the data as far as I can tell. This is not helpful */ /* Just guess at a suitable rowstride */ - return (_cogl_get_format_bpp (cogl_texture_get_format (texture)) + return (_cogl_pixel_format_get_bytes_per_pixel (format) * cogl_texture_get_width (texture)); } @@ -733,7 +734,7 @@ cogl_texture_set_region (CoglTexture *texture, /* Rowstride from width if none specified */ if (rowstride == 0) - rowstride = _cogl_get_format_bpp (format) * width; + rowstride = _cogl_pixel_format_get_bytes_per_pixel (format) * width; /* Init source bitmap */ source_bmp = _cogl_bitmap_new_from_data ((guint8 *) data, @@ -782,7 +783,7 @@ do_texture_draw_and_read (CoglTexture *texture, CoglBitmap *rect_bmp; unsigned int tex_width, tex_height; - bpp = _cogl_get_format_bpp (COGL_PIXEL_FORMAT_RGBA_8888); + bpp = _cogl_pixel_format_get_bytes_per_pixel (COGL_PIXEL_FORMAT_RGBA_8888); tex_width = cogl_texture_get_width (texture); tex_height = cogl_texture_get_height (texture); @@ -886,7 +887,7 @@ _cogl_texture_draw_and_read (CoglTexture *texture, _COGL_GET_CONTEXT (ctx, FALSE); - bpp = _cogl_get_format_bpp (COGL_PIXEL_FORMAT_RGBA_8888); + bpp = _cogl_pixel_format_get_bytes_per_pixel (COGL_PIXEL_FORMAT_RGBA_8888); framebuffer = cogl_get_draw_framebuffer (); /* Viewport needs to have some size and be inside the window for this */ @@ -1071,7 +1072,7 @@ get_texture_bits_via_copy (CoglTexture *texture, full_tex_width = cogl_texture_get_width (texture); full_tex_height = cogl_texture_get_height (texture); - bpp = _cogl_get_format_bpp (dst_format); + bpp = _cogl_pixel_format_get_bytes_per_pixel (dst_format); full_rowstride = bpp * full_tex_width; full_bits = g_malloc (full_rowstride * full_tex_height); @@ -1117,7 +1118,7 @@ texture_get_cb (CoglTexture *texture, { CoglTextureGetData *tg_data = user_data; CoglPixelFormat format = _cogl_bitmap_get_format (tg_data->target_bmp); - int bpp = _cogl_get_format_bpp (format); + int bpp = _cogl_pixel_format_get_bytes_per_pixel (format); unsigned int rowstride = _cogl_bitmap_get_rowstride (tg_data->target_bmp); int subtexture_width = cogl_texture_get_width (texture); int subtexture_height = cogl_texture_get_height (texture); @@ -1207,7 +1208,7 @@ cogl_texture_get_data (CoglTexture *texture, tex_height = cogl_texture_get_height (texture); /* Rowstride from texture width if none specified */ - bpp = _cogl_get_format_bpp (format); + bpp = _cogl_pixel_format_get_bytes_per_pixel (format); if (rowstride == 0) rowstride = tex_width * bpp; @@ -1220,7 +1221,7 @@ cogl_texture_get_data (CoglTexture *texture, ctx->texture_driver->find_best_gl_get_data_format (format, &closest_gl_format, &closest_gl_type); - closest_bpp = _cogl_get_format_bpp (closest_format); + closest_bpp = _cogl_pixel_format_get_bytes_per_pixel (closest_format); /* Is the requested format supported? */ if (closest_format == format) diff --git a/cogl/cogl.c b/cogl/cogl.c index 8ed44592c..d22a91faf 100644 --- a/cogl/cogl.c +++ b/cogl/cogl.c @@ -436,7 +436,7 @@ _cogl_read_pixels_with_rowstride (int x, y = framebuffer_height - y - height; /* Initialise the CoglBitmap */ - bpp = _cogl_get_format_bpp (format); + bpp = _cogl_pixel_format_get_bytes_per_pixel (format); bmp_format = format; if ((format & COGL_A_BIT)) @@ -574,10 +574,11 @@ cogl_read_pixels (int x, CoglPixelFormat format, guint8 *pixels) { + int bpp = _cogl_pixel_format_get_bytes_per_pixel (format); _cogl_read_pixels_with_rowstride (x, y, width, height, source, format, pixels, /* rowstride */ - _cogl_get_format_bpp (format) * width); + bpp * width); } void @@ -1005,3 +1006,21 @@ _cogl_init (void) g_once_init_leave (&init_status, 1); } } + +int +_cogl_pixel_format_get_bytes_per_pixel (CoglPixelFormat format) +{ + int bpp_lut[] = { + 0, /* invalid */ + 1, /* A_8 */ + 3, /* 888 */ + 4, /* 8888 */ + 2, /* 565 */ + 2, /* 4444 */ + 2, /* 5551 */ + 2, /* YUV */ + 1 /* G_8 */ + }; + + return bpp_lut [format & 0xf]; +} diff --git a/cogl/driver/gl/cogl-texture-driver-gl.c b/cogl/driver/gl/cogl-texture-driver-gl.c index 6ab1b3e3b..deda4c6c4 100644 --- a/cogl/driver/gl/cogl-texture-driver-gl.c +++ b/cogl/driver/gl/cogl-texture-driver-gl.c @@ -31,7 +31,7 @@ #endif #include "cogl.h" -#include "cogl-internal.h" +#include "cogl-private.h" #include "cogl-util.h" #include "cogl-bitmap.h" #include "cogl-bitmap-private.h" @@ -158,7 +158,8 @@ _cogl_texture_driver_upload_subregion_to_gl (GLenum gl_target, GLuint source_gl_type) { guint8 *data; - int bpp = _cogl_get_format_bpp (_cogl_bitmap_get_format (source_bmp)); + CoglPixelFormat source_format = _cogl_bitmap_get_format (source_bmp); + int bpp = _cogl_pixel_format_get_bytes_per_pixel (source_format); _COGL_GET_CONTEXT (ctx, NO_RETVAL); @@ -193,7 +194,8 @@ _cogl_texture_driver_upload_to_gl (GLenum gl_target, GLuint source_gl_type) { guint8 *data; - int bpp = _cogl_get_format_bpp (_cogl_bitmap_get_format (source_bmp)); + CoglPixelFormat source_format = _cogl_bitmap_get_format (source_bmp); + int bpp = _cogl_pixel_format_get_bytes_per_pixel (source_format); _COGL_GET_CONTEXT (ctx, NO_RETVAL); @@ -229,7 +231,8 @@ _cogl_texture_driver_upload_to_gl_3d (GLenum gl_target, GLuint source_gl_type) { guint8 *data; - int bpp = _cogl_get_format_bpp (_cogl_bitmap_get_format (source_bmp)); + CoglPixelFormat source_format = _cogl_bitmap_get_format (source_bmp); + int bpp = _cogl_pixel_format_get_bytes_per_pixel (source_format); _COGL_GET_CONTEXT (ctx, NO_RETVAL); diff --git a/cogl/driver/gles/cogl-texture-driver-gles.c b/cogl/driver/gles/cogl-texture-driver-gles.c index 5123993b3..bf80012e0 100644 --- a/cogl/driver/gles/cogl-texture-driver-gles.c +++ b/cogl/driver/gles/cogl-texture-driver-gles.c @@ -31,7 +31,7 @@ #endif #include "cogl.h" -#include "cogl-internal.h" +#include "cogl-private.h" #include "cogl-util.h" #include "cogl-bitmap.h" #include "cogl-bitmap-private.h" @@ -102,7 +102,7 @@ static CoglBitmap * prepare_bitmap_alignment_for_upload (CoglBitmap *src_bmp) { CoglPixelFormat format = _cogl_bitmap_get_format (src_bmp); - int bpp = _cogl_get_format_bpp (format); + int bpp = _cogl_pixel_format_get_bytes_per_pixel (format); int src_rowstride = _cogl_bitmap_get_rowstride (src_bmp); int width = _cogl_bitmap_get_width (src_bmp); int alignment = 1; @@ -140,7 +140,7 @@ _cogl_texture_driver_upload_subregion_to_gl (GLenum gl_target, { guint8 *data; CoglPixelFormat source_format = _cogl_bitmap_get_format (source_bmp); - int bpp = _cogl_get_format_bpp (source_format); + int bpp = _cogl_pixel_format_get_bytes_per_pixel (source_format); CoglBitmap *slice_bmp; int rowstride; @@ -201,7 +201,8 @@ _cogl_texture_driver_upload_to_gl (GLenum gl_target, GLuint source_gl_format, GLuint source_gl_type) { - int bpp = _cogl_get_format_bpp (_cogl_bitmap_get_format (source_bmp)); + CoglPixelFormat source_format = _cogl_bitmap_get_format (source_bmp); + int bpp = _cogl_pixel_format_get_bytes_per_pixel (source_format); int rowstride; int bmp_width = _cogl_bitmap_get_width (source_bmp); int bmp_height = _cogl_bitmap_get_height (source_bmp); @@ -244,7 +245,8 @@ _cogl_texture_driver_upload_to_gl_3d (GLenum gl_target, GLuint source_gl_format, GLuint source_gl_type) { - int bpp = _cogl_get_format_bpp (_cogl_bitmap_get_format (source_bmp)); + CoglPixelFormat source_format = _cogl_bitmap_get_format (source_bmp); + int bpp = _cogl_pixel_format_get_bytes_per_pixel (source_format); int rowstride = _cogl_bitmap_get_rowstride (source_bmp); int bmp_width = _cogl_bitmap_get_width (source_bmp); int bmp_height = _cogl_bitmap_get_height (source_bmp);