Warning, file /office/calligra/libs/pigment/KoCompositeOpRegistry.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* 0002 * Copyright (c) 2005 Adrian Page <adrian@pagenet.plus.com> 0003 * 0004 * This library is free software; you can redistribute it and/or 0005 * modify it under the terms of the GNU Lesser General Public 0006 * License as published by the Free Software Foundation; either 0007 * version 2.1 of the License, or (at your option) any later version. 0008 * 0009 * This library is distributed in the hope that it will be useful, 0010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0012 * Lesser General Public License for more details. 0013 * 0014 * You should have received a copy of the GNU Lesser General Public License 0015 * along with this library; see the file COPYING.LIB. If not, write to 0016 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0017 * Boston, MA 02110-1301, USA. 0018 */ 0019 0020 #include "KoCompositeOpRegistry.h" 0021 0022 #include <QGlobalStatic> 0023 #include <QList> 0024 0025 #include <klocalizedstring.h> 0026 0027 #include <KoID.h> 0028 #include "KoCompositeOp.h" 0029 #include "KoColorSpace.h" 0030 0031 #include <algorithm> 0032 0033 Q_GLOBAL_STATIC(KoCompositeOpRegistry, registry) 0034 0035 0036 KoCompositeOpRegistry::KoCompositeOpRegistry() 0037 { 0038 m_categories 0039 << KoID("arithmetic", i18n("Arithmetic")) 0040 << KoID("dark" , i18n("Darken")) 0041 << KoID("light" , i18n("Lighten")) 0042 << KoID("negative" , i18n("Negative")) 0043 << KoID("mix" , i18n("Mix")) 0044 << KoID("misc" , i18n("Misc")) 0045 << KoID("hsy" , i18n("HSY")) 0046 << KoID("hsi" , i18n("HSI")) 0047 << KoID("hsl" , i18n("HSL")) 0048 << KoID("hsv" , i18n("HSV")); 0049 0050 m_map.insert(m_categories[0], KoID(COMPOSITE_ADD , i18n("Addition"))); 0051 m_map.insert(m_categories[0], KoID(COMPOSITE_SUBTRACT , i18n("Subtract"))); 0052 m_map.insert(m_categories[0], KoID(COMPOSITE_MULT , i18n("Multiply"))); 0053 m_map.insert(m_categories[0], KoID(COMPOSITE_DIVIDE , i18n("Divide"))); 0054 m_map.insert(m_categories[0], KoID(COMPOSITE_INVERSE_SUBTRACT, i18n("Inverse Subtract"))); 0055 0056 m_map.insert(m_categories[1], KoID(COMPOSITE_BURN , i18n("Burn"))); 0057 m_map.insert(m_categories[1], KoID(COMPOSITE_LINEAR_BURN, i18n("Linear Burn"))); 0058 m_map.insert(m_categories[1], KoID(COMPOSITE_DARKEN , i18n("Darken"))); 0059 m_map.insert(m_categories[1], KoID(COMPOSITE_GAMMA_DARK , i18n("Gamma Dark"))); 0060 m_map.insert(m_categories[1], KoID(COMPOSITE_DARKER_COLOR , i18n("Darker Color"))); 0061 0062 m_map.insert(m_categories[2], KoID(COMPOSITE_DODGE , i18n("Color Dodge"))); 0063 m_map.insert(m_categories[2], KoID(COMPOSITE_LINEAR_DODGE, i18n("Linear Dodge"))); 0064 m_map.insert(m_categories[2], KoID(COMPOSITE_LIGHTEN , i18n("Lighten"))); 0065 m_map.insert(m_categories[2], KoID(COMPOSITE_LINEAR_LIGHT, i18n("Linear Light"))); 0066 m_map.insert(m_categories[2], KoID(COMPOSITE_SCREEN , i18n("Screen"))); 0067 m_map.insert(m_categories[2], KoID(COMPOSITE_PIN_LIGHT , i18n("Pin Light"))); 0068 m_map.insert(m_categories[2], KoID(COMPOSITE_VIVID_LIGHT , i18n("Vivid Light"))); 0069 m_map.insert(m_categories[2], KoID(COMPOSITE_HARD_LIGHT , i18n("Hard Light"))); 0070 m_map.insert(m_categories[2], KoID(COMPOSITE_SOFT_LIGHT_PHOTOSHOP, i18n("Soft Light (Photoshop)"))); 0071 m_map.insert(m_categories[2], KoID(COMPOSITE_SOFT_LIGHT_SVG, i18n("Soft Light (SVG)"))); 0072 m_map.insert(m_categories[2], KoID(COMPOSITE_GAMMA_LIGHT , i18n("Gamma Light"))); 0073 m_map.insert(m_categories[2], KoID(COMPOSITE_LIGHTER_COLOR , i18n("Lighter Color"))); 0074 0075 m_map.insert(m_categories[3], KoID(COMPOSITE_DIFF , i18n("Difference"))); 0076 m_map.insert(m_categories[3], KoID(COMPOSITE_EQUIVALENCE , i18n("Equivalence"))); 0077 m_map.insert(m_categories[3], KoID(COMPOSITE_ADDITIVE_SUBTRACTIVE, i18n("Additive Subtractive"))); 0078 m_map.insert(m_categories[3], KoID(COMPOSITE_EXCLUSION , i18n("Exclusion"))); 0079 m_map.insert(m_categories[3], KoID(COMPOSITE_ARC_TANGENT , i18n("Arcus Tangent"))); 0080 0081 m_map.insert(m_categories[4], KoID(COMPOSITE_OVER , i18n("Normal"))); 0082 m_map.insert(m_categories[4], KoID(COMPOSITE_BEHIND , i18n("Behind"))); 0083 m_map.insert(m_categories[4], KoID(COMPOSITE_GREATER , i18n("Greater"))); 0084 m_map.insert(m_categories[4], KoID(COMPOSITE_OVERLAY , i18n("Overlay"))); 0085 m_map.insert(m_categories[4], KoID(COMPOSITE_ERASE , i18n("Erase"))); 0086 m_map.insert(m_categories[4], KoID(COMPOSITE_ALPHA_DARKEN , i18n("Alpha Darken"))); 0087 m_map.insert(m_categories[4], KoID(COMPOSITE_HARD_MIX , i18n("Hard Mix"))); 0088 m_map.insert(m_categories[4], KoID(COMPOSITE_GRAIN_MERGE , i18n("Grain Merge"))); 0089 m_map.insert(m_categories[4], KoID(COMPOSITE_GRAIN_EXTRACT , i18n("Grain Extract"))); 0090 m_map.insert(m_categories[4], KoID(COMPOSITE_PARALLEL , i18n("Parallel"))); 0091 m_map.insert(m_categories[4], KoID(COMPOSITE_ALLANON , i18n("Allanon"))); 0092 m_map.insert(m_categories[4], KoID(COMPOSITE_GEOMETRIC_MEAN, i18n("Geometric Mean"))); 0093 0094 m_map.insert(m_categories[5], KoID(COMPOSITE_BUMPMAP , i18n("Bumpmap"))); 0095 m_map.insert(m_categories[5], KoID(COMPOSITE_COMBINE_NORMAL, i18n("Combine Normal Map"))); 0096 m_map.insert(m_categories[5], KoID(COMPOSITE_DISSOLVE , i18n("Dissolve"))); 0097 m_map.insert(m_categories[5], KoID(COMPOSITE_COPY_RED , i18n("Copy Red"))); 0098 m_map.insert(m_categories[5], KoID(COMPOSITE_COPY_GREEN, i18n("Copy Green"))); 0099 m_map.insert(m_categories[5], KoID(COMPOSITE_COPY_BLUE , i18n("Copy Blue"))); 0100 m_map.insert(m_categories[5], KoID(COMPOSITE_COPY , i18n("Copy"))); 0101 m_map.insert(m_categories[5], KoID(COMPOSITE_TANGENT_NORMALMAP, i18n("Tangent Normalmap"))); 0102 0103 m_map.insert(m_categories[6], KoID(COMPOSITE_COLOR , i18n("Color"))); 0104 m_map.insert(m_categories[6], KoID(COMPOSITE_HUE , i18n("Hue"))); 0105 m_map.insert(m_categories[6], KoID(COMPOSITE_SATURATION , i18n("Saturation"))); 0106 m_map.insert(m_categories[6], KoID(COMPOSITE_LUMINIZE , i18n("Luminosity"))); 0107 m_map.insert(m_categories[6], KoID(COMPOSITE_DEC_SATURATION, i18n("Decrease Saturation"))); 0108 m_map.insert(m_categories[6], KoID(COMPOSITE_INC_SATURATION, i18n("Increase Saturation"))); 0109 m_map.insert(m_categories[6], KoID(COMPOSITE_DEC_LUMINOSITY, i18n("Decrease Luminosity"))); 0110 m_map.insert(m_categories[6], KoID(COMPOSITE_INC_LUMINOSITY, i18n("Increase Luminosity"))); 0111 0112 m_map.insert(m_categories[7], KoID(COMPOSITE_COLOR_HSI , i18n("Color HSI"))); 0113 m_map.insert(m_categories[7], KoID(COMPOSITE_HUE_HSI , i18n("Hue HSI"))); 0114 m_map.insert(m_categories[7], KoID(COMPOSITE_SATURATION_HSI , i18n("Saturation HSI"))); 0115 m_map.insert(m_categories[7], KoID(COMPOSITE_INTENSITY , i18n("Intensity"))); 0116 m_map.insert(m_categories[7], KoID(COMPOSITE_DEC_SATURATION_HSI, i18n("Decrease Saturation HSI"))); 0117 m_map.insert(m_categories[7], KoID(COMPOSITE_INC_SATURATION_HSI, i18n("Increase Saturation HSI"))); 0118 m_map.insert(m_categories[7], KoID(COMPOSITE_DEC_INTENSITY , i18n("Decrease Intensity"))); 0119 m_map.insert(m_categories[7], KoID(COMPOSITE_INC_INTENSITY , i18n("Increase Intensity"))); 0120 0121 m_map.insert(m_categories[8], KoID(COMPOSITE_COLOR_HSL , i18n("Color HSL"))); 0122 m_map.insert(m_categories[8], KoID(COMPOSITE_HUE_HSL , i18n("Hue HSL"))); 0123 m_map.insert(m_categories[8], KoID(COMPOSITE_SATURATION_HSL , i18n("Saturation HSL"))); 0124 m_map.insert(m_categories[8], KoID(COMPOSITE_LIGHTNESS , i18n("Lightness"))); 0125 m_map.insert(m_categories[8], KoID(COMPOSITE_DEC_SATURATION_HSL, i18n("Decrease Saturation HSL"))); 0126 m_map.insert(m_categories[8], KoID(COMPOSITE_INC_SATURATION_HSL, i18n("Increase Saturation HSL"))); 0127 m_map.insert(m_categories[8], KoID(COMPOSITE_DEC_LIGHTNESS , i18n("Decrease Lightness"))); 0128 m_map.insert(m_categories[8], KoID(COMPOSITE_INC_LIGHTNESS , i18n("Increase Lightness"))); 0129 0130 m_map.insert(m_categories[9], KoID(COMPOSITE_COLOR_HSV , i18n("Color HSV"))); 0131 m_map.insert(m_categories[9], KoID(COMPOSITE_HUE_HSV , i18n("Hue HSV"))); 0132 m_map.insert(m_categories[9], KoID(COMPOSITE_SATURATION_HSV , i18n("Saturation HSV"))); 0133 m_map.insert(m_categories[9], KoID(COMPOSITE_VALUE , i18n("Value"))); 0134 m_map.insert(m_categories[9], KoID(COMPOSITE_DEC_SATURATION_HSV, i18n("Decrease Saturation HSV"))); 0135 m_map.insert(m_categories[9], KoID(COMPOSITE_INC_SATURATION_HSV, i18n("Increase Saturation HSV"))); 0136 m_map.insert(m_categories[9], KoID(COMPOSITE_DEC_VALUE , i18n("Decrease Value"))); 0137 m_map.insert(m_categories[9], KoID(COMPOSITE_INC_VALUE , i18n("Increase Value"))); 0138 } 0139 0140 const KoCompositeOpRegistry& KoCompositeOpRegistry::instance() 0141 { 0142 return *registry; 0143 } 0144 0145 KoID KoCompositeOpRegistry::getDefaultCompositeOp() const 0146 { 0147 return KoID(COMPOSITE_OVER, i18n("Normal")); 0148 } 0149 0150 KoID KoCompositeOpRegistry::getKoID(const QString& compositeOpID) const 0151 { 0152 KoIDMap::const_iterator itr = std::find(m_map.begin(), m_map.end(), KoID(compositeOpID)); 0153 return (itr != m_map.end()) ? *itr : KoID(); 0154 } 0155 0156 KoCompositeOpRegistry::KoIDMap KoCompositeOpRegistry::getCompositeOps() const 0157 { 0158 return m_map; 0159 } 0160 0161 KoCompositeOpRegistry::KoIDList KoCompositeOpRegistry::getCategories() const 0162 { 0163 return m_categories; 0164 } 0165 0166 KoCompositeOpRegistry::KoIDList KoCompositeOpRegistry::getCompositeOps(const KoID& category, const KoColorSpace* colorSpace) const 0167 { 0168 qint32 num = m_map.count(category); 0169 KoIDMap::const_iterator beg = m_map.find(category); 0170 KoIDMap::const_iterator end = beg + num; 0171 0172 KoIDList list; 0173 list.reserve(num); 0174 0175 if(colorSpace) { 0176 for(; beg!=end; ++beg){ 0177 if(colorSpace->hasCompositeOp(beg->id())) 0178 list.push_back(*beg); 0179 } 0180 } 0181 else { 0182 for(; beg!=end; ++beg) 0183 list.push_back(*beg); 0184 } 0185 0186 return list; 0187 } 0188 0189 KoCompositeOpRegistry::KoIDList KoCompositeOpRegistry::getCompositeOps(const KoColorSpace* colorSpace) const 0190 { 0191 KoIDMap::const_iterator beg = m_map.begin(); 0192 KoIDMap::const_iterator end = m_map.end(); 0193 0194 KoIDList list; 0195 list.reserve(m_map.size()); 0196 0197 if(colorSpace) { 0198 for(; beg!=end; ++beg){ 0199 if(colorSpace->hasCompositeOp(beg->id())) 0200 list.push_back(*beg); 0201 } 0202 } 0203 else { 0204 for(; beg!=end; ++beg) 0205 list.push_back(*beg); 0206 } 0207 0208 return list; 0209 } 0210 0211 bool KoCompositeOpRegistry::colorSpaceHasCompositeOp(const KoColorSpace* colorSpace, const KoID& compositeOp) const 0212 { 0213 return colorSpace ? colorSpace->hasCompositeOp(compositeOp.id()) : false; 0214 }