Merge pull request #5315 from Beep6581/rtsurface-cleanup

Rtsurface cleanup
This commit is contained in:
Floessie
2019-07-09 13:02:46 +02:00
committed by GitHub
9 changed files with 124 additions and 107 deletions

View File

@@ -18,9 +18,11 @@
*/
#include "pipettebuffer.h"
#include "../rtgui/editcallbacks.h"
#include "imagefloat.h"
#include "../rtgui/editcallbacks.h"
namespace rtengine
{

View File

@@ -16,13 +16,16 @@
* You should have received a copy of the GNU General Public License
* along with RawTherapee. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _PIPETTEBUFFER_H_
#define _PIPETTEBUFFER_H_
#pragma once
#include "../rtgui/editbuffer.h"
#include "array2D.h"
#include "iimage.h"
#include "coord.h"
#include "iimage.h"
class EditDataProvider;
class EditSubscriber;
enum EditUniqueID : int;
namespace rtengine
{
@@ -90,9 +93,7 @@ public:
bool bufferCreated();
// get the pipette values
void getPipetteData(int x, int y, const int squareSize);
void getPipetteData(int x, int y, int squareSize);
};
}
#endif

View File

@@ -21,7 +21,7 @@
/// @brief List of pipette editing operation
enum EditUniqueID {
enum EditUniqueID : int {
EUID_None, /// special value (default)
EUID_ToneCurve1,

View File

@@ -16,9 +16,15 @@
* You should have received a copy of the GNU General Public License
* along with RawTherapee. If not, see <http://www.gnu.org/licenses/>.
*/
#include <cstring>
#include <gdkmm/types.h>
#include "mydiagonalcurve.h"
#include "../rtengine/curves.h"
#include "editcallbacks.h"
#include "../rtengine/curves.h"
#include <cstring>
#include <gdkmm/types.h>

View File

@@ -16,12 +16,16 @@
* You should have received a copy of the GNU General Public License
* along with RawTherapee. If not, see <http://www.gnu.org/licenses/>.
*/
#include "myflatcurve.h"
#include "../rtengine/curves.h"
#include "editcallbacks.h"
#include <cstring>
#include <gdkmm/types.h>
#include "myflatcurve.h"
#include "editcallbacks.h"
#include "../rtengine/curves.h"
MyFlatCurve::MyFlatCurve () :
MyCurve(),
clampedX(0.0),

View File

@@ -19,66 +19,110 @@
#include <iostream>
#include "options.h"
#include "rtsurface.h"
#include "options.h"
namespace
{
std::map<std::string, Cairo::RefPtr<Cairo::ImageSurface>> surfaceCache;
using SurfaceCache = std::map<std::string, Cairo::RefPtr<Cairo::ImageSurface>>;
SurfaceCache surfaceCache;
}
double RTSurface::dpiBack = 0.;
int RTSurface::scaleBack = 0;
RTSurface::RTSurface () : RTScalable()
RTSurface::RTSurface() :
surface(new Cairo::ImageSurface(nullptr, false))
{
Cairo::RefPtr<Cairo::ImageSurface> imgSurf(new Cairo::ImageSurface(nullptr, false));
surface = imgSurf;
}
RTSurface::RTSurface(const RTSurface& other) : RTScalable()
RTSurface::RTSurface(const Glib::ustring& fileName, const Glib::ustring& rtlFileName) :
RTSurface()
{
surface = other.surface;
setImage(fileName, rtlFileName);
}
RTSurface::RTSurface (Glib::ustring fileName, Glib::ustring rtlFileName) : RTScalable()
void RTSurface::setImage(const Glib::ustring& fileName, const Glib::ustring& rtlFileName)
{
Cairo::RefPtr<Cairo::ImageSurface> imgSurf(new Cairo::ImageSurface(nullptr, false));
surface = imgSurf;
setImage (fileName, rtlFileName);
}
void RTSurface::setImage (Glib::ustring fileName, Glib::ustring rtlFileName)
{
Glib::ustring imageName;
if (!rtlFileName.empty() && getDirection() == Gtk::TEXT_DIR_RTL) {
imageName = rtlFileName;
} else {
imageName = fileName;
}
const Glib::ustring& imageName =
!rtlFileName.empty() && getDirection() == Gtk::TEXT_DIR_RTL
? rtlFileName
: fileName;
changeImage (imageName);
}
void RTSurface::setDPInScale (const double newDPI, const int newScale)
int RTSurface::getWidth() const
{
return
surface
? surface->get_width()
: -1;
}
int RTSurface::getHeight() const
{
return
surface
? surface->get_height()
: -1;
}
bool RTSurface::hasSurface() const
{
return static_cast<bool>(surface);
}
Cairo::RefPtr<const Cairo::ImageSurface> RTSurface::get() const
{
return surface;
}
const Cairo::RefPtr<Cairo::ImageSurface>& RTSurface::get()
{
return surface;
}
void RTSurface::init()
{
if (getScale() != newScale || (getScale() == 1 && getDPI() != newDPI)) {
RTScalable::setDPInScale(newDPI, newScale);
dpiBack = getDPI();
scaleBack = getScale();
//printf("RTSurface::setDPInScale : New scale = %d & new DPI = %.3f (%.3f asked) -> Reloading all RTSurface\n", scaleBack, dpiBack, newDPI);
}
void RTSurface::updateImages()
{
const double tweakedDpi = getTweakedDPI();
for (auto& entry : surfaceCache) {
entry.second = loadImage(entry.first, tweakedDpi);
}
}
void RTSurface::setDPInScale(const double newDPI, const int newScale)
{
if (
getScale() != newScale
|| (
getScale() == 1
&& getDPI() != newDPI
)
) {
setDPInScale(newDPI, newScale);
dpiBack = getDPI();
scaleBack = getScale();
updateImages();
}
}
void RTSurface::changeImage (Glib::ustring imageName)
void RTSurface::changeImage(const Glib::ustring& imageName)
{
auto iterator = surfaceCache.find (imageName);
const SurfaceCache::const_iterator iterator = surfaceCache.find(imageName);
if (iterator == surfaceCache.end ()) {
if (iterator != surfaceCache.end()) {
surface = iterator->second;
} else {
surface = loadImage(imageName, getTweakedDPI());
// HOMBRE: As of now, GDK_SCALE is forced to 1, so setting the Cairo::ImageSurface scale is not required
@@ -92,48 +136,10 @@ void RTSurface::changeImage (Glib::ustring imageName)
}
*/
iterator = surfaceCache.emplace (imageName, surface).first;
}
surface = iterator->second;
}
int RTSurface::getWidth() const
{
return surface ? surface->get_width() : -1;
}
int RTSurface::getHeight() const
{
return surface ? surface->get_height() : -1;
}
void RTSurface::init()
{
dpiBack = RTScalable::getDPI();
scaleBack = RTScalable::getScale();
}
void RTSurface::updateImages()
{
double res = getTweakedDPI();
for (auto entry : surfaceCache) {
entry.second = loadImage(entry.first, res);
//printf("RTSurface::updateImages : %s\n", entry.first.c_str());
surfaceCache.emplace(imageName, surface);
}
}
void RTSurface::from(Glib::RefPtr<RTSurface> other)
{
surface = other->surface;
}
double RTSurface::dpiBack = 0.;
bool RTSurface::hasSurface() const
{
return surface ? true : false;
}
const Cairo::RefPtr<Cairo::ImageSurface>& RTSurface::get() const
{
return surface;
}
int RTSurface::scaleBack = 0;

View File

@@ -19,38 +19,36 @@
#pragma once
#include <gtkmm/image.h>
#include "rtscalable.h"
/**
* @brief A derived class of Gtk::Image in order to handle theme-related icon sets.
*/
class RTSurface : public RTScalable
class RTSurface :
public RTScalable
{
private:
static double dpiBack; // used to keep track of master dpi change
static int scaleBack; // used to keep track of master scale change
Cairo::RefPtr<Cairo::ImageSurface> surface;
void changeImage (Glib::ustring imageName);
public:
RTSurface();
RTSurface(const Glib::ustring& fileName, const Glib::ustring& rtlFileName = {});
RTSurface ();
RTSurface (const RTSurface& other);
RTSurface (Glib::ustring fileName, Glib::ustring rtlFileName = Glib::ustring());
void setImage(const Glib::ustring& fileName, const Glib::ustring& rtlFileName = {});
void setImage (Glib::ustring fileName, Glib::ustring rtlFileName = Glib::ustring());
int getWidth() const;
int getHeight() const;
bool hasSurface() const;
const Cairo::RefPtr<Cairo::ImageSurface>& get() const;
Cairo::RefPtr<const Cairo::ImageSurface> get() const;
const Cairo::RefPtr<Cairo::ImageSurface>& get();
static void init();
static void updateImages ();
static void setDPInScale (const double newDPI, const int newScale);
static void setScale (const int newScale);
static void updateImages();
static void setDPInScale(double newDPI, int newScale);
void from(Glib::RefPtr<RTSurface> other);
private:
void changeImage(const Glib::ustring& imageName);
static double dpiBack; // used to keep track of master dpi change
static int scaleBack; // used to keep track of master scale change
Cairo::RefPtr<Cairo::ImageSurface> surface;
};