www.pudn.com > mputil.rar > ffimage.h


/*
 *  ffimage.h
 *  
 *
 *  Created by Ian Fasel 2002.
 *  Copyright (c) 2003 Machine Perception Laboratory
 *  University of California San Diego.
 *  Please read the disclaimer and notes about redistribution
 *  at the end of this file.
 *
 *  Authors: Ian Fasel, Bret Fortenberry
 *
 */
#ifndef _FFIMAGE_H_
#define _FFIMAGE_H_
#include "../common.h"
#include "rimage.h"
#include 

template 
class FFImage : public RImage {
public:
  // Construct an FFImage from a pixel array
  FFImage(T *array_, const int width_, const int height_, const bool flipped)
    : RImage(array_, width_, height_), m_flipped(flipped){};
   
  FFImage(T *array_, const int width_, const int height_)
    : RImage(array_, width_, height_)
	{
#ifdef WIN32
		m_flipped = true;
#else
		m_flipped = false;
#endif
	};
   
  FFImage (const FFImage &other){
		this->width = other.width;
		this->height = other.height;
		this->numpixels = other.numpixels;
		this->array = other.array;
		m_flipped = other.m_flipped;
		this->my_memory = false;
  }
  
  // A copy constructor specific to the RGBTRIPLE case, used to convert from RGB to grayscale
  FFImage(const FFImage& source, int subs=1);

  FFImage(const bool flipped = FALSE) : m_flipped(flipped){};
  ~FFImage(){;};
  
  inline T getPixel ( const int x, int y ) const{	
	if(m_flipped) y = this->height-y;
	if(x >= 0 && y >= 0 && x < this->width && y < this->height)
	  return this->array[this->width * y + x];
	else
#ifdef WIN32
	  return array[0];
#else
	  return 0;
#endif
  };
  
  inline void setPixel ( const int x, int y, const T value ){
	if(m_flipped) y = this->height-y;
	if(x >= 0 && y >= 0 && x < this->width && y < this->height)
	  this->array[this->width * y + x] = value;
  };

  inline void setSize(const int width_, const int height_, const bool flipped_){
	this->width = width_;
	this->height = height_;
	this->array = new T[this->width * this->height];
	m_flipped = flipped_;
	this->my_memory = 1;
  }

  inline void setSize(const int width_, const int height_){
	this->width = width_;
	this->height = height_;
	this->array = new T[this->width * this->height];
#ifdef WIN32
		m_flipped = true;
#else
		m_flipped = false;
#endif
	this->my_memory = 1;
  }

  inline bool isFlipped() const {return m_flipped;};
private:
	bool m_flipped;
};

#endif

/*
 * 
 * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
 * 
 *    1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
 *    2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
 *    3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 * 
 */