/* Copyright (c) 2008-2019 Jan W. Krieger () This software is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License (LGPL) as published by the Free Software Foundation, either version 2.1 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License (LGPL) for more details. You should have received a copy of the GNU Lesser General Public License (LGPL) along with this program. If not, see . */ #include "jkqtcommon/jkqtpbasicimagetools.h" #include #include #include #include #ifdef QT_XML_LIB # include #endif const int JKQTPImageTools::PALETTE_ICON_WIDTH = 64; const int JKQTPImageTools::PALETTE_IMAGEICON_HEIGHT = 64; const int JKQTPImageTools::LUTSIZE = 256; QMap JKQTPImageTools::global_jkqtpimagetools_lutstore = JKQTPImageTools::getDefaultLUTs(); int JKQTPImageTools::global_next_userpalette = JKQTPMathImageFIRST_REGISTERED_USER_PALETTE; QMap JKQTPImageTools::getDefaultLUTs() { QMap lutstore; { auto palette=JKQTPMathImageRED; QString palN="red"; QString palNT=QObject::tr("red"); lutstore[palette]=JKQTPImageTools::LUTData(QVector(JKQTPImageTools::LUTSIZE+1, 0), palN, palNT); QRgb* plut=lutstore[palette].lut.data(); if (plut!=nullptr) { for (int l=0; l<=JKQTPImageTools::LUTSIZE; l++) { double v=l/static_cast(JKQTPImageTools::LUTSIZE); plut[l]=qRgb(static_cast(255.0*v), 0, 0); } plut[JKQTPImageTools::LUTSIZE+1]=plut[JKQTPImageTools::LUTSIZE]; } } { auto palette=JKQTPMathImageGREEN; QString palN="green"; QString palNT=QObject::tr("green"); lutstore[palette]=JKQTPImageTools::LUTData(QVector(JKQTPImageTools::LUTSIZE+1, 0), palN, palNT); QRgb* plut=lutstore[palette].lut.data(); if (plut!=nullptr) { for (int l=0; l<=JKQTPImageTools::LUTSIZE; l++) { double v=l/static_cast(JKQTPImageTools::LUTSIZE); plut[l]=qRgb(0, static_cast(255.0*v), 0); } plut[JKQTPImageTools::LUTSIZE+1]=plut[JKQTPImageTools::LUTSIZE]; } } { auto palette=JKQTPMathImageBLUE; QString palN="blue"; QString palNT=QObject::tr("blue"); lutstore[palette]=JKQTPImageTools::LUTData(QVector(JKQTPImageTools::LUTSIZE+1, 0), palN, palNT); QRgb* plut=lutstore[palette].lut.data(); if (plut!=nullptr) { for (int l=0; l<=JKQTPImageTools::LUTSIZE; l++) { double v=l/static_cast(JKQTPImageTools::LUTSIZE); plut[l]=qRgb(0, 0, static_cast(255.0*v)); } plut[JKQTPImageTools::LUTSIZE+1]=plut[JKQTPImageTools::LUTSIZE]; } } { auto palette=JKQTPMathImageGRAY; QString palN="gray"; QString palNT=QObject::tr("gray"); lutstore[palette]=JKQTPImageTools::LUTData(QVector(JKQTPImageTools::LUTSIZE+1, 0), palN, palNT); QRgb* plut=lutstore[palette].lut.data(); if (plut!=nullptr) { for (int l=0; l<=JKQTPImageTools::LUTSIZE; l++) { double v=l/static_cast(JKQTPImageTools::LUTSIZE); plut[l]=qRgb(static_cast(255.0*v), static_cast(255.0*v), static_cast(255.0*v)); } plut[JKQTPImageTools::LUTSIZE+1]=plut[JKQTPImageTools::LUTSIZE]; } } { auto palette=JKQTPMathImageALPHA; QString palN="alpha"; QString palNT=QObject::tr("alpha"); lutstore[palette]=JKQTPImageTools::LUTData(QVector(JKQTPImageTools::LUTSIZE+1, 0), palN, palNT); QRgb* plut=lutstore[palette].lut.data(); if (plut!=nullptr) { for (int l=0; l<=JKQTPImageTools::LUTSIZE; l++) { double v=l/static_cast(JKQTPImageTools::LUTSIZE); plut[l]=qRgba(255,255,255, static_cast(255.0*v)); } plut[JKQTPImageTools::LUTSIZE+1]=plut[JKQTPImageTools::LUTSIZE]; } } { auto palette=JKQTPMathImageINVERTED_ALPHA; QString palN="invAlpha"; QString palNT=QObject::tr("inv. alpha"); lutstore[palette]=JKQTPImageTools::LUTData(QVector(JKQTPImageTools::LUTSIZE+1, 0), palN, palNT); QRgb* plut=lutstore[palette].lut.data(); if (plut!=nullptr) { for (int l=0; l<=JKQTPImageTools::LUTSIZE; l++) { double v=l/static_cast(JKQTPImageTools::LUTSIZE); plut[l]=qRgba(255,255,255, static_cast(255.0*v)); } plut[JKQTPImageTools::LUTSIZE+1]=plut[JKQTPImageTools::LUTSIZE]; } } { auto palette=JKQTPMathImageINVERTEDRED; QString palN="invred"; QString palNT=QObject::tr("inv. red"); lutstore[palette]=JKQTPImageTools::LUTData(QVector(JKQTPImageTools::LUTSIZE+1, 0), palN, palNT); QRgb* plut=lutstore[palette].lut.data(); if (plut!=nullptr) { for (int l=0; l<=JKQTPImageTools::LUTSIZE; l++) { double v=l/static_cast(JKQTPImageTools::LUTSIZE); plut[l]=qRgb(static_cast(255.0*(1.0-v)), 0, 0); } plut[JKQTPImageTools::LUTSIZE+1]=plut[JKQTPImageTools::LUTSIZE]; } } { auto palette=JKQTPMathImageINVERTEDGREEN; QString palN="invgreen"; QString palNT=QObject::tr("inv. green"); lutstore[palette]=JKQTPImageTools::LUTData(QVector(JKQTPImageTools::LUTSIZE+1, 0), palN, palNT); QRgb* plut=lutstore[palette].lut.data(); if (plut!=nullptr) { for (int l=0; l<=JKQTPImageTools::LUTSIZE; l++) { double v=l/static_cast(JKQTPImageTools::LUTSIZE); plut[l]=qRgb(0, static_cast(255.0*(1.0-v)), 0); } plut[JKQTPImageTools::LUTSIZE+1]=plut[JKQTPImageTools::LUTSIZE]; } } { auto palette=JKQTPMathImageINVERTEDBLUE; QString palN="invblue"; QString palNT=QObject::tr("inv. blue"); lutstore[palette]=JKQTPImageTools::LUTData(QVector(JKQTPImageTools::LUTSIZE+1, 0), palN, palNT); QRgb* plut=lutstore[palette].lut.data(); if (plut!=nullptr) { for (int l=0; l<=JKQTPImageTools::LUTSIZE; l++) { double v=l/static_cast(JKQTPImageTools::LUTSIZE); plut[l]=qRgb(0, 0, static_cast(255.0*(1.0-v))); } plut[JKQTPImageTools::LUTSIZE+1]=plut[JKQTPImageTools::LUTSIZE]; } } { auto palette=JKQTPMathImageINVERTEDGRAY; QString palN="invgray"; QString palNT=QObject::tr("inv. gray"); lutstore[palette]=JKQTPImageTools::LUTData(QVector(JKQTPImageTools::LUTSIZE+1, 0), palN, palNT); QRgb* plut=lutstore[palette].lut.data(); if (plut!=nullptr) { for (int l=0; l<=JKQTPImageTools::LUTSIZE; l++) { double v=1.0-(l/static_cast(JKQTPImageTools::LUTSIZE)); plut[l]=qRgb(static_cast(255.0*v), static_cast(255.0*v), static_cast(255.0*v)); } plut[JKQTPImageTools::LUTSIZE+1]=plut[JKQTPImageTools::LUTSIZE]; } } { auto palette=JKQTPMathImageMATLAB; QString palN="Matlab"; QString palNT=QObject::tr("Matlab"); lutstore[palette]=JKQTPImageTools::LUTData(QVector(JKQTPImageTools::LUTSIZE+1, 0), palN, palNT); QRgb* plut=lutstore[palette].lut.data(); if (plut!=nullptr) { for (int l=0; l<=JKQTPImageTools::LUTSIZE; l++) { double v=l/static_cast(JKQTPImageTools::LUTSIZE); double r = 382.5 - 1020.0 * std::abs(v - 0.75); if (r > 255.0) r = 255.0; else if (r < 0.0) r = 0.0; double g = 382.5 - 1020.0 * std::abs(v - 0.5); if (g > 255.0) g = 255.0; else if (g < 0.0) g = 0.0; double b = 382.5 - 1020.0 * std::abs(v - 0.25); if (b > 255.0) b = 255.0; else if (b < 0.0) b = 0.0; plut[l]=qRgb(static_cast(r), static_cast(g), static_cast(b)); } } } { auto palette=JKQTPMathImageINVERTED_MATLAB; QString palN="invMatlab"; QString palNT=QObject::tr("inv. Matlab"); lutstore[palette]=JKQTPImageTools::LUTData(QVector(JKQTPImageTools::LUTSIZE+1, 0), palN, palNT); QRgb* plut=lutstore[palette].lut.data(); if (plut!=nullptr) { for (int l=JKQTPImageTools::LUTSIZE; l>=0; l--) { double v=(JKQTPImageTools::LUTSIZE-l)/static_cast(JKQTPImageTools::LUTSIZE); double r = 382.5 - 1020.0 * std::abs(v - 0.75); if (r > 255.0) r = 255.0; else if (r < 0.0) r = 0.0; double g = 382.5 - 1020.0 * std::abs(v - 0.5); if (g > 255.0) g = 255.0; else if (g < 0.0) g = 0.0; double b = 382.5 - 1020.0 * std::abs(v - 0.25); if (b > 255.0) b = 255.0; else if (b < 0.0) b = 0.0; plut[l]=qRgb(static_cast(r), static_cast(g), static_cast(b)); } } } { auto palette=JKQTPMathImageRYGB; QString palN="RYGB"; QString palNT=QObject::tr("RYGB"); lutstore[palette]=JKQTPImageTools::LUTData(QVector(JKQTPImageTools::LUTSIZE+1, 0), palN, palNT); QRgb* plut=lutstore[palette].lut.data(); if (plut!=nullptr) { for (int l=0; l<=JKQTPImageTools::LUTSIZE; l++) { double v=l/static_cast(JKQTPImageTools::LUTSIZE); double r = 796.875*v - 199.21875; if (r > 255.0) r = 255.0; else if (r < 0.0) r = 0.0; double g = 255.0 * std::sin(M_PI*v); double b = 255.0 - 765.0 * v; if (b < 0.0) b = 0.0; plut[l]=qRgb(static_cast(r), static_cast(g), static_cast(b)); } } } { auto palette=JKQTPMathImageINVERTED_RYGB; QString palN="invRYGB"; QString palNT=QObject::tr("inv. RYGB"); lutstore[palette]=JKQTPImageTools::LUTData(QVector(JKQTPImageTools::LUTSIZE+1, 0), palN, palNT); QRgb* plut=lutstore[palette].lut.data(); if (plut!=nullptr) { for (int l=JKQTPImageTools::LUTSIZE; l>=0; l--) { double v=(JKQTPImageTools::LUTSIZE-l)/static_cast(JKQTPImageTools::LUTSIZE); double r = 796.875*v - 199.21875; if (r > 255.0) r = 255.0; else if (r < 0.0) r = 0.0; double g = 255.0 * std::sin(M_PI*v); double b = 255.0 - 765.0 * v; if (b < 0.0) b = 0.0; plut[l]=qRgb(static_cast(r), static_cast(g), static_cast(b)); } } } { auto palette=JKQTPMathImageHSV; QString palN="HSV"; QString palNT=QObject::tr("HSV"); lutstore[palette]=JKQTPImageTools::LUTData(QVector(JKQTPImageTools::LUTSIZE+1, 0), palN, palNT); QRgb* plut=lutstore[palette].lut.data(); if (plut!=nullptr) { for (int l=0; l<=JKQTPImageTools::LUTSIZE; l++) { double v=l/static_cast(JKQTPImageTools::LUTSIZE); int h = static_cast(floor(6*v)); double f = 6*v-double(h); switch (h) { case 0: plut[l]=qRgb(255, static_cast(255.0*f), 0); break; case 1: plut[l]=qRgb(static_cast(255.0*(1-f)), 255, 0); break; case 2: plut[l]=qRgb(0, 255, static_cast(255.0*f)); break; case 3: plut[l]=qRgb(0, static_cast(255.0*(1-f)), 255); break; case 4: plut[l]=qRgb(static_cast(255.0*f), 0, 255); break; case 5: plut[l]=qRgb(255, 0, static_cast(255.0*(1-f))); break; case 6: plut[l]=qRgb(255, static_cast(255.0*f), 0); break; } } } } { auto palette=JKQTPMathImageINVERTED_HSV; QString palN="invHSV"; QString palNT=QObject::tr("inv. HSV"); lutstore[palette]=JKQTPImageTools::LUTData(QVector(JKQTPImageTools::LUTSIZE+1, 0), palN, palNT); QRgb* plut=lutstore[palette].lut.data(); if (plut!=nullptr) { for (int l=0; l<=JKQTPImageTools::LUTSIZE; l++) { double v=l/static_cast(JKQTPImageTools::LUTSIZE); int h = static_cast(floor(6.0-6.0*v)); double f = 6.0-6.0*v-double(h); switch (h) { case 0: plut[l]=qRgb(255, static_cast(255.0*f), 0); break; case 1: plut[l]=qRgb(static_cast(255.0*(1-f)), 255, 0); break; case 2: plut[l]=qRgb(0, 255, static_cast(255.0*f)); break; case 3: plut[l]=qRgb(0, static_cast(255.0*(1-f)), 255); break; case 4: plut[l]=qRgb(static_cast(255.0*f), 0, 255); break; case 5: plut[l]=qRgb(255, 0, static_cast(255.0*(1-f))); break; case 6: plut[l]=qRgb(255, static_cast(255.0*f), 0); break; } } } } { auto palette=JKQTPMathImageRAINBOW; QString palN="rainbow"; QString palNT=QObject::tr("rainbow"); lutstore[palette]=JKQTPImageTools::LUTData(QVector(JKQTPImageTools::LUTSIZE+1, 0), palN, palNT); QRgb* plut=lutstore[palette].lut.data(); //std::cout<<"!!! creating rainbow lut\n"; if (plut!=nullptr) { for (int l=0; l<=JKQTPImageTools::LUTSIZE; l++) { double v=l/static_cast(JKQTPImageTools::LUTSIZE); double r = 255.0*std::abs(2.0*v-0.5); if (r > 255.0) r = 255.0; double g = 255.0*sin(M_PI*v); double b = 255.0*cos(0.5*M_PI*v); plut[l]=qRgb(static_cast(r), static_cast(g), static_cast(b)); } } } { auto palette=JKQTPMathImageINVERTED_RAINBOW; QString palN="invrainbow"; QString palNT=QObject::tr("inv. rainbow"); lutstore[palette]=JKQTPImageTools::LUTData(QVector(JKQTPImageTools::LUTSIZE+1, 0), palN, palNT); QRgb* plut=lutstore[palette].lut.data(); //std::cout<<"!!! creating rainbow lut\n"; if (plut!=nullptr) { for (int l=JKQTPImageTools::LUTSIZE; l>=0; l--) { double v=(JKQTPImageTools::LUTSIZE-l)/static_cast(JKQTPImageTools::LUTSIZE); double r = 255.0*std::abs(2.0*v-0.5); if (r > 255.0) r = 255.0; double g = 255.0*sin(M_PI*v); double b = 255.0*cos(0.5*M_PI*v); plut[l]=qRgb(static_cast(r), static_cast(g), static_cast(b)); } } } { auto palette=JKQTPMathImageHOT; QString palN="AFMhot"; QString palNT=QObject::tr("AFM hot"); lutstore[palette]=JKQTPImageTools::LUTData(QVector(JKQTPImageTools::LUTSIZE+1, 0), palN, palNT); QRgb* plut=lutstore[palette].lut.data(); if (plut!=nullptr) { for (int l=0; l<=JKQTPImageTools::LUTSIZE; l++) { double v=l/static_cast(JKQTPImageTools::LUTSIZE); double r = 765.0*v; if (r > 255.0) r = 255.0; double g = 765.0*v-255.0; if (g > 255.0) g = 255.0; else if (g < 0.0) g = 0.0; double b = 765.0*v-510.0; if (b < 0.0) b = 0.0; plut[l]=qRgb(static_cast(r), static_cast(g), static_cast(b)); } } } { auto palette=JKQTPMathImageINVERTED_HOT; QString palN="invAFMhot"; QString palNT=QObject::tr("inv. AFM hot"); lutstore[palette]=JKQTPImageTools::LUTData(QVector(JKQTPImageTools::LUTSIZE+1, 0), palN, palNT); QRgb* plut=lutstore[palette].lut.data(); if (plut!=nullptr) { for (int l=JKQTPImageTools::LUTSIZE; l>=0; l--) { double v=(JKQTPImageTools::LUTSIZE-l)/static_cast(JKQTPImageTools::LUTSIZE); double r = 765.0*v; if (r > 255.0) r = 255.0; double g = 765.0*v-255.0; if (g > 255.0) g = 255.0; else if (g < 0.0) g = 0.0; double b = 765.0*v-510.0; if (b < 0.0) b = 0.0; plut[l]=qRgb(static_cast(r), static_cast(g), static_cast(b)); } } } { auto palette=JKQTPMathImageOCEAN; QString palN="ocean"; QString palNT=QObject::tr("ocean"); lutstore[palette]=JKQTPImageTools::LUTData(QVector(JKQTPImageTools::LUTSIZE+1, 0), palN, palNT); QRgb* plut=lutstore[palette].lut.data(); if (plut!=nullptr) { for (int l=0; l<=JKQTPImageTools::LUTSIZE; l++) { double v=l/static_cast(JKQTPImageTools::LUTSIZE); double r = 765.0*v-510.0; if (r < 0.0) r = 0.0; double g = std::abs(382.5*v-127.5); double b = 255.0*v; plut[l]=qRgb(static_cast(r), static_cast(g), static_cast(b)); } } } { auto palette=JKQTPMathImageINVERTED_OCEAN; QString palN="invocean"; QString palNT=QObject::tr("inv. ocean"); lutstore[palette]=JKQTPImageTools::LUTData(QVector(JKQTPImageTools::LUTSIZE+1, 0), palN, palNT); QRgb* plut=lutstore[palette].lut.data(); if (plut!=nullptr) { for (int l=JKQTPImageTools::LUTSIZE; l>=0; l--) { double v=(JKQTPImageTools::LUTSIZE-l)/static_cast(JKQTPImageTools::LUTSIZE); double r = 765.0*v-510.0; if (r < 0.0) r = 0.0; double g = std::abs(382.5*v-127.5); double b = 255.0*v; plut[l]=qRgb(static_cast(r), static_cast(g), static_cast(b)); } } } { auto palette=JKQTPMathImageBLUEMAGENTAYELLOW; QString palN="BlMaYe"; QString palNT=QObject::tr("blue-magenta-yellow"); lutstore[palette]=JKQTPImageTools::LUTData(QVector(JKQTPImageTools::LUTSIZE+1, 0), palN, palNT); QRgb* plut=lutstore[palette].lut.data(); if (plut!=nullptr) { for (int l=0; l<=JKQTPImageTools::LUTSIZE; l++) { double v=l/static_cast(JKQTPImageTools::LUTSIZE); double r = (v/0.32-0.78125); if (r < 0.0) r = 0.0; if (r > 1.0) r = 1.0; double g = 2.0*v-0.84; if (g < 0.0) g = 0.0; if (g > 1.0) g = 1.0; double b = 4.0*v; if (b>1 || b<0) b = -2.0*v+1.84; if (b>1 || b<0) b = v/0.08-11.5; if (b>1 || b<0) b=1; if (b < 0.0) b = 0.0; if (b > 1.0) b = 1.0; plut[l]=qRgb(static_cast(255.0*r), static_cast(255.0*g), static_cast(255.0*b)); } } } { auto palette=JKQTPMathImageINVERTED_BLUEMAGENTAYELLOW; QString palN="YeMaBl"; QString palNT=QObject::tr("yellow-magenta-blue"); lutstore[palette]=JKQTPImageTools::LUTData(QVector(JKQTPImageTools::LUTSIZE+1, 0), palN, palNT); QRgb* plut=lutstore[palette].lut.data(); if (plut!=nullptr) { for (int l=0; l<=JKQTPImageTools::LUTSIZE; l++) { double v=(JKQTPImageTools::LUTSIZE-l)/static_cast(JKQTPImageTools::LUTSIZE); double r = (v/0.32-0.78125); if (r < 0.0) r = 0.0; if (r > 1.0) r = 1.0; double g = 2.0*v-0.84; if (g < 0.0) g = 0.0; if (g > 1.0) g = 1.0; double b = 4.0*v; if (b>1 || b<0) b = -2.0*v+1.84; if (b>1 || b<0) b = v/0.08-11.5; if (b>1 || b<0) b=1; if (b < 0.0) b = 0.0; if (b > 1.0) b = 1.0; plut[l]=qRgb(static_cast(255.0*r), static_cast(255.0*g), static_cast(255.0*b)); } } } { auto palette=JKQTPMathImageBLUEYELLOW; QString palN="BlYe"; QString palNT=QObject::tr("blue-yellow"); lutstore[palette]=JKQTPImageTools::LUTData(QVector(JKQTPImageTools::LUTSIZE+1, 0), palN, palNT); QRgb* plut=lutstore[palette].lut.data(); if (plut!=nullptr) { for (int l=0; l<=JKQTPImageTools::LUTSIZE; l++) { double v=l/static_cast(JKQTPImageTools::LUTSIZE); double r = sqrt(sqrt(v)); if (r < 0.0) r = 0.0; if (r > 1.0) r = 1.0; double g = sin(M_PI/2.0*v); if (g < 0.0) g = 0.0; if (g > 1.0) g = 1.0; double b = cos(M_PI/2.0*v); if (b < 0.0) b = 0.0; if (b > 1.0) b = 1.0; plut[l]=qRgb(static_cast(255.0*r), static_cast(255.0*g), static_cast(255.0*b)); } } } { auto palette=JKQTPMathImageINVERTED_BLUEYELLOW; QString palN="YeBl"; QString palNT=QObject::tr("yellow-blue"); lutstore[palette]=JKQTPImageTools::LUTData(QVector(JKQTPImageTools::LUTSIZE+1, 0), palN, palNT); QRgb* plut=lutstore[palette].lut.data(); if (plut!=nullptr) { for (int l=0; l<=JKQTPImageTools::LUTSIZE; l++) { double v=(JKQTPImageTools::LUTSIZE-l)/static_cast(JKQTPImageTools::LUTSIZE); double r = sqrt(sqrt(v)); if (r < 0.0) r = 0.0; if (r > 1.0) r = 1.0; double g = sin(M_PI/2.0*v); if (g < 0.0) g = 0.0; if (g > 1.0) g = 1.0; double b = cos(M_PI/2.0*v); if (b < 0.0) b = 0.0; if (b > 1.0) b = 1.0; plut[l]=qRgb(static_cast(255.0*r), static_cast(255.0*g), static_cast(255.0*b)); } } } { auto palette=JKQTPMathImageCYAN; QString palN="cyan"; QString palNT=QObject::tr("cyan"); lutstore[palette]=JKQTPImageTools::LUTData(QVector(JKQTPImageTools::LUTSIZE+1, 0), palN, palNT); QRgb* plut=lutstore[palette].lut.data(); if (plut!=nullptr) { for (int l=0; l<=JKQTPImageTools::LUTSIZE; l++) { double v=l/static_cast(JKQTPImageTools::LUTSIZE); double r = v*0.5; if (r < 0.0) r = 0.0; if (r > 1.0) r = 1.0; double g = v; if (g < 0.0) g = 0.0; if (g > 1.0) g = 1.0; double b = v; if (b < 0.0) b = 0.0; if (b > 1.0) b = 1.0; plut[l]=qRgb(static_cast(255.0*r), static_cast(255.0*g), static_cast(255.0*b)); } } } { auto palette=JKQTPMathImageINVERTED_CYAN; QString palN="invcyan"; QString palNT=QObject::tr("inv. cyan"); lutstore[palette]=JKQTPImageTools::LUTData(QVector(JKQTPImageTools::LUTSIZE+1, 0), palN, palNT); QRgb* plut=lutstore[palette].lut.data(); if (plut!=nullptr) { for (int l=0; l<=JKQTPImageTools::LUTSIZE; l++) { double v=(JKQTPImageTools::LUTSIZE-l)/static_cast(JKQTPImageTools::LUTSIZE); double r = v*0.5; if (r < 0.0) r = 0.0; if (r > 1.0) r = 1.0; double g = v; if (g < 0.0) g = 0.0; if (g > 1.0) g = 1.0; double b = v; if (b < 0.0) b = 0.0; if (b > 1.0) b = 1.0; plut[l]=qRgb(static_cast(255.0*r), static_cast(255.0*g), static_cast(255.0*b)); } } } { auto palette=JKQTPMathImageTRAFFICLIGHT; QString palN="trafficlight"; QString palNT=QObject::tr("trafficlight"); lutstore[palette]=JKQTPImageTools::LUTData(QVector(JKQTPImageTools::LUTSIZE+1, 0), palN, palNT); QRgb* plut=lutstore[palette].lut.data(); if (plut!=nullptr) { for (int l=0; l<=JKQTPImageTools::LUTSIZE; l++) { double v=l/static_cast(JKQTPImageTools::LUTSIZE); double r = (v < 0.5) ? 128.0*sin(M_PI*(2.0*v-0.5))+128.0 : 255.0; if (r > 255.0) r = 255.0; double g = (v < 0.5) ? 512.0*v+128.0 : 512.0-512.0*v; if (g > 255.0) g = 255.0; plut[l]=qRgb(static_cast(r), static_cast(g), 0); } } } { auto palette=JKQTPMathImageINVERTED_TRAFFICLIGHT; QString palN="invtrafficlight"; QString palNT=QObject::tr("inv. trafficlight"); lutstore[palette]=JKQTPImageTools::LUTData(QVector(JKQTPImageTools::LUTSIZE+1, 0), palN, palNT); QRgb* plut=lutstore[palette].lut.data(); if (plut!=nullptr) { for (int l=0; l<=JKQTPImageTools::LUTSIZE; l++) { double v=(JKQTPImageTools::LUTSIZE-l)/static_cast(JKQTPImageTools::LUTSIZE); double r = (v < 0.5) ? 128.0*sin(M_PI*(2.0*v-0.5))+128.0 : 255.0; if (r > 255.0) r = 255.0; double g = (v < 0.5) ? 512.0*v+128.0 : 512.0-512.0*v; if (g > 255.0) g = 255.0; plut[l]=qRgb(static_cast(r), static_cast(g), 0); } } } { auto palette=JKQTPMathImageBLUEWHITERED; QString palN="bluewhitered"; QString palNT=QObject::tr("blue-white-red"); lutstore[palette]=JKQTPImageTools::LUTData(QVector(JKQTPImageTools::LUTSIZE+1, 0), palN, palNT); QList > lst; lst<(8.0, 0xFFB2182B); lst<(7.0, 0xFFD6604D); lst<(6.0, 0xFFF4A582); lst<(5.0, 0xFFFDDBC7); lst<(4.0, 0xFFD1E5F0); lst<(3.0, 0xFF92C5DE); lst<(2.0, 0xFF4393C3); lst<(1.0, 0xFF2166AC); lutstore[palette].lut=JKQTPBuildColorPaletteLUTLinInterpolate(lst, JKQTPImageTools::LUTSIZE+1); } { auto palette=JKQTPMathImageREDWHITEBLUE; QString palN="redwhiteblue"; QString palNT=QObject::tr("red-white-blue"); lutstore[palette]=JKQTPImageTools::LUTData(QVector(JKQTPImageTools::LUTSIZE+1, 0), palN, palNT); QList > lst; lst<(0.0, 0xFFB2182B); lst<(1.0, 0xFFD6604D); lst<(2.0, 0xFFF4A582); lst<(3.0, 0xFFFDDBC7); lst<(4.0, 0xFFD1E5F0); lst<(5.0, 0xFF92C5DE); lst<(6.0, 0xFF4393C3); lst<(7.0, 0xFF2166AC); lutstore[palette].lut=JKQTPBuildColorPaletteLUTLinInterpolate(lst, JKQTPImageTools::LUTSIZE+1); } { auto palette=JKQTPMathImageBLACKBLUEREDYELLOW; QString palN="BBlRdYe"; QString palNT=QObject::tr("black-blue-red-yellow"); lutstore[palette]=JKQTPImageTools::LUTData(QVector(JKQTPImageTools::LUTSIZE+1, 0), palN, palNT); QRgb* plut=lutstore[palette].lut.data(); //std::cout<<"!!! creating rainbow lut\n"; if (plut!=nullptr) { for (int l=0; l<=JKQTPImageTools::LUTSIZE; l++) { double v=(l)/static_cast(JKQTPImageTools::LUTSIZE); double r = 255.0*qBound(0.0,sqrt(v),1.0); double g = 255.0*qBound(0.0,v*v*v,1.0); double b = 255.0*qBound(0.0,sin(2.0*M_PI*v),1.0); plut[l]=qRgb(static_cast(r), static_cast(g), static_cast(b)); } } } { auto palette=JKQTPMathImageGREENREDVIOLET; QString palN="GnRdVi"; QString palNT=QObject::tr("green-red-violet"); lutstore[palette]=JKQTPImageTools::LUTData(QVector(JKQTPImageTools::LUTSIZE+1, 0), palN, palNT); QRgb* plut=lutstore[palette].lut.data(); //std::cout<<"!!! creating rainbow lut\n"; if (plut!=nullptr) { for (int l=0; l<=JKQTPImageTools::LUTSIZE; l++) { double v=(l)/static_cast(JKQTPImageTools::LUTSIZE); double r = 255.0*qBound(0.0,v,1.0); double g = 255.0*qBound(0.0,fabs(v-0.5),1.0); double b = 255.0*qBound(0.0,v*v*v*v,1.0); plut[l]=qRgb(static_cast(r), static_cast(g), static_cast(b)); } } } { auto palette=JKQTPMathImageBLACKBLUEWHITEYELLOWWHITE; QString palN="BWprint"; QString palNT=QObject::tr("black-blue-white-yellow-white"); lutstore[palette]=JKQTPImageTools::LUTData(QVector(JKQTPImageTools::LUTSIZE+1, 0), palN, palNT); QRgb* plut=lutstore[palette].lut.data(); //std::cout<<"!!! creating rainbow lut\n"; if (plut!=nullptr) { for (int l=0; l<=JKQTPImageTools::LUTSIZE; l++) { double v=(l)/static_cast(JKQTPImageTools::LUTSIZE); double r = 255.0*qBound(0.0,v/0.32-0.78125,1.0); double g = 255.0*qBound(0.0,v/0.32-0.78125,1.0); double b = 255.0*qBound(0.0,(v<0.25)?4*v:(v<0.42)?1.0:(v<0.92)?-2.0*v+1.84:v/0.08-11.5,1.0); plut[l]=qRgb(static_cast(r), static_cast(g), static_cast(b)); } } } { auto palette=JKQTPMathImageWHITEYELLOWWHITEBLUEBLACK; QString palN="invBWprint"; QString palNT=QObject::tr("white-yellow-white-blue-black"); lutstore[palette]=JKQTPImageTools::LUTData(QVector(JKQTPImageTools::LUTSIZE+1, 0), palN, palNT); QRgb* plut=lutstore[palette].lut.data(); if (plut!=nullptr) { for (int l=0; l<=JKQTPImageTools::LUTSIZE; l++) { double v=(JKQTPImageTools::LUTSIZE-l)/static_cast(JKQTPImageTools::LUTSIZE); double r = 255.0*qBound(0.0,v/0.32-0.78125,1.0); double g = 255.0*qBound(0.0,v/0.32-0.78125,1.0); double b = 255.0*qBound(0.0,(v<0.25)?4*v:(v<0.42)?1.0:(v<0.92)?-2.0*v+1.84:v/0.08-11.5,1.0); plut[l]=qRgb(static_cast(r), static_cast(g), static_cast(b)); } } } { auto palette=JKQTPMathImageBR_GR; QString palN="BrBG"; QString palNT=QObject::tr("BrBG"); lutstore[palette]=JKQTPImageTools::LUTData(palN, palNT); QList > lst; lst<(0.0, qRgb(0x8C, 0x51, 0x0A)); lst<(1.0, qRgb(0xBF, 0x81, 0x2D)); lst<(2.0, qRgb(0xDF, 0xC2, 0x7D)); lst<(3.0, 0xFFF6E8C3); lst<(4.0, 0xFFC7EAE5); lst<(5.0, 0xFF80CDC1); lst<(6.0, 0xFF35978F); lst<(7.0, 0xFF01665E); lutstore[palette].lut=JKQTPBuildColorPaletteLUTLinInterpolate(lst); } { auto palette=JKQTPMathImageBR_GR_STEP; QString palN="stepsBrBG"; QString palNT=QObject::tr("steps: BrBG"); lutstore[palette]=JKQTPImageTools::LUTData( palN, palNT); QList > lst; lst<(0.0, qRgb(0x8C, 0x51, 0x0A)); lst<(1.0, qRgb(0xBF, 0x81, 0x2D)); lst<(2.0, qRgb(0xDF, 0xC2, 0x7D)); lst<(3.0, 0xFFF6E8C3); lst<(4.0, 0xFFC7EAE5); lst<(5.0, 0xFF80CDC1); lst<(6.0, 0xFF35978F); lst<(7.0, 0xFF01665E); lutstore[palette].lut=JKQTPBuildColorPaletteLUT(lst); } { auto palette=JKQTPMathImagePU_OR; QString palN="PuOr"; QString palNT=QObject::tr("PuOr"); lutstore[palette]=JKQTPImageTools::LUTData(palN, palNT); QList > lst; lst<(0.0, 0xFFB35806); lst<(1.0, 0xFFE08214); lst<(2.0, 0xFFFDB863); lst<(3.0, 0xFFFEE0B6); lst<(4.0, 0xFFF7F7F7); lst<(5.0, 0xFFD8DAEB); lst<(6.0, 0xFFB2ABD2); lst<(7.0, 0xFF8073AC); lst<(8.0, 0xFF542788); lutstore[palette].lut=JKQTPBuildColorPaletteLUTLinInterpolate(lst); } { auto palette=JKQTPMathImagePU_OR_STEP; QString palN="stepsPuOr"; QString palNT=QObject::tr("steps: PuOr"); lutstore[palette]=JKQTPImageTools::LUTData(palN, palNT); QList > lst; lst<(0.0, 0xFFB35806); lst<(1.0, 0xFFE08214); lst<(2.0, 0xFFFDB863); lst<(3.0, 0xFFFEE0B6); lst<(4.0, 0xFFF7F7F7); lst<(5.0, 0xFFD8DAEB); lst<(6.0, 0xFFB2ABD2); lst<(7.0, 0xFF8073AC); lst<(8.0, 0xFF542788); lutstore[palette].lut=JKQTPBuildColorPaletteLUT(lst); } { auto palette=JKQTPMathImageYL_GN_BU; QString palN="YeGnBu"; QString palNT=QObject::tr("YeGnBu"); lutstore[palette]=JKQTPImageTools::LUTData(palN, palNT); QList > lst; lst<(0.0, 0xFFFFFFD9); lst<(1.0, 0xFFEDF8B1); lst<(2.0, 0xFFC7E9B4); lst<(3.0, 0xFF7FCDBB); lst<(4.0, 0xFF41B6C4); lst<(5.0, 0xFF1D91C0); lst<(6.0, 0xFF225EA8); lst<(7.0, 0xFF253494); lst<(8.0, 0xFF081D58); lutstore[palette].lut=JKQTPBuildColorPaletteLUTLinInterpolate(lst); } { auto palette=JKQTPMathImageYL_GN_BU_STEP; QString palN="stepsYeGnBu"; QString palNT=QObject::tr("steps: YeGnBu"); lutstore[palette]=JKQTPImageTools::LUTData(palN, palNT); QList > lst; lst<(0.0, 0xFFFFFFD9); lst<(1.0, 0xFFEDF8B1); lst<(2.0, 0xFFC7E9B4); lst<(3.0, 0xFF7FCDBB); lst<(4.0, 0xFF41B6C4); lst<(5.0, 0xFF1D91C0); lst<(6.0, 0xFF225EA8); lst<(7.0, 0xFF253494); lst<(8.0, 0xFF081D58); lutstore[palette].lut=JKQTPBuildColorPaletteLUT(lst); } { auto palette=JKQTPMathImageGN_BU; QString palN="greenblue"; QString palNT=QObject::tr("green-blue"); lutstore[palette]=JKQTPImageTools::LUTData( palN, palNT); QList > lst; lst<(0.0, 0xFFF7FCF0); lst<(1.0, 0xFFE0F3DB); lst<(2.0, 0xFFCCEBC5); lst<(3.0, 0xFFA8DDB5); lst<(4.0, 0xFF7BCCC4); lst<(5.0, 0xFF4EB3D3); lst<(6.0, 0xFF2B8CBE); lst<(7.0, 0xFF0868AC); lst<(8.0, 0xFF084081); lutstore[palette].lut=JKQTPBuildColorPaletteLUTLinInterpolate(lst); } { auto palette=JKQTPMathImageGN_BU_STEP; QString palN="stepsGnBl"; QString palNT=QObject::tr("steps: green-blue"); lutstore[palette]=JKQTPImageTools::LUTData( palN, palNT); QList > lst; lst<(0.0, 0xFFF7FCF0); lst<(1.0, 0xFFE0F3DB); lst<(2.0, 0xFFCCEBC5); lst<(3.0, 0xFFA8DDB5); lst<(4.0, 0xFF7BCCC4); lst<(5.0, 0xFF4EB3D3); lst<(6.0, 0xFF2B8CBE); lst<(7.0, 0xFF0868AC); lst<(8.0, 0xFF084081); lutstore[palette].lut=JKQTPBuildColorPaletteLUT(lst); } { auto palette=JKQTPMathImageBU_GN; QString palN="bluegreen"; QString palNT=QObject::tr("blue-green"); lutstore[palette]=JKQTPImageTools::LUTData(palN, palNT); QList > lst; lst<(8.0, 0xFFF7FCF0); lst<(7.0, 0xFFE0F3DB); lst<(6.0, 0xFFCCEBC5); lst<(5.0, 0xFFA8DDB5); lst<(4.0, 0xFF7BCCC4); lst<(3.0, 0xFF4EB3D3); lst<(2.0, 0xFF2B8CBE); lst<(1.0, 0xFF0868AC); lst<(0.0, 0xFF084081); lutstore[palette].lut=JKQTPBuildColorPaletteLUTLinInterpolate(lst); } { auto palette=JKQTPMathImageBU_GN_STEP; QString palN="stepsBlGn"; QString palNT=QObject::tr("steps: blue-green"); lutstore[palette]=JKQTPImageTools::LUTData(palN, palNT); QList > lst; lst<(8.0, 0xFFF7FCF0); lst<(7.0, 0xFFE0F3DB); lst<(6.0, 0xFFCCEBC5); lst<(5.0, 0xFFA8DDB5); lst<(4.0, 0xFF7BCCC4); lst<(3.0, 0xFF4EB3D3); lst<(2.0, 0xFF2B8CBE); lst<(1.0, 0xFF0868AC); lst<(0.0, 0xFF084081); lutstore[palette].lut=JKQTPBuildColorPaletteLUT(lst); } { auto palette=JKQTPMathImageINVERTED_MAGENTA; QString palN="invmagenta"; QString palNT=QObject::tr("inv. magenta"); lutstore[palette]=JKQTPImageTools::LUTData(QVector(JKQTPImageTools::LUTSIZE+1, 0), palN, palNT); QRgb* plut=lutstore[palette].lut.data(); //std::cout<<"!!! creating rainbow lut\n"; if (plut!=nullptr) { for (int l=0; l<=JKQTPImageTools::LUTSIZE; l++) { double v=(l)/static_cast(JKQTPImageTools::LUTSIZE); plut[l]=QColor::fromCmykF(0,1,0,v).rgba(); } } } { auto palette=JKQTPMathImageMAGENTA; QString palN="magenta"; QString palNT=QObject::tr("magenta"); lutstore[palette]=JKQTPImageTools::LUTData(QVector(JKQTPImageTools::LUTSIZE+1, 0), palN, palNT); QRgb* plut=lutstore[palette].lut.data(); //std::cout<<"!!! creating rainbow lut\n"; if (plut!=nullptr) { for (int l=0; l<=JKQTPImageTools::LUTSIZE; l++) { double v=(JKQTPImageTools::LUTSIZE-l)/static_cast(JKQTPImageTools::LUTSIZE); plut[l]=QColor::fromCmykF(0,1,0,v).rgba(); } } } { auto palette=JKQTPMathImageINVERTED_YELLOW; QString palN="invyellow"; QString palNT=QObject::tr("inv. yellow"); lutstore[palette]=JKQTPImageTools::LUTData(QVector(JKQTPImageTools::LUTSIZE+1, 0), palN, palNT); QRgb* plut=lutstore[palette].lut.data(); //std::cout<<"!!! creating rainbow lut\n"; if (plut!=nullptr) { for (int l=0; l<=JKQTPImageTools::LUTSIZE; l++) { double v=(l)/static_cast(JKQTPImageTools::LUTSIZE); plut[l]=QColor::fromCmykF(0,0,1,v).rgba(); } } } { auto palette=JKQTPMathImageYELLOW; QString palN="yellow"; QString palNT=QObject::tr("yellow"); lutstore[palette]=JKQTPImageTools::LUTData(QVector(JKQTPImageTools::LUTSIZE+1, 0), palN, palNT); QRgb* plut=lutstore[palette].lut.data(); //std::cout<<"!!! creating rainbow lut\n"; if (plut!=nullptr) { for (int l=0; l<=JKQTPImageTools::LUTSIZE; l++) { double v=(JKQTPImageTools::LUTSIZE-l)/static_cast(JKQTPImageTools::LUTSIZE); plut[l]=QColor::fromCmykF(0,0,1,v).rgba(); } } } { auto palette=JKQTPMathImageINVERTED_MAGENTAWHITE; QString palN="whitemagenta"; QString palNT=QObject::tr("white-magenta"); lutstore[palette]=JKQTPImageTools::LUTData(QVector(JKQTPImageTools::LUTSIZE+1, 0), palN, palNT); QRgb* plut=lutstore[palette].lut.data(); //std::cout<<"!!! creating rainbow lut\n"; if (plut!=nullptr) { for (int l=0; l<=JKQTPImageTools::LUTSIZE; l++) { double v=(l)/static_cast(JKQTPImageTools::LUTSIZE); plut[l]=QColor::fromCmykF(0,v,0,0).rgba(); } } } { auto palette=JKQTPMathImageMAGENTAWHITE; QString palN="magentawhite"; QString palNT=QObject::tr("magenta-white"); lutstore[palette]=JKQTPImageTools::LUTData(QVector(JKQTPImageTools::LUTSIZE+1, 0), palN, palNT); QRgb* plut=lutstore[palette].lut.data(); //std::cout<<"!!! creating rainbow lut\n"; if (plut!=nullptr) { for (int l=0; l<=JKQTPImageTools::LUTSIZE; l++) { double v=(JKQTPImageTools::LUTSIZE-l)/static_cast(JKQTPImageTools::LUTSIZE); plut[l]=QColor::fromCmykF(0,v,0,0).rgba(); } } } { auto palette=JKQTPMathImageINVERTED_YELLOWWHITE; QString palN="whiteyellow"; QString palNT=QObject::tr("white-yellow"); lutstore[palette]=JKQTPImageTools::LUTData(QVector(JKQTPImageTools::LUTSIZE+1, 0), palN, palNT); QRgb* plut=lutstore[palette].lut.data(); //std::cout<<"!!! creating rainbow lut\n"; if (plut!=nullptr) { for (int l=0; l<=JKQTPImageTools::LUTSIZE; l++) { double v=(l)/static_cast(JKQTPImageTools::LUTSIZE); plut[l]=QColor::fromCmykF(0,0,v,0).rgba(); } } } { auto palette=JKQTPMathImageYELLOWWHITE; QString palN="yellowwhite"; QString palNT=QObject::tr("yellow-white"); lutstore[palette]=JKQTPImageTools::LUTData(QVector(JKQTPImageTools::LUTSIZE+1, 0), palN, palNT); QRgb* plut=lutstore[palette].lut.data(); //std::cout<<"!!! creating rainbow lut\n"; if (plut!=nullptr) { for (int l=0; l<=JKQTPImageTools::LUTSIZE; l++) { double v=(JKQTPImageTools::LUTSIZE-l)/static_cast(JKQTPImageTools::LUTSIZE); plut[l]=QColor::fromCmykF(0,0,v,0).rgba(); } } } { auto palette=JKQTPMathImageINVERTED_CYANWHITE; QString palN="whitecyan"; QString palNT=QObject::tr("white-cyan"); lutstore[palette]=JKQTPImageTools::LUTData(QVector(JKQTPImageTools::LUTSIZE+1, 0), palN, palNT); QRgb* plut=lutstore[palette].lut.data(); //std::cout<<"!!! creating rainbow lut\n"; if (plut!=nullptr) { for (int l=0; l<=JKQTPImageTools::LUTSIZE; l++) { double v=(l)/static_cast(JKQTPImageTools::LUTSIZE); plut[l]=QColor::fromCmykF(v,0,0,0).rgba(); } } } { auto palette=JKQTPMathImageCYANWHITE; QString palN="cyanwhite"; QString palNT=QObject::tr("cyan-white"); lutstore[palette]=JKQTPImageTools::LUTData(QVector(JKQTPImageTools::LUTSIZE+1, 0), palN, palNT); QRgb* plut=lutstore[palette].lut.data(); //std::cout<<"!!! creating rainbow lut\n"; if (plut!=nullptr) { for (int l=0; l<=JKQTPImageTools::LUTSIZE; l++) { double v=(JKQTPImageTools::LUTSIZE-l)/static_cast(JKQTPImageTools::LUTSIZE); plut[l]=QColor::fromCmykF(v,0,0,0).rgba(); } } } { auto palette=JKQTPMathImageBlueGreenRed; QString palN="bluegreenred"; QString palNT=QObject::tr("blue-green-red"); lutstore[palette]=JKQTPImageTools::LUTData( palN, palNT); QList > lst; lst<(1.0, QColor("blue").rgb()); lst<(2.0, QColor("green").rgb()); lst<(3.0, QColor("red").rgb()); lutstore[palette].lut=JKQTPBuildColorPaletteLUTLinInterpolate(lst); } { auto palette=JKQTPMathImageRedGreenBlue; QString palN="redgreenblue"; QString palNT=QObject::tr("red-green-blue"); lutstore[palette]=JKQTPImageTools::LUTData( palN, palNT); QList > lst; lst<(1.0, QColor("red").rgb()); lst<(2.0, QColor("green").rgb()); lst<(3.0, QColor("blue").rgb()); lutstore[palette].lut=JKQTPBuildColorPaletteLUTLinInterpolate(lst); } { auto palette=JKQTPMathImageMagentaYellow; QString palN="magentayellow"; QString palNT=QObject::tr("magenta-yellow"); lutstore[palette]=JKQTPImageTools::LUTData( palN, palNT); QList > lst; lst<(1.0, QColor("magenta").rgb()); lst<(2.0, QColor("yellow").rgb()); lutstore[palette].lut=JKQTPBuildColorPaletteLUTLinInterpolate(lst); } { auto palette=JKQTPMathImageYellowMagenta; QString palN="yellowmagenta"; QString palNT=QObject::tr("yellow-magenta"); lutstore[palette]=JKQTPImageTools::LUTData( palN, palNT); QList > lst; lst<(1.0, QColor("yellow").rgb()); lst<(2.0, QColor("magenta").rgb()); lutstore[palette].lut=JKQTPBuildColorPaletteLUTLinInterpolate(lst); } { auto palette=JKQTPMathImageRedBlue; QString palN="redblue"; QString palNT=QObject::tr("red-blue"); lutstore[palette]=JKQTPImageTools::LUTData(palN, palNT); QList > lst; lst<(1.0, QColor("red").rgb()); lst<(2.0, QColor("blue").rgb()); lutstore[palette].lut=JKQTPBuildColorPaletteLUTLinInterpolate(lst); } { auto palette=JKQTPMathImageBlueRed; QString palN="bluered"; QString palNT=QObject::tr("blue-red"); lutstore[palette]=JKQTPImageTools::LUTData( palN, palNT); QList > lst; lst<(1.0, QColor("blue").rgb()); lst<(2.0, QColor("red").rgb()); lutstore[palette].lut=JKQTPBuildColorPaletteLUTLinInterpolate(lst); } { auto palette=JKQTPMathImageSeismic; QString palN="seismic"; QString palNT=QObject::tr("seismic"); lutstore[palette]=JKQTPImageTools::LUTData( palN, palNT); QList > lst; lst<(0, QColor::fromRgbF(0.0, 0.0, 0.3).rgb()); lst<(1, QColor::fromRgbF(0.0, 0.0, 1.0).rgb()); lst<(2, QColor::fromRgbF(1.0, 1.0, 1.0).rgb()); lst<(3, QColor::fromRgbF(1.0, 0.0, 0.0).rgb()); lst<(4, QColor::fromRgbF(0.5, 0.0, 0.0).rgb()); lutstore[palette].lut=JKQTPBuildColorPaletteLUTLinInterpolate(lst); } { auto palette=JKQTPMathImageTerrain; QString palN="terrain"; QString palNT=QObject::tr("terrain"); lutstore[palette]=JKQTPImageTools::LUTData( palN, palNT); QList > lst; lst<(0.00, QColor::fromRgbF(0.2, 0.2, 0.6).rgb()); lst<(0.15, QColor::fromRgbF(0.0, 0.6, 1.0).rgb()); lst<(0.25, QColor::fromRgbF(0.0, 0.8, 0.4).rgb()); lst<(0.50, QColor::fromRgbF(1.0, 1.0, 0.6).rgb()); lst<(0.75, QColor::fromRgbF(0.5, 0.36, 0.33).rgb()); lst<(1.00, QColor::fromRgbF(1.0, 1.0, 1.0).rgb()); lutstore[palette].lut=JKQTPBuildColorPaletteLUTLinInterpolate(lst); } { auto palette=JKQTPMathImageBone; QString palN="bone"; QString palNT=QObject::tr("bone"); lutstore[palette]=JKQTPImageTools::LUTData( palN, palNT); QList lstR,lstG,lstB; lstR< lstR,lstG,lstB; lstR< lstR,lstG,lstB; lstR< lstR,lstG,lstB; lstR< &s1, const QPair &s2) { return s1.first > items, int lut_size) { qSort(items.begin(), items.end(), JKQTPBuildColorPaletteLUTLessThan); return JKQTPBuildColorPaletteLUTLinInterpolateSorted(items, lut_size); } JKQTPImageTools::LUTType JKQTPBuildColorPaletteLUT(QList > items, int lut_size) { qSort(items.begin(), items.end(), JKQTPBuildColorPaletteLUTLessThan); return JKQTPBuildColorPaletteLUTSorted(items, lut_size); } JKQTPImageTools::LUTType JKQTPBuildColorPaletteLUTLinSegments( QList itemsR, QList itemsG, QList itemsB, int lut_size) { qSort(itemsR.begin(), itemsR.end(), JKQTPBuildColorPaletteLUTLinSegLessThan); qSort(itemsG.begin(), itemsG.end(), JKQTPBuildColorPaletteLUTLinSegLessThan); qSort(itemsB.begin(), itemsB.end(), JKQTPBuildColorPaletteLUTLinSegLessThan); return JKQTPBuildColorPaletteLUTLinSegmentsSorted(itemsR, itemsG, itemsB, lut_size); } JKQTPImageTools::LUTType JKQTPBuildColorPaletteLUTLinSegmentsSorted(const QList &itemsR, const QList &itemsG, const QList &itemsB, int lut_size) { JKQTPImageTools::LUTType lut(lut_size, qRgb(255,255,255)); if (itemsR.size()<=0 && itemsG.size()<=0 && itemsB.size()<=0) return lut; auto buildChannel=[](JKQTPImageTools::LUTType& lut, const QList &items, int channel) { if (items.size()==1) { for (int i=0; i(lut.size()-2); double v=dmin; int j1=0; for (int i=0; i(static_cast(items[j2].colval_endprevious-items[j1].colval_startnext)*local_relV); JKQTPSetColorChannel(lut[i], channel, jkqtp_bounded(0, newCol, 255)); //qDebug()<<"i="< lut[i]=0x"<=items[j1].position && v>=items[j2].position && j1(0, items.last().colval_endprevious, 255)); } }; buildChannel(lut, itemsR, 0); buildChannel(lut, itemsG, 1); buildChannel(lut, itemsB, 2); return lut; } JKQTPImageTools::LUTType JKQTPBuildColorPaletteLUTLinInterpolateSorted(const QList > &items, int lut_size) { JKQTPImageTools::LUTType lut(lut_size, 0); if (items.size()<=1) return lut; double dmin=items.first().first; double dmax=items.last().first; double delta=(dmax-dmin)/static_cast(lut_size-2); double v=dmin; int j1=0; for (int i=0; i(r), static_cast(g), static_cast(b)); v+=delta; // advance over items, if v crosses items[j2].first while (v>=items[j1].first && v>=items[j2].first && j1 > &items, int lut_size) { JKQTPImageTools::LUTType lut(lut_size+1, 0); double dmin=items.first().first; double dmax=items.last().first; double delta=(dmax-dmin)/double(lut_size); int i=0; int j=0; for (double v=dmin; v<=dmax; v=v+delta) { double r=0; double g=0; double b=0; if (j+1=items[j+1].first) j++; } if (i<=lut_size) lut[i]=qRgb(static_cast(r), static_cast(g), static_cast(b)); i++; } return lut; } JKQTPImageTools::LUTType JKQTPBuildColorPaletteLUTLinInterpolate(const QMap &items, int lut_size) { QList > itemsi; for (auto it=items.begin(); it!=items.end(); ++it) { itemsi.append(qMakePair(it.key(), it.value())); } return JKQTPBuildColorPaletteLUTLinInterpolateSorted(itemsi, lut_size); } JKQTPImageTools::LUTType JKQTPBuildColorPaletteLUT(const QMap &items, int lut_size) { QList > itemsi; for (auto it=items.begin(); it!=items.end(); ++it) { itemsi.append(qMakePair(it.key(), it.value())); } return JKQTPBuildColorPaletteLUTSorted(itemsi, lut_size); } double JKQTPImagePlot_QStringToDouble(QString value) { QString v=value; if (value.contains(',')) { v=value.replace(',', '.'); } QLocale loc=QLocale::c(); loc.setNumberOptions(QLocale::OmitGroupSeparator); return loc.toDouble(v) ; } template bool JKQTPImagePlot_QPairCompareFirst(const QPair &s1, const QPair &s2) { return s1.first < s2.first; } QStringList JKQTPImageTools::getPredefinedPalettes() { static QStringList sl; if (sl.size()!=JKQTPImageTools::global_jkqtpimagetools_lutstore.size()) { sl.clear(); for (auto it=JKQTPImageTools::global_jkqtpimagetools_lutstore.begin(); it!=JKQTPImageTools::global_jkqtpimagetools_lutstore.end(); ++it) { if (it.key()>=0 && it.key()<=JKQTPMathImageLAST_POSSIBLE_REGISTERED_USER_PALETTE) { if (it.value().nameT.size()!=0) sl<=0) { if (it.value().name.size()!=0) sl<(p)); else { if (it.value().name.size()>0) return it.value().name; else return QString::number(static_cast(p)); } } JKQTPMathImageColorPalette JKQTPImageTools::String2JKQTPMathImageColorPalette(const QString &p) { for (auto it=JKQTPImageTools::global_jkqtpimagetools_lutstore.begin(); it!=JKQTPImageTools::global_jkqtpimagetools_lutstore.end(); ++it) { if (QString::compare(p, it.value().name, Qt::CaseInsensitive)==0) { return static_cast(it.key()); } } for (auto it=JKQTPImageTools::global_jkqtpimagetools_lutstore.begin(); it!=JKQTPImageTools::global_jkqtpimagetools_lutstore.end(); ++it) { if (QString::compare(p, it.value().nameT, Qt::CaseInsensitive)==0) { return static_cast(it.key()); } } bool ok=false; JKQTPMathImageColorPalette res = static_cast(p.toInt(&ok)); if (!ok) return JKQTPMathImageMATLAB; else return res; } const JKQTPImageTools::LUTType& JKQTPImageTools::getLUTforPalette(QMap& lutstore, JKQTPMathImageColorPalette palette) { static JKQTPImageTools::LUTType empty(JKQTPImageTools::LUTSIZE, 0); auto it=lutstore.find(static_cast(palette)); if (it==lutstore.end()) { return empty; } else { return it.value().lut; } } QImage JKQTPImageTools::GetPaletteImage(int i, int width) { return JKQTPImageTools::GetPaletteImage(i, width, 1); } QImage JKQTPImageTools::GetPaletteImage(int i, int width, int height) { QImage img; QVector pic(width*height,0); for (int j=0; j(pic.data(), width, height, img, static_cast(i), Qt::black, Qt::black); return img; } QImage JKQTPImageTools::GetPaletteImage(JKQTPMathImageColorPalette palette, int width) { return JKQTPImageTools::GetPaletteImage(static_cast(palette), width); } QImage JKQTPImageTools::GetPaletteImage(JKQTPMathImageColorPalette palette, int width, int height) { return JKQTPImageTools::GetPaletteImage(static_cast(palette), width, height); } QImage JKQTPImageTools::GetPaletteImage(const JKQTPImageTools::LUTType& lut, int width) { QImage img; QVector pic(width); for (int j=0; j(pic.data(), pic.size(), 1, img, lut, Qt::black, Qt::black); return img; } QIcon JKQTPImageTools::GetPaletteIcon(int i) { QImage img=JKQTPImageTools::GetPaletteImage(i, JKQTPImageTools::PALETTE_ICON_WIDTH); QPixmap pix(JKQTPImageTools::PALETTE_ICON_WIDTH,8); QRect r(0,0,JKQTPImageTools::PALETTE_ICON_WIDTH-1,7); QPainter p(&pix); p.drawImage(r, img); p.setPen(QPen(QColor("black"))); p.drawRect(r); p.end(); return QIcon(pix); } QIcon JKQTPImageTools::GetPaletteIcon(JKQTPMathImageColorPalette palette) { return JKQTPImageTools::GetPaletteIcon(static_cast(palette)); } int JKQTPImageTools::registerPalette(const QString &name, const JKQTPImageTools::LUTType &paletteLut, const QString &nameT) { int id=JKQTPImageTools::global_next_userpalette++; JKQTPImageTools::global_jkqtpimagetools_lutstore[id].name=name; JKQTPImageTools::global_jkqtpimagetools_lutstore[id].nameT=((nameT.size()>0)?nameT:name); JKQTPImageTools::global_jkqtpimagetools_lutstore[id].lut=paletteLut; return id; } QVector JKQTPImageTools::registerPalettesFromFile(const QString &filename, bool interpolatePalette) { QVector ids; QString ext=QFileInfo(filename).suffix().toLower(); if (ext=="rgb" || ext=="pal" || ext=="csv") { QFile file(filename); if (file.open(QIODevice::ReadOnly|QIODevice::Text)) { QString txt=file.readAll(); QStringList slt=txt.split('\n'); bool has4=false; bool rgb255=false; QList > pal; QRegExp rx3("\\s*([0-9eE.+-]+)\\s*([,\\t ])\\s*([0-9eE.+-]+)\\s*\\2\\s*([0-9eE.+-]+)\\s*", Qt::CaseInsensitive); rx3.setMinimal(false); QRegExp rx4("\\s*([0-9eE.+-]+)\\s*([,\\t ])\\s*([0-9eE.+-]+)\\s*\\2\\s*([0-9eE.+-]+)\\s*\\2\\s*([0-9eE.+-]+)\\s*", Qt::CaseInsensitive); rx4.setMinimal(false); // determine format for (int i=slt.size()-1; i>=0; i--) { slt[i]=slt[i].trimmed(); if (rx4.indexIn(slt[i])>=0) { has4=true; double r=JKQTPImagePlot_QStringToDouble(rx4.cap(3)); double g=JKQTPImagePlot_QStringToDouble(rx4.cap(4)); double b=JKQTPImagePlot_QStringToDouble(rx4.cap(5)); if (r>1.0 || g>1.0 || b>1.0) { rgb255=true; } } else if (rx3.indexIn(slt[i])>=0) { has4=false; double r=JKQTPImagePlot_QStringToDouble(rx3.cap(1)); double g=JKQTPImagePlot_QStringToDouble(rx3.cap(3)); double b=JKQTPImagePlot_QStringToDouble(rx3.cap(4)); if (r>1.0 || g>1.0 || b>1.0) { rgb255=true; } } else { slt.removeAt(i); } } // read data bool ok=true; for (int i=0; i=0) { x=JKQTPImagePlot_QStringToDouble(rx4.cap(1)); r=JKQTPImagePlot_QStringToDouble(rx4.cap(3)); g=JKQTPImagePlot_QStringToDouble(rx4.cap(4)); b=JKQTPImagePlot_QStringToDouble(rx4.cap(5)); } else if (!has4 && rx3.indexIn(slt[i])>=0) { x=i; r=JKQTPImagePlot_QStringToDouble(rx3.cap(1)); g=JKQTPImagePlot_QStringToDouble(rx3.cap(3)); b=JKQTPImagePlot_QStringToDouble(rx3.cap(4)); //qDebug()<(round(255*r)), 255), qBound(0,static_cast(round(255*g)), 255), qBound(0,static_cast(round(255*b)), 255))); } else { pal<(round(r)), 255), qBound(0,static_cast(round(g)), 255), qBound(0,static_cast(round(b)), 255))); } } } if (ok && pal.size()>1) { if (interpolatePalette) ids< > pal; if (colorspace=="rgb"){ QDomElement e = n.firstChildElement("Point"); while(!e.isNull()) { double x=JKQTPImagePlot_QStringToDouble(e.attribute("x", "0")); double r=JKQTPImagePlot_QStringToDouble(e.attribute("r", "0")); double g=JKQTPImagePlot_QStringToDouble(e.attribute("g", "0")); double b=JKQTPImagePlot_QStringToDouble(e.attribute("b", "0")); pal<(round(255*r)), 255), qBound(0,static_cast(round(255*g)), 255), qBound(0,static_cast(round(255*b)), 255))); e = e.nextSiblingElement("Point"); } if (pal.size()>1) { if (interpolatePalette) ids<(0, y1*255.0, 255), jkqtp_boundedRoundTo(0, y2*255.0, 255)); } JKQTPColorPaletteSingleColorLinSegment::JKQTPColorPaletteSingleColorLinSegment(): position(0), colval_endprevious(0), colval_startnext(0) { } JKQTPMathImageModifierMode StringToModifierMode(const QString &mode) { QString m=mode.toLower(); if (m=="value" ) return JKQTPMathImageModifierMode::ModifyValue; if (m=="saturation" ) return JKQTPMathImageModifierMode::ModifySaturation; if (m=="alpha" ) return JKQTPMathImageModifierMode::ModifyAlpha; if (m=="luminance" ) return JKQTPMathImageModifierMode::ModifyLuminance; if (m=="hue" ) return JKQTPMathImageModifierMode::ModifyHue; return JKQTPMathImageModifierMode::ModifyNone; } QString ModifierModeToString(const JKQTPMathImageModifierMode &mode) { if (mode==JKQTPMathImageModifierMode::ModifyValue) return "value"; if (mode==JKQTPMathImageModifierMode::ModifySaturation) return "saturation"; if (mode==JKQTPMathImageModifierMode::ModifyAlpha) return "alpha"; if (mode==JKQTPMathImageModifierMode::ModifyLuminance) return "luminance"; if (mode==JKQTPMathImageModifierMode::ModifyHue) return "hue"; return "none"; } void JKQTPModifyImage(QImage &img, JKQTPMathImageModifierMode modifierMode, void *dataModifier, JKQTPMathImageDataType datatypeModifier, int Nx, int Ny, double internalModifierMin, double internalModifierMax) { if (!dataModifier) return; //getModifierMinMax(internalModifierMin, internalModifierMax); if (modifierMode!=JKQTPMathImageModifierMode::ModifyNone) { JKQTPRGBMathImageRGBMode rgbModMode=JKQTPRGBMathImageModeRGBMode; int modChannel=3; if (modifierMode==JKQTPMathImageModifierMode::ModifyValue) { modChannel=2; rgbModMode=JKQTPRGBMathImageModeHSVMode; } else if (modifierMode==JKQTPMathImageModifierMode::ModifySaturation) { modChannel=1; rgbModMode=JKQTPRGBMathImageModeHSVMode; } else if (modifierMode==JKQTPMathImageModifierMode::ModifyAlpha) { modChannel=3; rgbModMode=JKQTPRGBMathImageModeRGBMode; } else if (modifierMode==JKQTPMathImageModifierMode::ModifyLuminance) { modChannel=2; rgbModMode=JKQTPRGBMathImageModeHSLMode; } else if (modifierMode==JKQTPMathImageModifierMode::ModifyHue) { modChannel=0; rgbModMode=JKQTPRGBMathImageModeHSLMode; } //qDebug()<<"mod: "<(static_cast(dataModifier), Nx, Ny, img, modChannel, internalModifierMin, internalModifierMax, rgbModMode); break; case JKQTPMathImageDataType::FloatArray: JKQTPImagePlot_array2RGBimage(static_cast(dataModifier), Nx, Ny, img, modChannel, internalModifierMin, internalModifierMax, rgbModMode); break; case JKQTPMathImageDataType::UInt8Array: JKQTPImagePlot_array2RGBimage(static_cast(dataModifier), Nx, Ny, img, modChannel, internalModifierMin, internalModifierMax, rgbModMode); break; case JKQTPMathImageDataType::UInt16Array: JKQTPImagePlot_array2RGBimage(static_cast(dataModifier), Nx, Ny, img, modChannel, internalModifierMin, internalModifierMax, rgbModMode); break; case JKQTPMathImageDataType::UInt32Array: JKQTPImagePlot_array2RGBimage(static_cast(dataModifier), Nx, Ny, img, modChannel, internalModifierMin, internalModifierMax, rgbModMode); break; case JKQTPMathImageDataType::UInt64Array: JKQTPImagePlot_array2RGBimage(static_cast(dataModifier), Nx, Ny, img, modChannel, internalModifierMin, internalModifierMax, rgbModMode); break; case JKQTPMathImageDataType::Int8Array: JKQTPImagePlot_array2RGBimage(static_cast(dataModifier), Nx, Ny, img, modChannel, internalModifierMin, internalModifierMax, rgbModMode); break; case JKQTPMathImageDataType::Int16Array: JKQTPImagePlot_array2RGBimage(static_cast(dataModifier), Nx, Ny, img, modChannel, internalModifierMin, internalModifierMax, rgbModMode); break; case JKQTPMathImageDataType::Int32Array: JKQTPImagePlot_array2RGBimage(static_cast(dataModifier), Nx, Ny, img, modChannel, internalModifierMin, internalModifierMax, rgbModMode); break; case JKQTPMathImageDataType::Int64Array: JKQTPImagePlot_array2RGBimage(static_cast(dataModifier), Nx, Ny, img, modChannel, internalModifierMin, internalModifierMax, rgbModMode); break; } } }