|
Shinya Kitaoka |
810553 |
#pragma once
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#ifndef T_RASTER_INCLUDED
|
|
Toshihiro Shimizu |
890ddd |
#define T_RASTER_INCLUDED
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "tutil.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tgeometry.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tpixel.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tpixelgr.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tsmartpointer.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tbigmemorymanager.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#undef DVAPI
|
|
Toshihiro Shimizu |
890ddd |
#undef DVVAR
|
|
Toshihiro Shimizu |
890ddd |
#ifdef TRASTER_EXPORTS
|
|
Toshihiro Shimizu |
890ddd |
#define DVAPI DV_EXPORT_API
|
|
Toshihiro Shimizu |
890ddd |
#define DVVAR DV_EXPORT_VAR
|
|
Toshihiro Shimizu |
890ddd |
#else
|
|
Toshihiro Shimizu |
890ddd |
#define DVAPI DV_IMPORT_API
|
|
Toshihiro Shimizu |
890ddd |
#define DVVAR DV_IMPORT_VAR
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=========================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
class DVAPI TRasterType {
|
|
Shinya Kitaoka |
120a6e |
int m_id;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
/*
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
120a6e |
enum Type {
|
|
Shinya Kitaoka |
120a6e |
None,
|
|
Shinya Kitaoka |
120a6e |
BW,
|
|
Shinya Kitaoka |
120a6e |
WB,
|
|
Shinya Kitaoka |
120a6e |
RGBM32, // LPIXEL, matte channel considered
|
|
Shinya Kitaoka |
120a6e |
RGBM64, // SPIXEL, matte channel considered
|
|
Shinya Kitaoka |
120a6e |
CM8, // color-mapped, 8 bits
|
|
Shinya Kitaoka |
120a6e |
GR8, // grey tones, 8 bits
|
|
Shinya Kitaoka |
120a6e |
CM16, // color-mapped, 16 bits
|
|
Shinya Kitaoka |
120a6e |
GR16, // grey tones, 16 bits
|
|
Shinya Kitaoka |
120a6e |
RGB555,
|
|
Shinya Kitaoka |
120a6e |
RGB565,
|
|
Shinya Kitaoka |
120a6e |
CM24, // cmapped, 8+8+8 bits (ink, paint, ramp), +8 bits spare
|
|
Shinya Kitaoka |
120a6e |
(MSB)
|
|
Shinya Kitaoka |
120a6e |
CM16S12,
|
|
Shinya Kitaoka |
120a6e |
CM16S8 // cmapped, 16 bits, standard SGI 256-color colormap
|
|
Shinya Kitaoka |
120a6e |
// ....
|
|
Shinya Kitaoka |
120a6e |
};
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
120a6e |
TRasterType(int id) : m_id(id){};
|
|
Shinya Kitaoka |
120a6e |
int getId() const { return m_id; };
|
|
Shinya Kitaoka |
120a6e |
bool operator==(TRasterType a) { return m_id == a.m_id; };
|
|
Shinya Kitaoka |
120a6e |
bool operator!=(TRasterType a) { return m_id != a.m_id; };
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=========================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// forward declaration
|
|
Toshihiro Shimizu |
890ddd |
template <class t=""></class>
|
|
Toshihiro Shimizu |
890ddd |
class TRasterPT;
|
|
Toshihiro Shimizu |
890ddd |
class TRaster;
|
|
Toshihiro Shimizu |
890ddd |
typedef TSmartPointerT<traster> TRasterP;</traster>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=========================================================
|
|
Toshihiro Shimizu |
890ddd |
/*!This class stores bitmap images. */
|
|
Shinya Kitaoka |
120a6e |
class DVAPI TRaster : public TSmartObject {
|
|
Shinya Kitaoka |
120a6e |
DECLARE_CLASS_CODE
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
protected:
|
|
Shinya Kitaoka |
120a6e |
int m_pixelSize;
|
|
Shinya Kitaoka |
120a6e |
int m_lx, m_ly;
|
|
Shinya Kitaoka |
120a6e |
int m_wrap;
|
|
Shinya Kitaoka |
120a6e |
int m_lockCount;
|
|
Shinya Kitaoka |
120a6e |
TRaster *m_parent; // nel caso di sotto-raster
|
|
Shinya Kitaoka |
120a6e |
UCHAR *m_buffer;
|
|
Shinya Kitaoka |
120a6e |
bool m_bufferOwner;
|
|
Shinya Kitaoka |
120a6e |
// i costruttori sono qui per centralizzare la gestione della memoria
|
|
Shinya Kitaoka |
120a6e |
// e' comunque impossibile fare new TRaster perche' e' una classe astratta
|
|
Shinya Kitaoka |
120a6e |
// (clone, extract)
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// crea il buffer associato (NON fa addRef())
|
|
Shinya Kitaoka |
120a6e |
TRaster(int lx, int ly, int pixelSize);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// si attacca ad un buffer pre-esistente (NON fa addRef() - neanche a parent)
|
|
Shinya Kitaoka |
120a6e |
TRaster(int lx, int ly, int pixelSize, int wrap, UCHAR *buffer,
|
|
Shinya Kitaoka |
120a6e |
TRaster *parent, bool bufferOwner = false);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
private:
|
|
Shinya Kitaoka |
120a6e |
static TAtomicVar m_totalMemory;
|
|
Shinya Kitaoka |
120a6e |
TThread::Mutex m_mutex;
|
|
Shinya Kitaoka |
120a6e |
// not implemented
|
|
Shinya Kitaoka |
120a6e |
TRaster(const TRaster &);
|
|
Shinya Kitaoka |
120a6e |
TRaster &operator=(const TRaster &);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Toshihiro Shimizu |
890ddd |
#ifdef _DEBUG
|
|
Shinya Kitaoka |
120a6e |
bool m_cashed;
|
|
Shinya Kitaoka |
120a6e |
static unsigned long getTotalMemoryInKB();
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
virtual ~TRaster();
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// accessors
|
|
Shinya Kitaoka |
120a6e |
// TRasterType getType() const {return m_type;};
|
|
Shinya Kitaoka |
120a6e |
int getLx() const { return m_lx; };
|
|
Shinya Kitaoka |
120a6e |
int getLy() const { return m_ly; };
|
|
Shinya Kitaoka |
120a6e |
TDimension getSize() const { return TDimension(m_lx, m_ly); };
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
//! Returns the length of a row in pixel.
|
|
Shinya Kitaoka |
120a6e |
int getWrap() const { return m_wrap; }; // lunghezza di una riga in pixel
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
TPointD getCenterD() const { return TPointD(0.5 * m_lx, 0.5 * m_ly); };
|
|
Shinya Kitaoka |
120a6e |
TPoint getCenter() const { return TPoint(m_lx / 2, m_ly / 2); };
|
|
Shinya Kitaoka |
120a6e |
TRect getBounds() const { return TRect(0, 0, m_lx - 1, m_ly - 1); };
|
|
Shinya Kitaoka |
120a6e |
int getPixelSize() const { return m_pixelSize; };
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
int getRowSize() const { return m_pixelSize * m_lx; };
|
|
Shinya Kitaoka |
120a6e |
// in bytes
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// when the bigMemoryManager is active, remapping can change buffers...need to
|
|
Shinya Kitaoka |
120a6e |
// to lock/unlock them o use them.
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
void lock() {
|
|
Shinya Kitaoka |
120a6e |
if (!TBigMemoryManager::instance()->isActive()) return;
|
|
Shinya Kitaoka |
120a6e |
TThread::MutexLocker sl(&m_mutex);
|
|
Shinya Kitaoka |
120a6e |
if (m_parent)
|
|
Shinya Kitaoka |
120a6e |
m_parent->lock();
|
|
Shinya Kitaoka |
120a6e |
else
|
|
Shinya Kitaoka |
120a6e |
++m_lockCount;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
void unlock() {
|
|
Shinya Kitaoka |
120a6e |
if (!TBigMemoryManager::instance()->isActive()) return;
|
|
Shinya Kitaoka |
120a6e |
TThread::MutexLocker sl(&m_mutex);
|
|
Shinya Kitaoka |
120a6e |
if (m_parent)
|
|
Shinya Kitaoka |
120a6e |
m_parent->unlock();
|
|
Shinya Kitaoka |
120a6e |
else {
|
|
Shinya Kitaoka |
120a6e |
assert(m_lockCount > 0);
|
|
Shinya Kitaoka |
120a6e |
--m_lockCount;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
void beginRemapping();
|
|
Shinya Kitaoka |
120a6e |
void endRemapping();
|
|
Shinya Kitaoka |
120a6e |
//! Returns a pointer to the image buffer.
|
|
Shinya Kitaoka |
120a6e |
// WARNING!!!!! before getting the buffer with getRawData(),
|
|
Shinya Kitaoka |
120a6e |
// you have to lock the raster with'lock method, and unlock
|
|
Shinya Kitaoka |
120a6e |
// it when you've done with the buffer
|
|
Shinya Kitaoka |
120a6e |
const UCHAR *getRawData() const { return m_buffer; };
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
UCHAR *getRawData() { return m_buffer; };
|
|
Shinya Kitaoka |
120a6e |
//! Returns a pointer to the image buffer positioned in the (x,y) coords.
|
|
Shinya Kitaoka |
120a6e |
const UCHAR *getRawData(int x, int y) const {
|
|
Shinya Kitaoka |
120a6e |
assert(0 <= x && x < m_lx && 0 <= y && y < m_ly);
|
|
Shinya Kitaoka |
120a6e |
return m_buffer + (y * m_wrap + x) * m_pixelSize;
|
|
Shinya Kitaoka |
120a6e |
};
|
|
Shinya Kitaoka |
120a6e |
UCHAR *getRawData(int x, int y) {
|
|
Shinya Kitaoka |
120a6e |
assert(0 <= x && x < m_lx && 0 <= y && y < m_ly);
|
|
Shinya Kitaoka |
120a6e |
return m_buffer + (y * m_wrap + x) * m_pixelSize;
|
|
Shinya Kitaoka |
120a6e |
};
|
|
Shinya Kitaoka |
120a6e |
bool isEmpty() const { return getSize() == TDimension(); };
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
TRasterP getParent() { return m_parent; }
|
|
Shinya Kitaoka |
120a6e |
// creazione di TRaster derivati
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// devono essere virtuali puri perche' il nuovo raster creato deve essere del
|
|
Shinya Kitaoka |
120a6e |
// tipo giusto
|
|
Shinya Kitaoka |
120a6e |
virtual TRasterP clone() const = 0;
|
|
Shinya Kitaoka |
120a6e |
virtual TRasterP extract(TRect &rect) = 0;
|
|
Shinya Kitaoka |
120a6e |
virtual TRasterP create() const = 0;
|
|
Shinya Kitaoka |
120a6e |
virtual TRasterP create(int lx, int ly) const = 0;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// definita in termini di extract(rect); non lo posso fare subito perche'
|
|
Shinya Kitaoka |
120a6e |
// manca il
|
|
Shinya Kitaoka |
120a6e |
// costruttore di copia di TRasterP
|
|
Shinya Kitaoka |
120a6e |
inline virtual TRasterP extract(int x0, int y0, int x1, int y1);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// operazioni sui pixel
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// Copia il contenuto di src (spostato di offset) nel raster corrente.
|
|
Shinya Kitaoka |
120a6e |
// Il tipo deve essere lo stesso
|
|
Shinya Kitaoka |
120a6e |
// In caso di dimensione diversa l'area copiata e' l'intersezione dei due
|
|
Shinya Kitaoka |
120a6e |
// getBounds()
|
|
Shinya Kitaoka |
120a6e |
// e i due raster sono allineati in basso a sinistra (src[0,0] -> dst[offset])
|
|
Shinya Kitaoka |
120a6e |
/*!Copies the content of the source raster in the current raster.
|
|
Shinya Kitaoka |
120a6e |
*/
|
|
Shinya Kitaoka |
120a6e |
void copy(const TRasterP &src, const TPoint &offset = TPoint());
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
void xMirror();
|
|
Shinya Kitaoka |
120a6e |
void yMirror();
|
|
Shinya Kitaoka |
120a6e |
void rotate180();
|
|
Shinya Kitaoka |
120a6e |
void rotate90();
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
void clear();
|
|
Shinya Kitaoka |
120a6e |
void clearOutside(const TRect &rect);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
friend class TBigMemoryManager;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
protected:
|
|
Shinya Kitaoka |
120a6e |
void fillRawData(const UCHAR *pixel);
|
|
Shinya Kitaoka |
120a6e |
void fillRawDataOutside(const TRect &rect, const UCHAR *pixel);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
private:
|
|
Shinya Kitaoka |
120a6e |
void remap(UCHAR *newLocation);
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//
|
|
Toshihiro Shimizu |
890ddd |
// Smart Pointer a TRaster
|
|
Toshihiro Shimizu |
890ddd |
//
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
9f5a1b |
#ifdef _WIN32
|
|
Toshihiro Shimizu |
890ddd |
template class DVAPI TSmartPointerT<traster>;</traster>
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
inline void detach(TRasterP &r) {
|
|
Shinya Kitaoka |
120a6e |
if (!r || r->getRefCount() == 1) return;
|
|
Shinya Kitaoka |
120a6e |
TRasterP tmp(r->clone());
|
|
Shinya Kitaoka |
120a6e |
r = tmp;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=========================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// forward declaration
|
|
Toshihiro Shimizu |
890ddd |
template <class t=""></class>
|
|
Toshihiro Shimizu |
890ddd |
class TRasterT;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//
|
|
Toshihiro Shimizu |
890ddd |
// TRasterPT<pixel>:</pixel>
|
|
Toshihiro Shimizu |
890ddd |
//
|
|
Toshihiro Shimizu |
890ddd |
// Smart Pointer to TRasterT<pixel></pixel>
|
|
Toshihiro Shimizu |
890ddd |
//
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//!\include raster_ex1.cpp
|
|
Toshihiro Shimizu |
890ddd |
//! \include rasterpt_ex1.cpp
|
|
Toshihiro Shimizu |
890ddd |
// class TRasterPT<t></t>
|
|
Toshihiro Shimizu |
890ddd |
template <class t=""></class>
|
|
Shinya Kitaoka |
d1f6c4 |
class TRasterPT final : public TSmartPointerT<trastert<t>> {</trastert<t>
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
120a6e |
typedef T Pixel;
|
|
Shinya Kitaoka |
120a6e |
typedef TRasterT<t> Raster;</t>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
TRasterPT(){};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
TRasterPT(int lx, int ly) { create(lx, ly); };
|
|
Shinya Kitaoka |
120a6e |
TRasterPT(const TDimension &d) { create(d.lx, d.ly); };
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
inline TRasterPT(const TRasterP &src);
|
|
Shinya Kitaoka |
120a6e |
inline TRasterPT(int lx, int ly, int wrap, T *buffer,
|
|
Shinya Kitaoka |
120a6e |
bool bufferOwner = false);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
~TRasterPT(){};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void create(int lx, int ly);
|
|
Shinya Kitaoka |
120a6e |
void create(const TDimension &d) { create(d.lx, d.ly); };
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
inline void detach();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
operator TRasterP() const;
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=========================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//
|
|
Toshihiro Shimizu |
890ddd |
// TRasterT<pixel></pixel>
|
|
Toshihiro Shimizu |
890ddd |
//
|
|
Toshihiro Shimizu |
890ddd |
// e' la classe concreta che discende da TRaster
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <class t=""></class>
|
|
Shinya Kitaoka |
120a6e |
class TRasterT : public TRaster {
|
|
Toshihiro Shimizu |
890ddd |
protected:
|
|
Shinya Kitaoka |
120a6e |
// Constructors are protected to prevent direct allocation of TRasterT
|
|
Shinya Kitaoka |
120a6e |
// instances.
|
|
Shinya Kitaoka |
120a6e |
// Users must adopt the TRasterPT smart pointer syntax instead.
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
// Buffer Allocation
|
|
Shinya Kitaoka |
120a6e |
TRasterT(int lx, int ly) : TRaster(lx, ly, sizeof(T)) {}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
// Buffer Attachment
|
|
Shinya Kitaoka |
120a6e |
TRasterT(int lx, int ly, int wrap, T *buffer, TRasterT<t> *parent,</t>
|
|
Shinya Kitaoka |
120a6e |
bool bufferOwner = false)
|
|
Shinya Kitaoka |
120a6e |
: TRaster(lx, ly, sizeof(T), wrap, reinterpret_cast<uchar *="">(buffer),</uchar>
|
|
Shinya Kitaoka |
120a6e |
parent, bufferOwner) {}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
120a6e |
typedef T Pixel;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
~TRasterT(){};
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// accessors
|
|
Shinya Kitaoka |
120a6e |
// WARNING!!!!! before getting the buffer with pixels(int y),
|
|
Shinya Kitaoka |
120a6e |
// you have to lock the raster with'lock method, and unlock
|
|
Shinya Kitaoka |
120a6e |
// it when you've done with the buffer
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
const T *pixels(int y = 0) const {
|
|
Shinya Kitaoka |
120a6e |
assert(0 <= y && y < getLy());
|
|
Shinya Kitaoka |
120a6e |
return reinterpret_cast<t *="">(m_buffer) + getWrap() * y;</t>
|
|
Shinya Kitaoka |
120a6e |
};
|
|
Shinya Kitaoka |
120a6e |
T *pixels(int y = 0) {
|
|
Shinya Kitaoka |
120a6e |
assert(0 <= y && y < getLy());
|
|
Shinya Kitaoka |
120a6e |
return reinterpret_cast<t *="">(m_buffer) + getWrap() * y;</t>
|
|
Shinya Kitaoka |
120a6e |
};
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// Derived rasters creation
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
473e70 |
TRasterP clone() const override {
|
|
Shinya Kitaoka |
120a6e |
TRasterP dst = TRasterPT<t>(m_lx, m_ly);</t>
|
|
Shinya Kitaoka |
120a6e |
TRasterP src(const_cast<traster *="">((const TRaster *)this));</traster>
|
|
Shinya Kitaoka |
120a6e |
dst->copy(src);
|
|
Shinya Kitaoka |
120a6e |
return dst;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
473e70 |
TRasterP create() const override { return TRasterPT<t>(m_lx, m_ly); }</t>
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
38fd86 |
TRasterP create(int lx, int ly) const override {
|
|
Shinya Kitaoka |
38fd86 |
return TRasterPT<t>(lx, ly);</t>
|
|
Shinya Kitaoka |
38fd86 |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
//!\include raster_ex2.cpp
|
|
Shinya Kitaoka |
473e70 |
TRasterP extract(int x0, int y0, int x1, int y1) override {
|
|
Shinya Kitaoka |
120a6e |
TRect rect(x0, y0, x1, y1);
|
|
Shinya Kitaoka |
120a6e |
return extract(rect);
|
|
Shinya Kitaoka |
120a6e |
};
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
473e70 |
TRasterP extract(TRect &rect) override {
|
|
Shinya Kitaoka |
120a6e |
if (isEmpty() || getBounds().overlaps(rect) == false) return TRasterP();
|
|
Shinya Kitaoka |
120a6e |
rect = getBounds() * rect;
|
|
Shinya Kitaoka |
120a6e |
// addRef();
|
|
Shinya Kitaoka |
120a6e |
return TRasterP(new TRasterT<t>(rect.getLx(), rect.getLy(), m_wrap,</t>
|
|
Shinya Kitaoka |
120a6e |
pixels(rect.y0) + rect.x0, this));
|
|
Shinya Kitaoka |
120a6e |
};
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
TRasterPT<t> extractT(TRect &rect);</t>
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
TRasterPT<t> extractT(int x0, int y0, int x1, int y1) {</t>
|
|
Shinya Kitaoka |
120a6e |
TRect rect(x0, y0, x1, y1);
|
|
Shinya Kitaoka |
120a6e |
return extractT(rect);
|
|
Shinya Kitaoka |
120a6e |
};
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
friend class TRasterPT<t>;</t>
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// Pixel Operations
|
|
Shinya Kitaoka |
120a6e |
void fill(const T &a) { fillRawData(reinterpret_cast<const *="" uchar="">(&a)); }</const>
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
void fillOutside(const TRect &rect, const T &a) {
|
|
Shinya Kitaoka |
120a6e |
fillRawDataOutside(rect, reinterpret_cast<const *="" uchar="">(&a));</const>
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
inline TRasterP TRaster::extract(int x0, int y0, int x1, int y1) {
|
|
Shinya Kitaoka |
120a6e |
TRect rect(x0, y0, x1, y1);
|
|
Shinya Kitaoka |
120a6e |
return extract(rect);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <class t=""></class>
|
|
Shinya Kitaoka |
120a6e |
TRasterPT<t> TRasterT<t>::extractT(TRect &rect) {</t></t>
|
|
Shinya Kitaoka |
120a6e |
if (isEmpty() || getBounds().overlaps(rect) == false) {
|
|
Shinya Kitaoka |
120a6e |
return TRasterPT<t>();</t>
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
rect = getBounds() * rect;
|
|
Shinya Kitaoka |
120a6e |
// addRef();
|
|
Shinya Kitaoka |
120a6e |
return TRasterPT<t>(new TRasterT<t>(rect.getLx(), rect.getLy(), m_wrap,</t></t>
|
|
Shinya Kitaoka |
120a6e |
pixels(rect.y0) + rect.x0, this));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=========================================================
|
|
Toshihiro Shimizu |
890ddd |
//
|
|
Toshihiro Shimizu |
890ddd |
// metodi inline di TRasterPT
|
|
Shinya Kitaoka |
120a6e |
// (n.b. se non si fanno esplicitament "inline" NT si confonde con dll
|
|
Shinya Kitaoka |
120a6e |
// exort/import)
|
|
Toshihiro Shimizu |
890ddd |
//
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <class t=""></class>
|
|
Shinya Kitaoka |
120a6e |
inline TRasterPT<t>::TRasterPT(const TRasterP &src) {</t>
|
|
Shinya Kitaoka |
120a6e |
TSmartPointerT<trastert<t>>::m_pointer =</trastert<t>
|
|
Shinya Kitaoka |
120a6e |
dynamic_cast<trastert<t> *>(src.getPointer());</trastert<t>
|
|
Shinya Kitaoka |
120a6e |
if (TSmartPointerT<trastert<t>>::m_pointer)</trastert<t>
|
|
Shinya Kitaoka |
120a6e |
TSmartPointerT<trastert<t>>::m_pointer->addRef();</trastert<t>
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <class t=""></class>
|
|
Shinya Kitaoka |
120a6e |
inline void TRasterPT<t>::create(int lx, int ly) {</t>
|
|
Shinya Kitaoka |
120a6e |
TRasterT<t> *raster = new TRasterT<t>(lx, ly);</t></t>
|
|
Shinya Kitaoka |
120a6e |
*this = TRasterPT<t>(raster);</t>
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <class t=""></class>
|
|
Shinya Kitaoka |
120a6e |
inline void TRasterPT<t>::detach() {</t>
|
|
Shinya Kitaoka |
120a6e |
if (!TSmartPointerT<trastert<t>>::m_pointer ||</trastert<t>
|
|
Shinya Kitaoka |
120a6e |
TSmartPointerT<trastert<t>>::m_pointer->getRefCount() == 1)</trastert<t>
|
|
Shinya Kitaoka |
120a6e |
return;
|
|
Shinya Kitaoka |
120a6e |
*this = TRasterPT(TSmartPointerT<trastert<t>>::m_pointer->clone());</trastert<t>
|
|
Shinya Kitaoka |
120a6e |
// uso l'operator di assign per aggiornare correttamente
|
|
Shinya Kitaoka |
120a6e |
// i reference counts del vecchio e del nuovo raster
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <class t=""></class>
|
|
Shinya Kitaoka |
120a6e |
inline TRasterPT<t>::operator TRasterP() const {</t>
|
|
Shinya Kitaoka |
120a6e |
return TRasterP(TSmartPointerT<trastert<t>>::m_pointer);</trastert<t>
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <class t=""></class>
|
|
Shinya Kitaoka |
120a6e |
inline TRasterPT<t>::TRasterPT(int lx, int ly, int wrap, T *buffer,</t>
|
|
Shinya Kitaoka |
120a6e |
bool bufferOwner) {
|
|
Shinya Kitaoka |
120a6e |
TSmartPointerT<trastert<t>>::m_pointer =</trastert<t>
|
|
Shinya Kitaoka |
120a6e |
new TRasterT<t>(lx, ly, wrap, buffer, 0, bufferOwner);</t>
|
|
Shinya Kitaoka |
120a6e |
TSmartPointerT<trastert<t>>::m_pointer->addRef();</trastert<t>
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
9f5a1b |
#ifdef _WIN32
|
|
Toshihiro Shimizu |
890ddd |
// su NT e' necessario per evitare un warning nelle classi
|
|
Toshihiro Shimizu |
890ddd |
// esportate che si riferiscono a TRaster32P/TRaster64P
|
|
Toshihiro Shimizu |
890ddd |
// su IRIX non compila perche' non riesce ad instanziare le
|
|
Toshihiro Shimizu |
890ddd |
// funzioni online (!!!)
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template class DVAPI TSmartPointerT<trastert<tpixel32>>;</trastert<tpixel32>
|
|
Toshihiro Shimizu |
890ddd |
template class DVAPI TRasterPT<tpixel32>;</tpixel32>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template class DVAPI TSmartPointerT<trastert<tpixel64>>;</trastert<tpixel64>
|
|
Toshihiro Shimizu |
890ddd |
template class DVAPI TRasterPT<tpixel64>;</tpixel64>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template class DVAPI TSmartPointerT<trastert<tpixelgr8>>;</trastert<tpixelgr8>
|
|
Toshihiro Shimizu |
890ddd |
template class DVAPI TRasterPT<tpixelgr8>;</tpixelgr8>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template class DVAPI TSmartPointerT<trastert<tpixelgr16>>;</trastert<tpixelgr16>
|
|
Toshihiro Shimizu |
890ddd |
template class DVAPI TRasterPT<tpixelgr16>;</tpixelgr16>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template class DVAPI TSmartPointerT<trastert<tpixelgrd>>;</trastert<tpixelgrd>
|
|
Toshihiro Shimizu |
890ddd |
template class DVAPI TRasterPT<tpixelgrd>;</tpixelgrd>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template class DVAPI TSmartPointerT<trastert<tpixelcy>>;</trastert<tpixelcy>
|
|
Toshihiro Shimizu |
890ddd |
template class DVAPI TRasterPT<tpixelcy>;</tpixelcy>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
typedef TRasterPT<tpixel32> TRaster32P;</tpixel32>
|
|
Toshihiro Shimizu |
890ddd |
typedef TRasterPT<tpixel64> TRaster64P;</tpixel64>
|
|
Toshihiro Shimizu |
890ddd |
typedef TRasterPT<tpixelgr8> TRasterGR8P;</tpixelgr8>
|
|
Toshihiro Shimizu |
890ddd |
typedef TRasterPT<tpixelgr16> TRasterGR16P;</tpixelgr16>
|
|
Toshihiro Shimizu |
890ddd |
typedef TRasterPT<tpixelgrd> TRasterGRDP;</tpixelgrd>
|
|
Toshihiro Shimizu |
890ddd |
typedef TRasterPT<tpixelcy> TRasterYUV422P;</tpixelcy>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=========================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Campbell Barton |
b3bd84 |
// functions
|
|
Campbell Barton |
b3bd84 |
|
|
Campbell Barton |
b3bd84 |
// trastercentroid.cpp
|
|
Campbell Barton |
b3bd84 |
TPoint computeCentroid(const TRaster32P &r);
|
|
Campbell Barton |
b3bd84 |
|
|
Campbell Barton |
b3bd84 |
//=========================================================
|
|
Campbell Barton |
b3bd84 |
|
|
Toshihiro Shimizu |
890ddd |
//=========================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
#endif //__T_RASTER_INCLUDED
|