/*-----------------------------------------------------------------
   pix2jpg v0.02 
   External for Gem and Pure Data to convert an image to jpg and send it 
	 via Unix Domain Sockets
  
   (c) 2012-2013 Santi Noreña libremediaserver@gmail.com 	

   GPL License.
-----------------------------------------------------------------*/

#ifndef _INCLUDE__GEM_PIXES_pix2jpg_H_
#define _INCLUDE__GEM_PIXES_pix2jpg_H_

#include "Base/GemPixObj.h"
#include "Base/GemBase.h"
#include "Gem/Manager.h"
#include "Gem/ImageIO.h"
#include "Gem/Image.h"
#include <stdio.h>
#include <Magick++.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <unistd.h>
#include <string.h>
#include <m_pd.h>

using namespace Magick;
/*-----------------------------------------------------------------
-------------------------------------------------------------------
CLASS
    pix2jpg

	  Convert a image to jpg and outputs in a Unix Domain Socket

KEYWORDS
    pix

DESCRIPTION

    "bang" - Process next image
    
    outlet : 
-----------------------------------------------------------------*/
class GEM_EXPORT pix2jpg : public GemPixObj
{
    CPPEXTERN_HEADER(pix2jpg, GemPixObj);

    public:

        //////////
        // Constructor
    	pix2jpg(t_symbol *s);

    protected:

    	//////////
    	// Destructor
    	virtual ~pix2jpg();

    	//////////
    	// Do the rendering
    	virtual void 	processImage(imageStruct&image);

    	//////////
    	// Set the filename and filetype
 //   	virtual void	fileMess(int argc, t_atom *argv);

    	//////////
    	// The original pix_writer
    	imageStruct 	*m_originalImage;

      //////////
      // Manual writing
      bool            m_banged;

      //////////
      // Automatic writing
      bool            m_automatic;
	
      //////////
      // Layer to write
			
			int m_layer;		

			t_outlet *outlet1; 			// outlet pointer

		 struct sockaddr_un address;
		 int  socket_fd, nbytes;

		
 private:

    	//////////
    	// static member functions
      static void 	startMessCallback(void *data);
	  static void 	stopMessCallback(void *data);    
	  static void 	bangMessCallback(void *data);
      static void layerimageMessCallback(void *data, t_float f); 

};
#endif	// for header file
