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   |
 |
mirek
Messages: 14257 Registered: November 2005
|
Ultimate Member |
|
|
Klugier wrote on Thu, 24 July 2014 22:32Hello 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?
|
|
|
 |
 |
Should RGBA have got 4 arguments constructor?
By: Klugier on Sat, 03 May 2014 20:59
|
 |
|
Re: Should RGBA have got 4 arguments constructor?
By: unodgs on Sat, 03 May 2014 21:44
|
 |
|
Re: Should RGBA have got 4 arguments constructor?
By: mirek on Thu, 29 May 2014 11:18
|
 |
|
Re: Should RGBA have got 4 arguments constructor?
By: mirek on Thu, 29 May 2014 11:32
|
 |
|
Re: Should RGBA have got 4 arguments constructor?
By: Klugier on Thu, 24 July 2014 22:32
|
 |
|
Re: Should RGBA have got 4 arguments constructor?
By: mirek on Fri, 25 July 2014 07:46
|
 |
|
Re: Should RGBA have got 4 arguments constructor?
By: Klugier on Fri, 25 July 2014 20:26
|
 |
|
Re: Should RGBA have got 4 arguments constructor?
By: mirek on Mon, 04 August 2014 14:21
|
 |
|
Re: Should RGBA have got 4 arguments constructor?
By: Klugier on Tue, 05 August 2014 21:25
|
 |
|
Re: Should RGBA have got 4 arguments constructor?
By: mirek on Wed, 06 August 2014 17:56
|
 |
|
Re: Should RGBA have got 4 arguments constructor?
By: Klugier on Sat, 09 August 2014 19:35
|
Goto Forum:
Current Time: Tue May 13 01:32:10 CEST 2025
Total time taken to generate the page: 0.00359 seconds
|