PixelLightAPI
.
|
00001 /*********************************************************\ 00002 * File: Color3.h * 00003 * 00004 * Copyright (C) 2002-2012 The PixelLight Team (http://www.pixellight.org/) 00005 * 00006 * This file is part of PixelLight. 00007 * 00008 * PixelLight is free software: you can redistribute it and/or modify 00009 * it under the terms of the GNU Lesser General Public License as published by 00010 * the Free Software Foundation, either version 3 of the License, or 00011 * (at your option) any later version. 00012 * 00013 * PixelLight is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 * GNU Lesser General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU Lesser General Public License 00019 * along with PixelLight. If not, see <http://www.gnu.org/licenses/>. 00020 \*********************************************************/ 00021 00022 00023 #ifndef __PLGRAPHICS_COLOR3_H__ 00024 #define __PLGRAPHICS_COLOR3_H__ 00025 #pragma once 00026 00027 00028 //[-------------------------------------------------------] 00029 //[ Includes ] 00030 //[-------------------------------------------------------] 00031 #include <PLCore/String/String.h> 00032 #include "PLGraphics/PLGraphics.h" 00033 00034 00035 //[-------------------------------------------------------] 00036 //[ Namespace ] 00037 //[-------------------------------------------------------] 00038 namespace PLGraphics { 00039 00040 00041 //[-------------------------------------------------------] 00042 //[ Forward declarations ] 00043 //[-------------------------------------------------------] 00044 class Color4; 00045 00046 00047 //[-------------------------------------------------------] 00048 //[ Classes ] 00049 //[-------------------------------------------------------] 00050 /** 00051 * @brief 00052 * RGB color 00053 */ 00054 class Color3 { 00055 00056 00057 //[-------------------------------------------------------] 00058 //[ Public static data ] 00059 //[-------------------------------------------------------] 00060 public: 00061 // Special 00062 static PLGRAPHICS_API const Color3 Null; /**< -1.0, -1.0, -1.0 */ 00063 // HTML 4/VGA 00064 static PLGRAPHICS_API const Color3 Black; /**< Black (sRGB="0 0 0", Hex="#000000") */ 00065 static PLGRAPHICS_API const Color3 White; /**< White (sRGB="255 255 255", Hex="#FFFFFF") */ 00066 static PLGRAPHICS_API const Color3 Red; /**< Red (sRGB="255 0 0", Hex="#FF0000") */ 00067 static PLGRAPHICS_API const Color3 Yellow; /**< Yellow (sRGB="255 255 0", Hex="#FFFF00") */ 00068 static PLGRAPHICS_API const Color3 Green; /**< Green (sRGB="0 128 0", Hex="#008000") */ 00069 static PLGRAPHICS_API const Color3 Aqua; /**< Aqua, also called cyan or blue-green (sRGB="0 255 255", Hex="#00FFFF") */ 00070 static PLGRAPHICS_API const Color3 Blue; /**< Blue (sRGB="0 0 255", Hex="#0000FF") */ 00071 static PLGRAPHICS_API const Color3 Fuchsia; /**< Fuchsia, also called full magenta, bright pink or vivid pink (sRGB="255 0 255", Hex="#FF00FF") */ 00072 static PLGRAPHICS_API const Color3 Maroon; /**< Maroon, dark brownish-red color (sRGB="128 0 0", Hex="#800000") */ 00073 static PLGRAPHICS_API const Color3 Olive; /**< Olive, dark green/brown color (sRGB="128 128 0", Hex="#808000") */ 00074 static PLGRAPHICS_API const Color3 Navy; /**< Navy, also called navy blue, very dark shade of the color blue (sRGB="0 0 128", Hex="#000080") */ 00075 static PLGRAPHICS_API const Color3 Purple; /**< Purple, color intermediate to red and blue (sRGB="128 0 128", Hex="#800080") */ 00076 static PLGRAPHICS_API const Color3 Teal; /**< Teal, also called teal blue, greenish dark-blue color (sRGB="0 128 128", Hex="#008080") */ 00077 static PLGRAPHICS_API const Color3 Gray; /**< Gray (sRGB="128 128 128", Hex="#808080") */ 00078 static PLGRAPHICS_API const Color3 Silver; /**< Silver (sRGB="192 192 192", Hex="#C0C0C0") */ 00079 static PLGRAPHICS_API const Color3 Lime; /**< Lime, actually corresponds to the green primary of an RGB display (sRGB="0 255 0", Hex="#00FF00") */ 00080 00081 00082 //[-------------------------------------------------------] 00083 //[ Public data ] 00084 //[-------------------------------------------------------] 00085 public: 00086 union { 00087 float fColor[3]; 00088 struct { 00089 float r, g, b; 00090 }; 00091 }; 00092 00093 00094 //[-------------------------------------------------------] 00095 //[ Public static functions ] 00096 //[-------------------------------------------------------] 00097 public: 00098 /** 00099 * @brief 00100 * Maps a RGB floating point channels (0.0f to 1.0f range) to PLCore::uint32 00101 * 00102 * @param[in] fR 00103 * Red color component (0.0-1.0) 00104 * @param[in] fG 00105 * Green color component (0.0-1.0) 00106 * @param[in] fB 00107 * Blue color component (0.0-1.0) 00108 * 00109 * @return 00110 * The color as PLCore::uint32 00111 */ 00112 static inline PLCore::uint32 ToUInt32(float fR, float fG, float fB); 00113 00114 /** 00115 * @brief 00116 * Returns the red color component (float, 0.0-1.0) from a PLCore::uint32 RGB color 00117 * 00118 * @param[in] nColor 00119 * Color as PLCore::uint32 00120 * 00121 * @return 00122 * The red color component (0.0-1.0) 00123 */ 00124 static inline float RedFromUInt32(PLCore::uint32 nColor); 00125 00126 /** 00127 * @brief 00128 * Returns the green color component (float, 0.0-1.0) from a PLCore::uint32 RGB color 00129 * 00130 * @param[in] nColor 00131 * Color as PLCore::uint32 00132 * 00133 * @return 00134 * The green color component (0.0-1.0) 00135 */ 00136 static inline float GreenFromUInt32(PLCore::uint32 nColor); 00137 00138 /** 00139 * @brief 00140 * Returns the blue color component (float, 0.0-1.0) from a PLCore::uint32 RGB color 00141 * 00142 * @param[in] nColor 00143 * Color as PLCore::uint32 00144 * 00145 * @return 00146 * The blue color component (0.0-1.0) 00147 */ 00148 static inline float BlueFromUInt32(PLCore::uint32 nColor); 00149 00150 /** 00151 * @brief 00152 * Swaps the RB components in the given buffer with 3 components (BGR <-> RGB) 00153 * 00154 * @param[in, out] nBuffer 00155 * Reference to the buffer (RGB or BGR) 00156 * @param[in] nNumOfPixels 00157 * Buffer size (width*height => number of pixels) 00158 * 00159 * @note 00160 * - This function is internally assembler optimizes for maximum performance 00161 */ 00162 static PLGRAPHICS_API void SwapRB(PLCore::uint8 nBuffer[], PLCore::uint32 nNumOfPixels); 00163 00164 00165 //[-------------------------------------------------------] 00166 //[ Public functions ] 00167 //[-------------------------------------------------------] 00168 public: 00169 /** 00170 * @brief 00171 * Constructor (all components are set to 0.0) 00172 */ 00173 inline Color3(); 00174 00175 /** 00176 * @brief 00177 * Constructor 00178 * 00179 * @param[in] fR 00180 * Red color component (0.0-1.0) 00181 * @param[in] fG 00182 * Green color component (0.0-1.0) 00183 * @param[in] fB 00184 * Blue color component (0.0-1.0) 00185 */ 00186 inline Color3(float fR, float fG, float fB); 00187 00188 /** 00189 * @brief 00190 * Constructor 00191 * 00192 * @param[in] nR 00193 * Red color component (0-255) 00194 * @param[in] nG 00195 * Green color component (0-255) 00196 * @param[in] nB 00197 * Blue color component (0-255) 00198 */ 00199 inline Color3(PLCore::uint8 nR, PLCore::uint8 nG, PLCore::uint8 nB); 00200 00201 /** 00202 * @brief 00203 * Constructor 00204 * 00205 * @param[in] fColor 00206 * Float array holding the color, MUST have 3 elements! (0.0-1.0) 00207 */ 00208 inline Color3(const float fColor[]); 00209 00210 /** 00211 * @brief 00212 * Constructor 00213 * 00214 * @param[in] nColor 00215 * PLCore::uint8 array holding the color, MUST have 3 elements! (0-255) 00216 */ 00217 inline Color3(const PLCore::uint8 nColor[]); 00218 00219 /** 00220 * @brief 00221 * Constructor 00222 * 00223 * @param[in] fColor 00224 * Value for all three color components (0.0-1.0) 00225 */ 00226 inline Color3(float fColor); 00227 00228 /** 00229 * @brief 00230 * Constructor 00231 * 00232 * @param[in] nColor 00233 * Value for all three color components (0-255) 00234 */ 00235 inline Color3(PLCore::uint8 nColor); 00236 00237 /** 00238 * @brief 00239 * Copy constructor 00240 * 00241 * @param[in] cSource 00242 * Source color 00243 */ 00244 inline Color3(const Color3 &cSource); 00245 00246 /** 00247 * @brief 00248 * Destructor 00249 */ 00250 inline ~Color3(); 00251 00252 /** 00253 * @brief 00254 * Maps this RGB floating point channels (0.0f to 1.0f range) to PLCore::uint32 00255 * 00256 * @return 00257 * This color as PLCore::uint32 00258 */ 00259 inline PLCore::uint32 ToUInt32() const; 00260 00261 /** 00262 * @brief 00263 * Maps from a PLCore::uint32 to RGB floating point channels (0.0f to 1.0f range) 00264 * 00265 * @param[in] nColor 00266 * Color as PLCore::uint32 00267 */ 00268 inline void FromUInt32(PLCore::uint32 nColor); 00269 00270 /** 00271 * @brief 00272 * Get the color component as float values 00273 * 00274 * @param[out] fR 00275 * Will receive the red color component (0.0-1.0) 00276 * @param[out] fG 00277 * Will receive the green color component (0.0-1.0) 00278 * @param[out] fB 00279 * Will receive the blue color component (0.0-1.0) 00280 */ 00281 inline void GetRGB(float &fR, float &fG, float &fB) const; 00282 00283 /** 00284 * @brief 00285 * Get the color component as integer values 00286 * 00287 * @param[out] nR 00288 * Will receive the red color component (0-255) 00289 * @param[out] nG 00290 * Will receive the green color component (0-255) 00291 * @param[out] nB 00292 * Will receive the blue color component (0-255) 00293 */ 00294 inline void GetRGB(PLCore::uint8 &nR, PLCore::uint8 &nG, PLCore::uint8 &nB) const; 00295 00296 /** 00297 * @brief 00298 * Set the color components by using float values 00299 * 00300 * @param[in] fR 00301 * Red color component (0.0-1.0) 00302 * @param[in] fG 00303 * Green color component (0.0-1.0) 00304 * @param[in] fB 00305 * Blue color component (0.0-1.0) 00306 */ 00307 inline void SetRGB(float fR, float fG, float fB); 00308 00309 /** 00310 * @brief 00311 * Set the color components by using integer values 00312 * 00313 * @param[in] nR 00314 * Red color component (0-255) 00315 * @param[in] nG 00316 * Green color component (0-255) 00317 * @param[in] nB 00318 * Blue color component (0-255) 00319 */ 00320 inline void SetRGB(PLCore::uint8 nR, PLCore::uint8 nG, PLCore::uint8 nB); 00321 00322 /** 00323 * @brief 00324 * Get the color component as array of float values 00325 * 00326 * @param[out] fColor 00327 * Reference to float array receiving the color values, MUST have 3 elements! (0.0-1.0) 00328 */ 00329 inline void GetRGB(float fColor[]) const; 00330 00331 /** 00332 * @brief 00333 * Get the color component as array of integer values 00334 * 00335 * @param[out] nColor 00336 * Reference to PLCore::uint8 array receiving the color values, MUST have 3 elements! (0-255) 00337 */ 00338 inline void GetRGB(PLCore::uint8 nColor[]) const; 00339 00340 /** 00341 * @brief 00342 * Set the color components by using a reference to float values 00343 * 00344 * @param[in] fColor 00345 * Reference to float array containing the color value, MUST have 3 elements! (0.0-1.0) 00346 */ 00347 inline void SetRGB(const float fColor[]); 00348 00349 /** 00350 * @brief 00351 * Set the color components by using a reference to integer values 00352 * 00353 * @param[in] nColor 00354 * Reference to PLCore::uint8 array containing the color value, MUST have 3 elements! (0-255) 00355 */ 00356 inline void SetRGB(const PLCore::uint8 nColor[]); 00357 00358 /** 00359 * @brief 00360 * Set all color component to the same float value 00361 * 00362 * @param[in] fValue 00363 * Value for all three color component (0.0-1.0) 00364 */ 00365 inline void SetRGB(float fValue); 00366 00367 /** 00368 * @brief 00369 * Set all color component to the same integer value 00370 * 00371 * @param[in] nColor 00372 * Value for all three color component (0-255) 00373 */ 00374 inline void SetRGB(PLCore::uint8 nColor); 00375 00376 /** 00377 * @brief 00378 * Get the red color value as float 00379 * 00380 * @return 00381 * Red value (0.0-1.0) 00382 */ 00383 inline float GetR() const; 00384 00385 /** 00386 * @brief 00387 * Get the red color value as integer 00388 * 00389 * @return 00390 * Red value (0-255) 00391 */ 00392 inline PLCore::uint8 GetRInt() const; 00393 00394 /** 00395 * @brief 00396 * Set the red color component using a float value 00397 * 00398 * @param[in] fR 00399 * Red value (0.0-1.0) 00400 */ 00401 inline void SetR(float fR); 00402 00403 /** 00404 * @brief 00405 * Set the red color component using an integer value 00406 * 00407 * @param[in] nR 00408 * Red value (0-255) 00409 */ 00410 inline void SetR(PLCore::uint8 nR); 00411 00412 /** 00413 * @brief 00414 * Get the green color value as float 00415 * 00416 * @return 00417 * Green value (0.0-1.0) 00418 */ 00419 inline float GetG() const; 00420 00421 /** 00422 * @brief 00423 * Get the green color value as integer 00424 * 00425 * @return 00426 * Green value (0-255) 00427 */ 00428 inline PLCore::uint8 GetGInt() const; 00429 00430 /** 00431 * @brief 00432 * Set the green color component using a float value 00433 * 00434 * @param[in] fG 00435 * Green value (0.0-1.0) 00436 */ 00437 inline void SetG(float fG); 00438 00439 /** 00440 * @brief 00441 * Set the green color component using an integer value 00442 * 00443 * @param[in] nG 00444 * Green value (0-255) 00445 */ 00446 inline void SetG(PLCore::uint8 nG); 00447 00448 /** 00449 * @brief 00450 * Get the blue color value as float 00451 * 00452 * @return 00453 * Blue value (0.0-1.0) 00454 */ 00455 inline float GetB() const; 00456 00457 /** 00458 * @brief 00459 * Get the blue color value as integer 00460 * 00461 * @return 00462 * Blue value (0-255) 00463 */ 00464 inline PLCore::uint8 GetBInt() const; 00465 00466 /** 00467 * @brief 00468 * Set the blue color component using a float value 00469 * 00470 * @param[in] fB 00471 * Blue value (0.0-1.0) 00472 */ 00473 inline void SetB(float fB); 00474 00475 /** 00476 * @brief 00477 * Set the blue color component using an integer value 00478 * 00479 * @param[in] nB 00480 * Blue value (0-255) 00481 */ 00482 inline void SetB(PLCore::uint8 nB); 00483 00484 /** 00485 * @brief 00486 * Returns if the color is valid 00487 * 00488 * @return 00489 * 'true' if the color is valid, else 'false' 00490 */ 00491 inline bool IsValid() const; 00492 00493 /** 00494 * @brief 00495 * Clamps the color values between 0.0 and 1.0 00496 */ 00497 inline void Saturate(); 00498 00499 /** 00500 * @brief 00501 * Get luminance of color as float 00502 * 00503 * @return 00504 * Luminance value (0.0-1.0) 00505 * 00506 * @note 00507 * - "human eye formula" (red*0.299 + green*0.587 + blue*0.114) is used 00508 */ 00509 inline float GetLuminance() const; 00510 00511 /** 00512 * @brief 00513 * Get luminance of color as integer 00514 * 00515 * @return 00516 * Luminance (0-255) 00517 * 00518 * @see 00519 * - GetLuminance() 00520 */ 00521 inline PLCore::uint8 GetLuminanceInt() const; 00522 00523 /** 00524 * @brief 00525 * Get luminance as color (results in a grayscale color) 00526 * 00527 * @return 00528 * Luminance color (grayscale) 00529 * 00530 * @see 00531 * - GetLuminance() 00532 */ 00533 inline Color3 GetLuminanceColor() const; 00534 00535 00536 //[-------------------------------------------------------] 00537 //[ Assignment operators ] 00538 //[-------------------------------------------------------] 00539 inline Color3 &operator =(const Color3 &cC); 00540 PLGRAPHICS_API Color3 &operator =(const Color4 &cC); 00541 inline Color3 &operator =(const float fC[]); 00542 inline Color3 &operator =(float fD); 00543 inline operator float *(); 00544 inline operator const float *() const; 00545 00546 //[-------------------------------------------------------] 00547 //[ Comparison ] 00548 //[-------------------------------------------------------] 00549 inline bool operator ==(const Color3 &cC) const; 00550 inline bool operator !=(const Color3 &cC) const; 00551 PLGRAPHICS_API bool operator ==(const Color4 &cC) const; 00552 PLGRAPHICS_API bool operator !=(const Color4 &cC) const; 00553 inline bool operator ==(float f) const; 00554 inline bool operator !=(float f) const; 00555 00556 //[-------------------------------------------------------] 00557 //[ Misc ] 00558 //[-------------------------------------------------------] 00559 inline Color3 operator +(const Color3 &cC) const; 00560 inline Color3 operator +(float fN) const; 00561 inline Color3 &operator +=(const Color3 &cC); 00562 inline Color3 &operator +=(float fN); 00563 inline Color3 operator -() const; 00564 inline Color3 operator -(const Color3 &cC) const; 00565 inline Color3 operator -(float fN) const; 00566 inline Color3 &operator -=(const Color3 &cC); 00567 inline Color3 &operator -=(float fN); 00568 inline Color3 operator *(const Color3 &cC) const; 00569 inline Color3 operator *(float fS) const; 00570 inline Color3 &operator *=(const Color3 &cC); 00571 inline Color3 &operator *=(float fS); 00572 inline Color3 operator /(const Color3 &cC) const; 00573 inline Color3 operator /(float fS) const; 00574 inline Color3 &operator /=(const Color3 &cC); 00575 inline Color3 &operator /=(float fS); 00576 inline float &operator [](int nIndex); 00577 00578 /** 00579 * @brief 00580 * To string 00581 * 00582 * @return 00583 * String with the data 00584 */ 00585 inline PLCore::String ToString() const; 00586 00587 /** 00588 * @brief 00589 * From string 00590 * 00591 * @param[in] sString 00592 * String with the data 00593 */ 00594 PLGRAPHICS_API bool FromString(const PLCore::String &sString); 00595 00596 00597 }; 00598 00599 00600 //[-------------------------------------------------------] 00601 //[ Namespace ] 00602 //[-------------------------------------------------------] 00603 } // PLGraphics 00604 00605 00606 //[-------------------------------------------------------] 00607 //[ Implementation ] 00608 //[-------------------------------------------------------] 00609 #include "PLGraphics/Color/Color3.inl" 00610 #include "PLGraphics/Color/TypeColor3.inl" 00611 00612 00613 #endif // __PLGRAPHICS_COLOR3_H__
|