Mine might not be the most eficient - but this is how it sits today:
jgc_rgba.h
/*============================================================================
| _________ _______ _______ ______ _______ Jegas, LLC |
| /___ ___// _____/ / _____/ / __ / / _____/ JasonPSage@jegas.com |
| / / / /__ / / ___ / /_/ / / /____ |
| / / / ____/ / / / / / __ / /____ / |
|____/ / / /___ / /__/ / / / / / _____/ / |
/_____/ /______/ /______/ /_/ /_/ /______/ |
| Under the Hood |
==============================================================================
Copyright(c)2008 Jegas, LLC
============================================================================*/
#pragma once
#include <DarkGDK.h>
// you don't need this - it's just here as a "general rule" for my library.
#include "jgc_configuration.h"
//----------------------------------------------------------------------------
// RGBA - Usage: uRGBA MyColor; MyColor.Red=100; MyColor.Pixel=(a dword)
//----------------------------------------------------------------------------
typedef union RGBA {
struct {
unsigned char Blue;
unsigned char Green;
unsigned char Red;
unsigned char Alpha;
};
DWORD Pixel;
} uRGBA;
//----------------------------------------------------------------------------
//============================================================================
// Begin JGC_RGBA
//============================================================================
class JGC_RGBA{
public:
JGC_RGBA();
~JGC_RGBA();
uRGBA *RGBA;
void Red_Set(unsigned char p_Red);
void Green_Set(unsigned char p_Green);
void Blue_Set(unsigned char p_Blue);
void Alpha_Set(unsigned char p_Alpha);
void RGB_Set(unsigned char p_Red, unsigned char p_Green, unsigned char p_Blue);
void RGB_Set(DWORD p_RGB);
void RGBA_Set(unsigned char p_Red, unsigned char p_Green, unsigned char p_Blue, unsigned char p_Alpha);
void RGBA_Set(DWORD p_RGBA);
unsigned int Red_Get(void);
unsigned int Green_Get(void);
unsigned int Blue_Get(void);
unsigned int Alpha_Get(void);
DWORD RGB_Get(void);
DWORD RGBA_Get(void);
};
//============================================================================
// End JGC_RGBA
//============================================================================
jgc_rgba.cpp
/*============================================================================
| _________ _______ _______ ______ _______ Jegas, LLC |
| /___ ___// _____/ / _____/ / __ / / _____/ JasonPSage@jegas.com |
| / / / /__ / / ___ / /_/ / / /____ |
| / / / ____/ / / / / / __ / /____ / |
|____/ / / /___ / /__/ / / / / / _____/ / |
/_____/ /______/ /______/ /_/ /_/ /______/ |
| Under the Hood |
==============================================================================
Copyright(c)2008 Jegas, LLC
============================================================================*/
#include "jgc_rgba.h"
//============================================================================
// begin JGC_RGB
//============================================================================
//----------------------------------------------------------------------------
JGC_RGBA::JGC_RGBA(){
//----------------------------------------------------------------------------
this->RGBA = new uRGBA();
RGBA->Pixel=0;
};
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
JGC_RGBA::~JGC_RGBA(){
//----------------------------------------------------------------------------
delete RGBA;
};
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
void JGC_RGBA::Red_Set(unsigned char p_Red){
//----------------------------------------------------------------------------
this->RGBA->Red=p_Red;
};
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
void JGC_RGBA::Green_Set(unsigned char p_Green){
//----------------------------------------------------------------------------
this->RGBA->Green=p_Green;
};
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
void JGC_RGBA::Blue_Set(unsigned char p_Blue){
//----------------------------------------------------------------------------
this->RGBA->Blue=p_Blue;
};
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
void JGC_RGBA::Alpha_Set(unsigned char p_Alpha){
//----------------------------------------------------------------------------
this->RGBA->Alpha=p_Alpha;
};
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
void JGC_RGBA::RGB_Set(
unsigned char p_Red,
unsigned char p_Green,
unsigned char p_Blue
){
//----------------------------------------------------------------------------
this->RGBA->Red=p_Red;
this->RGBA->Green=p_Green;
this->RGBA->Blue=p_Blue;
};
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
void JGC_RGBA::RGB_Set(DWORD p_RGB){
//----------------------------------------------------------------------------
uRGBA Temp;
Temp.Pixel=p_RGB;
Temp.Alpha=this->RGBA->Alpha;
this->RGBA->Pixel=Temp.Pixel;
};
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
void JGC_RGBA::RGBA_Set(
unsigned char p_Red,
unsigned char p_Green,
unsigned char p_Blue,
unsigned char p_Alpha
){
//----------------------------------------------------------------------------
this->RGBA->Red=p_Red;
this->RGBA->Green=p_Green;
this->RGBA->Blue=p_Blue;
this->RGBA->Alpha=p_Alpha;
};
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
void JGC_RGBA::RGBA_Set(DWORD p_RGBA){
//----------------------------------------------------------------------------
this->RGBA->Pixel=p_RGBA;
};
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
unsigned int JGC_RGBA::Red_Get(void){
//----------------------------------------------------------------------------
return this->RGBA->Red;
};
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
unsigned int JGC_RGBA::Green_Get(void){
//----------------------------------------------------------------------------
return this->RGBA->Green;
};
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
unsigned int JGC_RGBA::Blue_Get(void){
//----------------------------------------------------------------------------
return this->RGBA->Blue;
};
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
unsigned int JGC_RGBA::Alpha_Get(void){
//----------------------------------------------------------------------------
return this->RGBA->Alpha;
};
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
DWORD JGC_RGBA::RGB_Get(void){
//----------------------------------------------------------------------------
uRGBA Temp;
Temp.Pixel = this->RGBA->Pixel;
//Temp.Alpha=0;
return Temp.Pixel;
};
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
DWORD JGC_RGBA::RGBA_Get(void){
//----------------------------------------------------------------------------
return this->RGBA->Pixel;
};
//----------------------------------------------------------------------------
//============================================================================
// end JGC_RGB
//============================================================================
Hope this might be useful to someone
Jason