1/*
2 Large image displaying library.
3
4 Copyright (C) 2004 Maks Orlovich (maksim@kde.org)
5
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to deal
8 in the Software without restriction, including without limitation the rights
9 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
20 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
23*/
24
25#ifndef IMAGE_MANAGER_H
26#define IMAGE_MANAGER_H
27
28#include "animtimer.h"
29#include "loaderdatabase.h"
30#include "tilecache.h"
31#include "updater.h"
32
33class QPixmap;
34
35namespace khtmlImLoad
36{
37
38class ImageManager
39{
40private:
41 static AnimTimer *anmTimer;
42 static TileCache *imgCache;
43 static TileCache *pixCache;
44 static LoaderDatabase *loaderDB;
45 static Updater *theUpdater;
46 static QPixmap *emptyPix;
47
48 static unsigned int pixmapCacheSize();
49 static unsigned int imageCacheSize();
50
51 static void initLoaders();
52public:
53 // IMPORTANT: Don't even think about changing these to signed; it's security-critical
54 // This method determines whether we'll ever accept an image so large
55 static bool isAcceptableSize(unsigned width, unsigned height);
56
57 // IMPORTANT: Don't even think about changing these to signed; it's security-critical
58 // Says whether the target size is OK to scale an image too. This is much
59 // bigger than the above, as we store the actual data in the tile cache, so
60 // we just need some control information, which is much smaller
61 static bool isAcceptableScaleSize(unsigned width, unsigned height);
62
63 static AnimTimer *animTimer()
64 {
65 if (!anmTimer) {
66 anmTimer = new AnimTimer();
67 }
68 return anmTimer;
69 }
70
71 static TileCache *imageCache()
72 {
73 if (!imgCache) {
74 imgCache = new TileCache(imageCacheSize());
75 }
76 return imgCache;
77 }
78
79 static TileCache *pixmapCache()
80 {
81 if (!pixCache) {
82 pixCache = new TileCache(pixmapCacheSize());
83 }
84 return pixCache;
85 }
86
87 static Updater *updater()
88 {
89 if (!theUpdater) {
90 theUpdater = new Updater();
91 }
92 return theUpdater;
93 }
94
95 static LoaderDatabase *loaderDatabase()
96 {
97 if (!loaderDB) {
98 loaderDB = new LoaderDatabase();
99 initLoaders(); //Register built-in decoders
100 }
101 return loaderDB;
102 }
103};
104
105}
106
107#endif
108