/*------------------------------------------------------------------------------
 src/plugin/djImageIoPng/io.h
 
 Copyright (c) 2004-2006 Darby Johnston.
 All rights reserved.
 Use is subject to license terms.

 Requirements:
 
 * libpng, http://www.libpng.org

 Supported:
 
 * Channels: l, la, rgb, rgba.
 * Bit depths: u8, u16.
------------------------------------------------------------------------------*/

#ifndef DJ_IMAGE_IO_PNG_H
#define DJ_IMAGE_IO_PNG_H
#include "base.h"
#include <djImageIo.h>
#include <stdio.h>

namespace djImageIoPng {

// Image load plugin.
//
class Load : public ImageLoad {
public:

  Load();
  ~Load();
  
  const Str name() const { return djImageIoPng::name(); }
  Plugin * copy() const { return new Load(*this); }
  const StrList extensionList() const { return djImageIoPng::extensionList(); }
  
  bool open(const Str & fileName, ImageIoInfo *);

protected:

  bool imageOpen(const Str & fileName, ImageIoInfo *);
  void imageClose();
  bool imageBegin(int frame, ImageIoInfo *);
  bool imageGet(PixelData *, int proxyScale);

private:

  FileInfo _fileInfo;
  FILE * _f;
  png_structp _png;
  png_infop _pngInfo, _pngInfoEnd;
  PixelDataInfo _info;
};

// Image save plugin.
//
class Save : public ImageSave {
public:

  Save();
  ~Save();
  
  const Str name() const { return djImageIoPng::name(); }
  Plugin * copy() const { return new Save(*this); }
  const StrList extensionList() const { return djImageIoPng::extensionList(); }
  
  bool open(const Str & fileName, const ImageIoInfo &);

protected:

  bool imageOpen(const Str & fileName, const Image &);
  void imageClose();
  bool imageBegin(const Image &, int frame);
  bool imageSet(const PixelData &);

private:

  PixelDataInfo _info;
  
  FileInfo _fileInfo;
  FILE * _f;
  png_structp _png;
  png_infop _pngInfo;
};

}

#endif
