Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members

CodecImage.h

Go to the documentation of this file.
00001 #ifndef CODEC_IMAGE_HPP 00002 #define CODEC_IMAGE_HPP 00003 00004 #include <stdio.h> 00005 #include <stdlib.h> 00006 #include <string.h> 00007 #include <sys/types.h> 00008 00009 #if defined(WIN32) 00010 typedef __int16 int16_t; 00011 #endif 00012 00013 class CCodecImage 00014 { 00015 private: 00016 00017 protected: 00018 struct ImageData 00019 { 00020 unsigned int Count; 00021 int Width, Height; 00022 int Pixels; 00023 int16_t *pImage; 00024 00025 ImageData() 00026 { 00027 Count = 1; 00028 Width = 0; 00029 Height = 0; 00030 Pixels = 0; 00031 pImage = 0; 00032 } 00033 00034 ~ImageData() 00035 { 00036 free(pImage); 00037 pImage = 0; 00038 } 00039 00040 void Malloc(int w, int h) 00041 { 00042 void *s; 00043 00044 // Only reallocate when size is different 00045 if (w == Width && h == Height && pImage != 0) 00046 return; 00047 s = realloc(pImage, w * h * sizeof(int16_t)); 00048 if (s == 0) 00049 { 00050 printf("CCodecImage::ImageData::Malloc: no memory!\n"); 00051 free(pImage); 00052 s = 0; 00053 Width = 0; 00054 Height = 0; 00055 Pixels = 0; 00056 } 00057 else 00058 { 00059 Width = w; 00060 Height = h; 00061 Pixels = w * h; 00062 memset(s, 0, Pixels * sizeof(int16_t)); 00063 } 00064 pImage = (int16_t *)s; 00065 } 00066 00067 void ref() 00068 { 00069 Count++; 00070 } 00071 bool deref() 00072 { 00073 return !--Count; 00074 } 00075 } *m_pData; 00076 00077 static bool SanityCheck(const CCodecImage &one, const CCodecImage &two); 00078 virtual void detach(); 00079 CCodecImage copy() const; 00080 00081 public: 00082 CCodecImage(); 00083 CCodecImage(const CCodecImage &); 00084 CCodecImage(int width, int height); 00085 virtual ~CCodecImage(); 00086 00087 int Width() const; 00088 int Height() const; 00089 virtual void Resize(int w, int h); 00090 00091 void Load(int width, int height, const unsigned char *src); 00092 void Store(int width, int height, unsigned char *dst); 00093 00094 CCodecImage &operator =(const CCodecImage &src); 00095 CCodecImage &operator -=(const CCodecImage &sub); 00096 CCodecImage operator -(const CCodecImage &sub) const; 00097 }; 00098 00099 template <class Image> class YUVTriplet 00100 { 00101 private: 00102 00103 public: 00104 Image Y; 00105 Image U; 00106 Image V; 00107 00108 YUVTriplet<Image>() 00109 { 00110 /* Do exactly nothing */ 00111 } 00112 00113 YUVTriplet<Image>(const YUVTriplet <Image> &copy) 00114 { 00115 Y = copy.Y; 00116 U = copy.U; 00117 V = copy.V; 00118 } 00119 00120 YUVTriplet<Image> &operator =(const YUVTriplet<Image> &assign) 00121 { 00122 Y = assign.Y; 00123 U = assign.U; 00124 V = assign.V; 00125 return *this; 00126 } 00127 00128 void Resize(int w, int h) 00129 { 00130 Y.Resize(w, h); 00131 w >>= 1; 00132 h >>= 1; 00133 U.Resize(w, h); 00134 V.Resize(w, h); 00135 } 00136 00137 YUVTriplet<Image> operator -(const YUVTriplet<Image> &sub) const 00138 { 00139 YUVTriplet<Image> result; 00140 00141 result.Y = Y - sub.Y; 00142 result.U = U - sub.U; 00143 result.V = V - sub.V; 00144 return result; 00145 } 00146 }; 00147 00148 #endif

Generated on Wed Dec 13 23:38:46 2006 for CamStream by doxygen 1.3.7