Skip to content

Commit

Permalink
Refactor: Moved ColorRawf to color.cpp/h
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Nov 26, 2012
1 parent d185262 commit 1501440
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 12 deletions.
61 changes: 61 additions & 0 deletions doomsday/engine/include/color.h
@@ -0,0 +1,61 @@
/**
* @file color.h Color
*
* @author Copyright &copy; 2007-2012 Daniel Swanson <danij@dengine.net>
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
*
* <small>This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 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 General
* Public License for more details. You should have received a copy of the GNU
* General Public License along with this program; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA</small>
*/

#ifndef LIBDENG_DATA_COLOR_H
#define LIBDENG_DATA_COLOR_H

#ifdef __cplusplus
extern "C" {
#endif

/**
* ColorRawf. Color Raw (f)loating point. Is intended as a handy POD
* structure for easy manipulation of four component, floating point
* color plus alpha value sets.
*
* @ingroup data
*/
typedef struct ColorRawf_s {
union {
// Straight RGBA vector representation.
float rgba[4];
// Hybrid RGB plus alpha component representation.
struct {
float rgb[3];
float alpha;
};
// Component-wise representation.
struct {
float red;
float green;
float blue;
float _alpha;
};
};
} ColorRawf;

float ColorRawf_AverageColor(ColorRawf* color);
float ColorRawf_AverageColorMulAlpha(ColorRawf* color);

#ifdef __cplusplus
} // extern "C"
#endif

#endif /// LIBDENG_DATA_COLOR_H
34 changes: 34 additions & 0 deletions doomsday/engine/src/color.cpp
@@ -0,0 +1,34 @@
/**
* @file color.cpp Color
*
* @author Copyright &copy; 2007-2012 Daniel Swanson <danij@dengine.net>
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
*
* <small>This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 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 General
* Public License for more details. You should have received a copy of the GNU
* General Public License along with this program; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA</small>
*/

#include "de_platform.h"
#include "color.h"

float ColorRawf_AverageColor(ColorRawf* c)
{
DENG_ASSERT(c);
return (c->red + c->green + c->blue) / 3;
}

float ColorRawf_AverageColorMulAlpha(ColorRawf* c)
{
DENG_ASSERT(c);
return (c->red + c->green + c->blue) / 3 * c->alpha;
}
12 changes: 0 additions & 12 deletions doomsday/engine/src/resource/r_data.c
Expand Up @@ -3273,15 +3273,3 @@ boolean R_DrawVLightVector(const vlight_t* light, void* context)
}
return true; // Continue iteration.
}

float ColorRawf_AverageColor(ColorRawf* c)
{
assert(c);
return (c->red + c->green + c->blue) / 3;
}

float ColorRawf_AverageColorMulAlpha(ColorRawf* c)
{
assert(c);
return (c->red + c->green + c->blue) / 3 * c->alpha;
}

0 comments on commit 1501440

Please sign in to comment.