|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "ttoonzimage.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tpalette.h"
|
|
Toshihiro Shimizu |
890ddd |
//#include "ttile.h"
|
|
Toshihiro Shimizu |
890ddd |
//#include "transparencyCheck.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TToonzImage::TToonzImage()
|
|
Toshihiro Shimizu |
890ddd |
: m_ras(), m_dpix(0), m_dpiy(0), m_subsampling(1), m_name(""), m_savebox()
|
|
Toshihiro Shimizu |
890ddd |
//, m_hPos(0.0)
|
|
Toshihiro Shimizu |
890ddd |
,
|
|
Toshihiro Shimizu |
890ddd |
m_offset(0, 0), m_size()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TToonzImage::TToonzImage(const TRasterCM32P &ras, const TRect &saveBox)
|
|
Toshihiro Shimizu |
890ddd |
: m_ras(ras), m_size(ras->getSize()), m_dpix(0), m_dpiy(0), m_subsampling(1), m_name(""), m_savebox(saveBox)
|
|
Toshihiro Shimizu |
890ddd |
//, m_hPos(0.0)
|
|
Toshihiro Shimizu |
890ddd |
,
|
|
Toshihiro Shimizu |
890ddd |
m_offset(0, 0)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
assert(ras->getBounds().contains(saveBox));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TToonzImage::TToonzImage(const TToonzImage &src)
|
|
Toshihiro Shimizu |
890ddd |
: m_ras(TRasterCM32P()), m_dpix(src.m_dpix), m_dpiy(src.m_dpiy), m_subsampling(src.m_subsampling), m_name(src.m_name), m_savebox(src.m_savebox)
|
|
Toshihiro Shimizu |
890ddd |
//, m_hPos(src.m_hPos)
|
|
Toshihiro Shimizu |
890ddd |
,
|
|
Toshihiro Shimizu |
890ddd |
m_offset(src.m_offset), m_size(src.m_size)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (src.m_ras) //src non e' compressa
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
m_ras = src.m_ras->clone();
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
assert(false);
|
|
Toshihiro Shimizu |
890ddd |
assert(!src.m_ras);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TPalette *palette = src.getPalette();
|
|
Toshihiro Shimizu |
890ddd |
if (palette) {
|
|
Toshihiro Shimizu |
890ddd |
m_palette = palette->clone();
|
|
Toshihiro Shimizu |
890ddd |
m_palette->addRef();
|
|
Toshihiro Shimizu |
890ddd |
} else
|
|
Toshihiro Shimizu |
890ddd |
m_palette = 0;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TToonzImageP TToonzImage::clone() const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return TToonzImageP(cloneImage());
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TToonzImage::~TToonzImage()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TImage *TToonzImage::cloneImage() const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return new TToonzImage(*this);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=========================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void TToonzImage::setSubsampling(int s)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
m_subsampling = s;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void TToonzImage::setSavebox(const TRect &rect)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
QMutexLocker sl(&m_mutex);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// assert(m_lockCount>0);
|
|
Toshihiro Shimizu |
890ddd |
assert(m_ras);
|
|
Toshihiro Shimizu |
890ddd |
m_savebox = TRect(m_size) * rect;
|
|
Toshihiro Shimizu |
890ddd |
assert(TRect(m_size).contains(m_savebox));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
namespace
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
// il clipRect fa riferimento alle coordinate di rasIn
|
|
Toshihiro Shimizu |
890ddd |
// se clipRect.isEmpty() allora aggiorna tutto
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
void doUpdateRas32(const TRaster32P &rasOut,
|
|
Toshihiro Shimizu |
890ddd |
const TRasterCM32P &rasIn,
|
|
Toshihiro Shimizu |
890ddd |
TPaletteP palette,
|
|
Toshihiro Shimizu |
890ddd |
const TRect &theClipRect,
|
|
Toshihiro Shimizu |
890ddd |
bool transparencyCheck,
|
|
Toshihiro Shimizu |
890ddd |
bool applyFx)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
assert(palette);
|
|
Toshihiro Shimizu |
890ddd |
assert(rasIn && rasOut);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
applyFx = true;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TRect clipRect(theClipRect);
|
|
Toshihiro Shimizu |
890ddd |
if(clipRect.isEmpty())
|
|
Toshihiro Shimizu |
890ddd |
clipRect = rasIn->getBounds();
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if(!clipRect.overlaps(rasIn->getBounds())) return;
|
|
Toshihiro Shimizu |
890ddd |
clipRect = clipRect * rasIn->getBounds();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
if (clipRect.isEmpty())
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TRect clipRectIn, clipRectOut;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (applyFx && palette->getFxRects(clipRect, clipRectIn, clipRectOut))
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TRect rAux = clipRectIn;
|
|
Toshihiro Shimizu |
890ddd |
TRasterP rAuxIn = rasIn->extract(clipRectIn);
|
|
Toshihiro Shimizu |
890ddd |
if (rAux!=clipRectIn && rAux!=rasIn->getBounds())
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TRasterCM32P rNew(rAux.getSize());
|
|
Toshihiro Shimizu |
890ddd |
TRect tmpRect = clipRectIn - rAux.getP00();
|
|
Toshihiro Shimizu |
890ddd |
rNew->extract(tmpRect)->copy(rAuxIn);
|
|
Toshihiro Shimizu |
890ddd |
rAuxIn = rNew;
|
|
Toshihiro Shimizu |
890ddd |
clipRectIn = rAux;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
TTile tileIn(rAuxIn, convert(clipRectIn.getP00()));
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
rAux = clipRectOut;
|
|
Toshihiro Shimizu |
890ddd |
TRasterP rAuxOut = rasOut->extract(clipRectOut);
|
|
Toshihiro Shimizu |
890ddd |
TTile tileOut(rAuxOut, convert(clipRectOut.getP00()));
|
|
Toshihiro Shimizu |
890ddd |
TRop::convert(tileOut, tileIn, palette, transparencyCheck, true);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TRect clipRectIn = clipRect;
|
|
Toshihiro Shimizu |
890ddd |
TRect clipRectOut = clipRect;
|
|
Toshihiro Shimizu |
890ddd |
TRasterP _rasOut = rasOut->extract(clipRectOut);
|
|
Toshihiro Shimizu |
890ddd |
TRasterP _rasIn;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
_rasIn = rasIn->extract(clipRectIn);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TRop::convert(TTile(_rasOut, convert(clipRectOut.getP00())),
|
|
Toshihiro Shimizu |
890ddd |
TTile(_rasIn, convert(clipRectIn.getP00())),
|
|
Toshihiro Shimizu |
890ddd |
palette, transparencyCheck, false);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
} // anonymous namespace
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
TRaster32P TToonzImage::getRGBM(bool readOnly, bool computeFx)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (readOnly)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
QMutexLocker sl(m_mutex);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (m_ras32)
|
|
Toshihiro Shimizu |
890ddd |
return m_ras32->clone();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TRasterCM32P rasCM32;
|
|
Toshihiro Shimizu |
890ddd |
if (m_ras)
|
|
Toshihiro Shimizu |
890ddd |
rasCM32 = m_ras;
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
rasCM32 = getCMapped(true);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
assert(rasCM32);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TPalette *palette = getPalette();
|
|
Toshihiro Shimizu |
890ddd |
assert(palette);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TRaster32P ras32(rasCM32->getSize());
|
|
Toshihiro Shimizu |
890ddd |
const TPixel32 bgColor(255,255,255,0);
|
|
Toshihiro Shimizu |
890ddd |
ras32->fillOutside(m_savebox, bgColor);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
doUpdateRas32(ras32, rasCM32, palette, m_savebox, false, computeFx);
|
|
Toshihiro Shimizu |
890ddd |
return ras32;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
QMutexLocker sl(m_mutex);
|
|
Toshihiro Shimizu |
890ddd |
return m_ras32;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TRasterCM32P TToonzImage::getCMapped(/*bool readOnly*/) const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
if (readOnly)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
QMutexLocker sl(m_mutex);
|
|
Toshihiro Shimizu |
890ddd |
if (m_ras)
|
|
Toshihiro Shimizu |
890ddd |
return m_ras->clone();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
return decompress();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
//QMutexLocker sl(&m_mutex);
|
|
Toshihiro Shimizu |
890ddd |
return m_ras;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void TToonzImage::setCMapped(const TRasterCM32P &ras)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
QMutexLocker sl(&m_mutex);
|
|
Toshihiro Shimizu |
890ddd |
m_ras = ras;
|
|
Toshihiro Shimizu |
890ddd |
m_size = ras->getSize();
|
|
Toshihiro Shimizu |
890ddd |
m_savebox = ras->getBounds();
|
|
Toshihiro Shimizu |
890ddd |
//delete [] m_compressedBuffer;
|
|
Toshihiro Shimizu |
890ddd |
//m_compressedBuffer = 0;
|
|
Toshihiro Shimizu |
890ddd |
//m_compressedBufferSize = 0;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void TToonzImage::getCMapped(const TRasterCM32P &ras)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
assert(ras && ras->getSize() == m_size);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
QMutexLocker sl(&m_mutex);
|
|
Toshihiro Shimizu |
890ddd |
if (m_ras)
|
|
Toshihiro Shimizu |
890ddd |
ras->copy(m_ras);
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
decompress(ras);
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
}
|