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