Go to the documentation of this file.00001 #ifndef __MemoryImage_H__
00002 #define __MemoryImage_H__
00003
00004 #include "Image.h"
00005
00006 namespace EdgeDetection
00007 {
00008 class MemoryImage : public Image
00009 {
00010 private: void* data;
00011 private: int stride;
00012
00013 protected: void* GetData() { return data; }
00014 protected: int GetStride() { return stride; }
00015
00016 protected: MemoryImage(int width, int height, void* data, int stride) : Image(width, height)
00017 {
00018 if (data == 0) throw "The parameter 'data' cannot be NULL.";
00019 if (stride <= 0) throw "The parameter 'stride' was out of range.";
00020
00021 this->data = data;
00022 this->stride = stride;
00023 }
00024 };
00025 class RedByteGreenByteBlueByteMemoryImage : public MemoryImage
00026 {
00027 public: double Get(int x, int y)
00028 {
00029 if (x < 0 || x >= GetWidth()) throw "The parameter 'x' was out of range.";
00030 if (y < 0 || y >= GetHeight()) throw "The parameter 'y' was out of range.";
00031
00032 unsigned char red = ((unsigned char*)GetData())[0 + x * 3 + y * GetStride()];
00033 unsigned char green = ((unsigned char*)GetData())[1 + x * 3 + y * GetStride()];
00034 unsigned char blue = ((unsigned char*)GetData())[2 + x * 3 + y * GetStride()];
00035
00036 return (0.299 * red + 0.587 * green + 0.114 * blue) / 255;
00037 }
00038
00039 public: RedByteGreenByteBlueByteMemoryImage(int width, int height, void* data, int stride) : MemoryImage(width, height, data, stride) { }
00040
00041 public: Image* GetRegion(int left, int right, int top, int bottom);
00042 };
00043 class GrayDoubleMemoryImage : public MemoryImage
00044 {
00045 public: double Get(int x, int y)
00046 {
00047 if (x < 0 || x >= GetWidth()) throw "The parameter 'x' was out of range.";
00048 if (y < 0 || y >= GetHeight()) throw "The parameter 'y' was out of range.";
00049
00050 return ((double*)GetData())[0 + x * 1 + y * GetStride()];
00051 }
00052
00053 public: GrayDoubleMemoryImage(int width, int height, void* data, int stride) : MemoryImage(width, height, data, stride) { }
00054
00055 public: Image* GetRegion(int left, int right, int top, int bottom);
00056 };
00057 };
00058
00059 #endif