2 Large image displaying library.
4 Copyright (C) 2004 Maks Orlovich (maksim@kde.org)
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:
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
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.
26 #include "imagemanager.h"
27 #include "decoders/jpegloader.h"
28 #include "decoders/pngloader.h"
29 #include "decoders/gifloader.h"
31 namespace khtmlImLoad
{
33 TileCache
* ImageManager::imgCache
= 0;
34 TileCache
* ImageManager::pixCache
= 0;
35 Updater
* ImageManager::theUpdater
= 0;
36 LoaderDatabase
* ImageManager::loaderDB
= 0;
37 QPixmap
* ImageManager::emptyPix
= 0;
38 AnimTimer
* ImageManager::anmTimer
= 0;
40 //Each tile is 64x64 pixels, so normally
41 //64x64x4 = 16K, so 1 megabyte = 64 tiles, roughly.
42 //I'll probably switch to more precize accounting eventually
44 //### any way of detecting memory size?
46 unsigned int ImageManager::imageCacheSize()
51 unsigned int ImageManager::pixmapCacheSize()
56 void ImageManager::initLoaders()
58 loaderDB
->registerLoaderProvider(new JPEGLoaderProvider
);
59 loaderDB
->registerLoaderProvider(new PNGLoaderProvider
);
60 loaderDB
->registerLoaderProvider(new GIFLoaderProvider
);
63 bool ImageManager::isAcceptableSize(unsigned width
, unsigned height
)
65 // See the comment below if trying to change these!
66 if (width
> 16384 || height
> 16384)
69 unsigned pixels
= width
* height
; //Cannot overflow due to the above -- 16K by 16K is 256K...
71 if (pixels
> 6000 * 4000)
77 bool ImageManager::isAcceptableScaleSize(unsigned width
, unsigned height
)
79 if (width
> 32768 || height
> 32768)
82 // At this point, we have at most 512x512 tiles, each 3 pointers bigs,
83 // which is 3.1 meg on 32-bit, 6.2 meg on 64-bit.
84 // The scaling tables are at most 256KiB each. So this is all reasonable,
85 // even too reasonable.
91 // kate: indent-width 4; replace-tabs on; tab-width 4; space-indent on;