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

#include "nmm/multimedia/GenericFilterNode.hpp"
#include "nmm/plugins/video/filter/ILogoDisplayImpl.hpp"

#include <png.h>

namespace NMM {

  class LogoNode :
    public GenericFilterNode,
    public ILogoDisplayImpl
  {
  private:
    char *logo[9];               
    png_bytep *png_rows;               ///< stores the PNG image
    png_uint_32 png_width, png_height; ///< PNG image width and height
    
    int x_offset, y_offset; ///< display position
    string logo_filename;   ///< filename for the logo image
    
    int image_width;        ///< width of the image in the input stream
    int image_height;       ///< height of the image in the input stream
    
    /**
     * Loads and prepares the PNG image.
     */
    Result preparePNGLogo(string filename);
    
    /**
     * Sets a pixel on the buffer image.
     */
    void setPixel(char *image, int x, int y,
		  unsigned char r, unsigned char g, unsigned char b);
    
    /**
     * Displays the logo on the buffer image
     */
    void paintPNGLogo(char *image, int x, int y);
    
  protected:
    /**
     * The standard doInit method from Node. Effects in LogoNode:
     * loads the logo image.
     */
    virtual Result doInit();
    
    /**
     * The standard doinitOutput method from Node. Effects in LogoNode:
     * obtain and check the size of the incoming buffer image.
     */
    virtual Result doInitOutput();

    /**
     * The standard processBuffer method from GenericProcessorNode.
     * Effects in LogoNode: display the logo image
     * on the image in the buffer.
     */
    virtual Buffer *processBuffer(Buffer *in_buffer);
    
    /**
     * ILogoDisplay interface.
     */
    void setLogoImage(const string& path);
    void setOffset(const nmm_int32& x, const nmm_int32& y);
    void getOffset(nmm_int32& x, nmm_int32& y) const;
    
  public:
    LogoNode(const char *name = "LogoNode",
	     const StreamQueue::Mode queue_mode = StreamQueue::MODE_SUSPEND, 
	     const int queue_size = 1 );
    
    ~LogoNode();
  };
}

#endif
