KallistiOS git master
Independent SDK for the Sega Dreamcast
Loading...
Searching...
No Matches
img.h
Go to the documentation of this file.
1/* KallistiOS ##version##
2
3 kos/img.h
4 Copyright (C) 2002 Megan Potter
5
6*/
7
8#ifndef __KOS_IMG_H
9#define __KOS_IMG_H
10
11/** \file kos/img.h
12 \brief Platform-independent image type.
13 \ingroup video_img
14
15 This file provides a platform-independent image type that is designed to
16 hold any sort of textures or other image data. This type contains a very
17 basic description of the image data (width, height, pixel format), as well
18 as the image data itself.
19
20 All of the image-loading libraries in kos-ports should provide a function
21 to load the image data into one of these types.
22
23 \author Megan Potter
24*/
25
26#include <sys/cdefs.h>
27__BEGIN_DECLS
28
29#include <arch/types.h>
30
31/** \defgroup video_img Images
32 \brief Platform-independent image representation
33 \ingroup video
34*/
35
36/** \brief Platform-indpendent image type.
37 \ingroup video_img
38
39 You can use this type for textures or whatever you feel it's appropriate
40 for. "width" and "height" are as you would expect. "format" has a lower-half
41 which is platform-independent and used to basically describe the contained
42 data; the upper-half is platform-dependent and can hold anything (so AND it
43 off if you only want the bottom part).
44
45 Note that in some of the more obscure formats (like the paletted formats)
46 the data interpretation may be platform dependent. Thus we also provide a
47 data length field.
48
49 \headerfile kos/img.h
50*/
51typedef struct kos_img {
52 void *data; /**< \brief Image data in the specified format. */
53 uint32 w; /**< \brief Width of the image. */
54 uint32 h; /**< \brief Height of the image. */
55 uint32 fmt; /**< \brief Format of the image data.
56 \see kos_img_fmts
57 \see kos_img_fmt_macros */
58 uint32 byte_count; /**< \brief Length of the image data, in bytes. */
59} kos_img_t;
60
61/** \defgroup video_img_fmt Format
62 \brief Video image formats
63 \ingroup video_img
64*/
65
66/** \defgroup kos_img_fmt_macros Accessors
67 \brief Macros for accessing kos_image_t::fmt
68 \ingroup video_img_fmt
69
70 These macros provide easy access to the fmt field of a kos_img_t object.
71
72 @{
73*/
74/** \brief Read the platform-independent half of the format.
75
76 This macro masks the format of a kos_img_t to give you just the lower half
77 of the value, which contains the platform-independent half of the format.
78
79 \param x An image format (fmt field of a kos_img_t).
80
81 \return The platform-independent half of the format.
82*/
83#define KOS_IMG_FMT_I(x) ((x) & 0xffff)
84
85/** \brief Read the platform-specific half of the format.
86
87 This macro masks the format of a kos_img_t to give you just the upper half
88 of the value, which contains the platform-specific half of the format.
89
90 \param x An image format (fmt field of a kos_img_t).
91
92 \return The platform-specific half of the format.
93*/
94#define KOS_IMG_FMT_D(x) (((x) >> 16) & 0xffff)
95
96/** \brief Build a format value from a platform-independent half and a
97 platform-specific half of the value.
98
99 This macro combines the platform-independent and platform-specific portions
100 of an image format into a value suitable for storing as the fmt field of a
101 kos_img_t object.
102
103 \param i The platform-independent half of the format.
104 \param d The platform-specific half of the format. This should
105 not be pre-shifted.
106
107 \return A complete image format value, suitable for placing in
108 the fmt variable of a kos_img_t.
109*/
110#define KOS_IMG_FMT(i, d) ( ((i) & 0xffff) | (((d) & 0xffff) << 16) )
111
112/** @} */
113
114/** \defgroup kos_img_fmts Types
115 \brief Video image format types
116 \ingroup video_img_fmt
117
118 This is the list of platform-independent image types that can be used as the
119 lower-half of the fmt value for a kos_img_t.
120
121 @{
122*/
123/** \brief Undefined or uninitialized format. */
124#define KOS_IMG_FMT_NONE 0x00
125
126/** \brief 24-bpp interleaved R/G/B bytes. */
127#define KOS_IMG_FMT_RGB888 0x01
128
129/** \brief 32-bpp interleaved A/R/G/B bytes. */
130#define KOS_IMG_FMT_ARGB8888 0x02
131
132/** \brief 16-bpp interleaved R (5 bits), G (6 bits), B (5 bits). */
133#define KOS_IMG_FMT_RGB565 0x03
134
135/** \brief 16-bpp interleaved A/R/G/B (4 bits each). */
136#define KOS_IMG_FMT_ARGB4444 0x04
137
138/** \brief 16-bpp interleaved A (1 bit), R (5 bits), G (5 bits), B (5 bits).
139 \note This can also be used for RGB555 (with the top bit ignored). */
140#define KOS_IMG_FMT_ARGB1555 0x05
141
142/** \brief Paletted, 4 bits per pixel (16 colors). */
143#define KOS_IMG_FMT_PAL4BPP 0x06
144
145/** \brief Paletted, 8 bits per pixel (256 colors). */
146#define KOS_IMG_FMT_PAL8BPP 0x07
147
148/** \brief 8-bit Y (4 bits), U (2 bits), V (2 bits). */
149#define KOS_IMG_FMT_YUV422 0x08
150
151/** \brief 15-bpp interleaved B (5 bits), G (6 bits), R (5 bits). */
152#define KOS_IMG_FMT_BGR565 0x09
153
154/** \brief 32-bpp interleaved R/G/B/A bytes. */
155#define KOS_IMG_FMT_RGBA8888 0x10
156
157/** \brief Basic format mask (not an actual format value). */
158#define KOS_IMG_FMT_MASK 0xff
159
160/** \brief X axis of image data is inverted (stored right to left). */
161#define KOS_IMG_INVERTED_X 0x0100
162
163/** \brief Y axis of image data is inverted (stored bottom to top). */
164#define KOS_IMG_INVERTED_Y 0x0200
165
166/** \brief The image is not the owner of the image data buffer.
167
168 This generally implies that the image data is stored in ROM and thus cannot
169 be freed.
170*/
171#define KOS_IMG_NOT_OWNER 0x0400
172
173/** @} */
174
175/** \brief Free a kos_img_t object.
176 \ingroup video_img
177
178 This function frees the data in a kos_img_t object, returning any memory to
179 the heap as appropriate. Optionally, this can also free the object itself,
180 if required.
181
182 \param img The image object to free.
183 \param struct_also Set to non-zero to free the image object itself,
184 as well as any data contained therein.
185*/
186void kos_img_free(kos_img_t *img, int struct_also);
187
188__END_DECLS
189
190#endif /* __KOS_IMG_H */
191
unsigned long uint32
32-bit unsigned integer
Definition types.h:33
void kos_img_free(kos_img_t *img, int struct_also)
Free a kos_img_t object.
Platform-indpendent image type.
Definition img.h:51
void * data
Image data in the specified format.
Definition img.h:52
uint32 fmt
Format of the image data.
Definition img.h:55
uint32 w
Width of the image.
Definition img.h:53
uint32 byte_count
Length of the image data, in bytes.
Definition img.h:58
uint32 h
Height of the image.
Definition img.h:54
Common integer types.