30 #ifndef _D_BASE_IMAGE_H
31 #define _D_BASE_IMAGE_H
33 #include "DBaseObject.h"
39 #include "Gui/include/private/DImageViewer.hpp"
43 class BaseImageViewer;
44 template <
class T>
class ImageViewer;
54 BaseImage(
const char *_className =
"BaseImage")
55 :
BaseObject(_className), updatesEnabled(
true), width(0), height(0),
56 depth(0), pixelCount(0), lineCount(0), sliceCount(0),
57 allocated(
false), allocatedSize(0)
64 :
BaseObject(rhs), updatesEnabled(
true), width(0), height(0), depth(0),
65 pixelCount(0), lineCount(0), sliceCount(0), allocated(
false),
114 virtual RES_T
setSize(
size_t w,
size_t h,
size_t d = 1,
115 bool doAllocate =
true) = 0;
118 inline void getSize(
size_t *w,
size_t *h,
size_t *d)
const
127 inline void getSize(
int *w,
int *h,
int *d)
const
162 return this->pixelCount;
167 return this->lineCount;
172 return this->sliceCount;
178 return this->allocated;
194 if (x < 0 || y < 0 || z < 0)
196 if (x >= off_t(this->width) || y >= off_t(this->height) || z >= off_t(this->depth))
211 if (x >=
size_t(this->width) || y >=
size_t(this->height) || z >=
size_t(this->depth))
226 if (p.x < 0 || p.y < 0 || p.z < 0)
228 if (p.x >=
int(width) || p.y >=
int(height) || p.z >=
int(depth))
265 size_t vmax = numeric_limits<size_t>::max();
266 if (x >= this->width)
268 if (y >= this->height)
270 if (z >= this->depth)
272 return z * this->width * this->height + y * this->width + x;
278 size_t vmax = numeric_limits<size_t>::max();
279 if (p.x < 0 || p.y < 0 || p.z < 0)
281 if (p.x >=
int(width))
283 if (p.y >=
int(height))
285 if (p.z >=
int(depth))
287 return p.z * width * height + p.y * width + p.x;
294 z = off / (this->width * this->height);
295 y = (off % (this->width * this->height)) / this->width;
296 x = off % this->width;
303 z = off / (this->width * this->height);
304 y = (off % (this->width * this->height)) / this->width;
305 x = off % this->width;
311 vector<size_t> coords(3);
313 coords[2] = off / (this->width * this->height);
314 coords[1] = (off % (this->width * this->height)) / this->width;
315 coords[0] = off % this->width;
319 inline IntPoint getPointFromOffset(
size_t off)
const
323 pt.z = off / (this->width * this->height);
324 pt.y = (off % (this->width * this->height)) / this->width;
325 pt.x = off % this->width;
343 virtual void show(
const char * = NULL,
bool =
false);
345 virtual void showLabel(
const char * = NULL);
350 virtual RES_T
load(
const char * )
352 return RES_ERR_NOT_IMPLEMENTED;
355 virtual RES_T
save(
const char * )
357 return RES_ERR_NOT_IMPLEMENTED;
382 size_t allocatedSize;
389 : image(&im), update(updateOnDelete)
391 imState = im.updatesEnabled;
392 im.updatesEnabled =
false;
396 image->updatesEnabled = imState;
413 inline bool haveSameSize(
const BaseImage *im, ...)
425 while ((obj = va_arg(vargs,
BaseImage *))) {
443 inline bool setSameSize(
const BaseImage *im, ...)
445 if (!im->isAllocated())
451 size_t w = im->getWidth();
452 size_t h = im->getHeight();
453 size_t d = im->getDepth();
457 while ((obj = va_arg(vargs, BaseImage *))) {
458 if (obj->getWidth() != w || obj->getHeight() != h || obj->getDepth() != d)
459 if (obj->setSize(w, h, d) != RES_OK)
469 inline bool areAllocated(
const BaseImage *im, ...)
474 if (!im->isAllocated())
477 const BaseImage *obj;
478 while ((obj = va_arg(vargs,
const BaseImage *)))
479 if (!obj->isAllocated())
485 #define CHECK_ALLOCATED(...) (areAllocated(__VA_ARGS__, NULL))
486 #define ASSERT_ALLOCATED(...) \
487 ASSERT(CHECK_ALLOCATED(__VA_ARGS__), RES_ERR_BAD_ALLOCATION)
489 #define CHECK_SAME_SIZE(...) \
490 (Core::getInstance()->autoResizeImages ? setSameSize(__VA_ARGS__, NULL) \
491 : haveSameSize(__VA_ARGS__, NULL))
492 #define ASSERT_SAME_SIZE(...) \
493 ASSERT(CHECK_SAME_SIZE(__VA_ARGS__), RES_ERR_BAD_SIZE)
Base Image class.
Definition: DBaseImage.h:50
void getSize(off_t s[3]) const
Get image size.
Definition: DBaseImage.h:144
size_t getOffsetFromCoords(size_t x, size_t y, size_t z=0) const
Get an offset for given x,y(,z) coordinates.
Definition: DBaseImage.h:263
size_t getDepth() const
Get image depth (Z)
Definition: DBaseImage.h:90
virtual const char * getInfoString(const char *="") const
Get the description of the image.
Definition: DBaseImage.h:330
virtual size_t getAllocatedSize() const
Get memory size (bytes)
Definition: DBaseImage.h:96
bool isOffsetInImage(const off_t offset) const
isOffsetInImage() - checks if a buffer offset in inside the image bounds.
Definition: DBaseImage.h:240
void getCoordsFromOffset(off_t off, off_t &x, off_t &y, off_t &z) const
Get x,y(,z) coordinates for a given offset.
Definition: DBaseImage.h:300
void getCoordsFromOffset(size_t off, size_t &x, size_t &y, size_t &z) const
Get x,y(,z) coordinates for a given offset.
Definition: DBaseImage.h:291
virtual void * getVoidPointer()=0
Get the void* data array.
virtual void hide()=0
Hide the image (viewer)
bool isAllocated() const
Check if the image is allocated.
Definition: DBaseImage.h:176
void getSize(size_t s[3]) const
Get image size.
Definition: DBaseImage.h:136
void getSize(size_t *w, size_t *h, size_t *d) const
Get image size.
Definition: DBaseImage.h:118
bool areCoordsInImage(const off_t x, const off_t y, const off_t z=0) const
areCoordsInImage() - checks if the triplet (x, y, z) in inside the image bounds.
Definition: DBaseImage.h:192
bool areCoordsInImage(const size_t x, const size_t y, const size_t z=0) const
areCoordsInImage() - checks if the triplet (x, y, z) in inside the image bounds.
Definition: DBaseImage.h:209
virtual RES_T setSize(size_t w, size_t h, size_t d=1, bool doAllocate=true)=0
Set image size Set image size and allocate it if doAllocate is true.
size_t getSliceCount() const
Get the number of slices(for 3D images)
Definition: DBaseImage.h:170
size_t getWidth() const
Get image width.
Definition: DBaseImage.h:80
virtual RES_T save(const char *)
Save to file.
Definition: DBaseImage.h:355
virtual void show(const char *=NULL, bool=false)
Show the image (viewer)
Definition: DBaseImage.cpp:56
size_t getLineCount() const
Get the number of lines.
Definition: DBaseImage.h:165
virtual void modified()=0
Trigger modified event.
virtual bool isVisible()
Check if the image (viewer) is visible.
Definition: DBaseImage.h:338
virtual BaseImageViewer * getViewer()=0
Get the viewer associated to the image.
virtual void showLabel(const char *=NULL)
Show the image (viewer) as false colors.
Definition: DBaseImage.cpp:62
size_t getPixelCount() const
Get the number of pixels.
Definition: DBaseImage.h:160
bool isOffsetInImage(const size_t offset) const
isOffsetInImage() - checks if a buffer offset in inside the image bounds.
Definition: DBaseImage.h:255
UINT getDimension() const
Get dimension (2D or 3D)
Definition: DBaseImage.h:102
virtual const char * getTypeAsString()=0
Get the type of the image as a string ("UINT8",...)
vector< size_t > getCoordsFromOffset(size_t off) const
Get x,y(,z) coordinates for a given offset.
Definition: DBaseImage.h:309
size_t getOffsetFromPoint(IntPoint &p) const
Get an offset for given x,y(,z) coordinates.
Definition: DBaseImage.h:276
void getSize(int s[3]) const
Get image size.
Definition: DBaseImage.h:152
virtual RES_T load(const char *)
Load from file.
Definition: DBaseImage.h:350
bool isPointInImage(const IntPoint &p) const
isPointInImage() - checks if a Point is in inside the image bounds.
Definition: DBaseImage.h:224
size_t getHeight() const
Get image height.
Definition: DBaseImage.h:85
Definition: DBaseImageViewer.h:47
Base Smil Object.
Definition: DBaseObject.h:52
Definition: DBaseImage.h:386