"Initial commit to Gerrit"
[profile/ivi/cogl.git] / cogl / cogl-bitmap-private.h
1 /*
2  * Clutter COGL
3  *
4  * A basic GL/GLES Abstraction/Utility Layer
5  *
6  * Authored By Matthew Allum  <mallum@openedhand.com>
7  *
8  * Copyright (C) 2007 OpenedHand
9  *
10  * This library is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Lesser General Public
12  * License as published by the Free Software Foundation; either
13  * version 2 of the License, or (at your option) any later version.
14  *
15  * This library is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18  * Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public
21  * License along with this library. If not, see <http://www.gnu.org/licenses/>.
22  *
23  *
24  */
25
26 #ifndef __COGL_BITMAP_H
27 #define __COGL_BITMAP_H
28
29 #include <glib.h>
30
31 #include "cogl-handle.h"
32 #include "cogl-buffer.h"
33 #include "cogl-bitmap.h"
34
35 /*
36  * _cogl_bitmap_new_with_malloc_buffer:
37  * @context: A #CoglContext
38  * @width: width of the bitmap in pixels
39  * @height: height of the bitmap in pixels
40  * @format: the format of the pixels the array will store
41  *
42  * This is equivalent to cogl_bitmap_new_with_size() except that it
43  * allocated the buffer using g_malloc() instead of creating a
44  * #CoglPixelBuffer. The buffer will be automatically destroyed when
45  * the bitmap is freed.
46  *
47  * Return value: a #CoglPixelBuffer representing the newly created array
48  *
49  * Since: 1.10
50  * Stability: Unstable
51  */
52 CoglBitmap *
53 _cogl_bitmap_new_with_malloc_buffer (CoglContext *context,
54                                      unsigned int width,
55                                      unsigned int height,
56                                      CoglPixelFormat format);
57
58 /* The idea of this function is that it will create a bitmap that
59    shares the actual data with another bitmap. This is needed for the
60    atlas texture backend because it needs upload a bitmap to a sub
61    texture but override the format so that it ignores the premult
62    flag. */
63 CoglBitmap *
64 _cogl_bitmap_new_shared (CoglBitmap      *shared_bmp,
65                          CoglPixelFormat  format,
66                          int              width,
67                          int              height,
68                          int              rowstride);
69
70 CoglBitmap *
71 _cogl_bitmap_convert (CoglBitmap *bmp,
72                       CoglPixelFormat   dst_format);
73
74 gboolean
75 _cogl_bitmap_convert_into_bitmap (CoglBitmap *src_bmp,
76                                   CoglBitmap *dst_bmp);
77
78 CoglBitmap *
79 _cogl_bitmap_from_file (const char *filename,
80                         GError     **error);
81
82 gboolean
83 _cogl_bitmap_unpremult (CoglBitmap *dst_bmp);
84
85 gboolean
86 _cogl_bitmap_premult (CoglBitmap *dst_bmp);
87
88 gboolean
89 _cogl_bitmap_convert_premult_status (CoglBitmap      *bmp,
90                                      CoglPixelFormat  dst_format);
91
92 gboolean
93 _cogl_bitmap_copy_subregion (CoglBitmap *src,
94                              CoglBitmap *dst,
95                              int         src_x,
96                              int         src_y,
97                              int         dst_x,
98                              int         dst_y,
99                              int         width,
100                              int         height);
101
102 /* Creates a deep copy of the source bitmap */
103 CoglBitmap *
104 _cogl_bitmap_copy (CoglBitmap *src_bmp);
105
106 gboolean
107 _cogl_bitmap_get_size_from_file (const char *filename,
108                                  int        *width,
109                                  int        *height);
110
111 void
112 _cogl_bitmap_set_format (CoglBitmap *bitmap,
113                          CoglPixelFormat format);
114
115 /* Maps the bitmap so that the pixels can be accessed directly or if
116    the bitmap is just a memory bitmap then it just returns the pointer
117    to memory. Note that the bitmap isn't guaranteed to allocated to
118    the full size of rowstride*height so it is not safe to read up to
119    the rowstride of the last row. This will be the case if the user
120    uploads data using gdk_pixbuf_new_subpixbuf with a sub region
121    containing the last row of the pixbuf because in that case the
122    rowstride can be much larger than the width of the image */
123 guint8 *
124 _cogl_bitmap_map (CoglBitmap *bitmap,
125                   CoglBufferAccess access,
126                   CoglBufferMapHint hints);
127
128 void
129 _cogl_bitmap_unmap (CoglBitmap *bitmap);
130
131 /* These two are replacements for map and unmap that should used when
132    the pointer is going to be passed to GL for pixel packing or
133    unpacking. The address might not be valid for reading if the bitmap
134    was created with new_from_buffer but it will however be good to
135    pass to glTexImage2D for example. The access should be READ for
136    unpacking and WRITE for packing. It can not be both */
137 guint8 *
138 _cogl_bitmap_bind (CoglBitmap *bitmap,
139                    CoglBufferAccess access,
140                    CoglBufferMapHint hints);
141
142 void
143 _cogl_bitmap_unbind (CoglBitmap *bitmap);
144
145 #endif /* __COGL_BITMAP_H */