-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtexture_quicktime.c
executable file
·62 lines (51 loc) · 1.56 KB
/
texture_quicktime.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/* Load a texture from an image using OS X QuickTime framework.
* Not tested on little-endian yet.
*/
#include <Carbon/Carbon.h>
#include <QuickTime/Movies.h>
#include <QuickTime/QuickTimeComponents.h>
#include <OpenGL/GL.h>
#include "texture.h"
/* GL_UNSIGNED_INT_... is a hack to convert ARGB format into RGBA. The
* BGRA extension is supported on all Apple hardware, so we don't bother
* checking for it.
*/
#if TARGET_RT_BIG_ENDIAN
# define ARGB_FORMAT GL_BGRA
# define ARGB_TYPE GL_UNSIGNED_INT_8_8_8_8_REV
#elif TARGET_RT_LITTLE_ENDIAN
# define ARGB_FORMAT GL_BGRA
# define ARGB_TYPE GL_UNSIGNED_INT_8_8_8_8
#else
# error Target endianness not specified, please use Apple gcc.
#endif
GLuint texture_load(const char *filename)
{
FSSpec fss;
GraphicsImportComponent gi;
Rect rect;
GWorldPtr world;
int width;
int height;
int pitch;
unsigned char *buffer;
GLuint id;
NativePathNameToFSSpec(filename, &fss);
GetGraphicsImporterForFile(&fss, &gi);
GraphicsImportGetNaturalBounds(gi, &rect);
width = rect.right;
height = rect.bottom;
pitch = width * 4;
buffer = malloc(pitch * height);
QTNewGWorldFromPtr(&world, k32ARGBPixelFormat, &rect, NULL, NULL, 0,
buffer, pitch);
GraphicsImportSetGWorld(gi, world, NULL);
GraphicsImportDraw(gi);
DisposeGWorld(world);
CloseComponent(gi);
id = texture_load_data(buffer, width, height,
4, -pitch,
GL_RGBA, ARGB_FORMAT, ARGB_TYPE);
free(buffer);
return id;
}