//----------------------------------------------------------------------
// Copyright (C) 2006-2007 Electronic Arts    
//----------------------------------------------------------------------

#ifndef JOB_UTIL_IMAGE_DESC_H
#define JOB_UTIL_IMAGE_DESC_H

#include "job_util/for_each_desc.h"
#include "job_util/print.h"
#include "job_manager/config.h"

#if defined(EA_PLATFORM_PS3) && defined(EA_COMPILER_SN)
#pragma diag_push
#pragma diag_suppress=1788
#endif

namespace EA { 
    namespace Jobs {

EA_PREFIX_ALIGN(PLATFORM_PREFERRED_ALIGNMENT)
class ImageDesc : public ForEachDesc {
public: // External API

    // all sub-images to be processed must be same width, height
    // regionWidth and regionHeight must divide into width and height evenly
    ImageDesc(size_t width, size_t height, size_t regionWidth, size_t regionHeight);

    size_t GetWidth() const;
    size_t GetHeight() const;
    size_t GetRegionWidth() const;
    size_t GetRegionHeight() const;

    static size_t const sMaxImageRegionDescs = 16;

    // input images can be of a different size, taking an equal size subsection of each image,
    // hence bytesPerLine can differ.
    void SetImage(size_t number, size_t xOffset, size_t yOffset, size_t bytesPerPixel, size_t bytesPerLine, void const * inPtr, void * outPtr);

    // alternate form, assumes x and y offsets are 0.
    void SetImage(size_t number, size_t bytesPerPixel, size_t bytesPerLine, void const * inPtr, void * outPtr);

    size_t GetXOffsetForRegion(size_t number, int index) const;
    size_t GetYOffsetForRegion(size_t number, int index) const;

public: // Internal API
    ImageDesc();

    size_t GetOffsetForRegion(size_t number, int index) const;

    int GetLastOffset() const;

    static size_t const sImageRegionDescIdent = 0x101;

    struct ImageRegionDesc
    {
        size_t mXOffset;
        size_t mYOffset;
        char const * mInPtr;
        char * mOutPtr;
        size_t mBytesPerPixel;
        size_t mBytesPerLine;
        ImageRegionDesc();
    };

    ImageRegionDesc const & GetImageRegionDesc(size_t number) const;

    bool Verify() const;

private:
    ImageRegionDesc mImageRegion[sMaxImageRegionDescs];
    size_t mWidth;
    size_t mHeight;
    size_t mRegionWidth;
    size_t mRegionHeight;
    size_t mRowStep;

}
EA_POSTFIX_ALIGN(PLATFORM_PREFERRED_ALIGNMENT);

    }
}
#if defined(EA_PLATFORM_PS3) && defined(EA_COMPILER_SN)
#pragma diag_pop
#endif

#endif
