KHtml

imageplane.cpp
1 /*
2  Large image displaying library.
3 
4  Copyright (C) 2005 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 #include "imageplane.h"
25 #include "imagemanager.h"
26 #include <cstring>
27 
28 #include <QPainter>
29 
30 namespace khtmlImLoad
31 {
32 
33 bool ImagePlane::checkUpToDate(const unsigned char *versions, PixmapTile *tile)
34 {
35  //If the tile is discarded, it's clearly not up-to-date ;-)
36  if (!tile->pixmap) {
37  return false;
38  }
39 
40  //Now, just check the version array. It's enough to memcmp,
41  //since we init all to zero, and assume the pixmap plains don't
42  //magically figure out the image before the loader.
43  return std::memcmp(versions, tile->versions, Tile::TileSize) == 0;
44 }
45 
46 void ImagePlane::setupTile(unsigned int tileX, unsigned int tileY, PixmapTile *tile)
47 {
48  tile->pixmap = new QPixmap(tileWidth(tileX), tileHeight(tileY));
49  ImageManager::pixmapCache()->addEntry(tile);
50 }
51 
52 void ImagePlane::updatePixmap(PixmapTile *tile, const QImage &image,
53  unsigned int tileX, unsigned int tileY,
54  unsigned int offX, unsigned int offY,
55  unsigned char *versions)
56 {
57  //Determine the range which needs pushing.
58  int first = 0xFFFF, last = 0;
59  if (!tile->pixmap) {
60  //### this can be wasteful if we do conversion
61  setupTile(tileX, tileY, tile);
62  first = 0;
63  last = tileHeight(tileY) - 1;
64  } else {
65  ImageManager::pixmapCache()->touchEntry(tile);
66 
67  // figure out the dirty range
68  for (unsigned int line = 0; line < tileHeight(tileY); ++line) {
69  if (versions[line] > tile->versions[line]) {
70  last = line;
71  if (first == 0xFFFF) {
72  first = line;
73  }
74  }
75  }
76  }
77 
78  // Now tile will be up-to-date, so sync up w/our versions array
79  std::memcpy(tile->versions, versions, Tile::TileSize);
80 
81  assert(tile->pixmap);
82 
83  //Special case, hopefully-fast path: if we just wants to push
84  //the whole image to the whole tile, do convertFromImage directly.
85  if (offX == 0 && offY == 0 && first == 0 && last == image.height() - 1 &&
86  tile->pixmap->width() == image.width() &&
87  tile->pixmap->height() == image.height()) {
88  tile->discard();
89  tile->pixmap = new QPixmap(QPixmap::fromImage(image));
90  } else {
91  if (image.hasAlphaChannel()) {
92  //### When supported, use the src op.
93  QRect imagePortion(offX, offY,
94  tile->pixmap->width(),
95  tile->pixmap->height());
96 
97  //Note: we're copying the entire tile-size here,
98  //and not just the dirty portion.
99  QImage portion = image.copy(imagePortion);
100  tile->pixmap->fill(Qt::transparent);
101  QPainter p(tile->pixmap);
102  p.drawImage(0, 0, portion);
103  } else {
104  QRect imagePortion(offX, offY + first,
105  tile->pixmap->width(), last - first + 1);
106 
107  QImage portion = image.copy(imagePortion);
108  //Push the image portion update
109  QPainter p(tile->pixmap);
110  p.drawImage(QPoint(0, first), portion);
111  }
112  }
113 }
114 
115 ImagePlane::~ImagePlane()
116 {}
117 
118 }
bool hasAlphaChannel() const const
QPixmap fromImage(const QImage &image, Qt::ImageConversionFlags flags)
void updatePixmap(PixmapTile *tile, const QImage &image, unsigned int tileX, unsigned int tileY, unsigned int offX, unsigned int offY, unsigned char *versions)
Update the pixmap using the appropriate image, starting from offset (offX, offY), and the matching ve...
Definition: imageplane.cpp:52
QImage copy(const QRect &rectangle) const const
void setupTile(unsigned int tileX, unsigned int tileY, PixmapTile *tile)
Creates the pixmap in the tile.
Definition: imageplane.cpp:46
void fill(uint pixelValue)
int width() const const
bool checkUpToDate(const unsigned char *versions, PixmapTile *tile)
Checks whether the tile is up-to-date for a given version array.
Definition: imageplane.cpp:33
void drawImage(const QRectF &target, const QImage &image, const QRectF &source, Qt::ImageConversionFlags flags)
int height() const const
transparent
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sun Oct 24 2021 22:48:03 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.