Lower opacity OSD text.

git-svn-id: https://gambatte.svn.sourceforge.net/svnroot/gambatte@197 9dfb2916-2d38-0410-aef4-c5fe6c9ffc24
This commit is contained in:
sinamas 2008-10-26 15:11:07 +00:00
parent 3512fe21e0
commit c25bd691ad
3 changed files with 41 additions and 16 deletions

View File

@ -1,5 +1,5 @@
/***************************************************************************
* Copyright (C) 2008 by Sindre Aamås *
* Copyright (C) 2008 by Sindre Aam<EFBFBD>s *
* aamas@stud.ntnu.no *
* *
* This program is free software; you can redistribute it and/or modify *
@ -22,15 +22,21 @@
#include "int.h"
class OsdElement {
public:
enum Opacity { SEVEN_EIGHTHS, THREE_FOURTHS };
private:
Opacity opacity_;
unsigned x_;
unsigned y_;
unsigned w_;
unsigned h_;
protected:
OsdElement(unsigned x = 0, unsigned y = 0, unsigned w = 0, unsigned h = 0) {
OsdElement(unsigned x = 0, unsigned y = 0, unsigned w = 0, unsigned h = 0, Opacity opacity = SEVEN_EIGHTHS) {
setPos(x, y);
setSize(w, h);
setOpacity(opacity);
}
void setPos(unsigned x, unsigned y) {
@ -43,12 +49,15 @@ protected:
h_ = h;
}
void setOpacity(Opacity opacity) { opacity_ = opacity; }
public:
virtual ~OsdElement() {}
unsigned x() const { return x_; }
unsigned y() const { return y_; }
unsigned w() const { return w_; }
unsigned h() const { return h_; }
Opacity opacity() const { return opacity_; }
virtual const Gambatte::uint_least32_t* update() = 0;
};

View File

@ -1,5 +1,5 @@
/***************************************************************************
* Copyright (C) 2008 by Sindre Aamås *
* Copyright (C) 2008 by Sindre Aam<EFBFBD>s *
* aamas@stud.ntnu.no *
* *
* This program is free software; you can redistribute it and/or modify *
@ -50,7 +50,7 @@ public:
};
ShadedTextOsdElment::ShadedTextOsdElment(unsigned width, const char *txt) :
OsdElement(MAX_WIDTH, 144 - HEIGHT - HEIGHT, width + 2, HEIGHT + 2),
OsdElement(MAX_WIDTH, 144 - HEIGHT - HEIGHT, width + 2, HEIGHT + 2, THREE_FOURTHS),
pixels(new Gambatte::uint_least32_t[w() * h()]),
life(4 * 60) {
std::memset(pixels, 0xFF, w() * h() * sizeof(Gambatte::uint_least32_t));

View File

@ -338,6 +338,30 @@ unsigned int LCD::videoHeight() const {
return filter ? filter->info().outHeight : 144;
}
template<class Blend>
static void blitOsdElement(Gambatte::uint_least32_t *d, const Gambatte::uint_least32_t *s, const unsigned width, unsigned h, const unsigned dpitch, Blend blend) {
while (h--) {
for (unsigned w = width; w--;) {
if (*s != 0xFFFFFFFF)
*d = blend(*s, *d);
++d;
++s;
}
d += dpitch - width;
}
}
template<const unsigned weight>
struct Blend {
enum { SW = weight - 1 };
enum { LOWMASK = SW * 0x010101ul };
Gambatte::uint_least32_t operator()(const Gambatte::uint_least32_t s, const Gambatte::uint_least32_t d) const {
return (s * SW + d - (((s & LOWMASK) * SW + (d & LOWMASK)) & LOWMASK)) / weight;
}
};
void LCD::updateScreen(const unsigned long cycleCounter) {
update(cycleCounter);
@ -348,17 +372,9 @@ void LCD::updateScreen(const unsigned long cycleCounter) {
if (s) {
Gambatte::uint_least32_t *d = static_cast<Gambatte::uint_least32_t*>(dbuffer) + osdElement->y() * dpitch + osdElement->x();
for (unsigned h = osdElement->h(); h--;) {
for (unsigned w = osdElement->w(); w--;) {
if (*s != 0xFFFFFFFF)
*d = (*s * 7 + *d - (((*s & 0x070707) * 7 + (*d & 0x070707)) & 0x070707)) >> 3;
++d;
++s;
}
// std::memcpy(d, s, osdElement->w() * sizeof(Gambatte::uint_least32_t));
// s += osdElement->w();
d += dpitch - osdElement->w();
switch (osdElement->opacity()) {
case OsdElement::SEVEN_EIGHTHS: blitOsdElement(d, s, osdElement->w(), osdElement->h(), dpitch, Blend<8>()); break;
case OsdElement::THREE_FOURTHS: blitOsdElement(d, s, osdElement->w(), osdElement->h(), dpitch, Blend<4>()); break;
}
} else
osdElement.reset();