|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
9f5a1b |
#ifdef _WIN32
|
|
Toshihiro Shimizu |
890ddd |
#ifndef UNICODE
|
|
Toshihiro Shimizu |
890ddd |
#define UNICODE
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "tbigmemorymanager.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "traster.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "trastercm.h"
|
|
Toshihiro Shimizu |
890ddd |
//#include "tspecialstyleid.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tpixel.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tpixelgr.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "timagecache.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
DEFINE_CLASS_CODE(TRaster, 1)
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TRaster::TRaster(int lx, int ly, int pixelSize)
|
|
Toshihiro Shimizu |
890ddd |
: TSmartObject(m_classCode), m_pixelSize(pixelSize), m_lx(lx), m_ly(ly), m_wrap(lx), m_parent(0), m_bufferOwner(true), m_buffer(0), m_lockCount(0)
|
|
Toshihiro Shimizu |
890ddd |
#ifdef _DEBUG
|
|
Toshihiro Shimizu |
890ddd |
,
|
|
Toshihiro Shimizu |
890ddd |
m_cashed(false)
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
//try
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
assert(pixelSize > 0);
|
|
Toshihiro Shimizu |
890ddd |
assert(lx > 0 && ly > 0);
|
|
Toshihiro Shimizu |
890ddd |
TBigMemoryManager::instance()->putRaster(this);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//m_buffer = new UCHAR[lx*ly*pixelSize];
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (!m_buffer) {
|
|
Shinya Kitaoka |
9f5a1b |
#ifdef _WIN32
|
|
Toshihiro Shimizu |
890ddd |
static bool firstTime = true;
|
|
Toshihiro Shimizu |
890ddd |
if (firstTime) {
|
|
Toshihiro Shimizu |
890ddd |
firstTime = false;
|
|
Toshihiro Shimizu |
890ddd |
unsigned long size = pixelSize * lx * ly;
|
|
Toshihiro Shimizu |
890ddd |
TImageCache::instance()->outputMap(size, "C:\\runout");
|
|
Toshihiro Shimizu |
890ddd |
(*TBigMemoryManager::instance()->m_runOutCallback)(size);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// TBigMemoryManager::instance()->checkConsistency();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//m_totalMemory += ((lx*ly*pixelSize)>>10);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
/* catch(...)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TImageCache::instance()->putAllOnDisk();
|
|
Toshihiro Shimizu |
890ddd |
m_buffer = BigMemoryManager.getMemoryChunk(lx*ly*pixelSize, this);
|
|
Toshihiro Shimizu |
890ddd |
//m_buffer = new UCHAR[lx*ly*pixelSize];
|
|
Toshihiro Shimizu |
890ddd |
m_totalMemory += ((lx*ly*pixelSize)>>10);
|
|
Shinya Kitaoka |
9f5a1b |
#ifdef _WIN32
|
|
Toshihiro Shimizu |
890ddd |
MessageBox( NULL, "Run out of contiguos phisical memory: please save all and restart toonz!", "Warning", MB_OK);
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
}*/
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TRaster::TRaster(int lx, int ly, int pixelSize,
|
|
Toshihiro Shimizu |
890ddd |
int wrap, UCHAR *buffer, TRaster *parent, bool bufferOwner)
|
|
Toshihiro Shimizu |
890ddd |
: TSmartObject(m_classCode), m_pixelSize(pixelSize), m_lx(lx), m_ly(ly), m_wrap(wrap), m_buffer(buffer), m_bufferOwner(bufferOwner), m_lockCount(0)
|
|
Toshihiro Shimizu |
890ddd |
#ifdef _DEBUG
|
|
Toshihiro Shimizu |
890ddd |
,
|
|
Toshihiro Shimizu |
890ddd |
m_cashed(false)
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (parent) {
|
|
Toshihiro Shimizu |
890ddd |
assert(bufferOwner == false);
|
|
Toshihiro Shimizu |
890ddd |
while (parent->m_parent)
|
|
Toshihiro Shimizu |
890ddd |
parent = parent->m_parent;
|
|
Toshihiro Shimizu |
890ddd |
parent->addRef();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
#ifdef _DEBUG
|
|
Toshihiro Shimizu |
890ddd |
else if (bufferOwner)
|
|
Toshihiro Shimizu |
890ddd |
TBigMemoryManager::instance()->m_totRasterMemInKb += ((m_lx * m_ly * m_pixelSize) >> 10);
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
m_parent = parent;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
assert(pixelSize > 0);
|
|
Toshihiro Shimizu |
890ddd |
assert(lx > 0 && ly > 0);
|
|
Toshihiro Shimizu |
890ddd |
assert(wrap >= lx);
|
|
Toshihiro Shimizu |
890ddd |
assert(m_buffer);
|
|
Toshihiro Shimizu |
890ddd |
//if (parent)
|
|
Toshihiro Shimizu |
890ddd |
TBigMemoryManager::instance()->putRaster(this);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// TBigMemoryManager::instance()->checkConsistency();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//TAtomicVar TRaster::m_totalMemory;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//unsigned long TRaster::getTotalMemoryInKB(){ return m_totalMemory;}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TRaster::~TRaster()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
bool parent = false;
|
|
Toshihiro Shimizu |
890ddd |
#ifdef _DEBUG
|
|
Toshihiro Shimizu |
890ddd |
//TBigMemoryManager::instance()->checkConsistency();
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
//bool ret =
|
|
Toshihiro Shimizu |
890ddd |
TBigMemoryManager::instance()->releaseRaster(this);
|
|
Toshihiro Shimizu |
890ddd |
#ifdef _DEBUG
|
|
Toshihiro Shimizu |
890ddd |
//TBigMemoryManager::instance()->checkConsistency();
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
if (m_parent) {
|
|
Toshihiro Shimizu |
890ddd |
assert(!m_bufferOwner);
|
|
Toshihiro Shimizu |
890ddd |
m_parent->release();
|
|
Toshihiro Shimizu |
890ddd |
m_parent = 0;
|
|
Toshihiro Shimizu |
890ddd |
parent = true;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//if(m_buffer && m_bufferOwner)
|
|
Toshihiro Shimizu |
890ddd |
// {
|
|
Toshihiro Shimizu |
890ddd |
//delete [] m_buffer;
|
|
Toshihiro Shimizu |
890ddd |
//m_totalMemory += -((m_lx*m_ly*m_pixelSize)>>10);
|
|
Toshihiro Shimizu |
890ddd |
//assert(m_totalMemory>=0);
|
|
Toshihiro Shimizu |
890ddd |
// }
|
|
Toshihiro Shimizu |
890ddd |
// UCHAR* aux = m_buffer;
|
|
Toshihiro Shimizu |
890ddd |
m_buffer = 0;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#ifdef _DEBUG
|
|
Toshihiro Shimizu |
890ddd |
//TBigMemoryManager::instance()->checkConsistency();
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
void TRaster::beginRemapping()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
m_mutex.lock();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void TRaster::endRemapping()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
m_mutex.unlock();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
void TRaster::lock()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (m_parent) m_parent->lock();
|
|
Toshihiro Shimizu |
890ddd |
else ++m_lockCount;
|
|
Toshihiro Shimizu |
890ddd |
//TBigMemoryManager::instance()->lock(m_parent?(m_parent->m_buffer):m_buffer);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void TRaster::unlock()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (m_parent) m_parent->unlock();
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
assert(m_lockCount>0);
|
|
Toshihiro Shimizu |
890ddd |
--m_lockCount;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//TBigMemoryManager::instance()->unlock(m_parent?(m_parent->m_buffer):m_buffer);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
template<class t=""></class>
|
|
Toshihiro Shimizu |
890ddd |
TRasterT<t>::TRasterT<t>(int lx, int ly) : TRaster(lx,ly,sizeof(T)) {}</t></t>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// utilizzo di un raster preesistente
|
|
Toshihiro Shimizu |
890ddd |
template<class t=""></class>
|
|
Toshihiro Shimizu |
890ddd |
TRasterT<t>::TRasterT<t>(int lx, int ly, int wrap, T *buffer, TRasterT<t> *parent) </t></t></t>
|
|
Toshihiro Shimizu |
890ddd |
: TRaster(lx,ly,sizeof(T), wrap
|
|
Toshihiro Shimizu |
890ddd |
, reinterpret_cast<uchar*>(buffer), parent) {}</uchar*>
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void TRaster::fillRawData(const UCHAR *color)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (m_lx == 0 || m_ly == 0)
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// N.B. uso la convenzione stl per end()
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
const int wrapSize = m_wrap * m_pixelSize;
|
|
Toshihiro Shimizu |
890ddd |
const int rowSize = m_lx * m_pixelSize;
|
|
Toshihiro Shimizu |
890ddd |
UCHAR *buf1 = m_parent ? m_parent->m_buffer : m_buffer;
|
|
Toshihiro Shimizu |
890ddd |
lock();
|
|
Toshihiro Shimizu |
890ddd |
unsigned char *firstPixel = getRawData();
|
|
Toshihiro Shimizu |
890ddd |
const unsigned char *lastPixel = firstPixel +
|
|
Toshihiro Shimizu |
890ddd |
wrapSize * (m_ly - 1) + m_pixelSize * (m_lx - 1);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// riempio la prima riga
|
|
Toshihiro Shimizu |
890ddd |
unsigned char *pixel = firstPixel;
|
|
Toshihiro Shimizu |
890ddd |
const unsigned char *endpixel = firstPixel + rowSize;
|
|
Toshihiro Shimizu |
890ddd |
while (pixel < endpixel) {
|
|
Toshihiro Shimizu |
890ddd |
assert(firstPixel <= pixel && pixel <= lastPixel);
|
|
Toshihiro Shimizu |
890ddd |
::memcpy(pixel, color, m_pixelSize);
|
|
Toshihiro Shimizu |
890ddd |
pixel += m_pixelSize;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// riempio le altre
|
|
Toshihiro Shimizu |
890ddd |
pixel += wrapSize - rowSize;
|
|
Toshihiro Shimizu |
890ddd |
const unsigned char *endrow = pixel + wrapSize * (m_ly - 1);
|
|
Toshihiro Shimizu |
890ddd |
while (pixel < endrow) {
|
|
Toshihiro Shimizu |
890ddd |
assert(firstPixel <= pixel && pixel + rowSize - m_pixelSize <= lastPixel);
|
|
Toshihiro Shimizu |
890ddd |
::memcpy(pixel, firstPixel, rowSize);
|
|
Toshihiro Shimizu |
890ddd |
pixel += wrapSize;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
UCHAR *buf2 = m_parent ? m_parent->m_buffer : m_buffer;
|
|
Toshihiro Shimizu |
890ddd |
unlock();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void TRaster::fillRawDataOutside(const TRect &rect, const unsigned char *pixel)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (m_lx == 0 || m_ly == 0)
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
TRect r = rect * getBounds();
|
|
Toshihiro Shimizu |
890ddd |
if (r.isEmpty())
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (r.y0 > 0) // fascia "inferiore"
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TRect bounds(0, 0, m_lx - 1, r.y0 - 1);
|
|
Toshihiro Shimizu |
890ddd |
extract(bounds)->fillRawData(pixel);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (rect.y1 < m_ly - 1) // fascia "superiore"
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TRect bounds(0, r.y1 + 1, m_lx - 1, m_ly - 1);
|
|
Toshihiro Shimizu |
890ddd |
extract(bounds)->fillRawData(pixel);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (rect.x0 > 0) // zona "a sinistra"
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TRect bounds(0, r.y0, r.x0 - 1, r.y1);
|
|
Toshihiro Shimizu |
890ddd |
extract(bounds)->fillRawData(pixel);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (rect.x1 < m_lx - 1) // zona "a destra"
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TRect bounds(r.x1 + 1, r.y0, m_lx - 1, r.y1);
|
|
Toshihiro Shimizu |
890ddd |
extract(bounds)->fillRawData(pixel);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void TRaster::copy(const TRasterP &src0, const TPoint &offset)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
assert(m_pixelSize == src0->getPixelSize());
|
|
Toshihiro Shimizu |
890ddd |
TRect rect = getBounds() * (src0->getBounds() + offset);
|
|
Toshihiro Shimizu |
890ddd |
if (rect.isEmpty())
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
TRasterP dst = extract(rect);
|
|
Toshihiro Shimizu |
890ddd |
TRect r(rect);
|
|
Toshihiro Shimizu |
890ddd |
r -= offset;
|
|
Toshihiro Shimizu |
890ddd |
//TRasterP src = src0->extract(rect - offset);
|
|
Toshihiro Shimizu |
890ddd |
TRasterP src = src0->extract(r);
|
|
Toshihiro Shimizu |
890ddd |
assert(dst->getSize() == src->getSize());
|
|
Toshihiro Shimizu |
890ddd |
dst->lock();
|
|
Toshihiro Shimizu |
890ddd |
src0->lock();
|
|
Toshihiro Shimizu |
890ddd |
if (dst->getLx() == dst->getWrap() && src->getLx() == src->getWrap()) {
|
|
Toshihiro Shimizu |
890ddd |
int size = rect.getLx() * rect.getLy() * m_pixelSize;
|
|
Toshihiro Shimizu |
890ddd |
::memcpy(dst->getRawData(), src->getRawData(), size);
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
int rowSize = dst->getLx() * m_pixelSize;
|
|
Toshihiro Shimizu |
890ddd |
int srcWrapSize = src->getWrap() * m_pixelSize;
|
|
Toshihiro Shimizu |
890ddd |
int dstWrapSize = dst->getWrap() * m_pixelSize;
|
|
Toshihiro Shimizu |
890ddd |
const UCHAR *srcRow = src->getRawData();
|
|
Toshihiro Shimizu |
890ddd |
UCHAR *dstRow = dst->getRawData();
|
|
Toshihiro Shimizu |
890ddd |
UCHAR *maxDstRow = dstRow + dstWrapSize * dst->getLy();
|
|
Toshihiro Shimizu |
890ddd |
while (dstRow < maxDstRow) {
|
|
Toshihiro Shimizu |
890ddd |
::memcpy(dstRow, srcRow, rowSize);
|
|
Toshihiro Shimizu |
890ddd |
dstRow += dstWrapSize;
|
|
Toshihiro Shimizu |
890ddd |
srcRow += srcWrapSize;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
dst->unlock();
|
|
Toshihiro Shimizu |
890ddd |
src0->unlock();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void TRaster::yMirror()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
const int rowSize = m_lx * m_pixelSize;
|
|
Toshihiro Shimizu |
890ddd |
const int wrapSize = m_wrap * m_pixelSize;
|
|
Shinya Kitaoka |
6a4e01 |
std::unique_ptr<uchar[]> auxBuf(new UCHAR[rowSize]);</uchar[]>
|
|
Toshihiro Shimizu |
890ddd |
lock();
|
|
Toshihiro Shimizu |
890ddd |
UCHAR *buff1 = getRawData();
|
|
Toshihiro Shimizu |
890ddd |
UCHAR *buff2 = getRawData(0, (m_ly - 1));
|
|
Toshihiro Shimizu |
890ddd |
while (buff1 < buff2) {
|
|
Shinya Kitaoka |
6a4e01 |
::memcpy(auxBuf.get(), buff1, rowSize);
|
|
Toshihiro Shimizu |
890ddd |
::memcpy(buff1, buff2, rowSize);
|
|
Shinya Kitaoka |
6a4e01 |
::memcpy(buff2, auxBuf.get(), rowSize);
|
|
Toshihiro Shimizu |
890ddd |
buff1 += wrapSize;
|
|
Toshihiro Shimizu |
890ddd |
buff2 -= wrapSize;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
unlock();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void TRaster::xMirror()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
const int wrapSize = m_wrap * m_pixelSize;
|
|
Toshihiro Shimizu |
890ddd |
const int lastPixelOffset = (m_lx - 1) * m_pixelSize;
|
|
Shinya Kitaoka |
6a4e01 |
std::unique_ptr<uchar[]> auxBuf(new UCHAR[m_pixelSize]);</uchar[]>
|
|
Toshihiro Shimizu |
890ddd |
lock();
|
|
Toshihiro Shimizu |
890ddd |
UCHAR *row = getRawData();
|
|
Toshihiro Shimizu |
890ddd |
for (int i = 0; i < m_ly; i++) {
|
|
Toshihiro Shimizu |
890ddd |
UCHAR *a = row, *b = row + lastPixelOffset;
|
|
Toshihiro Shimizu |
890ddd |
while (a < b) {
|
|
Shinya Kitaoka |
6a4e01 |
::memcpy(auxBuf.get(), a, m_pixelSize);
|
|
Toshihiro Shimizu |
890ddd |
::memcpy(a, b, m_pixelSize);
|
|
Shinya Kitaoka |
6a4e01 |
::memcpy(b, auxBuf.get(), m_pixelSize);
|
|
Toshihiro Shimizu |
890ddd |
a += m_pixelSize;
|
|
Toshihiro Shimizu |
890ddd |
b -= m_pixelSize;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
row += wrapSize;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
unlock();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void TRaster::rotate180()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
//const int rowSize = m_lx * m_pixelSize;
|
|
Toshihiro Shimizu |
890ddd |
const int wrapSize = m_wrap * m_pixelSize;
|
|
Shinya Kitaoka |
6a4e01 |
std::unique_ptr<uchar[]> auxBuf(new UCHAR[m_pixelSize]);</uchar[]>
|
|
Toshihiro Shimizu |
890ddd |
lock();
|
|
Toshihiro Shimizu |
890ddd |
UCHAR *buff1 = getRawData();
|
|
Toshihiro Shimizu |
890ddd |
UCHAR *buff2 = buff1 + wrapSize * (m_ly - 1) + m_pixelSize * (m_lx - 1);
|
|
Toshihiro Shimizu |
890ddd |
if (m_wrap == m_lx) {
|
|
Toshihiro Shimizu |
890ddd |
while (buff1 < buff2) {
|
|
Shinya Kitaoka |
6a4e01 |
::memcpy(auxBuf.get(), buff1, m_pixelSize);
|
|
Toshihiro Shimizu |
890ddd |
::memcpy(buff1, buff2, m_pixelSize);
|
|
Shinya Kitaoka |
6a4e01 |
::memcpy(buff2, auxBuf.get(), m_pixelSize);
|
|
Toshihiro Shimizu |
890ddd |
buff1 += m_pixelSize;
|
|
Toshihiro Shimizu |
890ddd |
buff2 -= m_pixelSize;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
for (int y = 0; y < m_ly / 2; y++) {
|
|
Toshihiro Shimizu |
890ddd |
UCHAR *a = buff1, *b = buff2;
|
|
Toshihiro Shimizu |
890ddd |
for (int x = 0; x < m_lx; x++) {
|
|
Shinya Kitaoka |
6a4e01 |
::memcpy(auxBuf.get(), a, m_pixelSize);
|
|
Toshihiro Shimizu |
890ddd |
::memcpy(a, b, m_pixelSize);
|
|
Shinya Kitaoka |
6a4e01 |
::memcpy(b, auxBuf.get(), m_pixelSize);
|
|
Toshihiro Shimizu |
890ddd |
a += m_pixelSize;
|
|
Toshihiro Shimizu |
890ddd |
b -= m_pixelSize;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
buff1 += wrapSize;
|
|
Toshihiro Shimizu |
890ddd |
buff2 -= wrapSize;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
unlock();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void TRaster::rotate90()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
UCHAR *auxBuf= new UCHAR[m_pixelSize];
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
for(int y=m_ly;y>0;y--)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
UCHAR *a = getRawData() + wrapSize * (y-1) + m_pixelSize * (m_lx-1);
|
|
Toshihiro Shimizu |
890ddd |
for (int x=m_lx-1;x>=0;x--)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
UCHAR *b = a - (m_ly-1)*m_pixelSize *(m_lx-x);
|
|
Toshihiro Shimizu |
890ddd |
::memcpy(auxBuf, a, m_pixelSize);
|
|
Toshihiro Shimizu |
890ddd |
::memcpy(a, b, m_pixelSize);
|
|
Toshihiro Shimizu |
890ddd |
::memcpy(b, auxBuf, m_pixelSize);
|
|
Toshihiro Shimizu |
890ddd |
a-=m_pixelSize;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void TRaster::clear()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TRasterCM32 *ras = dynamic_cast<trastercm32 *="">(this);</trastercm32>
|
|
Toshihiro Shimizu |
890ddd |
if (ras) {
|
|
Toshihiro Shimizu |
890ddd |
// ras->fill(TPixelCM32(0,BackgroundStyle,TPixelCM32::getMaxTone()));
|
|
Toshihiro Shimizu |
890ddd |
ras->fill(TPixelCM32());
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
const int rowSize = getRowSize();
|
|
Toshihiro Shimizu |
890ddd |
lock();
|
|
Toshihiro Shimizu |
890ddd |
if (m_wrap == m_lx) {
|
|
Toshihiro Shimizu |
890ddd |
int bufferSize = rowSize * m_ly;
|
|
Toshihiro Shimizu |
890ddd |
memset(getRawData(), 0, bufferSize);
|
|
Toshihiro Shimizu |
890ddd |
} else
|
|
Toshihiro Shimizu |
890ddd |
for (int y = m_ly - 1; y >= 0; y--) {
|
|
Toshihiro Shimizu |
890ddd |
UCHAR *buffer = getRawData(0, y);
|
|
Toshihiro Shimizu |
890ddd |
memset(buffer, 0, rowSize);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
unlock();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void TRaster::remap(UCHAR *newLocation)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (m_parent) {
|
|
Toshihiro Shimizu |
890ddd |
assert(m_parent->m_buffer > newLocation);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
assert(m_parent->m_parent == 0);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int offset = (int)(m_buffer - m_parent->m_buffer);
|
|
Toshihiro Shimizu |
890ddd |
assert(offset >= 0);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//m_parent->remap(newLocation);
|
|
Toshihiro Shimizu |
890ddd |
m_buffer = newLocation + offset;
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
assert(m_buffer > newLocation);
|
|
Toshihiro Shimizu |
890ddd |
m_buffer = newLocation;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void TRaster::clearOutside(const TRect &rect)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (m_lx == 0 || m_ly == 0)
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
TRect r = rect * getBounds();
|
|
Toshihiro Shimizu |
890ddd |
if (r.isEmpty())
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (r.y0 > 0) // fascia "inferiore"
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TRect bounds(0, 0, m_lx - 1, r.y0 - 1);
|
|
Toshihiro Shimizu |
890ddd |
extract(bounds)->clear();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (rect.y1 < m_ly - 1) // fascia "superiore"
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TRect bounds(0, r.y1 + 1, m_lx - 1, m_ly - 1);
|
|
Toshihiro Shimizu |
890ddd |
extract(bounds)->clear();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (rect.x0 > 0) // zona "a sinistra"
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TRect bounds(0, r.y0, r.x0 - 1, r.y1);
|
|
Toshihiro Shimizu |
890ddd |
extract(bounds)->clear();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (rect.x1 < m_lx - 1) // zona "a destra"
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TRect bounds(r.x1 + 1, r.y0, m_lx - 1, r.y1);
|
|
Toshihiro Shimizu |
890ddd |
extract(bounds)->clear();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|