cv::Mat GCModule::cast(const QImage &qImage) { const int h = qImage.height(); const int w = qImage.width(); cv::Mat result(h, w, CV_8UC3); for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { const QColor qColor = qImage.pixelColor(j, i); const cv::Vec3b color(qColor.red(), qColor.green(), qColor.blue()); result.at<cv::Vec3b>(i, j) = color; } } return result; }
QImage YoonEncryptor::encrypt(const QImage &src) { auto result = src; if(result.height() > result.width()) result = result.transformed(QTransform().rotate(90)); QVector<int> seed = dividers(result.height()); int **lookUpTable = createLUT(seed); QImage tempImage; int red,green,blue; QColor oldColor; for(int r = 0; r < K; r++){ tempImage = result; int **mask = createMask(result.height()); for(int i = 0; i < result.height(); i++){ for(int j = 0; j < result.width(); j++){ oldColor = tempImage.pixelColor(j, i); red = oldColor.red()^mask[lookUpTable[i][j]][j]; green = oldColor.green()^mask[lookUpTable[i][j]][j]; blue = oldColor.blue()^mask[lookUpTable[i][j]][j]; result.setPixelColor(j, lookUpTable[i][j], QColor(red, green, blue)); } } freeMemory(mask, result.height()); } freeMemory(lookUpTable, result.height()); if(result.height() > result.width()) result = result.transformed(QTransform().rotate(-90)); return result; }
QColor IconColors::dominantColor() const { const QImage img = m_icon.pixmap({32, 32}).toImage(); if(img.isNull()) { qWarning() << "wrong icon" << m_icon << m_icon.name(); return QColor(Qt::black); } const int tolerance = 10; QVector<uint> hue(360/tolerance, 0); #ifdef OUTPUT_PIXMAP_DEBUG QImage thing(img.size()+QSize(0,1), QImage::Format_ARGB32); thing.fill(Qt::white); #endif for (int w=0, cw=img.width(); w<cw; ++w) { for (int h=0, ch=img.height(); h<ch; ++h) { #if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0) const QColor c = img.pixelColor(w, h).toHsv(); #else const QColor c(img.pixel(w, h)); #endif if (c.value()>150 && c.saturation()>20 && c.hue()>=0 && c.alpha()>200) { hue[c.hue()/tolerance]++; #ifdef OUTPUT_PIXMAP_DEBUG // qDebug() << "adopting" << w << "x" << h << c.name() << c.hue(); // thing.setPixelColor(w, h, c); thing.setPixelColor(w, h, QColor::fromHsv(tolerance*(c.hue()/tolerance), 220, 220)); #endif } } } uint dominantHue = 0, biggestAmount = 0; for(int i=0; i<hue.size(); ++i) { if (hue[i]>biggestAmount) { biggestAmount = hue[i]; dominantHue = i; } } QColor ret = QColor::fromHsv((dominantHue*tolerance + tolerance/2) % 360, 255, 255); #ifdef OUTPUT_PIXMAP_DEBUG qDebug() << "dominant" << dominantHue << hue[dominantHue] << "~=" << ((100*hue[dominantHue])/(img.width()*img.height())) << "% " << iconName(); thing.setPixelColor(0, img.height(), ret); thing.save("/tmp/"+iconName()+".png"); #endif return ret; }