00001
00002
00003 #ifndef IMAGE_H
00004 #define IMAGE_H
00005
00006 #include <stdlib.h>
00007 #include <string.h>
00008 #include <malloc.h>
00009 #include <signal.h>
00010 #include "imlib_io.h"
00011 #include "Exceptions.h"
00012 #include <stdio.h>
00013
00018 template< class T > class Image
00019 {
00023 protected:
00025 int width;
00026
00028 int height;
00029
00031 T **pixels;
00032
00034 char img_name[256];
00035
00036 int pid;
00037
00038 public:
00040 Image(char * name = "");
00041
00043 Image(int w, int h, char *name = "");
00044
00046 Image(const Image<T>&);
00047
00049 virtual ~Image();
00050
00052 int getWidth() const { return width; }
00053
00055 int getHeight() const { return height; }
00056
00058 int getSize() { return width*height; }
00059
00061 char *getName() { return img_name; }
00062
00064 void setName(const char *name);
00065
00067 void makeImage(int w, int h);
00068
00070 void destroyImage();
00071
00073 T *getPixels() { return pixels[0]; }
00074
00076 void setPixels(int w, int h, T *data);
00077
00080 T min();
00081
00084 T max();
00085
00088 float avg();
00089
00092 float dev();
00093
00097 T *operator[](int i) {
00098 if ((i > height) || (i < 0))
00099 throw Fatal_error("Index out of range");
00100 else
00101 return pixels[i];
00102 }
00103
00107 T &operator()(int i) {
00108 if ((i > getSize()) || (i < 0))
00109 throw Fatal_error("Index out of range");
00110 else
00111 return pixels[0][i];
00112 }
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00128 Image< T > &operator=(const Image< T > &img);
00129
00133 int operator==(const Image< T > &img);
00134
00138 int operator!=(const Image< T > &img);
00139
00142 Image< T > &operator=(const T val);
00143
00147 void clearImage(const T val);
00148
00152 Image< T > &operator+=(const T val);
00153
00157 Image< T > &operator-=(const T val);
00158
00162 Image< T > &operator*=(const T val);
00163
00167 Image< T > &operator+=(const Image< T > & img);
00168
00172 Image< T > &operator-=(const Image< T > & img);
00173
00177 Image< T > &operator*=(const Image< T > & img);
00178
00185 void pad(int w, int h, PADDING_TYPE p);
00186
00189 void crop(int x1, int y1, int x2, int y2);
00190
00193 void makeEvenSized(void);
00194
00197 void closeWindow();
00198
00201 void readImage(char *name) {
00202 T *d = read_image< T >(name, &width, &height);
00203 setPixels(width, height, d);
00204 setName(name);
00205 }
00206
00209 void writeImage()
00210 {
00211 if (width * height != 0)
00212 write_image(img_name, width, height, pixels[0]);
00213 else
00214 ERROR("Empty image; nothing to write");
00215 }
00216
00219 void writeImage(char *name)
00220 {
00221 setName(name);
00222 if (width * height != 0)
00223 write_image(img_name, width, height, pixels[0]);
00224 else
00225 ERROR("Empty image; nothing to write");
00226 }
00227
00230 int showImage() {
00231 if (width * height != 0) {
00232 char name[128];
00233 strncpy(name, img_name, 110);
00234 closeWindow();
00235 pid = show_image< T > (pixels[0], width, height, name);
00236 }
00237 else {
00238 pid = 0;
00239 ERROR("Empty image; cannot display it!");
00240 }
00241 return(pid);
00242 }
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260 };
00261
00262
00263
00264
00265
00266 #endif
00267