/*
 * This source file is part of KEOS (Free 3D Engine)
 * For the latest info, see http://www.keosengine.org/
 * E-mails : thierry.vouriot@keosengine.org, yeri@keosengine.org
 * 
 * This program is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free Software
 * Foundation; either version 2 of the License, or (at your option) any later
 * version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License along with
 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
 * Place - Suite 330, Boston, MA 02111-1307, USA, or go to
 * http://www.gnu.org/copyleft/lesser.txt.
 *
 */
#ifndef KEOS_IMAGE_H
#define KEOS_IMAGE_H

#include "KeosPrerequisites.h"

namespace Keos
{
    //-----------------------------------------------------------------------
    /** Class for the manipulation of images.
     *
     */
    class KEOS_EXPORT CImage
    {
    public :

        /** Default constructor.
         *  @param Size Image dimensions (default 1x1).
         *  @param Format Pixels format (default PXF_A8R8G8B8).
         */
        CImage(const TVector2I& Size = TVector2I(1, 1), TPixelFormat Format = PXF_A8R8G8B8);

        /** Constructor.
         *  @param Size Image dimensions.
         *  @param Format Pixels format.
         *  @param pPixels Pointer on the array of pixels.
         */
        CImage(const TVector2I& Size, TPixelFormat Format, const uchar* pPixels);

        /** Return the image dimensions.
         */
        const TVector2I& GetSize() const;

        /** Return the pixels format of the image.
         */
        TPixelFormat GetFormat() const;

        /** Return the array of pixels.
         */
        const uchar* GetData() const;

        /** Fill the image with a color.
         */
        void Fill(const CColor& Color);

        /** Change one pixel (no conversion).
         *  @param x Position X of the pixel.
         *  @param y Position Y of the pixel.
         *  @param pPix Bytes array with the new pixel.
         */
        void SetPixel(int x, int y, const uchar* pPix);

        /** Change one pixel with CColor (conversion).
         *  @param x Position X of the pixel.
         *  @param y Position Y of the pixel.
         *  @param Color The new color of the pixel.
         */
        void SetPixel(int x, int y, const CColor& Color);

        /** Get one pixel (no conversion).
         *  @param x Position X of the pixel.
         *  @param y Position Y of the pixel.
         *  @param pPix Bytes array with the pixel.
         */
        void GetPixel(int x, int y, uchar* pPix) const;

        /** Get one pixel in CColor (conversion).
         *  @param x Position X of the pixel.
         *  @param y Position Y of the pixel.
         *  @return The color of the pixel.
         */
        CColor GetPixel(int x, int y) const;

        /** Copy an image.
         *  Make the conversion of pixels if the 
         *  format or the dimensions are different.
         *  @param Src Image to be copied.
         */
        void CopyImage(const CImage& Src);

        /** Create a new image from a part of the current image.
         *  @param Rect Source rectangle.
         *  @return The new image.
         */
        CImage SubImage(const CRectangle& Rect) const;
        
        /** Turn the image (vertical symmetry)
         */
        void Flip();

        /** Turn the image (horizontal symmetry)
         */
        void Mirror();

    private :

        //! Image dimensions
        TVector2I m_Size;
        //! Pixels format
        TPixelFormat m_Format;
        //! Pixels vector
        std::vector<uchar> m_Pixels;
    };

} // namespace Keos

#endif // KEOS_IMAGE_H
