KHtml

canvasimage.cpp
1 /*
2  KHTML image displaying library.
3 
4  Copyright (C) 2007 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 "canvasimage.h"
25 #include "imageowner.h"
26 #include "pixmapplane.h"
27 #include "rawimageplane.h"
28 #include "scaledimageplane.h"
29 
30 namespace khtmlImLoad
31 {
32 
33 class TrivialImageOwner : public ImageOwner
34 {
35 public:
36  void imageHasGeometry(Image *, int, int) override {}
37  void imageChange(Image *, QRect) override {}
38  void imageError(Image *) override {};
39  void imageDone(Image *) override {};
40 };
41 
42 ImageOwner *CanvasImage::s_trivialOwner = nullptr;
43 
44 ImageOwner *CanvasImage::trivialOwner()
45 {
46  if (!s_trivialOwner) {
47  s_trivialOwner = new TrivialImageOwner;
48  }
49  return s_trivialOwner;
50 }
51 
52 void CanvasImage::setupOriginalPlane(int width, int height)
53 {
54  fullyDecoded = true;
55  this->width = width;
56  this->height = height;
57 
58  RawImagePlane *imgPlane = new RawImagePlane(width, height, 1 /*already "loaded"*/);
59  imgPlane->format.type = ImageFormat::Image_ARGB_32;
60  imgPlane->image = QImage(width, height, QImage::Format_ARGB32_Premultiplied);
61  original = new PixmapPlane(width, height, imgPlane);
62 
63 }
64 
65 CanvasImage::CanvasImage(int width, int height): Image(trivialOwner())
66 {
67  setupOriginalPlane(width, height);
68 }
69 
70 void CanvasImage::contentUpdated()
71 {
72  flushAllCaches();
73 }
74 
75 void CanvasImage::flushAllCaches()
76 {
77  // Flush all the planes, including any scaled ones, etc.
78  original->flushCache();
79 
80  for (QMap<QPair<int, int>, PixmapPlane *>::iterator i = scaled.begin(); i != scaled.end(); ++i) {
81  i.value()->flushCache();
82  }
83 }
84 
85 void CanvasImage::resizeImage(int width, int height)
86 {
87  // Dump any cached info, it's useless
88  flushAllCaches();
89 
90  // Create a new master pixmap and raw image planes
91  delete original;
92  setupOriginalPlane(width, height);
93  RawImagePlane *imgPlane = static_cast<RawImagePlane *>(original->parent);
94 
95  // Now go through the scaling cache, and fix things up.
96  for (QMap<QPair<int, int>, PixmapPlane *>::iterator i = scaled.begin(); i != scaled.end(); ++i) {
97  PixmapPlane *scaledPix = i.value();
98  delete scaledPix->parent;
99  scaledPix->parent = new ScaledImagePlane(scaledPix->width, scaledPix->height, imgPlane);
100  }
101 }
102 
103 }
104 
Format_ARGB32_Premultiplied
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jul 13 2020 22:45:53 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.