KHtml

imagemanager.cpp
1 /*
2  Large image displaying library.
3 
4  Copyright (C) 2004 Maks Orlovich ([email protected])
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 #include "imagemanager.h"
26 #include "decoders/jpegloader.h"
27 #include "decoders/pngloader.h"
28 #include "decoders/gifloader.h"
29 #include "decoders/qimageioloader.h"
30 
31 namespace khtmlImLoad
32 {
33 
34 TileCache *ImageManager::imgCache = nullptr;
35 TileCache *ImageManager::pixCache = nullptr;
36 Updater *ImageManager::theUpdater = nullptr;
37 LoaderDatabase *ImageManager::loaderDB = nullptr;
38 QPixmap *ImageManager::emptyPix = nullptr;
39 AnimTimer *ImageManager::anmTimer = nullptr;
40 
41 //Each tile is 64x64 pixels, so normally
42 //64x64x4 = 16K, so 1 megabyte = 64 tiles, roughly.
43 //I'll probably switch to more precize accounting eventually
44 
45 //### any way of detecting memory size?
46 
47 unsigned int ImageManager::imageCacheSize()
48 {
49  return 64 * 32;
50 }
51 
52 unsigned int ImageManager::pixmapCacheSize()
53 {
54  return 64 * 64;
55 }
56 
57 void ImageManager::initLoaders()
58 {
59  loaderDB->registerLoaderProvider(new JPEGLoaderProvider);
60  loaderDB->registerLoaderProvider(new PNGLoaderProvider);
61  loaderDB->registerLoaderProvider(new GIFLoaderProvider);
62  loaderDB->registerLoaderProvider(new QImageIOLoaderProvider);
63 }
64 
65 bool ImageManager::isAcceptableSize(unsigned width, unsigned height)
66 {
67  // See the comment below if trying to change these!
68  if (width > 16384 || height > 16384) {
69  return false;
70  }
71 
72  unsigned pixels = width * height; //Cannot overflow due to the above -- 16K by 16K is 256K...
73 
74  if (pixels > 6000 * 4000) {
75  return false;
76  }
77 
78  return true;
79 }
80 
81 bool ImageManager::isAcceptableScaleSize(unsigned width, unsigned height)
82 {
83  if (width > 32768 || height > 32768) {
84  return false;
85  }
86 
87  // At this point, we have at most 512x512 tiles, each 3 pointers bigs,
88  // which is 3.1 meg on 32-bit, 6.2 meg on 64-bit.
89  // The scaling tables are at most 256KiB each. So this is all reasonable,
90  // even too reasonable.
91  return true;
92 }
93 
94 }
95 
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Tue Oct 26 2021 22:48:03 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.