2012-08-25 04:19:58 -07:00
|
|
|
/*
|
|
|
|
* =====================================================================
|
|
|
|
* Version: 1.0
|
|
|
|
* Created: 25.08.2012 10:55:29
|
|
|
|
* Author: Miroslav Bendík
|
|
|
|
* Company: LinuxOS.sk
|
|
|
|
* =====================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef PIXELATTRIBUTES_H_ADZ35GYF
|
|
|
|
#define PIXELATTRIBUTES_H_ADZ35GYF
|
|
|
|
|
2012-08-25 04:27:40 -07:00
|
|
|
#include <limits>
|
2014-04-12 16:18:34 -07:00
|
|
|
#include <cmath>
|
2014-04-03 11:32:48 -07:00
|
|
|
#include <stdint.h>
|
2014-04-14 11:46:12 -07:00
|
|
|
#include <stdexcept>
|
2012-09-01 05:36:14 -07:00
|
|
|
#include "config.h"
|
2014-04-12 16:18:34 -07:00
|
|
|
#include "Color.h"
|
2012-08-25 04:19:58 -07:00
|
|
|
|
|
|
|
struct PixelAttribute {
|
2014-04-12 16:18:34 -07:00
|
|
|
PixelAttribute(): h(NAN), t(0), a(0), r(0), g(0), b(0) {};
|
|
|
|
PixelAttribute(const Color &color, double height);
|
|
|
|
PixelAttribute(const ColorEntry &entry, double height);
|
|
|
|
double h;
|
|
|
|
double t;
|
|
|
|
double a;
|
|
|
|
double r;
|
|
|
|
double g;
|
|
|
|
double b;
|
|
|
|
uint8_t red(void) const { return int(r*255+0.5); }
|
|
|
|
uint8_t green(void) const { return int(g*255+0.5); }
|
|
|
|
uint8_t blue(void) const { return int(b*255+0.5); }
|
|
|
|
uint8_t alpha(void) const { return int(a*255+0.5); }
|
|
|
|
uint8_t thicken(void) const { return int(t*255+0.5); }
|
|
|
|
unsigned height(void) const { return unsigned(h+0.5); }
|
|
|
|
Color color(void) const { return Color(red(), green(), blue(), alpha()); }
|
|
|
|
|
2014-04-14 11:46:12 -07:00
|
|
|
inline bool is_valid() const { return !isnan(h); }
|
2014-04-12 16:18:34 -07:00
|
|
|
PixelAttribute &operator=(const PixelAttribute &p);
|
|
|
|
void mixUnder(const PixelAttribute &p);
|
2012-08-25 04:19:58 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
class PixelAttributes
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
PixelAttributes();
|
2012-09-01 05:36:14 -07:00
|
|
|
virtual ~PixelAttributes();
|
2014-04-14 11:46:12 -07:00
|
|
|
void setParameters(int width, int lines);
|
|
|
|
void scroll(int keepY);
|
|
|
|
inline PixelAttribute &attribute(int y, int x) { return m_pixelAttributes[yCoord2Line(y)][x + 1]; };
|
2014-04-12 16:18:34 -07:00
|
|
|
void renderShading(bool drawAlpha);
|
2014-04-14 11:46:12 -07:00
|
|
|
void setLastY(int y) { m_lastY = y; }
|
2012-08-25 04:19:58 -07:00
|
|
|
|
|
|
|
private:
|
2014-04-14 11:46:12 -07:00
|
|
|
int yCoord2Line(int y) { return y - m_firstY + m_firstLine; }
|
2012-09-01 05:36:14 -07:00
|
|
|
void freeAttributes();
|
|
|
|
|
|
|
|
private:
|
2014-04-14 11:46:12 -07:00
|
|
|
int m_previousLine;
|
|
|
|
int m_firstLine;
|
|
|
|
int m_lastLine;
|
|
|
|
int m_emptyLine;
|
|
|
|
int m_lineCount;
|
|
|
|
PixelAttribute **m_pixelAttributes;
|
2012-09-01 05:36:14 -07:00
|
|
|
int m_width;
|
2014-04-14 11:46:12 -07:00
|
|
|
int m_firstY;
|
|
|
|
int m_lastY;
|
|
|
|
int m_firstUnshadedY;
|
2012-08-25 04:19:58 -07:00
|
|
|
};
|
|
|
|
|
2014-04-12 16:18:34 -07:00
|
|
|
|
|
|
|
inline PixelAttribute::PixelAttribute(const Color &color, double height) :
|
|
|
|
h(height), t(0), a(color.a/255.0),
|
|
|
|
r(color.r/255.0), g(color.g/255.0), b(color.b/255.0)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
inline PixelAttribute::PixelAttribute(const ColorEntry &entry, double height) :
|
|
|
|
h(height), t(entry.t/255.0), a(entry.a/255.0),
|
|
|
|
r(entry.r/255.0), g(entry.g/255.0), b(entry.b/255.0)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
inline PixelAttribute &PixelAttribute::operator=(const PixelAttribute &p)
|
|
|
|
{
|
|
|
|
h = p.h;
|
|
|
|
t = p.t;
|
|
|
|
a = p.a;
|
|
|
|
r = p.r;
|
|
|
|
g = p.g;
|
|
|
|
b = p.b;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2012-08-25 04:19:58 -07:00
|
|
|
#endif /* end of include guard: PIXELATTRIBUTES_H_ADZ35GYF */
|
|
|
|
|