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

#include "nmm/multimedia/GenericSinkNode.hpp"
#include "nmm/plugins/file/interfaces/ISinkFileHandlerImpl.hpp"

#include "Magick++.h"

namespace NMM{

  //! Writes images using formats supported by ImageMagick.
  class MagickWriteNode : public GenericSinkNode, public ISinkFileHandlerImpl
  {
  public:
    //! The main constructor.
    MagickWriteNode(const char* name = "MagickWriteNode");

    //! The destructor.
    virtual ~MagickWriteNode() {};

  protected:
    //! The doInit method from Node.
    virtual Result doInit();

    //! The doInitOutput method from Node.
    virtual Result doInitOutput();

    //! The processBuffer method from GenericNode.
    Message* processBuffer(Buffer*);

  protected:
    //! The setFileName method from ISinkFileHandlerImpl
    void setFilename(const string& file_name);

    //! The setWorkingDirectory method from ISinkFileHandlerImpl
    void   setWorkingDirectory(const string &)  {}

    //! The getWorkingDirectory method from ISinkFileHandlerImpl
    string getWorkingDirectory() { return string(); }

    //! The setFileExtension method from ISinkFileHandlerImpl (ignored)
    void   setFileExtension(const string &) {}

    //! The getFileExtension method from ISinkFileHandlerImpl (returns always "magick")
    string getFileExtension() { return "magick"; }

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

    //Internally used variables
    string         file_name;             //!< The output file name.
    pair<int, int> image_resolution;      //!< The image resolution.
    int            bit_per_pixel;         //!< The number of bits per pixel of the input format.
  };
}

#endif
