2008-04-25 13:37:36 +00:00
|
|
|
/*
|
2009-04-27 14:48:12 +00:00
|
|
|
* Cogl
|
2008-04-25 13:37:36 +00:00
|
|
|
*
|
2009-04-27 14:48:12 +00:00
|
|
|
* An object oriented GL/GLES Abstraction/Utility Layer
|
2008-04-25 13:37:36 +00:00
|
|
|
*
|
2009-04-27 14:48:12 +00:00
|
|
|
* Copyright (C) 2007,2008,2009 Intel Corporation.
|
2008-04-25 13:37:36 +00:00
|
|
|
*
|
|
|
|
* 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 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
|
2010-03-01 12:56:10 +00:00
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*
|
2008-04-25 13:37:36 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "cogl.h"
|
|
|
|
#include "cogl-internal.h"
|
2009-04-30 17:00:22 +00:00
|
|
|
#include "cogl-bitmap-private.h"
|
2008-04-25 13:37:36 +00:00
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
2008-06-09 21:15:12 +00:00
|
|
|
#ifdef USE_QUARTZ
|
|
|
|
#include <ApplicationServices/ApplicationServices.h>
|
|
|
|
#elif defined(USE_GDKPIXBUF)
|
2008-04-25 13:37:36 +00:00
|
|
|
#include <gdk-pixbuf/gdk-pixbuf.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
_cogl_bitmap_can_convert (CoglPixelFormat src, CoglPixelFormat dst)
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
_cogl_bitmap_can_unpremult (CoglPixelFormat format)
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2009-05-09 18:39:01 +00:00
|
|
|
gboolean
|
|
|
|
_cogl_bitmap_can_premult (CoglPixelFormat format)
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2010-07-07 17:44:16 +00:00
|
|
|
CoglBitmap *
|
|
|
|
_cogl_bitmap_convert (CoglBitmap *bmp,
|
2008-04-25 13:37:36 +00:00
|
|
|
CoglPixelFormat dst_format)
|
|
|
|
{
|
2010-07-07 17:44:16 +00:00
|
|
|
return NULL;
|
2008-04-25 13:37:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2010-01-29 15:15:08 +00:00
|
|
|
_cogl_bitmap_unpremult (CoglBitmap *dst_bmp)
|
2008-04-25 13:37:36 +00:00
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2009-05-09 18:39:01 +00:00
|
|
|
gboolean
|
2010-01-29 15:15:08 +00:00
|
|
|
_cogl_bitmap_premult (CoglBitmap *dst_bmp)
|
2009-05-09 18:39:01 +00:00
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2008-06-09 21:15:12 +00:00
|
|
|
#ifdef USE_QUARTZ
|
|
|
|
|
2009-01-12 16:52:20 +00:00
|
|
|
gboolean
|
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.
2010-02-10 01:57:32 +00:00
|
|
|
_cogl_bitmap_get_size_from_file (const char *filename,
|
|
|
|
int *width,
|
|
|
|
int *height)
|
2009-01-12 16:52:20 +00:00
|
|
|
{
|
|
|
|
if (width)
|
|
|
|
*width = 0;
|
|
|
|
|
|
|
|
if (height)
|
|
|
|
*height = 0;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2008-06-09 21:15:12 +00:00
|
|
|
/* the error does not contain the filename as the caller already has it */
|
2010-07-07 17:44:16 +00:00
|
|
|
CoglBitmap *
|
|
|
|
_cogl_bitmap_from_file (const char *filename,
|
2008-06-09 21:15:12 +00:00
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
g_assert (filename != NULL);
|
|
|
|
g_assert (error == NULL || *error == NULL);
|
|
|
|
|
|
|
|
CFURLRef url = CFURLCreateFromFileSystemRepresentation (NULL, (guchar*)filename, strlen(filename), false);
|
|
|
|
CGImageSourceRef image_source = CGImageSourceCreateWithURL (url, NULL);
|
|
|
|
int save_errno = errno;
|
|
|
|
CFRelease (url);
|
|
|
|
if (image_source == NULL)
|
|
|
|
{
|
|
|
|
/* doesn't exist, not readable, etc. */
|
|
|
|
g_set_error (error, COGL_BITMAP_ERROR, COGL_BITMAP_ERROR_FAILED,
|
|
|
|
"%s", g_strerror (save_errno));
|
2010-07-07 17:44:16 +00:00
|
|
|
return NULL;
|
2008-06-09 21:15:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Unknown images would be cleanly caught as zero width/height below, but try
|
|
|
|
* to provide better error message
|
|
|
|
*/
|
|
|
|
CFStringRef type = CGImageSourceGetType (image_source);
|
|
|
|
if (type == NULL)
|
|
|
|
{
|
|
|
|
CFRelease (image_source);
|
|
|
|
g_set_error (error, COGL_BITMAP_ERROR, COGL_BITMAP_ERROR_UNKNOWN_TYPE,
|
|
|
|
"Unknown image type");
|
2010-07-07 17:44:16 +00:00
|
|
|
return NULL;
|
2008-06-09 21:15:12 +00:00
|
|
|
}
|
|
|
|
CFRelease (type);
|
|
|
|
|
|
|
|
CGImageRef image = CGImageSourceCreateImageAtIndex (image_source, 0, NULL);
|
|
|
|
CFRelease (image_source);
|
|
|
|
|
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.
2010-02-10 01:57:32 +00:00
|
|
|
gsize width = CGImageGetWidth (image);
|
|
|
|
gsize height = CGImageGetHeight (image);
|
2008-06-09 21:15:12 +00:00
|
|
|
if (width == 0 || height == 0)
|
|
|
|
{
|
|
|
|
/* incomplete or corrupt */
|
|
|
|
CFRelease (image);
|
|
|
|
g_set_error (error, COGL_BITMAP_ERROR, COGL_BITMAP_ERROR_CORRUPT_IMAGE,
|
|
|
|
"Image has zero width or height");
|
2010-07-07 17:44:16 +00:00
|
|
|
return NULL;
|
2008-06-09 21:15:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* allocate buffer big enough to hold pixel data */
|
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.
2010-02-10 01:57:32 +00:00
|
|
|
gsize rowstride;
|
2009-11-06 11:57:43 +00:00
|
|
|
rowstride = 4 * width;
|
2008-06-09 21:15:12 +00:00
|
|
|
guint8 *out_data = g_malloc0 (height * rowstride);
|
|
|
|
|
|
|
|
/* render to buffer */
|
|
|
|
CGColorSpaceRef color_space = CGColorSpaceCreateWithName (kCGColorSpaceGenericRGB);
|
|
|
|
CGContextRef bitmap_context = CGBitmapContextCreate (out_data,
|
|
|
|
width, height, 8,
|
|
|
|
rowstride, color_space,
|
2009-11-06 11:57:43 +00:00
|
|
|
kCGImageAlphaPremultipliedFirst);
|
2008-06-09 21:15:12 +00:00
|
|
|
CGColorSpaceRelease (color_space);
|
|
|
|
|
|
|
|
const CGRect rect = {{0, 0}, {width, height}};
|
|
|
|
CGContextDrawImage (bitmap_context, rect, image);
|
|
|
|
|
|
|
|
CGImageRelease (image);
|
|
|
|
CGContextRelease (bitmap_context);
|
|
|
|
|
|
|
|
/* store bitmap info */
|
2010-07-07 17:44:16 +00:00
|
|
|
return _cogl_bitmap_new_from_data (out_data,
|
|
|
|
COGL_PIXEL_FORMAT_ARGB_8888,
|
|
|
|
width, height,
|
|
|
|
rowstride,
|
|
|
|
(CoglBitmapDestroyNotify) g_free,
|
|
|
|
NULL);
|
2008-06-09 21:15:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#elif defined(USE_GDKPIXBUF)
|
2008-04-25 13:37:36 +00:00
|
|
|
|
|
|
|
gboolean
|
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.
2010-02-10 01:57:32 +00:00
|
|
|
_cogl_bitmap_get_size_from_file (const char *filename,
|
|
|
|
int *width,
|
|
|
|
int *height)
|
2009-01-12 16:52:20 +00:00
|
|
|
{
|
|
|
|
g_return_val_if_fail (filename != NULL, FALSE);
|
|
|
|
|
|
|
|
if (gdk_pixbuf_get_file_info (filename, width, height) != NULL)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2010-07-15 10:32:08 +00:00
|
|
|
static void
|
|
|
|
_cogl_bitmap_unref_pixbuf (guint8 *pixels,
|
|
|
|
void *pixbuf)
|
|
|
|
{
|
|
|
|
g_object_unref (pixbuf);
|
|
|
|
}
|
|
|
|
|
2010-07-07 17:44:16 +00:00
|
|
|
CoglBitmap *
|
|
|
|
_cogl_bitmap_from_file (const char *filename,
|
2009-01-12 16:52:20 +00:00
|
|
|
GError **error)
|
2008-04-25 13:37:36 +00:00
|
|
|
{
|
|
|
|
GdkPixbuf *pixbuf;
|
|
|
|
gboolean has_alpha;
|
|
|
|
GdkColorspace color_space;
|
|
|
|
CoglPixelFormat pixel_format;
|
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.
2010-02-10 01:57:32 +00:00
|
|
|
int width;
|
|
|
|
int height;
|
|
|
|
int rowstride;
|
2010-07-22 18:58:47 +00:00
|
|
|
int aligned_rowstride;
|
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.
2010-02-10 01:57:32 +00:00
|
|
|
int bits_per_sample;
|
|
|
|
int n_channels;
|
|
|
|
guint8 *pixels;
|
|
|
|
guint8 *out_data;
|
|
|
|
guint8 *out;
|
|
|
|
int r;
|
2009-04-27 14:48:12 +00:00
|
|
|
|
2008-04-25 13:37:36 +00:00
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
|
|
|
|
|
|
|
|
/* Load from file using GdkPixbuf */
|
|
|
|
pixbuf = gdk_pixbuf_new_from_file (filename, error);
|
2009-01-12 16:52:20 +00:00
|
|
|
if (pixbuf == NULL)
|
|
|
|
return FALSE;
|
2009-04-27 14:48:12 +00:00
|
|
|
|
2008-04-25 13:37:36 +00:00
|
|
|
/* Get pixbuf properties */
|
|
|
|
has_alpha = gdk_pixbuf_get_has_alpha (pixbuf);
|
|
|
|
color_space = gdk_pixbuf_get_colorspace (pixbuf);
|
|
|
|
width = gdk_pixbuf_get_width (pixbuf);
|
|
|
|
height = gdk_pixbuf_get_height (pixbuf);
|
|
|
|
rowstride = gdk_pixbuf_get_rowstride (pixbuf);
|
|
|
|
bits_per_sample = gdk_pixbuf_get_bits_per_sample (pixbuf);
|
|
|
|
n_channels = gdk_pixbuf_get_n_channels (pixbuf);
|
2009-04-27 14:48:12 +00:00
|
|
|
|
2008-04-25 13:37:36 +00:00
|
|
|
/* According to current docs this should be true and so
|
|
|
|
* the translation to cogl pixel format below valid */
|
|
|
|
g_assert (bits_per_sample == 8);
|
|
|
|
|
|
|
|
if (has_alpha)
|
|
|
|
g_assert (n_channels == 4);
|
|
|
|
else
|
|
|
|
g_assert (n_channels == 3);
|
2009-04-27 14:48:12 +00:00
|
|
|
|
2008-04-25 13:37:36 +00:00
|
|
|
/* Translate to cogl pixel format */
|
|
|
|
switch (color_space)
|
|
|
|
{
|
|
|
|
case GDK_COLORSPACE_RGB:
|
|
|
|
/* The only format supported by GdkPixbuf so far */
|
|
|
|
pixel_format = has_alpha ?
|
|
|
|
COGL_PIXEL_FORMAT_RGBA_8888 :
|
|
|
|
COGL_PIXEL_FORMAT_RGB_888;
|
|
|
|
break;
|
2009-04-27 14:48:12 +00:00
|
|
|
|
2008-04-25 13:37:36 +00:00
|
|
|
default:
|
|
|
|
/* Ouch, spec changed! */
|
|
|
|
g_object_unref (pixbuf);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2009-04-27 14:48:12 +00:00
|
|
|
|
2010-07-22 18:58:47 +00:00
|
|
|
/* Work out what the rowstride would be if it was packing the data
|
|
|
|
but aligned to 4 bytes */
|
|
|
|
aligned_rowstride = (width * n_channels + 3) & ~3;
|
|
|
|
|
|
|
|
/* The documentation for GdkPixbuf states that is not safe to read
|
|
|
|
all of the data as height*rowstride because the buffer might not
|
|
|
|
be allocated to include the full length of the rowstride for the
|
|
|
|
last row so arguably we should always copy the buffer when
|
|
|
|
rowstride != width*bpp because some places in Cogl assume that it
|
|
|
|
can memcpy(height*rowstride). However that rule is probably only
|
|
|
|
in place so that GdkPixbuf can implement gdk_pixbuf_new_subpixbuf
|
|
|
|
by just sharing the data and setting a large rowstride. That does
|
|
|
|
not apply in this case because we are just creating a new buffer
|
|
|
|
for a file. It seems very unlikely that GdkPixbuf would not
|
|
|
|
allocate the full rowstride in this case and it is highly
|
|
|
|
desirable to avoid copying the buffer. This instead just assumes
|
|
|
|
that whatever buffer pixbuf points into will always be allocated
|
|
|
|
to a 4-byte aligned buffer so we can avoid copying unless the
|
|
|
|
rowstride is unusually large */
|
|
|
|
if (rowstride <= aligned_rowstride)
|
2010-07-15 10:32:08 +00:00
|
|
|
return _cogl_bitmap_new_from_data (gdk_pixbuf_get_pixels (pixbuf),
|
|
|
|
pixel_format,
|
|
|
|
width,
|
|
|
|
height,
|
|
|
|
rowstride,
|
|
|
|
_cogl_bitmap_unref_pixbuf,
|
|
|
|
pixbuf);
|
2009-04-27 14:48:12 +00:00
|
|
|
|
2008-04-25 13:37:36 +00:00
|
|
|
pixels = gdk_pixbuf_get_pixels (pixbuf);
|
2010-07-22 18:58:47 +00:00
|
|
|
out_data = g_malloc (aligned_rowstride * height);
|
2008-04-25 13:37:36 +00:00
|
|
|
out = out_data;
|
2009-04-27 14:48:12 +00:00
|
|
|
|
2010-07-15 10:32:08 +00:00
|
|
|
for (r = 0; r < height; ++r)
|
2008-04-25 13:37:36 +00:00
|
|
|
{
|
2010-07-15 10:32:08 +00:00
|
|
|
memcpy (out, pixels, n_channels * width);
|
2008-04-25 13:37:36 +00:00
|
|
|
pixels += rowstride;
|
2010-07-22 18:58:47 +00:00
|
|
|
out += aligned_rowstride;
|
2008-04-25 13:37:36 +00:00
|
|
|
}
|
2009-04-27 14:48:12 +00:00
|
|
|
|
2008-04-25 13:37:36 +00:00
|
|
|
/* Destroy GdkPixbuf object */
|
|
|
|
g_object_unref (pixbuf);
|
2009-04-27 14:48:12 +00:00
|
|
|
|
2010-07-07 17:44:16 +00:00
|
|
|
return _cogl_bitmap_new_from_data (out_data,
|
|
|
|
pixel_format,
|
|
|
|
width,
|
|
|
|
height,
|
2010-07-22 18:58:47 +00:00
|
|
|
aligned_rowstride,
|
2010-07-07 17:44:16 +00:00
|
|
|
(CoglBitmapDestroyNotify) g_free,
|
|
|
|
NULL);
|
2008-04-25 13:37:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
#include "stb_image.c"
|
|
|
|
|
2009-01-12 16:52:20 +00:00
|
|
|
gboolean
|
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.
2010-02-10 01:57:32 +00:00
|
|
|
_cogl_bitmap_get_size_from_file (const char *filename,
|
|
|
|
int *width,
|
|
|
|
int *height)
|
2009-01-12 16:52:20 +00:00
|
|
|
{
|
|
|
|
if (width)
|
|
|
|
*width = 0;
|
|
|
|
|
|
|
|
if (height)
|
|
|
|
*height = 0;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2010-07-07 17:44:16 +00:00
|
|
|
CoglBitmap *
|
|
|
|
_cogl_bitmap_from_file (const char *filename,
|
2008-04-25 13:37:36 +00:00
|
|
|
GError **error)
|
|
|
|
{
|
2010-07-07 17:44:16 +00:00
|
|
|
CoglBitmap *bmp;
|
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.
2010-02-10 01:57:32 +00:00
|
|
|
int stb_pixel_format;
|
|
|
|
int width;
|
|
|
|
int height;
|
|
|
|
guint8 *pixels;
|
2008-04-25 13:37:36 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
|
|
|
|
|
|
|
|
/* Load from file using stb */
|
2009-01-12 16:52:20 +00:00
|
|
|
pixels = stbi_load (filename,
|
|
|
|
&width, &height, &stb_pixel_format,
|
|
|
|
STBI_rgb_alpha);
|
|
|
|
if (pixels == NULL)
|
|
|
|
return FALSE;
|
2009-04-27 14:48:12 +00:00
|
|
|
|
2008-04-25 13:37:36 +00:00
|
|
|
/* Store bitmap info */
|
2010-07-07 17:44:16 +00:00
|
|
|
bmp = _cogl_bitmap_new_from_data (g_memdup (pixels, height * width * 4),
|
|
|
|
COGL_PIXEL_FORMAT_RGBA_8888,
|
|
|
|
width, height,
|
|
|
|
width * 4,
|
|
|
|
(CoglBitmapDestroyNotify) g_free,
|
|
|
|
NULL);
|
2008-04-25 13:37:36 +00:00
|
|
|
|
2008-08-27 12:56:54 +00:00
|
|
|
free (pixels);
|
|
|
|
|
2010-07-07 17:44:16 +00:00
|
|
|
return bmp;
|
2008-04-25 13:37:36 +00:00
|
|
|
}
|
|
|
|
#endif
|