Skip to content

Commit

Permalink
Fixed a few potenial memory leaks and variable clean up after analyze
Browse files Browse the repository at this point in the history
Fixed const and pass by reference for icctransform
Fixed profile, move to first of init
  • Loading branch information
mikaelsundell committed Feb 29, 2024
1 parent 9e4becf commit a754469
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 23 deletions.
22 changes: 11 additions & 11 deletions colorpicker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,12 @@ void
ColorpickerPrivate::init()
{
mac::setDarkAppearance();
// icc profile
ICCTransform* transform = ICCTransform::instance();
QDir resources(QApplication::applicationDirPath() + "/../Resources");
QString inputProfile = resources.filePath("sRGB2014.icc"); // built-in Qt input profile
transform->setInputProfile(inputProfile);
profile();
// ui
ui.reset(new Ui_Colorpicker());
ui->setupUi(window);
Expand Down Expand Up @@ -382,12 +388,8 @@ ColorpickerPrivate::init()
connect(this, &ColorpickerPrivate::readOnly, ui->s, &Label::setReadOnly);
connect(this, &ColorpickerPrivate::readOnly, ui->v, &Label::setReadOnly);
size = window->size();
// icc profile
ICCTransform* transform = ICCTransform::instance();
QDir resources(QApplication::applicationDirPath() + "/../Resources");
QString inputProfile = resources.filePath("sRGB2014.icc"); // built-in Qt input profile
transform->setInputProfile(inputProfile);
profile();
// stylesheet
stylesheet();
// debug
#ifdef QT_DEBUG
QMenu* menu = ui->menubar->addMenu("Debug");
Expand Down Expand Up @@ -472,7 +474,6 @@ ColorpickerPrivate::grabBuffer(QRect rect)
}
QImage buffer;
const QBrush blackBrush = QBrush(Qt::black);
QScreen* screen = QGuiApplication::screenAt(rect.center());
buffer = mac::grabImage(x, y, w, h, id);

QRegion geom(x, y, w, h);
Expand Down Expand Up @@ -656,8 +657,8 @@ ColorpickerPrivate::widget()
QColor color = dragcolor;
// icc profile
ICCTransform* transform = ICCTransform::instance();
if (state.iccProfile != transform->outputProfile()) {
color = transform->transformTo(color.rgb(), iccProfile, transform->outputProfile());
if (iccCurrentProfile != transform->outputProfile()) {
color = transform->transformTo(color.rgb(), iccCurrentProfile, transform->outputProfile());
}
colors.push_back(QPair<QColor,QString>(color.rgb(), QFileInfo(iccCurrentProfile).baseName()));
}
Expand Down Expand Up @@ -708,7 +709,6 @@ ColorpickerPrivate::profile()
// icc profile
ICCTransform* transform = ICCTransform::instance();
transform->setOutputProfile(outputProfile);
stylesheet();
}

void
Expand Down Expand Up @@ -759,6 +759,7 @@ ColorpickerPrivate::eventFilter(QObject* object, QEvent* event)
{
if (event->type() == QEvent::ScreenChangeInternal) {
profile();
stylesheet();
if (active) {
view();
widget();
Expand Down Expand Up @@ -932,7 +933,6 @@ ColorpickerPrivate::drag()
if (rect.width() > 5 && rect.height() > 5) // cluster limit
{
int width = image.width();
int height = image.height();
int colornum = 6;
{
cv::utils::logging::setLogLevel(cv::utils::logging::LOG_LEVEL_SILENT);
Expand Down
1 change: 0 additions & 1 deletion colorpicker.mm
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
{
static QMutex mutex;
static QPoint lastpos;
NSApplication* app = [NSApplication sharedApplication];
[[NSNotificationCenter defaultCenter] addObserverForName:NSApplicationDidBecomeActiveNotification
object:nil
queue:nil
Expand Down
1 change: 0 additions & 1 deletion colorwheel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,6 @@ ColorwheelPrivate::paintColorwheel(int w, int h, qreal dpr)
QPointF center(w/2.0, h/2.0);
int diameter = std::min(w, h);
int radius = diameter/2.0;

QPixmap colorwheel(w * dpr, h * dpr);
colorwheel.fill(Qt::transparent);
colorwheel.setDevicePixelRatio(dpr);
Expand Down
4 changes: 2 additions & 2 deletions dragger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ DraggerPrivate::mapToGeometry()
QSize size = mapToSize();
int x = position.x() - size.width() / 2;
int y = position.y() - size.height() / 2;
int width = baseRect.width();
int height = baseRect.height();
int width;
int height;

QRect screenGeometry = screen->geometry();
// left
Expand Down
6 changes: 3 additions & 3 deletions icctransform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,19 +186,19 @@ ICCTransform::ICCTransform::transformTo(QRgb color)
}

QImage
ICCTransform::ICCTransform::transformTo(QImage image)
ICCTransform::ICCTransform::transformTo(const QImage& image)
{
return p->transformTo(image, p->inputProfile, p->outputProfile);
}

QRgb
ICCTransform::ICCTransform::transformTo(QRgb color, QString inputProfile, QString outputProfile)
ICCTransform::ICCTransform::transformTo(QRgb color, const QString& inputProfile, const QString& outputProfile)
{
return p->transformTo(color, inputProfile, outputProfile);
}

QImage
ICCTransform::transformTo(QImage image, QString inputProfile, QString outputProfile)
ICCTransform::transformTo(const QImage& image, const QString& inputProfile, const QString& outputProfile)
{
return p->transformTo(image, inputProfile, outputProfile);
}
6 changes: 3 additions & 3 deletions icctransform.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ class ICCTransform : public QObject
QString inputProfile() const;
QString outputProfile() const;
QRgb transformTo(QRgb image);
QImage transformTo(QImage image);
QRgb transformTo(QRgb color, QString profile, QString outputProfile);
QImage transformTo(QImage image, QString profile, QString outputProfile);
QImage transformTo(const QImage& image);
QRgb transformTo(QRgb color, const QString& profile, const QString& outputProfile);
QImage transformTo(const QImage& image, const QString& profile, const QString& outputProfile);

public Q_SLOTS:
void setInputProfile(const QString& inputProfile);
Expand Down
5 changes: 5 additions & 0 deletions mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ ColorSyncProfile grabColorSyncProfile(NSScreen* screen)
if (iccURLRef) {
colorSyncProfile.displayProfileUrl = CFURLCopyFileSystemPath(iccURLRef, kCFURLPOSIXPathStyle);
}
CFRelease(csProfileRef);
}
return colorSyncProfile;
}
Expand Down Expand Up @@ -166,7 +167,11 @@ QImage grabImage(int x, int y, int width, int height, WId windowId)
CGRect cgRect = (width < 0 || height < 0) ? CGRectInfinite : grabRect.toCGRect();
const CGDisplayErr err = CGGetDisplaysWithRect(cgRect, maxDisplays, displays, &displayCount);
if (err || displayCount == 0)
{
CFRelease(screenWindows);
CFRelease(grabWindows);
return QImage();
}

// if the grab size is not specified, set it to be the bounding box of all screens,
if (width < 0 || height < 0) {
Expand Down
4 changes: 2 additions & 2 deletions picker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ PickerPrivate::mapToGeometry()

int x = position.x() - size.width() / 2;
int y = position.y() - size.height() / 2;
int width = widget->width();
int height = widget->height();
int width;
int height;
QRect screenGeometry = screen->geometry();
// left
if (x < screenGeometry.left()) {
Expand Down

0 comments on commit a754469

Please sign in to comment.