This repository has been archived by the owner on Jul 18, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimage.cpp
79 lines (69 loc) · 2.6 KB
/
image.cpp
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
Contains functions for loading images andything else to do with images/textures.
Copyright James Russell 2010
AC_LoadTex() function based off of LazyFoo image loading function.
Design used with permission.
*/
//INCLUDES//
#include "image.h"
////////////////FUNCTIONS////////////////
//Load image unto SDL_Surface.//
//TexFilename is the filename. Type flag is the transparency type, like CC or Alpha.
//CC_R, CC_G, and CC_B is the color that is going to be transparent in colorkeyed textures.
//If you set the Alpha to 128, that's a special case for alpha and it will be faster blitting.
SDL_Surface *AC_LoadTex(const char *AC_TexFilename,Uint8 AC_TypeFlag,Uint8 CK_R,Uint8 CK_G,Uint8 CK_B,bool AC_RLE)
{
//Temp surfaces.
SDL_Surface *AC_TempSurface=NULL;
SDL_Surface *AC_FinalSurface=NULL;
//Load the image into the temp surface.
AC_TempSurface=IMG_Load(AC_TexFilename);
//If the image didn't load...
if(!AC_TempSurface)
{
//Say so and why.
printf("***Image not loaded: %s***\n",IMG_GetError());
//Return NULL
return NULL;
}
//Optimize the surface according to
// whatever the output is to be.
//If no trans was set...
if(AC_TypeFlag==AC_NONE)
{
//Convert the temp surface to the screen format. And that's it.
AC_FinalSurface=SDL_DisplayFormat(AC_TempSurface);
}
//Otherwise, if colorkey trans was set...
else if(AC_TypeFlag==AC_CK)
{
//Get the color key that was input at function call.
Uint32 AC_CKey=SDL_MapRGB(AC_TempSurface->format,CK_R,CK_G,CK_B);
//Then set the color key onto the temp surface.
//If RLEAccel is set...
if(AC_RLE==true)
{
//Then set the colorkey with RLE accelleration.
SDL_SetColorKey(AC_TempSurface,SDL_SRCCOLORKEY|SDL_RLEACCEL,AC_CKey);
}
//Otherwise, if RLEAccel was not set...
else
{
//Then set the colorkey without RLEAccel.
SDL_SetColorKey(AC_TempSurface,SDL_SRCCOLORKEY,AC_CKey);
}
//Then convert the temp surface into the final surface with format change.
AC_FinalSurface=SDL_DisplayFormat(AC_TempSurface);
}
//Otherwise, if alpha trans was set...
else if(AC_TypeFlag==AC_A)
{
//Convert the surface to the screen format with alpha functionality.
AC_FinalSurface=SDL_DisplayFormatAlpha(AC_TempSurface);
}
//Say you loaded the file.
printf("Loaded %s.\n",AC_TexFilename);
//Return the final optimized surface.
return AC_FinalSurface;
}
////////////////EOF////////////////////