File indexing completed on 2024-05-19 15:12:18

0001 /*
0002     Large image displaying library.
0003 
0004     Copyright (C) 2004 Maks Orlovich (maksim@kde.org)
0005 
0006     Permission is hereby granted, free of charge, to any person obtaining a copy
0007     of this software and associated documentation files (the "Software"), to deal
0008     in the Software without restriction, including without limitation the rights
0009     to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
0010     copies of the Software, and to permit persons to whom the Software is
0011     furnished to do so, subject to the following conditions:
0012 
0013     The above copyright notice and this permission notice shall be included in
0014     all copies or substantial portions of the Software.
0015 
0016     THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
0017     IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0018     FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
0019     AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
0020     AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
0021     CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
0022 
0023 */
0024 
0025 #include "imagemanager.h"
0026 #include "decoders/jpegloader.h"
0027 #include "decoders/pngloader.h"
0028 #include "decoders/gifloader.h"
0029 #include "decoders/qimageioloader.h"
0030 
0031 namespace khtmlImLoad
0032 {
0033 
0034 TileCache      *ImageManager::imgCache   = nullptr;
0035 TileCache      *ImageManager::pixCache   = nullptr;
0036 Updater        *ImageManager::theUpdater = nullptr;
0037 LoaderDatabase *ImageManager::loaderDB   = nullptr;
0038 QPixmap        *ImageManager::emptyPix   = nullptr;
0039 AnimTimer      *ImageManager::anmTimer   = nullptr;
0040 
0041 //Each tile is 64x64 pixels, so normally
0042 //64x64x4 = 16K, so 1 megabyte = 64 tiles, roughly.
0043 //I'll probably switch to more precize accounting eventually
0044 
0045 //### any way of detecting memory size?
0046 
0047 unsigned int ImageManager::imageCacheSize()
0048 {
0049     return 64 * 32;
0050 }
0051 
0052 unsigned int ImageManager::pixmapCacheSize()
0053 {
0054     return 64 * 64;
0055 }
0056 
0057 void ImageManager::initLoaders()
0058 {
0059     loaderDB->registerLoaderProvider(new JPEGLoaderProvider);
0060     loaderDB->registerLoaderProvider(new PNGLoaderProvider);
0061     loaderDB->registerLoaderProvider(new GIFLoaderProvider);
0062     loaderDB->registerLoaderProvider(new QImageIOLoaderProvider);
0063 }
0064 
0065 bool ImageManager::isAcceptableSize(unsigned width, unsigned height)
0066 {
0067     // See the comment below if trying to change these!
0068     if (width > 16384 || height > 16384) {
0069         return false;
0070     }
0071 
0072     unsigned pixels = width * height; //Cannot overflow due to the above -- 16K by 16K is 256K...
0073 
0074     if (pixels > 6000 * 4000) {
0075         return false;
0076     }
0077 
0078     return true;
0079 }
0080 
0081 bool ImageManager::isAcceptableScaleSize(unsigned width, unsigned height)
0082 {
0083     if (width > 32768 || height > 32768) {
0084         return false;
0085     }
0086 
0087     // At this point, we have at most 512x512 tiles, each 3 pointers bigs,
0088     // which is 3.1 meg on 32-bit, 6.2 meg on 64-bit.
0089     // The scaling tables are at most 256KiB each. So this is all reasonable,
0090     // even too reasonable.
0091     return true;
0092 }
0093 
0094 }
0095