|
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()
|
|
Shinya Kitaoka |
120a6e |
: m_ras()
|
|
Shinya Kitaoka |
120a6e |
, m_dpix(0)
|
|
Shinya Kitaoka |
120a6e |
, m_dpiy(0)
|
|
Shinya Kitaoka |
120a6e |
, m_subsampling(1)
|
|
Shinya Kitaoka |
120a6e |
, m_name("")
|
|
Shinya Kitaoka |
120a6e |
, m_savebox()
|
|
Shinya Kitaoka |
120a6e |
//, m_hPos(0.0)
|
|
Shinya Kitaoka |
120a6e |
, m_offset(0, 0)
|
|
Shinya Kitaoka |
120a6e |
, m_size() {}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TToonzImage::TToonzImage(const TRasterCM32P &ras, const TRect &saveBox)
|
|
Shinya Kitaoka |
120a6e |
: m_ras(ras)
|
|
Shinya Kitaoka |
120a6e |
, m_size(ras->getSize())
|
|
Shinya Kitaoka |
120a6e |
, m_dpix(0)
|
|
Shinya Kitaoka |
120a6e |
, m_dpiy(0)
|
|
Shinya Kitaoka |
120a6e |
, m_subsampling(1)
|
|
Shinya Kitaoka |
120a6e |
, m_name("")
|
|
Shinya Kitaoka |
120a6e |
, m_savebox(saveBox)
|
|
Shinya Kitaoka |
120a6e |
//, m_hPos(0.0)
|
|
Shinya Kitaoka |
120a6e |
, m_offset(0, 0) {
|
|
Shinya Kitaoka |
120a6e |
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)
|
|
Shinya Kitaoka |
120a6e |
: m_ras(TRasterCM32P())
|
|
Shinya Kitaoka |
120a6e |
, m_dpix(src.m_dpix)
|
|
Shinya Kitaoka |
120a6e |
, m_dpiy(src.m_dpiy)
|
|
Shinya Kitaoka |
120a6e |
, m_subsampling(src.m_subsampling)
|
|
Shinya Kitaoka |
120a6e |
, m_name(src.m_name)
|
|
Shinya Kitaoka |
120a6e |
, m_savebox(src.m_savebox)
|
|
Shinya Kitaoka |
120a6e |
//, m_hPos(src.m_hPos)
|
|
Shinya Kitaoka |
120a6e |
, m_offset(src.m_offset)
|
|
Shinya Kitaoka |
120a6e |
, m_size(src.m_size) {
|
|
Shinya Kitaoka |
120a6e |
if (src.m_ras) // src non e' compressa
|
|
Shinya Kitaoka |
120a6e |
{
|
|
Shinya Kitaoka |
120a6e |
m_ras = src.m_ras->clone();
|
|
Shinya Kitaoka |
120a6e |
} else {
|
|
Shinya Kitaoka |
120a6e |
assert(false);
|
|
Shinya Kitaoka |
120a6e |
assert(!src.m_ras);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
TPalette *palette = src.getPalette();
|
|
Shinya Kitaoka |
120a6e |
if (palette) {
|
|
Shinya Kitaoka |
120a6e |
m_palette = palette->clone();
|
|
Shinya Kitaoka |
120a6e |
m_palette->addRef();
|
|
Shinya Kitaoka |
120a6e |
} else
|
|
Shinya Kitaoka |
120a6e |
m_palette = 0;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
TToonzImageP TToonzImage::clone() const { return TToonzImageP(cloneImage()); }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
TToonzImage::~TToonzImage() {}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
TImage *TToonzImage::cloneImage() const { return new TToonzImage(*this); }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=========================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void TToonzImage::setSubsampling(int s) { m_subsampling = s; }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void TToonzImage::setSavebox(const TRect &rect) {
|
|
Shinya Kitaoka |
120a6e |
QMutexLocker sl(&m_mutex);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
// assert(m_lockCount>0);
|
|
Shinya Kitaoka |
120a6e |
assert(m_ras);
|
|
Shinya Kitaoka |
120a6e |
m_savebox = TRect(m_size) * rect;
|
|
Shinya Kitaoka |
120a6e |
assert(TRect(m_size).contains(m_savebox));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
namespace {
|
|
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,
|
|
Shinya Kitaoka |
120a6e |
TPaletteP palette,
|
|
Toshihiro Shimizu |
890ddd |
const TRect &theClipRect,
|
|
Shinya Kitaoka |
120a6e |
bool
|
|
Shinya Kitaoka |
120a6e |
transparencyCheck,
|
|
Shinya Kitaoka |
120a6e |
bool
|
|
Shinya Kitaoka |
120a6e |
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;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
TRect clipRectIn, clipRectOut;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (applyFx && palette->getFxRects(clipRect, clipRectIn, clipRectOut))
|
|
Shinya Kitaoka |
120a6e |
{
|
|
Shinya Kitaoka |
120a6e |
TRect rAux = clipRectIn;
|
|
Shinya Kitaoka |
120a6e |
TRasterP rAuxIn = rasIn->extract(clipRectIn);
|
|
Shinya Kitaoka |
120a6e |
if (rAux!=clipRectIn && rAux!=rasIn->getBounds())
|
|
Shinya Kitaoka |
120a6e |
{
|
|
Shinya Kitaoka |
120a6e |
TRasterCM32P rNew(rAux.getSize());
|
|
Shinya Kitaoka |
120a6e |
TRect tmpRect = clipRectIn - rAux.getP00();
|
|
Toshihiro Shimizu |
890ddd |
rNew->extract(tmpRect)->copy(rAuxIn);
|
|
Toshihiro Shimizu |
890ddd |
rAuxIn = rNew;
|
|
Shinya Kitaoka |
120a6e |
clipRectIn = rAux;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
TTile tileIn(rAuxIn, convert(clipRectIn.getP00()));
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
rAux = clipRectOut;
|
|
Shinya Kitaoka |
120a6e |
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 |
}
|
|
Shinya Kitaoka |
120a6e |
else
|
|
Shinya Kitaoka |
120a6e |
{
|
|
Shinya Kitaoka |
120a6e |
TRect clipRectIn = clipRect;
|
|
Shinya Kitaoka |
120a6e |
TRect clipRectOut = clipRect;
|
|
Shinya Kitaoka |
120a6e |
TRasterP _rasOut = rasOut->extract(clipRectOut);
|
|
Shinya Kitaoka |
120a6e |
TRasterP _rasIn;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
_rasIn = rasIn->extract(clipRectIn);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
TRop::convert(TTile(_rasOut, convert(clipRectOut.getP00())),
|
|
Shinya Kitaoka |
120a6e |
TTile(_rasIn, convert(clipRectIn.getP00())),
|
|
Shinya Kitaoka |
120a6e |
palette,
|
|
Shinya Kitaoka |
120a6e |
transparencyCheck, false);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
} // anonymous namespace
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Shinya Kitaoka |
120a6e |
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;
|
|
Shinya Kitaoka |
120a6e |
else
|
|
Toshihiro Shimizu |
890ddd |
rasCM32 = getCMapped(true);
|
|
Shinya Kitaoka |
120a6e |
|
|
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);
|
|
Shinya Kitaoka |
120a6e |
|
|
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 |
|
|
Shinya Kitaoka |
120a6e |
TRasterCM32P TToonzImage::getCMapped(/*bool readOnly*/) const {
|
|
Shinya Kitaoka |
120a6e |
/*
|
|
Shinya Kitaoka |
120a6e |
if (readOnly)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Shinya Kitaoka |
120a6e |
{
|
|
Shinya Kitaoka |
120a6e |
QMutexLocker sl(m_mutex);
|
|
Shinya Kitaoka |
120a6e |
if (m_ras)
|
|
Shinya Kitaoka |
120a6e |
return m_ras->clone();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
return decompress();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
else
|
|
Shinya Kitaoka |
120a6e |
*/
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Shinya Kitaoka |
120a6e |
// QMutexLocker sl(&m_mutex);
|
|
Shinya Kitaoka |
120a6e |
return m_ras;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void TToonzImage::setCMapped(const TRasterCM32P &ras) {
|
|
Shinya Kitaoka |
120a6e |
QMutexLocker sl(&m_mutex);
|
|
Shinya Kitaoka |
120a6e |
m_ras = ras;
|
|
Shinya Kitaoka |
120a6e |
m_size = ras->getSize();
|
|
Shinya Kitaoka |
120a6e |
m_savebox = ras->getBounds();
|
|
Shinya Kitaoka |
120a6e |
// delete [] m_compressedBuffer;
|
|
Shinya Kitaoka |
120a6e |
// m_compressedBuffer = 0;
|
|
Shinya Kitaoka |
120a6e |
// m_compressedBufferSize = 0;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void TToonzImage::getCMapped(const TRasterCM32P &ras) {
|
|
Shinya Kitaoka |
120a6e |
assert(ras && ras->getSize() == m_size);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
QMutexLocker sl(&m_mutex);
|
|
Shinya Kitaoka |
120a6e |
if (m_ras) ras->copy(m_ras);
|
|
Shinya Kitaoka |
120a6e |
/*
|
|
Shinya Kitaoka |
120a6e |
else
|
|
Shinya Kitaoka |
120a6e |
decompress(ras);
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
}
|