]> de.git.xonotic.org Git - xonotic/netradiant.git/blob - plugins/image/image.cpp
set eol-style
[xonotic/netradiant.git] / plugins / image / image.cpp
1 /*\r
2 Copyright (c) 2001, Loki software, inc.\r
3 All rights reserved.\r
4 \r
5 Redistribution and use in source and binary forms, with or without modification, \r
6 are permitted provided that the following conditions are met:\r
7 \r
8 Redistributions of source code must retain the above copyright notice, this list \r
9 of conditions and the following disclaimer.\r
10 \r
11 Redistributions in binary form must reproduce the above copyright notice, this\r
12 list of conditions and the following disclaimer in the documentation and/or\r
13 other materials provided with the distribution.\r
14 \r
15 Neither the name of Loki software nor the names of its contributors may be used \r
16 to endorse or promote products derived from this software without specific prior \r
17 written permission. \r
18 \r
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' \r
20 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE \r
21 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE \r
22 DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY \r
23 DIRECT,INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES \r
24 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; \r
25 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON \r
26 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT \r
27 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS \r
28 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \r
29 */\r
30 \r
31 //\r
32 // Image loading plugin\r
33 //\r
34 // Leonardo Zide (leo@lokigames.com)\r
35 //\r
36 \r
37 #include <stdio.h>\r
38 #include "image.h"\r
39 #include "lbmlib.h"\r
40 \r
41 // =============================================================================\r
42 // global tables\r
43 \r
44 _QERFuncTable_1 g_FuncTable; // Radiant function table\r
45 _QERFileSystemTable g_FileSystemTable;\r
46 \r
47 // =============================================================================\r
48 // SYNAPSE\r
49 \r
50 CSynapseServer* g_pSynapseServer = NULL;\r
51 CSynapseClientImage g_SynapseClient;\r
52 \r
53 static const XMLConfigEntry_t entries[] = \r
54   { \r
55     { VFS_MAJOR, SYN_REQUIRE, sizeof(g_FileSystemTable), &g_FileSystemTable },\r
56     { NULL, SYN_UNKNOWN, 0, NULL } };\r
57 \r
58 #if __GNUC__ >= 4\r
59 #pragma GCC visibility push(default)\r
60 #endif\r
61 extern "C" CSynapseClient* SYNAPSE_DLL_EXPORT Synapse_EnumerateInterfaces( const char *version, CSynapseServer *pServer ) {\r
62 #if __GNUC__ >= 4\r
63 #pragma GCC visibility pop\r
64 #endif\r
65   if (strcmp(version, SYNAPSE_VERSION))\r
66   {\r
67     Syn_Printf("ERROR: synapse API version mismatch: should be '" SYNAPSE_VERSION "', got '%s'\n", version);\r
68     return NULL;\r
69   }\r
70   g_pSynapseServer = pServer;\r
71   g_pSynapseServer->IncRef();\r
72   Set_Syn_Printf(g_pSynapseServer->Get_Syn_Printf());\r
73 \r
74   g_SynapseClient.AddAPI(IMAGE_MAJOR, "jpg", sizeof(_QERPlugImageTable));\r
75   g_SynapseClient.AddAPI(IMAGE_MAJOR, "tga", sizeof(_QERPlugImageTable));\r
76   // NOTE: these two are for md2 support\r
77   // instead of requesting them systematically, we could request them per-config before enabling Q2 support\r
78   g_SynapseClient.AddAPI(IMAGE_MAJOR, "pcx", sizeof(_QERPlugImageTable));\r
79   g_SynapseClient.AddAPI(IMAGE_MAJOR, "bmp", sizeof(_QERPlugImageTable));\r
80   g_SynapseClient.AddAPI(RADIANT_MAJOR, NULL, sizeof(_QERFuncTable_1), SYN_REQUIRE, &g_FuncTable);\r
81   \r
82   if ( !g_SynapseClient.ConfigXML( pServer, NULL, entries ) ) {\r
83     return NULL;\r
84   }\r
85   \r
86   return &g_SynapseClient;\r
87 }\r
88 \r
89 bool CSynapseClientImage::RequestAPI(APIDescriptor_t *pAPI)\r
90 {\r
91   if (!strcmp(pAPI->major_name, "image"))\r
92   {    \r
93     _QERPlugImageTable* pTable= static_cast<_QERPlugImageTable*>(pAPI->mpTable);\r
94     if (!strcmp(pAPI->minor_name, "jpg"))\r
95     {      \r
96       pTable->m_pfnLoadImage = &LoadJPG;\r
97       return true;\r
98     }\r
99     if (!strcmp(pAPI->minor_name, "tga"))\r
100     {\r
101       pTable->m_pfnLoadImage = &LoadImage;\r
102       return true;\r
103     }\r
104     if (!strcmp(pAPI->minor_name, "pcx"))\r
105     {\r
106       pTable->m_pfnLoadImage = &LoadImage;\r
107       return true;\r
108     }\r
109     if (!strcmp(pAPI->minor_name, "bmp"))\r
110     {\r
111       pTable->m_pfnLoadImage = &LoadImage;\r
112       return true;\r
113     }\r
114   }\r
115 \r
116   Syn_Printf("ERROR: RequestAPI( '%s' ) not found in '%s'\n", pAPI->major_name, GetInfo());\r
117   return false;\r
118 }\r
119 \r
120 bool CSynapseClientImage::OnActivate() {\r
121   if (!g_FileSystemTable.m_nSize) {\r
122     Syn_Printf("ERROR: VFS_MAJOR table was not initialized before OnActivate in '%s' - incomplete synapse.config?\n", GetInfo());\r
123     return false;\r
124   }\r
125   return true;\r
126 }\r
127 \r
128 #include "version.h"\r
129 \r
130 const char* CSynapseClientImage::GetInfo()\r
131 {\r
132   return "image formats JPG TGA PCX BMP module built " __DATE__ " " RADIANT_VERSION;\r
133 }\r