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