4
* An object oriented GL/GLES Abstraction/Utility Layer
6
* Copyright (C) 2007,2008,2009 Intel Corporation.
8
* This library is free software; you can redistribute it and/or
9
* modify it under the terms of the GNU Lesser General Public
10
* License as published by the Free Software Foundation; either
11
* version 2 of the License, or (at your option) any later version.
13
* This library is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
* Lesser General Public License for more details.
18
* You should have received a copy of the GNU Lesser General Public
19
* License along with this library; if not, write to the
20
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21
* Boston, MA 02111-1307, USA.
29
#include "cogl-internal.h"
30
#include "cogl-bitmap-private.h"
34
static void _cogl_bitmap_free (CoglBitmap *bmp);
36
COGL_HANDLE_DEFINE (Bitmap, bitmap);
39
_cogl_bitmap_free (CoglBitmap *bmp)
46
_cogl_get_format_bpp (CoglPixelFormat format)
60
return bpp_lut [format & COGL_UNORDERED_MASK];
64
_cogl_bitmap_convert_and_premult (const CoglBitmap *bmp,
66
CoglPixelFormat dst_format)
68
CoglBitmap tmp_bmp = *bmp;
69
CoglBitmap new_bmp = *bmp;
70
gboolean new_bmp_owner = FALSE;
72
/* Is base format different (not considering premult status)? */
73
if ((bmp->format & COGL_UNPREMULT_MASK) !=
74
(dst_format & COGL_UNPREMULT_MASK))
76
/* Try converting using imaging library */
77
if (!_cogl_bitmap_convert (&new_bmp, &tmp_bmp, dst_format))
79
/* ... or try fallback */
80
if (!_cogl_bitmap_fallback_convert (&new_bmp, &tmp_bmp, dst_format))
84
/* Update bitmap with new data */
89
/* Do we need to unpremultiply */
90
if ((bmp->format & COGL_PREMULT_BIT) > 0 &&
91
(dst_format & COGL_PREMULT_BIT) == 0)
93
/* Try unpremultiplying using imaging library */
94
if (!_cogl_bitmap_unpremult (&new_bmp, &tmp_bmp))
96
/* ... or try fallback */
97
if (!_cogl_bitmap_fallback_unpremult (&new_bmp, &tmp_bmp))
100
g_free (new_bmp.data);
106
/* Update bitmap with new data */
108
g_free (new_bmp.data);
111
new_bmp_owner = TRUE;
114
/* Do we need to premultiply */
115
if ((bmp->format & COGL_PREMULT_BIT) == 0 &&
116
(dst_format & COGL_PREMULT_BIT) > 0)
118
/* Try premultiplying using imaging library */
119
if (!_cogl_bitmap_premult (&new_bmp, &tmp_bmp))
121
/* ... or try fallback */
122
if (!_cogl_bitmap_fallback_premult (&new_bmp, &tmp_bmp))
125
g_free (new_bmp.data);
131
/* Update bitmap with new data */
133
g_free (new_bmp.data);
136
new_bmp_owner = TRUE;
139
/* Output new bitmap info */
146
_cogl_bitmap_copy_subregion (CoglBitmap *src,
160
/* Intended only for fast copies when format is equal! */
161
g_assert (src->format == dst->format);
162
bpp = _cogl_get_format_bpp (src->format);
164
srcdata = src->data + src_y * src->rowstride + src_x * bpp;
165
dstdata = dst->data + dst_y * dst->rowstride + dst_x * bpp;
167
for (line=0; line<height; ++line)
169
memcpy (dstdata, srcdata, width * bpp);
170
srcdata += src->rowstride;
171
dstdata += dst->rowstride;
176
cogl_bitmap_get_size_from_file (const gchar *filename,
180
return _cogl_bitmap_get_size_from_file (filename, width, height);
184
cogl_bitmap_new_from_file (const gchar *filename,
190
g_return_val_if_fail (error == NULL || *error == NULL, COGL_INVALID_HANDLE);
192
/* Try loading with imaging backend */
193
if (!_cogl_bitmap_from_file (&bmp, filename, error))
196
if (!_cogl_bitmap_fallback_from_file (&bmp, filename))
198
else if (error && *error)
200
g_error_free (*error);
205
ret = g_memdup (&bmp, sizeof (CoglBitmap));
206
return _cogl_bitmap_handle_new (ret);