/* 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 MAGICK_READ_NODE_HPP
#define MAGICK_READ_NODE_HPP

#include "nmm/multimedia/GenericSourceNode.hpp"
#include "nmm/plugins/interfaces/IFileHandlerImpl.hpp"

#include "Magick++.h"

namespace NMM{

  //! Reads image files supported by ImageMagick.
  class MagickReadNode : public GenericSourceNode, public IFileHandlerImpl
  {
  public:
    //! The main constructor.
    MagickReadNode(const char* name = "MagickReadNode");

    //! The destructor.    
    virtual ~MagickReadNode();

  protected:
    //! The doInit method from Node.
    virtual Result doInit();
    
    //! The doInitOutput method from Node.
    virtual Result doInitOutput();
    
    //! The doActivate method from Node.
    virtual Result doActivate();
    
    //! The doStart method from Node.
    virtual Result doStart();
    
    //! The doStop method from Node.
    virtual Result doStop();
    
    //! The processBuffer method from GenericNode.
    Message* processBuffer(Buffer*);
    
  protected:
    //! The setFilename method from IFileHandlerImpl
    void setFilename(const string& file_name);

    //! Returns the image resolution of the current image. 
    pair<int, int> getImageResolution();

    // Internally used variables
    Magick::Image __image;                 //!< The current Magick image.
    string        __filename;                    //!< The current file name.
    unsigned int  __buffer_size;           //!< The current buffer size.
    int           __bit_per_pixel;         //!< The number of bits per pixel of the output format.
    bool          __end_track;
    bool          __format_changed;
  };
}

#endif
