1 /* This file is part of the KDE Project 2 Copyright (C) 2002 Klaas Freitag <freitag@suse.de> 3 4 This library is free software; you can redistribute it and/or 5 modify it under the terms of the GNU Library General Public 6 License as published by the Free Software Foundation; either 7 version 2 of the License, or (at your option) any later version. 8 9 This library is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 Library General Public License for more details. 13 14 You should have received a copy of the GNU Library General Public License 15 along with this library; see the file COPYING.LIB. If not, write to 16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 17 Boston, MA 02110-1301, USA. 18 */ 19 20 #ifndef KGAMMATABLE_H 21 #define KGAMMATABLE_H 22 23 #include "kookascan_export.h" 24 25 #include <qobject.h> 26 #include <qvector.h> 27 28 /** 29 * @short A gamma table. 30 * 31 * The gamma table maps input intensity values to output values. 32 * The transfer function is defined by three parameters gamma, brightness 33 * and contrast. These values are retained internally. 34 * 35 * When the data from the table is required, either for display or for 36 * sending to the scanner, it is calculated and made available as a vector 37 * of integers. Each of these values is in the range 0..(valueRange-1). 38 * 39 * The @c gamma values specified and returned are expressed as a 40 * percentage, so 100 is a linear transfer function. Reasonable values 41 * for the gamma are within the range 30..300 (corresponding to 42 * "conventional" gamma values of 0.3..3.0). 43 * 44 * Reasonable values for the @c brightness and @c contrast are within 45 * the range -50..+50. 46 * 47 * @author Klaas Freitag 48 * @author Jonathan Marten 49 **/ 50 51 class KOOKASCAN_EXPORT KGammaTable : public QObject 52 { 53 Q_OBJECT 54 55 Q_PROPERTY(int g READ getGamma WRITE setGamma) 56 Q_PROPERTY(int c READ getContrast WRITE setContrast) 57 Q_PROPERTY(int b READ getBrightness WRITE setBrightness) 58 59 public: 60 /** 61 * Constructor. 62 * 63 * Create a new gamma table object, with default parameters or 64 * as specified. 65 * 66 * @param gamma Initial gamma value 67 * @param brightness Initial brightness value 68 * @param contrast Initial contrast value 69 * 70 * @note The data array is not allocated at this point. 71 **/ 72 explicit KGammaTable(int gamma = 100, int brightness = 0, int contrast = 0); 73 74 /** 75 * Copy constructor. 76 * 77 * @param other Gamma table to be copied 78 * 79 * @note Only the gamma/brightness/contrast parameters are copied, 80 * the data array is neither copied nor allocated. 81 **/ 82 KGammaTable(const KGammaTable &other); 83 84 /** 85 * Set all of the gamma table parameters in one operation. 86 * 87 * @param gamma New gamma value 88 * @param brightness New brightness value 89 * @param contrast New contrast value 90 **/ 91 void setAll(int gamma, int brightness, int contrast); 92 93 /** 94 * Set the gamma table parameters from a string representation. 95 * 96 * @param str String value, in the form "gamma,brightness,contrast" 97 * where each parameter is a decimal integer. 98 * 99 * @return @c true if the string format is valid. If it is not 100 * valid, then @c false is returned and the gamma table parameters 101 * will not have been changed. 102 * 103 * @see toString 104 **/ 105 bool setFromString(const QString &str); 106 107 /** 108 * Convert the gamma table parameters to a string representation. 109 * 110 * @return The string representation, in the form "gamma,brightness,contrast". 111 * 112 * @see setFromString 113 **/ 114 QString toString() const; 115 116 /** 117 * Get the current gamma value. 118 * 119 * @return The gamma value 120 **/ getGamma()121 int getGamma() const 122 { 123 return (mGamma); 124 } 125 126 /** 127 * Get the current brightness value. 128 * 129 * @return The brightness value 130 **/ getBrightness()131 int getBrightness() const 132 { 133 return (mBrightness); 134 } 135 136 /** 137 * Get the current contrast value. 138 * 139 * @return The contrast value 140 **/ getContrast()141 int getContrast() const 142 { 143 return (mContrast); 144 } 145 146 /** 147 * Get the currently allocated table size. 148 * 149 * @return The number of entries in the gamma table. If the table 150 * has not yet been calculated (i.e. @c getTable() has never been 151 * called) then the size returned will be zero. Otherwise, the size 152 * returned is the last size requested for @c getTable(), or 256 153 * if no explicit size has been requested. 154 * 155 * @see getTable 156 **/ tableSize()157 int tableSize() const 158 { 159 return (mData.size()); 160 } 161 162 /** 163 * Calculate the gamma table values. 164 * 165 * @param size Size of the table required. If not specified, then 166 * the previous size requested for the table is retained. If no 167 * explicit size has ever been requested, then 256 is assumed. 168 * 169 * @return A pointer to the array of values 170 **/ 171 const int *getTable(int size = -1); 172 173 /** 174 * The range of values that will be found in the table. 175 **/ 176 static const int valueRange = 256; 177 178 public slots: 179 /** 180 * Set a new brightness value. 181 * 182 * @param brightness New brightness value 183 **/ 184 void setBrightness(int brightness); 185 186 /** 187 * Set a new contrast value. 188 * 189 * @param contrast New contrast value 190 **/ 191 void setContrast(int contrast); 192 193 /** 194 * Set a new gamma value. 195 * 196 * @param gamma New gamma value 197 **/ 198 void setGamma(int gamma); 199 200 signals: 201 /** 202 * Emitted when any of the table parameters (gamma, brightness or 203 * contrast) have changed. 204 **/ 205 void tableChanged(); 206 207 private: 208 void init(); 209 void calcTable(); 210 211 int mGamma; 212 int mBrightness; 213 int mContrast; 214 bool mDirty; 215 216 QVector<int> mData; 217 }; 218 219 #endif // KGAMMATABLE_H 220