fix logic
[personal-kdelibs.git] / khtml / imload / scaledimageplane.h
blob953c34c5131ac5d41affb15947e472c7ce430fbd
1 /*
2 Large image displaying library.
4 Copyright (C) 2004,2005 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.
24 #ifndef SCALED_IMAGE_PLANE_H
25 #define SCALED_IMAGE_PLANE_H
27 #include "array2d.h"
28 #include "imageplane.h"
29 #include "rawimageplane.h"
30 #include "imagetile.h"
32 namespace khtmlImLoad {
34 /**
35 A scaled image plane pulls data from a RawImagePlane and resizes it
37 class ScaledImagePlane: public ImagePlane
39 private:
40 RawImagePlane* parent;
41 Array2D<ImageTile> tiles;
44 unsigned int* calcScaleTable(unsigned int orig, unsigned int scaled)
46 if (scaled == 0)
47 return 0; // Don't need to compute origin for 0 pixels..
49 //### I bet this has all sorts of imprecision problems w/high ratios
50 unsigned int* origin = new unsigned int[scaled];
52 //### FIXME: replace with something that clamps on right edge later?
53 double ratio = double(orig)/double(scaled);
54 int intRatio = int(ratio*65536.0 + 1);
55 int pos = 0;
57 for (unsigned int pix = 0; pix < scaled; pix++)
59 origin[pix] = pos >> 16;
60 pos += intRatio;
63 return origin;
66 unsigned int* xScaleTable;
67 unsigned int* yScaleTable;
68 public:
69 virtual ~ScaledImagePlane();
71 virtual void flushCache();
73 ScaledImagePlane(unsigned int _width, unsigned int _height, RawImagePlane* _parent):
74 ImagePlane(_width, _height), parent(_parent), tiles(tilesWidth, tilesHeight)
76 //Create the mapping tables
77 yScaleTable = calcScaleTable(parent->height, height);
78 xScaleTable = calcScaleTable(parent->width , width );
82 virtual bool isUpToDate(unsigned int tileX, unsigned int tileY,
83 PixmapTile* tile);
85 virtual void ensureUpToDate(unsigned int tileX, unsigned int tileY,
86 PixmapTile* tile);
91 #endif
92 // kate: indent-width 4; replace-tabs on; tab-width 4; space-indent on;