1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
3 * ***** BEGIN LICENSE BLOCK *****
4 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6 * The contents of this file are subject to the Mozilla Public License Version
7 * 1.1 (the "License"); you may not use this file except in compliance with
8 * the License. You may obtain a copy of the License at
9 * http://www.mozilla.org/MPL/
11 * Software distributed under the License is distributed on an "AS IS" basis,
12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 * for the specific language governing rights and limitations under the
16 * The Original Code is mozilla.org code.
18 * The Initial Developer of the Original Code is
19 * Netscape Communications Corporation.
20 * Portions created by the Initial Developer are Copyright (C) 2001
21 * the Initial Developer. All Rights Reserved.
24 * Stuart Parmenter <pavlov@netscape.com>
26 * Alternatively, the contents of this file may be used under the terms of
27 * either the GNU General Public License Version 2 or later (the "GPL"), or
28 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 * in which case the provisions of the GPL or the LGPL are applicable instead
30 * of those above. If you wish to allow use of your version of this file only
31 * under the terms of either the GPL or the LGPL, and not to allow others to
32 * use your version of this file under the terms of the MPL, indicate your
33 * decision by deleting the provisions above and replace them with the notice
34 * and other provisions required by the GPL or the LGPL. If you do not delete
35 * the provisions above, a recipient may use your version of this file under
36 * the terms of any one of the MPL, the GPL or the LGPL.
38 * ***** END LICENSE BLOCK ***** */
40 #include "nsImgBuildDefines.h"
43 #define IMG_BUILD_gif 1
44 #define IMG_BUILD_bmp 1
45 #define IMG_BUILD_png 1
46 #define IMG_BUILD_jpeg 1
47 #define IMG_BUILD_xbm 1
50 #include "nsIGenericFactory.h"
51 #include "nsIModule.h"
52 #include "nsICategoryManager.h"
53 #include "nsXPCOMCID.h"
54 #include "nsServiceManagerUtils.h"
56 #include "imgContainer.h"
57 #include "imgLoader.h"
58 #include "imgRequest.h"
59 #include "imgRequestProxy.h"
62 #ifdef IMG_BUILD_DECODER_gif
64 #include "nsGIFDecoder2.h"
67 #ifdef IMG_BUILD_DECODER_bmp
69 #include "nsBMPDecoder.h"
70 #include "nsICODecoder.h"
73 #ifdef IMG_BUILD_DECODER_png
75 #include "nsPNGDecoder.h"
78 #ifdef IMG_BUILD_DECODER_jpeg
80 #include "nsJPEGDecoder.h"
83 #ifdef IMG_BUILD_DECODER_xbm
85 #include "nsXBMDecoder.h"
89 #ifdef IMG_BUILD_ENCODER_png
91 #include "nsPNGEncoder.h"
93 #ifdef IMG_BUILD_ENCODER_jpeg
95 #include "nsJPEGEncoder.h"
99 // objects that just require generic constructors
101 NS_GENERIC_FACTORY_CONSTRUCTOR(imgContainer
)
102 NS_GENERIC_FACTORY_CONSTRUCTOR(imgLoader
)
103 NS_GENERIC_FACTORY_CONSTRUCTOR(imgRequestProxy
)
104 NS_GENERIC_FACTORY_CONSTRUCTOR(imgTools
)
106 #ifdef IMG_BUILD_DECODER_gif
108 NS_GENERIC_FACTORY_CONSTRUCTOR(nsGIFDecoder2
)
111 #ifdef IMG_BUILD_DECODER_jpeg
113 NS_GENERIC_FACTORY_CONSTRUCTOR(nsJPEGDecoder
)
115 #ifdef IMG_BUILD_ENCODER_jpeg
117 NS_GENERIC_FACTORY_CONSTRUCTOR(nsJPEGEncoder
)
120 #ifdef IMG_BUILD_DECODER_bmp
122 NS_GENERIC_FACTORY_CONSTRUCTOR(nsICODecoder
)
123 NS_GENERIC_FACTORY_CONSTRUCTOR(nsBMPDecoder
)
126 #ifdef IMG_BUILD_DECODER_png
128 NS_GENERIC_FACTORY_CONSTRUCTOR(nsPNGDecoder
)
130 #ifdef IMG_BUILD_ENCODER_png
132 NS_GENERIC_FACTORY_CONSTRUCTOR(nsPNGEncoder
)
135 #ifdef IMG_BUILD_DECODER_xbm
137 NS_GENERIC_FACTORY_CONSTRUCTOR(nsXBMDecoder
)
140 static const char* gImageMimeTypes
[] = {
141 #ifdef IMG_BUILD_DECODER_gif
144 #ifdef IMG_BUILD_DECODER_jpeg
149 #ifdef IMG_BUILD_DECODER_bmp
151 "image/vnd.microsoft.icon",
155 #ifdef IMG_BUILD_DECODER_png
159 #ifdef IMG_BUILD_DECODER_xbm
166 static NS_METHOD
ImageRegisterProc(nsIComponentManager
*aCompMgr
,
168 const char *registryLocation
,
169 const char *componentType
,
170 const nsModuleComponentInfo
*info
) {
172 nsCOMPtr
<nsICategoryManager
> catMan(do_GetService(NS_CATEGORYMANAGER_CONTRACTID
, &rv
));
175 for (unsigned i
= 0; i
< sizeof(gImageMimeTypes
)/sizeof(*gImageMimeTypes
); i
++) {
176 catMan
->AddCategoryEntry("Gecko-Content-Viewers", gImageMimeTypes
[i
],
177 "@mozilla.org/content/document-loader-factory;1",
178 PR_TRUE
, PR_TRUE
, nsnull
);
181 catMan
->AddCategoryEntry("content-sniffing-services", "@mozilla.org/image/loader;1",
182 "@mozilla.org/image/loader;1", PR_TRUE
, PR_TRUE
,
187 static NS_METHOD
ImageUnregisterProc(nsIComponentManager
*aCompMgr
,
189 const char *registryLocation
,
190 const nsModuleComponentInfo
*info
) {
192 nsCOMPtr
<nsICategoryManager
> catMan(do_GetService(NS_CATEGORYMANAGER_CONTRACTID
, &rv
));
195 for (unsigned i
= 0; i
< sizeof(gImageMimeTypes
)/sizeof(*gImageMimeTypes
); i
++)
196 catMan
->DeleteCategoryEntry("Gecko-Content-Viewers", gImageMimeTypes
[i
], PR_TRUE
);
201 static const nsModuleComponentInfo components
[] =
205 "@mozilla.org/image/cache;1",
206 imgLoaderConstructor
, },
209 "@mozilla.org/image/container;1",
210 imgContainerConstructor
, },
213 "@mozilla.org/image/loader;1",
214 imgLoaderConstructor
,
215 ImageRegisterProc
, /* register the decoder mime types here */
216 ImageUnregisterProc
, },
217 { "image request proxy",
218 NS_IMGREQUESTPROXY_CID
,
219 "@mozilla.org/image/request;1",
220 imgRequestProxyConstructor
, },
223 "@mozilla.org/image/tools;1",
224 imgToolsConstructor
, },
226 #ifdef IMG_BUILD_DECODER_gif
230 "@mozilla.org/image/decoder;2?type=image/gif",
231 nsGIFDecoder2Constructor
, },
234 #ifdef IMG_BUILD_DECODER_jpeg
238 "@mozilla.org/image/decoder;2?type=image/jpeg",
239 nsJPEGDecoderConstructor
, },
242 "@mozilla.org/image/decoder;2?type=image/pjpeg",
243 nsJPEGDecoderConstructor
, },
246 "@mozilla.org/image/decoder;2?type=image/jpg",
247 nsJPEGDecoderConstructor
, },
249 #ifdef IMG_BUILD_ENCODER_jpeg
253 "@mozilla.org/image/encoder;2?type=image/jpeg",
254 nsJPEGEncoderConstructor
, },
257 #ifdef IMG_BUILD_DECODER_bmp
261 "@mozilla.org/image/decoder;2?type=image/x-icon",
262 nsICODecoderConstructor
, },
265 "@mozilla.org/image/decoder;2?type=image/vnd.microsoft.icon",
266 nsICODecoderConstructor
, },
269 "@mozilla.org/image/decoder;2?type=image/bmp",
270 nsBMPDecoderConstructor
, },
273 "@mozilla.org/image/decoder;2?type=image/x-ms-bmp",
274 nsBMPDecoderConstructor
, },
277 #ifdef IMG_BUILD_DECODER_png
281 "@mozilla.org/image/decoder;2?type=image/png",
282 nsPNGDecoderConstructor
, },
285 "@mozilla.org/image/decoder;2?type=image/x-png",
286 nsPNGDecoderConstructor
, },
288 #ifdef IMG_BUILD_ENCODER_png
292 "@mozilla.org/image/encoder;2?type=image/png",
293 nsPNGEncoderConstructor
, },
296 #ifdef IMG_BUILD_DECODER_xbm
300 "@mozilla.org/image/decoder;2?type=image/x-xbitmap",
301 nsXBMDecoderConstructor
, },
304 "@mozilla.org/image/decoder;2?type=image/x-xbm",
305 nsXBMDecoderConstructor
, },
308 "@mozilla.org/image/decoder;2?type=image/xbm",
309 nsXBMDecoderConstructor
, },
314 imglib_Initialize(nsIModule
* aSelf
)
316 imgLoader::InitCache();
321 imglib_Shutdown(nsIModule
* aSelf
)
323 imgLoader::Shutdown();
326 NS_IMPL_NSGETMODULE_WITH_CTOR_DTOR(nsImageLib2Module
, components
,
327 imglib_Initialize
, imglib_Shutdown
)