1 #include "ImageConvertThreaded.hh"
3 #include <Base/Debug/Exception.hh>
38 bool bPlanar,
const int num_threads)
40 vector<ImageBase> src(num_threads), dst(num_threads);
41 vector<ThreadArg__> arg(num_threads);
42 vector<pthread_t> thread(num_threads);
44 SplitImage_(source, num_threads, src);
46 for (
int i=0; i<num_threads; i++){
47 arg[i].src = &(src[i]);
48 arg[i].dst = &(dst[i]);
49 arg[i].colormodel = targetColorModel;
50 arg[i].planar = bPlanar;
51 if (pthread_create(&(thread[i]), NULL, ConvertThread_, &(arg[i]))!=0){
52 BEXCEPTION(
"error creating thread "<<i);
56 int overall_result = 0;
57 vector<int> res(num_threads);
59 for (
int i=0; i<num_threads; i++){
60 if (pthread_join(thread[i], &result)!=0){
61 BEXCEPTION(
"error joining thread "<<i);
63 res[i] = *(
int *)result;
64 if (res[i]!=0) { overall_result--; }
69 int tlx, tly, brx, bry;
76 dst[0].GetStorageType(), dst[0].IsInterleaved());
80 MergeImage_(dst, dest);
82 return overall_result;
88 ThreadArg__ *targ =
static_cast<ThreadArg__ *
>(arg);
91 targ->colormodel, targ->planar);
92 return static_cast<void *
>(res);
97 std::vector<ImageBase> &parts)
99 if ((
int)parts.size()!=num){
103 int tlx, tly, brx, bry;
109 BEXCEPTION(
"error copying ROI");
113 BEXCEPTION(
"error copying ROI");
120 BEXCEPTION(
"error copying ROI");
124 BEXCEPTION(
"error copying ROI");
128 BEXCEPTION(
"error copying ROI");
132 BEXCEPTION(
"error copying ROI");
136 BEXCEPTION(
"only 2 or 4 threads are supported");
145 int tlx, tly, brx, bry;
146 switch (parts.size()){
168 BEXCEPTION(
"only 2 or 4 threads are supported");
int GetCopyOfROI(ImageBase ©) const
returns a copy of ROI (a new image) lower right point excluded, only interleaved images ! ...
EColorModel
These are the most often used color models.
static void SplitImage_(const ImageBase &source, const int num, std::vector< ImageBase > &parts)
static void MergeImage_(const std::vector< ImageBase > &parts, ImageBase &dest)
int SetCorners(unsigned UpperLeftX, unsigned UpperLeftY, unsigned LowerRightX, unsigned LowerRightY)
Sets a rectangular region of interest.
void GetCorners(unsigned &UpperLeftX, unsigned &UpperLeftY, unsigned &LowerRightX, unsigned &LowerRightY) const
Return the region of interest, by saving the coordinates within the variables defined by the paramete...
bool IsEmpty() const
check if ImageData_ points to allocated image buffer or not
void SetColorModel(EColorModel Model)
unsigned int GetWidth() const
ROI * GetROI()
Returns a pointer to the roi object.
static int ConvertThreaded(BIAS::ImageBase &source, BIAS::ImageBase &dest, enum BIAS::ImageBase::EColorModel targetColorModel, bool bPlanar=false, const int num_threads=2)
Convert using num_threads threads.
unsigned int GetHeight() const
bool SamePixelAndChannelCount(const ImageBase &Image) const
checks if data area has same "size" as Image of other type
void Release(const bool reset_storage_type=false)
Free the allocated data structures Hands off: Do !!NOT!! change the default of reset_storage_type: Im...
void Init(unsigned int width, unsigned int height, unsigned int nChannels=1, enum EStorageType storageType=ST_unsignedchar, const bool interleaved=true)
Initialize image size and channels.
static void * ConvertThread_(void *arg)
static int Convert(BIAS::ImageBase &source, BIAS::ImageBase &dest, enum BIAS::ImageBase::EColorModel targetColorModel, bool bPlanar=false)
main general conversion function, calls desired specialized functions, always initializes the destIma...
int Paste2ROI(const ImageBase &Image)
paste Image to current ROI
This is the base class for images in BIAS.