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 #include "scaledimageplane.h"
25 #include "imagemanager.h"
27 namespace khtmlImLoad
{
29 bool ScaledImagePlane::isUpToDate(unsigned int tileX
, unsigned int tileY
,
32 if (!tile
->pixmap
) return false;
34 for (unsigned int line
= 0; line
< tileHeight(tileY
); ++line
)
36 if (tile
->versions
[line
] < parent
->versions
[yScaleTable
[line
+ tileY
*Tile::TileSize
]])
44 static void scaleLoop(QImage
* dst
, unsigned int* xScaleTable
,
45 int line
, const QImage
& src
, int srcLine
, int tileX
, int tileY
)
47 const T
* srcPix
= reinterpret_cast<const T
*>(src
.scanLine (srcLine
));
48 T
* dstPix
= reinterpret_cast<T
*>(dst
->scanLine(line
));
50 xScaleTable
+= tileX
* Tile::TileSize
;
51 for (int x
= 0; x
< (int)dst
->width(); ++x
)
53 *dstPix
= srcPix
[xScaleTable
[x
]];
57 //### is special version for TileSize worth it?
59 void ScaledImagePlane::flushCache()
61 for (unsigned tileX
= 0; tileX
< tilesWidth
; ++tileX
) {
62 for (unsigned tileY
= 0; tileY
< tilesHeight
; ++tileY
) {
63 ImageTile
& imageTile
= tiles
.at(tileX
, tileY
);
64 if (!imageTile
.image
.isNull())
65 ImageManager::imageCache()->removeEntry(&imageTile
);
70 void ScaledImagePlane::ensureUpToDate(unsigned int tileX
, unsigned int tileY
,
73 ImageTile
& imageTile
= tiles
.at(tileX
, tileY
);
75 //Create the image if need be.
76 if (imageTile
.image
.isNull())
78 imageTile
.image
= parent
->format
.makeImage(tileWidth (tileX
),
80 ImageManager::imageCache()->addEntry(&imageTile
);
81 std::memset(imageTile
.versions
, 0, Tile::TileSize
);
83 else ImageManager::imageCache()->touchEntry(&imageTile
);
85 //Pull in updates to the image.
86 for (unsigned int line
= 0; line
< tileHeight(tileY
); ++line
)
88 int origLine
= yScaleTable
[line
+ tileY
*Tile::TileSize
];
89 if (imageTile
.versions
[line
] < parent
->versions
[origLine
])
91 imageTile
.versions
[line
] = parent
->versions
[origLine
];
92 if (parent
->format
.depth() == 1)
93 scaleLoop
<quint8
>(&imageTile
.image
, xScaleTable
, line
,
94 parent
->image
, origLine
, tileX
, tileY
);
96 scaleLoop
<quint32
>(&imageTile
.image
, xScaleTable
, line
,
97 parent
->image
, origLine
, tileX
, tileY
);
101 //Now, push stuff into the pixmap.
102 updatePixmap(tile
, imageTile
.image
, tileX
, tileY
, 0, 0, imageTile
.versions
);
105 ScaledImagePlane::~ScaledImagePlane()
107 delete[] xScaleTable
;
108 delete[] yScaleTable
;
114 // kate: indent-width 4; replace-tabs on; tab-width 4; space-indent on;