|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "rasterstyles.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "trop.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tvectorimage.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "traster.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "trastercm.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tlevel_io.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tenv.h"
|
|
Toshihiro Shimizu |
890ddd |
//#include "tpixelutils.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//*************************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
// TAirbrushRasterStyle implementation
|
|
Toshihiro Shimizu |
890ddd |
//*************************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void TAirbrushRasterStyle::loadData(TInputStreamInterface &is)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
is >> m_blur;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void TAirbrushRasterStyle::saveData(TOutputStreamInterface &os) const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
os << m_blur;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
bool TAirbrushRasterStyle::compute(const Params ¶ms) const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (m_blur > 0.0)
|
|
Toshihiro Shimizu |
890ddd |
TRop::blur(params.m_r, params.m_r, m_blur, 0, 0, true);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
return true;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TColorStyle *TAirbrushRasterStyle::clone() const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TColorStyle *cs = new TAirbrushRasterStyle(*this);
|
|
Toshihiro Shimizu |
890ddd |
cs->assignNames(this);
|
|
Toshihiro Shimizu |
890ddd |
return cs;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void TAirbrushRasterStyle::makeIcon(const TDimension &d)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TFilePath dir = TEnv::getStuffDir() + "pixmaps";
|
|
Toshihiro Shimizu |
890ddd |
static TRasterP normalIc;
|
|
Toshihiro Shimizu |
890ddd |
if (normalIc == TRasterP())
|
|
Toshihiro Shimizu |
890ddd |
TImageReader::load(dir + "airbrush.bmp", normalIc);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
arrangeIcon(d, normalIc);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*---------------------------------------------------------------------------*/
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void TAirbrushRasterStyle::arrangeIcon(const TDimension &d,
|
|
Toshihiro Shimizu |
890ddd |
const TRasterP &normalIc)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (normalIc == TRasterP()) {
|
|
Toshihiro Shimizu |
890ddd |
m_icon = TRaster32P(d);
|
|
Toshihiro Shimizu |
890ddd |
m_icon->fill(TPixel32::Red);
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
m_icon = TRasterP();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (d == TDimension(52, 52))
|
|
Toshihiro Shimizu |
890ddd |
m_icon = normalIc->clone();
|
|
Toshihiro Shimizu |
890ddd |
else {
|
|
Toshihiro Shimizu |
890ddd |
m_icon = TRaster32P(d);
|
|
Toshihiro Shimizu |
890ddd |
TRop::resample(m_icon, normalIc, TScale(d.lx / 52.0, d.ly / 52.0));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
m_icon->lock();
|
|
Toshihiro Shimizu |
890ddd |
TPixel *buf = (TPixel *)m_icon->getRawData();
|
|
Toshihiro Shimizu |
890ddd |
TPixel color = getMainColor();
|
|
Toshihiro Shimizu |
890ddd |
double rd = (color.r - color.m) / 255.0;
|
|
Toshihiro Shimizu |
890ddd |
double gd = (color.g - color.m) / 255.0;
|
|
Toshihiro Shimizu |
890ddd |
double bd = (color.b - color.m) / 255.0;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
assert(m_icon->getWrap() == m_icon->getSize().lx);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
for (int i = 0; i < m_icon->getSize().lx * m_icon->getSize().ly; i++, buf++) {
|
|
Toshihiro Shimizu |
890ddd |
assert(buf->r == buf->g && buf->r == buf->b);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (buf->r < 255) {
|
|
Toshihiro Shimizu |
890ddd |
if (buf->r == 0)
|
|
Toshihiro Shimizu |
890ddd |
*buf = color;
|
|
Toshihiro Shimizu |
890ddd |
else {
|
|
Toshihiro Shimizu |
890ddd |
int val = 255 - buf->r;
|
|
Toshihiro Shimizu |
890ddd |
buf->r = (UCHAR)(val * rd + 255);
|
|
Toshihiro Shimizu |
890ddd |
buf->g = (UCHAR)(val * gd + 255);
|
|
Toshihiro Shimizu |
890ddd |
buf->b = (UCHAR)(val * bd + 255);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
m_icon->unlock();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//*************************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
// TBlendRasterStyle implementation
|
|
Toshihiro Shimizu |
890ddd |
//*************************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TColorStyle *TBlendRasterStyle::clone() const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return new TBlendRasterStyle(*this);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
bool TBlendRasterStyle::compute(const Params ¶ms) const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
int i, j;
|
|
Toshihiro Shimizu |
890ddd |
TRasterGR8P r = (TRasterGR8P)params.m_r;
|
|
Toshihiro Shimizu |
890ddd |
assert(r);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
double factor = computeFactor(params);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (m_blur > 0.0)
|
|
Toshihiro Shimizu |
890ddd |
TRop::blur(params.m_r, params.m_r, m_blur, 0, 0, true);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
r->lock();
|
|
Toshihiro Shimizu |
890ddd |
for (i = 0; i < r->getLy(); i++) {
|
|
Toshihiro Shimizu |
890ddd |
TPixelGR8 *bufGr = r->pixels(i);
|
|
Toshihiro Shimizu |
890ddd |
for (j = 0; j < r->getLx(); j++, bufGr++)
|
|
Toshihiro Shimizu |
890ddd |
if (bufGr->value > 0) {
|
|
Toshihiro Shimizu |
890ddd |
double val = bufGr->value * factor + 0.5;
|
|
Toshihiro Shimizu |
890ddd |
bufGr->value = (UCHAR)((val > 255) ? 255 : val);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
r->unlock();
|
|
Toshihiro Shimizu |
890ddd |
return true;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
namespace
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
bool inline doIsBorderPix(int index, TPixelCM32 *pix, TPixelGR8 *pixGr, int paint)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return (pix->getPaint() != paint && (pix->isPurePaint() || pixGr->value != 0));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
bool inline isBorderPix(int index, TPixelCM32 *pix, int wrap, TPixelGR8 *pixGr, int wrapGr, int color)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return doIsBorderPix(index, pix + 1, pixGr + 1, color) ||
|
|
Toshihiro Shimizu |
890ddd |
doIsBorderPix(index, pix - 1, pixGr - 1, color) ||
|
|
Toshihiro Shimizu |
890ddd |
doIsBorderPix(index, pix + wrap, pixGr + wrapGr, color) ||
|
|
Toshihiro Shimizu |
890ddd |
doIsBorderPix(index, pix - wrap, pixGr - wrapGr, color);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*---------------------------------------------------------------------------*/
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void TBlendRasterStyle::makeIcon(const TDimension &d)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TFilePath dir = TEnv::getStuffDir() + "pixmaps";
|
|
Toshihiro Shimizu |
890ddd |
static TRasterP normalIc;
|
|
Toshihiro Shimizu |
890ddd |
if (normalIc == TRasterP())
|
|
Toshihiro Shimizu |
890ddd |
TImageReader::load(dir + "blend.bmp", normalIc);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
arrangeIcon(d, normalIc);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
double TBlendRasterStyle::computeFactor(const Params ¶ms) const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TRasterCM32P rCm = (TRasterCM32P)params.m_rOrig;
|
|
Toshihiro Shimizu |
890ddd |
TRasterGR8P rGr = (TRasterGR8P)params.m_r;
|
|
Toshihiro Shimizu |
890ddd |
TPixelGR8 *bufGr;
|
|
Toshihiro Shimizu |
890ddd |
TPixelCM32 *bufCmap;
|
|
Toshihiro Shimizu |
890ddd |
int i, j;
|
|
Toshihiro Shimizu |
890ddd |
int wr = params.m_rOrig->getWrap();
|
|
Toshihiro Shimizu |
890ddd |
int wrGr = params.m_r->getWrap();
|
|
Toshihiro Shimizu |
890ddd |
int num_lines = 0;
|
|
Toshihiro Shimizu |
890ddd |
double tot_sum = 0;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//interactive!
|
|
Toshihiro Shimizu |
890ddd |
//if (Factor == 0)
|
|
Toshihiro Shimizu |
890ddd |
rGr->lock();
|
|
Toshihiro Shimizu |
890ddd |
rCm->lock();
|
|
Toshihiro Shimizu |
890ddd |
for (i = 1; i < params.m_r->getLy() - 1; i++) {
|
|
Toshihiro Shimizu |
890ddd |
int line_sum = 0, num_points = 0;
|
|
Toshihiro Shimizu |
890ddd |
bufGr = rGr->pixels(i) + 1;
|
|
Toshihiro Shimizu |
890ddd |
bufCmap = rCm->pixels(i) + 1;
|
|
Toshihiro Shimizu |
890ddd |
for (j = 1; j < rGr->getLx() - 1; j++, bufGr++, bufCmap++) {
|
|
Toshihiro Shimizu |
890ddd |
if (bufGr->value > 0) {
|
|
Toshihiro Shimizu |
890ddd |
int paint = bufCmap->getPaint();
|
|
Toshihiro Shimizu |
890ddd |
if ((bufCmap->isPurePaint() || bufGr->value != 0) &&
|
|
Toshihiro Shimizu |
890ddd |
isBorderPix(params.m_colorIndex, bufCmap, wr, bufGr, wrGr, paint)) {
|
|
Toshihiro Shimizu |
890ddd |
line_sum += troundp(bufGr->value);
|
|
Toshihiro Shimizu |
890ddd |
num_points++;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
rGr->unlock();
|
|
Toshihiro Shimizu |
890ddd |
rCm->unlock();
|
|
Toshihiro Shimizu |
890ddd |
if (num_points != 0) {
|
|
Toshihiro Shimizu |
890ddd |
tot_sum += ((float)line_sum / ((float)num_points * 255));
|
|
Toshihiro Shimizu |
890ddd |
num_lines++;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
if (num_lines == 0)
|
|
Toshihiro Shimizu |
890ddd |
return 0;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
return num_lines / tot_sum;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//*************************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
// TNoColorRasterStyle implementation
|
|
Toshihiro Shimizu |
890ddd |
//*************************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void TNoColorRasterStyle::makeIcon(const TDimension &d)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TFilePath dir = TEnv::getStuffDir() + "pixmaps";
|
|
Toshihiro Shimizu |
890ddd |
static TRasterP normalIc;
|
|
Toshihiro Shimizu |
890ddd |
if (normalIc == TRasterP())
|
|
Toshihiro Shimizu |
890ddd |
TImageReader::load(dir + "markup.bmp", normalIc);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (normalIc == TRasterP()) {
|
|
Toshihiro Shimizu |
890ddd |
m_icon = TRaster32P(d);
|
|
Toshihiro Shimizu |
890ddd |
m_icon->fill(TPixel32::Red);
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
m_icon = TRasterP();
|
|
Toshihiro Shimizu |
890ddd |
if (d == TDimension(52, 52) && normalIc != TRasterP())
|
|
Toshihiro Shimizu |
890ddd |
m_icon = normalIc->clone();
|
|
Toshihiro Shimizu |
890ddd |
else {
|
|
Toshihiro Shimizu |
890ddd |
m_icon = TRaster32P(d);
|
|
Toshihiro Shimizu |
890ddd |
TRop::resample(m_icon, normalIc, TScale(d.lx / 52.0, d.ly / 52.0));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|