mirror of
https://github.com/yuzu-emu/FasTC
synced 2024-11-26 01:07:59 +00:00
Add YCoCg pixel type
This commit is contained in:
parent
4fc75f22dc
commit
9dc23db287
2 changed files with 54 additions and 1 deletions
|
@ -59,7 +59,7 @@
|
|||
namespace FasTC {
|
||||
|
||||
class Pixel : public Vector4<uint16> {
|
||||
private:
|
||||
protected:
|
||||
typedef uint16 ChannelType;
|
||||
typedef Vector4<ChannelType> VectorType;
|
||||
uint8 m_BitDepth[4];
|
||||
|
@ -159,6 +159,28 @@ class Pixel : public Vector4<uint16> {
|
|||
};
|
||||
REGISTER_VECTOR_TYPE(Pixel);
|
||||
|
||||
class YCoCgPixel : public Pixel {
|
||||
private:
|
||||
void ToYCoCg();
|
||||
|
||||
public:
|
||||
YCoCgPixel() : Pixel() { }
|
||||
explicit YCoCgPixel(uint32 rgba) : Pixel(rgba) { ToYCoCg(); }
|
||||
explicit YCoCgPixel(const Pixel &p) : Pixel(p) { ToYCoCg(); }
|
||||
|
||||
Pixel ToRGBA() const;
|
||||
|
||||
float ToIntensity() const { return ConvertChannelToFloat(R(), 8); }
|
||||
uint32 Pack() const { return ToRGBA().Pack(); }
|
||||
void Unpack(uint32 rgba) { Pixel::Unpack(rgba); ToYCoCg(); }
|
||||
|
||||
const ChannelType &Co() const { return Z(); }
|
||||
ChannelType &Co() { return Z(); }
|
||||
const ChannelType &Cg() const { return W(); }
|
||||
ChannelType &Cg() { return W(); }
|
||||
};
|
||||
REGISTER_VECTOR_TYPE(YCoCgPixel);
|
||||
|
||||
} // namespace FasTC
|
||||
|
||||
#endif // BASE_INCLUDE_PIXEL_H_
|
||||
|
|
|
@ -56,6 +56,11 @@
|
|||
#include <cassert>
|
||||
#include <algorithm>
|
||||
|
||||
template<typename T>
|
||||
static inline T Clamp(const T &v, const T &_min, const T &_max) {
|
||||
return std::max(_min, std::min(v, _max));
|
||||
}
|
||||
|
||||
namespace FasTC {
|
||||
|
||||
void Pixel::FromBits(const uint8 *bits,
|
||||
|
@ -260,4 +265,30 @@ namespace FasTC {
|
|||
return ok;
|
||||
}
|
||||
|
||||
void YCoCgPixel::ToYCoCg() {
|
||||
int16 Y = ((R() + (G() << 1) + B()) + 2) >> 2;
|
||||
int16 Co = (R() - B() + 1) >> 1;
|
||||
int16 Cg = ((-R() + (G() << 1) - B()) + 2) >> 2;
|
||||
|
||||
this->Y() = Clamp<int16>(Y, 0, 255);
|
||||
this->Co() = Clamp<int16>(Co + 128, 0, 255);
|
||||
this->Cg() = Clamp<int16>(Cg + 128, 0, 255);
|
||||
}
|
||||
|
||||
Pixel YCoCgPixel::ToRGBA() const {
|
||||
int16 Co = this->Co() - 128;
|
||||
int16 Cg = this->Cg() - 128;
|
||||
|
||||
int16 R = Y() + (Co - Cg);
|
||||
int16 G = Y() + Cg;
|
||||
int16 B = Y() - (Co + Cg);
|
||||
|
||||
Pixel p;
|
||||
p.R() = Clamp<int16>(R, 0, 255);
|
||||
p.G() = Clamp<int16>(G, 0, 255);
|
||||
p.B() = Clamp<int16>(B, 0, 255);
|
||||
p.A() = A();
|
||||
return p;
|
||||
}
|
||||
|
||||
} // namespace FasTC
|
||||
|
|
Loading…
Reference in a new issue