/* image.h -*-C++-*- * by Will Wagner * last updated 19 Aug 1997, 19:28:38 wwagner * * This file contains the base image class for POVRay. * * Changes * 11 Aug 1997 * - Added this comment block; other minor changes. * * 12 Aug 1997 * - Added the ImageBuffer and MappedImageBuffer classes; removed * some of the ImageBuffer stuff from the Image class and put an * ImageBuffer pointer in its place; changed mapping, projection, * and interpolation to enums. * * 18 Aug 1997 * - Clarified some structuring concerns; added reference counts * to ImageBuffer classes; clarified the enum members. * * 19 Aug 1997 * - Added some interpolation method prototypes; added a depth * member to the MappedImageBuffer class; other minor changes. * * Things to do * - Add registration features for the descendant classes of Image * to the registry. Unfortunately, this will require yet another * structure in the registry, but not unlike what's already there. * The same will be necessary with fonts when I get to them. * */ #ifndef __INC_IMAGE_H__ #define __INC_IMAGE_H__ #include #include "frame.h" #include "parse.h" #include "vector.h" #include "texture.h" /* Mapping types; if there is some differentiation in the textures, we * can probably get rid of this enum and make a few more methods * instead. We shouldn't care how we get mapped, or even if we do; * this image class could also be used for output. */ typedef enum { PIGMENT_MAP = 0, NORMAL_MAP, PATTERN_MAP, TEXTURE_MAP, COLOUR_MAP, SLOPE_MAP } map_types; /* Projection types */ typedef enum { PLANAR_PROJECT = 0, SPHERICAL_PROJECT, CYLINDRICAL_PROJECT, PARABOLIC_PROJECT, HYPERBOLIC_PROJECT, TORUS_PROJECT, PIRIFORM_PROJECT, OLD_PROJECT, PARAMETRIC_PROJECT } projection_types; /* Interpolation types */ typedef enum { NO_INTERP = 0, NEAREST_NEIGHBOR_INTERP, BILINEAR_INTERP, CUBIC_SPLINE_INTERP, NORMALIZED_DISTANCE_INTERP } interpolation_types; typedef struct pixel_struct_tag { public: unsigned char red, green, blue, transmit; void operator=(const pov_vector& v) { red = v[0]; green = v[1]; blue = v[2]; transmit = v[3]; }; } pixel_struct; class ImageBuffer { protected: int width, height, ref_count; pixel_struct *pixels; public: ImageBuffer(void) { ref_count = 1; width = 0; height = 0; pixels = NULL; }; ImageBuffer(int w, int h) { ref_count = 1; width = w; height = h; pixels = new pixel_struct[w * h]; }; virtual ~ImageBuffer() { if (pixels) delete[] pixels; }; inline ImageBuffer *Refer(void) { ++ref_count; return this; }; inline void Forget(void) { if (--ref_count == 0) delete this; }; inline int GetWidth(void) const { return width; }; inline int GetHeight(void) const { return height; }; inline virtual pixel_struct& operator()(int x, int y) { return pixels[(x * width) + y]; }; }; class MappedImageBuffer : public ImageBuffer { protected: unsigned short *pixel_map, depth; public: MappedImageBuffer(void) : ImageBuffer() { pixel_map = NULL; depth = 0; }; MappedImageBuffer(int w, int h, int d) { width = w; height = h; depth = d; pixels = new pixel_struct[(unsigned int)pow(2, depth)]; pixel_map = new unsigned short[w * h]; }; virtual ~MappedImageBuffer() { if (pixel_map) delete[] pixel_map; }; inline virtual pixel_struct& operator()(int x, int y) { return pixels[pixel_map[(x * width) + y]]; }; }; class Image { private: map_types mapping; projection_types projection; interpolation_types interpolation; short once_flag, use_color_flag; pov_vector gradient; SNGL width, height; /* what does this do? scaling? */ ImageBuffer *data; protected: /* the high-level mapping and color-getting routines */ int map(pov_vector&, DBL *, DBL *) const; pov_vector color_at(DBL, DBL) const; /* the map projection functions */ int planar_map(pov_vector&, DBL, DBL) const; int spherical_map(pov_vector&, DBL, DBL) const; int cylindrical_map(pov_vector&, DBL, DBL) const; int parabolic_map(pov_vector&, DBL, DBL) const; int hyperbolic_map(pov_vector&, DBL, DBL) const; int toroidal_map(pov_vector&, DBL, DBL) const; int piriform_map(pov_vector&, DBL, DBL) const; int old_map(pov_vector&, DBL, DBL) const; int parametric_map(pov_vector&, DBL, DBL) const; /* the interpolation functions */ void no_interp(DBL, DBL) const; void interp(DBL, DBL) const; DBL nearest_neighbor_interp(DBL, DBL, DBL) const; DBL norm_dist_interp(DBL, DBL, DBL) const; DBL cubic_spline_interp(DBL, DBL, DBL) const; DBL bilinear_interp(DBL, DBL, DBL) const; public: Image(void); Image(const Image&); virtual ~Image(); static Image *Parse(Parser&); virtual int Read(const char *); virtual int Write(const char *) const; virtual inline Image *Copy(void) const; virtual pov_vector ImageMap(pov_vector&, list&) const; virtual Texture& MaterialMap(pov_vector&, list&) const; virtual pov_vector BumpMap(pov_vector&, list&) const; }; #endif /* __INC_IMAGE_H__ */