Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » Draw, Display, Images, Bitmaps, Icons » Should RGBA have got 4 arguments constructor?
Re: Should RGBA have got 4 arguments constructor? [message #43397 is a reply to message #43395] Fri, 25 July 2014 07:46 Go to previous messageGo to previous message
mirek is currently offline  mirek
Messages: 14257
Registered: November 2005
Ultimate Member
Klugier wrote on Thu, 24 July 2014 22:32
Hello Mirek,

We can easily implement RGBA constructor in C++11 branch... This standard changes a little bit POD rules. Now we can define constructor, but firstly we need to tell compiler that default constructor exists. I enclose demonstrative code:

#include <Core/Core.h>

#include <type_traits>

using namespace Upp;

namespace UppCpp11 {
struct RGBA {
	RGBA() = default;
	RGBA(byte r, byte g, byte b, byte a) {
		this->r = r;
		this->g = g;
		this->b = b;
		this->a = a;
	}
	
	byte b, g, r, a;
};

struct NotPodRGBA {
	NotPodRGBA(byte r, byte g, byte b, byte a) {
		this->r = r;
		this->g = g;
		this->b = b;
		this->a = a;
	}
	
	byte b, g, r, a;
};
}

CONSOLE_APP_MAIN
{
	UppCpp11::RGBA color(255, 255, 255, 255);
	Cout() << "Is RGBA POD? " << (std::is_pod<UppCpp11::RGBA>::value ? "True" : "False") << "!\n";
	Cout() << "Is NotPodRGBA POD? " << (std::is_pod<UppCpp11::NotPodRGBA>::value ? "True" : "False") << "!\n";
}


Result:
Is RGBA POD? True!
Is NotPodRGBA POD? False!


More information you can find on: http://stackoverflow.com/questions/4178175/what-are-aggregat es-and-pods-and-how-why-are-they-special/7189821#7189821 - second answer.

P.S.
Tested with g++ 4.8 using std=c++11 flag.

Sincerely,
Klugier


OK, but premultiplied alpha issue is still there... Should we add ASSERT

	RGBA(byte r, byte g, byte b, byte a) {
		ASSERT(r <= a && g <= a && b <= a);
		this->r = r;
		this->g = g;
		this->b = b;
		this->a = a;
	}


or perform conversion?
 
Read Message icon5.gif
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Drawing performance issue
Next Topic: Painter and viewports
Goto Forum:
  


Current Time: Tue May 13 01:32:10 CEST 2025

Total time taken to generate the page: 0.00359 seconds