/* Network-Integrated Multimedia Middleware (NMM)
 * http://www.motama.com/nmm.html
 *  
 * Copyright (C) 2006-2007
 * Motama GmbH, Saarbruecken, Germany
 * http://www.motama.com
 *  
 * This file is part of NMM. 
 * 
 * NMM is free software; you can redistribute it and/or modify it    
 * under the terms of the GNU General Public License as published by 
 * the Free Software Foundation; only version 2 of the License.      
 * 
 * NMM 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 General Public 
 * License for more details.  
 * 
 * You should have received a copy of the GNU General Public License 
 * along with NMM; if not, write to the Free Software Foundation,    
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 */

#ifndef _NMM_PNGREADNODE_HPP_
#define _NMM_PNGREADNODE_HPP_ _NMM_PNGREADNODE_HPP_

#include "nmm/nmm_prefix.hpp"

#include "nmm/multimedia/GenericSourceNode.hpp"
#include "nmm/plugins/file/png/IMultipleSourceFileHandlerImpl.hpp"
#include "nmm/plugins/file/interfaces/IFileModeHandlerImpl.hpp"
#include "nmm/plugins/interfaces/IFileHandlerImpl.hpp"
#include "nmm/plugins/file/png/ICreateImageImpl.hpp"
#include "visibility.hpp"
namespace NMM {

  class DLLEXPORT PNGReadNode : public GenericSourceNode,
		      public IMultipleSourceFileHandlerImpl,
		      public IFileModeHandlerImpl,
		      public ICreateImageImpl,
          public IFileHandlerImpl {

  private:
    bool last_image_done;      ///< set true when a picture is completely sent (including end_track)
    bool end_track;
    unsigned int image_width;  ///< width of the image in the input stream
    unsigned int image_height; ///< height of the image in the input stream
    int frame_count;           ///< How often was the picture send?
    unsigned char* data;       ///< Bitmap data (rgba format)
    int buff_size;
    string cur_filename;
    list<string> filenames;
    string fileext;
    const string deffileext;
    IFileModeHandler::FilenameMode filename_mode;
    ThreadMutex filename_mutex;   ///< Thread-Mutex
    bool format_changed;

    /**
     * loads a (PNG) Bitmap
     * \param filename filename of the bitmap
     * \param width pointer to a variable that holds the bitmap width after loading
     * \param height pointer to a variable that holds the bitmap height after loading
     * \returns pointer to the bitmap data (rgba format)
     */
    unsigned char* loadBitmap( string filename, unsigned int* width, unsigned int* height  );

    bool openImage();

    void setWOPInternal();

  protected:
    Result doInit();
    Result doInitOutput();
    Result doActivate();
    Message* processBuffer(Buffer *);

    /* This method calls addFilename */
    virtual void setFilename(const string& file);

    // IMultipleSourceFileHandler interface
    virtual void addFilename(const string&);

    // IFileModeHandler interface
    virtual void setMode(const IFileModeHandler::FileMode& mode);
    virtual IFileModeHandler::FileMode getMode();
    virtual void setFormat(const IFileModeHandler::FileFormat& format);
    virtual IFileModeHandler::FileFormat getFormat();
    virtual void setFilenameMode(const IFileModeHandler::FilenameMode& mode);
    virtual IFileModeHandler::FilenameMode getFilenameMode();
    virtual void setLoop(const nmm_bool& d);
    
    // ICreateImage interface 
    virtual Result createImage(const nmm_uint32& color, const nmm_uint32& w, const nmm_uint32& h);

  public:

    PNGReadNode(const char *name = "PNGReadNode",
		StreamQueue::Mode = StreamQueue::MODE_SUSPEND,
		int = StreamQueue::DEFAULT_SIZE);
    ~PNGReadNode();


  };

}

#include "nmm/nmm_suffix.hpp"

#endif //_NMM_PNGREADNODE_HPP_
