#ifndef IMG_LOADER_H_
#define IMG_LOADER_H_
#include "commStruct.h"
#include "readSegImg.h"
#include "wlThread.h"
#include "myMtux.h"

struct ThreadContent {
    int threadIdx;
    void *pThis;
    MySignal mLoadMySignal;
    int mIfBeignLoad;
    int mOffsetIndex;
};

class ImgLoader {
    public:
        ImgLoader(int num, int microSecond, int oneEpochNeedLoadNum, int loadNum, PicInfo *trainImgs, int c, int hw);
        ImgLoader(PixClassify *pSeg, int segNum, int num, int microSecond, int oneEpochNeedLoadNum, int loadNum, PicInfo *trainImgs, int c, int hw);     
        virtual ~ImgLoader();
        float *GetLoadImagesBuffPoint();
        void BeginLoadThisRandList(int *randArray);
        void UseEnhanceBox(struct PicGroundTrueBox *randPGBox);

    private:
        void SetLoadInfo(int num, int microSecond, int oneEpochNeedLoadNum, int loadNum, PicInfo *trainImgs, int c, int hw);
        void ConfigImgLoadThreads();
        void RunImgLoadThreads();
        void LoadDispatch(float *multiPic, int *randArray, int loadNum, PicInfo *trainImgs, int onePicSize);
        static void ThreadCallBack(void* content);
        void ALlThreadSetLoadStatus();

        void CheckIfNeedWaitThreadLoad();
        void ComputerEachThreadsLoadNum(int loadNum);
        int GetOffsetNum(int threadIdx);

        void EnhanceImgAndBox(float *multiPics, int picNum, int c, int hw, struct PicGroundTrueBox *randPGBox);
        
        float *mMultiPic;
        WLThread *mWLThreads;
        int *mDispathcNum;
        struct ThreadContent *mThreadContent;

        // Point To UI memory
        int *mIdxArray;
        PicInfo *mPicInfo;

        struct PicGroundTrueBox *mRandPGBox;

        MySignal mAllThreadsLoadMySignal;
        ReadSegImg mReadSegImg;

        int mLoadType, mThreadNum, mSleepMSecond, mPicsSaveBuffFlag;
        int mC, mHW, mOnePicSize, oneBatchLoadImgSize, mOneEpochNeedLoadNum, mOneEpochLoadedNum, mOneBatchNeedLoadNum, mOneBatchLoadedNum;
};

#endif
