1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  */
22 
23 #include "ags/engine/ac/global_dynamic_sprite.h"
24 #include "ags/engine/ac/draw.h"
25 #include "ags/engine/ac/dynamic_sprite.h"
26 #include "ags/engine/ac/path_helper.h"
27 #include "ags/shared/ac/sprite_cache.h"
28 #include "ags/engine/gfx/graphics_driver.h"
29 #include "ags/shared/gfx/bitmap.h"
30 #include "ags/globals.h"
31 
32 namespace AGS3 {
33 
34 using namespace AGS::Shared;
35 using namespace AGS::Engine;
36 
LoadImageFile(const char * filename)37 int LoadImageFile(const char *filename) {
38 	ResolvedPath rp;
39 	if (!ResolveScriptPath(filename, true, rp))
40 		return 0;
41 
42 	Bitmap *loadedFile = BitmapHelper::LoadFromFile(rp.FullPath);
43 	if (!loadedFile && !rp.AltPath.IsEmpty() && rp.AltPath.Compare(rp.FullPath) != 0)
44 		loadedFile = BitmapHelper::LoadFromFile(rp.AltPath);
45 	if (!loadedFile)
46 		return 0;
47 
48 	int gotSlot = _GP(spriteset).GetFreeIndex();
49 	if (gotSlot <= 0)
50 		return 0;
51 
52 	add_dynamic_sprite(gotSlot, ReplaceBitmapWithSupportedFormat(loadedFile));
53 
54 	return gotSlot;
55 }
56 
57 } // namespace AGS3
58